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

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

WS_MAXIMIZE & WS_MINIMIZE flags updated when necessary & RedrawWindow changes

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