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

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

LockWindowUpdate rewritten + small changes

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