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