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

Last change on this file since 2804 was 2804, checked in by sandervl, 26 years ago

Added new logging feature

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