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

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

extra exports for gdi32; moved 4 apis back into gdi32

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