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

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

hook, syscolor & message bugfixes

File size: 53.1 KB
Line 
1/* $Id: dc.cpp,v 1.57 2000-05-12 18:09:39 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//******************************************************************************
689BOOL WIN32API GetUpdateRect (HWND hwnd, LPRECT pRect, BOOL erase)
690{
691 if (!hwnd)
692 {
693 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
694 return FALSE;
695 }
696
697 RECTL rectl;
698 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
699
700 if (!wnd)
701 {
702 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
703 return FALSE;
704 }
705
706 BOOL updateRegionExists = WinQueryUpdateRect (wnd->getOS2WindowHandle(), pRect ? &rectl : NULL);
707 if (!pRect) {
708 return (updateRegionExists);
709 }
710
711 if (updateRegionExists)
712 {
713 //CB: for PM empty rect is valid
714 if ((rectl.xLeft == rectl.xRight) || (rectl.yTop == rectl.yBottom)) {
715 if(pRect) {
716 pRect->left = pRect->top = pRect->right = pRect->bottom = 0;
717 }
718 return FALSE;
719 }
720#if 0
721 //SvL: Hack for memory.exe (doesn't get repainted properly otherwise)
722// if (wnd->isOwnDC() && wnd->getOwnDC())
723 if (wnd->isOwnDC())
724 {
725 pDCData pHps = NULL;
726 pHps = (pDCData)GpiQueryDCData(wnd->getOwnDC());
727 if (!pHps)
728 {
729 SetLastError(ERROR_INVALID_HANDLE_W);
730 return FALSE;
731 }
732 GpiConvert (pHps->hps, CVTC_DEVICE, CVTC_WORLD, 2, (PPOINTL)&rectl);
733 }
734 else
735 {
736#endif
737 long height = wnd->getClientHeight();
738 rectl.yTop = height - rectl.yTop;
739 rectl.yBottom = height - rectl.yBottom;
740////////// }
741
742 if (pRect)
743 WINRECT_FROM_PMRECT (*pRect, rectl);
744
745 if (erase)
746 sendEraseBkgnd (wnd);
747 }
748 else
749 {
750 if(pRect) {
751 pRect->left = pRect->top = pRect->right = pRect->bottom = 0;
752 }
753 }
754
755 return updateRegionExists;
756}
757//******************************************************************************
758//functions for WM_NCPAINT
759//******************************************************************************
760INT SYSTEM GetOS2UpdateRgn(HWND hwnd,HRGN hrgn)
761{
762 return O32_GetUpdateRgn(hwnd,hrgn,FALSE);
763}
764//******************************************************************************
765//******************************************************************************
766BOOL SYSTEM GetOS2UpdateRect(HWND hwnd,LPRECT pRect)
767{
768 RECTL rectl;
769 BOOL updateRegionExists = WinQueryUpdateRect(hwnd,pRect ? &rectl:NULL);
770
771 if (!pRect)
772 return (updateRegionExists);
773
774 if (updateRegionExists)
775 {
776 //CB: for PM empty rect is valid
777 if ((rectl.xLeft == rectl.xRight) || (rectl.yTop == rectl.yBottom)) return FALSE;
778 mapOS2ToWin32Rect(hwnd,(PRECTLOS2)&rectl,pRect);
779 }
780 else
781 pRect->left = pRect->top = pRect->right = pRect->bottom = 0;
782
783 return updateRegionExists;
784}
785//******************************************************************************
786//******************************************************************************
787int WIN32API GetUpdateRgn (HWND hwnd, HRGN hrgn, BOOL erase)
788{
789 LONG Complexity;
790
791 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
792
793 if (!wnd)
794 {
795 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
796 return ERROR_W;
797 }
798
799 Complexity = O32_GetUpdateRgn (wnd->getOS2WindowHandle(), hrgn, FALSE);
800 if (erase && (Complexity > NULLREGION_W)) sendEraseBkgnd(wnd);
801
802 return Complexity;
803}
804//******************************************************************************
805//******************************************************************************
806int WIN32API ReleaseDC (HWND hwnd, HDC hdc)
807{
808 BOOL isOwnDC = FALSE;
809 int rc;
810
811 if (hwnd)
812 {
813 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
814 if(wnd == NULL) {
815 dprintf(("ERROR: ReleaseDC %x %x failed", hwnd, hdc));
816 return 0;
817 }
818 //SvL: Hack for memory.exe (doesn't get repainted properly otherwise)
819// isOwnDC = wnd->isOwnDC() && wnd->getOwnDC();
820 isOwnDC = wnd->isOwnDC() && (wnd->getOwnDC() == hdc);
821 }
822 if (isOwnDC)
823 rc = TRUE;
824 else
825 rc = O32_ReleaseDC (0, hdc);
826
827 dprintf(("ReleaseDC %x %x", hwnd, hdc));
828 return (rc);
829}
830//******************************************************************************
831// This implementation of GetDCEx supports
832// DCX_WINDOW
833// DCX_CACHE
834// DCX_EXCLUDERGN (complex regions allowed)
835// DCX_INTERSECTRGN (complex regions allowed)
836//
837//TODO: WM_SETREDRAW affects drawingAllowed flag!!
838//******************************************************************************
839HDC WIN32API GetDCEx (HWND hwnd, HRGN hrgn, ULONG flags)
840{
841 Win32BaseWindow *wnd = NULL;
842 HWND hWindow;
843 BOOL success;
844 pDCData pHps = NULL;
845 HPS hps = NULLHANDLE;
846 BOOL drawingAllowed = TRUE;
847 BOOL isWindowOwnDC;
848 BOOL creatingOwnDC = FALSE;
849 PS_Type psType;
850
851 if(hwnd == 0) {
852 dprintf(("error: GetDCEx window %x not found", hwnd));
853 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
854 return 0;
855 }
856
857 if (hwnd)
858 {
859 wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
860 if(wnd == NULL) {
861 dprintf (("ERROR: User32: GetDCEx bad window handle %X!!!!!", hwnd));
862 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
863 return 0;
864 }
865//SvL: Experimental change (doesn't work right)
866#if 0
867 if(wnd->fHasParentDC() && wnd->getParent()) {
868 wnd = wnd->getParent();
869 }
870#endif
871 if (flags & DCX_WINDOW_W)
872 hWindow = wnd->getOS2FrameWindowHandle();
873 else
874 hWindow = wnd->getOS2WindowHandle();
875 }
876
877 isWindowOwnDC = (((hWindow == HWND_DESKTOP) ? FALSE : (wnd->isOwnDC()))
878 && !(flags & (DCX_CACHE_W | DCX_WINDOW_W)));
879
880 if (isWindowOwnDC)
881 {
882 hps = wnd->getOwnDC();
883 if (hps)
884 {
885 pDCData pHps = (pDCData)GpiQueryDCData (hps);
886 if (!pHps)
887 goto error;
888
889 setPageXForm (wnd, pHps);
890
891 pHps->hdcType = TYPE_1;
892 dprintf (("User32: GetDCEx hwnd %x (%x %x) -> wnd %x hdc %x", hwnd, hrgn, flags, wnd, hps));
893 return (HDC)hps;
894 }
895 else
896 creatingOwnDC = TRUE;
897 }
898
899 if (isWindowOwnDC)
900 {
901 SIZEL sizel = {0,0};
902 hps = GpiCreatePS (WinQueryAnchorBlock (hWindow),
903 WinOpenWindowDC (hWindow),
904 &sizel, PU_PELS | GPIT_MICRO | GPIA_ASSOC );
905 psType = MICRO;
906 }
907 else
908 {
909 if (hWindow == HWND_DESKTOP)
910 hps = WinGetScreenPS (hWindow);
911 else
912 hps = WinGetPS (hWindow);
913
914 psType = MICRO_CACHED;
915 }
916
917 if (!hps)
918 goto error;
919
920 HPSToHDC (hWindow, hps, NULL, NULL);
921 pHps = (pDCData)GpiQueryDCData (hps);
922
923 if ((flags & DCX_EXCLUDERGN_W) || (flags & DCX_INTERSECTRGN_W))
924 {
925 ULONG BytesNeeded;
926 PRGNDATA_W RgnData;
927 PRECT pr;
928 int i;
929 RECTL rectl;
930
931 if (!hrgn)
932 goto error;
933
934 success = TRUE;
935 if (flags & DCX_EXCLUDERGN_W)
936 {
937#if 0 //CB: todo
938 long height;
939
940 BytesNeeded = GetRegionData (hrgn, 0, NULL);
941 RgnData = (PRGNDATA_W)_alloca (BytesNeeded);
942 if (RgnData == NULL)
943 goto error;
944 GetRegionData (hrgn, BytesNeeded, RgnData);
945
946 i = RgnData->rdh.nCount;
947 pr = (PRECT)(RgnData->Buffer);
948
949 if (flags & DCX_WINDOW_W)
950 height = wnd->getWindowHeight();
951 else height = wnd->getClientHeight();
952
953 for (; (i > 0) && success; i--, pr++) {
954 LONG y = pr->yBottom;
955
956 pr->yBottom = height - pr->yTop;
957 pr->yTop = height - y;
958 success &= GpiExcludeClipRectangle (pHps->hps, pr);
959 }
960#endif
961 }
962 else //DCX_INTERSECTRGN_W
963 {
964 //SvL: I'm getting paint problems when clipping a dc created in GetDCEx
965 // with a region that covers the entire window (RealPlayer 7 Update 1)
966 // Using SelectClipRgn here doesn't make any difference.
967 if(ExtSelectClipRgn(pHps->hps, hrgn, RGN_AND_W) == ERROR_W) {
968 dprintf(("ExtSelectClipRgn failed!!"));
969 }
970 }
971 if (!success)
972 goto error;
973 }
974
975 if (creatingOwnDC)
976 wnd->setOwnDC ((HDC)hps);
977
978 pHps->psType = psType;
979 pHps->hdcType = TYPE_1;
980 //TODO: WM_SETREDRAW affects drawingAllowed flag!!
981 GpiSetDrawControl (hps, DCTL_DISPLAY, drawingAllowed ? DCTL_ON : DCTL_OFF);
982
983 dprintf (("User32: GetDCEx hwnd %x (%x %x) -> hdc %x", hwnd, hrgn, flags, pHps->hps));
984 return (HDC)pHps->hps;
985
986error:
987 /* Something went wrong; clean up
988 */
989 dprintf(("ERROR: GetDCEx hwnd %x (%x %x) FAILED!", hwnd, hrgn, flags));
990 DebugInt3();
991 if (pHps)
992 {
993 if (pHps->hps)
994 {
995 if(pHps->psType == MICRO_CACHED)
996 WinReleasePS(pHps->hps);
997 else
998 GpiDestroyPS(pHps->hps);
999 }
1000
1001 if (pHps->hdc) DevCloseDC(pHps->hdc);
1002 if (pHps->hrgnHDC) GpiDestroyRegion(pHps->hps, pHps->hrgnHDC);
1003
1004 O32_DeleteObject (pHps->nullBitmapHandle);
1005 }
1006 SetLastError(ERROR_INVALID_PARAMETER_W);
1007 return NULL;
1008}
1009//******************************************************************************
1010//******************************************************************************
1011HDC WIN32API GetDC (HWND hwnd)
1012{
1013 if(!hwnd)
1014 return GetDCEx( GetDesktopWindow(), 0, DCX_CACHE_W | DCX_WINDOW_W );
1015 return GetDCEx (hwnd, NULL, 0);
1016}
1017//******************************************************************************
1018//******************************************************************************
1019HDC WIN32API GetWindowDC (HWND hwnd)
1020{
1021 if (!hwnd) hwnd = GetDesktopWindow();
1022 return GetDCEx (hwnd, NULL, DCX_USESTYLE_W | DCX_WINDOW_W);
1023}
1024//******************************************************************************
1025// This implementation of RedrawWindow supports
1026// RDW_ERASE
1027// RDW_NOERASE
1028// RDW_INTERNALPAINT
1029// RDW_NOINTERNALPAINT
1030// RDW_INVALIDATE
1031// RDW_VALIDATE
1032// RDW_ERASENOW
1033// RDW_UPDATENOW
1034//******************************************************************************
1035BOOL WIN32API RedrawWindow(HWND hwnd, const RECT* pRect, HRGN hrgn, DWORD redraw)
1036{
1037 Win32BaseWindow *wnd;
1038
1039 if(pRect) {
1040 dprintf(("RedrawWindow %x (%d,%d)(%d,%d) %x %x", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom, hrgn, redraw));
1041 }
1042 else dprintf(("RedrawWindow %x %x %x %x", hwnd, pRect, hrgn, redraw));
1043
1044 if (hwnd == NULLHANDLE)
1045 {
1046#if 1
1047 // Don't do this for now (causes lots of desktop repaints in WordPad)
1048 SetLastError(ERROR_INVALID_PARAMETER_W);
1049 return FALSE;
1050#else
1051 hwnd = HWND_DESKTOP;
1052 wnd = Win32BaseWindow::GetWindowFromOS2Handle(OSLIB_HWND_DESKTOP);
1053
1054 if (!wnd)
1055 {
1056 dprintf(("USER32:dc: RedrawWindow can't find desktop window %08xh\n",
1057 hwnd));
1058 SetLastError(ERROR_INVALID_PARAMETER_W);
1059 return FALSE;
1060 }
1061#endif
1062 }
1063 else
1064 {
1065 wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
1066
1067 if (!wnd)
1068 {
1069 dprintf(("USER32:dc: RedrawWindow can't find window %08xh\n",
1070 hwnd));
1071 SetLastError(ERROR_INVALID_PARAMETER_W);
1072 return FALSE;
1073 }
1074 //TODO: If frame, exclude client window from update
1075 if(redraw & RDW_FRAME_W) {
1076 hwnd = wnd->getOS2FrameWindowHandle();
1077 }
1078 else hwnd = wnd->getOS2WindowHandle();
1079
1080 }
1081
1082 BOOL IncludeChildren = redraw & RDW_ALLCHILDREN_W ? TRUE : FALSE;
1083 BOOL success = TRUE;
1084 HPS hpsTemp = NULLHANDLE;
1085 HRGN hrgnTemp = NULLHANDLE;
1086 RECTL rectl;
1087
1088 if (hrgn)
1089 {
1090 ULONG BytesNeeded;
1091 PRGNDATA_W RgnData;
1092 PRECTL pr;
1093 int i;
1094 LONG height = wnd ? wnd->getClientHeight() : OSLibQueryScreenHeight();
1095
1096 if (!hrgn)
1097 goto error;
1098
1099 BytesNeeded = O32_GetRegionData (hrgn, 0, NULL);
1100 RgnData = (PRGNDATA_W)_alloca (BytesNeeded);
1101 if (RgnData == NULL)
1102 goto error;
1103 O32_GetRegionData (hrgn, BytesNeeded, RgnData);
1104
1105 pr = (PRECTL)(RgnData->Buffer);
1106 for (i = RgnData->rdh.nCount; i > 0; i--, pr++) {
1107 LONG temp = pr->yTop;
1108 pr->yTop = height - pr->yBottom;
1109 pr->yBottom = height - temp;
1110 }
1111
1112 hpsTemp = WinGetScreenPS (HWND_DESKTOP);
1113 hrgnTemp = GpiCreateRegion (hpsTemp, RgnData->rdh.nCount, (PRECTL)(RgnData->Buffer));
1114 if (!hrgnTemp) goto error;
1115 }
1116 else if (pRect)
1117 {
1118 LONG height = wnd ? wnd->getClientHeight() : OSLibQueryScreenHeight();
1119
1120 PMRECT_FROM_WINRECT (rectl, *pRect);
1121 rectl.yTop = height - rectl.yTop;
1122 rectl.yBottom = height - rectl.yBottom;
1123 }
1124
1125 if (redraw & RDW_INVALIDATE_W)
1126 {
1127 //TODO: SvL: pingpong.exe doesn't have RDW_NOERASE, but doesn't want WM_ERASEBKGND msgs
1128 if (redraw & RDW_ERASE_W) {
1129 wnd->setEraseBkgnd(TRUE);
1130 }
1131
1132 if (!pRect && !hrgn)
1133 success = WinInvalidateRect (hwnd, NULL, IncludeChildren);
1134 else
1135 if (hrgn)
1136 success = WinInvalidateRegion (hwnd, hrgnTemp, IncludeChildren);
1137 else
1138 success = WinInvalidateRect (hwnd, &rectl, IncludeChildren);
1139
1140 if (!success) goto error;
1141 }
1142 else if (redraw & RDW_VALIDATE_W)
1143 {
1144 if (redraw & RDW_NOERASE_W)
1145 wnd->setEraseBkgnd(FALSE);
1146
1147 if (WinQueryUpdateRect (hwnd, NULL))
1148 {
1149 if (!pRect && !hrgn)
1150 success = WinValidateRect (hwnd, NULL, IncludeChildren);
1151 else
1152 if (hrgn)
1153 success = WinValidateRegion (hwnd, hrgnTemp, IncludeChildren);
1154 else
1155 success = WinValidateRect (hwnd, &rectl, IncludeChildren);
1156 if (!success) goto error;
1157 }
1158 }
1159
1160 if(WinQueryUpdateRect(hwnd, NULL))
1161 {
1162 //TODO: Does this work if RDW_ALLCHILDREN is set??
1163 if(redraw & RDW_UPDATENOW_W) {
1164 wnd->MsgPaint (0, FALSE);
1165 }
1166 else
1167// if((redraw & RDW_ERASE_W) && (redraw & RDW_ERASENOW_W))
1168 if(redraw & RDW_ERASENOW_W && wnd->needsEraseBkgnd())
1169 wnd->setEraseBkgnd(sendEraseBkgnd(wnd) == 0);
1170 }
1171 else if((redraw & RDW_INTERNALPAINT_W) && !(redraw & RDW_INVALIDATE_W))
1172 {
1173 if(redraw & RDW_UPDATENOW_W)
1174 wnd->MsgPaint (0, FALSE);
1175 else PostMessageA(hwnd, WINWM_PAINT, 0, 0);
1176 }
1177
1178error:
1179 /* clean up */
1180 if (hrgnTemp)
1181 GpiDestroyRegion (hpsTemp, hrgnTemp);
1182
1183 if (hpsTemp)
1184 WinReleasePS (hpsTemp);
1185
1186 if (!success)
1187 SetLastError(ERROR_INVALID_PARAMETER_W);
1188
1189 return (success);
1190}
1191//******************************************************************************
1192//******************************************************************************
1193BOOL WIN32API UpdateWindow (HWND hwnd)
1194{
1195 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
1196
1197 if(!wnd) {
1198 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
1199 return FALSE;
1200 }
1201
1202 dprintf (("User32: UpdateWindow hwnd %x", hwnd));
1203////SvL: This doesn't work right (Wine uses RDW_NOCHILDREN_W -> doesn't work here)
1204//// Breaks vpbuddy
1205//// return RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW_W | RDW_ALLCHILDREN_W);
1206 WinUpdateWindow(wnd->getOS2WindowHandle());
1207 return TRUE;
1208}
1209//******************************************************************************
1210//******************************************************************************
1211BOOL WIN32API InvalidateRect (HWND hwnd, const RECT *pRect, BOOL erase)
1212{
1213 BOOL result;
1214
1215 if(pRect) {
1216 dprintf(("InvalidateRect %x (%d,%d)(%d,%d) erase=%d", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom, erase));
1217 }
1218 else dprintf(("InvalidateRect %x NULL erase=%d", hwnd, erase));
1219 result = RedrawWindow (hwnd, pRect, NULLHANDLE,
1220 RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
1221 (erase ? RDW_ERASE_W : 0) |
1222 (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
1223 return (result);
1224}
1225//******************************************************************************
1226//******************************************************************************
1227BOOL WIN32API InvalidateRgn (HWND hwnd, HRGN hrgn, BOOL erase)
1228{
1229 BOOL result;
1230
1231 dprintf(("InvalidateRgn %x %x erase=%d", hwnd, hrgn, erase));
1232 result = RedrawWindow (hwnd, NULL, hrgn,
1233 RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
1234 (erase ? RDW_ERASE_W : 0) |
1235 (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
1236 return (result);
1237}
1238//******************************************************************************
1239//******************************************************************************
1240BOOL setPMRgnIntoWinRgn (HRGN hrgnPM, HRGN hrgnWin, LONG height)
1241{
1242 BOOL rc;
1243 HPS hps = WinGetScreenPS (HWND_DESKTOP);
1244 RGNRECT rgnRect;
1245 rgnRect.ircStart = 1;
1246 rgnRect.crc = 0;
1247 rgnRect.ulDirection = RECTDIR_LFRT_TOPBOT; // doesn't make a difference because we're getting them all
1248
1249 rc = GpiQueryRegionRects (hps, hrgnPM, NULL, &rgnRect, NULL);
1250
1251 if (rc && (rgnRect.crcReturned > 0))
1252 {
1253 PRECTL Rcls = new RECTL[rgnRect.crcReturned];
1254 PRECTL pRcl = Rcls;
1255
1256 if (Rcls != NULL)
1257 {
1258 rgnRect.crc = rgnRect.crcReturned;
1259 rc = GpiQueryRegionRects (hps, hrgnPM, NULL, &rgnRect, Rcls);
1260
1261 rc = O32_SetRectRgn (hrgnWin, pRcl->xLeft,
1262 pRcl->xRight,
1263 height - pRcl->yTop,
1264 height - pRcl->yBottom);
1265
1266 if (rgnRect.crcReturned > 1)
1267 {
1268 int i;
1269 HRGN temp;
1270 temp = O32_CreateRectRgn (0, 0, 1, 1);
1271
1272 for (i = 1, pRcl++; rc && (i < rgnRect.crcReturned); i++, pRcl++)
1273 {
1274 rc = O32_SetRectRgn (temp, pRcl->xLeft,
1275 pRcl->xRight,
1276 height - pRcl->yTop,
1277 height - pRcl->yBottom);
1278 rc &= O32_CombineRgn (hrgnWin, hrgnWin, temp, RGN_OR_W);
1279 }
1280 O32_DeleteObject (temp);
1281 }
1282 delete[] Rcls;
1283 }
1284 else
1285 {
1286 rc = FALSE;
1287 }
1288 }
1289 else
1290 {
1291 rc = O32_SetRectRgn (hrgnWin, 0, 0, 0, 0);
1292 }
1293
1294 WinReleasePS (hps);
1295 return (rc);
1296}
1297//******************************************************************************
1298//******************************************************************************
1299BOOL WIN32API ScrollDC (HDC hDC, int dx, int dy, const RECT *pScroll,
1300 const RECT *pClip, HRGN hrgnUpdate, LPRECT pRectUpdate)
1301{
1302 BOOL rc = TRUE;
1303
1304 dprintf (("USER32: ScrollDC"));
1305
1306 if (!hDC)
1307 {
1308 return (FALSE);
1309 }
1310
1311 pDCData pHps = (pDCData)GpiQueryDCData ((HPS)hDC);
1312 HWND hwnd = pHps->hwnd;
1313 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
1314
1315 if ((hwnd == NULLHANDLE) || !wnd)
1316 {
1317 return (FALSE);
1318 }
1319
1320 POINTL ptl[2] = { 0, 0, dx, dy };
1321
1322 GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, ptl);
1323 dx = (int)(ptl[1].x - ptl[0].x);
1324 dy = (int)(ptl[1].y - ptl[0].y);
1325
1326 RECTL scrollRect;
1327 RECTL clipRect;
1328
1329 if (pClip)
1330 {
1331 clipRect.xLeft = min (pClip->left, pClip->right);
1332 clipRect.xRight = max (pClip->left, pClip->right);
1333 clipRect.yTop = max (pClip->top, pClip->bottom);
1334 clipRect.yBottom = min (pClip->top, pClip->bottom);
1335
1336 if ((pHps->graphicsMode == GM_COMPATIBLE_W) &&
1337 (clipRect.xLeft != clipRect.xRight) &&
1338 (clipRect.yBottom != clipRect.yTop))
1339 {
1340 if (abs((int)pHps->viewportXExt) <= abs((int)pHps->windowExt.cx))
1341 clipRect.xRight -= abs(pHps->worldXDeltaFor1Pixel);
1342 else
1343 clipRect.xLeft += abs(pHps->worldXDeltaFor1Pixel);
1344
1345 if (abs((int)pHps->viewportYExt) <= abs((int)pHps->windowExt.cy))
1346 clipRect.yTop -= abs(pHps->worldYDeltaFor1Pixel);
1347 else
1348 clipRect.yBottom += abs(pHps->worldYDeltaFor1Pixel);
1349 }
1350 GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, (PPOINTL)&clipRect);
1351 if (clipRect.xRight < clipRect.xLeft) {
1352 ULONG temp = clipRect.xLeft;
1353 clipRect.xLeft = clipRect.xRight;
1354 clipRect.xRight = temp;
1355 }
1356 if (clipRect.yTop < clipRect.yBottom) {
1357 ULONG temp = clipRect.yBottom;
1358 clipRect.yBottom = clipRect.yTop;
1359 clipRect.yTop = temp;
1360 }
1361 }
1362
1363 if (pScroll)
1364 {
1365 scrollRect.xLeft = min (pScroll->left, pScroll->right);
1366 scrollRect.xRight = max (pScroll->left, pScroll->right);
1367 scrollRect.yTop = max (pScroll->top, pScroll->bottom);
1368 scrollRect.yBottom = min (pScroll->top, pScroll->bottom);
1369
1370 if ((pHps->graphicsMode == GM_COMPATIBLE_W) &&
1371 (scrollRect.xLeft != scrollRect.xRight) &&
1372 (scrollRect.yBottom != scrollRect.yTop))
1373 {
1374 if (abs((int)pHps->viewportXExt) <= abs((int)pHps->windowExt.cx))
1375 scrollRect.xRight -= abs(pHps->worldXDeltaFor1Pixel);
1376 else
1377 scrollRect.xLeft += abs(pHps->worldXDeltaFor1Pixel);
1378
1379 if (abs((int)pHps->viewportYExt) <= abs((int)pHps->windowExt.cy))
1380 scrollRect.yTop -= abs(pHps->worldYDeltaFor1Pixel);
1381 else
1382 scrollRect.yBottom += abs(pHps->worldYDeltaFor1Pixel);
1383 }
1384 GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, (PPOINTL)&scrollRect);
1385 if (scrollRect.xRight < scrollRect.xLeft) {
1386 ULONG temp = scrollRect.xLeft;
1387 scrollRect.xLeft = scrollRect.xRight;
1388 scrollRect.xRight = temp;
1389 }
1390 if (scrollRect.yTop < scrollRect.yBottom) {
1391 ULONG temp = scrollRect.yBottom;
1392 scrollRect.yBottom = scrollRect.yTop;
1393 scrollRect.yTop = temp;
1394 }
1395 }
1396 RECTL rectlUpdate;
1397 HRGN hrgn;
1398
1399 LONG lComplexity = WinScrollWindow (hwnd, dx, dy, (pScroll) ? &scrollRect : NULL, (pClip) ? &clipRect : NULL, hrgn, &rectlUpdate, 0);
1400 if (lComplexity == RGN_ERROR)
1401 {
1402 return (FALSE);
1403 }
1404
1405 RECT winRectUpdate;
1406 LONG height = wnd->getClientHeight();
1407
1408 winRectUpdate.left = rectlUpdate.xLeft;
1409 winRectUpdate.right = rectlUpdate.xRight;
1410 winRectUpdate.top = height - rectlUpdate.yTop;
1411 winRectUpdate.bottom = height - rectlUpdate.yBottom;
1412
1413 if (pRectUpdate)
1414 *pRectUpdate = winRectUpdate;
1415
1416 if (hrgnUpdate)
1417 rc = setPMRgnIntoWinRgn (hrgn, hrgnUpdate, height);
1418
1419 return (rc);
1420}
1421//******************************************************************************
1422//******************************************************************************
1423#if 1
1424BOOL WIN32API ScrollWindow(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip)
1425{
1426 Win32BaseWindow *window;
1427 APIRET rc;
1428 RECTL clientRect;
1429 PRECT pClientRect;
1430 RECTL scrollRect;
1431 RECTL clipRect;
1432 PRECTL pScrollRect = NULL;
1433 PRECTL pClipRect = 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 pClientRect = window->getClientRectPtr();
1444 clientRect.xLeft = 0;
1445 clientRect.yBottom = 0;
1446 clientRect.xRight = pClientRect->right - pClientRect->left;
1447 clientRect.yTop = pClientRect->bottom - pClientRect->top;
1448
1449 if(pScroll) {
1450 mapWin32ToOS2Rect(window,(RECT *)pScroll, (PRECTLOS2)&scrollRect);
1451 pScrollRect = &scrollRect;
1452
1453 //Scroll rectangle relative to client area
1454 WinIntersectRect ((HAB) 0, pScrollRect, pScrollRect, &clientRect);
1455 }
1456 else scrollFlags |= SW_SCROLLCHILDREN;
1457
1458 if(pClip) {
1459 mapWin32ToOS2Rect(window,(RECT *)pClip, (PRECTLOS2)&clipRect);
1460 pClipRect = &clipRect;
1461
1462 //Clip rectangle relative to client area
1463 WinIntersectRect ((HAB) 0, pClipRect, pClipRect, &clientRect);
1464 }
1465
1466 dy = revertDy (window, dy);
1467
1468 rc = WinScrollWindow(window->getOS2WindowHandle(), dx, dy,
1469 pScrollRect, pClipRect, NULLHANDLE,
1470 NULL, scrollFlags);
1471
1472 return (rc != RGN_ERROR);
1473}
1474#else
1475BOOL WIN32API ScrollWindow(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip)
1476{
1477 Win32BaseWindow *window;
1478 APIRET rc;
1479 RECTL clientRect;
1480 RECTL scrollRect;
1481 RECTL clipRect;
1482 PRECTL pScrollRect = NULL;
1483 PRECTL pClipRect = NULL;
1484 ULONG scrollFlags = SW_INVALIDATERGN;
1485
1486 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1487 if(!window) {
1488 dprintf(("ScrollWindow, window %x not found", hwnd));
1489 return 0;
1490 }
1491 dprintf(("ScrollWindow %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip));
1492 mapWin32ToOS2Rect(window,window->getClientRectPtr(),(PRECTLOS2)&clientRect);
1493#if 0
1494 //Rectangle could be relative to parent window, so fix this
1495 if(clientRect.yBottom != 0) {
1496 clientRect.yTop -= clientRect.yBottom;
1497 clientRect.yBottom = 0;
1498 }
1499 if(clientRect.xLeft != 0) {
1500 clientRect.xRight -= clientRect.xLeft;
1501 clientRect.xLeft = 0;
1502 }
1503#endif
1504 if(pScroll) {
1505 mapWin32ToOS2Rect(window,(RECT *)pScroll, (PRECTLOS2)&scrollRect);
1506 pScrollRect = &scrollRect;
1507
1508 //Scroll rectangle relative to client area
1509 pScrollRect->xLeft += clientRect.xLeft;
1510 pScrollRect->xRight += clientRect.xLeft;
1511 pScrollRect->yTop += clientRect.yBottom;
1512 pScrollRect->yBottom += clientRect.yBottom;
1513 WinIntersectRect ((HAB) 0, pScrollRect, pScrollRect, &clientRect);
1514 }
1515 else scrollFlags |= SW_SCROLLCHILDREN;
1516
1517 if(pClip) {
1518 mapWin32ToOS2Rect(window,(RECT *)pClip, (PRECTLOS2)&clipRect);
1519 pClipRect = &clipRect;
1520
1521 //Clip rectangle relative to client area
1522 pClipRect->xLeft += clientRect.xLeft;
1523 pClipRect->xRight += clientRect.xLeft;
1524 pClipRect->yTop += clientRect.yBottom;
1525 pClipRect->yBottom += clientRect.yBottom;
1526 WinIntersectRect ((HAB) 0, pClipRect, pClipRect, &clientRect);
1527 }
1528
1529 dy = revertDy (window, dy);
1530
1531 rc = WinScrollWindow(window->getOS2WindowHandle(), dx, dy,
1532 pScrollRect, pClipRect, NULLHANDLE,
1533 NULL, scrollFlags);
1534
1535 return (rc != RGN_ERROR);
1536}
1537#endif
1538//******************************************************************************
1539//******************************************************************************
1540INT WIN32API ScrollWindowEx(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip,
1541 HRGN hrgnUpdate, PRECT pRectUpdate, UINT scrollFlag)
1542{
1543 Win32BaseWindow *window;
1544 APIRET rc;
1545 RECTL scrollRect;
1546 RECTL clipRect;
1547 ULONG scrollFlags = 0;
1548 int regionType = ERROR_W;
1549
1550 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1551 if(!window) {
1552 dprintf(("ScrollWindowEx, window %x not found", hwnd));
1553 return 0;
1554 }
1555
1556 dprintf(("ScrollWindowEx %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip));
1557
1558 dy = revertDy (window, dy);
1559
1560 if (scrollFlag & SW_INVALIDATE_W) scrollFlags |= SW_INVALIDATERGN;
1561 if (scrollFlag & SW_SCROLLCHILDREN_W) scrollFlags |= SW_SCROLLCHILDREN;
1562
1563 if(pScroll) mapWin32ToOS2Rect(window,(RECT *)pScroll, (PRECTLOS2)&scrollRect);
1564 if(pClip) mapWin32ToOS2Rect(window,(RECT *)pClip, (PRECTLOS2)&clipRect);
1565
1566 RECTL rectlUpdate;
1567 HRGN hrgn;
1568
1569 if (scrollFlag & SW_SMOOTHSCROLL_W)
1570 {
1571 INT time = (scrollFlag >> 16) & 0xFFFF;
1572
1573 //CB: todo, scroll in several steps
1574 // is time in ms? time <-> iteration count?
1575 }
1576
1577 LONG lComplexity = WinScrollWindow (window->getOS2WindowHandle(), dx, dy,
1578 (pScroll) ? &scrollRect : NULL,
1579 (pClip) ? &clipRect : NULL,
1580 hrgn, &rectlUpdate, scrollFlags);
1581 if (lComplexity == RGN_ERROR)
1582 {
1583 return ERROR_W;
1584 }
1585
1586 RECT winRectUpdate;
1587 LONG height = window->getClientHeight();
1588
1589 winRectUpdate.left = rectlUpdate.xLeft;
1590 winRectUpdate.right = rectlUpdate.xRight;
1591 winRectUpdate.top = height - rectlUpdate.yTop;
1592 winRectUpdate.bottom = height - rectlUpdate.yBottom;
1593
1594 if (pRectUpdate)
1595 *pRectUpdate = winRectUpdate;
1596
1597 if (hrgnUpdate)
1598 rc = setPMRgnIntoWinRgn (hrgn, hrgnUpdate, height);
1599
1600 //SvL: WinScrollWindow already invalidates the area; no need to do it again
1601 //(call to invalidateRect was wrong; has to include erase flag)
1602#if 0
1603 if ((scrollFlag & SW_INVALIDATE_W) &&
1604 ((lComplexity == RGN_RECT) || (lComplexity == RGN_COMPLEX)))
1605 {
1606 rc = InvalidateRect (hwnd, &winRectUpdate, (scrollFlag & SW_ERASE_W) ? 1 : 0);
1607 if (rc == FALSE)
1608 {
1609 return (0);
1610 }
1611 }
1612#endif
1613
1614 switch (lComplexity)
1615 {
1616 case RGN_NULL:
1617 regionType = NULLREGION_W;
1618 break;
1619 case RGN_RECT:
1620 regionType = SIMPLEREGION_W;
1621 break;
1622 case RGN_COMPLEX:
1623 regionType = COMPLEXREGION_W;
1624 break;
1625 default:
1626 regionType = ERROR_W;
1627 break;
1628 }
1629
1630 return (regionType);
1631}
1632//******************************************************************************
1633//******************************************************************************
1634HWND WIN32API WindowFromDC(HDC hdc)
1635{
1636 pDCData pHps = (pDCData)GpiQueryDCData( (HPS)hdc );
1637
1638 dprintf2(("USER32: WindowFromDC %x", hdc));
1639 if ( pHps )
1640 return Win32BaseWindow::OS2ToWin32Handle(pHps->hwnd);
1641 else
1642 return 0;
1643}
1644//******************************************************************************
1645//******************************************************************************
1646INT WIN32API ExcludeUpdateRgn( HDC hDC, HWND hWnd)
1647{
1648 dprintf(("USER32: ExcludeUpdateRgn\n"));
1649 hWnd = Win32BaseWindow::Win32ToOS2Handle(hWnd);
1650
1651 return O32_ExcludeUpdateRgn(hDC,hWnd);
1652}
1653//******************************************************************************
1654//******************************************************************************
1655BOOL WIN32API ValidateRect( HWND hwnd, const RECT * lprc)
1656{
1657 if(lprc) {
1658 dprintf(("USER32: ValidateRect %x (%d,%d)(%d,%d)", hwnd, lprc->left, lprc->top, lprc->right, lprc->bottom));
1659 }
1660 else dprintf(("USER32: ValidateRect %x", hwnd));
1661
1662 return RedrawWindow( hwnd, lprc, 0, RDW_VALIDATE_W | RDW_NOCHILDREN_W | (hwnd==0 ? RDW_UPDATENOW_W : 0));
1663}
1664//******************************************************************************
1665//******************************************************************************
1666BOOL WIN32API ValidateRgn( HWND hwnd, HRGN hrgn)
1667{
1668 dprintf(("USER32: ValidateRgn %x %x", hwnd, hrgn));
1669 return RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE_W | RDW_NOCHILDREN_W | (hwnd==0 ? RDW_UPDATENOW_W : 0));
1670}
1671/*****************************************************************************
1672 * Name : int WIN32API GetWindowRgn
1673 * Purpose : The GetWindowRgn function obtains a copy of the window region of a window.
1674 * Parameters: HWND hWnd handle to window whose window region is to be obtained
1675 * HRGN hRgn handle to region that receives a copy of the window region
1676 * Variables :
1677 * Result : NULLREGION, SIMPLEREGION, COMPLEXREGION, ERROR
1678 * Remark :
1679 * Status : UNTESTED STUB
1680 *
1681 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
1682 *****************************************************************************/
1683
1684int WIN32API GetWindowRgn(HWND hwnd, HRGN hRgn)
1685{
1686 Win32BaseWindow *window;
1687 HRGN hWindowRegion;
1688
1689 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1690 if(!window) {
1691 dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
1692 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
1693 return 0;
1694 }
1695 dprintf(("USER32:GetWindowRgn (%x,%x)", hwnd, hRgn));
1696 hWindowRegion = window->GetWindowRegion();
1697
1698 return O32_CombineRgn(hRgn, hWindowRegion, 0, RGN_COPY_W);
1699}
1700/*****************************************************************************
1701 * Name : int WIN32API SetWindowRgn
1702 * Purpose : The SetWindowRgn function sets the window region of a window. The
1703 * window region determines the area within the window where the
1704 * operating system permits drawing. The operating system does not
1705 * display any portion of a window that lies outside of the window region
1706 * When this function is called, the system sends the WM_WINDOWPOSCHANGING and
1707 * WM_WINDOWPOSCHANGED messages to the window.
1708 *
1709 * Parameters: HWND hWnd handle to window whose window region is to be set
1710 * HRGN hRgn handle to region
1711 * BOOL bRedraw window redraw flag
1712 * Variables :
1713 * Result : If the function succeeds, the return value is non-zero.
1714 * If the function fails, the return value is zero.
1715 * Remark :
1716 * Status : UNTESTED STUB
1717 *
1718 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
1719 *****************************************************************************/
1720
1721int WIN32API SetWindowRgn(HWND hwnd,
1722 HRGN hRgn,
1723 BOOL bRedraw)
1724{
1725 Win32BaseWindow *window;
1726 HRGN hWindowRegion;
1727
1728 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1729 if(!window) {
1730 dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
1731 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
1732 return 0;
1733 }
1734 dprintf(("USER32:SetWindowRgn (%x,%x,%d)", hwnd, hRgn, bRedraw));
1735 if(window->GetWindowRegion()) {
1736 O32_DeleteObject(window->GetWindowRegion());
1737 }
1738 window->SetWindowRegion(hRgn);
1739 if(bRedraw) {
1740 RedrawWindow(hwnd, 0, 0, RDW_UPDATENOW_W);
1741 }
1742//TODO:
1743// When this function is called, the system sends the WM_WINDOWPOSCHANGING and
1744// WM_WINDOWPOSCHANGED messages to the window.
1745 return 1;
1746}
1747//******************************************************************************
1748//******************************************************************************
Note: See TracBrowser for help on using the repository browser.