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

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

Win32ToOS2Handle & OS2ToWin32Handle exported with stdcall calling convention

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