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

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

WM_CTLCOLOR fixes for apps that don't return brushes

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