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

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

BeginPaint fix

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