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

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

Fix for DCX_INTERSECTRGN in GetDCEx

File size: 52.2 KB
Line 
1/* $Id: dc.cpp,v 1.44 2000-02-07 14:30:18 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 if (redraw & RDW_NOERASE_W) {
1090 wnd->setSuppressErase(TRUE);
1091 }
1092 else wnd->setSuppressErase(FALSE);
1093
1094 if (hrgn)
1095 {
1096 ULONG BytesNeeded;
1097 PRGNDATA_W RgnData;
1098 PRECTL pr;
1099 int i;
1100 LONG height = wnd ? wnd->getClientHeight() : OSLibQueryScreenHeight();
1101
1102 if (!hrgn)
1103 goto error;
1104
1105 BytesNeeded = O32_GetRegionData (hrgn, 0, NULL);
1106 RgnData = (PRGNDATA_W)_alloca (BytesNeeded);
1107 if (RgnData == NULL)
1108 goto error;
1109 O32_GetRegionData (hrgn, BytesNeeded, RgnData);
1110
1111 pr = (PRECTL)(RgnData->Buffer);
1112 for (i = RgnData->rdh.nCount; i > 0; i--, pr++) {
1113 LONG temp = pr->yTop;
1114 pr->yTop = height - pr->yBottom;
1115 pr->yBottom = height - temp;
1116 }
1117
1118 hpsTemp = WinGetScreenPS (HWND_DESKTOP);
1119 hrgnTemp = GpiCreateRegion (hpsTemp, RgnData->rdh.nCount, (PRECTL)(RgnData->Buffer));
1120 if (!hrgnTemp) goto error;
1121 }
1122 else if (pRect)
1123 {
1124 LONG height = wnd ? wnd->getClientHeight() : OSLibQueryScreenHeight();
1125
1126 PMRECT_FROM_WINRECT (rectl, *pRect);
1127 rectl.yTop = height - rectl.yTop;
1128 rectl.yBottom = height - rectl.yBottom;
1129 }
1130
1131 if (redraw & RDW_INVALIDATE_W)
1132 {
1133 if (redraw & RDW_ERASE_W)
1134 wnd->setEraseBkgnd (TRUE, TRUE);
1135
1136 if (!pRect && !hrgn)
1137 success = WinInvalidateRect (hwnd, NULL, IncludeChildren);
1138 else if (hrgn)
1139 success = WinInvalidateRegion (hwnd, hrgnTemp, IncludeChildren);
1140 else
1141 success = WinInvalidateRect (hwnd, &rectl, IncludeChildren);
1142 if (!success) goto error;
1143 }
1144 else if (redraw & RDW_VALIDATE_W)
1145 {
1146 if (WinQueryUpdateRect (hwnd, NULL))
1147 {
1148 if (!pRect && !hrgn)
1149 success = WinValidateRect (hwnd, NULL, IncludeChildren);
1150 else if (hrgn)
1151 success = WinValidateRegion (hwnd, hrgnTemp, IncludeChildren);
1152 else
1153 success = WinValidateRect (hwnd, &rectl, IncludeChildren);
1154 if (!success) goto error;
1155 }
1156 }
1157
1158 if(WinQueryUpdateRect(hwnd, NULL))
1159 {
1160 if(redraw & RDW_UPDATENOW_W) {
1161 wnd->MsgPaint (0, FALSE);
1162 }
1163 else
1164 if((redraw & RDW_ERASE_W) && (redraw & RDW_ERASENOW_W))
1165 wnd->setEraseBkgnd (FALSE, !sendEraseBkgnd (wnd));
1166 }
1167 else if((redraw & RDW_INTERNALPAINT_W) && !(redraw & RDW_INVALIDATE_W))
1168 {
1169 if(redraw & RDW_UPDATENOW_W)
1170 wnd->MsgPaint (0, FALSE);
1171 else PostMessageA(hwnd, WINWM_PAINT, 0, 0);
1172 }
1173
1174error:
1175 /* clean up */
1176 if (hrgnTemp)
1177 GpiDestroyRegion (hpsTemp, hrgnTemp);
1178
1179 if (hpsTemp)
1180 WinReleasePS (hpsTemp);
1181
1182//SvL: Test
1183// if ((redraw & RDW_INVALIDATE_W) == 0)
1184// wnd->setSuppressErase (FALSE);
1185// else if ((redraw & RDW_ERASENOW_W) == RDW_ERASENOW_W)
1186// wnd->setSuppressErase (TRUE);
1187
1188 if (!success)
1189 O32_SetLastError (ERROR_INVALID_PARAMETER);
1190
1191 return (success);
1192}
1193//******************************************************************************
1194//******************************************************************************
1195BOOL WIN32API UpdateWindow (HWND hwnd)
1196{
1197 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
1198
1199 if(!wnd) {
1200 O32_SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1201 return FALSE;
1202 }
1203
1204 dprintf (("User32: UpdateWindow hwnd %x", hwnd));
1205////SvL: This doesn't work right (it's what Wine does) -> TODO
1206//// return RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW_W | RDW_NOCHILDREN_W);
1207 WinUpdateWindow(wnd->getOS2WindowHandle());
1208 return TRUE;
1209}
1210//******************************************************************************
1211//******************************************************************************
1212BOOL WIN32API InvalidateRect (HWND hwnd, const RECT *pRect, BOOL erase)
1213{
1214 BOOL result;
1215
1216 result = RedrawWindow (hwnd, pRect, NULLHANDLE,
1217 RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
1218 (erase ? RDW_ERASE_W : 0) |
1219 (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
1220 return (result);
1221}
1222//******************************************************************************
1223//******************************************************************************
1224BOOL WIN32API InvalidateRgn (HWND hwnd, HRGN hrgn, BOOL erase)
1225{
1226 BOOL result;
1227
1228 result = RedrawWindow (hwnd, NULL, hrgn,
1229 RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
1230 (erase ? RDW_ERASE_W : 0) |
1231 (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
1232 return (result);
1233}
1234//******************************************************************************
1235//******************************************************************************
1236BOOL setPMRgnIntoWinRgn (HRGN hrgnPM, HRGN hrgnWin, LONG height)
1237{
1238 BOOL rc;
1239 HPS hps = WinGetScreenPS (HWND_DESKTOP);
1240 RGNRECT rgnRect;
1241 rgnRect.ircStart = 1;
1242 rgnRect.crc = 0;
1243 rgnRect.ulDirection = RECTDIR_LFRT_TOPBOT; // doesn't make a difference because we're getting them all
1244
1245 rc = GpiQueryRegionRects (hps, hrgnPM, NULL, &rgnRect, NULL);
1246
1247 if (rc && (rgnRect.crcReturned > 0))
1248 {
1249 PRECTL Rcls = new RECTL[rgnRect.crcReturned];
1250 PRECTL pRcl = Rcls;
1251
1252 if (Rcls != NULL)
1253 {
1254 rgnRect.crc = rgnRect.crcReturned;
1255 rc = GpiQueryRegionRects (hps, hrgnPM, NULL, &rgnRect, Rcls);
1256
1257 rc = O32_SetRectRgn (hrgnWin, pRcl->xLeft,
1258 pRcl->xRight,
1259 height - pRcl->yTop,
1260 height - pRcl->yBottom);
1261
1262 if (rgnRect.crcReturned > 1)
1263 {
1264 int i;
1265 HRGN temp;
1266 temp = O32_CreateRectRgn (0, 0, 1, 1);
1267
1268 for (i = 1, pRcl++; rc && (i < rgnRect.crcReturned); i++, pRcl++)
1269 {
1270 rc = O32_SetRectRgn (temp, pRcl->xLeft,
1271 pRcl->xRight,
1272 height - pRcl->yTop,
1273 height - pRcl->yBottom);
1274 rc &= O32_CombineRgn (hrgnWin, hrgnWin, temp, RGN_OR_W);
1275 }
1276 O32_DeleteObject (temp);
1277 }
1278 delete[] Rcls;
1279 }
1280 else
1281 {
1282 rc = FALSE;
1283 }
1284 }
1285 else
1286 {
1287 rc = O32_SetRectRgn (hrgnWin, 0, 0, 0, 0);
1288 }
1289
1290 WinReleasePS (hps);
1291 return (rc);
1292}
1293//******************************************************************************
1294//******************************************************************************
1295BOOL WIN32API ScrollDC (HDC hDC, int dx, int dy, const RECT *pScroll,
1296 const RECT *pClip, HRGN hrgnUpdate, LPRECT pRectUpdate)
1297{
1298 BOOL rc = TRUE;
1299
1300 dprintf (("USER32: ScrollDC"));
1301
1302 if (!hDC)
1303 {
1304 return (FALSE);
1305 }
1306
1307 pDCData pHps = (pDCData)GpiQueryDCData ((HPS)hDC);
1308 HWND hwnd = pHps->hwnd;
1309 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
1310
1311 if ((hwnd == NULLHANDLE) || !wnd)
1312 {
1313 return (FALSE);
1314 }
1315
1316 POINTL ptl[2] = { 0, 0, dx, dy };
1317
1318 GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, ptl);
1319 dx = (int)(ptl[1].x - ptl[0].x);
1320 dy = (int)(ptl[1].y - ptl[0].y);
1321
1322 RECTL scrollRect;
1323 RECTL clipRect;
1324
1325 if (pClip)
1326 {
1327 clipRect.xLeft = min (pClip->left, pClip->right);
1328 clipRect.xRight = max (pClip->left, pClip->right);
1329 clipRect.yTop = max (pClip->top, pClip->bottom);
1330 clipRect.yBottom = min (pClip->top, pClip->bottom);
1331
1332 if ((pHps->graphicsMode == GM_COMPATIBLE_W) &&
1333 (clipRect.xLeft != clipRect.xRight) &&
1334 (clipRect.yBottom != clipRect.yTop))
1335 {
1336 if (abs((int)pHps->viewportXExt) <= abs((int)pHps->windowExt.cx))
1337 clipRect.xRight -= abs(pHps->worldXDeltaFor1Pixel);
1338 else
1339 clipRect.xLeft += abs(pHps->worldXDeltaFor1Pixel);
1340
1341 if (abs((int)pHps->viewportYExt) <= abs((int)pHps->windowExt.cy))
1342 clipRect.yTop -= abs(pHps->worldYDeltaFor1Pixel);
1343 else
1344 clipRect.yBottom += abs(pHps->worldYDeltaFor1Pixel);
1345 }
1346 GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, (PPOINTL)&clipRect);
1347 if (clipRect.xRight < clipRect.xLeft) {
1348 ULONG temp = clipRect.xLeft;
1349 clipRect.xLeft = clipRect.xRight;
1350 clipRect.xRight = temp;
1351 }
1352 if (clipRect.yTop < clipRect.yBottom) {
1353 ULONG temp = clipRect.yBottom;
1354 clipRect.yBottom = clipRect.yTop;
1355 clipRect.yTop = temp;
1356 }
1357 }
1358
1359 if (pScroll)
1360 {
1361 scrollRect.xLeft = min (pScroll->left, pScroll->right);
1362 scrollRect.xRight = max (pScroll->left, pScroll->right);
1363 scrollRect.yTop = max (pScroll->top, pScroll->bottom);
1364 scrollRect.yBottom = min (pScroll->top, pScroll->bottom);
1365
1366 if ((pHps->graphicsMode == GM_COMPATIBLE_W) &&
1367 (scrollRect.xLeft != scrollRect.xRight) &&
1368 (scrollRect.yBottom != scrollRect.yTop))
1369 {
1370 if (abs((int)pHps->viewportXExt) <= abs((int)pHps->windowExt.cx))
1371 scrollRect.xRight -= abs(pHps->worldXDeltaFor1Pixel);
1372 else
1373 scrollRect.xLeft += abs(pHps->worldXDeltaFor1Pixel);
1374
1375 if (abs((int)pHps->viewportYExt) <= abs((int)pHps->windowExt.cy))
1376 scrollRect.yTop -= abs(pHps->worldYDeltaFor1Pixel);
1377 else
1378 scrollRect.yBottom += abs(pHps->worldYDeltaFor1Pixel);
1379 }
1380 GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, (PPOINTL)&scrollRect);
1381 if (scrollRect.xRight < scrollRect.xLeft) {
1382 ULONG temp = scrollRect.xLeft;
1383 scrollRect.xLeft = scrollRect.xRight;
1384 scrollRect.xRight = temp;
1385 }
1386 if (scrollRect.yTop < scrollRect.yBottom) {
1387 ULONG temp = scrollRect.yBottom;
1388 scrollRect.yBottom = scrollRect.yTop;
1389 scrollRect.yTop = temp;
1390 }
1391 }
1392 RECTL rectlUpdate;
1393 HRGN hrgn;
1394
1395 LONG lComplexity = WinScrollWindow (hwnd, dx, dy, (pScroll) ? &scrollRect : NULL, (pClip) ? &clipRect : NULL, hrgn, &rectlUpdate, 0);
1396 if (lComplexity == RGN_ERROR)
1397 {
1398 return (FALSE);
1399 }
1400
1401 RECT winRectUpdate;
1402 LONG height = wnd->getClientHeight();
1403
1404 winRectUpdate.left = rectlUpdate.xLeft;
1405 winRectUpdate.right = rectlUpdate.xRight;
1406 winRectUpdate.top = height - rectlUpdate.yTop;
1407 winRectUpdate.bottom = height - rectlUpdate.yBottom;
1408
1409 if (pRectUpdate)
1410 *pRectUpdate = winRectUpdate;
1411
1412 if (hrgnUpdate)
1413 rc = setPMRgnIntoWinRgn (hrgn, hrgnUpdate, height);
1414
1415 return (rc);
1416}
1417//******************************************************************************
1418//******************************************************************************
1419#if 1
1420BOOL WIN32API ScrollWindow(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip)
1421{
1422 Win32BaseWindow *window;
1423 APIRET rc;
1424 RECTL clientRect;
1425 PRECT pClientRect;
1426 RECTL scrollRect;
1427 RECTL clipRect;
1428 PRECTL pScrollRect = NULL;
1429 PRECTL pClipRect = NULL;
1430 ULONG scrollFlags = SW_INVALIDATERGN;
1431
1432 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1433 if(!window) {
1434 dprintf(("ScrollWindow, window %x not found", hwnd));
1435 return 0;
1436 }
1437 dprintf(("ScrollWindow %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip));
1438
1439 pClientRect = window->getClientRectPtr();
1440 clientRect.xLeft = 0;
1441 clientRect.yBottom = 0;
1442 clientRect.xRight = pClientRect->right - pClientRect->left;
1443 clientRect.yTop = pClientRect->bottom - pClientRect->top;
1444
1445 if(pScroll) {
1446 mapWin32ToOS2Rect(window,(RECT *)pScroll, (PRECTLOS2)&scrollRect);
1447 pScrollRect = &scrollRect;
1448
1449 //Scroll rectangle relative to client area
1450 WinIntersectRect ((HAB) 0, pScrollRect, pScrollRect, &clientRect);
1451 }
1452 else scrollFlags |= SW_SCROLLCHILDREN;
1453
1454 if(pClip) {
1455 mapWin32ToOS2Rect(window,(RECT *)pClip, (PRECTLOS2)&clipRect);
1456 pClipRect = &clipRect;
1457
1458 //Clip rectangle relative to client area
1459 WinIntersectRect ((HAB) 0, pClipRect, pClipRect, &clientRect);
1460 }
1461
1462 dy = revertDy (window, dy);
1463
1464 rc = WinScrollWindow(window->getOS2WindowHandle(), dx, dy,
1465 pScrollRect, pClipRect, NULLHANDLE,
1466 NULL, scrollFlags);
1467
1468 return (rc != RGN_ERROR);
1469}
1470#else
1471BOOL WIN32API ScrollWindow(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip)
1472{
1473 Win32BaseWindow *window;
1474 APIRET rc;
1475 RECTL clientRect;
1476 RECTL scrollRect;
1477 RECTL clipRect;
1478 PRECTL pScrollRect = NULL;
1479 PRECTL pClipRect = NULL;
1480 ULONG scrollFlags = SW_INVALIDATERGN;
1481
1482 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1483 if(!window) {
1484 dprintf(("ScrollWindow, window %x not found", hwnd));
1485 return 0;
1486 }
1487 dprintf(("ScrollWindow %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip));
1488 mapWin32ToOS2Rect(window,window->getClientRectPtr(),(PRECTLOS2)&clientRect);
1489#if 0
1490 //Rectangle could be relative to parent window, so fix this
1491 if(clientRect.yBottom != 0) {
1492 clientRect.yTop -= clientRect.yBottom;
1493 clientRect.yBottom = 0;
1494 }
1495 if(clientRect.xLeft != 0) {
1496 clientRect.xRight -= clientRect.xLeft;
1497 clientRect.xLeft = 0;
1498 }
1499#endif
1500 if(pScroll) {
1501 mapWin32ToOS2Rect(window,(RECT *)pScroll, (PRECTLOS2)&scrollRect);
1502 pScrollRect = &scrollRect;
1503
1504 //Scroll rectangle relative to client area
1505 pScrollRect->xLeft += clientRect.xLeft;
1506 pScrollRect->xRight += clientRect.xLeft;
1507 pScrollRect->yTop += clientRect.yBottom;
1508 pScrollRect->yBottom += clientRect.yBottom;
1509 WinIntersectRect ((HAB) 0, pScrollRect, pScrollRect, &clientRect);
1510 }
1511 else scrollFlags |= SW_SCROLLCHILDREN;
1512
1513 if(pClip) {
1514 mapWin32ToOS2Rect(window,(RECT *)pClip, (PRECTLOS2)&clipRect);
1515 pClipRect = &clipRect;
1516
1517 //Clip rectangle relative to client area
1518 pClipRect->xLeft += clientRect.xLeft;
1519 pClipRect->xRight += clientRect.xLeft;
1520 pClipRect->yTop += clientRect.yBottom;
1521 pClipRect->yBottom += clientRect.yBottom;
1522 WinIntersectRect ((HAB) 0, pClipRect, pClipRect, &clientRect);
1523 }
1524
1525 dy = revertDy (window, dy);
1526
1527 rc = WinScrollWindow(window->getOS2WindowHandle(), dx, dy,
1528 pScrollRect, pClipRect, NULLHANDLE,
1529 NULL, scrollFlags);
1530
1531 return (rc != RGN_ERROR);
1532}
1533#endif
1534//******************************************************************************
1535//******************************************************************************
1536INT WIN32API ScrollWindowEx(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip,
1537 HRGN hrgnUpdate, PRECT pRectUpdate, UINT scrollFlag)
1538{
1539 Win32BaseWindow *window;
1540 APIRET rc;
1541 RECTL scrollRect;
1542 RECTL clipRect;
1543 ULONG scrollFlags = 0;
1544 int regionType = ERROR_W;
1545
1546 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1547 if(!window) {
1548 dprintf(("ScrollWindowEx, window %x not found", hwnd));
1549 return 0;
1550 }
1551
1552 dprintf(("ScrollWindowEx %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip));
1553
1554 dy = revertDy (window, dy);
1555
1556 if (scrollFlag & SW_INVALIDATE_W) scrollFlags |= SW_INVALIDATERGN;
1557 if (scrollFlag & SW_SCROLLCHILDREN_W) scrollFlags |= SW_SCROLLCHILDREN;
1558
1559 if(pScroll) mapWin32ToOS2Rect(window,(RECT *)pScroll, (PRECTLOS2)&scrollRect);
1560 if(pClip) mapWin32ToOS2Rect(window,(RECT *)pClip, (PRECTLOS2)&clipRect);
1561
1562 RECTL rectlUpdate;
1563 HRGN hrgn;
1564
1565 if (scrollFlag & SW_SMOOTHSCROLL_W)
1566 {
1567 INT time = (scrollFlag >> 16) & 0xFFFF;
1568
1569 //CB: todo, scroll in several steps
1570 // is time in ms? time <-> iteration count?
1571 }
1572
1573 LONG lComplexity = WinScrollWindow (window->getOS2WindowHandle(), dx, dy,
1574 (pScroll) ? &scrollRect : NULL,
1575 (pClip) ? &clipRect : NULL,
1576 hrgn, &rectlUpdate, scrollFlags);
1577 if (lComplexity == RGN_ERROR)
1578 {
1579 return ERROR_W;
1580 }
1581
1582 RECT winRectUpdate;
1583 LONG height = window->getClientHeight();
1584
1585 winRectUpdate.left = rectlUpdate.xLeft;
1586 winRectUpdate.right = rectlUpdate.xRight;
1587 winRectUpdate.top = height - rectlUpdate.yTop;
1588 winRectUpdate.bottom = height - rectlUpdate.yBottom;
1589
1590 if (pRectUpdate)
1591 *pRectUpdate = winRectUpdate;
1592
1593 if (hrgnUpdate)
1594 rc = setPMRgnIntoWinRgn (hrgn, hrgnUpdate, height);
1595
1596 if ((scrollFlag & SW_INVALIDATE_W) &&
1597 ((lComplexity == RGN_RECT) || (lComplexity == RGN_COMPLEX)))
1598 {
1599 rc = InvalidateRect (hwnd, &winRectUpdate, (scrollFlag & SW_ERASE_W) ? 1 : 0);
1600 if (rc == FALSE)
1601 {
1602 return (0);
1603 }
1604 }
1605
1606 switch (lComplexity)
1607 {
1608 case RGN_NULL:
1609 regionType = NULLREGION_W;
1610 break;
1611 case RGN_RECT:
1612 regionType = SIMPLEREGION_W;
1613 break;
1614 case RGN_COMPLEX:
1615 regionType = COMPLEXREGION_W;
1616 break;
1617 default:
1618 regionType = ERROR_W;
1619 break;
1620 }
1621
1622 return (regionType);
1623}
1624//******************************************************************************
1625//******************************************************************************
1626HWND WIN32API WindowFromDC(HDC hdc)
1627{
1628 pDCData pHps = (pDCData)GpiQueryDCData( (HPS)hdc );
1629
1630 dprintf2(("USER32: WindowFromDC %x", hdc));
1631 if ( pHps )
1632 return Win32BaseWindow::OS2ToWin32Handle(pHps->hwnd);
1633 else
1634 return 0;
1635}
1636//******************************************************************************
1637//******************************************************************************
1638INT WIN32API ExcludeUpdateRgn( HDC hDC, HWND hWnd)
1639{
1640 dprintf(("USER32: ExcludeUpdateRgn\n"));
1641 hWnd = Win32BaseWindow::Win32ToOS2Handle(hWnd);
1642
1643 return O32_ExcludeUpdateRgn(hDC,hWnd);
1644}
1645//******************************************************************************
1646//******************************************************************************
1647BOOL WIN32API ValidateRect( HWND hwnd, const RECT * lprc)
1648{
1649 if(lprc) {
1650 dprintf(("USER32: ValidateRect %x (%d,%d)(%d,%d)", hwnd, lprc->left, lprc->top, lprc->right, lprc->bottom));
1651 }
1652 else dprintf(("USER32: ValidateRect %x", hwnd));
1653
1654 return RedrawWindow( hwnd, lprc, 0, RDW_VALIDATE_W | RDW_NOCHILDREN_W | (hwnd==0 ? RDW_UPDATENOW_W : 0));
1655}
1656//******************************************************************************
1657//******************************************************************************
1658BOOL WIN32API ValidateRgn( HWND hwnd, HRGN hrgn)
1659{
1660 dprintf(("USER32: ValidateRgn %x %x", hwnd, hrgn));
1661 return RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE_W | RDW_NOCHILDREN_W | (hwnd==0 ? RDW_UPDATENOW_W : 0));
1662}
1663/*****************************************************************************
1664 * Name : int WIN32API GetWindowRgn
1665 * Purpose : The GetWindowRgn function obtains a copy of the window region of a window.
1666 * Parameters: HWND hWnd handle to window whose window region is to be obtained
1667 * HRGN hRgn handle to region that receives a copy of the window region
1668 * Variables :
1669 * Result : NULLREGION, SIMPLEREGION, COMPLEXREGION, ERROR
1670 * Remark :
1671 * Status : UNTESTED STUB
1672 *
1673 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
1674 *****************************************************************************/
1675
1676int WIN32API GetWindowRgn(HWND hwnd, HRGN hRgn)
1677{
1678 Win32BaseWindow *window;
1679 HRGN hWindowRegion;
1680
1681 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1682 if(!window) {
1683 dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
1684 O32_SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1685 return 0;
1686 }
1687 dprintf(("USER32:GetWindowRgn (%x,%x)", hwnd, hRgn));
1688 hWindowRegion = window->GetWindowRegion();
1689
1690 return O32_CombineRgn(hRgn, hWindowRegion, 0, RGN_COPY_W);
1691}
1692/*****************************************************************************
1693 * Name : int WIN32API SetWindowRgn
1694 * Purpose : The SetWindowRgn function sets the window region of a window. The
1695 * window region determines the area within the window where the
1696 * operating system permits drawing. The operating system does not
1697 * display any portion of a window that lies outside of the window region
1698 * When this function is called, the system sends the WM_WINDOWPOSCHANGING and
1699 * WM_WINDOWPOSCHANGED messages to the window.
1700 *
1701 * Parameters: HWND hWnd handle to window whose window region is to be set
1702 * HRGN hRgn handle to region
1703 * BOOL bRedraw window redraw flag
1704 * Variables :
1705 * Result : If the function succeeds, the return value is non-zero.
1706 * If the function fails, the return value is zero.
1707 * Remark :
1708 * Status : UNTESTED STUB
1709 *
1710 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
1711 *****************************************************************************/
1712
1713int WIN32API SetWindowRgn(HWND hwnd,
1714 HRGN hRgn,
1715 BOOL bRedraw)
1716{
1717 Win32BaseWindow *window;
1718 HRGN hWindowRegion;
1719
1720 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1721 if(!window) {
1722 dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
1723 O32_SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1724 return 0;
1725 }
1726 dprintf(("USER32:SetWindowRgn (%x,%x,%d)", hwnd, hRgn, bRedraw));
1727 if(window->GetWindowRegion()) {
1728 O32_DeleteObject(window->GetWindowRegion());
1729 }
1730 window->SetWindowRegion(hRgn);
1731 if(bRedraw) {
1732 RedrawWindow(hwnd, 0, 0, RDW_UPDATENOW_W);
1733 }
1734//TODO:
1735// When this function is called, the system sends the WM_WINDOWPOSCHANGING and
1736// WM_WINDOWPOSCHANGED messages to the window.
1737 return 1;
1738}
1739//******************************************************************************
1740//******************************************************************************
Note: See TracBrowser for help on using the repository browser.