source: trunk/src/user32/dc.cpp@ 5655

Last change on this file since 5655 was 5655, checked in by sandervl, 24 years ago

FrameTrackFrame & nccalcsize bugfixes

File size: 63.4 KB
Line 
1/* $Id: dc.cpp,v 1.98 2001-05-04 17:02:50 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
70const XFORM_W XFORMIdentity = { 1.0, 0.0, 0.0, 1.0, 0, 0 };
71const MATRIXLF matrixlfIdentity = { 0x10000, 0, 0, 0, 0x10000, 0, 0, 0, 0};
72
73BOOL setPageXForm(Win32BaseWindow *wnd, pDCData pHps);
74BOOL changePageXForm(Win32BaseWindow *wnd, pDCData pHps, PPOINTL pValue, int x, int y, PPOINTL pPrev);
75LONG 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
80void 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//******************************************************************************
98void 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//******************************************************************************
122void 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//******************************************************************************
132int 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//******************************************************************************
212BOOL 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//******************************************************************************
326BOOL 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//******************************************************************************
387VOID 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//******************************************************************************
414void 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#ifdef DEBUG
494 dprintf(("Combining client & parent client regions"));
495 dprintfRegion1(pHps->hps, window->getWindowHandle(), hrgnParentClip);
496 dprintfRegion1(pHps->hps, window->getWindowHandle(), hrgnRect);
497#endif
498
499 GreCombineRegion(pHps->hps, hrgnRect, hrgnParentClip, hrgnRect, CRGN_AND);
500 GreDestroyRegion(pHps->hps, hrgnParentClip);
501 }
502#endif
503
504 // Query the visible region
505 GreCopyClipRegion(pHps->hps, pHps->hrgnVis, 0, COPYCRGN_VISRGN);
506 GpiQueryRegionBox(pHps->hps, pHps->hrgnVis, &rcltemp);
507 // And the visible region of the frame with the client rectangle
508 // to get the new visible region
509 GreCombineRegion(pHps->hps, hrgnRect, pHps->hrgnVis, hrgnRect, CRGN_AND);
510#ifdef DEBUG
511 dprintfRegion1(pHps->hps, window->getWindowHandle(), hrgnRect);
512#endif
513
514 // Set the new origin plus visible region in the DC
515 GreSetupDC(pHps->hps,
516 hrgnRect,
517 rcl.xLeft,
518 rcl.yBottom,
519 NULL,
520 SETUPDC_ORIGIN | SETUPDC_VISRGN | SETUPDC_RECALCCLIP);
521
522 // Destroy the region now we have finished with it.
523 GreDestroyRegion(pHps->hps, hrgnRect);
524
525 pHps->isClientArea = TRUE;
526
527 if(pClient->left == 0 && pClient->top == 0 &&
528 window->getClientHeight() == window->getWindowHeight() &&
529 window->getClientWidth() == window->getWindowWidth())
530 {
531 //client = frame, so no changes are necessary when switching between the two
532 pHps->isClient = FALSE;
533 pHps->isClientArea = FALSE;
534 }
535 if(window->isOwnDCDirty()) {
536 window->validateOwnDC();
537 setPageXForm(window, pHps);
538 }
539
540//testestest
541#if 0
542 GpiQueryViewingLimits(pHps->hps, &rectWindowOS2);
543 dprintf2(("view limits (%d,%d)(%d,%d)", rectWindowOS2.xLeft, rectWindowOS2.yBottom, rectWindowOS2.xRight, rectWindowOS2.yTop));
544 GpiQueryDefViewingLimits(pHps->hps, &rectWindowOS2);
545 dprintf2(("def view limits (%d,%d)(%d,%d)", rectWindowOS2.xLeft, rectWindowOS2.yBottom, rectWindowOS2.xRight, rectWindowOS2.yTop));
546 GpiQueryPageViewport(pHps->hps, &rectWindowOS2);
547 dprintf2(("page viewport (%d,%d)(%d,%d)", rectWindowOS2.xLeft, rectWindowOS2.yBottom, rectWindowOS2.xRight, rectWindowOS2.yTop));
548
549 GpiQueryBoundaryData(pHps->hps, &rectWindowOS2);
550 dprintf2(("boundary data (%d,%d)(%d,%d)", rectWindowOS2.xLeft, rectWindowOS2.yBottom, rectWindowOS2.xRight, rectWindowOS2.yTop));
551
552 GpiQueryGraphicsField(pHps->hps, &rectWindowOS2);
553 dprintf2(("graphics field (%d,%d)(%d,%d)", rectWindowOS2.xLeft, rectWindowOS2.yBottom, rectWindowOS2.xRight, rectWindowOS2.yTop));
554
555 SIZEL size;
556 GpiQueryPickApertureSize(pHps->hps, &size);
557 dprintf2(("page viewport (%d,%d)", size.cx, size.cy));
558
559 GpiQueryPS(pHps->hps, &size);
560 dprintf2(("page space (%d,%d)", size.cx, size.cy));
561#endif
562//testestest
563
564}
565//******************************************************************************
566//******************************************************************************
567void selectClientArea(Win32BaseWindow *wnd, HDC hdc)
568{
569 pDCData pHps = (pDCData)GpiQueryDCData (wnd->getOwnDC());
570
571 if (pHps != NULLHANDLE)
572 selectClientArea(wnd, pHps);
573}
574//******************************************************************************
575//******************************************************************************
576LONG clientHeight(Win32BaseWindow *wnd, HWND hwnd, pDCData pHps)
577{
578 if ((hwnd == 0) && (pHps != 0))
579 hwnd = pHps->hwnd;
580
581 if ((hwnd != 0) || (pHps == 0))
582 {
583 if(wnd) {
584 if(pHps && !pHps->isClientArea) {
585 return (wnd->getWindowHeight());
586 }
587 else return (wnd->getClientHeight());
588 }
589 else return OSLibQueryScreenHeight();
590 }
591 else if (pHps->bitmapHandle)
592 {
593 return pHps->bitmapHeight;
594 }
595 else if (pHps->isMetaPS)
596 {
597 return 0;
598 }
599 else if (pHps->isPrinter)
600 {
601 return pHps->printPageHeight;
602 }
603 else
604 {
605 return MEM_HPS_MAX;
606 }
607}
608//******************************************************************************
609//******************************************************************************
610BOOL WIN32API changePageXForm(pDCData pHps, PPOINTL pValue, int x, int y, PPOINTL pPrev)
611{
612 Win32BaseWindow *wnd;
613
614 wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
615 return changePageXForm(wnd, pHps, pValue, x, y, pPrev);
616}
617//******************************************************************************
618//******************************************************************************
619BOOL WIN32API setPageXForm(pDCData pHps)
620{
621 Win32BaseWindow *wnd;
622
623 wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
624 return setPageXForm(wnd, pHps);
625}
626//******************************************************************************
627//******************************************************************************
628VOID WIN32API removeClientArea(pDCData pHps)
629{
630 Win32BaseWindow *wnd;
631
632 wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
633 if(wnd) {
634 removeClientArea(wnd, pHps);
635 }
636}
637//******************************************************************************
638//******************************************************************************
639VOID WIN32API selectClientArea(pDCData pHps)
640{
641 Win32BaseWindow *wnd;
642
643 wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
644 if(wnd) {
645 selectClientArea(wnd, pHps);
646 }
647}
648//******************************************************************************
649//******************************************************************************
650VOID WIN32API checkOrigin(pDCData pHps)
651{
652 Win32BaseWindow *wnd;
653
654 wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
655 if(wnd) {
656 dprintfOrigin(pHps->hps);
657 if(pHps->isClient)
658 selectClientArea(wnd, pHps);
659 }
660}
661//******************************************************************************
662//******************************************************************************
663LONG WIN32API clientHeight(HWND hwnd, pDCData pHps)
664{
665 Win32BaseWindow *wnd;
666
667 wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
668 return clientHeight(wnd, hwnd, pHps);
669}
670//******************************************************************************
671//******************************************************************************
672int WIN32API setMapMode(pDCData pHps, int mode)
673{
674 Win32BaseWindow *wnd;
675
676 wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
677 return setMapMode(wnd, pHps, mode);
678}
679//******************************************************************************
680//******************************************************************************
681BOOL isYup (pDCData pHps)
682{
683 if (((pHps->windowExt.cy < 0) && (pHps->viewportYExt > 0.0)) ||
684 ((pHps->windowExt.cy > 0) && (pHps->viewportYExt < 0.0)))
685 {
686 if ((pHps->graphicsMode == GM_COMPATIBLE_W) ||
687 ((pHps->graphicsMode == GM_ADVANCED_W) && (pHps->xform.eM22 >= 0.0)))
688 return TRUE;
689 }
690 else
691 {
692 if ((pHps->graphicsMode == GM_ADVANCED_W) && (pHps->xform.eM22 < 0.0))
693 return TRUE;
694 }
695 return FALSE;
696}
697//******************************************************************************
698//******************************************************************************
699INT revertDy (Win32BaseWindow *wnd, INT dy)
700{
701 //SvL: Hack for memory.exe (doesn't get repainted properly otherwise)
702// if (wnd->isOwnDC() && wnd->getOwnDC())
703 if (wnd->isOwnDC())
704 {
705 pDCData pHps = (pDCData)GpiQueryDCData (wnd->getOwnDC());
706
707 if (pHps != NULLHANDLE)
708 if (!isYup (pHps))
709 dy = -dy;
710 }
711 else
712 {
713 dy = -dy;
714 }
715 return (dy);
716}
717//******************************************************************************
718//******************************************************************************
719HDC sendEraseBkgnd (Win32BaseWindow *wnd)
720{
721 BOOL erased;
722 HWND hwnd;
723 HDC hdc;
724 HPS hps;
725 HRGN hrgnUpdate, hrgnOld, hrgnClip, hrgnCombined;
726 RECTL rectl = { 1, 1, 2, 2 };
727
728 hwnd = wnd->getOS2WindowHandle();
729 hps = WinGetPS(hwnd);
730
731 hrgnUpdate = GpiCreateRegion (hps, 1, &rectl);
732 WinQueryUpdateRegion (hwnd, hrgnUpdate);
733 hrgnClip = GpiQueryClipRegion (hps);
734
735 if (hrgnClip == NULLHANDLE)
736 {
737 GpiSetClipRegion (hps, hrgnUpdate, &hrgnOld);
738 }
739 else
740 {
741 hrgnCombined = GpiCreateRegion (hps, 1, &rectl);
742 GpiCombineRegion (hps, hrgnCombined, hrgnClip, hrgnUpdate, CRGN_AND);
743 GpiSetClipRegion (hps, hrgnCombined, &hrgnOld);
744 GpiDestroyRegion (hps, hrgnUpdate);
745 GpiDestroyRegion (hps, hrgnClip);
746 }
747 if (hrgnOld != NULLHANDLE)
748 GpiDestroyRegion (hps, hrgnOld);
749
750 hdc = HPSToHDC (hwnd, hps, NULL, NULL);
751
752 erased = wnd->MsgEraseBackGround (hdc);
753
754 DeleteHDC (hdc);
755 WinReleasePS (hps);
756
757 return erased;
758}
759//******************************************************************************
760//******************************************************************************
761void releaseOwnDC (HDC hps)
762{
763 pDCData pHps = (pDCData)GpiQueryDCData ((HPS)hps);
764
765 dprintf2(("releaseOwnDC %x", hps));
766
767 if (pHps) {
768 if (pHps->hrgnHDC)
769 GpiDestroyRegion (pHps->hps, pHps->hrgnHDC);
770
771 GpiSetBitmap (pHps->hps, NULL);
772 O32_DeleteObject (pHps->nullBitmapHandle);
773 GpiDestroyPS(pHps->hps);
774
775 if (pHps->hdc)
776 DevCloseDC(pHps->hdc);
777 }
778}
779//******************************************************************************
780//******************************************************************************
781HDC WIN32API BeginPaint (HWND hWnd, PPAINTSTRUCT_W lpps)
782{
783 HWND hwnd = hWnd ? hWnd : HWND_DESKTOP;
784 pDCData pHps = NULLHANDLE;
785 HPS hPS_ownDC = NULLHANDLE, hpsPaint = 0;
786 RECTL rectl = {0, 0, 1, 1};
787 HRGN hrgnOldClip;
788 LONG lComplexity;
789 RECTL rectlClient;
790 RECTL rectlClip;
791
792 if(lpps == NULL) {
793 //BeginPaint does NOT change last error in this case
794 //(verified in NT4, SP6)
795 dprintf (("USER32: BeginPaint %x NULL PAINTSTRUCT pointer", hWnd));
796 return 0;
797 }
798 memset(lpps, 0, sizeof(*lpps));
799
800 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
801 if(!wnd) {
802 dprintf (("USER32: BeginPaint %x %x: invalid window handle!!", hWnd, lpps));
803 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W); //(verified in NT4, SP6)
804 return (HDC)0;
805 }
806 HWND hwndClient = wnd->getOS2WindowHandle();
807
808 if(hwnd != HWND_DESKTOP && wnd->isOwnDC())
809 {
810 hPS_ownDC = wnd->getOwnDC();
811 //SvL: Hack for memory.exe (doesn't get repainted properly otherwise)
812 if(hPS_ownDC) {
813 pHps = (pDCData)GpiQueryDCData(hPS_ownDC);
814 if (!pHps)
815 {
816 dprintf (("USER32: BeginPaint %x invalid parameter %x", hWnd, lpps));
817 SetLastError(ERROR_INVALID_PARAMETER_W);
818 return (HDC)NULLHANDLE;
819 }
820 hpsPaint = hPS_ownDC;
821 }
822 }
823 if(!hpsPaint) {
824 hpsPaint = GetDCEx(hwnd, 0, (DCX_CACHE_W|DCX_WINDOW_W|DCX_USESTYLE_W));
825 pHps = (pDCData)GpiQueryDCData(hpsPaint);
826 if (!pHps)
827 {
828 dprintf (("USER32: BeginPaint %x invalid parameter %x", hWnd, lpps));
829 SetLastError(ERROR_INVALID_PARAMETER_W);
830 return (HDC)NULLHANDLE;
831 }
832 }
833
834 if(WinQueryUpdateRect(hwndClient, &rectl) == FALSE) {
835 memset(&rectl, 0, sizeof(rectl));
836 dprintf (("USER32: WARNING: WinQueryUpdateRect failed (error or no update rectangle)!!"));
837
838 HRGN hrgnClip = GpiCreateRegion(pHps->hps, 1, &rectl);
839 GpiSetClipRegion(pHps->hps, hrgnClip, &hrgnOldClip);
840
841 selectClientArea(wnd, pHps);
842
843 //save old clip region (restored for CS_OWNDC windows in EndPaint)
844 wnd->SetClipRegion(hrgnOldClip);
845 lComplexity = RGN_NULL;
846 }
847 else {
848 rectlClip.yBottom = rectlClip.xLeft = 0;
849 rectlClip.yTop = rectlClip.xRight = 1;
850
851 //Query update region
852 HRGN hrgnClip = GpiCreateRegion(pHps->hps, 1, &rectlClip);
853 WinQueryUpdateRegion(hwndClient, hrgnClip);
854 WinValidateRegion(hwndClient, hrgnClip, FALSE);
855
856 mapWin32ToOS2Rect(wnd->getWindowHeight(), wnd->getClientRectPtr(), (PRECTLOS2)&rectlClient);
857 WinIntersectRect(NULL, &rectlClip, &rectl, &rectlClient);
858 WinOffsetRect(NULL, &rectlClip, -rectlClient.xLeft, -rectlClient.yBottom);
859
860 //clip update region with client window rectangle
861 HRGN hrgnClient = GpiCreateRegion(pHps->hps, 1, &rectlClient);
862 GpiCombineRegion(pHps->hps, hrgnClip, hrgnClip, hrgnClient, CRGN_AND);
863 GpiDestroyRegion(pHps->hps, hrgnClient);
864
865 //change origin of clip region (window -> client)
866 POINTL point = {-rectlClient.xLeft, -rectlClient.yBottom};
867 GpiOffsetRegion(pHps->hps, hrgnClip, &point);
868#ifdef DEBUG
869 dprintfRegion1(pHps->hps, hWnd, hrgnClip);
870#endif
871 //set clip region
872 lComplexity = GpiSetClipRegion(pHps->hps, hrgnClip, &hrgnOldClip);
873
874 //change presentation space for client window
875 //NOTE: MUST do this after GpiSetClipRegion call!
876 // When a window with CS_OWNDC looses focus, for some reason
877 // GpiSetClipRegion resets the window dc origin back to (0,0)
878 selectClientArea(wnd, pHps);
879
880 GpiQueryClipBox(pHps->hps, &rectl);
881 dprintf(("ClipBox (%d): (%d,%d)(%d,%d)", lComplexity, rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop));
882
883 //save old clip region (restored for CS_OWNDC windows in EndPaint)
884 wnd->SetClipRegion(hrgnOldClip);
885 memcpy(&rectl, &rectlClip, sizeof(RECTL));
886 lComplexity = RGN_RECT;
887 }
888
889 if(hPS_ownDC == 0)
890 setMapMode (wnd, pHps, MM_TEXT_W);
891 else
892 setPageXForm(wnd, pHps);
893
894 pHps->hdcType = TYPE_3;
895
896 HideCaret(hwnd);
897 WinShowTrackRect(wnd->getOS2WindowHandle(), FALSE);
898
899 if(wnd->needsEraseBkgnd() && lComplexity != RGN_NULL) {
900 wnd->setEraseBkgnd(FALSE);
901 lpps->fErase = (wnd->MsgEraseBackGround(pHps->hps) == 0);
902 }
903 else lpps->fErase = TRUE;
904
905 dprintfOrigin(pHps->hps);
906
907 lpps->hdc = (HDC)pHps->hps;
908
909 if(lComplexity != RGN_NULL) {
910 long height = wnd->getClientHeight();
911 lpps->rcPaint.top = height - rectl.yTop;
912 lpps->rcPaint.left = rectl.xLeft;
913 lpps->rcPaint.bottom = height - rectl.yBottom;
914 lpps->rcPaint.right = rectl.xRight;
915 }
916 else {
917 lpps->rcPaint.bottom = lpps->rcPaint.top = 0;
918 lpps->rcPaint.right = lpps->rcPaint.left = 0;
919 }
920
921 SetLastError(0);
922 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));
923 return (HDC)pHps->hps;
924}
925//******************************************************************************
926//******************************************************************************
927BOOL WIN32API EndPaint (HWND hWnd, const PAINTSTRUCT_W *pPaint)
928{
929 HWND hwnd = hWnd ? hWnd : HWND_DESKTOP;
930 HRGN hrgnOld;
931 pDCData pHps;
932
933 dprintf (("USER32: EndPaint(%x)", hwnd));
934
935 if (!pPaint || !pPaint->hdc )
936 return TRUE;
937
938 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
939
940 if (!wnd) goto exit;
941
942 pHps = (pDCData)GpiQueryDCData((HPS)pPaint->hdc);
943 if (pHps && (pHps->hdcType == TYPE_3))
944 {
945 dprintfOrigin(pHps->hps);
946
947 GpiSetClipRegion(pHps->hps, wnd->GetClipRegion(), &hrgnOld);
948 wnd->SetClipRegion(0);
949 if(hrgnOld) {
950 GpiDestroyRegion(pHps->hps, hrgnOld);
951 }
952 pHps->hdcType = TYPE_1; //otherwise Open32's ReleaseDC fails
953 ReleaseDC(hwnd, pPaint->hdc);
954 }
955 else {
956 dprintf(("EndPaint: wrong hdc %x!!", pPaint->hdc));
957 }
958 wnd->setEraseBkgnd(TRUE);
959 ShowCaret(hwnd);
960 WinShowTrackRect(wnd->getOS2WindowHandle(), TRUE);
961
962exit:
963 SetLastError(0);
964 return TRUE;
965}
966//******************************************************************************
967//******************************************************************************
968int WIN32API ReleaseDC (HWND hwnd, HDC hdc)
969{
970 BOOL isOwnDC = FALSE;
971 int rc;
972
973 if (hwnd)
974 {
975 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
976 if(wnd == NULL) {
977 dprintf(("ERROR: ReleaseDC %x %x failed", hwnd, hdc));
978 return 0;
979 }
980 isOwnDC = wnd->isOwnDC() && (wnd->getOwnDC() == hdc);
981 if(!isOwnDC)
982 {
983 pDCData pHps = (pDCData)GpiQueryDCData((HPS)hdc);
984 if(pHps && pHps->psType == MICRO_CACHED) {
985 removeClientArea(wnd, pHps);
986 if(pHps->hrgnVis) {
987 GreDestroyRegion(pHps->hps, pHps->hrgnVis);
988 pHps->hrgnVis = 0;
989 }
990 }
991 else {
992 dprintf(("ERROR: ReleaseDC: pHps == NULL!!"));
993 DebugInt3();
994 }
995 }
996 else {
997 dprintf2(("ReleaseDC: CS_OWNDC, not released"));
998 }
999 }
1000
1001 if(isOwnDC) {
1002 rc = TRUE;
1003 }
1004 else {
1005 UnselectGDIObjects(hdc);
1006 rc = O32_ReleaseDC (0, hdc);
1007 }
1008
1009 dprintf(("ReleaseDC %x %x", hwnd, hdc));
1010 return (rc);
1011}
1012//******************************************************************************
1013// This implementation of GetDCEx supports
1014// DCX_WINDOW
1015// DCX_CACHE
1016// DCX_EXCLUDERGN (complex regions allowed)
1017// DCX_INTERSECTRGN (complex regions allowed)
1018// DCX_USESTYLE
1019// DCX_CLIPSIBLINGS
1020// DCX_CLIPCHILDREN
1021// DCX_PARENTCLIP
1022//
1023//TODO: WM_SETREDRAW affects drawingAllowed flag!!
1024//******************************************************************************
1025HDC WIN32API GetDCEx (HWND hwnd, HRGN hrgn, ULONG flags)
1026{
1027 Win32BaseWindow *wnd = NULL;
1028 HWND hWindow;
1029 BOOL success;
1030 pDCData pHps = NULL;
1031 HPS hps = NULLHANDLE;
1032 BOOL drawingAllowed = TRUE;
1033 BOOL isWindowOwnDC;
1034 BOOL creatingOwnDC = FALSE;
1035 PS_Type psType;
1036
1037 if(hwnd == 0) {
1038 dprintf(("error: GetDCEx window %x not found", hwnd));
1039 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
1040 return 0;
1041 }
1042
1043 if (hwnd)
1044 {
1045 wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
1046 if(wnd == NULL) {
1047 dprintf (("ERROR: User32: GetDCEx bad window handle %X!!!!!", hwnd));
1048 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
1049 return 0;
1050 }
1051 hWindow = wnd->getOS2WindowHandle();
1052 }
1053
1054 isWindowOwnDC = (((hWindow == HWND_DESKTOP) ? FALSE : (wnd->isOwnDC()))
1055 && !(flags & (DCX_CACHE_W|DCX_WINDOW_W)));
1056
1057 if(isWindowOwnDC) //own dc always for client area
1058 {
1059 hps = wnd->getOwnDC();
1060 if (hps)
1061 {
1062 pDCData pHps = (pDCData)GpiQueryDCData (hps);
1063 if (!pHps)
1064 goto error;
1065
1066 selectClientArea(wnd, pHps);
1067
1068 //TODO: Is this always necessary??
1069 setPageXForm (wnd, pHps);
1070 pHps->hdcType = TYPE_1;
1071
1072 //TODO: intersect/exclude clip region?
1073 dprintf (("User32: GetDCEx hwnd %x (%x %x) -> wnd %x hdc %x", hwnd, hrgn, flags, wnd, hps));
1074 return (HDC)hps;
1075 }
1076 else
1077 creatingOwnDC = TRUE;
1078 }
1079
1080 if(isWindowOwnDC)
1081 {
1082 SIZEL sizel = {0,0};
1083 hps = GpiCreatePS (WinQueryAnchorBlock (hWindow),
1084 WinOpenWindowDC (hWindow),
1085 &sizel, PU_PELS | GPIT_MICRO | GPIA_ASSOC );
1086 psType = MICRO;
1087 // default cp is OS/2 one: set to windows default (ODIN.INI)
1088 GpiSetCp(hps, GetDisplayCodepage());
1089 }
1090 else
1091 {
1092 if (hWindow == HWND_DESKTOP) {
1093 hps = WinGetScreenPS (hWindow);
1094 }
1095 else {
1096 int clipstyle = 0;
1097 int clipwnd = HWND_TOP;
1098 if(flags & (DCX_USESTYLE_W)) {
1099 int style = wnd->getStyle();
1100 if(style & WS_CLIPCHILDREN_W) {
1101 clipstyle |= PSF_CLIPCHILDREN;
1102 }
1103 if(style & WS_CLIPSIBLINGS_W) {
1104 clipstyle |= PSF_CLIPSIBLINGS;
1105 }
1106 if(wnd->fHasParentDC()) {
1107 clipstyle |= PSF_PARENTCLIP;
1108 }
1109 }
1110 if(flags & DCX_CLIPSIBLINGS_W) {
1111 clipstyle |= PSF_CLIPSIBLINGS;
1112 }
1113 if(flags & DCX_CLIPCHILDREN_W) {
1114 clipstyle |= PSF_CLIPCHILDREN;
1115 }
1116 if(flags & DCX_PARENTCLIP_W) {
1117 clipstyle |= PSF_PARENTCLIP;
1118 }
1119 if(clipstyle) {
1120 dprintf2(("WinGetClipPS style %x", clipstyle));
1121 hps = WinGetClipPS(hWindow, clipwnd, clipstyle);
1122 }
1123 else hps = WinGetPS (hWindow);
1124
1125 // default cp is OS/2 one: set to windows default (ODIN.INI)
1126 GpiSetCp(hps, GetDisplayCodepage());
1127 }
1128 psType = MICRO_CACHED;
1129 }
1130
1131 if (!hps)
1132 goto error;
1133
1134 HPSToHDC (hWindow, hps, NULL, NULL);
1135 pHps = (pDCData)GpiQueryDCData (hps);
1136
1137 if(!(flags & DCX_WINDOW_W))
1138 {
1139 selectClientArea(wnd, pHps);
1140 }
1141 else removeClientArea(wnd, pHps);
1142
1143 setMapMode(wnd, pHps, MM_TEXT_W);
1144
1145 if ((flags & DCX_EXCLUDERGN_W) || (flags & DCX_INTERSECTRGN_W))
1146 {
1147 ULONG BytesNeeded;
1148 PRGNDATA RgnData;
1149 PRECT pr;
1150 int i;
1151 RECTL rectl;
1152
1153 if (!hrgn)
1154 goto error;
1155
1156 success = TRUE;
1157 if (flags & DCX_EXCLUDERGN_W)
1158 {
1159#if 0 //CB: todo
1160 long height;
1161
1162 BytesNeeded = GetRegionData (hrgn, 0, NULL);
1163 RgnData = (PRGNDATA_W)_alloca (BytesNeeded);
1164 if (RgnData == NULL)
1165 goto error;
1166 GetRegionData (hrgn, BytesNeeded, RgnData);
1167
1168 i = RgnData->rdh.nCount;
1169 pr = (PRECT)(RgnData->Buffer);
1170
1171 if (flags & DCX_WINDOW_W)
1172 height = wnd->getWindowHeight();
1173 else height = wnd->getClientHeight();
1174
1175 for (; (i > 0) && success; i--, pr++) {
1176 LONG y = pr->yBottom;
1177
1178 pr->yBottom = height - pr->yTop;
1179 pr->yTop = height - y;
1180 success &= GpiExcludeClipRectangle (pHps->hps, pr);
1181 }
1182#endif
1183 }
1184 else //DCX_INTERSECTRGN_W
1185 {
1186 //SvL: I'm getting paint problems when clipping a dc created in GetDCEx
1187 // with a region that covers the entire window (RealPlayer 7 Update 1)
1188 // Using SelectClipRgn here doesn't make any difference.
1189 if(ExtSelectClipRgn(pHps->hps, hrgn, RGN_AND_W) == ERROR_W) {
1190 dprintf(("ExtSelectClipRgn failed!!"));
1191 }
1192 }
1193 if (!success)
1194 goto error;
1195 }
1196
1197 if (creatingOwnDC)
1198 wnd->setOwnDC ((HDC)hps);
1199
1200 pHps->psType = psType;
1201 pHps->hdcType = TYPE_1;
1202 //TODO: WM_SETREDRAW affects drawingAllowed flag!!
1203 GpiSetDrawControl (hps, DCTL_DISPLAY, drawingAllowed ? DCTL_ON : DCTL_OFF);
1204
1205 dprintf (("User32: GetDCEx hwnd %x (%x %x) -> hdc %x", hwnd, hrgn, flags, pHps->hps));
1206 return (HDC)pHps->hps;
1207
1208error:
1209 /* Something went wrong; clean up
1210 */
1211 dprintf(("ERROR: GetDCEx hwnd %x (%x %x) FAILED!", hwnd, hrgn, flags));
1212 DebugInt3();
1213 if (pHps)
1214 {
1215 if (pHps->hps)
1216 {
1217 if(pHps->psType == MICRO_CACHED)
1218 WinReleasePS(pHps->hps);
1219 else
1220 GpiDestroyPS(pHps->hps);
1221 }
1222
1223 if (pHps->hdc) DevCloseDC(pHps->hdc);
1224 if (pHps->hrgnHDC) GpiDestroyRegion(pHps->hps, pHps->hrgnHDC);
1225
1226 O32_DeleteObject (pHps->nullBitmapHandle);
1227 }
1228 SetLastError(ERROR_INVALID_PARAMETER_W);
1229 return NULL;
1230}
1231//******************************************************************************
1232//******************************************************************************
1233HDC WIN32API GetDC (HWND hwnd)
1234{
1235 if(!hwnd)
1236 return GetDCEx( GetDesktopWindow(), 0, DCX_CACHE_W | DCX_WINDOW_W );
1237 return GetDCEx (hwnd, NULL, 0);
1238}
1239//******************************************************************************
1240//******************************************************************************
1241HDC WIN32API GetWindowDC (HWND hwnd)
1242{
1243 if (!hwnd) hwnd = GetDesktopWindow();
1244 return GetDCEx (hwnd, NULL, DCX_WINDOW_W);
1245}
1246//******************************************************************************
1247//Helper for RedrawWindow (RDW_ALLCHILDREN_W)
1248//******************************************************************************
1249LRESULT WIN32API RedrawChildEnumProc(HWND hwnd, LPARAM lParam)
1250{
1251 RedrawWindow(hwnd, NULL, 0, lParam);
1252 return TRUE;
1253}
1254//******************************************************************************
1255// This implementation of RedrawWindow supports
1256// RDW_ERASE
1257// RDW_NOERASE
1258// RDW_INTERNALPAINT
1259// RDW_NOINTERNALPAINT
1260// RDW_INVALIDATE
1261// RDW_VALIDATE
1262// RDW_ERASENOW
1263// RDW_UPDATENOW
1264// RDW_FRAME
1265//
1266//TODO: Works ok for RDW_FRAME??
1267//******************************************************************************
1268BOOL WIN32API RedrawWindow(HWND hwnd, const RECT* pRect, HRGN hrgn, DWORD redraw)
1269{
1270 Win32BaseWindow *wnd;
1271
1272 if(pRect) {
1273 dprintf(("RedrawWindow %x (%d,%d)(%d,%d) %x %x", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom, hrgn, redraw));
1274 }
1275 else dprintf(("RedrawWindow %x %x %x %x", hwnd, pRect, hrgn, redraw));
1276
1277 if (hwnd == NULLHANDLE)
1278 {
1279#if 1
1280 // Don't do this for now (causes lots of desktop repaints in WordPad)
1281 SetLastError(ERROR_INVALID_PARAMETER_W);
1282 return FALSE;
1283#else
1284 hwnd = HWND_DESKTOP;
1285 wnd = Win32BaseWindow::GetWindowFromOS2Handle(OSLIB_HWND_DESKTOP);
1286
1287 if (!wnd)
1288 {
1289 dprintf(("USER32:dc: RedrawWindow can't find desktop window %08xh\n",
1290 hwnd));
1291 SetLastError(ERROR_INVALID_PARAMETER_W);
1292 return FALSE;
1293 }
1294#endif
1295 }
1296 else
1297 {
1298 wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
1299
1300 if (!wnd)
1301 {
1302 dprintf(("USER32:dc: RedrawWindow can't find window %08xh\n",
1303 hwnd));
1304 SetLastError(ERROR_INVALID_PARAMETER_W);
1305 return FALSE;
1306 }
1307 hwnd = wnd->getOS2WindowHandle();
1308 }
1309
1310 BOOL IncludeChildren = (redraw & RDW_ALLCHILDREN_W) ? TRUE : FALSE;
1311 BOOL success = TRUE;
1312 HPS hpsTemp = NULLHANDLE;
1313 HRGN hrgnTemp = NULLHANDLE;
1314 RECTL rectl;
1315
1316 if (hrgn)
1317 {
1318 ULONG BytesNeeded;
1319 PRGNDATA RgnData;
1320 PRECTL pr;
1321 int i;
1322 LONG height;
1323
1324 if(wnd) {
1325 height = (redraw & RDW_FRAME_W) ? wnd->getWindowHeight() : wnd->getClientHeight();
1326 }
1327 else height = OSLibQueryScreenHeight();
1328
1329 if (!hrgn)
1330 goto error;
1331
1332 BytesNeeded = GetRegionData (hrgn, 0, NULL);
1333 RgnData = (PRGNDATA)_alloca (BytesNeeded);
1334 if (RgnData == NULL)
1335 goto error;
1336 GetRegionData (hrgn, BytesNeeded, RgnData);
1337
1338 pr = (PRECTL)(RgnData->Buffer);
1339 for (i = RgnData->rdh.nCount; i > 0; i--, pr++) {
1340 LONG temp = pr->yTop;
1341 pr->yTop = height - pr->yBottom;
1342 pr->yBottom = height - temp;
1343 dprintf2(("RedrawWindow: region (%d,%d) (%d,%d)", pr->xLeft, pr->yBottom, pr->xRight, pr->yTop));
1344 }
1345
1346 hpsTemp = WinGetScreenPS (HWND_DESKTOP);
1347 hrgnTemp = GpiCreateRegion (hpsTemp, RgnData->rdh.nCount, (PRECTL)(RgnData->Buffer));
1348 if (!hrgnTemp) goto error;
1349 }
1350 else if (pRect)
1351 {
1352 if(wnd) {
1353 if(redraw & RDW_FRAME_W) {
1354 mapWin32ToOS2Rect(wnd->getWindowHeight(), (PRECT)pRect, (PRECTLOS2)&rectl);
1355 }
1356 else mapWin32ToOS2RectClientToFrame(wnd, (PRECT)pRect, (PRECTLOS2)&rectl);
1357 }
1358 else mapWin32ToOS2Rect(OSLibQueryScreenHeight(), (PRECT)pRect, (PRECTLOS2)&rectl);
1359 }
1360
1361 if (redraw & RDW_INVALIDATE_W)
1362 {
1363 //TODO: SvL: pingpong.exe doesn't have RDW_NOERASE, but doesn't want WM_ERASEBKGND msgs
1364 if (redraw & RDW_ERASE_W) {
1365 wnd->setEraseBkgnd(TRUE);
1366 }
1367 else
1368 if (redraw & RDW_NOERASE_W)
1369 wnd->setEraseBkgnd(FALSE);
1370
1371 if (!pRect && !hrgn)
1372 success = WinInvalidateRect (hwnd, NULL, IncludeChildren);
1373 else
1374 if (hrgn) {
1375 success = WinInvalidateRegion (hwnd, hrgnTemp, IncludeChildren);
1376 if(IncludeChildren && WinQueryUpdateRect(hwnd, NULL) == FALSE) {
1377 dprintf(("WARNING: WinQueryUpdateRect %x region %x returned false even though we just invalidated part of a window!!!", hwnd, hrgnTemp));
1378 success = success = WinInvalidateRegion (hwnd, hrgnTemp, FALSE);
1379 }
1380 }
1381 else {
1382 dprintf2(("WinInvalidateRect (%d,%d)(%d,%d)", rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop));
1383 success = WinInvalidateRect (hwnd, &rectl, IncludeChildren);
1384//SvL: If all children are included, then WinInvalidateRect is called
1385// with fIncludeChildren=1 -> rect of hwnd isn't invalidated if child(ren)
1386// overlap(s) the specified rectangle completely (EVEN if window doesn't
1387// have WS_CLIPCHILREN!)
1388// -> example: XWing vs Tie Fighter install window
1389// WinInvalidateRect with fIncludeChildren=0 invalidates both the parent
1390// and child windows
1391//SvL: Can't always set fIncludeChildren to FALSE or else some controls in
1392// the RealPlayer setup application aren't redrawn when invalidating
1393// their parent
1394// SO: Check if IncludeChildren is set and part of the window is invalid
1395// If not -> call WinInvalidateRect with IncludeChildren=0 to force
1396// the window rectangle to be invalidated
1397//
1398 if(IncludeChildren && WinQueryUpdateRect(hwnd, NULL) == FALSE) {
1399 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));
1400 success = WinInvalidateRect (hwnd, &rectl, FALSE);
1401 }
1402 }
1403
1404 if (!success) goto error;
1405 }
1406 else if (redraw & RDW_VALIDATE_W)
1407 {
1408 if (redraw & RDW_NOERASE_W)
1409 wnd->setEraseBkgnd(FALSE);
1410
1411 if (WinQueryUpdateRect (hwnd, NULL))
1412 {
1413 if(!pRect && !hrgn) {
1414 success = WinValidateRect (hwnd, NULL, IncludeChildren);
1415 }
1416 else
1417 if(hrgn) {
1418 success = WinValidateRegion (hwnd, hrgnTemp, IncludeChildren);
1419 }
1420 else {
1421 success = WinValidateRect (hwnd, &rectl, IncludeChildren);
1422 }
1423 if(!success) goto error;
1424 }
1425 }
1426
1427 if(WinQueryUpdateRect(hwnd, NULL))
1428 {
1429 //TODO: Does this work if RDW_ALLCHILDREN is set??
1430 if(redraw & RDW_UPDATENOW_W) {
1431 wnd->MsgNCPaint();
1432 wnd->MsgPaint(0, FALSE);
1433 }
1434 else
1435// if((redraw & RDW_ERASE_W) && (redraw & RDW_ERASENOW_W))
1436 if(redraw & RDW_ERASENOW_W && wnd->needsEraseBkgnd())
1437 wnd->setEraseBkgnd(sendEraseBkgnd(wnd) == 0);
1438// if(redraw & RDW_ALLCHILDREN_W) {
1439// EnumChildWindows(wnd->getWindowHandle(), RedrawChildEnumProc, redraw);
1440// }
1441 }
1442 else if((redraw & RDW_INTERNALPAINT_W) && !(redraw & RDW_INVALIDATE_W))
1443 {
1444 if(redraw & RDW_UPDATENOW_W) {
1445 wnd->MsgNCPaint();
1446 wnd->MsgPaint (0, FALSE);
1447 }
1448 else PostMessageA(hwnd, WINWM_PAINT, 0, 0);
1449 }
1450
1451error:
1452 /* clean up */
1453 if (hrgnTemp)
1454 GpiDestroyRegion (hpsTemp, hrgnTemp);
1455
1456 if (hpsTemp)
1457 WinReleasePS (hpsTemp);
1458
1459 if (!success) {
1460 dprintf(("RedrawWindow failure!"));
1461 SetLastError(ERROR_INVALID_PARAMETER_W);
1462 }
1463 return (success);
1464}
1465//******************************************************************************
1466//******************************************************************************
1467BOOL WIN32API UpdateWindow (HWND hwnd)
1468{
1469 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
1470
1471 if(!wnd) {
1472 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
1473 return FALSE;
1474 }
1475
1476 dprintf (("User32: UpdateWindow hwnd %x", hwnd));
1477//SvL: This doesn't work right (Wine uses RDW_NOCHILDREN_W -> doesn't work here)
1478// Breaks vpbuddy
1479// return RedrawWindow(hwnd, NULL, 0, RDW_UPDATENOW_W | RDW_ALLCHILDREN_W);
1480// -> RDW_UPDATENOW causes WM_PAINT messages to be directy posted to window
1481// handler; possibly bypassing queued WM_PAINT messages for parent window(s)
1482// -> out of sync painting (i.e. parent paints over child)
1483 WinUpdateWindow(wnd->getOS2WindowHandle());
1484 return TRUE;
1485}
1486//******************************************************************************
1487//******************************************************************************
1488BOOL WIN32API ValidateRect( HWND hwnd, const RECT * lprc)
1489{
1490 if(lprc) {
1491 dprintf(("USER32: ValidateRect %x (%d,%d)(%d,%d)", hwnd, lprc->left, lprc->top, lprc->right, lprc->bottom));
1492 }
1493 else dprintf(("USER32: ValidateRect %x", hwnd));
1494
1495 return RedrawWindow( hwnd, lprc, 0, RDW_VALIDATE_W | RDW_NOCHILDREN_W | (hwnd==0 ? RDW_UPDATENOW_W : 0));
1496}
1497//******************************************************************************
1498//******************************************************************************
1499BOOL WIN32API ValidateRgn( HWND hwnd, HRGN hrgn)
1500{
1501 dprintf(("USER32: ValidateRgn %x %x", hwnd, hrgn));
1502 return RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE_W | RDW_NOCHILDREN_W | (hwnd==0 ? RDW_UPDATENOW_W : 0));
1503}
1504//******************************************************************************
1505//******************************************************************************
1506BOOL WIN32API InvalidateRect (HWND hwnd, const RECT *pRect, BOOL erase)
1507{
1508 BOOL result;
1509
1510 if(pRect) {
1511 dprintf(("InvalidateRect %x (%d,%d)(%d,%d) erase=%d", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom, erase));
1512 }
1513 else dprintf(("InvalidateRect %x NULL erase=%d", hwnd, erase));
1514#if 1
1515 result = RedrawWindow (hwnd, pRect, NULLHANDLE,
1516 RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
1517 (erase ? RDW_ERASE_W : 0) |
1518 (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
1519#else
1520 result = RedrawWindow (hwnd, pRect, NULLHANDLE,
1521 RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
1522 (erase ? RDW_ERASE_W : RDW_NOERASE_W) |
1523 (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
1524#endif
1525 return (result);
1526}
1527//******************************************************************************
1528//******************************************************************************
1529BOOL WIN32API InvalidateRgn (HWND hwnd, HRGN hrgn, BOOL erase)
1530{
1531 BOOL result;
1532
1533 dprintf(("InvalidateRgn %x %x erase=%d", hwnd, hrgn, erase));
1534#if 1
1535 result = RedrawWindow (hwnd, NULL, hrgn,
1536 RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
1537 (erase ? RDW_ERASE_W : 0) |
1538 (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
1539#else
1540 result = RedrawWindow (hwnd, NULL, hrgn,
1541 RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
1542 (erase ? RDW_ERASE_W : RDW_NOERASE_W) |
1543 (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
1544#endif
1545 return (result);
1546}
1547//******************************************************************************
1548//TODO: Change for client rectangle!!!!!
1549//******************************************************************************
1550BOOL setPMRgnIntoWinRgn (HRGN hrgnPM, HRGN hrgnWin, LONG height)
1551{
1552 BOOL rc;
1553 HPS hps = WinGetScreenPS (HWND_DESKTOP);
1554 RGNRECT rgnRect;
1555 rgnRect.ircStart = 1;
1556 rgnRect.crc = 0;
1557 rgnRect.ulDirection = RECTDIR_LFRT_TOPBOT; // doesn't make a difference because we're getting them all
1558
1559 rc = GpiQueryRegionRects (hps, hrgnPM, NULL, &rgnRect, NULL);
1560
1561 if (rc && (rgnRect.crcReturned > 0))
1562 {
1563 PRECTL Rcls = new RECTL[rgnRect.crcReturned];
1564 PRECTL pRcl = Rcls;
1565
1566 if (Rcls != NULL)
1567 {
1568 rgnRect.crc = rgnRect.crcReturned;
1569 rc = GpiQueryRegionRects (hps, hrgnPM, NULL, &rgnRect, Rcls);
1570
1571 rc = SetRectRgn(hrgnWin, pRcl->xLeft,
1572 pRcl->xRight,
1573 height - pRcl->yTop,
1574 height - pRcl->yBottom);
1575
1576 if (rgnRect.crcReturned > 1)
1577 {
1578 int i;
1579 HRGN temp;
1580 temp = CreateRectRgn (0, 0, 1, 1);
1581
1582 for (i = 1, pRcl++; rc && (i < rgnRect.crcReturned); i++, pRcl++)
1583 {
1584 rc = SetRectRgn (temp, pRcl->xLeft,
1585 pRcl->xRight,
1586 height - pRcl->yTop,
1587 height - pRcl->yBottom);
1588 rc &= CombineRgn (hrgnWin, hrgnWin, temp, RGN_OR_W);
1589 }
1590 DeleteObject (temp);
1591 }
1592 delete[] Rcls;
1593 }
1594 else
1595 {
1596 rc = FALSE;
1597 }
1598 }
1599 else
1600 {
1601 rc = SetRectRgn (hrgnWin, 0, 0, 0, 0);
1602 }
1603
1604 WinReleasePS (hps);
1605 return (rc);
1606}
1607//******************************************************************************
1608//TODO: Check if this one works correctly...
1609//Have to check if dc is for frame or client!!
1610//******************************************************************************
1611BOOL WIN32API ScrollDC(HDC hDC, int dx, int dy, const RECT *pScroll,
1612 const RECT *pClip, HRGN hrgnUpdate, LPRECT pRectUpdate)
1613{
1614 BOOL rc = TRUE;
1615
1616 dprintf (("USER32: ScrollDC %x (%d,%d), %x %x %x %x", hDC, dx, dy, pScroll, pClip, hrgnUpdate, pRectUpdate));
1617
1618 if (!hDC)
1619 {
1620 return (FALSE);
1621 }
1622
1623 pDCData pHps = (pDCData)GpiQueryDCData ((HPS)hDC);
1624 HWND hwnd = pHps->hwnd;
1625 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
1626
1627 if ((hwnd == NULLHANDLE) || !wnd)
1628 {
1629 return (FALSE);
1630 }
1631
1632 POINTL ptl[2] = { 0, 0, dx, dy };
1633
1634 GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, ptl);
1635 dx = (int)(ptl[1].x - ptl[0].x);
1636 dy = (int)(ptl[1].y - ptl[0].y);
1637
1638 RECT scrollRect;
1639 RECT clipRect;
1640
1641 if (pClip)
1642 {
1643 memcpy(&clipRect, pClip, sizeof(clipRect));
1644
1645 if ((pHps->graphicsMode == GM_COMPATIBLE_W) &&
1646 (clipRect.left != clipRect.right) &&
1647 (clipRect.bottom != clipRect.top))
1648 {
1649 if (abs((int)pHps->viewportXExt) <= abs((int)pHps->windowExt.cx))
1650 clipRect.right -= abs(pHps->worldXDeltaFor1Pixel);
1651 else
1652 clipRect.left += abs(pHps->worldXDeltaFor1Pixel);
1653
1654 if (abs((int)pHps->viewportYExt) <= abs((int)pHps->windowExt.cy))
1655 clipRect.bottom -= abs(pHps->worldYDeltaFor1Pixel);
1656 else
1657 clipRect.top += abs(pHps->worldYDeltaFor1Pixel);
1658 }
1659 GpiConvert(pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, (PPOINTL)&clipRect);
1660 if (clipRect.right < clipRect.left) {
1661 ULONG temp = clipRect.left;
1662 clipRect.left = clipRect.right;
1663 clipRect.right = temp;
1664 }
1665 if (clipRect.bottom < clipRect.top) {
1666 ULONG temp = clipRect.top;
1667 clipRect.top = clipRect.bottom;
1668 clipRect.bottom = temp;
1669 }
1670 }
1671
1672 if (pScroll)
1673 {
1674 memcpy(&scrollRect, pScroll, sizeof(scrollRect));
1675
1676 if ((pHps->graphicsMode == GM_COMPATIBLE_W) &&
1677 (scrollRect.left != scrollRect.right) &&
1678 (scrollRect.top != scrollRect.bottom))
1679 {
1680 if (abs((int)pHps->viewportXExt) <= abs((int)pHps->windowExt.cx))
1681 scrollRect.right -= abs(pHps->worldXDeltaFor1Pixel);
1682 else
1683 scrollRect.left += abs(pHps->worldXDeltaFor1Pixel);
1684
1685 if (abs((int)pHps->viewportYExt) <= abs((int)pHps->windowExt.cy))
1686 scrollRect.bottom -= abs(pHps->worldYDeltaFor1Pixel);
1687 else
1688 scrollRect.top += abs(pHps->worldYDeltaFor1Pixel);
1689 }
1690 GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, (PPOINTL)&scrollRect);
1691 if (scrollRect.right < scrollRect.left) {
1692 ULONG temp = scrollRect.left;
1693 scrollRect.left = scrollRect.right;
1694 scrollRect.right = temp;
1695 }
1696 if (scrollRect.bottom < scrollRect.top) {
1697 ULONG temp = scrollRect.top;
1698 scrollRect.top = scrollRect.bottom;
1699 scrollRect.bottom = temp;
1700 }
1701 }
1702 RECTL rectlUpdate;
1703 HRGN hrgn;
1704 RECTL clientRect;
1705 RECTL clipOS2;
1706 RECTL scrollOS2;
1707 PRECTL pScrollOS2 = NULL;
1708 PRECTL pClipOS2 = NULL;
1709
1710 mapWin32ToOS2Rect(wnd->getWindowHeight(), wnd->getClientRectPtr(), (PRECTLOS2)&clientRect);
1711
1712 if(pScroll) {
1713 mapWin32ToOS2RectClientToFrame(wnd, &scrollRect, (PRECTLOS2)&scrollOS2);
1714 pScrollOS2 = &scrollOS2;
1715
1716 //Scroll rectangle relative to client area
1717 WinIntersectRect ((HAB) 0, pScrollOS2, pScrollOS2, &clientRect);
1718 }
1719 else {
1720 pScrollOS2 = &clientRect;
1721 }
1722
1723 if(pClip) {
1724 mapWin32ToOS2RectClientToFrame(wnd, &clipRect, (PRECTLOS2)&clipOS2);
1725 pClipOS2 = &clipOS2;
1726
1727 //Clip rectangle relative to client area
1728 WinIntersectRect((HAB) 0, pClipOS2, pClipOS2, &clientRect);
1729 }
1730 else {
1731 pClipOS2 = &clientRect;
1732 }
1733
1734 LONG lComplexity = WinScrollWindow(hwnd, dx, dy, pScrollOS2,
1735 pClipOS2, hrgn, &rectlUpdate, 0);
1736 if (lComplexity == RGN_ERROR)
1737 {
1738 return (FALSE);
1739 }
1740
1741 RECT winRectUpdate;
1742
1743 mapOS2ToWin32Rect(wnd->getWindowHeight(), (PRECTLOS2)&rectlUpdate, &winRectUpdate);
1744
1745 if (pRectUpdate)
1746 *pRectUpdate = winRectUpdate;
1747
1748 if (hrgnUpdate)
1749 rc = setPMRgnIntoWinRgn(hrgn, hrgnUpdate, wnd->getWindowHeight());
1750
1751 return (rc);
1752}
1753//******************************************************************************
1754//SvL: Using WinScrollWindow to scroll child windows is better (smoother).
1755//******************************************************************************
1756INT WIN32API ScrollWindowEx(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip,
1757 HRGN hrgnUpdate, PRECT pRectUpdate, UINT scrollFlag)
1758{
1759 Win32BaseWindow *window;
1760 APIRET rc;
1761 RECTL clientRect;
1762 RECTL scrollRect;
1763 RECTL clipRect;
1764 PRECTL pScrollOS2 = NULL;
1765 PRECTL pClipOS2 = NULL;
1766 ULONG scrollFlagsOS2 = 0;
1767 int orgdy = dy;
1768 int regionType = ERROR_W;
1769
1770 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1771 if(!window) {
1772 dprintf(("ScrollWindowEx, window %x not found", hwnd));
1773 return 0;
1774 }
1775
1776 dprintf(("ScrollWindowEx %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip));
1777
1778 dy = revertDy (window, dy);
1779
1780 if (scrollFlag & SW_INVALIDATE_W) scrollFlagsOS2 |= SW_INVALIDATERGN;
1781 if (scrollFlag & SW_SCROLLCHILDREN_W) scrollFlagsOS2 |= SW_SCROLLCHILDREN;
1782
1783 mapWin32ToOS2Rect(window->getWindowHeight(), window->getClientRectPtr(), (PRECTLOS2)&clientRect);
1784
1785 if(pScroll) {
1786 mapWin32ToOS2RectClientToFrame(window,(RECT *)pScroll, (PRECTLOS2)&scrollRect);
1787 pScrollOS2 = &scrollRect;
1788
1789 //Scroll rectangle relative to client area
1790 WinIntersectRect ((HAB) 0, pScrollOS2, pScrollOS2, &clientRect);
1791 }
1792 else {
1793 pScrollOS2 = &clientRect;
1794 }
1795
1796 if(pClip) {
1797 mapWin32ToOS2RectClientToFrame(window,(RECT *)pClip, (PRECTLOS2)&clipRect);
1798 pClipOS2 = &clipRect;
1799
1800 //Clip rectangle relative to client area
1801 WinIntersectRect ((HAB) 0, pClipOS2, pClipOS2, &clientRect);
1802 }
1803 else {
1804 pClipOS2 = &clientRect;
1805 }
1806
1807 RECTL rectlUpdate;
1808 HRGN hrgn;
1809
1810 if (scrollFlag & SW_SMOOTHSCROLL_W)
1811 {
1812 INT time = (scrollFlag >> 16) & 0xFFFF;
1813
1814 //CB: todo, scroll in several steps
1815 // is time in ms? time <-> iteration count?
1816 }
1817
1818 LONG lComplexity = WinScrollWindow (window->getOS2WindowHandle(), dx, dy,
1819 pScrollOS2,
1820 pClipOS2,
1821 hrgn, &rectlUpdate, scrollFlagsOS2);
1822 if (lComplexity == RGN_ERROR)
1823 {
1824 return ERROR_W;
1825 }
1826
1827 //Notify children that they have moved (according to the SDK docs,
1828 //they only receive a WM_MOVE message)
1829 //(PM only does this for windows with CS_MOVENOTIFY class)
1830 //TODO: Verify this (no WM_WINDOWPOSCHANGING/ED?)
1831 if (scrollFlag & SW_SCROLLCHILDREN_W)
1832 {
1833 HWND hwndChild;
1834 RECT rectChild, rc;
1835
1836 dprintf(("ScrollWindowEx: Scroll child windows"));
1837 GetClientRect(hwnd, &rc);
1838 if (pScroll) IntersectRect(&rc, &rc, pScroll);
1839
1840 hwndChild = GetWindow(hwnd, GW_CHILD_W);
1841
1842 while(hwndChild)
1843 {
1844 Win32BaseWindow *child;
1845
1846 child = Win32BaseWindow::GetWindowFromHandle(hwndChild);
1847 if(!child) {
1848 dprintf(("ERROR: ScrollWindowEx, child %x not found", hwnd));
1849 return 0;
1850 }
1851 rectChild = *child->getWindowRect();
1852 if(!pRectUpdate || IntersectRect(&rectChild, &rectChild, &rc))
1853 {
1854 dprintf(("ScrollWindowEx: Scroll child window %x", hwndChild));
1855 child->ScrollWindow(dx, orgdy);
1856 }
1857 hwndChild = GetWindow(hwndChild, GW_HWNDNEXT_W);
1858 }
1859 dprintf(("***ScrollWindowEx: Scroll child windows DONE"));
1860 }
1861
1862 RECT winRectUpdate;
1863
1864 mapOS2ToWin32Rect(window->getWindowHeight(), (PRECTLOS2)&rectlUpdate, &winRectUpdate);
1865
1866 if (pRectUpdate)
1867 *pRectUpdate = winRectUpdate;
1868
1869 if (hrgnUpdate)
1870 rc = setPMRgnIntoWinRgn (hrgn, hrgnUpdate, window->getWindowHeight());
1871
1872#if 0
1873 //SvL: WinScrollWindow already invalidates the area; no need to do it again
1874 //(call to invalidateRect was wrong; has to include erase flag)
1875 if ((scrollFlag & SW_INVALIDATE_W) &&
1876 ((lComplexity == RGN_RECT) || (lComplexity == RGN_COMPLEX)))
1877 {
1878 rc = RedrawWindow (hwnd, &winRectUpdate, NULLHANDLE,
1879 RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
1880 ((scrollFlag & SW_ERASE_W) ? RDW_ERASE_W : 0) |
1881 RDW_UPDATENOW_W);
1882
1883// rc = InvalidateRect (hwnd, &winRectUpdate, (scrollFlag & SW_ERASE_W) ? 1 : 0);
1884 if (rc == FALSE)
1885 {
1886 return (0);
1887 }
1888 }
1889#endif
1890
1891 switch (lComplexity)
1892 {
1893 case RGN_NULL:
1894 regionType = NULLREGION_W;
1895 break;
1896 case RGN_RECT:
1897 regionType = SIMPLEREGION_W;
1898 break;
1899 case RGN_COMPLEX:
1900 regionType = COMPLEXREGION_W;
1901 break;
1902 default:
1903 regionType = ERROR_W;
1904 break;
1905 }
1906
1907 return (regionType);
1908}
1909//******************************************************************************
1910//******************************************************************************
1911BOOL WIN32API ScrollWindow(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip)
1912{
1913 Win32BaseWindow *window;
1914
1915 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1916 if(!window) {
1917 dprintf(("ScrollWindow, window %x not found", hwnd));
1918 return 0;
1919 }
1920 dprintf(("ScrollWindow %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip));
1921 return (ERROR_W != ScrollWindowEx(hwnd, dx, dy, pScroll, pClip, 0, NULL,
1922 (pScroll ? 0 : SW_SCROLLCHILDREN_W) |
1923 SW_INVALIDATE_W ));
1924}
1925//******************************************************************************
1926//******************************************************************************
1927HWND WIN32API WindowFromDC(HDC hdc)
1928{
1929 pDCData pHps = (pDCData)GpiQueryDCData( (HPS)hdc );
1930
1931 dprintf2(("USER32: WindowFromDC %x", hdc));
1932 if ( pHps )
1933 return OS2ToWin32Handle(pHps->hwnd);
1934 else
1935 return 0;
1936}
1937//******************************************************************************
1938//******************************************************************************
1939#ifdef DEBUG
1940void dprintfOrigin(HDC hdc)
1941{
1942 POINTL point;
1943
1944 pDCData pHps = (pDCData)GpiQueryDCData((HPS)hdc);
1945 if(!pHps)
1946 {
1947 return;
1948 }
1949
1950 GreGetDCOrigin(pHps->hps, &point);
1951 dprintf(("HDC %x origin (%d,%d) org (%d,%d)", hdc, point.x, point.y, pHps->ptlOrigin.x, pHps->ptlOrigin.y));
1952}
1953#endif
1954//******************************************************************************
1955//******************************************************************************
Note: See TracBrowser for help on using the repository browser.