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

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

Moved GetClipRgn & GetClipBox into user32 (dc.cpp)

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