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

Last change on this file since 10379 was 10379, checked in by sandervl, 22 years ago

Update

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