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

Last change on this file since 5189 was 5189, checked in by sandervl, 25 years ago

Invalidation after resize fix

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