1 | /* $Id: oslibgdi.cpp,v 1.4 1999-11-26 17:06:07 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 |
|
---|
19 | #include <misc.h>
|
---|
20 | #include <oslibgdi.h>
|
---|
21 | #include <oslibwin.h>
|
---|
22 |
|
---|
23 | //******************************************************************************
|
---|
24 | //******************************************************************************
|
---|
25 | inline ULONG MAPWIN32POINT(RECTLOS2 *parent, ULONG cy, ULONG y)
|
---|
26 | {
|
---|
27 | return (parent->yTop - parent->yBottom - cy - y);
|
---|
28 | }
|
---|
29 | //******************************************************************************
|
---|
30 | //Map win32 y coordinate (in parent window coordinates) to OS/2 y coord. (in parent window coordinates)
|
---|
31 | //******************************************************************************
|
---|
32 | ULONG MapOS2ToWin32Y(HWND hwndParent, ULONG cy, ULONG y)
|
---|
33 | {
|
---|
34 | RECTLOS2 rectParent = {0};
|
---|
35 |
|
---|
36 | if(hwndParent == OSLIB_HWND_DESKTOP) {
|
---|
37 | hwndParent = HWND_DESKTOP;
|
---|
38 | }
|
---|
39 | WinQueryWindowRect(hwndParent, (PRECTL)&rectParent);
|
---|
40 | return MAPWIN32POINT(&rectParent, cy, y);
|
---|
41 | }
|
---|
42 | //******************************************************************************
|
---|
43 | //******************************************************************************
|
---|
44 | BOOL MapOS2ToWin32Point(HWND hwndParent, HWND hwndChild, OSLIBPOINT *point)
|
---|
45 | {
|
---|
46 | RECTLOS2 rectParent = {0};
|
---|
47 |
|
---|
48 | if(hwndParent == OSLIB_HWND_DESKTOP) {
|
---|
49 | hwndParent = HWND_DESKTOP;
|
---|
50 | }
|
---|
51 | if(WinMapWindowPoints(hwndChild, hwndParent, (POINTL *)point, 1) != TRUE) {
|
---|
52 | dprintf(("MapOS2ToWin32Point:WinMapWindowPoint %x %x returned false", hwndParent, hwndChild));
|
---|
53 | return FALSE;
|
---|
54 | }
|
---|
55 | WinQueryWindowRect(hwndParent, (PRECTL)&rectParent);
|
---|
56 | point->y = rectParent.yTop - point->y - 1;
|
---|
57 | return TRUE;
|
---|
58 | }
|
---|
59 | //******************************************************************************
|
---|
60 | // MapOS2ToWin32Rect
|
---|
61 | // Map os/2 rectangle to screen coordinates and convert to win32 rect
|
---|
62 | //
|
---|
63 | // Parameters:
|
---|
64 | // hwndParent: Parent window handle
|
---|
65 | // hwndChild: Child window handle
|
---|
66 | // rectOS2: OS/2 child window RECTL
|
---|
67 | // rectWin32: Win32 Child window RECT (IN)
|
---|
68 | //
|
---|
69 | // Returns:
|
---|
70 | // TRUE: Success
|
---|
71 | // FALSE: Failures
|
---|
72 | //******************************************************************************
|
---|
73 | BOOL MapOS2ToWin32Rectl(HWND hwndParent, HWND hwndChild, PRECTLOS2 rectOS2, PRECT rectWin32)
|
---|
74 | {
|
---|
75 | RECTLOS2 rectParent = {0};
|
---|
76 | Win32BaseWindow *window;
|
---|
77 | LONG height;
|
---|
78 |
|
---|
79 | if(hwndParent == OSLIB_HWND_DESKTOP) {
|
---|
80 | hwndParent = HWND_DESKTOP;
|
---|
81 | }
|
---|
82 | if(WinMapWindowPoints(hwndChild, hwndParent, (PPOINTL)rectOS2, 2) != TRUE) {
|
---|
83 | dprintf(("MapOS2ToWin32Rect:WinMapWindowPoint %x %x returned false", hwndParent, hwndChild));
|
---|
84 | return FALSE;
|
---|
85 | }
|
---|
86 |
|
---|
87 | if(hwndParent != HWND_DESKTOP)
|
---|
88 | {
|
---|
89 | window = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwndParent);
|
---|
90 | if(window == NULL)
|
---|
91 | return FALSE;
|
---|
92 | height = window->getWindowHeight();
|
---|
93 | }
|
---|
94 | else height = OSLibQueryScreenHeight();
|
---|
95 |
|
---|
96 | rectWin32->bottom = height - rectOS2->yBottom;
|
---|
97 | rectWin32->top = height - rectOS2->yTop;
|
---|
98 | rectWin32->left = rectOS2->xLeft;
|
---|
99 | rectWin32->right = rectOS2->xRight;
|
---|
100 |
|
---|
101 | return TRUE;
|
---|
102 | }
|
---|
103 | //******************************************************************************
|
---|
104 | // MapOS2ToWin32Rectl
|
---|
105 | // Convert OS/2 to Win32 RECTL structure
|
---|
106 | //
|
---|
107 | // Parameters:
|
---|
108 | // hwnd: OS/2 window handle
|
---|
109 | // rectOS2: OS/2 child window RECTL
|
---|
110 | // rectWin32: Win32 Child window RECT (IN)
|
---|
111 | //
|
---|
112 | // Returns:
|
---|
113 | // TRUE: Success
|
---|
114 | // FALSE: Failures
|
---|
115 | //******************************************************************************
|
---|
116 | BOOL MapOS2ToWin32Rectl(HWND hwnd,PRECTLOS2 rectOS2, PRECT rectWin32)
|
---|
117 | {
|
---|
118 | RECTL rect;
|
---|
119 |
|
---|
120 | if (!WinQueryWindowRect(hwnd,&rect)) return FALSE;
|
---|
121 |
|
---|
122 | rectWin32->bottom = rect.yTop-rectOS2->yBottom;
|
---|
123 | rectWin32->top = rect.yTop-rectOS2->yTop;
|
---|
124 | rectWin32->left = rectOS2->xLeft;
|
---|
125 | rectWin32->right = rectOS2->xRight;
|
---|
126 |
|
---|
127 | return TRUE;
|
---|
128 | }
|
---|
129 | //******************************************************************************
|
---|
130 | // MapWin32ToOS2Rectl
|
---|
131 | // Convert Win32 to OS/2 RECTL structure
|
---|
132 | //
|
---|
133 | // Parameters:
|
---|
134 | // hwnd: OS/2 window handle
|
---|
135 | // rectWin32: Win32 Child window RECT (IN)
|
---|
136 | // rectOS2: OS/2 Child window RECTL (OUT)
|
---|
137 | // Returns:
|
---|
138 | // TRUE: Success
|
---|
139 | // FALSE: Failures
|
---|
140 | //******************************************************************************
|
---|
141 | BOOL MapWin32ToOS2Rectl(HWND hwnd,PRECT rectWin32, PRECTLOS2 rectOS2)
|
---|
142 | {
|
---|
143 | RECTL rect;
|
---|
144 |
|
---|
145 | if (!WinQueryWindowRect(hwnd,&rect)) return FALSE;
|
---|
146 |
|
---|
147 | rectOS2->yBottom = rect.yTop-rectWin32->bottom;
|
---|
148 | rectOS2->yTop = rect.yTop-rectWin32->top;
|
---|
149 | rectOS2->xLeft = rectWin32->left;
|
---|
150 | rectOS2->xRight = rectWin32->right;
|
---|
151 |
|
---|
152 | return TRUE;
|
---|
153 | }
|
---|
154 | //******************************************************************************
|
---|
155 | //******************************************************************************
|
---|
156 | BOOL MapOS2ToWin32WindowRect(PRECTLOS2 rectOS2,PRECT rectWin32)
|
---|
157 | {
|
---|
158 | rectWin32->bottom = rectOS2->yTop;
|
---|
159 | rectWin32->top = rectOS2->yBottom;
|
---|
160 | rectWin32->left = rectOS2->xLeft;
|
---|
161 | rectWin32->right = rectOS2->xRight;
|
---|
162 |
|
---|
163 | return TRUE;
|
---|
164 | }
|
---|
165 | //******************************************************************************
|
---|
166 | //******************************************************************************
|
---|
167 | BOOL MapWin32ToOS2WindowRect(PRECT rectWin32,PRECTLOS2 rectOS2)
|
---|
168 | {
|
---|
169 | rectOS2->yBottom = rectWin32->top;
|
---|
170 | rectOS2->yTop = rectWin32->bottom;
|
---|
171 | rectOS2->xLeft = rectWin32->left;
|
---|
172 | rectOS2->xRight = rectWin32->right;
|
---|
173 |
|
---|
174 | return TRUE;
|
---|
175 | }
|
---|
176 | //******************************************************************************
|
---|
177 | //******************************************************************************
|
---|
178 | HDC OSLibWinBeginPaint(HWND hwnd, RECT *rectWin32)
|
---|
179 | {
|
---|
180 | RECTL rectl;
|
---|
181 |
|
---|
182 | if(WinQueryUpdateRect(hwnd, &rectl) == FALSE)
|
---|
183 | {
|
---|
184 | dprintf(("BeginPaint, NO update rectl"));
|
---|
185 | return 0;
|
---|
186 | }
|
---|
187 | MapOS2ToWin32Rectl(hwnd,(RECTLOS2 *)&rectl, rectWin32);
|
---|
188 | return WinBeginPaint(hwnd, NULLHANDLE, &rectl);
|
---|
189 | }
|
---|
190 | //******************************************************************************
|
---|
191 | //******************************************************************************
|
---|
192 | BOOL OSLibWinEndPaint(HDC hdc)
|
---|
193 | {
|
---|
194 | return WinEndPaint((HPS)hdc);
|
---|
195 | }
|
---|
196 | //******************************************************************************
|
---|
197 | //******************************************************************************
|
---|
198 | HDC OSLibWinGetPS(HWND hwnd)
|
---|
199 | {
|
---|
200 | if(hwnd == OSLIB_HWND_DESKTOP)
|
---|
201 | hwnd = HWND_DESKTOP;
|
---|
202 |
|
---|
203 | return (HDC)WinGetPS(hwnd);
|
---|
204 | }
|
---|
205 | //******************************************************************************
|
---|
206 | //******************************************************************************
|
---|
207 | BOOL OSLibWinReleasePS(HDC hdc)
|
---|
208 | {
|
---|
209 | return WinReleasePS((HPS)hdc);
|
---|
210 | }
|
---|
211 | //******************************************************************************
|
---|
212 | //******************************************************************************
|
---|
213 | BOOL OSLibWinInvalidateRect(HWND hwnd, PRECT pRect, BOOL fIncludeChildren)
|
---|
214 | {
|
---|
215 | RECTLOS2 rectl;
|
---|
216 |
|
---|
217 | if(pRect) {
|
---|
218 | MapWin32ToOS2Rectl(hwnd,pRect, &rectl);
|
---|
219 | return WinInvalidateRect(hwnd, (PRECTL)&rectl, fIncludeChildren);
|
---|
220 | }
|
---|
221 | return WinInvalidateRect(hwnd, NULL, fIncludeChildren);
|
---|
222 | }
|
---|
223 | //******************************************************************************
|
---|
224 | //Returns rectangle in Win32 window coordinates
|
---|
225 | //******************************************************************************
|
---|
226 | BOOL OSLibWinQueryUpdateRect(HWND hwnd, PRECT pRect)
|
---|
227 | {
|
---|
228 | BOOL rc;
|
---|
229 | RECTLOS2 rectl;
|
---|
230 |
|
---|
231 | rc = WinQueryUpdateRect(hwnd, (PRECTL)&rectl);
|
---|
232 | if(rc) {
|
---|
233 | MapOS2ToWin32Rectl(hwnd,&rectl, pRect);
|
---|
234 | }
|
---|
235 | else memset(pRect, 0, sizeof(RECT));
|
---|
236 | return rc;
|
---|
237 | }
|
---|
238 | //******************************************************************************
|
---|
239 | //******************************************************************************
|
---|
240 |
|
---|