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

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

update

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