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

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

added statistics

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