1 | /* $Id: dc.cpp,v 1.67 2000-07-18 18:35:38 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_dc
|
---|
40 | #include "dbglocal.h"
|
---|
41 |
|
---|
42 | #ifndef DEVESC_SETPS
|
---|
43 | #define DEVESC_SETPS 49149L
|
---|
44 | #endif
|
---|
45 |
|
---|
46 | #define FLOAT_TO_FIXED(x) ((FIXED) ((x) * 65536.0))
|
---|
47 | #define MICRO_HPS_TO_HDC(x) ((x) & 0xFFFFFFFE)
|
---|
48 |
|
---|
49 | #define PMRECT_FROM_WINRECT( pmRect, winRect ) \
|
---|
50 | { \
|
---|
51 | (pmRect).xLeft = (winRect).left; \
|
---|
52 | (pmRect).yBottom = (winRect).bottom; \
|
---|
53 | (pmRect).xRight = (winRect).right; \
|
---|
54 | (pmRect).yTop = (winRect).top; \
|
---|
55 | }
|
---|
56 |
|
---|
57 | #define WINRECT_FROM_PMRECT( winRect, pmRect ) \
|
---|
58 | { \
|
---|
59 | (winRect).left = (pmRect).xLeft; \
|
---|
60 | (winRect).top = (pmRect).yTop; \
|
---|
61 | (winRect).right = (pmRect).xRight; \
|
---|
62 | (winRect).bottom = (pmRect).yBottom; \
|
---|
63 | }
|
---|
64 |
|
---|
65 | #define MEM_HPS_MAX 768
|
---|
66 |
|
---|
67 | const XFORM_W XFORMIdentity = { 1.0, 0.0, 0.0, 1.0, 0, 0 };
|
---|
68 | const MATRIXLF matrixlfIdentity = { 0x10000, 0, 0, 0, 0x10000, 0, 0, 0, 0};
|
---|
69 |
|
---|
70 | BOOL setPageXForm(Win32BaseWindow *wnd, pDCData pHps);
|
---|
71 | BOOL changePageXForm(Win32BaseWindow *wnd, pDCData pHps, PPOINTL pValue, int x, int y, PPOINTL pPrev);
|
---|
72 | LONG clientHeight(Win32BaseWindow *wnd, HWND hwnd, pDCData pHps);
|
---|
73 |
|
---|
74 | //******************************************************************************
|
---|
75 | //******************************************************************************
|
---|
76 | void TestWideLine (pDCData pHps)
|
---|
77 | {
|
---|
78 | const LOGPEN_W *pLogPen;
|
---|
79 |
|
---|
80 | pHps->isWideLine = FALSE;
|
---|
81 | pLogPen = pHps->penIsExtPen ?
|
---|
82 | &(pHps->lastPenObject->ExtPen.logpen) :
|
---|
83 | &(pHps->lastPenObject->Pen.logpen);
|
---|
84 |
|
---|
85 | if (((pLogPen->lopnStyle & PS_STYLE_MASK_W) != PS_NULL_W) &&
|
---|
86 | (pLogPen->lopnWidth.x > 0))
|
---|
87 | {
|
---|
88 | POINTL aptl[2] = { 0, 0, pLogPen->lopnWidth.x, pLogPen->lopnWidth.x };
|
---|
89 |
|
---|
90 | GpiConvert(pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, aptl);
|
---|
91 |
|
---|
92 | ULONG dx = abs(aptl[0].x - aptl[1].x);
|
---|
93 | ULONG dy = abs(aptl[0].y - aptl[1].y);
|
---|
94 |
|
---|
95 | pHps->isWideLine = (dx > 1) || (dy > 1);
|
---|
96 | }
|
---|
97 | }
|
---|
98 | //******************************************************************************
|
---|
99 | //******************************************************************************
|
---|
100 | void Calculate1PixelDelta(pDCData pHps)
|
---|
101 | {
|
---|
102 | POINTL aptl[2] = {0, 0, 1, 1};
|
---|
103 |
|
---|
104 | GpiConvert(pHps->hps, CVTC_DEVICE, CVTC_WORLD, 2, aptl);
|
---|
105 | pHps->worldYDeltaFor1Pixel = (int)(aptl[1].y - aptl[0].y);
|
---|
106 | pHps->worldXDeltaFor1Pixel = (int)(aptl[1].x - aptl[0].x); // 171182
|
---|
107 | }
|
---|
108 | //******************************************************************************
|
---|
109 | //******************************************************************************
|
---|
110 | int setMapMode(Win32BaseWindow *wnd, pDCData pHps, int mode)
|
---|
111 | {
|
---|
112 | int prevMode = 0;
|
---|
113 | ULONG flOptions;
|
---|
114 |
|
---|
115 | switch (mode)
|
---|
116 | {
|
---|
117 | case MM_HIENGLISH_W : flOptions = PU_HIENGLISH; break;
|
---|
118 | case MM_LOENGLISH_W : flOptions = PU_LOENGLISH; break;
|
---|
119 | case MM_HIMETRIC_W : flOptions = PU_HIMETRIC ; break;
|
---|
120 | case MM_LOMETRIC_W : flOptions = PU_LOMETRIC ; break;
|
---|
121 | case MM_TEXT_W : flOptions = PU_PELS ; break;
|
---|
122 | case MM_TWIPS_W : flOptions = PU_TWIPS ; break;
|
---|
123 | case MM_ANISOTROPIC_W: flOptions = PU_PELS ; break;
|
---|
124 | case MM_ISOTROPIC_W : flOptions = PU_LOMETRIC ; break;
|
---|
125 | default:
|
---|
126 | SetLastError(ERROR_INVALID_PARAMETER_W);
|
---|
127 | return FALSE;
|
---|
128 | }
|
---|
129 |
|
---|
130 | prevMode = pHps->MapMode; /* store previous mode */
|
---|
131 | pHps->MapMode = mode;
|
---|
132 |
|
---|
133 | if (mode == MM_TEXT_W)
|
---|
134 | {
|
---|
135 | pHps->viewportXExt =
|
---|
136 | pHps->viewportYExt = 1.0;
|
---|
137 | pHps->windowExt.cx =
|
---|
138 | pHps->windowExt.cy = 1;
|
---|
139 | }
|
---|
140 | else if (mode != MM_ANISOTROPIC_W)
|
---|
141 | {
|
---|
142 | RECTL rectl;
|
---|
143 | SIZEL sizel;
|
---|
144 | ULONG data[3];
|
---|
145 |
|
---|
146 | data[0] = flOptions;
|
---|
147 | data[1] = data[2] = 0;
|
---|
148 |
|
---|
149 | if (DevEscape(pHps->hdc ? pHps->hdc : pHps->hps, DEVESC_SETPS, 12, (PBYTE)data, 0, 0) == DEVESC_ERROR)
|
---|
150 | {
|
---|
151 | SetLastError(ERROR_INVALID_PARAMETER_W);
|
---|
152 | return 0;
|
---|
153 | }
|
---|
154 |
|
---|
155 | GpiQueryPageViewport(pHps->hps, &rectl);
|
---|
156 | pHps->viewportXExt = (double)rectl.xRight;
|
---|
157 | pHps->viewportYExt = -(double)rectl.yTop;
|
---|
158 |
|
---|
159 | GreGetPageUnits(pHps->hdc? pHps->hdc : pHps->hps, &sizel);
|
---|
160 | pHps->windowExt.cx = sizel.cx;
|
---|
161 | pHps->windowExt.cy = sizel.cy;
|
---|
162 |
|
---|
163 | data[0] = PU_PELS;
|
---|
164 | DevEscape(pHps->hdc ? pHps->hdc : pHps->hps, DEVESC_SETPS, 12, (PBYTE)data, 0, 0);
|
---|
165 | }
|
---|
166 |
|
---|
167 | if (((prevMode != MM_ISOTROPIC_W) && (prevMode != MM_ANISOTROPIC_W)) &&
|
---|
168 | ((mode == MM_ISOTROPIC_W) || (mode == MM_ANISOTROPIC_W)))
|
---|
169 | {
|
---|
170 | if (pHps->lWndXExtSave && pHps->lWndYExtSave)
|
---|
171 | {
|
---|
172 | changePageXForm (wnd, pHps, (PPOINTL)&pHps->windowExt,
|
---|
173 | pHps->lWndXExtSave, pHps->lWndYExtSave, NULL );
|
---|
174 | pHps->lWndXExtSave = pHps->lWndYExtSave = 0;
|
---|
175 | }
|
---|
176 | if (pHps->lVwpXExtSave && pHps->lVwpYExtSave)
|
---|
177 | {
|
---|
178 | changePageXForm (wnd, pHps, NULL,
|
---|
179 | pHps->lVwpXExtSave, pHps->lVwpYExtSave, NULL );
|
---|
180 | pHps->lVwpXExtSave = pHps->lVwpYExtSave = 0;
|
---|
181 | }
|
---|
182 | }
|
---|
183 |
|
---|
184 | setPageXForm(wnd, pHps);
|
---|
185 |
|
---|
186 | return prevMode;
|
---|
187 | }
|
---|
188 | //******************************************************************************
|
---|
189 | //******************************************************************************
|
---|
190 | BOOL setPageXForm(Win32BaseWindow *wnd, pDCData pHps)
|
---|
191 | {
|
---|
192 | MATRIXLF mlf;
|
---|
193 | BOOL rc = TRUE;
|
---|
194 |
|
---|
195 | pHps->height = clientHeight(wnd, 0, pHps) - 1;
|
---|
196 |
|
---|
197 | double xScale = pHps->viewportXExt / (double)pHps->windowExt.cx;
|
---|
198 | double yScale = pHps->viewportYExt / (double)pHps->windowExt.cy;
|
---|
199 |
|
---|
200 | mlf.fxM11 = FLOAT_TO_FIXED(xScale);
|
---|
201 | mlf.fxM12 = 0;
|
---|
202 | mlf.lM13 = 0;
|
---|
203 | mlf.fxM21 = 0;
|
---|
204 | mlf.fxM22 = FLOAT_TO_FIXED(yScale);
|
---|
205 | mlf.lM23 = 0;
|
---|
206 | mlf.lM31 = pHps->viewportOrg.x - (LONG)(pHps->windowOrg.x * xScale);
|
---|
207 | mlf.lM32 = pHps->viewportOrg.y - (LONG)(pHps->windowOrg.y * yScale);
|
---|
208 |
|
---|
209 | pHps->isLeftLeft = mlf.fxM11 >= 0;
|
---|
210 | pHps->isTopTop = mlf.fxM22 >= 0;
|
---|
211 |
|
---|
212 | BOOL bEnableYInversion = FALSE;
|
---|
213 | if ((mlf.fxM22 > 0) ||
|
---|
214 | ((pHps->graphicsMode == GM_ADVANCED_W) &&
|
---|
215 | ((pHps->MapMode == MM_ANISOTROPIC_W) ||
|
---|
216 | (pHps->MapMode == MM_ISOTROPIC_W))))
|
---|
217 | {
|
---|
218 | bEnableYInversion = TRUE;
|
---|
219 | }
|
---|
220 | else
|
---|
221 | {
|
---|
222 | bEnableYInversion = FALSE;
|
---|
223 | mlf.lM32 = pHps->HPStoHDCInversionHeight + pHps->height - mlf.lM32;
|
---|
224 | mlf.fxM22 = -mlf.fxM22;
|
---|
225 | }
|
---|
226 |
|
---|
227 | if (!pHps->isMetaPS)
|
---|
228 | // if ((!pHps->isMetaPS) ||
|
---|
229 | // (pHps->pMetaFileObject && pHps->pMetaFileObject->isEnhanced()))
|
---|
230 | rc = GpiSetDefaultViewMatrix(pHps->hps, 8, &mlf, TRANSFORM_REPLACE);
|
---|
231 |
|
---|
232 | if (bEnableYInversion)
|
---|
233 | GpiEnableYInversion(pHps->hps, pHps->height + pHps->HPStoHDCInversionHeight);
|
---|
234 | else
|
---|
235 | GpiEnableYInversion(pHps->hps, 0);
|
---|
236 |
|
---|
237 | TestWideLine(pHps);
|
---|
238 | Calculate1PixelDelta(pHps);
|
---|
239 | return rc;
|
---|
240 | }
|
---|
241 | //******************************************************************************
|
---|
242 | //******************************************************************************
|
---|
243 | BOOL changePageXForm(Win32BaseWindow *wnd, pDCData pHps, PPOINTL pValue, int x, int y, PPOINTL pPrev)
|
---|
244 | {
|
---|
245 | BOOL result = FALSE;
|
---|
246 |
|
---|
247 | if (pValue)
|
---|
248 | {
|
---|
249 | if (pPrev)
|
---|
250 | *pPrev = *pValue;
|
---|
251 |
|
---|
252 | if ((pValue->x == x) && (pValue->y == y)) {
|
---|
253 | return TRUE;
|
---|
254 | }
|
---|
255 | pValue->x = x;
|
---|
256 | pValue->y = y;
|
---|
257 | }
|
---|
258 | else
|
---|
259 | {
|
---|
260 | if (pPrev)
|
---|
261 | {
|
---|
262 | pPrev->x = (int)pHps->viewportXExt;
|
---|
263 | pPrev->y = (int)pHps->viewportYExt;
|
---|
264 | }
|
---|
265 | pHps->viewportXExt = (double)x;
|
---|
266 | pHps->viewportYExt = (double)y;
|
---|
267 | }
|
---|
268 |
|
---|
269 | if (pHps->MapMode == MM_ISOTROPIC_W)
|
---|
270 | {
|
---|
271 | double xExt = fabs(pHps->viewportXExt);
|
---|
272 | double yExt = fabs(pHps->viewportYExt);
|
---|
273 | double sf = fabs((double)pHps->windowExt.cx / pHps->windowExt.cy);
|
---|
274 |
|
---|
275 | if (xExt > (yExt * sf))
|
---|
276 | {
|
---|
277 | xExt = yExt * sf;
|
---|
278 |
|
---|
279 | if ((double)LONG_MAX <= xExt) return (result);
|
---|
280 |
|
---|
281 | if (pHps->viewportXExt < 0.0)
|
---|
282 | pHps->viewportXExt = -xExt;
|
---|
283 | else
|
---|
284 | pHps->viewportXExt = xExt;
|
---|
285 | }
|
---|
286 | else
|
---|
287 | {
|
---|
288 | yExt = xExt / sf;
|
---|
289 |
|
---|
290 | if ((double)LONG_MAX <= yExt) return (result);
|
---|
291 |
|
---|
292 | if (pHps->viewportYExt < 0.0)
|
---|
293 | pHps->viewportYExt = -yExt;
|
---|
294 | else
|
---|
295 | pHps->viewportYExt = yExt;
|
---|
296 | }
|
---|
297 | }
|
---|
298 | result = setPageXForm(wnd, pHps);
|
---|
299 |
|
---|
300 | return (result);
|
---|
301 | }
|
---|
302 | //******************************************************************************
|
---|
303 | //******************************************************************************
|
---|
304 | VOID removeClientArea(pDCData pHps)
|
---|
305 | {
|
---|
306 | POINTL point;
|
---|
307 |
|
---|
308 | // This function checks to see if a client area is currently selected, if
|
---|
309 | // it is the origin plus the visible region of the frame are restored.
|
---|
310 |
|
---|
311 | pHps->isClient = FALSE;
|
---|
312 |
|
---|
313 | GreGetDCOrigin(pHps->hps, &point);
|
---|
314 |
|
---|
315 | if(pHps->isClientArea)
|
---|
316 | {
|
---|
317 | dprintf2(("removeClientArea: (%d,%d) -> (%d,%d)", point.x, point.y, pHps->ptlOrigin.x, pHps->ptlOrigin.y));
|
---|
318 | pHps->isClientArea = FALSE;
|
---|
319 | GreSetupDC(pHps->hps,
|
---|
320 | pHps->hrgnVis,
|
---|
321 | pHps->ptlOrigin.x,
|
---|
322 | pHps->ptlOrigin.y,
|
---|
323 | 0,
|
---|
324 | SETUPDC_ORIGIN | SETUPDC_VISRGN | SETUPDC_RECALCCLIP);
|
---|
325 | }
|
---|
326 | else dprintf(("removeClientArea: (%d,%d)", point.x, point.y));
|
---|
327 |
|
---|
328 | }
|
---|
329 | //******************************************************************************
|
---|
330 | //******************************************************************************
|
---|
331 | HRGN selectClientArea(Win32BaseWindow *window, pDCData pHps, PRECTL prclPaint)
|
---|
332 | {
|
---|
333 | // This function checks to see if the DC needs to be adjusted to a client
|
---|
334 | // area and makes the adjustment.
|
---|
335 | RECTL rcl, rcltemp;
|
---|
336 | HRGN hrgnRect, hrgnClip, hrgnOldClip = 0;
|
---|
337 | HWND hwnd;
|
---|
338 | LONG rc;
|
---|
339 | PRECT pClient = window->getClientRectPtr();
|
---|
340 | PRECT pWindow = window->getWindowRect();
|
---|
341 |
|
---|
342 | if(pClient->left == 0 && pClient->top == 0 &&
|
---|
343 | window->getClientHeight() == window->getWindowHeight() &&
|
---|
344 | window->getClientWidth() == window->getWindowWidth())
|
---|
345 | {
|
---|
346 | //client rectangle = frame rectangle -> no change necessary
|
---|
347 | //only setup the clip region
|
---|
348 | goto setupclipregion;
|
---|
349 | }
|
---|
350 | if(pHps->isClientArea) {
|
---|
351 | //TODO: counter
|
---|
352 | dprintf(("WARNING: selectClientArea; already selected!!"));
|
---|
353 | goto setupclipregion;
|
---|
354 | }
|
---|
355 | pHps->isClient = TRUE;
|
---|
356 |
|
---|
357 | hwnd = window->getOS2WindowHandle();
|
---|
358 |
|
---|
359 | mapWin32ToOS2Rect(window->getWindowHeight(), window->getClientRectPtr(), (PRECTLOS2)&rcl);
|
---|
360 |
|
---|
361 | //convert to screen coordinates
|
---|
362 | GreGetDCOrigin(pHps->hps, (PPOINTL)&rcltemp);
|
---|
363 | rcl.xLeft += rcltemp.xLeft;
|
---|
364 | rcl.xRight += rcltemp.xLeft;
|
---|
365 | rcl.yTop += rcltemp.yBottom;
|
---|
366 | rcl.yBottom += rcltemp.yBottom;
|
---|
367 |
|
---|
368 | pHps->ptlOrigin.x = rcltemp.xLeft;
|
---|
369 | pHps->ptlOrigin.y = rcltemp.yBottom;
|
---|
370 |
|
---|
371 | dprintf2(("selectClientArea: (%d,%d) -> (%d,%d)", rcltemp.xLeft, rcltemp.yBottom, rcl.xLeft, rcl.yBottom));
|
---|
372 |
|
---|
373 | if(pHps->hrgnVis == 0)
|
---|
374 | pHps->hrgnVis = GreCreateRectRegion(pHps->hps, &rcl, 1);
|
---|
375 |
|
---|
376 | hrgnRect = GreCreateRectRegion(pHps->hps, &rcl, 1);
|
---|
377 |
|
---|
378 | // Query the visible region
|
---|
379 | GreCopyClipRegion(pHps->hps, pHps->hrgnVis, 0, COPYCRGN_VISRGN);
|
---|
380 | GpiQueryRegionBox(pHps->hps, pHps->hrgnVis, &rcltemp);
|
---|
381 | // And the visible region of the frame with the client rectangle
|
---|
382 | // to get the new visible region
|
---|
383 | GreCombineRegion(pHps->hps, hrgnRect, pHps->hrgnVis, hrgnRect, CRGN_AND);
|
---|
384 |
|
---|
385 | // Set the new origin plus visible region in the DC
|
---|
386 | GreSetupDC(pHps->hps,
|
---|
387 | hrgnRect,
|
---|
388 | rcl.xLeft,
|
---|
389 | rcl.yBottom,
|
---|
390 | NULL,
|
---|
391 | SETUPDC_ORIGIN | SETUPDC_VISRGN | SETUPDC_RECALCCLIP);
|
---|
392 |
|
---|
393 | /*
|
---|
394 | GpiQueryRegionBox(pHps->hps, hrgnClip, &rcltemp);
|
---|
395 | GpiQueryRegionBox(pHps->hps, hrgnOldClip, &rcltemp);
|
---|
396 |
|
---|
397 | GpiQueryRegionBox(pHps->hps, hrgnRect, &rcltemp);
|
---|
398 |
|
---|
399 | GreGetDCOrigin(pHps->hps, (PPOINTL)&rcltemp);
|
---|
400 |
|
---|
401 | GreCopyClipRegion(pHps->hps, hrgnRect, 0, COPYCRGN_VISRGN);
|
---|
402 | GpiQueryRegionBox(pHps->hps, hrgnRect, &rcltemp);
|
---|
403 |
|
---|
404 | GreCopyClipRegion(pHps->hps, hrgnRect, 0, COPYCRGN_ALLINTERSECT);
|
---|
405 | GpiQueryRegionBox(pHps->hps, hrgnRect, &rcltemp);
|
---|
406 |
|
---|
407 | GreCopyClipRegion(pHps->hps, hrgnRect, 0, COPYCRGN_CLIPRGN);
|
---|
408 | GpiQueryRegionBox(pHps->hps, hrgnRect, &rcltemp);
|
---|
409 | */
|
---|
410 | pHps->isClientArea = TRUE;
|
---|
411 |
|
---|
412 | // Destroy the region now we have finished with it.
|
---|
413 | GreDestroyRegion(pHps->hps, hrgnRect);
|
---|
414 |
|
---|
415 | setupclipregion:
|
---|
416 | if(prclPaint) {
|
---|
417 | #if 0
|
---|
418 | hrgnClip = GpiQueryClipRegion(pHps->hps);
|
---|
419 | if(hrgnClip) {
|
---|
420 | rc = GreIntersectClipRectangle(pHps->hps, prclPaint);
|
---|
421 | if(rc == RGN_ERROR) {
|
---|
422 | dprintf(("selectClientArea: GreIntersectClipRectangle returned RGN_ERROR!"));
|
---|
423 | }
|
---|
424 | }
|
---|
425 | else {
|
---|
426 | #endif
|
---|
427 | hrgnClip = GreCreateRectRegion(pHps->hps, prclPaint, 1);
|
---|
428 | GreSelectClipRegion(pHps->hps, hrgnClip, &hrgnOldClip);
|
---|
429 | // }
|
---|
430 | }
|
---|
431 |
|
---|
432 | return hrgnOldClip;
|
---|
433 | }
|
---|
434 | //******************************************************************************
|
---|
435 | //******************************************************************************
|
---|
436 | LONG clientHeight(Win32BaseWindow *wnd, HWND hwnd, pDCData pHps)
|
---|
437 | {
|
---|
438 | if ((hwnd == 0) && (pHps != 0))
|
---|
439 | hwnd = pHps->hwnd;
|
---|
440 |
|
---|
441 | if ((hwnd != 0) || (pHps == 0))
|
---|
442 | {
|
---|
443 | if(wnd) {
|
---|
444 | if(pHps && !pHps->isClientArea) {
|
---|
445 | return (wnd->getWindowHeight());
|
---|
446 | }
|
---|
447 | else return (wnd->getClientHeight());
|
---|
448 | }
|
---|
449 | else return OSLibQueryScreenHeight();
|
---|
450 | }
|
---|
451 | else if (pHps->bitmapHandle)
|
---|
452 | {
|
---|
453 | return pHps->bitmapHeight;
|
---|
454 | }
|
---|
455 | else if (pHps->isMetaPS)
|
---|
456 | {
|
---|
457 | return 0;
|
---|
458 | }
|
---|
459 | else if (pHps->isPrinter)
|
---|
460 | {
|
---|
461 | return pHps->printPageHeight;
|
---|
462 | }
|
---|
463 | else
|
---|
464 | {
|
---|
465 | return MEM_HPS_MAX;
|
---|
466 | }
|
---|
467 | }
|
---|
468 | //******************************************************************************
|
---|
469 | //******************************************************************************
|
---|
470 | BOOL isYup (pDCData pHps)
|
---|
471 | {
|
---|
472 | if (((pHps->windowExt.cy < 0) && (pHps->viewportYExt > 0.0)) ||
|
---|
473 | ((pHps->windowExt.cy > 0) && (pHps->viewportYExt < 0.0)))
|
---|
474 | {
|
---|
475 | if ((pHps->graphicsMode == GM_COMPATIBLE_W) ||
|
---|
476 | ((pHps->graphicsMode == GM_ADVANCED_W) && (pHps->xform.eM22 >= 0.0)))
|
---|
477 | return TRUE;
|
---|
478 | }
|
---|
479 | else
|
---|
480 | {
|
---|
481 | if ((pHps->graphicsMode == GM_ADVANCED_W) && (pHps->xform.eM22 < 0.0))
|
---|
482 | return TRUE;
|
---|
483 | }
|
---|
484 | return FALSE;
|
---|
485 | }
|
---|
486 | //******************************************************************************
|
---|
487 | //******************************************************************************
|
---|
488 | INT revertDy (Win32BaseWindow *wnd, INT dy)
|
---|
489 | {
|
---|
490 | //SvL: Hack for memory.exe (doesn't get repainted properly otherwise)
|
---|
491 | // if (wnd->isOwnDC() && wnd->getOwnDC())
|
---|
492 | if (wnd->isOwnDC())
|
---|
493 | {
|
---|
494 | pDCData pHps = (pDCData)GpiQueryDCData (wnd->getOwnDC());
|
---|
495 |
|
---|
496 | if (pHps != NULLHANDLE)
|
---|
497 | if (!isYup (pHps))
|
---|
498 | dy = -dy;
|
---|
499 | }
|
---|
500 | else
|
---|
501 | {
|
---|
502 | dy = -dy;
|
---|
503 | }
|
---|
504 | return (dy);
|
---|
505 | }
|
---|
506 | //******************************************************************************
|
---|
507 | //******************************************************************************
|
---|
508 | HDC sendEraseBkgnd (Win32BaseWindow *wnd)
|
---|
509 | {
|
---|
510 | BOOL erased;
|
---|
511 | HWND hwnd;
|
---|
512 | HDC hdc;
|
---|
513 | HPS hps;
|
---|
514 | HRGN hrgnUpdate, hrgnOld, hrgnClip, hrgnCombined;
|
---|
515 | RECTL rectl = { 1, 1, 2, 2 };
|
---|
516 |
|
---|
517 | hwnd = wnd->getOS2WindowHandle();
|
---|
518 | hps = WinGetPS(hwnd);
|
---|
519 |
|
---|
520 | hrgnUpdate = GpiCreateRegion (hps, 1, &rectl);
|
---|
521 | WinQueryUpdateRegion (hwnd, hrgnUpdate);
|
---|
522 | hrgnClip = GpiQueryClipRegion (hps);
|
---|
523 |
|
---|
524 | if (hrgnClip == NULLHANDLE)
|
---|
525 | {
|
---|
526 | GpiSetClipRegion (hps, hrgnUpdate, &hrgnOld);
|
---|
527 | }
|
---|
528 | else
|
---|
529 | {
|
---|
530 | hrgnCombined = GpiCreateRegion (hps, 1, &rectl);
|
---|
531 | GpiCombineRegion (hps, hrgnCombined, hrgnClip, hrgnUpdate, CRGN_AND);
|
---|
532 | GpiSetClipRegion (hps, hrgnCombined, &hrgnOld);
|
---|
533 | GpiDestroyRegion (hps, hrgnUpdate);
|
---|
534 | GpiDestroyRegion (hps, hrgnClip);
|
---|
535 | }
|
---|
536 | if (hrgnOld != NULLHANDLE)
|
---|
537 | GpiDestroyRegion (hps, hrgnOld);
|
---|
538 |
|
---|
539 | hdc = HPSToHDC (hwnd, hps, NULL, NULL);
|
---|
540 |
|
---|
541 | erased = wnd->MsgEraseBackGround (hdc);
|
---|
542 |
|
---|
543 | DeleteHDC (hdc);
|
---|
544 | WinReleasePS (hps);
|
---|
545 |
|
---|
546 | return erased;
|
---|
547 | }
|
---|
548 | //******************************************************************************
|
---|
549 | //******************************************************************************
|
---|
550 | void releaseOwnDC (HDC hps)
|
---|
551 | {
|
---|
552 | pDCData pHps = (pDCData)GpiQueryDCData ((HPS)hps);
|
---|
553 |
|
---|
554 | if (pHps) {
|
---|
555 | if (pHps->hrgnHDC)
|
---|
556 | GpiDestroyRegion (pHps->hps, pHps->hrgnHDC);
|
---|
557 |
|
---|
558 | GpiSetBitmap (pHps->hps, NULL);
|
---|
559 | O32_DeleteObject (pHps->nullBitmapHandle);
|
---|
560 | GpiDestroyPS(pHps->hps);
|
---|
561 |
|
---|
562 | if (pHps->hdc)
|
---|
563 | DevCloseDC(pHps->hdc);
|
---|
564 | }
|
---|
565 | }
|
---|
566 | //******************************************************************************
|
---|
567 | //******************************************************************************
|
---|
568 | HDC WIN32API BeginPaint (HWND hWnd, PPAINTSTRUCT_W lpps)
|
---|
569 | {
|
---|
570 | HWND hwnd = hWnd ? hWnd : HWND_DESKTOP;
|
---|
571 | pDCData pHps = NULLHANDLE;
|
---|
572 | HPS hPS_ownDC = NULLHANDLE, hpsPaint = 0;
|
---|
573 | RECTL rectl = {0, 0, 1, 1};
|
---|
574 | HRGN hrgnUpdate, hrgnOld, hrgnOldClip;
|
---|
575 | LONG lComplexity;
|
---|
576 | RECTL rectlClient;
|
---|
577 | RECTL rectlClip;
|
---|
578 |
|
---|
579 | memset(lpps, 0, sizeof(*lpps));
|
---|
580 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
581 | if(!lpps || !wnd) {
|
---|
582 | dprintf (("USER32: BeginPaint %x invalid parameter %x", hWnd, lpps));
|
---|
583 | SetLastError(ERROR_INVALID_PARAMETER_W);
|
---|
584 | return (HDC)0;
|
---|
585 | }
|
---|
586 | HWND hwndClient = wnd->getOS2WindowHandle();
|
---|
587 |
|
---|
588 | if(hwnd != HWND_DESKTOP && wnd->isOwnDC())
|
---|
589 | {
|
---|
590 | hPS_ownDC = wnd->getOwnDC();
|
---|
591 | //SvL: Hack for memory.exe (doesn't get repainted properly otherwise)
|
---|
592 | if(hPS_ownDC) {
|
---|
593 | pHps = (pDCData)GpiQueryDCData(hPS_ownDC);
|
---|
594 | if (!pHps)
|
---|
595 | {
|
---|
596 | dprintf (("USER32: BeginPaint %x invalid parameter %x", hWnd, lpps));
|
---|
597 | SetLastError(ERROR_INVALID_PARAMETER_W);
|
---|
598 | return (HDC)NULLHANDLE;
|
---|
599 | }
|
---|
600 | hpsPaint = hPS_ownDC;
|
---|
601 | }
|
---|
602 | }
|
---|
603 | if(!hpsPaint) {
|
---|
604 | hpsPaint = GetDCEx(hwnd, 0, (DCX_CACHE_W|DCX_WINDOW_W|DCX_USESTYLE_W));
|
---|
605 | pHps = (pDCData)GpiQueryDCData(hpsPaint);
|
---|
606 | if (!pHps)
|
---|
607 | {
|
---|
608 | dprintf (("USER32: BeginPaint %x invalid parameter %x", hWnd, lpps));
|
---|
609 | SetLastError(ERROR_INVALID_PARAMETER_W);
|
---|
610 | return (HDC)NULLHANDLE;
|
---|
611 | }
|
---|
612 | }
|
---|
613 |
|
---|
614 | if(WinQueryUpdateRect(hwndClient, &rectl) == FALSE) {
|
---|
615 | memset(&rectl, 0, sizeof(rectl));
|
---|
616 | dprintf (("USER32: WARNING: WinQueryUpdateRect failed (error or no update rectangle)!!"));
|
---|
617 |
|
---|
618 | // mapWin32ToOS2Rect(wnd->getWindowHeight(), wnd->getClientRectPtr(), (PRECTLOS2)&rectlClient);
|
---|
619 | // WinOffsetRect(NULL, &rectlClient, -rectlClient.xLeft, -rectlClient.yBottom);
|
---|
620 |
|
---|
621 | hrgnOldClip = selectClientArea(wnd, pHps, &rectl);
|
---|
622 | //save old clip region (restored for CS_OWNDC windows in EndPaint)
|
---|
623 | wnd->SetClipRegion(hrgnOldClip);
|
---|
624 | lComplexity = RGN_NULL;
|
---|
625 | }
|
---|
626 | else {
|
---|
627 | WinValidateRect(hwndClient, &rectl, FALSE);
|
---|
628 |
|
---|
629 | mapWin32ToOS2Rect(wnd->getWindowHeight(), wnd->getClientRectPtr(), (PRECTLOS2)&rectlClient);
|
---|
630 | WinIntersectRect(NULL, &rectlClip, &rectl, &rectlClient);
|
---|
631 | WinOffsetRect(NULL, &rectlClip, -rectlClient.xLeft, -rectlClient.yBottom);
|
---|
632 |
|
---|
633 | hrgnOldClip = selectClientArea(wnd, pHps, &rectlClip);
|
---|
634 |
|
---|
635 | //save old clip region (restored for CS_OWNDC windows in EndPaint)
|
---|
636 | wnd->SetClipRegion(hrgnOldClip);
|
---|
637 | memcpy(&rectl, &rectlClip, sizeof(RECTL));
|
---|
638 | lComplexity = RGN_RECT;
|
---|
639 | }
|
---|
640 |
|
---|
641 | if(hPS_ownDC == 0)
|
---|
642 | setMapMode (wnd, pHps, MM_TEXT_W);
|
---|
643 | else
|
---|
644 | setPageXForm(wnd, pHps);
|
---|
645 |
|
---|
646 | pHps->hdcType = TYPE_3;
|
---|
647 |
|
---|
648 | HideCaret(hwnd);
|
---|
649 | WinShowTrackRect(wnd->getOS2WindowHandle(), FALSE);
|
---|
650 |
|
---|
651 | if(wnd->needsEraseBkgnd() && lComplexity != RGN_NULL) {
|
---|
652 | wnd->setEraseBkgnd(FALSE);
|
---|
653 | lpps->fErase = (wnd->MsgEraseBackGround(pHps->hps) != 0);
|
---|
654 | }
|
---|
655 | else lpps->fErase = TRUE;
|
---|
656 |
|
---|
657 | lpps->hdc = (HDC)pHps->hps;
|
---|
658 |
|
---|
659 | if(lComplexity != RGN_NULL) {
|
---|
660 | long height = wnd->getClientHeight();
|
---|
661 | lpps->rcPaint.top = height - rectl.yTop;
|
---|
662 | lpps->rcPaint.left = rectl.xLeft;
|
---|
663 | lpps->rcPaint.bottom = height - rectl.yBottom;
|
---|
664 | lpps->rcPaint.right = rectl.xRight;
|
---|
665 | }
|
---|
666 | else {
|
---|
667 | lpps->rcPaint.bottom = lpps->rcPaint.top = 0;
|
---|
668 | lpps->rcPaint.right = lpps->rcPaint.left = 0;
|
---|
669 | }
|
---|
670 |
|
---|
671 | SetLastError(0);
|
---|
672 | dprintf(("USER32: BeginPaint %x -> hdc %x (%d,%d)(%d,%d)", hWnd, pHps->hps, lpps->rcPaint.left, lpps->rcPaint.top, lpps->rcPaint.right, lpps->rcPaint.bottom));
|
---|
673 | return (HDC)pHps->hps;
|
---|
674 | }
|
---|
675 | //******************************************************************************
|
---|
676 | //******************************************************************************
|
---|
677 | BOOL WIN32API EndPaint (HWND hWnd, const PAINTSTRUCT_W *pPaint)
|
---|
678 | {
|
---|
679 | HWND hwnd = hWnd ? hWnd : HWND_DESKTOP;
|
---|
680 | HRGN hrgnOld;
|
---|
681 | pDCData pHps;
|
---|
682 |
|
---|
683 | dprintf (("USER32: EndPaint(%x)", hwnd));
|
---|
684 |
|
---|
685 | if (!pPaint || !pPaint->hdc )
|
---|
686 | return TRUE;
|
---|
687 |
|
---|
688 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
689 |
|
---|
690 | if (!wnd) goto exit;
|
---|
691 |
|
---|
692 | pHps = (pDCData)GpiQueryDCData((HPS)pPaint->hdc);
|
---|
693 | if (pHps && (pHps->hdcType == TYPE_3))
|
---|
694 | {
|
---|
695 | GpiSetClipRegion(pHps->hps, wnd->GetClipRegion(), &hrgnOld);
|
---|
696 | wnd->SetClipRegion(0);
|
---|
697 | if(hrgnOld) {
|
---|
698 | GpiDestroyRegion(pHps->hps, hrgnOld);
|
---|
699 | }
|
---|
700 | pHps->hdcType = TYPE_1; //otherwise Open32's ReleaseDC fails
|
---|
701 | ReleaseDC(hwnd, pPaint->hdc);
|
---|
702 | }
|
---|
703 | else {
|
---|
704 | dprintf(("EndPaint: wrong hdc %x!!", pPaint->hdc));
|
---|
705 | }
|
---|
706 | wnd->setEraseBkgnd(TRUE);
|
---|
707 | ShowCaret(hwnd);
|
---|
708 | WinShowTrackRect(wnd->getOS2WindowHandle(), TRUE);
|
---|
709 |
|
---|
710 | exit:
|
---|
711 | SetLastError(0);
|
---|
712 | return TRUE;
|
---|
713 | }
|
---|
714 | //******************************************************************************
|
---|
715 | //******************************************************************************
|
---|
716 | int WIN32API ReleaseDC (HWND hwnd, HDC hdc)
|
---|
717 | {
|
---|
718 | BOOL isOwnDC = FALSE;
|
---|
719 | int rc;
|
---|
720 |
|
---|
721 | if (hwnd)
|
---|
722 | {
|
---|
723 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
|
---|
724 | if(wnd == NULL) {
|
---|
725 | dprintf(("ERROR: ReleaseDC %x %x failed", hwnd, hdc));
|
---|
726 | return 0;
|
---|
727 | }
|
---|
728 | isOwnDC = wnd->isOwnDC() && (wnd->getOwnDC() == hdc);
|
---|
729 | if(!isOwnDC)
|
---|
730 | {
|
---|
731 | pDCData pHps = (pDCData)GpiQueryDCData((HPS)hdc);
|
---|
732 | if(pHps && pHps->psType == MICRO_CACHED) {
|
---|
733 | removeClientArea(pHps);
|
---|
734 | if(pHps->hrgnVis) {
|
---|
735 | GreDestroyRegion(pHps->hps, pHps->hrgnVis);
|
---|
736 | pHps->hrgnVis = 0;
|
---|
737 | }
|
---|
738 | }
|
---|
739 | else {
|
---|
740 | dprintf(("ERROR: ReleaseDC: pHps == NULL!!"));
|
---|
741 | DebugInt3();
|
---|
742 | }
|
---|
743 | }
|
---|
744 | }
|
---|
745 |
|
---|
746 | if(isOwnDC) {
|
---|
747 | rc = TRUE;
|
---|
748 | }
|
---|
749 | else {
|
---|
750 | rc = O32_ReleaseDC (0, hdc);
|
---|
751 | }
|
---|
752 |
|
---|
753 | dprintf(("ReleaseDC %x %x", hwnd, hdc));
|
---|
754 | return (rc);
|
---|
755 | }
|
---|
756 | //******************************************************************************
|
---|
757 | // This implementation of GetDCEx supports
|
---|
758 | // DCX_WINDOW
|
---|
759 | // DCX_CACHE
|
---|
760 | // DCX_EXCLUDERGN (complex regions allowed)
|
---|
761 | // DCX_INTERSECTRGN (complex regions allowed)
|
---|
762 | // DCX_USESTYLE
|
---|
763 | // DCX_CLIPSIBLINGS
|
---|
764 | // DCX_CLIPCHILDREN
|
---|
765 | // DCX_PARENTCLIP
|
---|
766 | //
|
---|
767 | //TODO: WM_SETREDRAW affects drawingAllowed flag!!
|
---|
768 | //******************************************************************************
|
---|
769 | HDC WIN32API GetDCEx (HWND hwnd, HRGN hrgn, ULONG flags)
|
---|
770 | {
|
---|
771 | Win32BaseWindow *wnd = NULL;
|
---|
772 | HWND hWindow;
|
---|
773 | BOOL success;
|
---|
774 | pDCData pHps = NULL;
|
---|
775 | HPS hps = NULLHANDLE;
|
---|
776 | BOOL drawingAllowed = TRUE;
|
---|
777 | BOOL isWindowOwnDC;
|
---|
778 | BOOL creatingOwnDC = FALSE;
|
---|
779 | PS_Type psType;
|
---|
780 |
|
---|
781 | if(hwnd == 0) {
|
---|
782 | dprintf(("error: GetDCEx window %x not found", hwnd));
|
---|
783 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
|
---|
784 | return 0;
|
---|
785 | }
|
---|
786 |
|
---|
787 | if (hwnd)
|
---|
788 | {
|
---|
789 | wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
790 | if(wnd == NULL) {
|
---|
791 | dprintf (("ERROR: User32: GetDCEx bad window handle %X!!!!!", hwnd));
|
---|
792 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
|
---|
793 | return 0;
|
---|
794 | }
|
---|
795 | hWindow = wnd->getOS2WindowHandle();
|
---|
796 | }
|
---|
797 |
|
---|
798 | isWindowOwnDC = (((hWindow == HWND_DESKTOP) ? FALSE : (wnd->isOwnDC()))
|
---|
799 | && !(flags & (DCX_CACHE_W|DCX_WINDOW_W)));
|
---|
800 |
|
---|
801 | if(isWindowOwnDC) //own dc always for client area
|
---|
802 | {
|
---|
803 | hps = wnd->getOwnDC();
|
---|
804 | if (hps)
|
---|
805 | {
|
---|
806 | pDCData pHps = (pDCData)GpiQueryDCData (hps);
|
---|
807 | if (!pHps)
|
---|
808 | goto error;
|
---|
809 |
|
---|
810 | selectClientArea(wnd, pHps, NULL);
|
---|
811 |
|
---|
812 | //TODO: Is this always necessary??
|
---|
813 | setPageXForm (wnd, pHps);
|
---|
814 | pHps->hdcType = TYPE_1;
|
---|
815 |
|
---|
816 | //TODO: intersect/exclude clip region?
|
---|
817 | dprintf (("User32: GetDCEx hwnd %x (%x %x) -> wnd %x hdc %x", hwnd, hrgn, flags, wnd, hps));
|
---|
818 | return (HDC)hps;
|
---|
819 | }
|
---|
820 | else
|
---|
821 | creatingOwnDC = TRUE;
|
---|
822 | }
|
---|
823 |
|
---|
824 | if(isWindowOwnDC)
|
---|
825 | {
|
---|
826 | SIZEL sizel = {0,0};
|
---|
827 | hps = GpiCreatePS (WinQueryAnchorBlock (hWindow),
|
---|
828 | WinOpenWindowDC (hWindow),
|
---|
829 | &sizel, PU_PELS | GPIT_MICRO | GPIA_ASSOC );
|
---|
830 | psType = MICRO;
|
---|
831 | }
|
---|
832 | else
|
---|
833 | {
|
---|
834 | if (hWindow == HWND_DESKTOP) {
|
---|
835 | hps = WinGetScreenPS (hWindow);
|
---|
836 | }
|
---|
837 | else {
|
---|
838 | int clipstyle = 0;
|
---|
839 | int clipwnd = HWND_TOP;
|
---|
840 | if(flags & (DCX_USESTYLE_W)) {
|
---|
841 | int style = wnd->getStyle();
|
---|
842 | if(style & WS_CLIPCHILDREN_W) {
|
---|
843 | clipstyle |= PSF_CLIPCHILDREN;
|
---|
844 | }
|
---|
845 | if(style & WS_CLIPSIBLINGS_W) {
|
---|
846 | clipstyle |= PSF_CLIPSIBLINGS;
|
---|
847 | }
|
---|
848 | if(wnd->fHasParentDC()) {
|
---|
849 | clipstyle |= PSF_PARENTCLIP;
|
---|
850 | }
|
---|
851 | }
|
---|
852 | if(flags & DCX_CLIPSIBLINGS_W) {
|
---|
853 | clipstyle |= PSF_CLIPSIBLINGS;
|
---|
854 | }
|
---|
855 | if(flags & DCX_CLIPCHILDREN_W) {
|
---|
856 | clipstyle |= PSF_CLIPCHILDREN;
|
---|
857 | }
|
---|
858 | if(flags & DCX_PARENTCLIP_W) {
|
---|
859 | clipstyle |= PSF_PARENTCLIP;
|
---|
860 | }
|
---|
861 | if(clipstyle) {
|
---|
862 | dprintf2(("WinGetClipPS style %x", clipstyle));
|
---|
863 | hps = WinGetClipPS(hWindow, clipwnd, clipstyle);
|
---|
864 | }
|
---|
865 | else hps = WinGetPS (hWindow);
|
---|
866 | }
|
---|
867 | psType = MICRO_CACHED;
|
---|
868 | }
|
---|
869 |
|
---|
870 | if (!hps)
|
---|
871 | goto error;
|
---|
872 |
|
---|
873 | HPSToHDC (hWindow, hps, NULL, NULL);
|
---|
874 | pHps = (pDCData)GpiQueryDCData (hps);
|
---|
875 |
|
---|
876 | if(!(flags & DCX_WINDOW_W))
|
---|
877 | {
|
---|
878 | selectClientArea(wnd, pHps, NULL);
|
---|
879 | }
|
---|
880 | else removeClientArea(pHps);
|
---|
881 |
|
---|
882 | setMapMode(wnd, pHps, MM_TEXT_W);
|
---|
883 |
|
---|
884 | if ((flags & DCX_EXCLUDERGN_W) || (flags & DCX_INTERSECTRGN_W))
|
---|
885 | {
|
---|
886 | ULONG BytesNeeded;
|
---|
887 | PRGNDATA RgnData;
|
---|
888 | PRECT pr;
|
---|
889 | int i;
|
---|
890 | RECTL rectl;
|
---|
891 |
|
---|
892 | if (!hrgn)
|
---|
893 | goto error;
|
---|
894 |
|
---|
895 | success = TRUE;
|
---|
896 | if (flags & DCX_EXCLUDERGN_W)
|
---|
897 | {
|
---|
898 | #if 0 //CB: todo
|
---|
899 | long height;
|
---|
900 |
|
---|
901 | BytesNeeded = GetRegionData (hrgn, 0, NULL);
|
---|
902 | RgnData = (PRGNDATA_W)_alloca (BytesNeeded);
|
---|
903 | if (RgnData == NULL)
|
---|
904 | goto error;
|
---|
905 | GetRegionData (hrgn, BytesNeeded, RgnData);
|
---|
906 |
|
---|
907 | i = RgnData->rdh.nCount;
|
---|
908 | pr = (PRECT)(RgnData->Buffer);
|
---|
909 |
|
---|
910 | if (flags & DCX_WINDOW_W)
|
---|
911 | height = wnd->getWindowHeight();
|
---|
912 | else height = wnd->getClientHeight();
|
---|
913 |
|
---|
914 | for (; (i > 0) && success; i--, pr++) {
|
---|
915 | LONG y = pr->yBottom;
|
---|
916 |
|
---|
917 | pr->yBottom = height - pr->yTop;
|
---|
918 | pr->yTop = height - y;
|
---|
919 | success &= GpiExcludeClipRectangle (pHps->hps, pr);
|
---|
920 | }
|
---|
921 | #endif
|
---|
922 | }
|
---|
923 | else //DCX_INTERSECTRGN_W
|
---|
924 | {
|
---|
925 | //SvL: I'm getting paint problems when clipping a dc created in GetDCEx
|
---|
926 | // with a region that covers the entire window (RealPlayer 7 Update 1)
|
---|
927 | // Using SelectClipRgn here doesn't make any difference.
|
---|
928 | if(ExtSelectClipRgn(pHps->hps, hrgn, RGN_AND_W) == ERROR_W) {
|
---|
929 | dprintf(("ExtSelectClipRgn failed!!"));
|
---|
930 | }
|
---|
931 | }
|
---|
932 | if (!success)
|
---|
933 | goto error;
|
---|
934 | }
|
---|
935 |
|
---|
936 | if (creatingOwnDC)
|
---|
937 | wnd->setOwnDC ((HDC)hps);
|
---|
938 |
|
---|
939 | pHps->psType = psType;
|
---|
940 | pHps->hdcType = TYPE_1;
|
---|
941 | //TODO: WM_SETREDRAW affects drawingAllowed flag!!
|
---|
942 | GpiSetDrawControl (hps, DCTL_DISPLAY, drawingAllowed ? DCTL_ON : DCTL_OFF);
|
---|
943 |
|
---|
944 | dprintf (("User32: GetDCEx hwnd %x (%x %x) -> hdc %x", hwnd, hrgn, flags, pHps->hps));
|
---|
945 | return (HDC)pHps->hps;
|
---|
946 |
|
---|
947 | error:
|
---|
948 | /* Something went wrong; clean up
|
---|
949 | */
|
---|
950 | dprintf(("ERROR: GetDCEx hwnd %x (%x %x) FAILED!", hwnd, hrgn, flags));
|
---|
951 | DebugInt3();
|
---|
952 | if (pHps)
|
---|
953 | {
|
---|
954 | if (pHps->hps)
|
---|
955 | {
|
---|
956 | if(pHps->psType == MICRO_CACHED)
|
---|
957 | WinReleasePS(pHps->hps);
|
---|
958 | else
|
---|
959 | GpiDestroyPS(pHps->hps);
|
---|
960 | }
|
---|
961 |
|
---|
962 | if (pHps->hdc) DevCloseDC(pHps->hdc);
|
---|
963 | if (pHps->hrgnHDC) GpiDestroyRegion(pHps->hps, pHps->hrgnHDC);
|
---|
964 |
|
---|
965 | O32_DeleteObject (pHps->nullBitmapHandle);
|
---|
966 | }
|
---|
967 | SetLastError(ERROR_INVALID_PARAMETER_W);
|
---|
968 | return NULL;
|
---|
969 | }
|
---|
970 | //******************************************************************************
|
---|
971 | //******************************************************************************
|
---|
972 | HDC WIN32API GetDC (HWND hwnd)
|
---|
973 | {
|
---|
974 | if(!hwnd)
|
---|
975 | return GetDCEx( GetDesktopWindow(), 0, DCX_CACHE_W | DCX_WINDOW_W );
|
---|
976 | return GetDCEx (hwnd, NULL, 0);
|
---|
977 | }
|
---|
978 | //******************************************************************************
|
---|
979 | //******************************************************************************
|
---|
980 | HDC WIN32API GetWindowDC (HWND hwnd)
|
---|
981 | {
|
---|
982 | if (!hwnd) hwnd = GetDesktopWindow();
|
---|
983 | return GetDCEx (hwnd, NULL, DCX_WINDOW_W);
|
---|
984 | }
|
---|
985 | //******************************************************************************
|
---|
986 | //Helper for RedrawWindow (RDW_ALLCHILDREN_W)
|
---|
987 | //******************************************************************************
|
---|
988 | LRESULT WIN32API RedrawChildEnumProc(HWND hwnd, LPARAM lParam)
|
---|
989 | {
|
---|
990 | RedrawWindow(hwnd, NULL, 0, lParam);
|
---|
991 | return TRUE;
|
---|
992 | }
|
---|
993 | //******************************************************************************
|
---|
994 | // This implementation of RedrawWindow supports
|
---|
995 | // RDW_ERASE
|
---|
996 | // RDW_NOERASE
|
---|
997 | // RDW_INTERNALPAINT
|
---|
998 | // RDW_NOINTERNALPAINT
|
---|
999 | // RDW_INVALIDATE
|
---|
1000 | // RDW_VALIDATE
|
---|
1001 | // RDW_ERASENOW
|
---|
1002 | // RDW_UPDATENOW
|
---|
1003 | // RDW_FRAME
|
---|
1004 | //
|
---|
1005 | //TODO: Work ok for RDW_FRAME??
|
---|
1006 | //******************************************************************************
|
---|
1007 | BOOL WIN32API RedrawWindow(HWND hwnd, const RECT* pRect, HRGN hrgn, DWORD redraw)
|
---|
1008 | {
|
---|
1009 | Win32BaseWindow *wnd;
|
---|
1010 |
|
---|
1011 | if(pRect) {
|
---|
1012 | dprintf(("RedrawWindow %x (%d,%d)(%d,%d) %x %x", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom, hrgn, redraw));
|
---|
1013 | }
|
---|
1014 | else dprintf(("RedrawWindow %x %x %x %x", hwnd, pRect, hrgn, redraw));
|
---|
1015 |
|
---|
1016 | if (hwnd == NULLHANDLE)
|
---|
1017 | {
|
---|
1018 | #if 1
|
---|
1019 | // Don't do this for now (causes lots of desktop repaints in WordPad)
|
---|
1020 | SetLastError(ERROR_INVALID_PARAMETER_W);
|
---|
1021 | return FALSE;
|
---|
1022 | #else
|
---|
1023 | hwnd = HWND_DESKTOP;
|
---|
1024 | wnd = Win32BaseWindow::GetWindowFromOS2Handle(OSLIB_HWND_DESKTOP);
|
---|
1025 |
|
---|
1026 | if (!wnd)
|
---|
1027 | {
|
---|
1028 | dprintf(("USER32:dc: RedrawWindow can't find desktop window %08xh\n",
|
---|
1029 | hwnd));
|
---|
1030 | SetLastError(ERROR_INVALID_PARAMETER_W);
|
---|
1031 | return FALSE;
|
---|
1032 | }
|
---|
1033 | #endif
|
---|
1034 | }
|
---|
1035 | else
|
---|
1036 | {
|
---|
1037 | wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
|
---|
1038 |
|
---|
1039 | if (!wnd)
|
---|
1040 | {
|
---|
1041 | dprintf(("USER32:dc: RedrawWindow can't find window %08xh\n",
|
---|
1042 | hwnd));
|
---|
1043 | SetLastError(ERROR_INVALID_PARAMETER_W);
|
---|
1044 | return FALSE;
|
---|
1045 | }
|
---|
1046 | hwnd = wnd->getOS2WindowHandle();
|
---|
1047 | }
|
---|
1048 |
|
---|
1049 | BOOL IncludeChildren = (redraw & RDW_ALLCHILDREN_W) ? TRUE : FALSE;
|
---|
1050 | BOOL success = TRUE;
|
---|
1051 | HPS hpsTemp = NULLHANDLE;
|
---|
1052 | HRGN hrgnTemp = NULLHANDLE;
|
---|
1053 | RECTL rectl;
|
---|
1054 |
|
---|
1055 | if (hrgn)
|
---|
1056 | {
|
---|
1057 | ULONG BytesNeeded;
|
---|
1058 | PRGNDATA RgnData;
|
---|
1059 | PRECTL pr;
|
---|
1060 | int i;
|
---|
1061 | LONG height;
|
---|
1062 |
|
---|
1063 | if(wnd) {
|
---|
1064 | height = (redraw & RDW_FRAME_W) ? wnd->getWindowHeight() : wnd->getClientHeight();
|
---|
1065 | }
|
---|
1066 | else height = OSLibQueryScreenHeight();
|
---|
1067 |
|
---|
1068 | if (!hrgn)
|
---|
1069 | goto error;
|
---|
1070 |
|
---|
1071 | BytesNeeded = GetRegionData (hrgn, 0, NULL);
|
---|
1072 | RgnData = (PRGNDATA)_alloca (BytesNeeded);
|
---|
1073 | if (RgnData == NULL)
|
---|
1074 | goto error;
|
---|
1075 | GetRegionData (hrgn, BytesNeeded, RgnData);
|
---|
1076 |
|
---|
1077 | pr = (PRECTL)(RgnData->Buffer);
|
---|
1078 | for (i = RgnData->rdh.nCount; i > 0; i--, pr++) {
|
---|
1079 | LONG temp = pr->yTop;
|
---|
1080 | pr->yTop = height - pr->yBottom;
|
---|
1081 | pr->yBottom = height - temp;
|
---|
1082 | }
|
---|
1083 |
|
---|
1084 | hpsTemp = WinGetScreenPS (HWND_DESKTOP);
|
---|
1085 | hrgnTemp = GpiCreateRegion (hpsTemp, RgnData->rdh.nCount, (PRECTL)(RgnData->Buffer));
|
---|
1086 | if (!hrgnTemp) goto error;
|
---|
1087 | }
|
---|
1088 | else if (pRect)
|
---|
1089 | {
|
---|
1090 | if(wnd) {
|
---|
1091 | if(redraw & RDW_FRAME_W) {
|
---|
1092 | mapWin32ToOS2Rect(wnd->getWindowHeight(), (PRECT)pRect, (PRECTLOS2)&rectl);
|
---|
1093 | }
|
---|
1094 | else mapWin32ToOS2RectClientToFrame(wnd, (PRECT)pRect, (PRECTLOS2)&rectl);
|
---|
1095 | }
|
---|
1096 | else mapWin32ToOS2Rect(OSLibQueryScreenHeight(), (PRECT)pRect, (PRECTLOS2)&rectl);
|
---|
1097 | }
|
---|
1098 |
|
---|
1099 | if (redraw & RDW_INVALIDATE_W)
|
---|
1100 | {
|
---|
1101 | //TODO: SvL: pingpong.exe doesn't have RDW_NOERASE, but doesn't want WM_ERASEBKGND msgs
|
---|
1102 | if (redraw & RDW_ERASE_W) {
|
---|
1103 | wnd->setEraseBkgnd(TRUE);
|
---|
1104 | }
|
---|
1105 | else
|
---|
1106 | if (redraw & RDW_NOERASE_W)
|
---|
1107 | wnd->setEraseBkgnd(FALSE);
|
---|
1108 |
|
---|
1109 | if (!pRect && !hrgn)
|
---|
1110 | success = WinInvalidateRect (hwnd, NULL, IncludeChildren);
|
---|
1111 | else
|
---|
1112 | if (hrgn) {
|
---|
1113 | success = WinInvalidateRegion (hwnd, hrgnTemp, IncludeChildren);
|
---|
1114 | if(IncludeChildren && WinQueryUpdateRect(hwnd, NULL) == FALSE) {
|
---|
1115 | dprintf(("WARNING: WinQueryUpdateRect %x region %x returned false even though we just invalidated part of a window!!!", hwnd, hrgnTemp));
|
---|
1116 | success = success = WinInvalidateRegion (hwnd, hrgnTemp, FALSE);
|
---|
1117 | }
|
---|
1118 | }
|
---|
1119 | else {
|
---|
1120 | success = WinInvalidateRect (hwnd, &rectl, IncludeChildren);
|
---|
1121 | //SvL: If all children are included, then WinInvalidateRect is called
|
---|
1122 | // with fIncludeChildren=1 -> rect of hwnd isn't invalidated if child(ren)
|
---|
1123 | // overlap(s) the specified rectangle completely (EVEN if window doesn't
|
---|
1124 | // have WS_CLIPCHILREN!)
|
---|
1125 | // -> example: XWing vs Tie Fighter install window
|
---|
1126 | // WinInvalidateRect with fIncludeChildren=0 invalidates both the parent
|
---|
1127 | // and child windows
|
---|
1128 | //SvL: Can't always set fIncludeChildren to FALSE or else some controls in
|
---|
1129 | // the RealPlayer setup application aren't redrawn when invalidating
|
---|
1130 | // their parent
|
---|
1131 | // SO: Check if IncludeChildren is set and part of the window is invalid
|
---|
1132 | // If not -> call WinInvalidateRect with IncludeChildren=0 to force
|
---|
1133 | // the window rectangle to be invalidated
|
---|
1134 | //
|
---|
1135 | if(IncludeChildren && WinQueryUpdateRect(hwnd, NULL) == FALSE) {
|
---|
1136 | dprintf(("WARNING: WinQueryUpdateRect %x (%d,%d)(%d,%d) returned false even though we just invalidated part of a window!!!", hwnd, rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop));
|
---|
1137 | success = WinInvalidateRect (hwnd, &rectl, FALSE);
|
---|
1138 | }
|
---|
1139 | }
|
---|
1140 |
|
---|
1141 | if (!success) goto error;
|
---|
1142 | }
|
---|
1143 | else if (redraw & RDW_VALIDATE_W)
|
---|
1144 | {
|
---|
1145 | if (redraw & RDW_NOERASE_W)
|
---|
1146 | wnd->setEraseBkgnd(FALSE);
|
---|
1147 |
|
---|
1148 | if (WinQueryUpdateRect (hwnd, NULL))
|
---|
1149 | {
|
---|
1150 | if(!pRect && !hrgn) {
|
---|
1151 | success = WinValidateRect (hwnd, NULL, IncludeChildren);
|
---|
1152 | }
|
---|
1153 | else
|
---|
1154 | if(hrgn) {
|
---|
1155 | success = WinValidateRegion (hwnd, hrgnTemp, IncludeChildren);
|
---|
1156 | }
|
---|
1157 | else {
|
---|
1158 | success = WinValidateRect (hwnd, &rectl, IncludeChildren);
|
---|
1159 | }
|
---|
1160 | if(!success) goto error;
|
---|
1161 | }
|
---|
1162 | }
|
---|
1163 |
|
---|
1164 | if(WinQueryUpdateRect(hwnd, NULL))
|
---|
1165 | {
|
---|
1166 | //TODO: Does this work if RDW_ALLCHILDREN is set??
|
---|
1167 | if(redraw & RDW_UPDATENOW_W) {
|
---|
1168 | wnd->MsgNCPaint();
|
---|
1169 | wnd->MsgPaint(0, FALSE);
|
---|
1170 | }
|
---|
1171 | else
|
---|
1172 | // if((redraw & RDW_ERASE_W) && (redraw & RDW_ERASENOW_W))
|
---|
1173 | if(redraw & RDW_ERASENOW_W && wnd->needsEraseBkgnd())
|
---|
1174 | wnd->setEraseBkgnd(sendEraseBkgnd(wnd) == 0);
|
---|
1175 | if(redraw & RDW_ALLCHILDREN_W) {
|
---|
1176 | EnumChildWindows(wnd->getWindowHandle(), RedrawChildEnumProc, redraw);
|
---|
1177 | }
|
---|
1178 | }
|
---|
1179 | else if((redraw & RDW_INTERNALPAINT_W) && !(redraw & RDW_INVALIDATE_W))
|
---|
1180 | {
|
---|
1181 | if(redraw & RDW_UPDATENOW_W) {
|
---|
1182 | wnd->MsgNCPaint();
|
---|
1183 | wnd->MsgPaint (0, FALSE);
|
---|
1184 | }
|
---|
1185 | else PostMessageA(hwnd, WINWM_PAINT, 0, 0);
|
---|
1186 | }
|
---|
1187 |
|
---|
1188 | error:
|
---|
1189 | /* clean up */
|
---|
1190 | if (hrgnTemp)
|
---|
1191 | GpiDestroyRegion (hpsTemp, hrgnTemp);
|
---|
1192 |
|
---|
1193 | if (hpsTemp)
|
---|
1194 | WinReleasePS (hpsTemp);
|
---|
1195 |
|
---|
1196 | if (!success) {
|
---|
1197 | dprintf(("RedrawWindow failure!"));
|
---|
1198 | SetLastError(ERROR_INVALID_PARAMETER_W);
|
---|
1199 | }
|
---|
1200 | return (success);
|
---|
1201 | }
|
---|
1202 | //******************************************************************************
|
---|
1203 | //******************************************************************************
|
---|
1204 | BOOL WIN32API UpdateWindow (HWND hwnd)
|
---|
1205 | {
|
---|
1206 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
|
---|
1207 |
|
---|
1208 | if(!wnd) {
|
---|
1209 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
|
---|
1210 | return FALSE;
|
---|
1211 | }
|
---|
1212 |
|
---|
1213 | dprintf (("User32: UpdateWindow hwnd %x", hwnd));
|
---|
1214 | //SvL: This doesn't work right (Wine uses RDW_NOCHILDREN_W -> doesn't work here)
|
---|
1215 | // Breaks vpbuddy
|
---|
1216 | // return RedrawWindow(hwnd, NULL, 0, RDW_UPDATENOW_W | RDW_ALLCHILDREN_W);
|
---|
1217 | // -> RDW_UPDATENOW causes WM_PAINT messages to be directy posted to window
|
---|
1218 | // handler; possibly bypassing queued WM_PAINT messages for parent window(s)
|
---|
1219 | // -> out of sync painting (i.e. parent paints over child)
|
---|
1220 | WinUpdateWindow(wnd->getOS2WindowHandle());
|
---|
1221 | return TRUE;
|
---|
1222 | }
|
---|
1223 | //******************************************************************************
|
---|
1224 | //******************************************************************************
|
---|
1225 | BOOL WIN32API ValidateRect( HWND hwnd, const RECT * lprc)
|
---|
1226 | {
|
---|
1227 | if(lprc) {
|
---|
1228 | dprintf(("USER32: ValidateRect %x (%d,%d)(%d,%d)", hwnd, lprc->left, lprc->top, lprc->right, lprc->bottom));
|
---|
1229 | }
|
---|
1230 | else dprintf(("USER32: ValidateRect %x", hwnd));
|
---|
1231 |
|
---|
1232 | return RedrawWindow( hwnd, lprc, 0, RDW_VALIDATE_W | RDW_NOCHILDREN_W | (hwnd==0 ? RDW_UPDATENOW_W : 0));
|
---|
1233 | }
|
---|
1234 | //******************************************************************************
|
---|
1235 | //******************************************************************************
|
---|
1236 | BOOL WIN32API ValidateRgn( HWND hwnd, HRGN hrgn)
|
---|
1237 | {
|
---|
1238 | dprintf(("USER32: ValidateRgn %x %x", hwnd, hrgn));
|
---|
1239 | return RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE_W | RDW_NOCHILDREN_W | (hwnd==0 ? RDW_UPDATENOW_W : 0));
|
---|
1240 | }
|
---|
1241 | //******************************************************************************
|
---|
1242 | //******************************************************************************
|
---|
1243 | BOOL WIN32API InvalidateRect (HWND hwnd, const RECT *pRect, BOOL erase)
|
---|
1244 | {
|
---|
1245 | BOOL result;
|
---|
1246 |
|
---|
1247 | if(pRect) {
|
---|
1248 | dprintf(("InvalidateRect %x (%d,%d)(%d,%d) erase=%d", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom, erase));
|
---|
1249 | }
|
---|
1250 | else dprintf(("InvalidateRect %x NULL erase=%d", hwnd, erase));
|
---|
1251 | result = RedrawWindow (hwnd, pRect, NULLHANDLE,
|
---|
1252 | RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
|
---|
1253 | (erase ? RDW_ERASE_W : RDW_NOERASE_W) |
|
---|
1254 | (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
|
---|
1255 | return (result);
|
---|
1256 | }
|
---|
1257 | //******************************************************************************
|
---|
1258 | //******************************************************************************
|
---|
1259 | BOOL WIN32API InvalidateRgn (HWND hwnd, HRGN hrgn, BOOL erase)
|
---|
1260 | {
|
---|
1261 | BOOL result;
|
---|
1262 |
|
---|
1263 | dprintf(("InvalidateRgn %x %x erase=%d", hwnd, hrgn, erase));
|
---|
1264 | result = RedrawWindow (hwnd, NULL, hrgn,
|
---|
1265 | RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
|
---|
1266 | (erase ? RDW_ERASE_W : RDW_NOERASE_W) |
|
---|
1267 | (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
|
---|
1268 | return (result);
|
---|
1269 | }
|
---|
1270 | //******************************************************************************
|
---|
1271 | //TODO: Change for client rectangle!!!!!
|
---|
1272 | //******************************************************************************
|
---|
1273 | BOOL setPMRgnIntoWinRgn (HRGN hrgnPM, HRGN hrgnWin, LONG height)
|
---|
1274 | {
|
---|
1275 | BOOL rc;
|
---|
1276 | HPS hps = WinGetScreenPS (HWND_DESKTOP);
|
---|
1277 | RGNRECT rgnRect;
|
---|
1278 | rgnRect.ircStart = 1;
|
---|
1279 | rgnRect.crc = 0;
|
---|
1280 | rgnRect.ulDirection = RECTDIR_LFRT_TOPBOT; // doesn't make a difference because we're getting them all
|
---|
1281 |
|
---|
1282 | rc = GpiQueryRegionRects (hps, hrgnPM, NULL, &rgnRect, NULL);
|
---|
1283 |
|
---|
1284 | if (rc && (rgnRect.crcReturned > 0))
|
---|
1285 | {
|
---|
1286 | PRECTL Rcls = new RECTL[rgnRect.crcReturned];
|
---|
1287 | PRECTL pRcl = Rcls;
|
---|
1288 |
|
---|
1289 | if (Rcls != NULL)
|
---|
1290 | {
|
---|
1291 | rgnRect.crc = rgnRect.crcReturned;
|
---|
1292 | rc = GpiQueryRegionRects (hps, hrgnPM, NULL, &rgnRect, Rcls);
|
---|
1293 |
|
---|
1294 | rc = SetRectRgn(hrgnWin, pRcl->xLeft,
|
---|
1295 | pRcl->xRight,
|
---|
1296 | height - pRcl->yTop,
|
---|
1297 | height - pRcl->yBottom);
|
---|
1298 |
|
---|
1299 | if (rgnRect.crcReturned > 1)
|
---|
1300 | {
|
---|
1301 | int i;
|
---|
1302 | HRGN temp;
|
---|
1303 | temp = CreateRectRgn (0, 0, 1, 1);
|
---|
1304 |
|
---|
1305 | for (i = 1, pRcl++; rc && (i < rgnRect.crcReturned); i++, pRcl++)
|
---|
1306 | {
|
---|
1307 | rc = SetRectRgn (temp, pRcl->xLeft,
|
---|
1308 | pRcl->xRight,
|
---|
1309 | height - pRcl->yTop,
|
---|
1310 | height - pRcl->yBottom);
|
---|
1311 | rc &= CombineRgn (hrgnWin, hrgnWin, temp, RGN_OR_W);
|
---|
1312 | }
|
---|
1313 | DeleteObject (temp);
|
---|
1314 | }
|
---|
1315 | delete[] Rcls;
|
---|
1316 | }
|
---|
1317 | else
|
---|
1318 | {
|
---|
1319 | rc = FALSE;
|
---|
1320 | }
|
---|
1321 | }
|
---|
1322 | else
|
---|
1323 | {
|
---|
1324 | rc = SetRectRgn (hrgnWin, 0, 0, 0, 0);
|
---|
1325 | }
|
---|
1326 |
|
---|
1327 | WinReleasePS (hps);
|
---|
1328 | return (rc);
|
---|
1329 | }
|
---|
1330 | //******************************************************************************
|
---|
1331 | //TODO: Check if this one works correctly...
|
---|
1332 | //Have to check if dc is for frame or client!!
|
---|
1333 | //******************************************************************************
|
---|
1334 | BOOL WIN32API ScrollDC(HDC hDC, int dx, int dy, const RECT *pScroll,
|
---|
1335 | const RECT *pClip, HRGN hrgnUpdate, LPRECT pRectUpdate)
|
---|
1336 | {
|
---|
1337 | BOOL rc = TRUE;
|
---|
1338 |
|
---|
1339 | dprintf (("USER32: ScrollDC %x (%d,%d), %x %x %x %x", hDC, dx, dy, pScroll, pClip, hrgnUpdate, pRectUpdate));
|
---|
1340 |
|
---|
1341 | if (!hDC)
|
---|
1342 | {
|
---|
1343 | return (FALSE);
|
---|
1344 | }
|
---|
1345 |
|
---|
1346 | pDCData pHps = (pDCData)GpiQueryDCData ((HPS)hDC);
|
---|
1347 | HWND hwnd = pHps->hwnd;
|
---|
1348 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
|
---|
1349 |
|
---|
1350 | if ((hwnd == NULLHANDLE) || !wnd)
|
---|
1351 | {
|
---|
1352 | return (FALSE);
|
---|
1353 | }
|
---|
1354 |
|
---|
1355 | POINTL ptl[2] = { 0, 0, dx, dy };
|
---|
1356 |
|
---|
1357 | GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, ptl);
|
---|
1358 | dx = (int)(ptl[1].x - ptl[0].x);
|
---|
1359 | dy = (int)(ptl[1].y - ptl[0].y);
|
---|
1360 |
|
---|
1361 | RECT scrollRect;
|
---|
1362 | RECT clipRect;
|
---|
1363 |
|
---|
1364 | if (pClip)
|
---|
1365 | {
|
---|
1366 | memcpy(&clipRect, pClip, sizeof(clipRect));
|
---|
1367 |
|
---|
1368 | if ((pHps->graphicsMode == GM_COMPATIBLE_W) &&
|
---|
1369 | (clipRect.left != clipRect.right) &&
|
---|
1370 | (clipRect.bottom != clipRect.top))
|
---|
1371 | {
|
---|
1372 | if (abs((int)pHps->viewportXExt) <= abs((int)pHps->windowExt.cx))
|
---|
1373 | clipRect.right -= abs(pHps->worldXDeltaFor1Pixel);
|
---|
1374 | else
|
---|
1375 | clipRect.left += abs(pHps->worldXDeltaFor1Pixel);
|
---|
1376 |
|
---|
1377 | if (abs((int)pHps->viewportYExt) <= abs((int)pHps->windowExt.cy))
|
---|
1378 | clipRect.bottom -= abs(pHps->worldYDeltaFor1Pixel);
|
---|
1379 | else
|
---|
1380 | clipRect.top += abs(pHps->worldYDeltaFor1Pixel);
|
---|
1381 | }
|
---|
1382 | GpiConvert(pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, (PPOINTL)&clipRect);
|
---|
1383 | if (clipRect.right < clipRect.left) {
|
---|
1384 | ULONG temp = clipRect.left;
|
---|
1385 | clipRect.left = clipRect.right;
|
---|
1386 | clipRect.right = temp;
|
---|
1387 | }
|
---|
1388 | if (clipRect.bottom < clipRect.top) {
|
---|
1389 | ULONG temp = clipRect.top;
|
---|
1390 | clipRect.top = clipRect.bottom;
|
---|
1391 | clipRect.bottom = temp;
|
---|
1392 | }
|
---|
1393 | }
|
---|
1394 |
|
---|
1395 | if (pScroll)
|
---|
1396 | {
|
---|
1397 | memcpy(&scrollRect, pScroll, sizeof(scrollRect));
|
---|
1398 |
|
---|
1399 | if ((pHps->graphicsMode == GM_COMPATIBLE_W) &&
|
---|
1400 | (scrollRect.left != scrollRect.right) &&
|
---|
1401 | (scrollRect.top != scrollRect.bottom))
|
---|
1402 | {
|
---|
1403 | if (abs((int)pHps->viewportXExt) <= abs((int)pHps->windowExt.cx))
|
---|
1404 | scrollRect.right -= abs(pHps->worldXDeltaFor1Pixel);
|
---|
1405 | else
|
---|
1406 | scrollRect.left += abs(pHps->worldXDeltaFor1Pixel);
|
---|
1407 |
|
---|
1408 | if (abs((int)pHps->viewportYExt) <= abs((int)pHps->windowExt.cy))
|
---|
1409 | scrollRect.bottom -= abs(pHps->worldYDeltaFor1Pixel);
|
---|
1410 | else
|
---|
1411 | scrollRect.top += abs(pHps->worldYDeltaFor1Pixel);
|
---|
1412 | }
|
---|
1413 | GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, (PPOINTL)&scrollRect);
|
---|
1414 | if (scrollRect.right < scrollRect.left) {
|
---|
1415 | ULONG temp = scrollRect.left;
|
---|
1416 | scrollRect.left = scrollRect.right;
|
---|
1417 | scrollRect.right = temp;
|
---|
1418 | }
|
---|
1419 | if (scrollRect.bottom < scrollRect.top) {
|
---|
1420 | ULONG temp = scrollRect.top;
|
---|
1421 | scrollRect.top = scrollRect.bottom;
|
---|
1422 | scrollRect.bottom = temp;
|
---|
1423 | }
|
---|
1424 | }
|
---|
1425 | RECTL rectlUpdate;
|
---|
1426 | HRGN hrgn;
|
---|
1427 | RECTL clientRect;
|
---|
1428 | RECTL clipOS2;
|
---|
1429 | RECTL scrollOS2;
|
---|
1430 | PRECTL pScrollOS2 = NULL;
|
---|
1431 | PRECTL pClipOS2 = NULL;
|
---|
1432 |
|
---|
1433 | mapWin32ToOS2Rect(wnd->getWindowHeight(), wnd->getClientRectPtr(), (PRECTLOS2)&clientRect);
|
---|
1434 |
|
---|
1435 | if(pScroll) {
|
---|
1436 | mapWin32ToOS2RectClientToFrame(wnd, &scrollRect, (PRECTLOS2)&scrollOS2);
|
---|
1437 | pScrollOS2 = &scrollOS2;
|
---|
1438 |
|
---|
1439 | //Scroll rectangle relative to client area
|
---|
1440 | WinIntersectRect ((HAB) 0, pScrollOS2, pScrollOS2, &clientRect);
|
---|
1441 | }
|
---|
1442 | else {
|
---|
1443 | pScrollOS2 = &clientRect;
|
---|
1444 | }
|
---|
1445 |
|
---|
1446 | if(pClip) {
|
---|
1447 | mapWin32ToOS2RectClientToFrame(wnd, &clipRect, (PRECTLOS2)&clipOS2);
|
---|
1448 | pClipOS2 = &clipOS2;
|
---|
1449 |
|
---|
1450 | //Clip rectangle relative to client area
|
---|
1451 | WinIntersectRect((HAB) 0, pClipOS2, pClipOS2, &clientRect);
|
---|
1452 | }
|
---|
1453 | else {
|
---|
1454 | pClipOS2 = &clientRect;
|
---|
1455 | }
|
---|
1456 |
|
---|
1457 | LONG lComplexity = WinScrollWindow(hwnd, dx, dy, pScrollOS2,
|
---|
1458 | pClipOS2, hrgn, &rectlUpdate, 0);
|
---|
1459 | if (lComplexity == RGN_ERROR)
|
---|
1460 | {
|
---|
1461 | return (FALSE);
|
---|
1462 | }
|
---|
1463 |
|
---|
1464 | RECT winRectUpdate;
|
---|
1465 |
|
---|
1466 | mapOS2ToWin32Rect(wnd->getWindowHeight(), (PRECTLOS2)&rectlUpdate, &winRectUpdate);
|
---|
1467 |
|
---|
1468 | if (pRectUpdate)
|
---|
1469 | *pRectUpdate = winRectUpdate;
|
---|
1470 |
|
---|
1471 | if (hrgnUpdate)
|
---|
1472 | rc = setPMRgnIntoWinRgn(hrgn, hrgnUpdate, wnd->getWindowHeight());
|
---|
1473 |
|
---|
1474 | return (rc);
|
---|
1475 | }
|
---|
1476 | //******************************************************************************
|
---|
1477 | //******************************************************************************
|
---|
1478 | BOOL WIN32API ScrollWindow(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip)
|
---|
1479 | {
|
---|
1480 | Win32BaseWindow *window;
|
---|
1481 | APIRET rc;
|
---|
1482 | RECTL clientRect;
|
---|
1483 | RECTL scrollRect;
|
---|
1484 | RECTL clipRect;
|
---|
1485 | PRECTL pScrollOS2 = NULL;
|
---|
1486 | PRECTL pClipOS2 = NULL;
|
---|
1487 | ULONG scrollFlags = SW_INVALIDATERGN;
|
---|
1488 |
|
---|
1489 | window = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
1490 | if(!window) {
|
---|
1491 | dprintf(("ScrollWindow, window %x not found", hwnd));
|
---|
1492 | return 0;
|
---|
1493 | }
|
---|
1494 | dprintf(("ScrollWindow %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip));
|
---|
1495 |
|
---|
1496 | mapWin32ToOS2Rect(window->getWindowHeight(), window->getClientRectPtr(), (PRECTLOS2)&clientRect);
|
---|
1497 |
|
---|
1498 | if(pScroll) {
|
---|
1499 | mapWin32ToOS2RectClientToFrame(window,(RECT *)pScroll, (PRECTLOS2)&scrollRect);
|
---|
1500 | pScrollOS2 = &scrollRect;
|
---|
1501 |
|
---|
1502 | //Scroll rectangle relative to client area
|
---|
1503 | WinIntersectRect ((HAB) 0, pScrollOS2, pScrollOS2, &clientRect);
|
---|
1504 | }
|
---|
1505 | else {
|
---|
1506 | pScrollOS2 = &clientRect;
|
---|
1507 | scrollFlags |= SW_SCROLLCHILDREN;
|
---|
1508 | }
|
---|
1509 |
|
---|
1510 | if(pClip) {
|
---|
1511 | mapWin32ToOS2RectClientToFrame(window,(RECT *)pClip, (PRECTLOS2)&clipRect);
|
---|
1512 | pClipOS2 = &clipRect;
|
---|
1513 |
|
---|
1514 | //Clip rectangle relative to client area
|
---|
1515 | WinIntersectRect ((HAB) 0, pClipOS2, pClipOS2, &clientRect);
|
---|
1516 | }
|
---|
1517 | else {
|
---|
1518 | pClipOS2 = &clientRect;
|
---|
1519 | }
|
---|
1520 |
|
---|
1521 | dy = revertDy (window, dy);
|
---|
1522 |
|
---|
1523 | rc = WinScrollWindow(window->getOS2WindowHandle(), dx, dy,
|
---|
1524 | pScrollOS2, pClipOS2, NULLHANDLE,
|
---|
1525 | NULL, scrollFlags);
|
---|
1526 |
|
---|
1527 | return (rc != RGN_ERROR);
|
---|
1528 | }
|
---|
1529 | //******************************************************************************
|
---|
1530 | //******************************************************************************
|
---|
1531 | INT WIN32API ScrollWindowEx(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip,
|
---|
1532 | HRGN hrgnUpdate, PRECT pRectUpdate, UINT scrollFlag)
|
---|
1533 | {
|
---|
1534 | Win32BaseWindow *window;
|
---|
1535 | APIRET rc;
|
---|
1536 | RECTL clientRect;
|
---|
1537 | RECTL scrollRect;
|
---|
1538 | RECTL clipRect;
|
---|
1539 | PRECTL pScrollOS2 = NULL;
|
---|
1540 | PRECTL pClipOS2 = NULL;
|
---|
1541 | ULONG scrollFlags = 0;
|
---|
1542 | int regionType = ERROR_W;
|
---|
1543 |
|
---|
1544 | window = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
1545 | if(!window) {
|
---|
1546 | dprintf(("ScrollWindowEx, window %x not found", hwnd));
|
---|
1547 | return 0;
|
---|
1548 | }
|
---|
1549 |
|
---|
1550 | dprintf(("ScrollWindowEx %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip));
|
---|
1551 |
|
---|
1552 | dy = revertDy (window, dy);
|
---|
1553 |
|
---|
1554 | if (scrollFlag & SW_INVALIDATE_W) scrollFlags |= SW_INVALIDATERGN;
|
---|
1555 | if (scrollFlag & SW_SCROLLCHILDREN_W) scrollFlags |= SW_SCROLLCHILDREN;
|
---|
1556 |
|
---|
1557 | mapWin32ToOS2Rect(window->getWindowHeight(), window->getClientRectPtr(), (PRECTLOS2)&clientRect);
|
---|
1558 |
|
---|
1559 | if(pScroll) {
|
---|
1560 | mapWin32ToOS2RectClientToFrame(window,(RECT *)pScroll, (PRECTLOS2)&scrollRect);
|
---|
1561 | pScrollOS2 = &scrollRect;
|
---|
1562 |
|
---|
1563 | //Scroll rectangle relative to client area
|
---|
1564 | WinIntersectRect ((HAB) 0, pScrollOS2, pScrollOS2, &clientRect);
|
---|
1565 | }
|
---|
1566 | else {
|
---|
1567 | pScrollOS2 = &clientRect;
|
---|
1568 | scrollFlags |= SW_SCROLLCHILDREN; //TODO: ?????
|
---|
1569 | }
|
---|
1570 |
|
---|
1571 | if(pClip) {
|
---|
1572 | mapWin32ToOS2RectClientToFrame(window,(RECT *)pClip, (PRECTLOS2)&clipRect);
|
---|
1573 | pClipOS2 = &clipRect;
|
---|
1574 |
|
---|
1575 | //Clip rectangle relative to client area
|
---|
1576 | WinIntersectRect ((HAB) 0, pClipOS2, pClipOS2, &clientRect);
|
---|
1577 | }
|
---|
1578 | else {
|
---|
1579 | pClipOS2 = &clientRect;
|
---|
1580 | }
|
---|
1581 |
|
---|
1582 | RECTL rectlUpdate;
|
---|
1583 | HRGN hrgn;
|
---|
1584 |
|
---|
1585 | if (scrollFlag & SW_SMOOTHSCROLL_W)
|
---|
1586 | {
|
---|
1587 | INT time = (scrollFlag >> 16) & 0xFFFF;
|
---|
1588 |
|
---|
1589 | //CB: todo, scroll in several steps
|
---|
1590 | // is time in ms? time <-> iteration count?
|
---|
1591 | }
|
---|
1592 |
|
---|
1593 | LONG lComplexity = WinScrollWindow (window->getOS2WindowHandle(), dx, dy,
|
---|
1594 | pScrollOS2,
|
---|
1595 | pClipOS2,
|
---|
1596 | hrgn, &rectlUpdate, scrollFlags);
|
---|
1597 | if (lComplexity == RGN_ERROR)
|
---|
1598 | {
|
---|
1599 | return ERROR_W;
|
---|
1600 | }
|
---|
1601 |
|
---|
1602 | RECT winRectUpdate;
|
---|
1603 |
|
---|
1604 | mapOS2ToWin32Rect(window->getWindowHeight(), (PRECTLOS2)&rectlUpdate, &winRectUpdate);
|
---|
1605 |
|
---|
1606 | if (pRectUpdate)
|
---|
1607 | *pRectUpdate = winRectUpdate;
|
---|
1608 |
|
---|
1609 | if (hrgnUpdate)
|
---|
1610 | rc = setPMRgnIntoWinRgn (hrgn, hrgnUpdate, window->getWindowHeight());
|
---|
1611 |
|
---|
1612 | #if 0
|
---|
1613 | //SvL: WinScrollWindow already invalidates the area; no need to do it again
|
---|
1614 | //(call to invalidateRect was wrong; has to include erase flag)
|
---|
1615 | if ((scrollFlag & SW_INVALIDATE_W) &&
|
---|
1616 | ((lComplexity == RGN_RECT) || (lComplexity == RGN_COMPLEX)))
|
---|
1617 | {
|
---|
1618 | rc = InvalidateRect (hwnd, &winRectUpdate, (scrollFlag & SW_ERASE_W) ? 1 : 0);
|
---|
1619 | if (rc == FALSE)
|
---|
1620 | {
|
---|
1621 | return (0);
|
---|
1622 | }
|
---|
1623 | }
|
---|
1624 | #endif
|
---|
1625 |
|
---|
1626 | switch (lComplexity)
|
---|
1627 | {
|
---|
1628 | case RGN_NULL:
|
---|
1629 | regionType = NULLREGION_W;
|
---|
1630 | break;
|
---|
1631 | case RGN_RECT:
|
---|
1632 | regionType = SIMPLEREGION_W;
|
---|
1633 | break;
|
---|
1634 | case RGN_COMPLEX:
|
---|
1635 | regionType = COMPLEXREGION_W;
|
---|
1636 | break;
|
---|
1637 | default:
|
---|
1638 | regionType = ERROR_W;
|
---|
1639 | break;
|
---|
1640 | }
|
---|
1641 |
|
---|
1642 | return (regionType);
|
---|
1643 | }
|
---|
1644 | //******************************************************************************
|
---|
1645 | //******************************************************************************
|
---|
1646 | HWND WIN32API WindowFromDC(HDC hdc)
|
---|
1647 | {
|
---|
1648 | pDCData pHps = (pDCData)GpiQueryDCData( (HPS)hdc );
|
---|
1649 |
|
---|
1650 | dprintf2(("USER32: WindowFromDC %x", hdc));
|
---|
1651 | if ( pHps )
|
---|
1652 | return Win32BaseWindow::OS2ToWin32Handle(pHps->hwnd);
|
---|
1653 | else
|
---|
1654 | return 0;
|
---|
1655 | }
|
---|
1656 | //******************************************************************************
|
---|
1657 | //******************************************************************************
|
---|
1658 | int WIN32API SetMapMode(HDC hdc, int mode)
|
---|
1659 | {
|
---|
1660 | Win32BaseWindow *wnd;
|
---|
1661 | pDCData pHps = (pDCData)GpiQueryDCData((HPS)hdc);
|
---|
1662 | if(!pHps)
|
---|
1663 | {
|
---|
1664 | SetLastError(ERROR_INVALID_HANDLE_W);
|
---|
1665 | dprintf(("GDI32: SetMapMode %x %x -> invalid hdc!!", hdc, mode));
|
---|
1666 | return 0;
|
---|
1667 | }
|
---|
1668 | wnd = Win32BaseWindow::GetWindowFromHandle(WindowFromDC(hdc));
|
---|
1669 | //todo: metafile recording
|
---|
1670 |
|
---|
1671 | dprintf(("GDI32: SetMapMode %x %x", hdc, mode));
|
---|
1672 | return setMapMode(wnd, pHps, mode);
|
---|
1673 | }
|
---|
1674 | //******************************************************************************
|
---|
1675 | //******************************************************************************
|
---|
1676 | int WIN32API GetMapMode(HDC hdc)
|
---|
1677 | {
|
---|
1678 | pDCData pHps = (pDCData)GpiQueryDCData((HPS)hdc);
|
---|
1679 | if(pHps) {
|
---|
1680 | dprintf(("GDI32: GetMapMode %x -> %x", hdc, pHps->MapMode));
|
---|
1681 | return pHps->MapMode;
|
---|
1682 | }
|
---|
1683 | dprintf(("GDI32: GetMapMode: invalid hdc %x!!!", hdc));
|
---|
1684 | SetLastError(ERROR_INVALID_HANDLE_W);
|
---|
1685 | return 0;
|
---|
1686 | }
|
---|
1687 | //******************************************************************************
|
---|
1688 | //******************************************************************************
|
---|
1689 | BOOL WIN32API SetViewportExtEx(HDC hdc, int xExt, int yExt, LPSIZE pSize)
|
---|
1690 | {
|
---|
1691 | Win32BaseWindow *wnd;
|
---|
1692 | pDCData pHps = (pDCData)GpiQueryDCData((HPS)hdc);
|
---|
1693 |
|
---|
1694 | if(!pHps)
|
---|
1695 | {
|
---|
1696 | dprintf(("GDI32: SetViewportExtEx %x %d %d %x -> INVALID HDC", hdc, xExt, yExt, pSize));
|
---|
1697 | SetLastError(ERROR_INVALID_HANDLE_W);
|
---|
1698 | return FALSE;
|
---|
1699 | }
|
---|
1700 |
|
---|
1701 | if(pSize) {
|
---|
1702 | dprintf(("GDI32: SetViewportExtEx %x %d %d (%d,%d)", hdc, xExt, yExt, pSize->cx, pSize->cy));
|
---|
1703 | }
|
---|
1704 | else dprintf(("GDI32: SetViewportExtEx %x %d %d NULL", hdc, xExt, yExt));
|
---|
1705 |
|
---|
1706 | if (xExt && yExt )
|
---|
1707 | {
|
---|
1708 | //todo: Metafile recording!! (done for any map mode)
|
---|
1709 |
|
---|
1710 | if(pHps->MapMode == MM_ISOTROPIC_W || pHps->MapMode == MM_ANISOTROPIC_W)
|
---|
1711 | {
|
---|
1712 | wnd = Win32BaseWindow::GetWindowFromHandle(WindowFromDC(hdc));
|
---|
1713 | if(changePageXForm(wnd, pHps, NULL, xExt, yExt, (PPOINTL) pSize))
|
---|
1714 | {
|
---|
1715 | SetLastError(ERROR_SUCCESS_W);
|
---|
1716 | return TRUE;
|
---|
1717 | }
|
---|
1718 | }
|
---|
1719 | else
|
---|
1720 | {
|
---|
1721 | pHps->lVwpXExtSave = xExt;
|
---|
1722 | pHps->lVwpYExtSave = yExt;
|
---|
1723 |
|
---|
1724 | //if map mode is not ISOTROPIC nor ANISOTROPIC, this function does
|
---|
1725 | //nothing and returns TRUE (NT)
|
---|
1726 | SetLastError(ERROR_SUCCESS_W);
|
---|
1727 | return TRUE;
|
---|
1728 | }
|
---|
1729 |
|
---|
1730 | SetLastError(ERROR_SUCCESS_W);
|
---|
1731 | return FALSE;
|
---|
1732 | }
|
---|
1733 |
|
---|
1734 | SetLastError(ERROR_INVALID_PARAMETER_W);
|
---|
1735 | return FALSE;
|
---|
1736 | }
|
---|
1737 | //******************************************************************************
|
---|
1738 | //******************************************************************************
|
---|
1739 | BOOL WIN32API GetViewportExtEx(HDC hdc, LPSIZE pSize)
|
---|
1740 | {
|
---|
1741 | pDCData pHps = (pDCData)GpiQueryDCData((HPS)hdc);
|
---|
1742 | if(!pHps)
|
---|
1743 | {
|
---|
1744 | dprintf(("GDI32: GetViewportExtEx %x %x -> INVALID HDC", hdc, pSize));
|
---|
1745 | SetLastError(ERROR_INVALID_HANDLE_W);
|
---|
1746 | return FALSE;
|
---|
1747 | }
|
---|
1748 |
|
---|
1749 | if(!pSize)
|
---|
1750 | {
|
---|
1751 | dprintf(("GDI32: GetViewportExtEx %x NULL -> INVALID parameter", hdc));
|
---|
1752 | SetLastError(ERROR_INVALID_PARAMETER_W);
|
---|
1753 | return FALSE;
|
---|
1754 | }
|
---|
1755 |
|
---|
1756 | pSize->cx = (LONG)pHps->viewportXExt;
|
---|
1757 | pSize->cy = (LONG)pHps->viewportYExt;
|
---|
1758 | dprintf(("GDI32: GetViewportExtEx %x -> (%d,%d)", hdc, pSize->cx, pSize->cy));
|
---|
1759 |
|
---|
1760 | SetLastError(ERROR_SUCCESS_W);
|
---|
1761 | return TRUE;
|
---|
1762 | }
|
---|
1763 | //******************************************************************************
|
---|
1764 | //******************************************************************************
|
---|