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

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

fix for excessive redrawing in Notes

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