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