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

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

GetWindow + z-order bugfixes

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