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

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

check wnd pointer in ReleaseDC

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