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

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

window tracking rewrite + getdcex change (clipping)

File size: 55.2 KB
Line 
1/* $Id: dc.cpp,v 1.112 2001-10-03 18:37:51 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(DbgEnabledLvl2USER32[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 pHps->isClient = FALSE;
390 pHps->isClientArea = FALSE;
391}
392//******************************************************************************
393//******************************************************************************
394void selectClientArea(Win32BaseWindow *window, pDCData pHps)
395{
396 pHps->isClient = TRUE;
397 pHps->isClientArea = TRUE;
398}
399//******************************************************************************
400//******************************************************************************
401void selectClientArea(Win32BaseWindow *wnd, HDC hdc)
402{
403 pDCData pHps = (pDCData)GpiQueryDCData (wnd->getOwnDC());
404
405 if (pHps != NULLHANDLE)
406 selectClientArea(wnd, pHps);
407}
408//******************************************************************************
409//******************************************************************************
410LONG clientHeight(Win32BaseWindow *wnd, HWND hwnd, pDCData pHps)
411{
412 if ((hwnd == 0) && (pHps != 0))
413 hwnd = pHps->hwnd;
414
415 if ((hwnd != 0) || (pHps == 0))
416 {
417 if(wnd) {
418 if(pHps && !pHps->isClientArea) {
419 return (wnd->getWindowHeight());
420 }
421 else return (wnd->getClientHeight());
422 }
423 else return OSLibQueryScreenHeight();
424 }
425 else if (pHps->bitmapHandle)
426 {
427 return pHps->bitmapHeight;
428 }
429 else if (pHps->isMetaPS)
430 {
431 return 0;
432 }
433 else if (pHps->isPrinter)
434 {
435 return pHps->printPageHeight;
436 }
437 else
438 {
439 return MEM_HPS_MAX;
440 }
441}
442//******************************************************************************
443//******************************************************************************
444BOOL WIN32API changePageXForm(pDCData pHps, PPOINTL pValue, int x, int y, PPOINTL pPrev)
445{
446 Win32BaseWindow *wnd;
447
448 if(pHps->isClient) {
449 wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
450 }
451 else wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(pHps->hwnd);
452 BOOL ret = changePageXForm(wnd, pHps, pValue, x, y, pPrev);
453 if(wnd) RELEASE_WNDOBJ(wnd);
454 return ret;
455}
456//******************************************************************************
457//******************************************************************************
458BOOL WIN32API setPageXForm(pDCData pHps)
459{
460 Win32BaseWindow *wnd;
461
462 if(pHps->isClient) {
463 wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
464 }
465 else wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(pHps->hwnd);
466 BOOL ret = setPageXForm(wnd, pHps);
467 if(wnd) RELEASE_WNDOBJ(wnd);
468 return ret;
469}
470//******************************************************************************
471//******************************************************************************
472VOID WIN32API removeClientArea(pDCData pHps)
473{
474 Win32BaseWindow *wnd;
475
476 if(pHps->isClient) {
477 wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
478 }
479 else wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(pHps->hwnd);
480 if(wnd) {
481 removeClientArea(wnd, pHps);
482 RELEASE_WNDOBJ(wnd);
483 }
484}
485//******************************************************************************
486//******************************************************************************
487VOID WIN32API selectClientArea(pDCData pHps)
488{
489 Win32BaseWindow *wnd;
490
491 if(pHps->isClient) {
492 wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
493 }
494 else wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(pHps->hwnd);
495 if(wnd) {
496 selectClientArea(wnd, pHps);
497 RELEASE_WNDOBJ(wnd);
498 }
499}
500//******************************************************************************
501//******************************************************************************
502VOID WIN32API checkOrigin(pDCData pHps)
503{
504 Win32BaseWindow *wnd;
505
506 if(pHps->isClient) {
507 wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
508 }
509 else wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(pHps->hwnd);
510 if(wnd) {
511 if(pHps->isClient)
512 selectClientArea(wnd, pHps);
513 RELEASE_WNDOBJ(wnd);
514 }
515}
516//******************************************************************************
517//******************************************************************************
518LONG WIN32API clientHeight(HWND hwnd, pDCData pHps)
519{
520 Win32BaseWindow *wnd;
521
522 if(!pHps) {
523 wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
524 }
525 else
526 if(pHps->isClient) {
527 wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
528 }
529 else wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(pHps->hwnd);
530 LONG ret = clientHeight(wnd, hwnd, pHps);
531 if(wnd) RELEASE_WNDOBJ(wnd);
532 return ret;
533}
534//******************************************************************************
535//******************************************************************************
536int WIN32API setMapModeDC(pDCData pHps, int mode)
537{
538 Win32BaseWindow *wnd;
539
540 if(pHps->isClient) {
541 wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
542 }
543 else wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(pHps->hwnd);
544 int ret = setMapMode(wnd, pHps, mode);
545 if(wnd) RELEASE_WNDOBJ(wnd);
546 return ret;
547}
548//******************************************************************************
549//******************************************************************************
550BOOL isYup (pDCData pHps)
551{
552 if (((pHps->windowExt.cy < 0) && (pHps->viewportYExt > 0.0)) ||
553 ((pHps->windowExt.cy > 0) && (pHps->viewportYExt < 0.0)))
554 {
555 if ((pHps->graphicsMode == GM_COMPATIBLE_W) ||
556 ((pHps->graphicsMode == GM_ADVANCED_W) && (pHps->xform.eM22 >= 0.0)))
557 return TRUE;
558 }
559 else
560 {
561 if ((pHps->graphicsMode == GM_ADVANCED_W) && (pHps->xform.eM22 < 0.0))
562 return TRUE;
563 }
564 return FALSE;
565}
566//******************************************************************************
567//******************************************************************************
568INT revertDy (Win32BaseWindow *wnd, INT dy)
569{
570 //SvL: Hack for memory.exe (doesn't get repainted properly otherwise)
571// if (wnd->isOwnDC() && wnd->getOwnDC())
572 if (wnd->isOwnDC())
573 {
574 pDCData pHps = (pDCData)GpiQueryDCData (wnd->getOwnDC());
575
576 if (pHps != NULLHANDLE)
577 if (!isYup (pHps))
578 dy = -dy;
579 }
580 else
581 {
582 dy = -dy;
583 }
584 return (dy);
585}
586//******************************************************************************
587//******************************************************************************
588HDC sendEraseBkgnd (Win32BaseWindow *wnd)
589{
590 BOOL erased;
591 HWND hwnd;
592 HDC hdc;
593 HPS hps;
594 HRGN hrgnUpdate, hrgnOld, hrgnClip, hrgnCombined;
595 RECTL rectl = { 1, 1, 2, 2 };
596
597 hwnd = wnd->getOS2WindowHandle();
598 hps = WinGetPS(hwnd);
599
600 hrgnUpdate = GpiCreateRegion (hps, 1, &rectl);
601 WinQueryUpdateRegion (hwnd, hrgnUpdate);
602 hrgnClip = GpiQueryClipRegion (hps);
603
604 if (hrgnClip == NULLHANDLE)
605 {
606 GpiSetClipRegion (hps, hrgnUpdate, &hrgnOld);
607 }
608 else
609 {
610 hrgnCombined = GpiCreateRegion (hps, 1, &rectl);
611 GpiCombineRegion (hps, hrgnCombined, hrgnClip, hrgnUpdate, CRGN_AND);
612 GpiSetClipRegion (hps, hrgnCombined, &hrgnOld);
613 GpiDestroyRegion (hps, hrgnUpdate);
614 GpiDestroyRegion (hps, hrgnClip);
615 }
616 if (hrgnOld != NULLHANDLE)
617 GpiDestroyRegion (hps, hrgnOld);
618
619 hdc = HPSToHDC (hwnd, hps, NULL, NULL);
620
621 erased = wnd->MsgEraseBackGround (hdc);
622
623 DeleteHDC (hdc);
624 WinReleasePS (hps);
625
626 return erased;
627}
628//******************************************************************************
629//******************************************************************************
630void releaseOwnDC (HDC hps)
631{
632 pDCData pHps = (pDCData)GpiQueryDCData ((HPS)hps);
633
634 dprintf2(("releaseOwnDC %x", hps));
635
636 if (pHps) {
637 if (pHps->hrgnHDC)
638 GpiDestroyRegion (pHps->hps, pHps->hrgnHDC);
639
640 GpiSetBitmap (pHps->hps, NULL);
641 O32_DeleteObject (pHps->nullBitmapHandle);
642 GpiDestroyPS(pHps->hps);
643
644 if (pHps->hdc)
645 DevCloseDC(pHps->hdc);
646 }
647}
648//******************************************************************************
649//******************************************************************************
650HDC WIN32API BeginPaint (HWND hWnd, PPAINTSTRUCT_W lpps)
651{
652 HWND hwnd = hWnd ? hWnd : HWND_DESKTOP;
653 pDCData pHps = NULLHANDLE;
654 HPS hPS_ownDC = NULLHANDLE, hpsPaint = 0;
655 RECTL rectl = {0, 0, 1, 1};
656 HRGN hrgnOldClip;
657 LONG lComplexity;
658 RECTL rectlClient;
659 RECTL rectlClip;
660
661 if(lpps == NULL) {
662 //BeginPaint does NOT change last error in this case
663 //(verified in NT4, SP6)
664 dprintf (("USER32: BeginPaint %x NULL PAINTSTRUCT pointer", hWnd));
665 return 0;
666 }
667 memset(lpps, 0, sizeof(*lpps));
668
669 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
670 if(!wnd) {
671 dprintf (("USER32: BeginPaint %x %x: invalid window handle!!", hWnd, lpps));
672 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W); //(verified in NT4, SP6)
673 return (HDC)0;
674 }
675 HWND hwndClient = wnd->getOS2WindowHandle();
676
677 if(hwnd != HWND_DESKTOP && wnd->isOwnDC())
678 {
679 hPS_ownDC = wnd->getOwnDC();
680 //SvL: Hack for memory.exe (doesn't get repainted properly otherwise)
681 if(hPS_ownDC) {
682 pHps = (pDCData)GpiQueryDCData(hPS_ownDC);
683 if (!pHps)
684 {
685 dprintf (("USER32: BeginPaint %x invalid parameter %x", hWnd, lpps));
686 RELEASE_WNDOBJ(wnd);
687 SetLastError(ERROR_INVALID_PARAMETER_W);
688 return (HDC)NULLHANDLE;
689 }
690 hpsPaint = hPS_ownDC;
691 }
692 }
693 if(!hpsPaint) {
694 hpsPaint = GetDCEx(hwnd, 0, (DCX_CACHE_W|DCX_USESTYLE_W));
695 pHps = (pDCData)GpiQueryDCData(hpsPaint);
696 if (!pHps)
697 {
698 dprintf (("USER32: BeginPaint %x invalid parameter %x", hWnd, lpps));
699 RELEASE_WNDOBJ(wnd);
700 SetLastError(ERROR_INVALID_PARAMETER_W);
701 return (HDC)NULLHANDLE;
702 }
703 }
704
705 if(WinQueryUpdateRect(hwndClient, &rectl) == FALSE)
706 {
707 memset(&rectl, 0, sizeof(rectl));
708 dprintf (("USER32: WARNING: WinQueryUpdateRect failed (error or no update rectangle)!!"));
709
710 HRGN hrgnClip = GpiCreateRegion(pHps->hps, 1, &rectl);
711 GpiSetClipRegion(pHps->hps, hrgnClip, &hrgnOldClip);
712
713 selectClientArea(wnd, pHps);
714
715 //save old clip region (restored for CS_OWNDC windows in EndPaint)
716 wnd->SetClipRegion(hrgnOldClip);
717 lComplexity = RGN_NULL;
718 }
719 else {
720 rectlClip.yBottom = rectlClip.xLeft = 0;
721 rectlClip.yTop = rectlClip.xRight = 1;
722
723 //Query update region
724 HRGN hrgnClip = GpiCreateRegion(pHps->hps, 1, &rectlClip);
725 WinQueryUpdateRegion(hwndClient, hrgnClip);
726 WinValidateRegion(hwndClient, hrgnClip, FALSE);
727
728 dprintfRegion(pHps->hps, wnd->getWindowHandle(), hrgnClip);
729
730#ifdef DEBUG
731 //Note: GpiQueryClipBox returns logical points
732 lComplexity = GpiQueryClipBox(pHps->hps, &rectlClip);
733 dprintf(("ClipBox (%d): (%d,%d)(%d,%d)", lComplexity, rectlClip.xLeft, rectlClip.yBottom, rectlClip.xRight, rectlClip.yTop));
734#endif
735
736 //set clip region
737 lComplexity = GpiSetClipRegion(pHps->hps, hrgnClip, &hrgnOldClip);
738
739 if(lComplexity == RGN_NULL) {
740 dprintf (("BeginPaint %x: EMPTY update rectangle (show=%d/%d vis=%d/%d", hWnd, WinIsWindowVisible(wnd->getOS2FrameWindowHandle()), WinIsWindowVisible(wnd->getOS2WindowHandle()), WinIsWindowShowing(wnd->getOS2FrameWindowHandle()), WinIsWindowShowing(wnd->getOS2WindowHandle())));
741 }
742 else dprintf (("BeginPaint %x: (show=%d/%d vis=%d/%d)", hWnd, WinIsWindowVisible(wnd->getOS2FrameWindowHandle()), WinIsWindowVisible(wnd->getOS2WindowHandle()), WinIsWindowShowing(wnd->getOS2FrameWindowHandle()), WinIsWindowShowing(wnd->getOS2WindowHandle())));
743
744 selectClientArea(wnd, pHps);
745
746#ifdef DEBUG
747 //Note: GpiQueryClipBox returns logical points
748 GpiQueryClipBox(pHps->hps, &rectlClip);
749 dprintf(("ClipBox (%d): (%d,%d)(%d,%d)", lComplexity, rectlClip.xLeft, rectlClip.yBottom, rectlClip.xRight, rectlClip.yTop));
750#endif
751 //save old clip region (restored for CS_OWNDC windows in EndPaint)
752 wnd->SetClipRegion(hrgnOldClip);
753 }
754
755 if(hPS_ownDC == 0)
756 setMapMode (wnd, pHps, MM_TEXT_W);
757 else
758 setPageXForm(wnd, pHps);
759
760 pHps->hdcType = TYPE_3;
761
762 HideCaret(hwnd);
763 WinShowTrackRect(wnd->getOS2WindowHandle(), FALSE);
764
765 if((wnd->needsEraseBkgnd() || wnd->IsVisibleRegionChanged()) && lComplexity != RGN_NULL) {
766 wnd->setEraseBkgnd(FALSE);
767 wnd->SetVisibleRegionChanged(FALSE);
768 lpps->fErase = (wnd->MsgEraseBackGround(pHps->hps) == 0);
769 }
770 else lpps->fErase = TRUE;
771
772 lpps->hdc = (HDC)pHps->hps;
773
774 if(lComplexity != RGN_NULL) {
775 long height = wnd->getClientHeight();
776 lpps->rcPaint.top = height - rectl.yTop;
777 lpps->rcPaint.left = rectl.xLeft;
778 lpps->rcPaint.bottom = height - rectl.yBottom;
779 lpps->rcPaint.right = rectl.xRight;
780 //BeginPaint must return logical points instead of device points.
781 //(not the same if e.g. app changes page viewport)
782 DPtoLP(lpps->hdc, (LPPOINT)&lpps->rcPaint, 2);
783 }
784 else {
785 lpps->rcPaint.bottom = lpps->rcPaint.top = 0;
786 lpps->rcPaint.right = lpps->rcPaint.left = 0;
787 }
788 RELEASE_WNDOBJ(wnd);
789
790 SetLastError(0);
791 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));
792 return (HDC)pHps->hps;
793}
794//******************************************************************************
795//******************************************************************************
796BOOL WIN32API EndPaint (HWND hWnd, const PAINTSTRUCT_W *pPaint)
797{
798 HWND hwnd = hWnd ? hWnd : HWND_DESKTOP;
799 HRGN hrgnOld;
800 pDCData pHps;
801
802 dprintf (("USER32: EndPaint(%x)", hwnd));
803
804 if (!pPaint || !pPaint->hdc )
805 return TRUE;
806
807 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
808
809 if (!wnd) goto exit;
810
811 pHps = (pDCData)GpiQueryDCData((HPS)pPaint->hdc);
812 if (pHps && (pHps->hdcType == TYPE_3))
813 {
814 GpiSetClipRegion(pHps->hps, wnd->GetClipRegion(), &hrgnOld);
815 wnd->SetClipRegion(0);
816 if(hrgnOld) {
817 GpiDestroyRegion(pHps->hps, hrgnOld);
818 }
819 pHps->hdcType = TYPE_1; //otherwise Open32's ReleaseDC fails
820 ReleaseDC(hwnd, pPaint->hdc);
821 }
822 else {
823 dprintf(("EndPaint: wrong hdc %x!!", pPaint->hdc));
824 }
825 wnd->setEraseBkgnd(TRUE);
826 ShowCaret(hwnd);
827 WinShowTrackRect(wnd->getOS2WindowHandle(), TRUE);
828
829exit:
830 if(wnd) RELEASE_WNDOBJ(wnd);
831 SetLastError(0);
832 return TRUE;
833}
834//******************************************************************************
835//******************************************************************************
836int WIN32API ReleaseDC (HWND hwnd, HDC hdc)
837{
838 BOOL isOwnDC = FALSE;
839 int rc;
840
841 if (hwnd)
842 {
843 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
844 if(wnd == NULL) {
845 dprintf(("ERROR: ReleaseDC %x %x failed", hwnd, hdc));
846 return 0;
847 }
848 isOwnDC = wnd->isOwnDC() && (wnd->getOwnDC() == hdc);
849 if(!isOwnDC)
850 {
851 pDCData pHps = (pDCData)GpiQueryDCData((HPS)hdc);
852 if(pHps && pHps->psType == MICRO_CACHED) {
853 removeClientArea(wnd, pHps);
854 if(pHps->hrgnVis) {
855 GreDestroyRegion(pHps->hps, pHps->hrgnVis);
856 pHps->hrgnVis = 0;
857 }
858 }
859 else {
860 dprintf(("ERROR: ReleaseDC: pHps == NULL!!"));
861 DebugInt3();
862 }
863 }
864 else {
865 dprintf2(("ReleaseDC: CS_OWNDC, not released"));
866 }
867 RELEASE_WNDOBJ(wnd);
868 }
869
870 if(isOwnDC) {
871 rc = TRUE;
872 }
873 else {
874 UnselectGDIObjects(hdc);
875 rc = O32_ReleaseDC (0, hdc);
876 }
877
878 dprintf(("ReleaseDC %x %x", hwnd, hdc));
879 return (rc);
880}
881//******************************************************************************
882// This implementation of GetDCEx supports
883// DCX_WINDOW
884// DCX_CACHE
885// DCX_EXCLUDERGN (complex regions allowed)
886// DCX_INTERSECTRGN (complex regions allowed)
887// DCX_USESTYLE
888// DCX_CLIPSIBLINGS
889// DCX_CLIPCHILDREN
890// DCX_PARENTCLIP
891//
892//TODO: WM_SETREDRAW affects drawingAllowed flag!!
893//******************************************************************************
894HDC WIN32API GetDCEx (HWND hwnd, HRGN hrgn, ULONG flags)
895{
896 Win32BaseWindow *wnd = NULL;
897 HWND hWindow;
898 BOOL success;
899 pDCData pHps = NULL;
900 HPS hps = NULLHANDLE;
901 BOOL drawingAllowed = TRUE;
902 BOOL isWindowOwnDC;
903 BOOL creatingOwnDC = FALSE;
904 PS_Type psType;
905
906 if(hwnd == 0) {
907 dprintf(("error: GetDCEx window %x not found", hwnd));
908 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
909 return 0;
910 }
911
912 if(hwnd)
913 {
914 wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
915 if(wnd == NULL) {
916 dprintf (("ERROR: User32: GetDCEx bad window handle %X!!!!!", hwnd));
917 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
918 return 0;
919 }
920 if(flags & DCX_WINDOW_W) {
921 hWindow = wnd->getOS2FrameWindowHandle();
922 }
923 else hWindow = wnd->getOS2WindowHandle();
924 }
925
926 isWindowOwnDC = (((hWindow == HWND_DESKTOP) ? FALSE : (wnd->isOwnDC()))
927 && !(flags & (DCX_CACHE_W|DCX_WINDOW_W)));
928
929 if(isWindowOwnDC) //own dc always for client area
930 {
931 hps = wnd->getOwnDC();
932 if (hps)
933 {
934 pDCData pHps = (pDCData)GpiQueryDCData (hps);
935 if (!pHps)
936 goto error;
937
938 selectClientArea(wnd, pHps);
939
940 //TODO: Is this always necessary??
941 setPageXForm (wnd, pHps);
942 pHps->hdcType = TYPE_1;
943
944 //TODO: intersect/exclude clip region?
945 dprintf (("User32: GetDCEx hwnd %x (%x %x) -> wnd %x hdc %x", hwnd, hrgn, flags, wnd, hps));
946
947 RELEASE_WNDOBJ(wnd);
948 return (HDC)hps;
949 }
950 else creatingOwnDC = TRUE;
951 }
952
953 if(isWindowOwnDC)
954 {
955 SIZEL sizel = {0,0};
956 hps = GpiCreatePS (WinQueryAnchorBlock (hWindow),
957 WinOpenWindowDC (hWindow),
958 &sizel, PU_PELS | GPIT_MICRO | GPIA_ASSOC );
959 psType = MICRO;
960 // default cp is OS/2 one: set to windows default (ODIN.INI)
961 GpiSetCp(hps, GetDisplayCodepage());
962 }
963 else
964 {
965 if (hWindow == HWND_DESKTOP) {
966 hps = WinGetScreenPS (hWindow);
967 }
968 else {
969 int clipstyle = 0;
970 int clipwnd = HWND_TOP;
971 if(flags & (DCX_USESTYLE_W))
972 {
973 int style = wnd->getStyle();
974 if(style & WS_CLIPCHILDREN_W) {
975 clipstyle |= PSF_CLIPCHILDREN;
976 }
977 if(style & WS_CLIPSIBLINGS_W) {
978 clipstyle |= PSF_CLIPSIBLINGS;
979 }
980 if(wnd->fHasParentDC()) {
981 clipstyle |= PSF_PARENTCLIP;
982 }
983 }
984 if(flags & DCX_CLIPSIBLINGS_W) {
985 clipstyle |= PSF_CLIPSIBLINGS;
986 }
987 if(flags & DCX_CLIPCHILDREN_W) {
988 clipstyle |= PSF_CLIPCHILDREN;
989 }
990 if(flags & DCX_PARENTCLIP_W) {
991 clipstyle |= PSF_PARENTCLIP;
992 }
993 //Always call WinGetClipPS; WinGetPS takes window & class style
994 //into account
995// if(clipstyle || !(flags & DCX_DEFAULTCLIP_W)) {
996 dprintf2(("WinGetClipPS style %x", clipstyle));
997 hps = WinGetClipPS(hWindow, clipwnd, clipstyle);
998// }
999// else hps = WinGetPS (hWindow);
1000
1001 // default cp is OS/2 one: set to windows default (ODIN.INI)
1002 GpiSetCp(hps, GetDisplayCodepage());
1003 }
1004 psType = MICRO_CACHED;
1005 }
1006
1007 if (!hps)
1008 goto error;
1009
1010 HPSToHDC (hWindow, hps, NULL, NULL);
1011 pHps = (pDCData)GpiQueryDCData (hps);
1012
1013 if(flags & DCX_WINDOW_W) {
1014 removeClientArea(wnd, pHps);
1015 }
1016 else selectClientArea(wnd, pHps);
1017
1018 setMapMode(wnd, pHps, MM_TEXT_W);
1019
1020 if ((flags & DCX_EXCLUDERGN_W) || (flags & DCX_INTERSECTRGN_W))
1021 {
1022 ULONG BytesNeeded;
1023 PRGNDATA RgnData;
1024 PRECT pr;
1025 int i;
1026 RECTL rectl;
1027
1028 if (!hrgn)
1029 goto error;
1030
1031 success = TRUE;
1032 if (flags & DCX_EXCLUDERGN_W)
1033 {
1034#if 0 //CB: todo
1035 long height;
1036
1037 BytesNeeded = GetRegionData (hrgn, 0, NULL);
1038 RgnData = (PRGNDATA_W)_alloca (BytesNeeded);
1039 if (RgnData == NULL)
1040 goto error;
1041 GetRegionData (hrgn, BytesNeeded, RgnData);
1042
1043 i = RgnData->rdh.nCount;
1044 pr = (PRECT)(RgnData->Buffer);
1045
1046 if (flags & DCX_WINDOW_W)
1047 height = wnd->getWindowHeight();
1048 else height = wnd->getClientHeight();
1049
1050 for (; (i > 0) && success; i--, pr++) {
1051 LONG y = pr->yBottom;
1052
1053 pr->yBottom = height - pr->yTop;
1054 pr->yTop = height - y;
1055 success &= GpiExcludeClipRectangle (pHps->hps, pr);
1056 }
1057#endif
1058 }
1059 else //DCX_INTERSECTRGN_W
1060 {
1061 //SvL: I'm getting paint problems when clipping a dc created in GetDCEx
1062 // with a region that covers the entire window (RealPlayer 7 Update 1)
1063 // Using SelectClipRgn here doesn't make any difference.
1064 if(ExtSelectClipRgn(pHps->hps, hrgn, RGN_AND_W) == ERROR_W) {
1065 dprintf(("ExtSelectClipRgn failed!!"));
1066 }
1067 }
1068 if (!success)
1069 goto error;
1070 }
1071
1072 if (creatingOwnDC)
1073 wnd->setOwnDC ((HDC)hps);
1074
1075 pHps->psType = psType;
1076 pHps->hdcType = TYPE_1;
1077 //TODO: WM_SETREDRAW affects drawingAllowed flag!!
1078 GpiSetDrawControl (hps, DCTL_DISPLAY, drawingAllowed ? DCTL_ON : DCTL_OFF);
1079
1080 dprintf (("User32: GetDCEx hwnd %x (%x %x) -> hdc %x", hwnd, hrgn, flags, pHps->hps));
1081 RELEASE_WNDOBJ(wnd);
1082
1083 return (HDC)pHps->hps;
1084
1085error:
1086 /* Something went wrong; clean up
1087 */
1088 dprintf(("ERROR: GetDCEx hwnd %x (%x %x) FAILED!", hwnd, hrgn, flags));
1089 DebugInt3();
1090 if (pHps)
1091 {
1092 if (pHps->hps)
1093 {
1094 if(pHps->psType == MICRO_CACHED)
1095 WinReleasePS(pHps->hps);
1096 else
1097 GpiDestroyPS(pHps->hps);
1098 }
1099
1100 if (pHps->hdc) DevCloseDC(pHps->hdc);
1101 if (pHps->hrgnHDC) GpiDestroyRegion(pHps->hps, pHps->hrgnHDC);
1102
1103 O32_DeleteObject (pHps->nullBitmapHandle);
1104 }
1105 if(wnd) RELEASE_WNDOBJ(wnd);
1106 SetLastError(ERROR_INVALID_PARAMETER_W);
1107 return NULL;
1108}
1109//******************************************************************************
1110//******************************************************************************
1111HDC WIN32API GetDC (HWND hwnd)
1112{
1113 if(!hwnd)
1114 return GetDCEx( GetDesktopWindow(), 0, DCX_CACHE_W | DCX_WINDOW_W );
1115
1116 return GetDCEx (hwnd, NULL, DCX_USESTYLE_W);
1117}
1118//******************************************************************************
1119//******************************************************************************
1120HDC WIN32API GetWindowDC (HWND hwnd)
1121{
1122 if (!hwnd) hwnd = GetDesktopWindow();
1123 return GetDCEx (hwnd, NULL, DCX_WINDOW_W | DCX_USESTYLE_W);
1124}
1125//******************************************************************************
1126//Helper for RedrawWindow (RDW_ALLCHILDREN_W)
1127//******************************************************************************
1128LRESULT WIN32API RedrawChildEnumProc(HWND hwnd, LPARAM lParam)
1129{
1130 RedrawWindow(hwnd, NULL, 0, lParam);
1131 return TRUE;
1132}
1133//******************************************************************************
1134// This implementation of RedrawWindow supports
1135// RDW_ERASE
1136// RDW_NOERASE
1137// RDW_INTERNALPAINT
1138// RDW_NOINTERNALPAINT
1139// RDW_INVALIDATE
1140// RDW_VALIDATE
1141// RDW_ERASENOW
1142// RDW_UPDATENOW
1143// RDW_FRAME
1144//
1145//TODO: Works ok for RDW_FRAME??
1146// SDK docs say RDW_FRAME is only valid for RDW_INVALIDATE...
1147//******************************************************************************
1148BOOL WIN32API RedrawWindow(HWND hwnd, const RECT* pRect, HRGN hrgn, DWORD redraw)
1149{
1150 Win32BaseWindow *wnd;
1151
1152 if(pRect) {
1153 dprintf(("RedrawWindow %x (%d,%d)(%d,%d) %x %x", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom, hrgn, redraw));
1154 }
1155 else dprintf(("RedrawWindow %x %x %x %x", hwnd, pRect, hrgn, redraw));
1156
1157 if (hwnd == NULLHANDLE)
1158 {
1159 hwnd = HWND_DESKTOP;
1160 wnd = Win32BaseWindow::GetWindowFromOS2Handle(OSLIB_HWND_DESKTOP);
1161
1162 if (!wnd)
1163 {
1164 dprintf(("USER32:dc: RedrawWindow can't find desktop window %08xh\n",
1165 hwnd));
1166 SetLastError(ERROR_INVALID_PARAMETER_W);
1167 return FALSE;
1168 }
1169 }
1170 else
1171 {
1172 wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
1173
1174 if (!wnd)
1175 {
1176 dprintf(("USER32:dc: RedrawWindow can't find window %08xh\n",
1177 hwnd));
1178 SetLastError(ERROR_INVALID_PARAMETER_W);
1179 return FALSE;
1180 }
1181 if(redraw & RDW_FRAME_W) {
1182 hwnd = wnd->getOS2FrameWindowHandle();
1183 }
1184 else hwnd = wnd->getOS2WindowHandle();
1185 }
1186
1187 BOOL IncludeChildren = (redraw & RDW_ALLCHILDREN_W) ? TRUE : FALSE;
1188 BOOL success = TRUE;
1189 HPS hpsTemp = NULLHANDLE;
1190 HRGN hrgnTemp = NULLHANDLE;
1191 RECTL rectl;
1192
1193 if (hrgn)
1194 {
1195 ULONG BytesNeeded;
1196 PRGNDATA RgnData;
1197 PRECTL pr;
1198 int i;
1199 LONG height;
1200
1201 if(wnd) {
1202 height = (redraw & RDW_FRAME_W) ? wnd->getWindowHeight() : wnd->getClientHeight();
1203 }
1204 else height = OSLibQueryScreenHeight();
1205
1206 if (!hrgn)
1207 goto error;
1208
1209 BytesNeeded = GetRegionData (hrgn, 0, NULL);
1210 RgnData = (PRGNDATA)_alloca (BytesNeeded);
1211 if (RgnData == NULL)
1212 goto error;
1213 GetRegionData (hrgn, BytesNeeded, RgnData);
1214
1215 pr = (PRECTL)(RgnData->Buffer);
1216 for (i = RgnData->rdh.nCount; i > 0; i--, pr++) {
1217 LONG temp = pr->yTop;
1218 pr->yTop = height - pr->yBottom;
1219 pr->yBottom = height - temp;
1220 dprintf2(("RedrawWindow: region (%d,%d) (%d,%d)", pr->xLeft, pr->yBottom, pr->xRight, pr->yTop));
1221 }
1222
1223 hpsTemp = WinGetScreenPS (HWND_DESKTOP);
1224 hrgnTemp = GpiCreateRegion (hpsTemp, RgnData->rdh.nCount, (PRECTL)(RgnData->Buffer));
1225 if (!hrgnTemp) goto error;
1226 }
1227 else if (pRect)
1228 {
1229 if(wnd) {
1230 if(redraw & RDW_FRAME_W) {
1231 mapWin32ToOS2Rect(wnd->getWindowHeight(), (PRECT)pRect, (PRECTLOS2)&rectl);
1232 }
1233 else mapWin32ToOS2Rect(wnd->getClientHeight(), (PRECT)pRect, (PRECTLOS2)&rectl);
1234 }
1235 else mapWin32ToOS2Rect(OSLibQueryScreenHeight(), (PRECT)pRect, (PRECTLOS2)&rectl);
1236 }
1237
1238 if (redraw & RDW_INVALIDATE_W)
1239 {
1240 //TODO: SvL: pingpong.exe doesn't have RDW_NOERASE, but doesn't want WM_ERASEBKGND msgs
1241 if (redraw & RDW_ERASE_W) {
1242 wnd->setEraseBkgnd(TRUE);
1243 }
1244 else
1245 //Don't clear erase background flag if the window is
1246 //already (partly) invalidated
1247 if (!WinQueryUpdateRect (hwnd, NULL)) {
1248 wnd->setEraseBkgnd(FALSE);
1249 }
1250
1251 if (!pRect && !hrgn)
1252 success = WinInvalidateRect (hwnd, NULL, IncludeChildren);
1253 else
1254 if (hrgn) {
1255 success = WinInvalidateRegion (hwnd, hrgnTemp, IncludeChildren);
1256 if(IncludeChildren && WinQueryUpdateRect(hwnd, NULL) == FALSE) {
1257 dprintf(("WARNING: WinQueryUpdateRect %x region %x returned false even though we just invalidated part of a window!!!", hwnd, hrgnTemp));
1258 success = success = WinInvalidateRegion (hwnd, hrgnTemp, FALSE);
1259 }
1260 }
1261 else {
1262 dprintf2(("WinInvalidateRect (%d,%d)(%d,%d)", rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop));
1263 success = WinInvalidateRect (hwnd, &rectl, IncludeChildren);
1264//SvL: If all children are included, then WinInvalidateRect is called
1265// with fIncludeChildren=1 -> rect of hwnd isn't invalidated if child(ren)
1266// overlap(s) the specified rectangle completely (EVEN if window doesn't
1267// have WS_CLIPCHILREN!)
1268// -> example: XWing vs Tie Fighter install window
1269// WinInvalidateRect with fIncludeChildren=0 invalidates both the parent
1270// and child windows
1271//SvL: Can't always set fIncludeChildren to FALSE or else some controls in
1272// the RealPlayer setup application aren't redrawn when invalidating
1273// their parent
1274// SO: Check if IncludeChildren is set and part of the window is invalid
1275// If not -> call WinInvalidateRect with IncludeChildren=0 to force
1276// the window rectangle to be invalidated
1277//
1278 if(IncludeChildren && WinQueryUpdateRect(hwnd, NULL) == FALSE) {
1279 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));
1280 success = WinInvalidateRect (hwnd, &rectl, FALSE);
1281 }
1282 }
1283
1284 if (!success) goto error;
1285 }
1286 else if (redraw & RDW_VALIDATE_W)
1287 {
1288 if (redraw & RDW_NOERASE_W)
1289 wnd->setEraseBkgnd(FALSE);
1290
1291 if (WinQueryUpdateRect (hwnd, NULL))
1292 {
1293 if(!pRect && !hrgn) {
1294 success = WinValidateRect (hwnd, NULL, IncludeChildren);
1295 }
1296 else
1297 if(hrgn) {
1298 success = WinValidateRegion (hwnd, hrgnTemp, IncludeChildren);
1299 }
1300 else {
1301 success = WinValidateRect (hwnd, &rectl, IncludeChildren);
1302 }
1303 if(!success) goto error;
1304 }
1305 }
1306
1307 if(WinQueryUpdateRect(hwnd, &rectl))
1308 {
1309 dprintf2(("Update region (%d,%d)(%d,%d)", rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop));
1310 //TODO: Does this work if RDW_ALLCHILDREN is set??
1311 if(redraw & RDW_UPDATENOW_W) {
1312 RECT rectUpdate;
1313
1314 if(redraw & RDW_FRAME_W) {
1315 mapOS2ToWin32Rect(wnd->getWindowHeight(), (PRECTLOS2)&rectl, &rectUpdate);
1316 wnd->MsgNCPaint(&rectUpdate);
1317 }
1318
1319 wnd->MsgPaint(0, FALSE);
1320 }
1321 else
1322// if((redraw & RDW_ERASE_W) && (redraw & RDW_ERASENOW_W))
1323 if(redraw & RDW_ERASENOW_W && wnd->needsEraseBkgnd())
1324 wnd->setEraseBkgnd(sendEraseBkgnd(wnd) == 0);
1325// if(redraw & RDW_ALLCHILDREN_W) {
1326// EnumChildWindows(wnd->getWindowHandle(), RedrawChildEnumProc, redraw);
1327// }
1328 }
1329 else if((redraw & RDW_INTERNALPAINT_W) && !(redraw & RDW_INVALIDATE_W))
1330 {
1331 if(redraw & RDW_UPDATENOW_W) {
1332 wnd->MsgPaint(0, FALSE);
1333 }
1334 else PostMessageA(hwnd, WINWM_PAINT, 0, 0);
1335 }
1336
1337error:
1338 /* clean up */
1339 if (hrgnTemp)
1340 GpiDestroyRegion (hpsTemp, hrgnTemp);
1341
1342 if (hpsTemp)
1343 WinReleasePS (hpsTemp);
1344
1345 if (!success) {
1346 dprintf(("RedrawWindow failure!"));
1347 SetLastError(ERROR_INVALID_PARAMETER_W);
1348 }
1349 if(wnd) RELEASE_WNDOBJ(wnd);
1350 return (success);
1351}
1352//******************************************************************************
1353//******************************************************************************
1354BOOL WIN32API UpdateWindow (HWND hwnd)
1355{
1356 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
1357 RECTL rectl;
1358 BOOL rc;
1359
1360 if(!wnd) {
1361 dprintf (("ERROR: User32: UpdateWindow INVALID hwnd %x", hwnd));
1362 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
1363 return FALSE;
1364 }
1365
1366#ifdef DEBUG
1367 if(WinQueryUpdateRect(wnd->getOS2WindowHandle(), &rectl))
1368 {
1369 RECT rectUpdate;
1370 mapOS2ToWin32Rect(wnd->getClientHeight(), (PRECTLOS2)&rectl, &rectUpdate);
1371
1372 dprintf (("User32: UpdateWindow hwnd %x: update rectangle (%d,%d)(%d,%d)", hwnd, rectUpdate.left, rectUpdate.top, rectUpdate.right, rectUpdate.bottom));
1373 }
1374 else dprintf (("User32: UpdateWindow hwnd %x; EMPTY update rectangle (vis=%d/%d, show=%d/%d)", hwnd, WinIsWindowVisible(wnd->getOS2FrameWindowHandle()), WinIsWindowVisible(wnd->getOS2WindowHandle()), WinIsWindowShowing(wnd->getOS2FrameWindowHandle()), WinIsWindowShowing(wnd->getOS2WindowHandle())));
1375#endif
1376 //SvL: This doesn't work right (Wine uses RDW_NOCHILDREN_W -> doesn't work here)
1377 // Breaks vpbuddy
1378 //rc = RedrawWindow(hwnd, NULL, 0, RDW_UPDATENOW_W | RDW_ALLCHILDREN_W);
1379 // -> RDW_UPDATENOW causes WM_PAINT messages to be directy posted to window
1380 // handler; possibly bypassing queued WM_PAINT messages for parent window(s)
1381 // -> out of sync painting (i.e. parent paints over child)
1382
1383// if(!WinIsWindowShowing(wnd->getOS2FrameWindowHandle()) || !WinIsWindowShowing(wnd->getOS2WindowHandle())) {
1384// dprintf(("UpdateWindow: window not showing %d/%d", WinIsWindowShowing(wnd->getOS2FrameWindowHandle()), WinIsWindowShowing(wnd->getOS2WindowHandle()) ));
1385// RELEASE_WNDOBJ(wnd);
1386// return FALSE;
1387// }
1388 //Must use frame window here. If the frame window has a valid update region and we call
1389 //WinUpdateWindow for the client window, then no WM_PAINT messages will be sent.
1390 rc = WinUpdateWindow(wnd->getOS2FrameWindowHandle());
1391#ifdef DEBUG
1392 if(WinQueryUpdateRect(wnd->getOS2WindowHandle(), NULL))
1393 {
1394 //if parent has valid update region then WinUpdateWindow will still fail..
1395 //might be harmless and happen even in windows
1396 dprintf (("ERROR: User32: UpdateWindow didn't send WM_PAINT messages!!"));
1397 }
1398#endif
1399 RELEASE_WNDOBJ(wnd);
1400 return rc;
1401}
1402//******************************************************************************
1403//******************************************************************************
1404BOOL WIN32API ValidateRect( HWND hwnd, const RECT * lprc)
1405{
1406 if(lprc) {
1407 dprintf(("USER32: ValidateRect %x (%d,%d)(%d,%d)", hwnd, lprc->left, lprc->top, lprc->right, lprc->bottom));
1408 }
1409 else dprintf(("USER32: ValidateRect %x", hwnd));
1410
1411 return RedrawWindow( hwnd, lprc, 0, RDW_VALIDATE_W | RDW_NOCHILDREN_W | (hwnd==0 ? RDW_UPDATENOW_W : 0));
1412}
1413//******************************************************************************
1414//******************************************************************************
1415BOOL WIN32API ValidateRgn( HWND hwnd, HRGN hrgn)
1416{
1417 dprintf(("USER32: ValidateRgn %x %x", hwnd, hrgn));
1418 return RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE_W | RDW_NOCHILDREN_W | (hwnd==0 ? RDW_UPDATENOW_W : 0));
1419}
1420//******************************************************************************
1421//******************************************************************************
1422BOOL WIN32API InvalidateRect (HWND hwnd, const RECT *pRect, BOOL erase)
1423{
1424 BOOL result;
1425
1426 if(pRect) {
1427 dprintf(("InvalidateRect %x (%d,%d)(%d,%d) erase=%d", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom, erase));
1428 }
1429 else dprintf(("InvalidateRect %x NULL erase=%d", hwnd, erase));
1430#if 1
1431 result = RedrawWindow (hwnd, pRect, NULLHANDLE,
1432 RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
1433 (erase ? RDW_ERASE_W : 0) |
1434 (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
1435#else
1436 result = RedrawWindow (hwnd, pRect, NULLHANDLE,
1437 RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
1438 (erase ? RDW_ERASE_W : RDW_NOERASE_W) |
1439 (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
1440#endif
1441 return (result);
1442}
1443//******************************************************************************
1444//******************************************************************************
1445BOOL WIN32API InvalidateRgn (HWND hwnd, HRGN hrgn, BOOL erase)
1446{
1447 BOOL result;
1448
1449 dprintf(("InvalidateRgn %x %x erase=%d", hwnd, hrgn, erase));
1450#if 1
1451 result = RedrawWindow (hwnd, NULL, hrgn,
1452 RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
1453 (erase ? RDW_ERASE_W : 0) |
1454 (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
1455#else
1456 result = RedrawWindow (hwnd, NULL, hrgn,
1457 RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
1458 (erase ? RDW_ERASE_W : RDW_NOERASE_W) |
1459 (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
1460#endif
1461 return (result);
1462}
1463//******************************************************************************
1464//TODO: Change for client rectangle!!!!!
1465//******************************************************************************
1466BOOL setPMRgnIntoWinRgn (HPS hps, HRGN hrgnPM, HRGN hrgnWin, LONG height)
1467{
1468 BOOL rc;
1469 RGNRECT rgnRect;
1470 rgnRect.ircStart = 1;
1471 rgnRect.crc = 0;
1472 rgnRect.ulDirection = RECTDIR_LFRT_TOPBOT;
1473
1474 rc = GpiQueryRegionRects (hps, hrgnPM, NULL, &rgnRect, NULL);
1475
1476 if (rc && (rgnRect.crcReturned > 0))
1477 {
1478 PRECTL Rcls = new RECTL[rgnRect.crcReturned];
1479 PRECTL pRcl = Rcls;
1480
1481 if (Rcls != NULL)
1482 {
1483 rgnRect.crc = rgnRect.crcReturned;
1484 rc = GpiQueryRegionRects (hps, hrgnPM, NULL, &rgnRect, Rcls);
1485
1486 rc = SetRectRgn(hrgnWin, pRcl->xLeft, height - pRcl->yTop,
1487 pRcl->xRight, height - pRcl->yBottom);
1488
1489 if (rgnRect.crcReturned > 1)
1490 {
1491 int i;
1492 HRGN temp;
1493 temp = CreateRectRgn (0, 0, 1, 1);
1494
1495 for (i = 1, pRcl++; rc && (i < rgnRect.crcReturned); i++, pRcl++)
1496 {
1497 rc = SetRectRgn (temp, pRcl->xLeft, height - pRcl->yTop,
1498 pRcl->xRight, height - pRcl->yBottom);
1499 rc &= CombineRgn (hrgnWin, hrgnWin, temp, RGN_OR_W);
1500 }
1501 DeleteObject (temp);
1502 }
1503 delete[] Rcls;
1504 }
1505 else
1506 {
1507 rc = FALSE;
1508 }
1509 }
1510 else
1511 {
1512 rc = SetRectRgn (hrgnWin, 0, 0, 0, 0);
1513 }
1514
1515 return (rc);
1516}
1517//******************************************************************************
1518//Using WinScrollWindow to scroll child windows is better (smoother).
1519//******************************************************************************
1520INT WIN32API ScrollWindowEx(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip,
1521 HRGN hrgnUpdate, PRECT pRectUpdate, UINT scrollFlag)
1522{
1523 Win32BaseWindow *window;
1524 APIRET rc;
1525 RECTL scrollRect;
1526 RECTL clipRect;
1527 PRECTL pScrollOS2 = NULL;
1528 PRECTL pClipOS2 = NULL;
1529 ULONG scrollFlagsOS2 = 0;
1530 int orgdy = dy;
1531 int regionType = ERROR_W;
1532
1533 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1534 if(!window) {
1535 dprintf(("ScrollWindowEx, window %x not found", hwnd));
1536 return 0;
1537 }
1538
1539 dprintf(("ScrollWindowEx %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip));
1540
1541 dy = revertDy (window, dy);
1542
1543 if (scrollFlag & SW_INVALIDATE_W) scrollFlagsOS2 |= SW_INVALIDATERGN;
1544 if (scrollFlag & SW_SCROLLCHILDREN_W) scrollFlagsOS2 |= SW_SCROLLCHILDREN;
1545
1546 if(pScroll) {
1547 mapWin32ToOS2Rect(window->getClientHeight(), (RECT *)pScroll, (PRECTLOS2)&scrollRect);
1548 pScrollOS2 = &scrollRect;
1549 }
1550
1551 if(pClip) {
1552 mapWin32ToOS2Rect(window->getClientHeight(), (RECT *)pClip, (PRECTLOS2)&clipRect);
1553 pClipOS2 = &clipRect;
1554 }
1555
1556 RECTL rectlUpdate;
1557 HRGN hrgn = NULLHANDLE;
1558 HPS hpsScreen = 0;
1559
1560 if(hrgnUpdate) {
1561 RECTL rectl = { 1, 1, 2, 2 };
1562
1563 hpsScreen = WinGetScreenPS (HWND_DESKTOP);
1564 hrgn = GpiCreateRegion(hpsScreen, 1, &rectl);
1565 }
1566
1567 if (scrollFlag & SW_SMOOTHSCROLL_W)
1568 {
1569 INT time = (scrollFlag >> 16) & 0xFFFF;
1570
1571 //CB: todo, scroll in several steps
1572 // is time in ms? time <-> iteration count?
1573 }
1574
1575 LONG lComplexity = WinScrollWindow(window->getOS2WindowHandle(), dx, dy,
1576 pScrollOS2, pClipOS2,
1577 hrgn, &rectlUpdate, scrollFlagsOS2);
1578 if (lComplexity == RGN_ERROR)
1579 {
1580 RELEASE_WNDOBJ(window);
1581 return ERROR_W;
1582 }
1583
1584 //Notify children that they have moved (according to the SDK docs,
1585 //they only receive a WM_MOVE message)
1586 //(PM only does this for windows with CS_MOVENOTIFY class)
1587 //TODO: Verify this (no WM_WINDOWPOSCHANGING/ED?)
1588 if (scrollFlag & SW_SCROLLCHILDREN_W)
1589 {
1590 HWND hwndChild;
1591 RECT rectChild, rc;
1592
1593 dprintf(("ScrollWindowEx: Scroll child windows"));
1594 GetClientRect(hwnd, &rc);
1595 if (pScroll) IntersectRect(&rc, &rc, pScroll);
1596
1597 hwndChild = GetWindow(hwnd, GW_CHILD_W);
1598
1599 while(hwndChild)
1600 {
1601 Win32BaseWindow *child;
1602
1603 child = Win32BaseWindow::GetWindowFromHandle(hwndChild);
1604 if(!child) {
1605 dprintf(("ERROR: ScrollWindowEx, child %x not found", hwnd));
1606 RELEASE_WNDOBJ(window);
1607 return 0;
1608 }
1609 rectChild = *child->getWindowRect();
1610 if(!pScroll || IntersectRect(&rectChild, &rectChild, &rc))
1611 {
1612 dprintf(("ScrollWindowEx: Scroll child window %x", hwndChild));
1613 child->ScrollWindow(dx, orgdy);
1614 }
1615 RELEASE_WNDOBJ(child);
1616 hwndChild = GetWindow(hwndChild, GW_HWNDNEXT_W);
1617 }
1618 dprintf(("***ScrollWindowEx: Scroll child windows DONE"));
1619 }
1620
1621 RECT winRectUpdate;
1622
1623 mapOS2ToWin32Rect(window->getClientHeight(), (PRECTLOS2)&rectlUpdate, &winRectUpdate);
1624
1625 if (pRectUpdate)
1626 *pRectUpdate = winRectUpdate;
1627
1628 if (hrgnUpdate) {
1629 rc = setPMRgnIntoWinRgn(hpsScreen, hrgn, hrgnUpdate, window->getClientHeight());
1630 GpiDestroyRegion(hpsScreen, hrgn);
1631 WinReleasePS(hpsScreen);
1632 }
1633
1634#if 0
1635 //SvL: WinScrollWindow already invalidates the area; no need to do it again
1636 //(call to invalidateRect was wrong; has to include erase flag)
1637 if ((scrollFlag & SW_INVALIDATE_W) &&
1638 ((lComplexity == RGN_RECT) || (lComplexity == RGN_COMPLEX)))
1639 {
1640 rc = RedrawWindow (hwnd, &winRectUpdate, NULLHANDLE,
1641 RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
1642 ((scrollFlag & SW_ERASE_W) ? RDW_ERASE_W : 0) |
1643 RDW_UPDATENOW_W);
1644
1645// rc = InvalidateRect (hwnd, &winRectUpdate, (scrollFlag & SW_ERASE_W) ? 1 : 0);
1646 if (rc == FALSE)
1647 {
1648 RELEASE_WNDOBJ(window);
1649 return (0);
1650 }
1651 }
1652#endif
1653
1654 switch (lComplexity)
1655 {
1656 case RGN_NULL:
1657 regionType = NULLREGION_W;
1658 break;
1659 case RGN_RECT:
1660 regionType = SIMPLEREGION_W;
1661 break;
1662 case RGN_COMPLEX:
1663 regionType = COMPLEXREGION_W;
1664 break;
1665 default:
1666 regionType = ERROR_W;
1667 break;
1668 }
1669
1670 RELEASE_WNDOBJ(window);
1671 return (regionType);
1672}
1673//******************************************************************************
1674//******************************************************************************
1675BOOL WIN32API ScrollWindow(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip)
1676{
1677 dprintf(("ScrollWindow %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip));
1678 return (ERROR_W != ScrollWindowEx(hwnd, dx, dy, pScroll, pClip, 0, NULL,
1679 (pScroll ? 0 : SW_SCROLLCHILDREN_W) |
1680 SW_INVALIDATE_W ));
1681}
1682//******************************************************************************
1683//******************************************************************************
1684HWND WIN32API WindowFromDC(HDC hdc)
1685{
1686 pDCData pHps = (pDCData)GpiQueryDCData( (HPS)hdc );
1687
1688 dprintf2(("USER32: WindowFromDC %x", hdc));
1689 if ( pHps )
1690 return OS2ToWin32Handle(pHps->hwnd);
1691 else
1692 return 0;
1693}
1694//******************************************************************************
1695//******************************************************************************
1696
Note: See TracBrowser for help on using the repository browser.