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

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

region fixes for RedrawWindow

File size: 48.5 KB
Line 
1/* $Id: dc.cpp,v 1.62 2000-06-17 09:45:00 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 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 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 = GetRegionData (hrgn, 0, NULL);
1069 RgnData = (PRGNDATA)_alloca (BytesNeeded);
1070 if (RgnData == NULL)
1071 goto error;
1072 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 }
1112 else
1113 success = WinInvalidateRect (hwnd, &rectl, IncludeChildren);
1114
1115 if (!success) goto error;
1116 }
1117 else if (redraw & RDW_VALIDATE_W)
1118 {
1119 if (redraw & RDW_NOERASE_W)
1120 wnd->setEraseBkgnd(FALSE);
1121
1122 if (WinQueryUpdateRect (hwnd, NULL))
1123 {
1124 if (!pRect && !hrgn)
1125 success = WinValidateRect (hwnd, NULL, IncludeChildren);
1126 else
1127 if (hrgn) {
1128 success = WinValidateRegion (hwnd, hrgnTemp, IncludeChildren);
1129 }
1130 else
1131 success = WinValidateRect (hwnd, &rectl, IncludeChildren);
1132 if (!success) goto error;
1133 }
1134 }
1135
1136 if(WinQueryUpdateRect(hwnd, NULL))
1137 {
1138 //TODO: Does this work if RDW_ALLCHILDREN is set??
1139 if(redraw & RDW_UPDATENOW_W) {
1140 wnd->MsgNCPaint();
1141 wnd->MsgPaint(0, FALSE);
1142 }
1143 else
1144// if((redraw & RDW_ERASE_W) && (redraw & RDW_ERASENOW_W))
1145 if(redraw & RDW_ERASENOW_W && wnd->needsEraseBkgnd())
1146 wnd->setEraseBkgnd(sendEraseBkgnd(wnd) == 0);
1147 }
1148 else if((redraw & RDW_INTERNALPAINT_W) && !(redraw & RDW_INVALIDATE_W))
1149 {
1150 if(redraw & RDW_UPDATENOW_W) {
1151 wnd->MsgNCPaint();
1152 wnd->MsgPaint (0, FALSE);
1153 }
1154 else PostMessageA(hwnd, WINWM_PAINT, 0, 0);
1155 }
1156
1157error:
1158 /* clean up */
1159 if (hrgnTemp)
1160 GpiDestroyRegion (hpsTemp, hrgnTemp);
1161
1162 if (hpsTemp)
1163 WinReleasePS (hpsTemp);
1164
1165 if (!success)
1166 SetLastError(ERROR_INVALID_PARAMETER_W);
1167
1168 return (success);
1169}
1170//******************************************************************************
1171//******************************************************************************
1172BOOL WIN32API UpdateWindow (HWND hwnd)
1173{
1174 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
1175
1176 if(!wnd) {
1177 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
1178 return FALSE;
1179 }
1180
1181 dprintf (("User32: UpdateWindow hwnd %x", hwnd));
1182////SvL: This doesn't work right (Wine uses RDW_NOCHILDREN_W -> doesn't work here)
1183//// Breaks vpbuddy
1184//// return RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW_W | RDW_ALLCHILDREN_W);
1185 WinUpdateWindow(wnd->getOS2WindowHandle());
1186 return TRUE;
1187}
1188//******************************************************************************
1189//******************************************************************************
1190BOOL WIN32API InvalidateRect (HWND hwnd, const RECT *pRect, BOOL erase)
1191{
1192 BOOL result;
1193
1194 if(pRect) {
1195 dprintf(("InvalidateRect %x (%d,%d)(%d,%d) erase=%d", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom, erase));
1196 }
1197 else dprintf(("InvalidateRect %x NULL erase=%d", hwnd, erase));
1198 result = RedrawWindow (hwnd, pRect, NULLHANDLE,
1199 RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
1200 (erase ? RDW_ERASE_W : RDW_NOERASE_W) |
1201 (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
1202 return (result);
1203}
1204//******************************************************************************
1205//******************************************************************************
1206BOOL WIN32API InvalidateRgn (HWND hwnd, HRGN hrgn, BOOL erase)
1207{
1208 BOOL result;
1209
1210 dprintf(("InvalidateRgn %x %x erase=%d", hwnd, hrgn, erase));
1211 result = RedrawWindow (hwnd, NULL, hrgn,
1212 RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
1213 (erase ? RDW_ERASE_W : RDW_NOERASE_W) |
1214 (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
1215 return (result);
1216}
1217//******************************************************************************
1218//TODO: Change for client rectangle!!!!!
1219//******************************************************************************
1220BOOL setPMRgnIntoWinRgn (HRGN hrgnPM, HRGN hrgnWin, LONG height)
1221{
1222 BOOL rc;
1223 HPS hps = WinGetScreenPS (HWND_DESKTOP);
1224 RGNRECT rgnRect;
1225 rgnRect.ircStart = 1;
1226 rgnRect.crc = 0;
1227 rgnRect.ulDirection = RECTDIR_LFRT_TOPBOT; // doesn't make a difference because we're getting them all
1228
1229 rc = GpiQueryRegionRects (hps, hrgnPM, NULL, &rgnRect, NULL);
1230
1231 if (rc && (rgnRect.crcReturned > 0))
1232 {
1233 PRECTL Rcls = new RECTL[rgnRect.crcReturned];
1234 PRECTL pRcl = Rcls;
1235
1236 if (Rcls != NULL)
1237 {
1238 rgnRect.crc = rgnRect.crcReturned;
1239 rc = GpiQueryRegionRects (hps, hrgnPM, NULL, &rgnRect, Rcls);
1240
1241 rc = SetRectRgn(hrgnWin, pRcl->xLeft,
1242 pRcl->xRight,
1243 height - pRcl->yTop,
1244 height - pRcl->yBottom);
1245
1246 if (rgnRect.crcReturned > 1)
1247 {
1248 int i;
1249 HRGN temp;
1250 temp = CreateRectRgn (0, 0, 1, 1);
1251
1252 for (i = 1, pRcl++; rc && (i < rgnRect.crcReturned); i++, pRcl++)
1253 {
1254 rc = SetRectRgn (temp, pRcl->xLeft,
1255 pRcl->xRight,
1256 height - pRcl->yTop,
1257 height - pRcl->yBottom);
1258 rc &= CombineRgn (hrgnWin, hrgnWin, temp, RGN_OR_W);
1259 }
1260 DeleteObject (temp);
1261 }
1262 delete[] Rcls;
1263 }
1264 else
1265 {
1266 rc = FALSE;
1267 }
1268 }
1269 else
1270 {
1271 rc = SetRectRgn (hrgnWin, 0, 0, 0, 0);
1272 }
1273
1274 WinReleasePS (hps);
1275 return (rc);
1276}
1277//******************************************************************************
1278//TODO: Check if this one works correctly...
1279//Have to check if dc is for frame or client!!
1280//******************************************************************************
1281BOOL WIN32API ScrollDC(HDC hDC, int dx, int dy, const RECT *pScroll,
1282 const RECT *pClip, HRGN hrgnUpdate, LPRECT pRectUpdate)
1283{
1284 BOOL rc = TRUE;
1285
1286 dprintf (("USER32: ScrollDC %x (%d,%d), %x %x %x %x", hDC, dx, dy, pScroll, pClip, hrgnUpdate, pRectUpdate));
1287
1288 if (!hDC)
1289 {
1290 return (FALSE);
1291 }
1292
1293 pDCData pHps = (pDCData)GpiQueryDCData ((HPS)hDC);
1294 HWND hwnd = pHps->hwnd;
1295 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
1296
1297 if ((hwnd == NULLHANDLE) || !wnd)
1298 {
1299 return (FALSE);
1300 }
1301
1302 POINTL ptl[2] = { 0, 0, dx, dy };
1303
1304 GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, ptl);
1305 dx = (int)(ptl[1].x - ptl[0].x);
1306 dy = (int)(ptl[1].y - ptl[0].y);
1307
1308 RECT scrollRect;
1309 RECT clipRect;
1310
1311 if (pClip)
1312 {
1313 memcpy(&clipRect, pClip, sizeof(clipRect));
1314
1315 if ((pHps->graphicsMode == GM_COMPATIBLE_W) &&
1316 (clipRect.left != clipRect.right) &&
1317 (clipRect.bottom != clipRect.top))
1318 {
1319 if (abs((int)pHps->viewportXExt) <= abs((int)pHps->windowExt.cx))
1320 clipRect.right -= abs(pHps->worldXDeltaFor1Pixel);
1321 else
1322 clipRect.left += abs(pHps->worldXDeltaFor1Pixel);
1323
1324 if (abs((int)pHps->viewportYExt) <= abs((int)pHps->windowExt.cy))
1325 clipRect.bottom -= abs(pHps->worldYDeltaFor1Pixel);
1326 else
1327 clipRect.top += abs(pHps->worldYDeltaFor1Pixel);
1328 }
1329 GpiConvert(pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, (PPOINTL)&clipRect);
1330 if (clipRect.right < clipRect.left) {
1331 ULONG temp = clipRect.left;
1332 clipRect.left = clipRect.right;
1333 clipRect.right = temp;
1334 }
1335 if (clipRect.bottom < clipRect.top) {
1336 ULONG temp = clipRect.top;
1337 clipRect.top = clipRect.bottom;
1338 clipRect.bottom = temp;
1339 }
1340 }
1341
1342 if (pScroll)
1343 {
1344 memcpy(&scrollRect, pScroll, sizeof(scrollRect));
1345
1346 if ((pHps->graphicsMode == GM_COMPATIBLE_W) &&
1347 (scrollRect.left != scrollRect.right) &&
1348 (scrollRect.top != scrollRect.bottom))
1349 {
1350 if (abs((int)pHps->viewportXExt) <= abs((int)pHps->windowExt.cx))
1351 scrollRect.right -= abs(pHps->worldXDeltaFor1Pixel);
1352 else
1353 scrollRect.left += abs(pHps->worldXDeltaFor1Pixel);
1354
1355 if (abs((int)pHps->viewportYExt) <= abs((int)pHps->windowExt.cy))
1356 scrollRect.bottom -= abs(pHps->worldYDeltaFor1Pixel);
1357 else
1358 scrollRect.top += abs(pHps->worldYDeltaFor1Pixel);
1359 }
1360 GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, (PPOINTL)&scrollRect);
1361 if (scrollRect.right < scrollRect.left) {
1362 ULONG temp = scrollRect.left;
1363 scrollRect.left = scrollRect.right;
1364 scrollRect.right = temp;
1365 }
1366 if (scrollRect.bottom < scrollRect.top) {
1367 ULONG temp = scrollRect.top;
1368 scrollRect.top = scrollRect.bottom;
1369 scrollRect.bottom = temp;
1370 }
1371 }
1372 RECTL rectlUpdate;
1373 HRGN hrgn;
1374 RECTL clientRect;
1375 RECTL clipOS2;
1376 RECTL scrollOS2;
1377 PRECTL pScrollOS2 = NULL;
1378 PRECTL pClipOS2 = NULL;
1379
1380 mapWin32ToOS2Rect(wnd->getWindowHeight(), wnd->getClientRectPtr(), (PRECTLOS2)&clientRect);
1381
1382 if(pScroll) {
1383 mapWin32ToOS2RectClientToFrame(wnd, &scrollRect, (PRECTLOS2)&scrollOS2);
1384 pScrollOS2 = &scrollOS2;
1385
1386 //Scroll rectangle relative to client area
1387 WinIntersectRect ((HAB) 0, pScrollOS2, pScrollOS2, &clientRect);
1388 }
1389 else {
1390 pScrollOS2 = &clientRect;
1391 }
1392
1393 if(pClip) {
1394 mapWin32ToOS2RectClientToFrame(wnd, &clipRect, (PRECTLOS2)&clipOS2);
1395 pClipOS2 = &clipOS2;
1396
1397 //Clip rectangle relative to client area
1398 WinIntersectRect((HAB) 0, pClipOS2, pClipOS2, &clientRect);
1399 }
1400 else {
1401 pClipOS2 = &clientRect;
1402 }
1403
1404 LONG lComplexity = WinScrollWindow(hwnd, dx, dy, pScrollOS2,
1405 pClipOS2, hrgn, &rectlUpdate, 0);
1406 if (lComplexity == RGN_ERROR)
1407 {
1408 return (FALSE);
1409 }
1410
1411 RECT winRectUpdate;
1412
1413 mapOS2ToWin32Rect(wnd->getWindowHeight(), (PRECTLOS2)&rectlUpdate, &winRectUpdate);
1414
1415 if (pRectUpdate)
1416 *pRectUpdate = winRectUpdate;
1417
1418 if (hrgnUpdate)
1419 rc = setPMRgnIntoWinRgn(hrgn, hrgnUpdate, wnd->getWindowHeight());
1420
1421 return (rc);
1422}
1423//******************************************************************************
1424//******************************************************************************
1425BOOL WIN32API ScrollWindow(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip)
1426{
1427 Win32BaseWindow *window;
1428 APIRET rc;
1429 RECTL clientRect;
1430 RECTL scrollRect;
1431 RECTL clipRect;
1432 PRECTL pScrollOS2 = NULL;
1433 PRECTL pClipOS2 = NULL;
1434 ULONG scrollFlags = SW_INVALIDATERGN;
1435
1436 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1437 if(!window) {
1438 dprintf(("ScrollWindow, window %x not found", hwnd));
1439 return 0;
1440 }
1441 dprintf(("ScrollWindow %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip));
1442
1443 mapWin32ToOS2Rect(window->getWindowHeight(), window->getClientRectPtr(), (PRECTLOS2)&clientRect);
1444
1445 if(pScroll) {
1446 mapWin32ToOS2RectClientToFrame(window,(RECT *)pScroll, (PRECTLOS2)&scrollRect);
1447 pScrollOS2 = &scrollRect;
1448
1449 //Scroll rectangle relative to client area
1450 WinIntersectRect ((HAB) 0, pScrollOS2, pScrollOS2, &clientRect);
1451 }
1452 else {
1453 pScrollOS2 = &clientRect;
1454 scrollFlags |= SW_SCROLLCHILDREN;
1455 }
1456
1457 if(pClip) {
1458 mapWin32ToOS2RectClientToFrame(window,(RECT *)pClip, (PRECTLOS2)&clipRect);
1459 pClipOS2 = &clipRect;
1460
1461 //Clip rectangle relative to client area
1462 WinIntersectRect ((HAB) 0, pClipOS2, pClipOS2, &clientRect);
1463 }
1464 else {
1465 pClipOS2 = &clientRect;
1466 }
1467
1468 dy = revertDy (window, dy);
1469
1470 rc = WinScrollWindow(window->getOS2WindowHandle(), dx, dy,
1471 pScrollOS2, pClipOS2, NULLHANDLE,
1472 NULL, scrollFlags);
1473
1474 return (rc != RGN_ERROR);
1475}
1476//******************************************************************************
1477//******************************************************************************
1478INT WIN32API ScrollWindowEx(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip,
1479 HRGN hrgnUpdate, PRECT pRectUpdate, UINT scrollFlag)
1480{
1481 Win32BaseWindow *window;
1482 APIRET rc;
1483 RECTL clientRect;
1484 RECTL scrollRect;
1485 RECTL clipRect;
1486 PRECTL pScrollOS2 = NULL;
1487 PRECTL pClipOS2 = NULL;
1488 ULONG scrollFlags = 0;
1489 int regionType = ERROR_W;
1490
1491 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1492 if(!window) {
1493 dprintf(("ScrollWindowEx, window %x not found", hwnd));
1494 return 0;
1495 }
1496
1497 dprintf(("ScrollWindowEx %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip));
1498
1499 dy = revertDy (window, dy);
1500
1501 if (scrollFlag & SW_INVALIDATE_W) scrollFlags |= SW_INVALIDATERGN;
1502 if (scrollFlag & SW_SCROLLCHILDREN_W) scrollFlags |= SW_SCROLLCHILDREN;
1503
1504 mapWin32ToOS2Rect(window->getWindowHeight(), window->getClientRectPtr(), (PRECTLOS2)&clientRect);
1505
1506 if(pScroll) {
1507 mapWin32ToOS2RectClientToFrame(window,(RECT *)pScroll, (PRECTLOS2)&scrollRect);
1508 pScrollOS2 = &scrollRect;
1509
1510 //Scroll rectangle relative to client area
1511 WinIntersectRect ((HAB) 0, pScrollOS2, pScrollOS2, &clientRect);
1512 }
1513 else {
1514 pScrollOS2 = &clientRect;
1515 scrollFlags |= SW_SCROLLCHILDREN; //TODO: ?????
1516 }
1517
1518 if(pClip) {
1519 mapWin32ToOS2RectClientToFrame(window,(RECT *)pClip, (PRECTLOS2)&clipRect);
1520 pClipOS2 = &clipRect;
1521
1522 //Clip rectangle relative to client area
1523 WinIntersectRect ((HAB) 0, pClipOS2, pClipOS2, &clientRect);
1524 }
1525 else {
1526 pClipOS2 = &clientRect;
1527 }
1528
1529 RECTL rectlUpdate;
1530 HRGN hrgn;
1531
1532 if (scrollFlag & SW_SMOOTHSCROLL_W)
1533 {
1534 INT time = (scrollFlag >> 16) & 0xFFFF;
1535
1536 //CB: todo, scroll in several steps
1537 // is time in ms? time <-> iteration count?
1538 }
1539
1540 LONG lComplexity = WinScrollWindow (window->getOS2WindowHandle(), dx, dy,
1541 pScrollOS2,
1542 pClipOS2,
1543 hrgn, &rectlUpdate, scrollFlags);
1544 if (lComplexity == RGN_ERROR)
1545 {
1546 return ERROR_W;
1547 }
1548
1549 RECT winRectUpdate;
1550
1551 mapOS2ToWin32Rect(window->getWindowHeight(), (PRECTLOS2)&rectlUpdate, &winRectUpdate);
1552
1553 if (pRectUpdate)
1554 *pRectUpdate = winRectUpdate;
1555
1556 if (hrgnUpdate)
1557 rc = setPMRgnIntoWinRgn (hrgn, hrgnUpdate, window->getWindowHeight());
1558
1559#if 0
1560 //SvL: WinScrollWindow already invalidates the area; no need to do it again
1561 //(call to invalidateRect was wrong; has to include erase flag)
1562 if ((scrollFlag & SW_INVALIDATE_W) &&
1563 ((lComplexity == RGN_RECT) || (lComplexity == RGN_COMPLEX)))
1564 {
1565 rc = InvalidateRect (hwnd, &winRectUpdate, (scrollFlag & SW_ERASE_W) ? 1 : 0);
1566 if (rc == FALSE)
1567 {
1568 return (0);
1569 }
1570 }
1571#endif
1572
1573 switch (lComplexity)
1574 {
1575 case RGN_NULL:
1576 regionType = NULLREGION_W;
1577 break;
1578 case RGN_RECT:
1579 regionType = SIMPLEREGION_W;
1580 break;
1581 case RGN_COMPLEX:
1582 regionType = COMPLEXREGION_W;
1583 break;
1584 default:
1585 regionType = ERROR_W;
1586 break;
1587 }
1588
1589 return (regionType);
1590}
1591//******************************************************************************
1592//******************************************************************************
1593HWND WIN32API WindowFromDC(HDC hdc)
1594{
1595 pDCData pHps = (pDCData)GpiQueryDCData( (HPS)hdc );
1596
1597 dprintf2(("USER32: WindowFromDC %x", hdc));
1598 if ( pHps )
1599 return Win32BaseWindow::OS2ToWin32Handle(pHps->hwnd);
1600 else
1601 return 0;
1602}
1603//******************************************************************************
1604//******************************************************************************
1605BOOL WIN32API ValidateRect( HWND hwnd, const RECT * lprc)
1606{
1607 if(lprc) {
1608 dprintf(("USER32: ValidateRect %x (%d,%d)(%d,%d)", hwnd, lprc->left, lprc->top, lprc->right, lprc->bottom));
1609 }
1610 else dprintf(("USER32: ValidateRect %x", hwnd));
1611
1612 return RedrawWindow( hwnd, lprc, 0, RDW_VALIDATE_W | RDW_NOCHILDREN_W | (hwnd==0 ? RDW_UPDATENOW_W : 0));
1613}
1614//******************************************************************************
1615//******************************************************************************
1616BOOL WIN32API ValidateRgn( HWND hwnd, HRGN hrgn)
1617{
1618 dprintf(("USER32: ValidateRgn %x %x", hwnd, hrgn));
1619 return RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE_W | RDW_NOCHILDREN_W | (hwnd==0 ? RDW_UPDATENOW_W : 0));
1620}
1621//******************************************************************************
1622//******************************************************************************
Note: See TracBrowser for help on using the repository browser.