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

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

GetMinMaxInfo fix (border) + CS_OWNDC fix (origin)

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