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

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

export selectClientArea for gdi32

File size: 54.6 KB
Line 
1/* $Id: dc.cpp,v 1.78 2000-11-15 13:57:56 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 success = WinInvalidateRect (hwnd, &rectl, IncludeChildren);
1235//SvL: If all children are included, then WinInvalidateRect is called
1236// with fIncludeChildren=1 -> rect of hwnd isn't invalidated if child(ren)
1237// overlap(s) the specified rectangle completely (EVEN if window doesn't
1238// have WS_CLIPCHILREN!)
1239// -> example: XWing vs Tie Fighter install window
1240// WinInvalidateRect with fIncludeChildren=0 invalidates both the parent
1241// and child windows
1242//SvL: Can't always set fIncludeChildren to FALSE or else some controls in
1243// the RealPlayer setup application aren't redrawn when invalidating
1244// their parent
1245// SO: Check if IncludeChildren is set and part of the window is invalid
1246// If not -> call WinInvalidateRect with IncludeChildren=0 to force
1247// the window rectangle to be invalidated
1248//
1249 if(IncludeChildren && WinQueryUpdateRect(hwnd, NULL) == FALSE) {
1250 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));
1251 success = WinInvalidateRect (hwnd, &rectl, FALSE);
1252 }
1253 }
1254
1255 if (!success) goto error;
1256 }
1257 else if (redraw & RDW_VALIDATE_W)
1258 {
1259 if (redraw & RDW_NOERASE_W)
1260 wnd->setEraseBkgnd(FALSE);
1261
1262 if (WinQueryUpdateRect (hwnd, NULL))
1263 {
1264 if(!pRect && !hrgn) {
1265 success = WinValidateRect (hwnd, NULL, IncludeChildren);
1266 }
1267 else
1268 if(hrgn) {
1269 success = WinValidateRegion (hwnd, hrgnTemp, IncludeChildren);
1270 }
1271 else {
1272 success = WinValidateRect (hwnd, &rectl, IncludeChildren);
1273 }
1274 if(!success) goto error;
1275 }
1276 }
1277
1278 if(WinQueryUpdateRect(hwnd, NULL))
1279 {
1280 //TODO: Does this work if RDW_ALLCHILDREN is set??
1281 if(redraw & RDW_UPDATENOW_W) {
1282 wnd->MsgNCPaint();
1283 wnd->MsgPaint(0, FALSE);
1284 }
1285 else
1286// if((redraw & RDW_ERASE_W) && (redraw & RDW_ERASENOW_W))
1287 if(redraw & RDW_ERASENOW_W && wnd->needsEraseBkgnd())
1288 wnd->setEraseBkgnd(sendEraseBkgnd(wnd) == 0);
1289// if(redraw & RDW_ALLCHILDREN_W) {
1290// EnumChildWindows(wnd->getWindowHandle(), RedrawChildEnumProc, redraw);
1291// }
1292 }
1293 else if((redraw & RDW_INTERNALPAINT_W) && !(redraw & RDW_INVALIDATE_W))
1294 {
1295 if(redraw & RDW_UPDATENOW_W) {
1296 wnd->MsgNCPaint();
1297 wnd->MsgPaint (0, FALSE);
1298 }
1299 else PostMessageA(hwnd, WINWM_PAINT, 0, 0);
1300 }
1301
1302error:
1303 /* clean up */
1304 if (hrgnTemp)
1305 GpiDestroyRegion (hpsTemp, hrgnTemp);
1306
1307 if (hpsTemp)
1308 WinReleasePS (hpsTemp);
1309
1310 if (!success) {
1311 dprintf(("RedrawWindow failure!"));
1312 SetLastError(ERROR_INVALID_PARAMETER_W);
1313 }
1314 return (success);
1315}
1316//******************************************************************************
1317//******************************************************************************
1318BOOL WIN32API UpdateWindow (HWND hwnd)
1319{
1320 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
1321
1322 if(!wnd) {
1323 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
1324 return FALSE;
1325 }
1326
1327 dprintf (("User32: UpdateWindow hwnd %x", hwnd));
1328//SvL: This doesn't work right (Wine uses RDW_NOCHILDREN_W -> doesn't work here)
1329// Breaks vpbuddy
1330// return RedrawWindow(hwnd, NULL, 0, RDW_UPDATENOW_W | RDW_ALLCHILDREN_W);
1331// -> RDW_UPDATENOW causes WM_PAINT messages to be directy posted to window
1332// handler; possibly bypassing queued WM_PAINT messages for parent window(s)
1333// -> out of sync painting (i.e. parent paints over child)
1334 WinUpdateWindow(wnd->getOS2WindowHandle());
1335 return TRUE;
1336}
1337//******************************************************************************
1338//******************************************************************************
1339BOOL WIN32API ValidateRect( HWND hwnd, const RECT * lprc)
1340{
1341 if(lprc) {
1342 dprintf(("USER32: ValidateRect %x (%d,%d)(%d,%d)", hwnd, lprc->left, lprc->top, lprc->right, lprc->bottom));
1343 }
1344 else dprintf(("USER32: ValidateRect %x", hwnd));
1345
1346 return RedrawWindow( hwnd, lprc, 0, RDW_VALIDATE_W | RDW_NOCHILDREN_W | (hwnd==0 ? RDW_UPDATENOW_W : 0));
1347}
1348//******************************************************************************
1349//******************************************************************************
1350BOOL WIN32API ValidateRgn( HWND hwnd, HRGN hrgn)
1351{
1352 dprintf(("USER32: ValidateRgn %x %x", hwnd, hrgn));
1353 return RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE_W | RDW_NOCHILDREN_W | (hwnd==0 ? RDW_UPDATENOW_W : 0));
1354}
1355//******************************************************************************
1356//******************************************************************************
1357BOOL WIN32API InvalidateRect (HWND hwnd, const RECT *pRect, BOOL erase)
1358{
1359 BOOL result;
1360
1361 if(pRect) {
1362 dprintf(("InvalidateRect %x (%d,%d)(%d,%d) erase=%d", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom, erase));
1363 }
1364 else dprintf(("InvalidateRect %x NULL erase=%d", hwnd, erase));
1365 result = RedrawWindow (hwnd, pRect, NULLHANDLE,
1366 RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
1367 (erase ? RDW_ERASE_W : RDW_NOERASE_W) |
1368 (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
1369 return (result);
1370}
1371//******************************************************************************
1372//******************************************************************************
1373BOOL WIN32API InvalidateRgn (HWND hwnd, HRGN hrgn, BOOL erase)
1374{
1375 BOOL result;
1376
1377 dprintf(("InvalidateRgn %x %x erase=%d", hwnd, hrgn, erase));
1378 result = RedrawWindow (hwnd, NULL, hrgn,
1379 RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
1380 (erase ? RDW_ERASE_W : RDW_NOERASE_W) |
1381 (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
1382 return (result);
1383}
1384//******************************************************************************
1385//TODO: Change for client rectangle!!!!!
1386//******************************************************************************
1387BOOL setPMRgnIntoWinRgn (HRGN hrgnPM, HRGN hrgnWin, LONG height)
1388{
1389 BOOL rc;
1390 HPS hps = WinGetScreenPS (HWND_DESKTOP);
1391 RGNRECT rgnRect;
1392 rgnRect.ircStart = 1;
1393 rgnRect.crc = 0;
1394 rgnRect.ulDirection = RECTDIR_LFRT_TOPBOT; // doesn't make a difference because we're getting them all
1395
1396 rc = GpiQueryRegionRects (hps, hrgnPM, NULL, &rgnRect, NULL);
1397
1398 if (rc && (rgnRect.crcReturned > 0))
1399 {
1400 PRECTL Rcls = new RECTL[rgnRect.crcReturned];
1401 PRECTL pRcl = Rcls;
1402
1403 if (Rcls != NULL)
1404 {
1405 rgnRect.crc = rgnRect.crcReturned;
1406 rc = GpiQueryRegionRects (hps, hrgnPM, NULL, &rgnRect, Rcls);
1407
1408 rc = SetRectRgn(hrgnWin, pRcl->xLeft,
1409 pRcl->xRight,
1410 height - pRcl->yTop,
1411 height - pRcl->yBottom);
1412
1413 if (rgnRect.crcReturned > 1)
1414 {
1415 int i;
1416 HRGN temp;
1417 temp = CreateRectRgn (0, 0, 1, 1);
1418
1419 for (i = 1, pRcl++; rc && (i < rgnRect.crcReturned); i++, pRcl++)
1420 {
1421 rc = SetRectRgn (temp, pRcl->xLeft,
1422 pRcl->xRight,
1423 height - pRcl->yTop,
1424 height - pRcl->yBottom);
1425 rc &= CombineRgn (hrgnWin, hrgnWin, temp, RGN_OR_W);
1426 }
1427 DeleteObject (temp);
1428 }
1429 delete[] Rcls;
1430 }
1431 else
1432 {
1433 rc = FALSE;
1434 }
1435 }
1436 else
1437 {
1438 rc = SetRectRgn (hrgnWin, 0, 0, 0, 0);
1439 }
1440
1441 WinReleasePS (hps);
1442 return (rc);
1443}
1444//******************************************************************************
1445//TODO: Check if this one works correctly...
1446//Have to check if dc is for frame or client!!
1447//******************************************************************************
1448BOOL WIN32API ScrollDC(HDC hDC, int dx, int dy, const RECT *pScroll,
1449 const RECT *pClip, HRGN hrgnUpdate, LPRECT pRectUpdate)
1450{
1451 BOOL rc = TRUE;
1452
1453 dprintf (("USER32: ScrollDC %x (%d,%d), %x %x %x %x", hDC, dx, dy, pScroll, pClip, hrgnUpdate, pRectUpdate));
1454
1455 if (!hDC)
1456 {
1457 return (FALSE);
1458 }
1459
1460 pDCData pHps = (pDCData)GpiQueryDCData ((HPS)hDC);
1461 HWND hwnd = pHps->hwnd;
1462 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
1463
1464 if ((hwnd == NULLHANDLE) || !wnd)
1465 {
1466 return (FALSE);
1467 }
1468
1469 POINTL ptl[2] = { 0, 0, dx, dy };
1470
1471 GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, ptl);
1472 dx = (int)(ptl[1].x - ptl[0].x);
1473 dy = (int)(ptl[1].y - ptl[0].y);
1474
1475 RECT scrollRect;
1476 RECT clipRect;
1477
1478 if (pClip)
1479 {
1480 memcpy(&clipRect, pClip, sizeof(clipRect));
1481
1482 if ((pHps->graphicsMode == GM_COMPATIBLE_W) &&
1483 (clipRect.left != clipRect.right) &&
1484 (clipRect.bottom != clipRect.top))
1485 {
1486 if (abs((int)pHps->viewportXExt) <= abs((int)pHps->windowExt.cx))
1487 clipRect.right -= abs(pHps->worldXDeltaFor1Pixel);
1488 else
1489 clipRect.left += abs(pHps->worldXDeltaFor1Pixel);
1490
1491 if (abs((int)pHps->viewportYExt) <= abs((int)pHps->windowExt.cy))
1492 clipRect.bottom -= abs(pHps->worldYDeltaFor1Pixel);
1493 else
1494 clipRect.top += abs(pHps->worldYDeltaFor1Pixel);
1495 }
1496 GpiConvert(pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, (PPOINTL)&clipRect);
1497 if (clipRect.right < clipRect.left) {
1498 ULONG temp = clipRect.left;
1499 clipRect.left = clipRect.right;
1500 clipRect.right = temp;
1501 }
1502 if (clipRect.bottom < clipRect.top) {
1503 ULONG temp = clipRect.top;
1504 clipRect.top = clipRect.bottom;
1505 clipRect.bottom = temp;
1506 }
1507 }
1508
1509 if (pScroll)
1510 {
1511 memcpy(&scrollRect, pScroll, sizeof(scrollRect));
1512
1513 if ((pHps->graphicsMode == GM_COMPATIBLE_W) &&
1514 (scrollRect.left != scrollRect.right) &&
1515 (scrollRect.top != scrollRect.bottom))
1516 {
1517 if (abs((int)pHps->viewportXExt) <= abs((int)pHps->windowExt.cx))
1518 scrollRect.right -= abs(pHps->worldXDeltaFor1Pixel);
1519 else
1520 scrollRect.left += abs(pHps->worldXDeltaFor1Pixel);
1521
1522 if (abs((int)pHps->viewportYExt) <= abs((int)pHps->windowExt.cy))
1523 scrollRect.bottom -= abs(pHps->worldYDeltaFor1Pixel);
1524 else
1525 scrollRect.top += abs(pHps->worldYDeltaFor1Pixel);
1526 }
1527 GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, (PPOINTL)&scrollRect);
1528 if (scrollRect.right < scrollRect.left) {
1529 ULONG temp = scrollRect.left;
1530 scrollRect.left = scrollRect.right;
1531 scrollRect.right = temp;
1532 }
1533 if (scrollRect.bottom < scrollRect.top) {
1534 ULONG temp = scrollRect.top;
1535 scrollRect.top = scrollRect.bottom;
1536 scrollRect.bottom = temp;
1537 }
1538 }
1539 RECTL rectlUpdate;
1540 HRGN hrgn;
1541 RECTL clientRect;
1542 RECTL clipOS2;
1543 RECTL scrollOS2;
1544 PRECTL pScrollOS2 = NULL;
1545 PRECTL pClipOS2 = NULL;
1546
1547 mapWin32ToOS2Rect(wnd->getWindowHeight(), wnd->getClientRectPtr(), (PRECTLOS2)&clientRect);
1548
1549 if(pScroll) {
1550 mapWin32ToOS2RectClientToFrame(wnd, &scrollRect, (PRECTLOS2)&scrollOS2);
1551 pScrollOS2 = &scrollOS2;
1552
1553 //Scroll rectangle relative to client area
1554 WinIntersectRect ((HAB) 0, pScrollOS2, pScrollOS2, &clientRect);
1555 }
1556 else {
1557 pScrollOS2 = &clientRect;
1558 }
1559
1560 if(pClip) {
1561 mapWin32ToOS2RectClientToFrame(wnd, &clipRect, (PRECTLOS2)&clipOS2);
1562 pClipOS2 = &clipOS2;
1563
1564 //Clip rectangle relative to client area
1565 WinIntersectRect((HAB) 0, pClipOS2, pClipOS2, &clientRect);
1566 }
1567 else {
1568 pClipOS2 = &clientRect;
1569 }
1570
1571 LONG lComplexity = WinScrollWindow(hwnd, dx, dy, pScrollOS2,
1572 pClipOS2, hrgn, &rectlUpdate, 0);
1573 if (lComplexity == RGN_ERROR)
1574 {
1575 return (FALSE);
1576 }
1577
1578 RECT winRectUpdate;
1579
1580 mapOS2ToWin32Rect(wnd->getWindowHeight(), (PRECTLOS2)&rectlUpdate, &winRectUpdate);
1581
1582 if (pRectUpdate)
1583 *pRectUpdate = winRectUpdate;
1584
1585 if (hrgnUpdate)
1586 rc = setPMRgnIntoWinRgn(hrgn, hrgnUpdate, wnd->getWindowHeight());
1587
1588 return (rc);
1589}
1590//******************************************************************************
1591//******************************************************************************
1592BOOL WIN32API ScrollWindow(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip)
1593{
1594 Win32BaseWindow *window;
1595 APIRET rc;
1596 RECTL clientRect;
1597 RECTL scrollRect;
1598 RECTL clipRect;
1599 PRECTL pScrollOS2 = NULL;
1600 PRECTL pClipOS2 = NULL;
1601 ULONG scrollFlags = SW_INVALIDATERGN;
1602
1603 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1604 if(!window) {
1605 dprintf(("ScrollWindow, window %x not found", hwnd));
1606 return 0;
1607 }
1608 dprintf(("ScrollWindow %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip));
1609
1610 mapWin32ToOS2Rect(window->getWindowHeight(), window->getClientRectPtr(), (PRECTLOS2)&clientRect);
1611
1612 if(pScroll) {
1613 mapWin32ToOS2RectClientToFrame(window,(RECT *)pScroll, (PRECTLOS2)&scrollRect);
1614 pScrollOS2 = &scrollRect;
1615
1616 //Scroll rectangle relative to client area
1617 WinIntersectRect ((HAB) 0, pScrollOS2, pScrollOS2, &clientRect);
1618 }
1619 else {
1620 pScrollOS2 = &clientRect;
1621 scrollFlags |= SW_SCROLLCHILDREN;
1622 }
1623
1624 if(pClip) {
1625 mapWin32ToOS2RectClientToFrame(window,(RECT *)pClip, (PRECTLOS2)&clipRect);
1626 pClipOS2 = &clipRect;
1627
1628 //Clip rectangle relative to client area
1629 WinIntersectRect ((HAB) 0, pClipOS2, pClipOS2, &clientRect);
1630 }
1631 else {
1632 pClipOS2 = &clientRect;
1633 }
1634
1635 dy = revertDy (window, dy);
1636
1637 rc = WinScrollWindow(window->getOS2WindowHandle(), dx, dy,
1638 pScrollOS2, pClipOS2, NULLHANDLE,
1639 NULL, scrollFlags);
1640
1641 return (rc != RGN_ERROR);
1642}
1643//******************************************************************************
1644//******************************************************************************
1645INT WIN32API ScrollWindowEx(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip,
1646 HRGN hrgnUpdate, PRECT pRectUpdate, UINT scrollFlag)
1647{
1648 Win32BaseWindow *window;
1649 APIRET rc;
1650 RECTL clientRect;
1651 RECTL scrollRect;
1652 RECTL clipRect;
1653 PRECTL pScrollOS2 = NULL;
1654 PRECTL pClipOS2 = NULL;
1655 ULONG scrollFlags = 0;
1656 int regionType = ERROR_W;
1657
1658 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1659 if(!window) {
1660 dprintf(("ScrollWindowEx, window %x not found", hwnd));
1661 return 0;
1662 }
1663
1664 dprintf(("ScrollWindowEx %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip));
1665
1666 dy = revertDy (window, dy);
1667
1668 if (scrollFlag & SW_INVALIDATE_W) scrollFlags |= SW_INVALIDATERGN;
1669 if (scrollFlag & SW_SCROLLCHILDREN_W) scrollFlags |= SW_SCROLLCHILDREN;
1670
1671 mapWin32ToOS2Rect(window->getWindowHeight(), window->getClientRectPtr(), (PRECTLOS2)&clientRect);
1672
1673 if(pScroll) {
1674 mapWin32ToOS2RectClientToFrame(window,(RECT *)pScroll, (PRECTLOS2)&scrollRect);
1675 pScrollOS2 = &scrollRect;
1676
1677 //Scroll rectangle relative to client area
1678 WinIntersectRect ((HAB) 0, pScrollOS2, pScrollOS2, &clientRect);
1679 }
1680 else {
1681 pScrollOS2 = &clientRect;
1682 scrollFlags |= SW_SCROLLCHILDREN; //TODO: ?????
1683 }
1684
1685 if(pClip) {
1686 mapWin32ToOS2RectClientToFrame(window,(RECT *)pClip, (PRECTLOS2)&clipRect);
1687 pClipOS2 = &clipRect;
1688
1689 //Clip rectangle relative to client area
1690 WinIntersectRect ((HAB) 0, pClipOS2, pClipOS2, &clientRect);
1691 }
1692 else {
1693 pClipOS2 = &clientRect;
1694 }
1695
1696 RECTL rectlUpdate;
1697 HRGN hrgn;
1698
1699 if (scrollFlag & SW_SMOOTHSCROLL_W)
1700 {
1701 INT time = (scrollFlag >> 16) & 0xFFFF;
1702
1703 //CB: todo, scroll in several steps
1704 // is time in ms? time <-> iteration count?
1705 }
1706
1707 LONG lComplexity = WinScrollWindow (window->getOS2WindowHandle(), dx, dy,
1708 pScrollOS2,
1709 pClipOS2,
1710 hrgn, &rectlUpdate, scrollFlags);
1711 if (lComplexity == RGN_ERROR)
1712 {
1713 return ERROR_W;
1714 }
1715
1716 RECT winRectUpdate;
1717
1718 mapOS2ToWin32Rect(window->getWindowHeight(), (PRECTLOS2)&rectlUpdate, &winRectUpdate);
1719
1720 if (pRectUpdate)
1721 *pRectUpdate = winRectUpdate;
1722
1723 if (hrgnUpdate)
1724 rc = setPMRgnIntoWinRgn (hrgn, hrgnUpdate, window->getWindowHeight());
1725
1726#if 0
1727 //SvL: WinScrollWindow already invalidates the area; no need to do it again
1728 //(call to invalidateRect was wrong; has to include erase flag)
1729 if ((scrollFlag & SW_INVALIDATE_W) &&
1730 ((lComplexity == RGN_RECT) || (lComplexity == RGN_COMPLEX)))
1731 {
1732 rc = InvalidateRect (hwnd, &winRectUpdate, (scrollFlag & SW_ERASE_W) ? 1 : 0);
1733 if (rc == FALSE)
1734 {
1735 return (0);
1736 }
1737 }
1738#endif
1739
1740 switch (lComplexity)
1741 {
1742 case RGN_NULL:
1743 regionType = NULLREGION_W;
1744 break;
1745 case RGN_RECT:
1746 regionType = SIMPLEREGION_W;
1747 break;
1748 case RGN_COMPLEX:
1749 regionType = COMPLEXREGION_W;
1750 break;
1751 default:
1752 regionType = ERROR_W;
1753 break;
1754 }
1755
1756 return (regionType);
1757}
1758//******************************************************************************
1759//******************************************************************************
1760HWND WIN32API WindowFromDC(HDC hdc)
1761{
1762 pDCData pHps = (pDCData)GpiQueryDCData( (HPS)hdc );
1763
1764 dprintf2(("USER32: WindowFromDC %x", hdc));
1765 if ( pHps )
1766 return Win32BaseWindow::OS2ToWin32Handle(pHps->hwnd);
1767 else
1768 return 0;
1769}
1770//******************************************************************************
1771//******************************************************************************
Note: See TracBrowser for help on using the repository browser.