source: trunk/src/user32/new/dc.cpp@ 2421

Last change on this file since 2421 was 2421, checked in by cbratschi, 26 years ago

fixed WM_CALCVALIDRECTS, added region for WM_NCPAINT

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