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

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

Commented out winzip button change in BeginPaint (fixes repaint problems) + implemented IsZoomed)

File size: 54.9 KB
Line 
1/* $Id: dc.cpp,v 1.70 2000-09-02 08:30:09 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#if 1
633 HRGN hrgnClip = GpiCreateRegion(pHps->hps, 1, &rectl);
634#else
635 HRGN hrgnClip = GpiCreateRegion(pHps->hps, 1, &rectlClip);
636 WinQueryUpdateRegion(hwndClient, hrgnClip);
637 dprintfRegion(pHps->hps, hWnd, hrgnClip);
638 WinQueryVisibleRegion(hwndClient, hrgnClip);
639 dprintfRegion(pHps->hps, hWnd, hrgnClip);
640 WinQueryUpdateRegion(hwndClient, hrgnClip);
641#endif
642 WinValidateRegion(hwndClient, hrgnClip, FALSE);
643
644 mapWin32ToOS2Rect(wnd->getWindowHeight(), wnd->getClientRectPtr(), (PRECTLOS2)&rectlClient);
645 WinIntersectRect(NULL, &rectlClip, &rectl, &rectlClient);
646 WinOffsetRect(NULL, &rectlClip, -rectlClient.xLeft, -rectlClient.yBottom);
647
648 //change presentation space for client window
649 selectClientArea(wnd, pHps);
650
651 //clip update region with client window rectangle
652 HRGN hrgnClient = GpiCreateRegion(pHps->hps, 1, &rectlClient);
653 GpiCombineRegion(pHps->hps, hrgnClip, hrgnClip, hrgnClient, CRGN_AND);
654 GpiDestroyRegion(pHps->hps, hrgnClient);
655
656 //change origin of clip region (window -> client)
657 POINTL point = {-rectlClient.xLeft, -rectlClient.yBottom};
658 GpiOffsetRegion(pHps->hps, hrgnClip, &point);
659
660 //set clip region
661 GpiSetClipRegion(pHps->hps, hrgnClip, &hrgnOldClip);
662
663 //save old clip region (restored for CS_OWNDC windows in EndPaint)
664 wnd->SetClipRegion(hrgnOldClip);
665 memcpy(&rectl, &rectlClip, sizeof(RECTL));
666 lComplexity = RGN_RECT;
667 }
668
669 if(hPS_ownDC == 0)
670 setMapMode (wnd, pHps, MM_TEXT_W);
671 else
672 setPageXForm(wnd, pHps);
673
674 pHps->hdcType = TYPE_3;
675
676 HideCaret(hwnd);
677 WinShowTrackRect(wnd->getOS2WindowHandle(), FALSE);
678
679 if(wnd->needsEraseBkgnd() && lComplexity != RGN_NULL) {
680 wnd->setEraseBkgnd(FALSE);
681 lpps->fErase = (wnd->MsgEraseBackGround(pHps->hps) != 0);
682 }
683 else lpps->fErase = TRUE;
684
685 lpps->hdc = (HDC)pHps->hps;
686
687 if(lComplexity != RGN_NULL) {
688 long height = wnd->getClientHeight();
689 lpps->rcPaint.top = height - rectl.yTop;
690 lpps->rcPaint.left = rectl.xLeft;
691 lpps->rcPaint.bottom = height - rectl.yBottom;
692 lpps->rcPaint.right = rectl.xRight;
693 }
694 else {
695 lpps->rcPaint.bottom = lpps->rcPaint.top = 0;
696 lpps->rcPaint.right = lpps->rcPaint.left = 0;
697 }
698
699 SetLastError(0);
700 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));
701 return (HDC)pHps->hps;
702}
703//******************************************************************************
704//******************************************************************************
705BOOL WIN32API EndPaint (HWND hWnd, const PAINTSTRUCT_W *pPaint)
706{
707 HWND hwnd = hWnd ? hWnd : HWND_DESKTOP;
708 HRGN hrgnOld;
709 pDCData pHps;
710
711 dprintf (("USER32: EndPaint(%x)", hwnd));
712
713 if (!pPaint || !pPaint->hdc )
714 return TRUE;
715
716 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
717
718 if (!wnd) goto exit;
719
720 pHps = (pDCData)GpiQueryDCData((HPS)pPaint->hdc);
721 if (pHps && (pHps->hdcType == TYPE_3))
722 {
723 GpiSetClipRegion(pHps->hps, wnd->GetClipRegion(), &hrgnOld);
724 wnd->SetClipRegion(0);
725 if(hrgnOld) {
726 GpiDestroyRegion(pHps->hps, hrgnOld);
727 }
728 pHps->hdcType = TYPE_1; //otherwise Open32's ReleaseDC fails
729 ReleaseDC(hwnd, pPaint->hdc);
730 }
731 else {
732 dprintf(("EndPaint: wrong hdc %x!!", pPaint->hdc));
733 }
734 wnd->setEraseBkgnd(TRUE);
735 ShowCaret(hwnd);
736 WinShowTrackRect(wnd->getOS2WindowHandle(), TRUE);
737
738exit:
739 SetLastError(0);
740 return TRUE;
741}
742//******************************************************************************
743//******************************************************************************
744int WIN32API ReleaseDC (HWND hwnd, HDC hdc)
745{
746 BOOL isOwnDC = FALSE;
747 int rc;
748
749 if (hwnd)
750 {
751 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
752 if(wnd == NULL) {
753 dprintf(("ERROR: ReleaseDC %x %x failed", hwnd, hdc));
754 return 0;
755 }
756 isOwnDC = wnd->isOwnDC() && (wnd->getOwnDC() == hdc);
757 if(!isOwnDC)
758 {
759 pDCData pHps = (pDCData)GpiQueryDCData((HPS)hdc);
760 if(pHps && pHps->psType == MICRO_CACHED) {
761 removeClientArea(pHps);
762 if(pHps->hrgnVis) {
763 GreDestroyRegion(pHps->hps, pHps->hrgnVis);
764 pHps->hrgnVis = 0;
765 }
766 }
767 else {
768 dprintf(("ERROR: ReleaseDC: pHps == NULL!!"));
769 DebugInt3();
770 }
771 }
772 }
773
774 if(isOwnDC) {
775 rc = TRUE;
776 }
777 else {
778 rc = O32_ReleaseDC (0, hdc);
779 }
780
781 dprintf(("ReleaseDC %x %x", hwnd, hdc));
782 return (rc);
783}
784//******************************************************************************
785// This implementation of GetDCEx supports
786// DCX_WINDOW
787// DCX_CACHE
788// DCX_EXCLUDERGN (complex regions allowed)
789// DCX_INTERSECTRGN (complex regions allowed)
790// DCX_USESTYLE
791// DCX_CLIPSIBLINGS
792// DCX_CLIPCHILDREN
793// DCX_PARENTCLIP
794//
795//TODO: WM_SETREDRAW affects drawingAllowed flag!!
796//******************************************************************************
797HDC WIN32API GetDCEx (HWND hwnd, HRGN hrgn, ULONG flags)
798{
799 Win32BaseWindow *wnd = NULL;
800 HWND hWindow;
801 BOOL success;
802 pDCData pHps = NULL;
803 HPS hps = NULLHANDLE;
804 BOOL drawingAllowed = TRUE;
805 BOOL isWindowOwnDC;
806 BOOL creatingOwnDC = FALSE;
807 PS_Type psType;
808
809 if(hwnd == 0) {
810 dprintf(("error: GetDCEx window %x not found", hwnd));
811 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
812 return 0;
813 }
814
815 if (hwnd)
816 {
817 wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
818 if(wnd == NULL) {
819 dprintf (("ERROR: User32: GetDCEx bad window handle %X!!!!!", hwnd));
820 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
821 return 0;
822 }
823 hWindow = wnd->getOS2WindowHandle();
824 }
825
826 isWindowOwnDC = (((hWindow == HWND_DESKTOP) ? FALSE : (wnd->isOwnDC()))
827 && !(flags & (DCX_CACHE_W|DCX_WINDOW_W)));
828
829 if(isWindowOwnDC) //own dc always for client area
830 {
831 hps = wnd->getOwnDC();
832 if (hps)
833 {
834 pDCData pHps = (pDCData)GpiQueryDCData (hps);
835 if (!pHps)
836 goto error;
837
838 selectClientArea(wnd, pHps);
839
840 //TODO: Is this always necessary??
841 setPageXForm (wnd, pHps);
842 pHps->hdcType = TYPE_1;
843
844 //TODO: intersect/exclude clip region?
845 dprintf (("User32: GetDCEx hwnd %x (%x %x) -> wnd %x hdc %x", hwnd, hrgn, flags, wnd, hps));
846 return (HDC)hps;
847 }
848 else
849 creatingOwnDC = TRUE;
850 }
851
852 if(isWindowOwnDC)
853 {
854 SIZEL sizel = {0,0};
855 hps = GpiCreatePS (WinQueryAnchorBlock (hWindow),
856 WinOpenWindowDC (hWindow),
857 &sizel, PU_PELS | GPIT_MICRO | GPIA_ASSOC );
858 psType = MICRO;
859 }
860 else
861 {
862 if (hWindow == HWND_DESKTOP) {
863 hps = WinGetScreenPS (hWindow);
864 }
865 else {
866 int clipstyle = 0;
867 int clipwnd = HWND_TOP;
868 if(flags & (DCX_USESTYLE_W)) {
869 int style = wnd->getStyle();
870 if(style & WS_CLIPCHILDREN_W) {
871 clipstyle |= PSF_CLIPCHILDREN;
872 }
873 if(style & WS_CLIPSIBLINGS_W) {
874 clipstyle |= PSF_CLIPSIBLINGS;
875 }
876 if(wnd->fHasParentDC()) {
877 clipstyle |= PSF_PARENTCLIP;
878 }
879 }
880 if(flags & DCX_CLIPSIBLINGS_W) {
881 clipstyle |= PSF_CLIPSIBLINGS;
882 }
883 if(flags & DCX_CLIPCHILDREN_W) {
884 clipstyle |= PSF_CLIPCHILDREN;
885 }
886 if(flags & DCX_PARENTCLIP_W) {
887 clipstyle |= PSF_PARENTCLIP;
888 }
889 if(clipstyle) {
890 dprintf2(("WinGetClipPS style %x", clipstyle));
891 hps = WinGetClipPS(hWindow, clipwnd, clipstyle);
892 }
893 else hps = WinGetPS (hWindow);
894 }
895 psType = MICRO_CACHED;
896 }
897
898 if (!hps)
899 goto error;
900
901 HPSToHDC (hWindow, hps, NULL, NULL);
902 pHps = (pDCData)GpiQueryDCData (hps);
903
904 if(!(flags & DCX_WINDOW_W))
905 {
906 selectClientArea(wnd, pHps);
907 }
908 else removeClientArea(pHps);
909
910 setMapMode(wnd, pHps, MM_TEXT_W);
911
912 if ((flags & DCX_EXCLUDERGN_W) || (flags & DCX_INTERSECTRGN_W))
913 {
914 ULONG BytesNeeded;
915 PRGNDATA RgnData;
916 PRECT pr;
917 int i;
918 RECTL rectl;
919
920 if (!hrgn)
921 goto error;
922
923 success = TRUE;
924 if (flags & DCX_EXCLUDERGN_W)
925 {
926#if 0 //CB: todo
927 long height;
928
929 BytesNeeded = GetRegionData (hrgn, 0, NULL);
930 RgnData = (PRGNDATA_W)_alloca (BytesNeeded);
931 if (RgnData == NULL)
932 goto error;
933 GetRegionData (hrgn, BytesNeeded, RgnData);
934
935 i = RgnData->rdh.nCount;
936 pr = (PRECT)(RgnData->Buffer);
937
938 if (flags & DCX_WINDOW_W)
939 height = wnd->getWindowHeight();
940 else height = wnd->getClientHeight();
941
942 for (; (i > 0) && success; i--, pr++) {
943 LONG y = pr->yBottom;
944
945 pr->yBottom = height - pr->yTop;
946 pr->yTop = height - y;
947 success &= GpiExcludeClipRectangle (pHps->hps, pr);
948 }
949#endif
950 }
951 else //DCX_INTERSECTRGN_W
952 {
953 //SvL: I'm getting paint problems when clipping a dc created in GetDCEx
954 // with a region that covers the entire window (RealPlayer 7 Update 1)
955 // Using SelectClipRgn here doesn't make any difference.
956 if(ExtSelectClipRgn(pHps->hps, hrgn, RGN_AND_W) == ERROR_W) {
957 dprintf(("ExtSelectClipRgn failed!!"));
958 }
959 }
960 if (!success)
961 goto error;
962 }
963
964 if (creatingOwnDC)
965 wnd->setOwnDC ((HDC)hps);
966
967 pHps->psType = psType;
968 pHps->hdcType = TYPE_1;
969 //TODO: WM_SETREDRAW affects drawingAllowed flag!!
970 GpiSetDrawControl (hps, DCTL_DISPLAY, drawingAllowed ? DCTL_ON : DCTL_OFF);
971
972 dprintf (("User32: GetDCEx hwnd %x (%x %x) -> hdc %x", hwnd, hrgn, flags, pHps->hps));
973 return (HDC)pHps->hps;
974
975error:
976 /* Something went wrong; clean up
977 */
978 dprintf(("ERROR: GetDCEx hwnd %x (%x %x) FAILED!", hwnd, hrgn, flags));
979 DebugInt3();
980 if (pHps)
981 {
982 if (pHps->hps)
983 {
984 if(pHps->psType == MICRO_CACHED)
985 WinReleasePS(pHps->hps);
986 else
987 GpiDestroyPS(pHps->hps);
988 }
989
990 if (pHps->hdc) DevCloseDC(pHps->hdc);
991 if (pHps->hrgnHDC) GpiDestroyRegion(pHps->hps, pHps->hrgnHDC);
992
993 O32_DeleteObject (pHps->nullBitmapHandle);
994 }
995 SetLastError(ERROR_INVALID_PARAMETER_W);
996 return NULL;
997}
998//******************************************************************************
999//******************************************************************************
1000HDC WIN32API GetDC (HWND hwnd)
1001{
1002 if(!hwnd)
1003 return GetDCEx( GetDesktopWindow(), 0, DCX_CACHE_W | DCX_WINDOW_W );
1004 return GetDCEx (hwnd, NULL, 0);
1005}
1006//******************************************************************************
1007//******************************************************************************
1008HDC WIN32API GetWindowDC (HWND hwnd)
1009{
1010 if (!hwnd) hwnd = GetDesktopWindow();
1011 return GetDCEx (hwnd, NULL, DCX_WINDOW_W);
1012}
1013//******************************************************************************
1014//Helper for RedrawWindow (RDW_ALLCHILDREN_W)
1015//******************************************************************************
1016LRESULT WIN32API RedrawChildEnumProc(HWND hwnd, LPARAM lParam)
1017{
1018 RedrawWindow(hwnd, NULL, 0, lParam);
1019 return TRUE;
1020}
1021//******************************************************************************
1022// This implementation of RedrawWindow supports
1023// RDW_ERASE
1024// RDW_NOERASE
1025// RDW_INTERNALPAINT
1026// RDW_NOINTERNALPAINT
1027// RDW_INVALIDATE
1028// RDW_VALIDATE
1029// RDW_ERASENOW
1030// RDW_UPDATENOW
1031// RDW_FRAME
1032//
1033//TODO: Works ok for RDW_FRAME??
1034//******************************************************************************
1035BOOL WIN32API RedrawWindow(HWND hwnd, const RECT* pRect, HRGN hrgn, DWORD redraw)
1036{
1037 Win32BaseWindow *wnd;
1038
1039 if(pRect) {
1040 dprintf(("RedrawWindow %x (%d,%d)(%d,%d) %x %x", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom, hrgn, redraw));
1041 }
1042 else dprintf(("RedrawWindow %x %x %x %x", hwnd, pRect, hrgn, redraw));
1043
1044 if (hwnd == NULLHANDLE)
1045 {
1046#if 1
1047 // Don't do this for now (causes lots of desktop repaints in WordPad)
1048 SetLastError(ERROR_INVALID_PARAMETER_W);
1049 return FALSE;
1050#else
1051 hwnd = HWND_DESKTOP;
1052 wnd = Win32BaseWindow::GetWindowFromOS2Handle(OSLIB_HWND_DESKTOP);
1053
1054 if (!wnd)
1055 {
1056 dprintf(("USER32:dc: RedrawWindow can't find desktop window %08xh\n",
1057 hwnd));
1058 SetLastError(ERROR_INVALID_PARAMETER_W);
1059 return FALSE;
1060 }
1061#endif
1062 }
1063 else
1064 {
1065 wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
1066
1067 if (!wnd)
1068 {
1069 dprintf(("USER32:dc: RedrawWindow can't find window %08xh\n",
1070 hwnd));
1071 SetLastError(ERROR_INVALID_PARAMETER_W);
1072 return FALSE;
1073 }
1074 hwnd = wnd->getOS2WindowHandle();
1075 }
1076
1077 BOOL IncludeChildren = (redraw & RDW_ALLCHILDREN_W) ? TRUE : FALSE;
1078 BOOL success = TRUE;
1079 HPS hpsTemp = NULLHANDLE;
1080 HRGN hrgnTemp = NULLHANDLE;
1081 RECTL rectl;
1082
1083 if (hrgn)
1084 {
1085 ULONG BytesNeeded;
1086 PRGNDATA RgnData;
1087 PRECTL pr;
1088 int i;
1089 LONG height;
1090
1091 if(wnd) {
1092 height = (redraw & RDW_FRAME_W) ? wnd->getWindowHeight() : wnd->getClientHeight();
1093 }
1094 else height = OSLibQueryScreenHeight();
1095
1096 if (!hrgn)
1097 goto error;
1098
1099 BytesNeeded = GetRegionData (hrgn, 0, NULL);
1100 RgnData = (PRGNDATA)_alloca (BytesNeeded);
1101 if (RgnData == NULL)
1102 goto error;
1103 GetRegionData (hrgn, BytesNeeded, RgnData);
1104
1105 pr = (PRECTL)(RgnData->Buffer);
1106 for (i = RgnData->rdh.nCount; i > 0; i--, pr++) {
1107 LONG temp = pr->yTop;
1108 pr->yTop = height - pr->yBottom;
1109 pr->yBottom = height - temp;
1110 }
1111
1112 hpsTemp = WinGetScreenPS (HWND_DESKTOP);
1113 hrgnTemp = GpiCreateRegion (hpsTemp, RgnData->rdh.nCount, (PRECTL)(RgnData->Buffer));
1114 if (!hrgnTemp) goto error;
1115 }
1116 else if (pRect)
1117 {
1118 if(wnd) {
1119 if(redraw & RDW_FRAME_W) {
1120 mapWin32ToOS2Rect(wnd->getWindowHeight(), (PRECT)pRect, (PRECTLOS2)&rectl);
1121 }
1122 else mapWin32ToOS2RectClientToFrame(wnd, (PRECT)pRect, (PRECTLOS2)&rectl);
1123 }
1124 else mapWin32ToOS2Rect(OSLibQueryScreenHeight(), (PRECT)pRect, (PRECTLOS2)&rectl);
1125 }
1126
1127 if (redraw & RDW_INVALIDATE_W)
1128 {
1129 //TODO: SvL: pingpong.exe doesn't have RDW_NOERASE, but doesn't want WM_ERASEBKGND msgs
1130 if (redraw & RDW_ERASE_W) {
1131 wnd->setEraseBkgnd(TRUE);
1132 }
1133 else
1134 if (redraw & RDW_NOERASE_W)
1135 wnd->setEraseBkgnd(FALSE);
1136
1137 if (!pRect && !hrgn)
1138 success = WinInvalidateRect (hwnd, NULL, IncludeChildren);
1139 else
1140 if (hrgn) {
1141 success = WinInvalidateRegion (hwnd, hrgnTemp, IncludeChildren);
1142 if(IncludeChildren && WinQueryUpdateRect(hwnd, NULL) == FALSE) {
1143 dprintf(("WARNING: WinQueryUpdateRect %x region %x returned false even though we just invalidated part of a window!!!", hwnd, hrgnTemp));
1144 success = success = WinInvalidateRegion (hwnd, hrgnTemp, FALSE);
1145 }
1146 }
1147 else {
1148 success = WinInvalidateRect (hwnd, &rectl, IncludeChildren);
1149//SvL: If all children are included, then WinInvalidateRect is called
1150// with fIncludeChildren=1 -> rect of hwnd isn't invalidated if child(ren)
1151// overlap(s) the specified rectangle completely (EVEN if window doesn't
1152// have WS_CLIPCHILREN!)
1153// -> example: XWing vs Tie Fighter install window
1154// WinInvalidateRect with fIncludeChildren=0 invalidates both the parent
1155// and child windows
1156//SvL: Can't always set fIncludeChildren to FALSE or else some controls in
1157// the RealPlayer setup application aren't redrawn when invalidating
1158// their parent
1159// SO: Check if IncludeChildren is set and part of the window is invalid
1160// If not -> call WinInvalidateRect with IncludeChildren=0 to force
1161// the window rectangle to be invalidated
1162//
1163 if(IncludeChildren && WinQueryUpdateRect(hwnd, NULL) == FALSE) {
1164 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));
1165 success = WinInvalidateRect (hwnd, &rectl, FALSE);
1166 }
1167 }
1168
1169 if (!success) goto error;
1170 }
1171 else if (redraw & RDW_VALIDATE_W)
1172 {
1173 if (redraw & RDW_NOERASE_W)
1174 wnd->setEraseBkgnd(FALSE);
1175
1176 if (WinQueryUpdateRect (hwnd, NULL))
1177 {
1178 if(!pRect && !hrgn) {
1179 success = WinValidateRect (hwnd, NULL, IncludeChildren);
1180 }
1181 else
1182 if(hrgn) {
1183 success = WinValidateRegion (hwnd, hrgnTemp, IncludeChildren);
1184 }
1185 else {
1186 success = WinValidateRect (hwnd, &rectl, IncludeChildren);
1187 }
1188 if(!success) goto error;
1189 }
1190 }
1191
1192 if(WinQueryUpdateRect(hwnd, NULL))
1193 {
1194 //TODO: Does this work if RDW_ALLCHILDREN is set??
1195 if(redraw & RDW_UPDATENOW_W) {
1196 wnd->MsgNCPaint();
1197 wnd->MsgPaint(0, FALSE);
1198 }
1199 else
1200// if((redraw & RDW_ERASE_W) && (redraw & RDW_ERASENOW_W))
1201 if(redraw & RDW_ERASENOW_W && wnd->needsEraseBkgnd())
1202 wnd->setEraseBkgnd(sendEraseBkgnd(wnd) == 0);
1203// if(redraw & RDW_ALLCHILDREN_W) {
1204// EnumChildWindows(wnd->getWindowHandle(), RedrawChildEnumProc, redraw);
1205// }
1206 }
1207 else if((redraw & RDW_INTERNALPAINT_W) && !(redraw & RDW_INVALIDATE_W))
1208 {
1209 if(redraw & RDW_UPDATENOW_W) {
1210 wnd->MsgNCPaint();
1211 wnd->MsgPaint (0, FALSE);
1212 }
1213 else PostMessageA(hwnd, WINWM_PAINT, 0, 0);
1214 }
1215
1216error:
1217 /* clean up */
1218 if (hrgnTemp)
1219 GpiDestroyRegion (hpsTemp, hrgnTemp);
1220
1221 if (hpsTemp)
1222 WinReleasePS (hpsTemp);
1223
1224 if (!success) {
1225 dprintf(("RedrawWindow failure!"));
1226 SetLastError(ERROR_INVALID_PARAMETER_W);
1227 }
1228 return (success);
1229}
1230//******************************************************************************
1231//******************************************************************************
1232BOOL WIN32API UpdateWindow (HWND hwnd)
1233{
1234 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
1235
1236 if(!wnd) {
1237 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
1238 return FALSE;
1239 }
1240
1241 dprintf (("User32: UpdateWindow hwnd %x", hwnd));
1242//SvL: This doesn't work right (Wine uses RDW_NOCHILDREN_W -> doesn't work here)
1243// Breaks vpbuddy
1244// return RedrawWindow(hwnd, NULL, 0, RDW_UPDATENOW_W | RDW_ALLCHILDREN_W);
1245// -> RDW_UPDATENOW causes WM_PAINT messages to be directy posted to window
1246// handler; possibly bypassing queued WM_PAINT messages for parent window(s)
1247// -> out of sync painting (i.e. parent paints over child)
1248 WinUpdateWindow(wnd->getOS2WindowHandle());
1249 return TRUE;
1250}
1251//******************************************************************************
1252//******************************************************************************
1253BOOL WIN32API ValidateRect( HWND hwnd, const RECT * lprc)
1254{
1255 if(lprc) {
1256 dprintf(("USER32: ValidateRect %x (%d,%d)(%d,%d)", hwnd, lprc->left, lprc->top, lprc->right, lprc->bottom));
1257 }
1258 else dprintf(("USER32: ValidateRect %x", hwnd));
1259
1260 return RedrawWindow( hwnd, lprc, 0, RDW_VALIDATE_W | RDW_NOCHILDREN_W | (hwnd==0 ? RDW_UPDATENOW_W : 0));
1261}
1262//******************************************************************************
1263//******************************************************************************
1264BOOL WIN32API ValidateRgn( HWND hwnd, HRGN hrgn)
1265{
1266 dprintf(("USER32: ValidateRgn %x %x", hwnd, hrgn));
1267 return RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE_W | RDW_NOCHILDREN_W | (hwnd==0 ? RDW_UPDATENOW_W : 0));
1268}
1269//******************************************************************************
1270//******************************************************************************
1271BOOL WIN32API InvalidateRect (HWND hwnd, const RECT *pRect, BOOL erase)
1272{
1273 BOOL result;
1274
1275 if(pRect) {
1276 dprintf(("InvalidateRect %x (%d,%d)(%d,%d) erase=%d", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom, erase));
1277 }
1278 else dprintf(("InvalidateRect %x NULL erase=%d", hwnd, erase));
1279 result = RedrawWindow (hwnd, pRect, NULLHANDLE,
1280 RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
1281 (erase ? RDW_ERASE_W : RDW_NOERASE_W) |
1282 (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
1283 return (result);
1284}
1285//******************************************************************************
1286//******************************************************************************
1287BOOL WIN32API InvalidateRgn (HWND hwnd, HRGN hrgn, BOOL erase)
1288{
1289 BOOL result;
1290
1291 dprintf(("InvalidateRgn %x %x erase=%d", hwnd, hrgn, erase));
1292 result = RedrawWindow (hwnd, NULL, hrgn,
1293 RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
1294 (erase ? RDW_ERASE_W : RDW_NOERASE_W) |
1295 (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
1296 return (result);
1297}
1298//******************************************************************************
1299//TODO: Change for client rectangle!!!!!
1300//******************************************************************************
1301BOOL setPMRgnIntoWinRgn (HRGN hrgnPM, HRGN hrgnWin, LONG height)
1302{
1303 BOOL rc;
1304 HPS hps = WinGetScreenPS (HWND_DESKTOP);
1305 RGNRECT rgnRect;
1306 rgnRect.ircStart = 1;
1307 rgnRect.crc = 0;
1308 rgnRect.ulDirection = RECTDIR_LFRT_TOPBOT; // doesn't make a difference because we're getting them all
1309
1310 rc = GpiQueryRegionRects (hps, hrgnPM, NULL, &rgnRect, NULL);
1311
1312 if (rc && (rgnRect.crcReturned > 0))
1313 {
1314 PRECTL Rcls = new RECTL[rgnRect.crcReturned];
1315 PRECTL pRcl = Rcls;
1316
1317 if (Rcls != NULL)
1318 {
1319 rgnRect.crc = rgnRect.crcReturned;
1320 rc = GpiQueryRegionRects (hps, hrgnPM, NULL, &rgnRect, Rcls);
1321
1322 rc = SetRectRgn(hrgnWin, pRcl->xLeft,
1323 pRcl->xRight,
1324 height - pRcl->yTop,
1325 height - pRcl->yBottom);
1326
1327 if (rgnRect.crcReturned > 1)
1328 {
1329 int i;
1330 HRGN temp;
1331 temp = CreateRectRgn (0, 0, 1, 1);
1332
1333 for (i = 1, pRcl++; rc && (i < rgnRect.crcReturned); i++, pRcl++)
1334 {
1335 rc = SetRectRgn (temp, pRcl->xLeft,
1336 pRcl->xRight,
1337 height - pRcl->yTop,
1338 height - pRcl->yBottom);
1339 rc &= CombineRgn (hrgnWin, hrgnWin, temp, RGN_OR_W);
1340 }
1341 DeleteObject (temp);
1342 }
1343 delete[] Rcls;
1344 }
1345 else
1346 {
1347 rc = FALSE;
1348 }
1349 }
1350 else
1351 {
1352 rc = SetRectRgn (hrgnWin, 0, 0, 0, 0);
1353 }
1354
1355 WinReleasePS (hps);
1356 return (rc);
1357}
1358//******************************************************************************
1359//TODO: Check if this one works correctly...
1360//Have to check if dc is for frame or client!!
1361//******************************************************************************
1362BOOL WIN32API ScrollDC(HDC hDC, int dx, int dy, const RECT *pScroll,
1363 const RECT *pClip, HRGN hrgnUpdate, LPRECT pRectUpdate)
1364{
1365 BOOL rc = TRUE;
1366
1367 dprintf (("USER32: ScrollDC %x (%d,%d), %x %x %x %x", hDC, dx, dy, pScroll, pClip, hrgnUpdate, pRectUpdate));
1368
1369 if (!hDC)
1370 {
1371 return (FALSE);
1372 }
1373
1374 pDCData pHps = (pDCData)GpiQueryDCData ((HPS)hDC);
1375 HWND hwnd = pHps->hwnd;
1376 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
1377
1378 if ((hwnd == NULLHANDLE) || !wnd)
1379 {
1380 return (FALSE);
1381 }
1382
1383 POINTL ptl[2] = { 0, 0, dx, dy };
1384
1385 GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, ptl);
1386 dx = (int)(ptl[1].x - ptl[0].x);
1387 dy = (int)(ptl[1].y - ptl[0].y);
1388
1389 RECT scrollRect;
1390 RECT clipRect;
1391
1392 if (pClip)
1393 {
1394 memcpy(&clipRect, pClip, sizeof(clipRect));
1395
1396 if ((pHps->graphicsMode == GM_COMPATIBLE_W) &&
1397 (clipRect.left != clipRect.right) &&
1398 (clipRect.bottom != clipRect.top))
1399 {
1400 if (abs((int)pHps->viewportXExt) <= abs((int)pHps->windowExt.cx))
1401 clipRect.right -= abs(pHps->worldXDeltaFor1Pixel);
1402 else
1403 clipRect.left += abs(pHps->worldXDeltaFor1Pixel);
1404
1405 if (abs((int)pHps->viewportYExt) <= abs((int)pHps->windowExt.cy))
1406 clipRect.bottom -= abs(pHps->worldYDeltaFor1Pixel);
1407 else
1408 clipRect.top += abs(pHps->worldYDeltaFor1Pixel);
1409 }
1410 GpiConvert(pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, (PPOINTL)&clipRect);
1411 if (clipRect.right < clipRect.left) {
1412 ULONG temp = clipRect.left;
1413 clipRect.left = clipRect.right;
1414 clipRect.right = temp;
1415 }
1416 if (clipRect.bottom < clipRect.top) {
1417 ULONG temp = clipRect.top;
1418 clipRect.top = clipRect.bottom;
1419 clipRect.bottom = temp;
1420 }
1421 }
1422
1423 if (pScroll)
1424 {
1425 memcpy(&scrollRect, pScroll, sizeof(scrollRect));
1426
1427 if ((pHps->graphicsMode == GM_COMPATIBLE_W) &&
1428 (scrollRect.left != scrollRect.right) &&
1429 (scrollRect.top != scrollRect.bottom))
1430 {
1431 if (abs((int)pHps->viewportXExt) <= abs((int)pHps->windowExt.cx))
1432 scrollRect.right -= abs(pHps->worldXDeltaFor1Pixel);
1433 else
1434 scrollRect.left += abs(pHps->worldXDeltaFor1Pixel);
1435
1436 if (abs((int)pHps->viewportYExt) <= abs((int)pHps->windowExt.cy))
1437 scrollRect.bottom -= abs(pHps->worldYDeltaFor1Pixel);
1438 else
1439 scrollRect.top += abs(pHps->worldYDeltaFor1Pixel);
1440 }
1441 GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, (PPOINTL)&scrollRect);
1442 if (scrollRect.right < scrollRect.left) {
1443 ULONG temp = scrollRect.left;
1444 scrollRect.left = scrollRect.right;
1445 scrollRect.right = temp;
1446 }
1447 if (scrollRect.bottom < scrollRect.top) {
1448 ULONG temp = scrollRect.top;
1449 scrollRect.top = scrollRect.bottom;
1450 scrollRect.bottom = temp;
1451 }
1452 }
1453 RECTL rectlUpdate;
1454 HRGN hrgn;
1455 RECTL clientRect;
1456 RECTL clipOS2;
1457 RECTL scrollOS2;
1458 PRECTL pScrollOS2 = NULL;
1459 PRECTL pClipOS2 = NULL;
1460
1461 mapWin32ToOS2Rect(wnd->getWindowHeight(), wnd->getClientRectPtr(), (PRECTLOS2)&clientRect);
1462
1463 if(pScroll) {
1464 mapWin32ToOS2RectClientToFrame(wnd, &scrollRect, (PRECTLOS2)&scrollOS2);
1465 pScrollOS2 = &scrollOS2;
1466
1467 //Scroll rectangle relative to client area
1468 WinIntersectRect ((HAB) 0, pScrollOS2, pScrollOS2, &clientRect);
1469 }
1470 else {
1471 pScrollOS2 = &clientRect;
1472 }
1473
1474 if(pClip) {
1475 mapWin32ToOS2RectClientToFrame(wnd, &clipRect, (PRECTLOS2)&clipOS2);
1476 pClipOS2 = &clipOS2;
1477
1478 //Clip rectangle relative to client area
1479 WinIntersectRect((HAB) 0, pClipOS2, pClipOS2, &clientRect);
1480 }
1481 else {
1482 pClipOS2 = &clientRect;
1483 }
1484
1485 LONG lComplexity = WinScrollWindow(hwnd, dx, dy, pScrollOS2,
1486 pClipOS2, hrgn, &rectlUpdate, 0);
1487 if (lComplexity == RGN_ERROR)
1488 {
1489 return (FALSE);
1490 }
1491
1492 RECT winRectUpdate;
1493
1494 mapOS2ToWin32Rect(wnd->getWindowHeight(), (PRECTLOS2)&rectlUpdate, &winRectUpdate);
1495
1496 if (pRectUpdate)
1497 *pRectUpdate = winRectUpdate;
1498
1499 if (hrgnUpdate)
1500 rc = setPMRgnIntoWinRgn(hrgn, hrgnUpdate, wnd->getWindowHeight());
1501
1502 return (rc);
1503}
1504//******************************************************************************
1505//******************************************************************************
1506BOOL WIN32API ScrollWindow(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip)
1507{
1508 Win32BaseWindow *window;
1509 APIRET rc;
1510 RECTL clientRect;
1511 RECTL scrollRect;
1512 RECTL clipRect;
1513 PRECTL pScrollOS2 = NULL;
1514 PRECTL pClipOS2 = NULL;
1515 ULONG scrollFlags = SW_INVALIDATERGN;
1516
1517 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1518 if(!window) {
1519 dprintf(("ScrollWindow, window %x not found", hwnd));
1520 return 0;
1521 }
1522 dprintf(("ScrollWindow %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip));
1523
1524 mapWin32ToOS2Rect(window->getWindowHeight(), window->getClientRectPtr(), (PRECTLOS2)&clientRect);
1525
1526 if(pScroll) {
1527 mapWin32ToOS2RectClientToFrame(window,(RECT *)pScroll, (PRECTLOS2)&scrollRect);
1528 pScrollOS2 = &scrollRect;
1529
1530 //Scroll rectangle relative to client area
1531 WinIntersectRect ((HAB) 0, pScrollOS2, pScrollOS2, &clientRect);
1532 }
1533 else {
1534 pScrollOS2 = &clientRect;
1535 scrollFlags |= SW_SCROLLCHILDREN;
1536 }
1537
1538 if(pClip) {
1539 mapWin32ToOS2RectClientToFrame(window,(RECT *)pClip, (PRECTLOS2)&clipRect);
1540 pClipOS2 = &clipRect;
1541
1542 //Clip rectangle relative to client area
1543 WinIntersectRect ((HAB) 0, pClipOS2, pClipOS2, &clientRect);
1544 }
1545 else {
1546 pClipOS2 = &clientRect;
1547 }
1548
1549 dy = revertDy (window, dy);
1550
1551 rc = WinScrollWindow(window->getOS2WindowHandle(), dx, dy,
1552 pScrollOS2, pClipOS2, NULLHANDLE,
1553 NULL, scrollFlags);
1554
1555 return (rc != RGN_ERROR);
1556}
1557//******************************************************************************
1558//******************************************************************************
1559INT WIN32API ScrollWindowEx(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip,
1560 HRGN hrgnUpdate, PRECT pRectUpdate, UINT scrollFlag)
1561{
1562 Win32BaseWindow *window;
1563 APIRET rc;
1564 RECTL clientRect;
1565 RECTL scrollRect;
1566 RECTL clipRect;
1567 PRECTL pScrollOS2 = NULL;
1568 PRECTL pClipOS2 = NULL;
1569 ULONG scrollFlags = 0;
1570 int regionType = ERROR_W;
1571
1572 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1573 if(!window) {
1574 dprintf(("ScrollWindowEx, window %x not found", hwnd));
1575 return 0;
1576 }
1577
1578 dprintf(("ScrollWindowEx %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip));
1579
1580 dy = revertDy (window, dy);
1581
1582 if (scrollFlag & SW_INVALIDATE_W) scrollFlags |= SW_INVALIDATERGN;
1583 if (scrollFlag & SW_SCROLLCHILDREN_W) scrollFlags |= SW_SCROLLCHILDREN;
1584
1585 mapWin32ToOS2Rect(window->getWindowHeight(), window->getClientRectPtr(), (PRECTLOS2)&clientRect);
1586
1587 if(pScroll) {
1588 mapWin32ToOS2RectClientToFrame(window,(RECT *)pScroll, (PRECTLOS2)&scrollRect);
1589 pScrollOS2 = &scrollRect;
1590
1591 //Scroll rectangle relative to client area
1592 WinIntersectRect ((HAB) 0, pScrollOS2, pScrollOS2, &clientRect);
1593 }
1594 else {
1595 pScrollOS2 = &clientRect;
1596 scrollFlags |= SW_SCROLLCHILDREN; //TODO: ?????
1597 }
1598
1599 if(pClip) {
1600 mapWin32ToOS2RectClientToFrame(window,(RECT *)pClip, (PRECTLOS2)&clipRect);
1601 pClipOS2 = &clipRect;
1602
1603 //Clip rectangle relative to client area
1604 WinIntersectRect ((HAB) 0, pClipOS2, pClipOS2, &clientRect);
1605 }
1606 else {
1607 pClipOS2 = &clientRect;
1608 }
1609
1610 RECTL rectlUpdate;
1611 HRGN hrgn;
1612
1613 if (scrollFlag & SW_SMOOTHSCROLL_W)
1614 {
1615 INT time = (scrollFlag >> 16) & 0xFFFF;
1616
1617 //CB: todo, scroll in several steps
1618 // is time in ms? time <-> iteration count?
1619 }
1620
1621 LONG lComplexity = WinScrollWindow (window->getOS2WindowHandle(), dx, dy,
1622 pScrollOS2,
1623 pClipOS2,
1624 hrgn, &rectlUpdate, scrollFlags);
1625 if (lComplexity == RGN_ERROR)
1626 {
1627 return ERROR_W;
1628 }
1629
1630 RECT winRectUpdate;
1631
1632 mapOS2ToWin32Rect(window->getWindowHeight(), (PRECTLOS2)&rectlUpdate, &winRectUpdate);
1633
1634 if (pRectUpdate)
1635 *pRectUpdate = winRectUpdate;
1636
1637 if (hrgnUpdate)
1638 rc = setPMRgnIntoWinRgn (hrgn, hrgnUpdate, window->getWindowHeight());
1639
1640#if 0
1641 //SvL: WinScrollWindow already invalidates the area; no need to do it again
1642 //(call to invalidateRect was wrong; has to include erase flag)
1643 if ((scrollFlag & SW_INVALIDATE_W) &&
1644 ((lComplexity == RGN_RECT) || (lComplexity == RGN_COMPLEX)))
1645 {
1646 rc = InvalidateRect (hwnd, &winRectUpdate, (scrollFlag & SW_ERASE_W) ? 1 : 0);
1647 if (rc == FALSE)
1648 {
1649 return (0);
1650 }
1651 }
1652#endif
1653
1654 switch (lComplexity)
1655 {
1656 case RGN_NULL:
1657 regionType = NULLREGION_W;
1658 break;
1659 case RGN_RECT:
1660 regionType = SIMPLEREGION_W;
1661 break;
1662 case RGN_COMPLEX:
1663 regionType = COMPLEXREGION_W;
1664 break;
1665 default:
1666 regionType = ERROR_W;
1667 break;
1668 }
1669
1670 return (regionType);
1671}
1672//******************************************************************************
1673//******************************************************************************
1674HWND WIN32API WindowFromDC(HDC hdc)
1675{
1676 pDCData pHps = (pDCData)GpiQueryDCData( (HPS)hdc );
1677
1678 dprintf2(("USER32: WindowFromDC %x", hdc));
1679 if ( pHps )
1680 return Win32BaseWindow::OS2ToWin32Handle(pHps->hwnd);
1681 else
1682 return 0;
1683}
1684//******************************************************************************
1685//******************************************************************************
1686int WIN32API SetMapMode(HDC hdc, int mode)
1687{
1688 Win32BaseWindow *wnd;
1689 pDCData pHps = (pDCData)GpiQueryDCData((HPS)hdc);
1690 if(!pHps)
1691 {
1692 SetLastError(ERROR_INVALID_HANDLE_W);
1693 dprintf(("GDI32: SetMapMode %x %x -> invalid hdc!!", hdc, mode));
1694 return 0;
1695 }
1696 wnd = Win32BaseWindow::GetWindowFromHandle(WindowFromDC(hdc));
1697 //todo: metafile recording
1698
1699 dprintf(("GDI32: SetMapMode %x %x", hdc, mode));
1700 return setMapMode(wnd, pHps, mode);
1701}
1702//******************************************************************************
1703//******************************************************************************
1704int WIN32API GetMapMode(HDC hdc)
1705{
1706 pDCData pHps = (pDCData)GpiQueryDCData((HPS)hdc);
1707 if(pHps) {
1708 dprintf(("GDI32: GetMapMode %x -> %x", hdc, pHps->MapMode));
1709 return pHps->MapMode;
1710 }
1711 dprintf(("GDI32: GetMapMode: invalid hdc %x!!!", hdc));
1712 SetLastError(ERROR_INVALID_HANDLE_W);
1713 return 0;
1714}
1715//******************************************************************************
1716//******************************************************************************
1717BOOL WIN32API SetViewportExtEx(HDC hdc, int xExt, int yExt, LPSIZE pSize)
1718{
1719 Win32BaseWindow *wnd;
1720 pDCData pHps = (pDCData)GpiQueryDCData((HPS)hdc);
1721
1722 if(!pHps)
1723 {
1724 dprintf(("GDI32: SetViewportExtEx %x %d %d %x -> INVALID HDC", hdc, xExt, yExt, pSize));
1725 SetLastError(ERROR_INVALID_HANDLE_W);
1726 return FALSE;
1727 }
1728
1729 if(pSize) {
1730 dprintf(("GDI32: SetViewportExtEx %x %d %d (%d,%d)", hdc, xExt, yExt, pSize->cx, pSize->cy));
1731 }
1732 else dprintf(("GDI32: SetViewportExtEx %x %d %d NULL", hdc, xExt, yExt));
1733
1734 if (xExt && yExt )
1735 {
1736 //todo: Metafile recording!! (done for any map mode)
1737
1738 if(pHps->MapMode == MM_ISOTROPIC_W || pHps->MapMode == MM_ANISOTROPIC_W)
1739 {
1740 wnd = Win32BaseWindow::GetWindowFromHandle(WindowFromDC(hdc));
1741 if(changePageXForm(wnd, pHps, NULL, xExt, yExt, (PPOINTL) pSize))
1742 {
1743 SetLastError(ERROR_SUCCESS_W);
1744 return TRUE;
1745 }
1746 }
1747 else
1748 {
1749 pHps->lVwpXExtSave = xExt;
1750 pHps->lVwpYExtSave = yExt;
1751
1752 //if map mode is not ISOTROPIC nor ANISOTROPIC, this function does
1753 //nothing and returns TRUE (NT)
1754 SetLastError(ERROR_SUCCESS_W);
1755 return TRUE;
1756 }
1757
1758 SetLastError(ERROR_SUCCESS_W);
1759 return FALSE;
1760 }
1761
1762 SetLastError(ERROR_INVALID_PARAMETER_W);
1763 return FALSE;
1764}
1765//******************************************************************************
1766//******************************************************************************
1767BOOL WIN32API GetViewportExtEx(HDC hdc, LPSIZE pSize)
1768{
1769 pDCData pHps = (pDCData)GpiQueryDCData((HPS)hdc);
1770 if(!pHps)
1771 {
1772 dprintf(("GDI32: GetViewportExtEx %x %x -> INVALID HDC", hdc, pSize));
1773 SetLastError(ERROR_INVALID_HANDLE_W);
1774 return FALSE;
1775 }
1776
1777 if(!pSize)
1778 {
1779 dprintf(("GDI32: GetViewportExtEx %x NULL -> INVALID parameter", hdc));
1780 SetLastError(ERROR_INVALID_PARAMETER_W);
1781 return FALSE;
1782 }
1783
1784 pSize->cx = (LONG)pHps->viewportXExt;
1785 pSize->cy = (LONG)pHps->viewportYExt;
1786 dprintf(("GDI32: GetViewportExtEx %x -> (%d,%d)", hdc, pSize->cx, pSize->cy));
1787
1788 SetLastError(ERROR_SUCCESS_W);
1789 return TRUE;
1790}
1791//******************************************************************************
1792//******************************************************************************
Note: See TracBrowser for help on using the repository browser.