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

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

Don't call default frame handler for WM_ADJUSTWINDOWPOS

File size: 47.2 KB
Line 
1/* $Id: dc.cpp,v 1.38 2000-01-28 22:25:59 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 if ( !lpps )
441 {
442 dprintf (("USER32: BeginPaint %x invalid parameter %x", hWnd, lpps));
443 O32_SetLastError (ERROR_INVALID_PARAMETER);
444 return (HDC)NULLHANDLE;
445 }
446
447 if(hWnd == 0x6800003a) {
448 hwnd = 0x6800003a;
449 }
450 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
451
452 if ((hwnd != HWND_DESKTOP) && wnd->isOwnDC())
453 {
454 hPS_ownDC = wnd->getOwnDC();
455 //SvL: Hack for memory.exe (doesn't get repainted properly otherwise)
456 if(hPS_ownDC) {
457 pHps = (pDCData)GpiQueryDCData(hPS_ownDC);
458 if (!pHps)
459 {
460 dprintf (("USER32: BeginPaint %x invalid parameter %x", hWnd, lpps));
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 dprintf(("USER32: BeginPaint %x -> hdc %x", hWnd, pHps->hps));
507 return (HDC)pHps->hps;
508}
509//******************************************************************************
510//******************************************************************************
511BOOL WIN32API EndPaint (HWND hwnd, const PAINTSTRUCT_W *pPaint)
512{
513 dprintf (("USER32: EndPaint(%x)", hwnd));
514
515 if (!pPaint || !pPaint->hdc )
516 return TRUE;
517
518 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
519
520 if (!wnd) goto exit;
521
522 //SvL: Hack for memory.exe (doesn't get repainted properly otherwise)
523 if(wnd->isOwnDC() && wnd->getOwnDC())
524// if(wnd->isOwnDC())
525 {
526 pDCData pHps = (pDCData)GpiQueryDCData((HPS)pPaint->hdc);
527 if (pHps && (pHps->hdcType == TYPE_3))
528 {
529 WinEndPaint (pHps->hps);
530 }
531 }
532 else
533 {
534 O32_EndPaint (HWND_DESKTOP, pPaint);
535 }
536 wnd->setSuppressErase(FALSE);
537
538exit:
539 O32_SetLastError(0);
540 return TRUE;
541}
542//******************************************************************************
543//******************************************************************************
544BOOL WIN32API GetUpdateRect (HWND hwnd, LPRECT pRect, BOOL erase)
545{
546 if (!hwnd)
547 {
548 O32_SetLastError (ERROR_INVALID_HANDLE);
549 return FALSE;
550 }
551
552 RECTL rectl;
553 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
554
555 if (!wnd)
556 {
557 O32_SetLastError (ERROR_INVALID_HANDLE);
558 return FALSE;
559 }
560
561 BOOL updateRegionExists = WinQueryUpdateRect (wnd->getOS2WindowHandle(), pRect ? &rectl : NULL);
562 if (!pRect) {
563 return (updateRegionExists);
564 }
565
566 if (updateRegionExists)
567 {
568 //CB: for PM empty rect is valid
569 if ((rectl.xLeft == rectl.xRight) || (rectl.yTop == rectl.yBottom)) return FALSE;
570 //SvL: Hack for memory.exe (doesn't get repainted properly otherwise)
571// if (wnd->isOwnDC() && wnd->getOwnDC())
572 if (wnd->isOwnDC())
573 {
574 pDCData pHps = NULL;
575 pHps = (pDCData)GpiQueryDCData(wnd->getOwnDC());
576 if (!pHps)
577 {
578 O32_SetLastError (ERROR_INVALID_HANDLE);
579 return FALSE;
580 }
581 GpiConvert (pHps->hps, CVTC_DEVICE, CVTC_WORLD, 2, (PPOINTL)&rectl);
582 }
583 else
584 {
585 long height = wnd->getClientHeight();
586 rectl.yTop = height - rectl.yTop;
587 rectl.yBottom = height - rectl.yBottom;
588 }
589
590 if (pRect)
591 WINRECT_FROM_PMRECT (*pRect, rectl);
592
593 if (erase)
594 sendEraseBkgnd (wnd);
595 }
596 else
597 {
598 if (pRect)
599 pRect->left = pRect->top = pRect->right = pRect->bottom = 0;
600 }
601
602 return updateRegionExists;
603}
604//******************************************************************************
605//functions for WM_NCPAINT
606//******************************************************************************
607INT SYSTEM GetOS2UpdateRgn(HWND hwnd,HRGN hrgn)
608{
609 return O32_GetUpdateRgn(hwnd,hrgn,FALSE);
610}
611//******************************************************************************
612//******************************************************************************
613BOOL SYSTEM GetOS2UpdateRect(HWND hwnd,LPRECT pRect)
614{
615 RECTL rectl;
616 BOOL updateRegionExists = WinQueryUpdateRect(hwnd,pRect ? &rectl:NULL);
617
618 if (!pRect)
619 return (updateRegionExists);
620
621 if (updateRegionExists)
622 {
623 //CB: for PM empty rect is valid
624 if ((rectl.xLeft == rectl.xRight) || (rectl.yTop == rectl.yBottom)) return FALSE;
625 mapOS2ToWin32Rect(hwnd,(PRECTLOS2)&rectl,pRect);
626 } else
627 pRect->left = pRect->top = pRect->right = pRect->bottom = 0;
628
629 return updateRegionExists;
630}
631//******************************************************************************
632//******************************************************************************
633int WIN32API GetUpdateRgn (HWND hwnd, HRGN hrgn, BOOL erase)
634{
635 LONG Complexity;
636
637 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
638
639 if (!wnd)
640 {
641 O32_SetLastError (ERROR_INVALID_HANDLE);
642 return ERROR_W;
643 }
644
645 Complexity = O32_GetUpdateRgn (wnd->getOS2WindowHandle(), hrgn, FALSE);
646 if (erase && (Complexity > NULLREGION_W)) sendEraseBkgnd (wnd);
647
648 return Complexity;
649}
650//******************************************************************************
651// This implementation of GetDCEx supports
652// DCX_WINDOW
653// DCX_CACHE
654// DCX_EXCLUDERGN (complex regions allowed)
655// DCX_INTERSECTRGN (complex regions allowed)
656//******************************************************************************
657HDC WIN32API GetDCEx (HWND hwnd, HRGN hrgn, ULONG flags)
658{
659 Win32BaseWindow *wnd = NULL;
660 HWND hWindow;
661 BOOL success;
662 pDCData pHps = NULL;
663 HPS hps = NULLHANDLE;
664 BOOL drawingAllowed = TRUE;
665 BOOL isWindowOwnDC;
666 BOOL creatingOwnDC = FALSE;
667 PS_Type psType;
668
669 if (hwnd)
670 {
671 wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
672 if(wnd == NULL) {
673 dprintf (("ERROR: User32: GetDCEx bad window handle %X!!!!!", hwnd));
674 O32_SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
675 return 0;
676 }
677//SvL: Experimental change (doesn't work right)
678#if 0
679 if(wnd->fHasParentDC() && wnd->getParent()) {
680 wnd = wnd->getParent();
681 }
682#endif
683 if (flags & DCX_WINDOW_W)
684 hWindow = wnd->getOS2FrameWindowHandle();
685 else
686 hWindow = wnd->getOS2WindowHandle();
687 }
688 else
689 hWindow = HWND_DESKTOP;
690
691 //SvL: Hack for memory.exe (doesn't get repainted properly otherwise)
692// isWindowOwnDC = (((hWindow == HWND_DESKTOP) ? FALSE : (wnd->isOwnDC() && wnd->getOwnDC()))
693 isWindowOwnDC = (((hWindow == HWND_DESKTOP) ? FALSE : (wnd->isOwnDC()))
694 && !(flags & DCX_CACHE_W|DCX_WINDOW_W));
695
696 if (isWindowOwnDC)
697 {
698 hps = wnd->getOwnDC();
699 if (hps)
700 {
701 pDCData pHps = (pDCData)GpiQueryDCData (hps);
702 if (!pHps)
703 goto error;
704
705 setPageXForm (wnd, pHps);
706
707 pHps->hdcType = TYPE_1;
708 dprintf (("User32: GetDCEx hwnd %x (%x %x) -> wnd %x hdc %x", hwnd, hrgn, flags, wnd, hps));
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 dprintf (("User32: GetDCEx hwnd %x (%x %x) -> hdc %x", hwnd, hrgn, flags, pHps->hps));
787 return (HDC)pHps->hps;
788
789error:
790 /* Something went wrong; clean up
791 */
792 if (pHps)
793 {
794 if (pHps->hps)
795 {
796 if(pHps->psType == MICRO_CACHED)
797 WinReleasePS(pHps->hps);
798 else
799 GpiDestroyPS(pHps->hps);
800 }
801
802 if (pHps->hdc) DevCloseDC(pHps->hdc);
803 if (pHps->hrgnHDC) GpiDestroyRegion(pHps->hps, pHps->hrgnHDC);
804
805 O32_DeleteObject (pHps->nullBitmapHandle);
806 }
807 O32_SetLastError (ERROR_INVALID_PARAMETER);
808 return NULL;
809}
810//******************************************************************************
811//******************************************************************************
812HDC WIN32API GetDC (HWND hwnd)
813{
814 return GetDCEx (hwnd, NULL, 0);
815}
816//******************************************************************************
817//******************************************************************************
818HDC WIN32API GetWindowDC (HWND hwnd)
819{
820 return GetDCEx (hwnd, NULL, DCX_WINDOW_W);
821}
822//******************************************************************************
823//******************************************************************************
824int WIN32API ReleaseDC (HWND hwnd, HDC hdc)
825{
826 BOOL isOwnDC = FALSE;
827 int rc;
828
829 if (hwnd)
830 {
831 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
832 if(wnd == NULL) {
833 dprintf(("ERROR: ReleaseDC %x %x failed", hwnd, hdc));
834 return 0;
835 }
836 //SvL: Hack for memory.exe (doesn't get repainted properly otherwise)
837// isOwnDC = wnd->isOwnDC() && wnd->getOwnDC();
838 isOwnDC = wnd->isOwnDC() && (wnd->getOwnDC() == hdc);
839 }
840 if (isOwnDC)
841 rc = TRUE;
842 else
843 rc = O32_ReleaseDC (0, hdc);
844
845 dprintf(("ReleaseDC %x %x", hwnd, hdc));
846 return (rc);
847}
848//******************************************************************************
849//******************************************************************************
850BOOL WIN32API UpdateWindow (HWND hwnd)
851{
852 if (!hwnd)
853 return FALSE;
854
855 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
856
857 dprintf (("User32: UpdateWindow hwnd %x -> wnd %x", hwnd, wnd));
858
859#if 0
860 if (WinQueryUpdateRect (wnd->getOS2WindowHandle(), NULL))
861 sendEraseBkgnd (wnd);
862#endif
863
864 WinUpdateWindow(wnd->getOS2FrameWindowHandle());
865
866 return (TRUE);
867}
868//******************************************************************************
869// This implementation of RedrawWindow supports
870// RDW_ERASE
871// RDW_NOERASE
872// RDW_INTERNALPAINT
873// RDW_NOINTERNALPAINT
874// RDW_INVALIDATE
875// RDW_VALIDATE
876// RDW_ERASENOW
877// RDW_UPDATENOW
878//******************************************************************************
879BOOL WIN32API RedrawWindow(HWND hwnd, const RECT* pRect, HRGN hrgn, DWORD redraw)
880{
881 Win32BaseWindow *wnd;
882
883 if (redraw & (RDW_FRAME_W | RDW_NOFRAME_W))
884 {
885 O32_SetLastError (ERROR_NOT_SUPPORTED);
886 return FALSE;
887 }
888
889 if (hwnd == NULLHANDLE)
890 {
891#if 1
892 // Don't do this for now (causes lots of desktop repaints in WordPad)
893 O32_SetLastError (ERROR_INVALID_PARAMETER);
894 return FALSE;
895#else
896 hwnd = HWND_DESKTOP;
897 wnd = Win32BaseWindow::GetWindowFromOS2Handle(OSLIB_HWND_DESKTOP);
898
899 if (!wnd)
900 {
901 dprintf(("USER32:dc: RedrawWindow can't find desktop window %08xh\n",
902 hwnd));
903 O32_SetLastError (ERROR_INVALID_PARAMETER);
904 return FALSE;
905 }
906#endif
907 }
908 else
909 {
910 wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
911
912 if (!wnd)
913 {
914 dprintf(("USER32:dc: RedrawWindow can't find window %08xh\n",
915 hwnd));
916 O32_SetLastError (ERROR_INVALID_PARAMETER);
917 return FALSE;
918 }
919 hwnd = wnd->getOS2WindowHandle();
920 }
921
922 BOOL IncludeChildren = redraw & RDW_ALLCHILDREN_W ? TRUE : FALSE;
923 BOOL success = TRUE;
924 HPS hpsTemp = NULLHANDLE;
925 HRGN hrgnTemp = NULLHANDLE;
926 RECTL rectl;
927
928 if (redraw & RDW_UPDATENOW_W) redraw &= ~RDW_ERASENOW_W;
929
930 if (redraw & RDW_NOERASE_W)
931 wnd->setEraseBkgnd (FALSE);
932
933//SvL: Test
934// if (redraw & RDW_UPDATENOW_W)
935// wnd->setSuppressErase (FALSE);
936// else if (redraw & RDW_ERASENOW_W)
937// wnd->setSuppressErase (FALSE);
938
939 if (hrgn)
940 {
941 ULONG BytesNeeded;
942 PRGNDATA_W RgnData;
943 PRECTL pr;
944 int i;
945 LONG height = wnd ? wnd->getClientHeight() : OSLibQueryScreenHeight();
946
947 if (!hrgn)
948 goto error;
949
950 BytesNeeded = O32_GetRegionData (hrgn, 0, NULL);
951 RgnData = (PRGNDATA_W)_alloca (BytesNeeded);
952 if (RgnData == NULL)
953 goto error;
954 O32_GetRegionData (hrgn, BytesNeeded, RgnData);
955
956 pr = (PRECTL)(RgnData->Buffer);
957 for (i = RgnData->rdh.nCount; i > 0; i--, pr++) {
958 LONG temp = pr->yTop;
959 pr->yTop = height - pr->yBottom;
960 pr->yBottom = height - temp;
961 }
962
963 hpsTemp = WinGetScreenPS (HWND_DESKTOP);
964 hrgnTemp = GpiCreateRegion (hpsTemp, RgnData->rdh.nCount, (PRECTL)(RgnData->Buffer));
965 if (!hrgnTemp) goto error;
966 }
967 else if (pRect)
968 {
969 LONG height = wnd ? wnd->getClientHeight() : OSLibQueryScreenHeight();
970
971 PMRECT_FROM_WINRECT (rectl, *pRect);
972 rectl.yTop = height - rectl.yTop;
973 rectl.yBottom = height - rectl.yBottom;
974 }
975
976 if (redraw & RDW_INVALIDATE_W)
977 {
978 if (redraw & RDW_ERASE_W)
979 wnd->setEraseBkgnd (TRUE, TRUE);
980
981 if (!pRect && !hrgn)
982 success = WinInvalidateRect (hwnd, NULL, IncludeChildren);
983 else if (hrgn)
984 success = WinInvalidateRegion (hwnd, hrgnTemp, IncludeChildren);
985 else
986 success = WinInvalidateRect (hwnd, &rectl, IncludeChildren);
987 if (!success) goto error;
988 }
989 else if (redraw & RDW_VALIDATE_W)
990 {
991 if (WinQueryUpdateRect (hwnd, NULL))
992 {
993 if (!pRect && !hrgn)
994 success = WinValidateRect (hwnd, NULL, IncludeChildren);
995 else if (hrgn)
996 success = WinValidateRegion (hwnd, hrgnTemp, IncludeChildren);
997 else
998 success = WinValidateRect (hwnd, &rectl, IncludeChildren);
999 if (!success) goto error;
1000 }
1001 }
1002
1003 if (WinQueryUpdateRect (hwnd, NULL))
1004 {
1005 if (redraw & RDW_UPDATENOW_W)
1006 wnd->MsgPaint (0, FALSE);
1007
1008 else if ((redraw & RDW_ERASE_W) && (redraw & RDW_ERASENOW_W))
1009 wnd->setEraseBkgnd (FALSE, !sendEraseBkgnd (wnd));
1010 }
1011 else if ((redraw & RDW_INTERNALPAINT_W) && !(redraw & RDW_INVALIDATE_W))
1012 {
1013 if (redraw & RDW_UPDATENOW_W)
1014 wnd->MsgPaint (0, FALSE);
1015// else
1016// WinPostMsg( hwnd, WM_VIRTUAL_INTERNALPAINT, MPVOID, MPVOID );
1017 }
1018
1019error:
1020 /* clean up */
1021 if (hrgnTemp)
1022 GpiDestroyRegion (hpsTemp, hrgnTemp);
1023
1024 if (hpsTemp)
1025 WinReleasePS (hpsTemp);
1026
1027//SvL: Test
1028// if ((redraw & RDW_INVALIDATE_W) == 0)
1029// wnd->setSuppressErase (FALSE);
1030// else if ((redraw & RDW_ERASENOW_W) == RDW_ERASENOW_W)
1031// wnd->setSuppressErase (TRUE);
1032
1033 if (!success)
1034 O32_SetLastError (ERROR_INVALID_PARAMETER);
1035
1036 return (success);
1037}
1038//******************************************************************************
1039//******************************************************************************
1040BOOL WIN32API InvalidateRect (HWND hwnd, const RECT *pRect, BOOL erase)
1041{
1042 BOOL result;
1043
1044 result = RedrawWindow (hwnd, pRect, NULLHANDLE,
1045 RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
1046 (erase ? RDW_ERASE_W : 0) |
1047 (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
1048 return (result);
1049}
1050//******************************************************************************
1051//******************************************************************************
1052BOOL WIN32API InvalidateRgn (HWND hwnd, HRGN hrgn, BOOL erase)
1053{
1054 BOOL result;
1055
1056 result = RedrawWindow (hwnd, NULL, hrgn,
1057 RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
1058 (erase ? RDW_ERASE_W : 0) |
1059 (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
1060 return (result);
1061}
1062//******************************************************************************
1063//******************************************************************************
1064BOOL setPMRgnIntoWinRgn (HRGN hrgnPM, HRGN hrgnWin, LONG height)
1065{
1066 BOOL rc;
1067 HPS hps = WinGetScreenPS (HWND_DESKTOP);
1068 RGNRECT rgnRect;
1069 rgnRect.ircStart = 1;
1070 rgnRect.crc = 0;
1071 rgnRect.ulDirection = RECTDIR_LFRT_TOPBOT; // doesn't make a difference because we're getting them all
1072
1073 rc = GpiQueryRegionRects (hps, hrgnPM, NULL, &rgnRect, NULL);
1074
1075 if (rc && (rgnRect.crcReturned > 0))
1076 {
1077 PRECTL Rcls = new RECTL[rgnRect.crcReturned];
1078 PRECTL pRcl = Rcls;
1079
1080 if (Rcls != NULL)
1081 {
1082 rgnRect.crc = rgnRect.crcReturned;
1083 rc = GpiQueryRegionRects (hps, hrgnPM, NULL, &rgnRect, Rcls);
1084
1085 rc = O32_SetRectRgn (hrgnWin, pRcl->xLeft,
1086 pRcl->xRight,
1087 height - pRcl->yTop,
1088 height - pRcl->yBottom);
1089
1090 if (rgnRect.crcReturned > 1)
1091 {
1092 int i;
1093 HRGN temp;
1094 temp = O32_CreateRectRgn (0, 0, 1, 1);
1095
1096 for (i = 1, pRcl++; rc && (i < rgnRect.crcReturned); i++, pRcl++)
1097 {
1098 rc = O32_SetRectRgn (temp, pRcl->xLeft,
1099 pRcl->xRight,
1100 height - pRcl->yTop,
1101 height - pRcl->yBottom);
1102 rc &= O32_CombineRgn (hrgnWin, hrgnWin, temp, RGN_OR_W);
1103 }
1104 O32_DeleteObject (temp);
1105 }
1106 delete[] Rcls;
1107 }
1108 else
1109 {
1110 rc = FALSE;
1111 }
1112 }
1113 else
1114 {
1115 rc = O32_SetRectRgn (hrgnWin, 0, 0, 0, 0);
1116 }
1117
1118 WinReleasePS (hps);
1119 return (rc);
1120}
1121//******************************************************************************
1122//******************************************************************************
1123BOOL WIN32API ScrollDC (HDC hDC, int dx, int dy, const RECT *pScroll,
1124 const RECT *pClip, HRGN hrgnUpdate, LPRECT pRectUpdate)
1125{
1126 BOOL rc = TRUE;
1127
1128 dprintf (("USER32: ScrollDC"));
1129
1130 if (!hDC)
1131 {
1132 return (FALSE);
1133 }
1134
1135 pDCData pHps = (pDCData)GpiQueryDCData ((HPS)hDC);
1136 HWND hwnd = pHps->hwnd;
1137 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
1138
1139 if ((hwnd == NULLHANDLE) || !wnd)
1140 {
1141 return (FALSE);
1142 }
1143
1144 POINTL ptl[2] = { 0, 0, dx, dy };
1145
1146 GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, ptl);
1147 dx = (int)(ptl[1].x - ptl[0].x);
1148 dy = (int)(ptl[1].y - ptl[0].y);
1149
1150 RECTL scrollRect;
1151 RECTL clipRect;
1152
1153 if (pClip)
1154 {
1155 clipRect.xLeft = min (pClip->left, pClip->right);
1156 clipRect.xRight = max (pClip->left, pClip->right);
1157 clipRect.yTop = max (pClip->top, pClip->bottom);
1158 clipRect.yBottom = min (pClip->top, pClip->bottom);
1159
1160 if ((pHps->graphicsMode == GM_COMPATIBLE_W) &&
1161 (clipRect.xLeft != clipRect.xRight) &&
1162 (clipRect.yBottom != clipRect.yTop))
1163 {
1164 if (abs((int)pHps->viewportXExt) <= abs((int)pHps->windowExt.cx))
1165 clipRect.xRight -= abs(pHps->worldXDeltaFor1Pixel);
1166 else
1167 clipRect.xLeft += abs(pHps->worldXDeltaFor1Pixel);
1168
1169 if (abs((int)pHps->viewportYExt) <= abs((int)pHps->windowExt.cy))
1170 clipRect.yTop -= abs(pHps->worldYDeltaFor1Pixel);
1171 else
1172 clipRect.yBottom += abs(pHps->worldYDeltaFor1Pixel);
1173 }
1174 GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, (PPOINTL)&clipRect);
1175 if (clipRect.xRight < clipRect.xLeft) {
1176 ULONG temp = clipRect.xLeft;
1177 clipRect.xLeft = clipRect.xRight;
1178 clipRect.xRight = temp;
1179 }
1180 if (clipRect.yTop < clipRect.yBottom) {
1181 ULONG temp = clipRect.yBottom;
1182 clipRect.yBottom = clipRect.yTop;
1183 clipRect.yTop = temp;
1184 }
1185 }
1186
1187 if (pScroll)
1188 {
1189 scrollRect.xLeft = min (pScroll->left, pScroll->right);
1190 scrollRect.xRight = max (pScroll->left, pScroll->right);
1191 scrollRect.yTop = max (pScroll->top, pScroll->bottom);
1192 scrollRect.yBottom = min (pScroll->top, pScroll->bottom);
1193
1194 if ((pHps->graphicsMode == GM_COMPATIBLE_W) &&
1195 (scrollRect.xLeft != scrollRect.xRight) &&
1196 (scrollRect.yBottom != scrollRect.yTop))
1197 {
1198 if (abs((int)pHps->viewportXExt) <= abs((int)pHps->windowExt.cx))
1199 scrollRect.xRight -= abs(pHps->worldXDeltaFor1Pixel);
1200 else
1201 scrollRect.xLeft += abs(pHps->worldXDeltaFor1Pixel);
1202
1203 if (abs((int)pHps->viewportYExt) <= abs((int)pHps->windowExt.cy))
1204 scrollRect.yTop -= abs(pHps->worldYDeltaFor1Pixel);
1205 else
1206 scrollRect.yBottom += abs(pHps->worldYDeltaFor1Pixel);
1207 }
1208 GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, (PPOINTL)&scrollRect);
1209 if (scrollRect.xRight < scrollRect.xLeft) {
1210 ULONG temp = scrollRect.xLeft;
1211 scrollRect.xLeft = scrollRect.xRight;
1212 scrollRect.xRight = temp;
1213 }
1214 if (scrollRect.yTop < scrollRect.yBottom) {
1215 ULONG temp = scrollRect.yBottom;
1216 scrollRect.yBottom = scrollRect.yTop;
1217 scrollRect.yTop = temp;
1218 }
1219 }
1220 RECTL rectlUpdate;
1221 HRGN hrgn;
1222
1223 LONG lComplexity = WinScrollWindow (hwnd, dx, dy, (pScroll) ? &scrollRect : NULL, (pClip) ? &clipRect : NULL, hrgn, &rectlUpdate, 0);
1224 if (lComplexity == RGN_ERROR)
1225 {
1226 return (FALSE);
1227 }
1228
1229 RECT winRectUpdate;
1230 LONG height = wnd->getClientHeight();
1231
1232 winRectUpdate.left = rectlUpdate.xLeft;
1233 winRectUpdate.right = rectlUpdate.xRight;
1234 winRectUpdate.top = height - rectlUpdate.yTop;
1235 winRectUpdate.bottom = height - rectlUpdate.yBottom;
1236
1237 if (pRectUpdate)
1238 *pRectUpdate = winRectUpdate;
1239
1240 if (hrgnUpdate)
1241 rc = setPMRgnIntoWinRgn (hrgn, hrgnUpdate, height);
1242
1243 return (rc);
1244}
1245//******************************************************************************
1246//******************************************************************************
1247#if 1
1248BOOL WIN32API ScrollWindow(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip)
1249{
1250 Win32BaseWindow *window;
1251 APIRET rc;
1252 RECTL clientRect;
1253 PRECT pClientRect;
1254 RECTL scrollRect;
1255 RECTL clipRect;
1256 PRECTL pScrollRect = NULL;
1257 PRECTL pClipRect = NULL;
1258 ULONG scrollFlags = SW_INVALIDATERGN;
1259
1260 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1261 if(!window) {
1262 dprintf(("ScrollWindow, window %x not found", hwnd));
1263 return 0;
1264 }
1265 dprintf(("ScrollWindow %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip));
1266
1267 pClientRect = window->getClientRectPtr();
1268 clientRect.xLeft = 0;
1269 clientRect.yBottom = 0;
1270 clientRect.xRight = pClientRect->right - pClientRect->left;
1271 clientRect.yTop = pClientRect->bottom - pClientRect->top;
1272
1273 if(pScroll) {
1274 mapWin32ToOS2Rect(window,(RECT *)pScroll, (PRECTLOS2)&scrollRect);
1275 pScrollRect = &scrollRect;
1276
1277 //Scroll rectangle relative to client area
1278 WinIntersectRect ((HAB) 0, pScrollRect, pScrollRect, &clientRect);
1279 }
1280 else scrollFlags |= SW_SCROLLCHILDREN;
1281
1282 if(pClip) {
1283 mapWin32ToOS2Rect(window,(RECT *)pClip, (PRECTLOS2)&clipRect);
1284 pClipRect = &clipRect;
1285
1286 //Clip rectangle relative to client area
1287 WinIntersectRect ((HAB) 0, pClipRect, pClipRect, &clientRect);
1288 }
1289
1290 dy = revertDy (window, dy);
1291
1292 rc = WinScrollWindow(window->getOS2WindowHandle(), dx, dy,
1293 pScrollRect, pClipRect, NULLHANDLE,
1294 NULL, scrollFlags);
1295
1296 return (rc != RGN_ERROR);
1297}
1298#else
1299BOOL WIN32API ScrollWindow(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip)
1300{
1301 Win32BaseWindow *window;
1302 APIRET rc;
1303 RECTL clientRect;
1304 RECTL scrollRect;
1305 RECTL clipRect;
1306 PRECTL pScrollRect = NULL;
1307 PRECTL pClipRect = NULL;
1308 ULONG scrollFlags = SW_INVALIDATERGN;
1309
1310 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1311 if(!window) {
1312 dprintf(("ScrollWindow, window %x not found", hwnd));
1313 return 0;
1314 }
1315 dprintf(("ScrollWindow %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip));
1316 mapWin32ToOS2Rect(window,window->getClientRectPtr(),(PRECTLOS2)&clientRect);
1317#if 0
1318 //Rectangle could be relative to parent window, so fix this
1319 if(clientRect.yBottom != 0) {
1320 clientRect.yTop -= clientRect.yBottom;
1321 clientRect.yBottom = 0;
1322 }
1323 if(clientRect.xLeft != 0) {
1324 clientRect.xRight -= clientRect.xLeft;
1325 clientRect.xLeft = 0;
1326 }
1327#endif
1328 if(pScroll) {
1329 mapWin32ToOS2Rect(window,(RECT *)pScroll, (PRECTLOS2)&scrollRect);
1330 pScrollRect = &scrollRect;
1331
1332 //Scroll rectangle relative to client area
1333 pScrollRect->xLeft += clientRect.xLeft;
1334 pScrollRect->xRight += clientRect.xLeft;
1335 pScrollRect->yTop += clientRect.yBottom;
1336 pScrollRect->yBottom += clientRect.yBottom;
1337 WinIntersectRect ((HAB) 0, pScrollRect, pScrollRect, &clientRect);
1338 }
1339 else scrollFlags |= SW_SCROLLCHILDREN;
1340
1341 if(pClip) {
1342 mapWin32ToOS2Rect(window,(RECT *)pClip, (PRECTLOS2)&clipRect);
1343 pClipRect = &clipRect;
1344
1345 //Clip rectangle relative to client area
1346 pClipRect->xLeft += clientRect.xLeft;
1347 pClipRect->xRight += clientRect.xLeft;
1348 pClipRect->yTop += clientRect.yBottom;
1349 pClipRect->yBottom += clientRect.yBottom;
1350 WinIntersectRect ((HAB) 0, pClipRect, pClipRect, &clientRect);
1351 }
1352
1353 dy = revertDy (window, dy);
1354
1355 rc = WinScrollWindow(window->getOS2WindowHandle(), dx, dy,
1356 pScrollRect, pClipRect, NULLHANDLE,
1357 NULL, scrollFlags);
1358
1359 return (rc != RGN_ERROR);
1360}
1361#endif
1362//******************************************************************************
1363//******************************************************************************
1364INT WIN32API ScrollWindowEx(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip,
1365 HRGN hrgnUpdate, PRECT pRectUpdate, UINT scrollFlag)
1366{
1367 Win32BaseWindow *window;
1368 APIRET rc;
1369 RECTL scrollRect;
1370 RECTL clipRect;
1371 ULONG scrollFlags = 0;
1372 int regionType = ERROR_W;
1373
1374 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1375 if(!window) {
1376 dprintf(("ScrollWindowEx, window %x not found", hwnd));
1377 return 0;
1378 }
1379
1380 dprintf(("ScrollWindowEx %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip));
1381
1382 dy = revertDy (window, dy);
1383
1384 if (scrollFlag & SW_INVALIDATE_W) scrollFlags |= SW_INVALIDATERGN;
1385 if (scrollFlag & SW_SCROLLCHILDREN_W) scrollFlags |= SW_SCROLLCHILDREN;
1386
1387 if(pScroll) mapWin32ToOS2Rect(window,(RECT *)pScroll, (PRECTLOS2)&scrollRect);
1388 if(pClip) mapWin32ToOS2Rect(window,(RECT *)pClip, (PRECTLOS2)&clipRect);
1389
1390 RECTL rectlUpdate;
1391 HRGN hrgn;
1392
1393 if (scrollFlag & SW_SMOOTHSCROLL_W)
1394 {
1395 INT time = (scrollFlag >> 16) & 0xFFFF;
1396
1397 //CB: todo, scroll in several steps
1398 // is time in ms? time <-> iteration count?
1399 }
1400
1401 LONG lComplexity = WinScrollWindow (window->getOS2WindowHandle(), dx, dy,
1402 (pScroll) ? &scrollRect : NULL,
1403 (pClip) ? &clipRect : NULL,
1404 hrgn, &rectlUpdate, scrollFlags);
1405 if (lComplexity == RGN_ERROR)
1406 {
1407 return ERROR_W;
1408 }
1409
1410 RECT winRectUpdate;
1411 LONG height = window->getClientHeight();
1412
1413 winRectUpdate.left = rectlUpdate.xLeft;
1414 winRectUpdate.right = rectlUpdate.xRight;
1415 winRectUpdate.top = height - rectlUpdate.yTop;
1416 winRectUpdate.bottom = height - rectlUpdate.yBottom;
1417
1418 if (pRectUpdate)
1419 *pRectUpdate = winRectUpdate;
1420
1421 if (hrgnUpdate)
1422 rc = setPMRgnIntoWinRgn (hrgn, hrgnUpdate, height);
1423
1424 if ((scrollFlag & SW_INVALIDATE_W) &&
1425 ((lComplexity == RGN_RECT) || (lComplexity == RGN_COMPLEX)))
1426 {
1427 rc = InvalidateRect (hwnd, &winRectUpdate, (scrollFlag & SW_ERASE_W) ? 1 : 0);
1428 if (rc == FALSE)
1429 {
1430 return (0);
1431 }
1432 }
1433
1434 switch (lComplexity)
1435 {
1436 case RGN_NULL:
1437 regionType = NULLREGION_W;
1438 break;
1439 case RGN_RECT:
1440 regionType = SIMPLEREGION_W;
1441 break;
1442 case RGN_COMPLEX:
1443 regionType = COMPLEXREGION_W;
1444 break;
1445 default:
1446 regionType = ERROR_W;
1447 break;
1448 }
1449
1450 return (regionType);
1451}
1452//******************************************************************************
1453//******************************************************************************
1454HWND WIN32API WindowFromDC(HDC hdc)
1455{
1456 pDCData pHps = (pDCData)GpiQueryDCData( (HPS)hdc );
1457
1458 dprintf2(("USER32: WindowFromDC %x", hdc));
1459 if ( pHps )
1460 return Win32BaseWindow::OS2ToWin32Handle(pHps->hwnd);
1461 else
1462 return 0;
1463}
1464//******************************************************************************
1465//******************************************************************************
1466INT WIN32API ExcludeUpdateRgn( HDC hDC, HWND hWnd)
1467{
1468 dprintf(("USER32: ExcludeUpdateRgn\n"));
1469 hWnd = Win32BaseWindow::Win32ToOS2Handle(hWnd);
1470
1471 return O32_ExcludeUpdateRgn(hDC,hWnd);
1472}
1473//******************************************************************************
1474//******************************************************************************
1475BOOL WIN32API ValidateRect( HWND hwnd, const RECT * lprc)
1476{
1477 if(lprc) {
1478 dprintf(("USER32: ValidateRect %x (%d,%d)(%d,%d)", hwnd, lprc->left, lprc->top, lprc->right, lprc->bottom));
1479 }
1480 else dprintf(("USER32: ValidateRect %x", hwnd));
1481
1482 return RedrawWindow( hwnd, lprc, 0, RDW_VALIDATE_W | RDW_NOCHILDREN_W | (hwnd==0 ? RDW_UPDATENOW_W : 0));
1483}
1484//******************************************************************************
1485//******************************************************************************
1486BOOL WIN32API ValidateRgn( HWND hwnd, HRGN hrgn)
1487{
1488 dprintf(("USER32: ValidateRgn %x %x", hwnd, hrgn));
1489 return RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE_W | RDW_NOCHILDREN_W | (hwnd==0 ? RDW_UPDATENOW_W : 0));
1490}
1491/*****************************************************************************
1492 * Name : int WIN32API GetWindowRgn
1493 * Purpose : The GetWindowRgn function obtains a copy of the window region of a window.
1494 * Parameters: HWND hWnd handle to window whose window region is to be obtained
1495 * HRGN hRgn handle to region that receives a copy of the window region
1496 * Variables :
1497 * Result : NULLREGION, SIMPLEREGION, COMPLEXREGION, ERROR
1498 * Remark :
1499 * Status : UNTESTED STUB
1500 *
1501 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
1502 *****************************************************************************/
1503
1504int WIN32API GetWindowRgn(HWND hwnd, HRGN hRgn)
1505{
1506 Win32BaseWindow *window;
1507 HRGN hWindowRegion;
1508
1509 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1510 if(!window) {
1511 dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
1512 O32_SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1513 return 0;
1514 }
1515 dprintf(("USER32:GetWindowRgn (%x,%x)", hwnd, hRgn));
1516 hWindowRegion = window->GetWindowRegion();
1517
1518 return O32_CombineRgn(hRgn, hWindowRegion, 0, RGN_COPY_W);
1519}
1520/*****************************************************************************
1521 * Name : int WIN32API SetWindowRgn
1522 * Purpose : The SetWindowRgn function sets the window region of a window. The
1523 * window region determines the area within the window where the
1524 * operating system permits drawing. The operating system does not
1525 * display any portion of a window that lies outside of the window region
1526 * When this function is called, the system sends the WM_WINDOWPOSCHANGING and
1527 * WM_WINDOWPOSCHANGED messages to the window.
1528 *
1529 * Parameters: HWND hWnd handle to window whose window region is to be set
1530 * HRGN hRgn handle to region
1531 * BOOL bRedraw window redraw flag
1532 * Variables :
1533 * Result : If the function succeeds, the return value is non-zero.
1534 * If the function fails, the return value is zero.
1535 * Remark :
1536 * Status : UNTESTED STUB
1537 *
1538 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
1539 *****************************************************************************/
1540
1541int WIN32API SetWindowRgn(HWND hwnd,
1542 HRGN hRgn,
1543 BOOL bRedraw)
1544{
1545 Win32BaseWindow *window;
1546 HRGN hWindowRegion;
1547
1548 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1549 if(!window) {
1550 dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
1551 O32_SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1552 return 0;
1553 }
1554 dprintf(("USER32:SetWindowRgn (%x,%x,%d)", hwnd, hRgn, bRedraw));
1555 if(window->GetWindowRegion()) {
1556 O32_DeleteObject(window->GetWindowRegion());
1557 }
1558 window->SetWindowRegion(hRgn);
1559 if(bRedraw) {
1560 RedrawWindow(hwnd, 0, 0, RDW_UPDATENOW_W);
1561 }
1562//TODO:
1563// When this function is called, the system sends the WM_WINDOWPOSCHANGING and
1564// WM_WINDOWPOSCHANGED messages to the window.
1565 return 1;
1566}
1567//******************************************************************************
1568//******************************************************************************
Note: See TracBrowser for help on using the repository browser.