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

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

GetDCEx changes (fail if hwnd == 0)

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