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

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

Turn of WM_BACKERASEBKGND when calling RedrawWindow to invalidate a window

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