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

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

DeleteDC check for DIB section + SelectObject fixes

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