1 | /* $Id: dcrgn.cpp,v 1.1 2000-06-08 18:10:10 sandervl Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * DC functions for USER32
|
---|
5 | *
|
---|
6 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
7 | *
|
---|
8 | */
|
---|
9 |
|
---|
10 | /*****************************************************************************
|
---|
11 | * Includes *
|
---|
12 | *****************************************************************************/
|
---|
13 |
|
---|
14 | #include <odin.h>
|
---|
15 |
|
---|
16 | #define INCL_WIN
|
---|
17 | #define INCL_GPI
|
---|
18 | #define INCL_GREALL
|
---|
19 | #define INCL_DEV
|
---|
20 | #include <os2wrap.h>
|
---|
21 | //#include <pmddi.h>
|
---|
22 | #include <stdlib.h>
|
---|
23 |
|
---|
24 | #include <string.h>
|
---|
25 | #include <win32type.h>
|
---|
26 | #include <win32api.h>
|
---|
27 | #include <winconst.h>
|
---|
28 | #include <misc.h>
|
---|
29 | #include <win32wbase.h>
|
---|
30 | #include <math.h>
|
---|
31 | #include <limits.h>
|
---|
32 | #include "oslibwin.h"
|
---|
33 | #include "oslibmsg.h"
|
---|
34 | #include <dcdata.h>
|
---|
35 |
|
---|
36 | #define INCLUDED_BY_DC
|
---|
37 | #include "dc.h"
|
---|
38 |
|
---|
39 | #define DBG_LOCALLOG DBG_dcrgn
|
---|
40 | #include "dbglocal.h"
|
---|
41 |
|
---|
42 | //******************************************************************************
|
---|
43 | //******************************************************************************
|
---|
44 | int WIN32API GetClipBox( HDC hdc, PRECT lpRect)
|
---|
45 | {
|
---|
46 | pDCData pHps = (pDCData)GpiQueryDCData((HPS)hdc);
|
---|
47 | RECTL rectl;
|
---|
48 | LONG lComplexity;
|
---|
49 | int rc;
|
---|
50 |
|
---|
51 | if(!hdc || !lpRect || !pHps) {
|
---|
52 | dprintf(("GDI32: GetClipBox %x %x ERROR_INVALID_PARAMETER", hdc, lpRect));
|
---|
53 | SetLastError(ERROR_INVALID_PARAMETER_W);
|
---|
54 | return ERROR_W;
|
---|
55 | }
|
---|
56 | if(pHps->isPrinter)
|
---|
57 | {
|
---|
58 | lpRect->left = 0;
|
---|
59 | lpRect->top = 0;
|
---|
60 | lpRect->right = GetDeviceCaps( hdc, HORZRES_W);
|
---|
61 | lpRect->bottom = GetDeviceCaps( hdc, VERTRES_W);
|
---|
62 |
|
---|
63 | rc = SIMPLEREGION_W;
|
---|
64 | }
|
---|
65 | else {
|
---|
66 | lComplexity = GpiQueryClipBox(pHps->hps, &rectl);
|
---|
67 | if(lComplexity == RGN_ERROR)
|
---|
68 | {
|
---|
69 | rc = ERROR_W;
|
---|
70 | }
|
---|
71 | else
|
---|
72 | if(lComplexity == RGN_NULL)
|
---|
73 | {
|
---|
74 | memset(lpRect, 0, sizeof(*lpRect));
|
---|
75 | rc = NULLREGION_W;
|
---|
76 | }
|
---|
77 | else {
|
---|
78 | lpRect->left = rectl.xLeft;
|
---|
79 | lpRect->right = rectl.xRight;
|
---|
80 | #if 0
|
---|
81 | lpRect->top = pHps->height - rectl.yTop;
|
---|
82 | lpRect->bottom = pHps->height - rectl.yBottom;
|
---|
83 | #else
|
---|
84 | //No conversion required as GpiQueryClipBox is affected by
|
---|
85 | //the y-inversion of the window
|
---|
86 | lpRect->top = rectl.yBottom;
|
---|
87 | lpRect->bottom = rectl.yTop;
|
---|
88 | #endif
|
---|
89 | //Convert including/including to including/excluding
|
---|
90 | if(lpRect->left != lpRect->right) {
|
---|
91 | lpRect->right++;
|
---|
92 | }
|
---|
93 | if(lpRect->top != lpRect->bottom) {
|
---|
94 | lpRect->bottom++;
|
---|
95 | }
|
---|
96 | rc = (lComplexity == RGN_RECT) ? SIMPLEREGION_W : COMPLEXREGION_W;
|
---|
97 | }
|
---|
98 | }
|
---|
99 | dprintf(("GDI32: GetClipBox of %X returned %d\n", hdc, rc));
|
---|
100 | return rc;
|
---|
101 | }
|
---|
102 | //******************************************************************************
|
---|
103 | //******************************************************************************
|
---|
104 | int WIN32API GetClipRgn( HDC hdc, HRGN hRgn)
|
---|
105 | {
|
---|
106 | int rc;
|
---|
107 |
|
---|
108 | rc = O32_GetClipRgn(hdc, hRgn);
|
---|
109 | dprintf(("GDI32: GetClipRgn %x %x returned %x", hdc, hRgn, rc));
|
---|
110 | return rc;
|
---|
111 | }
|
---|
112 | //******************************************************************************
|
---|
113 | //******************************************************************************
|
---|
114 | int WIN32API ExcludeClipRect( HDC arg1, int arg2, int arg3, int arg4, int arg5)
|
---|
115 | {
|
---|
116 | dprintf(("GDI32: ExcludeClipRect"));
|
---|
117 | return O32_ExcludeClipRect(arg1, arg2, arg3, arg4, arg5);
|
---|
118 | }
|
---|
119 | //******************************************************************************
|
---|
120 | //******************************************************************************
|
---|
121 | int WIN32API IntersectClipRect(HDC arg1, int arg2, int arg3, int arg4, int arg5)
|
---|
122 | {
|
---|
123 | int rc;
|
---|
124 |
|
---|
125 | rc = O32_IntersectClipRect(arg1, arg2, arg3, arg4, arg5);
|
---|
126 | dprintf(("GDI32: IntersectClipRect returned %d\n", rc));
|
---|
127 | return(rc);
|
---|
128 | }
|
---|
129 | //******************************************************************************
|
---|
130 | //******************************************************************************
|
---|
131 | int WIN32API ExtSelectClipRgn( HDC arg1, HRGN arg2, int arg3)
|
---|
132 | {
|
---|
133 | dprintf(("GDI32: ExtSelectClipRgn"));
|
---|
134 | return O32_ExtSelectClipRgn(arg1, arg2, arg3);
|
---|
135 | }
|
---|
136 | //******************************************************************************
|
---|
137 | //******************************************************************************
|
---|
138 | int WIN32API OffsetClipRgn( HDC arg1, int arg2, int arg3)
|
---|
139 | {
|
---|
140 | dprintf(("GDI32: OffsetClipRgn"));
|
---|
141 | return O32_OffsetClipRgn(arg1, arg2, arg3);
|
---|
142 | }
|
---|
143 | //******************************************************************************
|
---|
144 | //******************************************************************************
|
---|
145 | int WIN32API SelectClipRgn( HDC hdc, HRGN hRgn)
|
---|
146 | {
|
---|
147 | dprintf(("GDI32: SelectClipRgn %x %x", hdc, hRgn));
|
---|
148 | return O32_SelectClipRgn(hdc, hRgn);
|
---|
149 | }
|
---|
150 | //******************************************************************************
|
---|
151 | //******************************************************************************
|
---|
152 | BOOL WIN32API GetUpdateRect (HWND hwnd, LPRECT pRect, BOOL erase)
|
---|
153 | {
|
---|
154 | if (!hwnd)
|
---|
155 | {
|
---|
156 | dprintf(("GetUpdateRect %x %x %d -> invalid handle!!", hwnd, pRect, erase));
|
---|
157 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
|
---|
158 | return FALSE;
|
---|
159 | }
|
---|
160 |
|
---|
161 | RECTL rectl, rectlClient;
|
---|
162 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
163 |
|
---|
164 | if (!wnd)
|
---|
165 | {
|
---|
166 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
|
---|
167 | dprintf(("GetUpdateRect %x %x %d -> invalid handle!!", hwnd, pRect, erase));
|
---|
168 | return FALSE;
|
---|
169 | }
|
---|
170 |
|
---|
171 | dprintf(("GetUpdateRect %x %x %d", hwnd, pRect, erase));
|
---|
172 |
|
---|
173 | BOOL updateRegionExists = WinQueryUpdateRect (wnd->getOS2WindowHandle(), pRect ? &rectl : NULL);
|
---|
174 | if (!pRect) {
|
---|
175 | return (updateRegionExists);
|
---|
176 | }
|
---|
177 |
|
---|
178 | if(updateRegionExists)
|
---|
179 | {
|
---|
180 | //CB: for PM empty rect is valid
|
---|
181 | if ((rectl.xLeft == rectl.xRight) || (rectl.yTop == rectl.yBottom)) {
|
---|
182 | if(pRect) {
|
---|
183 | pRect->left = pRect->top = pRect->right = pRect->bottom = 0;
|
---|
184 | }
|
---|
185 | return FALSE;
|
---|
186 | }
|
---|
187 | mapWin32ToOS2Rect(wnd->getWindowHeight(), wnd->getClientRectPtr(), (PRECTLOS2)&rectlClient);
|
---|
188 | WinIntersectRect(NULL, &rectl, &rectl, &rectlClient);
|
---|
189 | mapOS2ToWin32RectFrameToClient(wnd, (PRECTLOS2)&rectl, pRect);
|
---|
190 |
|
---|
191 | if(wnd->isOwnDC() && GetMapMode(wnd->getOwnDC()) != MM_TEXT_W)
|
---|
192 | {
|
---|
193 | DPtoLP(wnd->getOwnDC(), (LPPOINT)pRect, 2);
|
---|
194 | }
|
---|
195 | if (erase)
|
---|
196 | sendEraseBkgnd (wnd);
|
---|
197 | }
|
---|
198 | else
|
---|
199 | {
|
---|
200 | if(pRect) {
|
---|
201 | pRect->left = pRect->top = pRect->right = pRect->bottom = 0;
|
---|
202 | }
|
---|
203 | }
|
---|
204 |
|
---|
205 | return updateRegionExists;
|
---|
206 | }
|
---|
207 | //******************************************************************************
|
---|
208 | //******************************************************************************
|
---|
209 | BOOL GetOS2UpdateRect(Win32BaseWindow *window, LPRECT pRect)
|
---|
210 | {
|
---|
211 | RECTL rectl;
|
---|
212 | BOOL updateRegionExists = WinQueryUpdateRect(window->getOS2WindowHandle(),pRect ? &rectl:NULL);
|
---|
213 |
|
---|
214 | if (!pRect)
|
---|
215 | return (updateRegionExists);
|
---|
216 |
|
---|
217 | if (updateRegionExists)
|
---|
218 | {
|
---|
219 | //CB: for PM empty rect is valid
|
---|
220 | if ((rectl.xLeft == rectl.xRight) || (rectl.yTop == rectl.yBottom)) return FALSE;
|
---|
221 | mapOS2ToWin32Rect(window->getWindowHeight(), (PRECTLOS2)&rectl,pRect);
|
---|
222 | }
|
---|
223 | else
|
---|
224 | pRect->left = pRect->top = pRect->right = pRect->bottom = 0;
|
---|
225 |
|
---|
226 | return updateRegionExists;
|
---|
227 | }
|
---|
228 | //******************************************************************************
|
---|
229 | //******************************************************************************
|
---|
230 | int WIN32API GetUpdateRgn (HWND hwnd, HRGN hrgn, BOOL erase)
|
---|
231 | {
|
---|
232 | LONG Complexity;
|
---|
233 |
|
---|
234 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
235 |
|
---|
236 | if (!wnd)
|
---|
237 | {
|
---|
238 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
|
---|
239 | return ERROR_W;
|
---|
240 | }
|
---|
241 |
|
---|
242 | Complexity = O32_GetUpdateRgn (wnd->getOS2WindowHandle(), hrgn, FALSE);
|
---|
243 | if (erase && (Complexity > NULLREGION_W)) sendEraseBkgnd(wnd);
|
---|
244 |
|
---|
245 | return Complexity;
|
---|
246 | }
|
---|
247 | //******************************************************************************
|
---|
248 | //******************************************************************************
|
---|
249 | INT WIN32API ExcludeUpdateRgn( HDC hDC, HWND hWnd)
|
---|
250 | {
|
---|
251 | dprintf(("USER32: ExcludeUpdateRgn\n"));
|
---|
252 | hWnd = Win32BaseWindow::Win32ToOS2Handle(hWnd);
|
---|
253 |
|
---|
254 | return O32_ExcludeUpdateRgn(hDC,hWnd);
|
---|
255 | }
|
---|
256 | /*****************************************************************************
|
---|
257 | * Name : int WIN32API GetWindowRgn
|
---|
258 | * Purpose : The GetWindowRgn function obtains a copy of the window region of a window.
|
---|
259 | * Parameters: HWND hWnd handle to window whose window region is to be obtained
|
---|
260 | * HRGN hRgn handle to region that receives a copy of the window region
|
---|
261 | * Variables :
|
---|
262 | * Result : NULLREGION, SIMPLEREGION, COMPLEXREGION, ERROR
|
---|
263 | * Remark :
|
---|
264 | * Status : UNTESTED STUB
|
---|
265 | *
|
---|
266 | * Author : Patrick Haller [Thu, 1998/02/26 11:55]
|
---|
267 | *****************************************************************************/
|
---|
268 |
|
---|
269 | int WIN32API GetWindowRgn(HWND hwnd, HRGN hRgn)
|
---|
270 | {
|
---|
271 | Win32BaseWindow *window;
|
---|
272 | HRGN hWindowRegion;
|
---|
273 |
|
---|
274 | window = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
275 | if(!window) {
|
---|
276 | dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
|
---|
277 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
|
---|
278 | return 0;
|
---|
279 | }
|
---|
280 | dprintf(("USER32:GetWindowRgn (%x,%x)", hwnd, hRgn));
|
---|
281 | hWindowRegion = window->GetWindowRegion();
|
---|
282 |
|
---|
283 | return O32_CombineRgn(hRgn, hWindowRegion, 0, RGN_COPY_W);
|
---|
284 | }
|
---|
285 | /*****************************************************************************
|
---|
286 | * Name : int WIN32API SetWindowRgn
|
---|
287 | * Purpose : The SetWindowRgn function sets the window region of a window. The
|
---|
288 | * window region determines the area within the window where the
|
---|
289 | * operating system permits drawing. The operating system does not
|
---|
290 | * display any portion of a window that lies outside of the window region
|
---|
291 | * When this function is called, the system sends the WM_WINDOWPOSCHANGING and
|
---|
292 | * WM_WINDOWPOSCHANGED messages to the window.
|
---|
293 | *
|
---|
294 | * Parameters: HWND hWnd handle to window whose window region is to be set
|
---|
295 | * HRGN hRgn handle to region
|
---|
296 | * BOOL bRedraw window redraw flag
|
---|
297 | * Variables :
|
---|
298 | * Result : If the function succeeds, the return value is non-zero.
|
---|
299 | * If the function fails, the return value is zero.
|
---|
300 | * Remark :
|
---|
301 | * Status : UNTESTED STUB
|
---|
302 | *
|
---|
303 | * Author : Patrick Haller [Thu, 1998/02/26 11:55]
|
---|
304 | *****************************************************************************/
|
---|
305 |
|
---|
306 | int WIN32API SetWindowRgn(HWND hwnd,
|
---|
307 | HRGN hRgn,
|
---|
308 | BOOL bRedraw)
|
---|
309 | {
|
---|
310 | Win32BaseWindow *window;
|
---|
311 | HRGN hWindowRegion;
|
---|
312 |
|
---|
313 | window = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
314 | if(!window) {
|
---|
315 | dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
|
---|
316 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
|
---|
317 | return 0;
|
---|
318 | }
|
---|
319 | dprintf(("USER32:SetWindowRgn (%x,%x,%d)", hwnd, hRgn, bRedraw));
|
---|
320 | if(window->GetWindowRegion()) {
|
---|
321 | O32_DeleteObject(window->GetWindowRegion());
|
---|
322 | }
|
---|
323 | window->SetWindowRegion(hRgn);
|
---|
324 | if(bRedraw) {
|
---|
325 | RedrawWindow(hwnd, 0, 0, RDW_UPDATENOW_W);
|
---|
326 | }
|
---|
327 | //TODO:
|
---|
328 | // When this function is called, the system sends the WM_WINDOWPOSCHANGING and
|
---|
329 | // WM_WINDOWPOSCHANGED messages to the window.
|
---|
330 | return 1;
|
---|
331 | }
|
---|
332 | //******************************************************************************
|
---|
333 | //******************************************************************************
|
---|