1 | /* $Id: oslibgdi.cpp,v 1.5 1999-12-27 22:53:52 cbratschi Exp $ */
|
---|
2 | /*
|
---|
3 | * Window GDI wrapper functions for OS/2
|
---|
4 | *
|
---|
5 | *
|
---|
6 | * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
7 | *
|
---|
8 | *
|
---|
9 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
10 | *
|
---|
11 | */
|
---|
12 | #define INCL_WIN
|
---|
13 | #define INCL_PM
|
---|
14 | #include <os2.h>
|
---|
15 | #include <os2wrap.h>
|
---|
16 | #include <stdlib.h>
|
---|
17 | #include <string.h>
|
---|
18 | #include <misc.h>
|
---|
19 | #include <oslibgdi.h>
|
---|
20 | #include <oslibwin.h>
|
---|
21 |
|
---|
22 | //CB: new mapping infrastructure to avoid transformation bugs -> available soon
|
---|
23 |
|
---|
24 | /*
|
---|
25 | All functions can be used to transform from Win32 to OS/2 and vice versa
|
---|
26 | First letter is lower case to avoid conflicts with Win32 API names
|
---|
27 |
|
---|
28 | Single y mapping:
|
---|
29 | mapScreenY()
|
---|
30 | mapWindowY()
|
---|
31 |
|
---|
32 | Single point mapping:
|
---|
33 | mapScreenPoint()
|
---|
34 | mapWindowPoint()
|
---|
35 |
|
---|
36 | Single rect mapping:
|
---|
37 | mapScreenRect()
|
---|
38 | mapWindowRect()
|
---|
39 |
|
---|
40 | Rect transformation:
|
---|
41 | copyOS2Rect()
|
---|
42 | copyWin32Rect()
|
---|
43 | */
|
---|
44 |
|
---|
45 | INT mapScreenY(INT y)
|
---|
46 | {
|
---|
47 | return WinQuerySysValue(HWND_DESKTOP,SV_CYSCREEN)-1-y;
|
---|
48 | }
|
---|
49 | //******************************************************************************
|
---|
50 | //******************************************************************************
|
---|
51 | INT mapScreenY(INT screenH,INT y)
|
---|
52 | {
|
---|
53 | return screenH-1-y;
|
---|
54 | }
|
---|
55 |
|
---|
56 |
|
---|
57 | //******************************************************************************
|
---|
58 | //******************************************************************************
|
---|
59 | inline ULONG MAPWIN32POINT(RECTLOS2 *parent, ULONG cy, ULONG y)
|
---|
60 | {
|
---|
61 | return (parent->yTop - parent->yBottom - cy - y);
|
---|
62 | }
|
---|
63 | //******************************************************************************
|
---|
64 | //Map win32 y coordinate (in parent window coordinates) to OS/2 y coord. (in parent window coordinates)
|
---|
65 | //******************************************************************************
|
---|
66 | ULONG MapOS2ToWin32Y(HWND hwndParent, ULONG cy, ULONG y)
|
---|
67 | {
|
---|
68 | RECTLOS2 rectParent = {0};
|
---|
69 |
|
---|
70 | if(hwndParent == OSLIB_HWND_DESKTOP) {
|
---|
71 | hwndParent = HWND_DESKTOP;
|
---|
72 | }
|
---|
73 | WinQueryWindowRect(hwndParent, (PRECTL)&rectParent);
|
---|
74 | return MAPWIN32POINT(&rectParent, cy, y);
|
---|
75 | }
|
---|
76 | //******************************************************************************
|
---|
77 | //******************************************************************************
|
---|
78 | BOOL MapOS2ToWin32Point(HWND hwndParent, HWND hwndChild, OSLIBPOINT *point)
|
---|
79 | {
|
---|
80 | RECTLOS2 rectParent = {0};
|
---|
81 |
|
---|
82 | if(hwndParent == OSLIB_HWND_DESKTOP) {
|
---|
83 | hwndParent = HWND_DESKTOP;
|
---|
84 | }
|
---|
85 | if(WinMapWindowPoints(hwndChild, hwndParent, (POINTL *)point, 1) != TRUE) {
|
---|
86 | dprintf(("MapOS2ToWin32Point:WinMapWindowPoint %x %x returned false", hwndParent, hwndChild));
|
---|
87 | return FALSE;
|
---|
88 | }
|
---|
89 | WinQueryWindowRect(hwndParent, (PRECTL)&rectParent);
|
---|
90 | point->y = rectParent.yTop - point->y - 1;
|
---|
91 | return TRUE;
|
---|
92 | }
|
---|
93 | //******************************************************************************
|
---|
94 | // MapOS2ToWin32Rect
|
---|
95 | // Map os/2 rectangle to screen coordinates and convert to win32 rect
|
---|
96 | //
|
---|
97 | // Parameters:
|
---|
98 | // hwndParent: Parent window handle
|
---|
99 | // hwndChild: Child window handle
|
---|
100 | // rectOS2: OS/2 child window RECTL
|
---|
101 | // rectWin32: Win32 Child window RECT (IN)
|
---|
102 | //
|
---|
103 | // Returns:
|
---|
104 | // TRUE: Success
|
---|
105 | // FALSE: Failures
|
---|
106 | //******************************************************************************
|
---|
107 | BOOL MapOS2ToWin32Rectl(HWND hwndParent, HWND hwndChild, PRECTLOS2 rectOS2, PRECT rectWin32)
|
---|
108 | {
|
---|
109 | RECTLOS2 rectParent = {0};
|
---|
110 | Win32BaseWindow *window;
|
---|
111 | LONG height;
|
---|
112 |
|
---|
113 | if(hwndParent == OSLIB_HWND_DESKTOP) {
|
---|
114 | hwndParent = HWND_DESKTOP;
|
---|
115 | }
|
---|
116 | if(WinMapWindowPoints(hwndChild, hwndParent, (PPOINTL)rectOS2, 2) != TRUE) {
|
---|
117 | dprintf(("MapOS2ToWin32Rect:WinMapWindowPoint %x %x returned false", hwndParent, hwndChild));
|
---|
118 | return FALSE;
|
---|
119 | }
|
---|
120 |
|
---|
121 | if(hwndParent != HWND_DESKTOP)
|
---|
122 | {
|
---|
123 | window = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwndParent);
|
---|
124 | if(window == NULL)
|
---|
125 | return FALSE;
|
---|
126 | height = window->getWindowHeight();
|
---|
127 | }
|
---|
128 | else height = OSLibQueryScreenHeight();
|
---|
129 |
|
---|
130 | rectWin32->bottom = height - rectOS2->yBottom;
|
---|
131 | rectWin32->top = height - rectOS2->yTop;
|
---|
132 | rectWin32->left = rectOS2->xLeft;
|
---|
133 | rectWin32->right = rectOS2->xRight;
|
---|
134 |
|
---|
135 | return TRUE;
|
---|
136 | }
|
---|
137 | //******************************************************************************
|
---|
138 | // MapOS2ToWin32Rectl
|
---|
139 | // Convert OS/2 to Win32 RECTL structure
|
---|
140 | //
|
---|
141 | // Parameters:
|
---|
142 | // hwnd: OS/2 window handle
|
---|
143 | // rectOS2: OS/2 child window RECTL
|
---|
144 | // rectWin32: Win32 Child window RECT (IN)
|
---|
145 | //
|
---|
146 | // Returns:
|
---|
147 | // TRUE: Success
|
---|
148 | // FALSE: Failures
|
---|
149 | //******************************************************************************
|
---|
150 | BOOL MapOS2ToWin32Rectl(HWND hwnd,PRECTLOS2 rectOS2, PRECT rectWin32)
|
---|
151 | {
|
---|
152 | RECTL rect;
|
---|
153 |
|
---|
154 | if (!WinQueryWindowRect(hwnd,&rect)) return FALSE;
|
---|
155 |
|
---|
156 | rectWin32->bottom = rect.yTop-rectOS2->yBottom;
|
---|
157 | rectWin32->top = rect.yTop-rectOS2->yTop;
|
---|
158 | rectWin32->left = rectOS2->xLeft;
|
---|
159 | rectWin32->right = rectOS2->xRight;
|
---|
160 |
|
---|
161 | return TRUE;
|
---|
162 | }
|
---|
163 | //******************************************************************************
|
---|
164 | // MapWin32ToOS2Rectl
|
---|
165 | // Convert Win32 to OS/2 RECTL structure
|
---|
166 | //
|
---|
167 | // Parameters:
|
---|
168 | // hwnd: OS/2 window handle
|
---|
169 | // rectWin32: Win32 Child window RECT (IN)
|
---|
170 | // rectOS2: OS/2 Child window RECTL (OUT)
|
---|
171 | // Returns:
|
---|
172 | // TRUE: Success
|
---|
173 | // FALSE: Failures
|
---|
174 | //******************************************************************************
|
---|
175 | BOOL MapWin32ToOS2Rectl(HWND hwnd,PRECT rectWin32, PRECTLOS2 rectOS2)
|
---|
176 | {
|
---|
177 | RECTL rect;
|
---|
178 |
|
---|
179 | if (!WinQueryWindowRect(hwnd,&rect)) return FALSE;
|
---|
180 |
|
---|
181 | rectOS2->yBottom = rect.yTop-rectWin32->bottom;
|
---|
182 | rectOS2->yTop = rect.yTop-rectWin32->top;
|
---|
183 | rectOS2->xLeft = rectWin32->left;
|
---|
184 | rectOS2->xRight = rectWin32->right;
|
---|
185 |
|
---|
186 | return TRUE;
|
---|
187 | }
|
---|
188 | //******************************************************************************
|
---|
189 | //******************************************************************************
|
---|
190 | BOOL MapOS2ToWin32WindowRect(PRECTLOS2 rectOS2,PRECT rectWin32)
|
---|
191 | {
|
---|
192 | rectWin32->bottom = rectOS2->yTop;
|
---|
193 | rectWin32->top = rectOS2->yBottom;
|
---|
194 | rectWin32->left = rectOS2->xLeft;
|
---|
195 | rectWin32->right = rectOS2->xRight;
|
---|
196 |
|
---|
197 | return TRUE;
|
---|
198 | }
|
---|
199 | //******************************************************************************
|
---|
200 | //******************************************************************************
|
---|
201 | BOOL MapWin32ToOS2WindowRect(PRECT rectWin32,PRECTLOS2 rectOS2)
|
---|
202 | {
|
---|
203 | rectOS2->yBottom = rectWin32->top;
|
---|
204 | rectOS2->yTop = rectWin32->bottom;
|
---|
205 | rectOS2->xLeft = rectWin32->left;
|
---|
206 | rectOS2->xRight = rectWin32->right;
|
---|
207 |
|
---|
208 | return TRUE;
|
---|
209 | }
|
---|
210 | //******************************************************************************
|
---|
211 | //******************************************************************************
|
---|
212 | HDC OSLibWinBeginPaint(HWND hwnd, RECT *rectWin32)
|
---|
213 | {
|
---|
214 | RECTL rectl;
|
---|
215 |
|
---|
216 | if(WinQueryUpdateRect(hwnd, &rectl) == FALSE)
|
---|
217 | {
|
---|
218 | dprintf(("BeginPaint, NO update rectl"));
|
---|
219 | return 0;
|
---|
220 | }
|
---|
221 | MapOS2ToWin32Rectl(hwnd,(RECTLOS2 *)&rectl, rectWin32);
|
---|
222 | return WinBeginPaint(hwnd, NULLHANDLE, &rectl);
|
---|
223 | }
|
---|
224 | //******************************************************************************
|
---|
225 | //******************************************************************************
|
---|
226 | BOOL OSLibWinEndPaint(HDC hdc)
|
---|
227 | {
|
---|
228 | return WinEndPaint((HPS)hdc);
|
---|
229 | }
|
---|
230 | //******************************************************************************
|
---|
231 | //******************************************************************************
|
---|
232 | HDC OSLibWinGetPS(HWND hwnd)
|
---|
233 | {
|
---|
234 | if(hwnd == OSLIB_HWND_DESKTOP)
|
---|
235 | hwnd = HWND_DESKTOP;
|
---|
236 |
|
---|
237 | return (HDC)WinGetPS(hwnd);
|
---|
238 | }
|
---|
239 | //******************************************************************************
|
---|
240 | //******************************************************************************
|
---|
241 | BOOL OSLibWinReleasePS(HDC hdc)
|
---|
242 | {
|
---|
243 | return WinReleasePS((HPS)hdc);
|
---|
244 | }
|
---|
245 | //******************************************************************************
|
---|
246 | //******************************************************************************
|
---|
247 | BOOL OSLibWinInvalidateRect(HWND hwnd, PRECT pRect, BOOL fIncludeChildren)
|
---|
248 | {
|
---|
249 | RECTLOS2 rectl;
|
---|
250 |
|
---|
251 | if(pRect) {
|
---|
252 | MapWin32ToOS2Rectl(hwnd,pRect, &rectl);
|
---|
253 | return WinInvalidateRect(hwnd, (PRECTL)&rectl, fIncludeChildren);
|
---|
254 | }
|
---|
255 | return WinInvalidateRect(hwnd, NULL, fIncludeChildren);
|
---|
256 | }
|
---|
257 | //******************************************************************************
|
---|
258 | //Returns rectangle in Win32 window coordinates
|
---|
259 | //******************************************************************************
|
---|
260 | BOOL OSLibWinQueryUpdateRect(HWND hwnd, PRECT pRect)
|
---|
261 | {
|
---|
262 | BOOL rc;
|
---|
263 | RECTLOS2 rectl;
|
---|
264 |
|
---|
265 | rc = WinQueryUpdateRect(hwnd, (PRECTL)&rectl);
|
---|
266 | if(rc) {
|
---|
267 | MapOS2ToWin32Rectl(hwnd,&rectl, pRect);
|
---|
268 | }
|
---|
269 | else memset(pRect, 0, sizeof(RECT));
|
---|
270 | return rc;
|
---|
271 | }
|
---|
272 | //******************************************************************************
|
---|
273 | //******************************************************************************
|
---|
274 |
|
---|