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

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

some fixes

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