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

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

BeginPaint bugfix

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