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

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

MDI changes + WM_INITMENU support added + disabled experimental support for CS_PARENTDC style

File size: 37.1 KB
Line 
1/* $Id: dc.cpp,v 1.28 1999-12-14 19:13:18 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 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
439
440 if ((hwnd != HWND_DESKTOP) && wnd->isOwnDC())
441 {
442 hPS_ownDC = wnd->getOwnDC();
443 //SvL: Hack for memory.exe (doesn't get repainted properly otherwise)
444 if(hPS_ownDC) {
445 pHps = (pDCData)GpiQueryDCData(hPS_ownDC);
446 if (!pHps)
447 {
448 O32_SetLastError (ERROR_INVALID_PARAMETER);
449 return (HDC)NULLHANDLE;
450 }
451 }
452 }
453
454 HWND hwndClient = wnd->getOS2WindowHandle();
455 HPS hps = WinBeginPaint(hwndClient, hPS_ownDC, &rect);
456
457 if (!pHps)
458 {
459 HDC hdc = HPSToHDC (hwndClient, hps, NULL, NULL);
460 pHps = (pDCData)GpiQueryDCData(hps);
461 }
462
463 if (hPS_ownDC == 0)
464 setMapMode (wnd, pHps, MM_TEXT_W);
465 else
466 setPageXForm (wnd, pHps);
467
468 pHps->hdcType = TYPE_3;
469 lpps->hdc = (HDC)hps;
470
471// if (wnd->isEraseBkgnd())
472 wnd->setEraseBkgnd (FALSE, !wnd->MsgEraseBackGround(lpps->hdc));
473 wnd->setSupressErase (FALSE);
474 lpps->fErase = wnd->isPSErase();
475
476 if (!hPS_ownDC)
477 {
478 long height = wnd->getWindowHeight();
479 rect.yTop = height - rect.yTop;
480 rect.yBottom = height - rect.yBottom;
481 }
482 else
483 {
484 rect.yTop--;
485 rect.yBottom--;
486 GpiConvert(pHps->hps, CVTC_DEVICE, CVTC_WORLD, 2, (PPOINTL)&rect);
487 }
488
489 WINRECT_FROM_PMRECT(lpps->rcPaint, rect);
490
491 O32_SetLastError(0);
492 return (HDC)pHps->hps;
493}
494
495BOOL WIN32API EndPaint (HWND hwnd, const PAINTSTRUCT_W *pPaint)
496{
497dprintf (("USER32: EndPaint(%x)", hwnd));
498
499 if (!pPaint || !pPaint->hdc )
500 return TRUE;
501
502 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
503
504 if (!wnd) goto exit;
505
506 //SvL: Hack for memory.exe (doesn't get repainted properly otherwise)
507 if(wnd->isOwnDC() && wnd->getOwnDC())
508// if(wnd->isOwnDC())
509 {
510 pDCData pHps = (pDCData)GpiQueryDCData((HPS)pPaint->hdc);
511 if (pHps && (pHps->hdcType == TYPE_3))
512 {
513 WinEndPaint (pHps->hps);
514 }
515 }
516 else
517 {
518 O32_EndPaint (HWND_DESKTOP, pPaint);
519 }
520
521exit:
522 O32_SetLastError(0);
523 return TRUE;
524}
525
526BOOL WIN32API GetUpdateRect (HWND hwnd, LPRECT pRect, BOOL erase)
527{
528 if (hwnd)
529 {
530 O32_SetLastError (ERROR_INVALID_HANDLE);
531 return FALSE;
532 }
533
534 RECTL rectl;
535 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
536
537 BOOL updateRegionExists = WinQueryUpdateRect (hwnd, pRect ? &rectl : NULL);
538 if (!pRect) {
539 return (updateRegionExists);
540 }
541
542 if (updateRegionExists)
543 {
544 //SvL: Hack for memory.exe (doesn't get repainted properly otherwise)
545// if (wnd->isOwnDC() && wnd->getOwnDC())
546 if (wnd->isOwnDC())
547 {
548 pDCData pHps = NULL;
549 pHps = (pDCData)GpiQueryDCData(wnd->getOwnDC());
550 if (!pHps)
551 {
552 O32_SetLastError (ERROR_INVALID_HANDLE);
553 return FALSE;
554 }
555 GpiConvert (pHps->hps, CVTC_DEVICE, CVTC_WORLD, 2, (PPOINTL)&rectl);
556 }
557 else
558 {
559 long height = wnd->getWindowHeight();
560 rectl.yTop = height - rectl.yTop;
561 rectl.yBottom = height - rectl.yBottom;
562 }
563
564 if (pRect)
565 WINRECT_FROM_PMRECT (*pRect, rectl);
566
567 if (erase)
568 sendEraseBkgnd (wnd);
569 }
570 else
571 {
572 if (pRect)
573 pRect->left = pRect->top = pRect->right = pRect->bottom = 0;
574 }
575
576 return updateRegionExists;
577}
578
579int WIN32API GetUpdateRgn (HWND hwnd, HRGN hrgn, BOOL erase)
580{
581 LONG Complexity;
582
583 Complexity = O32_GetUpdateRgn (hwnd, hrgn, FALSE);
584 if (erase && (Complexity > NULLREGION_W)) {
585 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
586 sendEraseBkgnd (wnd);
587 }
588
589 return Complexity;
590}
591
592// This implementation of GetDCEx supports
593// DCX_WINDOW
594// DCX_CACHE
595// DCX_EXCLUDERGN (complex regions allowed)
596// DCX_INTERSECTRGN (complex regions allowed)
597
598HDC WIN32API GetDCEx (HWND hwnd, HRGN hrgn, ULONG flags)
599{
600 Win32BaseWindow *wnd = NULL;
601 HWND hWindow;
602 BOOL success;
603 pDCData pHps = NULL;
604 HPS hps = NULLHANDLE;
605 BOOL drawingAllowed = TRUE;
606 BOOL isWindowOwnDC;
607 BOOL creatingOwnDC = FALSE;
608 PS_Type psType;
609
610 if (hwnd)
611 {
612 wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
613 if(wnd == NULL) {
614 dprintf (("ERROR: User32: GetDCEx bad window handle %X!!!!!", hwnd));
615 O32_SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
616 return 0;
617 }
618//SvL: Experimental change (doesn't work right)
619#if 0
620 if(wnd->fHasParentDC() && wnd->getParent()) {
621 wnd = wnd->getParent();
622 }
623#endif
624 if (flags & DCX_WINDOW_W)
625 hWindow = wnd->getOS2FrameWindowHandle();
626 else
627 hWindow = wnd->getOS2WindowHandle();
628 }
629 else
630 hWindow = HWND_DESKTOP;
631
632 dprintf (("User32: GetDCEx hwnd %x (%x %x) -> wnd %x", hwnd, hrgn, flags, wnd));
633
634 //SvL: Hack for memory.exe (doesn't get repainted properly otherwise)
635// isWindowOwnDC = (((hWindow == HWND_DESKTOP) ? FALSE : (wnd->isOwnDC() && wnd->getOwnDC()))
636 isWindowOwnDC = (((hWindow == HWND_DESKTOP) ? FALSE : (wnd->isOwnDC()))
637 && !(flags & DCX_CACHE_W));
638
639 if (isWindowOwnDC)
640 {
641 hps = wnd->getOwnDC();
642 if (hps)
643 {
644 pDCData pHps = (pDCData)GpiQueryDCData (hps);
645 if (!pHps)
646 goto error;
647
648 setPageXForm (wnd, pHps);
649
650 pHps->hdcType = TYPE_1;
651 return (HDC)hps;
652 }
653 else
654 creatingOwnDC = TRUE;
655 }
656
657 if (isWindowOwnDC)
658 {
659 SIZEL sizel = {0,0};
660 hps = GpiCreatePS (WinQueryAnchorBlock (hWindow),
661 WinOpenWindowDC (hWindow),
662 &sizel, PU_PELS | GPIT_MICRO | GPIA_ASSOC );
663 psType = MICRO;
664 }
665 else
666 {
667 if (hWindow == HWND_DESKTOP)
668 hps = WinGetScreenPS (hWindow);
669 else
670 hps = WinGetPS (hWindow);
671
672 psType = MICRO_CACHED;
673 }
674
675 if (!hps)
676 goto error;
677
678 HPSToHDC (hWindow, hps, NULL, NULL);
679 pHps = (pDCData)GpiQueryDCData (hps);
680
681 if ((flags & DCX_EXCLUDERGN_W) || (flags & DCX_INTERSECTRGN_W))
682 {
683 ULONG BytesNeeded;
684 PRGNDATA_W RgnData;
685 PRECTL pr;
686 int i;
687 LONG height = OSLibQueryScreenHeight();
688
689 if (!hrgn)
690 goto error;
691
692 BytesNeeded = O32_GetRegionData (hrgn, 0, NULL);
693 RgnData = (PRGNDATA_W)_alloca (BytesNeeded);
694 if (RgnData == NULL)
695 goto error;
696 O32_GetRegionData (hrgn, BytesNeeded, RgnData);
697
698 i = RgnData->rdh.nCount;
699 pr = (PRECTL)(RgnData->Buffer);
700
701 success = TRUE;
702 if (flags & DCX_EXCLUDERGN_W)
703 for (; (i > 0) && success; i--, pr++) {
704 LONG y = pr->yBottom;
705
706 pr->yBottom = height - pr->yTop;
707 pr->yTop = height - y;
708 success &= GpiExcludeClipRectangle (pHps->hps, pr);
709 }
710 else
711 for (; (i > 0) && success; i--, pr++) {
712 LONG y = pr->yBottom;
713
714 pr->yBottom = height - pr->yTop;
715 pr->yTop = height - y;
716 success &= GpiIntersectClipRectangle (pHps->hps, pr);
717 }
718 if (!success)
719 goto error;
720 }
721
722 if (creatingOwnDC)
723 wnd->setOwnDC ((HDC)hps);
724
725 pHps->psType = psType;
726 pHps->hdcType = TYPE_1;
727 GpiSetDrawControl (hps, DCTL_DISPLAY, drawingAllowed ? DCTL_ON : DCTL_OFF);
728
729 return (HDC)pHps->hps;
730
731error:
732 /* Something went wrong; clean up
733 */
734 if (pHps)
735 {
736 if (pHps->hps)
737 {
738 if(pHps->psType == MICRO_CACHED)
739 WinReleasePS(pHps->hps);
740 else
741 GpiDestroyPS(pHps->hps);
742 }
743
744 if (pHps->hdc) DevCloseDC(pHps->hdc);
745 if (pHps->hrgnHDC) GpiDestroyRegion(pHps->hps, pHps->hrgnHDC);
746
747 O32_DeleteObject (pHps->nullBitmapHandle);
748 }
749 O32_SetLastError (ERROR_INVALID_PARAMETER);
750 return NULL;
751}
752
753HDC WIN32API GetDC (HWND hwnd)
754{
755 return GetDCEx (hwnd, NULL, 0);
756}
757
758HDC WIN32API GetWindowDC (HWND hwnd)
759{
760 return GetDCEx (hwnd, NULL, DCX_WINDOW_W);
761}
762
763int WIN32API ReleaseDC (HWND hwnd, HDC hdc)
764{
765 BOOL isOwnDC = FALSE;
766 int rc;
767
768 if (hwnd)
769 {
770 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
771 //SvL: Hack for memory.exe (doesn't get repainted properly otherwise)
772// isOwnDC = wnd->isOwnDC() && wnd->getOwnDC();
773 isOwnDC = wnd->isOwnDC();
774 }
775 if (isOwnDC)
776 rc = TRUE;
777 else
778 rc = O32_ReleaseDC (0, hdc);
779
780 dprintf(("ReleaseDC %x %x", hwnd, hdc));
781 return (rc);
782}
783
784BOOL WIN32API UpdateWindow (HWND hwnd)
785{
786 if (!hwnd)
787 return FALSE;
788
789 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
790
791 dprintf (("User32: UpdateWindow hwnd %x -> wnd %x", hwnd, wnd));
792
793#if 0
794 if (WinQueryUpdateRect (wnd->getOS2WindowHandle(), NULL))
795 sendEraseBkgnd (wnd);
796#endif
797
798#if 1
799 WinUpdateWindow(wnd->getOS2FrameWindowHandle());
800#else
801 wnd->MsgPaint(0);
802#endif
803
804 return (TRUE);
805}
806
807// This implementation of RedrawWindow supports
808// RDW_ERASE
809// RDW_NOERASE
810// RDW_INTERNALPAINT
811// RDW_NOINTERNALPAINT
812// RDW_INVALIDATE
813// RDW_VALIDATE
814// RDW_ERASENOW
815// RDW_UPDATENOW
816
817BOOL WIN32API RedrawWindow(HWND hwnd, const RECT* pRect, HRGN hrgn, DWORD redraw)
818{
819 Win32BaseWindow *wnd;
820
821 if (redraw & (RDW_FRAME_W | RDW_NOFRAME_W))
822 {
823 O32_SetLastError (ERROR_NOT_SUPPORTED);
824 return FALSE;
825 }
826
827 if (hwnd == NULLHANDLE)
828 {
829#if 1
830 // Don't do this for now (causes lots of desktop repaints in WordPad)
831 O32_SetLastError (ERROR_INVALID_PARAMETER);
832 return FALSE;
833#else
834 hwnd = HWND_DESKTOP;
835 wnd = Win32BaseWindow::GetWindowFromOS2Handle(OSLIB_HWND_DESKTOP);
836
837 if (!wnd)
838 {
839 dprintf(("USER32:dc: RedrawWindow can't find desktop window %08xh\n",
840 hwnd));
841 O32_SetLastError (ERROR_INVALID_PARAMETER);
842 return FALSE;
843 }
844#endif
845 }
846 else
847 {
848 wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
849
850 if (!wnd)
851 {
852 dprintf(("USER32:dc: RedrawWindow can't find window %08xh\n",
853 hwnd));
854 O32_SetLastError (ERROR_INVALID_PARAMETER);
855 return FALSE;
856 }
857 hwnd = wnd->getOS2WindowHandle();
858 }
859
860 BOOL IncludeChildren = redraw & RDW_ALLCHILDREN_W ? TRUE : FALSE;
861 BOOL success = TRUE;
862 HPS hpsTemp = NULLHANDLE;
863 HRGN hrgnTemp = NULLHANDLE;
864 RECTL rectl;
865
866 if (redraw & RDW_UPDATENOW_W) redraw &= ~RDW_ERASENOW_W;
867
868 if (redraw & RDW_NOERASE_W)
869 wnd->setEraseBkgnd (FALSE);
870
871 if (redraw & RDW_UPDATENOW_W)
872 wnd->setSupressErase (FALSE);
873 else if (redraw & RDW_ERASENOW_W)
874 wnd->setSupressErase (FALSE);
875#if 0
876 else
877 {
878 QMSG qmsg;
879 BOOL erase;
880
881 erase = (WinPeekMsg (HABX, &qmsg, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE)
882 && (redraw & RDW_NOERASE_W) == 0);
883
884 wnd->setSupressErase (!erase);
885 }
886
887 if (redraw & (RDW_NOINTERNALPAINT_W | RDW_INTERNALPAINT_W))
888 {
889 QMSG qmsg;
890
891 WinPeekMsg( (HAB)0, &qmsg, hwnd, WM_VIRTUAL_INTERNALPAINT,
892 WM_VIRTUAL_INTERNALPAINT, PM_REMOVE );
893 }
894#endif
895
896 if (hrgn)
897 {
898 ULONG BytesNeeded;
899 PRGNDATA_W RgnData;
900 PRECTL pr;
901 int i;
902 LONG height = wnd ? wnd->getWindowHeight() : OSLibQueryScreenHeight();
903
904 if (!hrgn)
905 goto error;
906
907 BytesNeeded = O32_GetRegionData (hrgn, 0, NULL);
908 RgnData = (PRGNDATA_W)_alloca (BytesNeeded);
909 if (RgnData == NULL)
910 goto error;
911 O32_GetRegionData (hrgn, BytesNeeded, RgnData);
912
913 pr = (PRECTL)(RgnData->Buffer);
914 for (i = RgnData->rdh.nCount; i > 0; i--, pr++) {
915 LONG temp = pr->yTop;
916 pr->yTop = height - pr->yBottom;
917 pr->yBottom = height - temp;
918 }
919
920 hpsTemp = WinGetScreenPS (HWND_DESKTOP);
921 hrgnTemp = GpiCreateRegion (hpsTemp, RgnData->rdh.nCount, (PRECTL)(RgnData->Buffer));
922 if (!hrgnTemp) goto error;
923 }
924 else if (pRect)
925 {
926 LONG height = wnd ? wnd->getWindowHeight() : OSLibQueryScreenHeight();
927
928 PMRECT_FROM_WINRECT (rectl, *pRect);
929 rectl.yTop = height - rectl.yTop;
930 rectl.yBottom = height - rectl.yBottom;
931 }
932
933 if (redraw & RDW_INVALIDATE_W)
934 {
935 if (redraw & RDW_ERASE_W)
936 wnd->setEraseBkgnd (TRUE, TRUE);
937
938 if (!pRect && !hrgn)
939 success = WinInvalidateRect (hwnd, NULL, IncludeChildren);
940 else if (hrgn)
941 success = WinInvalidateRegion (hwnd, hrgnTemp, IncludeChildren);
942 else
943 success = WinInvalidateRect (hwnd, &rectl, IncludeChildren);
944 if (!success) goto error;
945 }
946 else if (redraw & RDW_VALIDATE_W)
947 {
948 if (WinQueryUpdateRect (hwnd, NULL))
949 {
950 if (!pRect && !hrgn)
951 success = WinValidateRect (hwnd, NULL, IncludeChildren);
952 else if (hrgn)
953 success = WinValidateRegion (hwnd, hrgnTemp, IncludeChildren);
954 else
955 success = WinValidateRect (hwnd, &rectl, IncludeChildren);
956 if (!success) goto error;
957 }
958 }
959
960 if (WinQueryUpdateRect (hwnd, NULL))
961 {
962 if (redraw & RDW_UPDATENOW_W)
963 wnd->MsgPaint (0, FALSE);
964
965 else if ((redraw & RDW_ERASE_W) && (redraw & RDW_ERASENOW_W))
966 wnd->setEraseBkgnd (FALSE, !sendEraseBkgnd (wnd));
967 }
968 else if ((redraw & RDW_INTERNALPAINT_W) && !(redraw & RDW_INVALIDATE_W))
969 {
970 if (redraw & RDW_UPDATENOW_W)
971 wnd->MsgPaint (0, FALSE);
972// else
973// WinPostMsg( hwnd, WM_VIRTUAL_INTERNALPAINT, MPVOID, MPVOID );
974 }
975
976error:
977 /* clean up */
978 if (hrgnTemp)
979 GpiDestroyRegion (hpsTemp, hrgnTemp);
980
981 if (hpsTemp)
982 WinReleasePS (hpsTemp);
983
984 if ((redraw & RDW_INVALIDATE_W) == 0)
985 wnd->setSupressErase (FALSE);
986 else if ((redraw & RDW_ERASENOW_W) == RDW_ERASENOW_W)
987 wnd->setSupressErase (TRUE);
988
989 if (!success)
990 O32_SetLastError (ERROR_INVALID_PARAMETER);
991
992 return (success);
993}
994
995BOOL WIN32API InvalidateRect (HWND hwnd, const RECT *pRect, BOOL erase)
996{
997// Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
998 BOOL result;
999
1000// todo !!
1001// if ( isFrame without client )
1002// erase = TRUE;
1003
1004 result = RedrawWindow (hwnd, pRect, NULLHANDLE,
1005 RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
1006 (erase ? RDW_ERASE_W : 0) |
1007 (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
1008 return (result);
1009}
1010
1011BOOL WIN32API InvalidateRgn (HWND hwnd, HRGN hrgn, BOOL erase)
1012{
1013// Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
1014 BOOL result;
1015
1016// todo !!
1017// if ( isFrame without client )
1018// erase = TRUE;
1019
1020 result = RedrawWindow (hwnd, NULL, hrgn,
1021 RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
1022 (erase ? RDW_ERASE_W : 0) |
1023 (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
1024 return (result);
1025}
1026
1027BOOL setPMRgnIntoWinRgn (HRGN hrgnPM, HRGN hrgnWin, LONG height)
1028{
1029 BOOL rc;
1030 HPS hps = WinGetScreenPS (HWND_DESKTOP);
1031 RGNRECT rgnRect;
1032 rgnRect.ircStart = 1;
1033 rgnRect.crc = 0;
1034 rgnRect.ulDirection = RECTDIR_LFRT_TOPBOT; // doesn't make a difference because we're getting them all
1035
1036 rc = GpiQueryRegionRects (hps, hrgnPM, NULL, &rgnRect, NULL);
1037
1038 if (rc && (rgnRect.crcReturned > 0))
1039 {
1040 PRECTL Rcls = new RECTL[rgnRect.crcReturned];
1041 PRECTL pRcl = Rcls;
1042
1043 if (Rcls != NULL)
1044 {
1045 rgnRect.crc = rgnRect.crcReturned;
1046 rc = GpiQueryRegionRects (hps, hrgnPM, NULL, &rgnRect, Rcls);
1047
1048 rc = O32_SetRectRgn (hrgnWin, pRcl->xLeft,
1049 pRcl->xRight,
1050 height - pRcl->yTop,
1051 height - pRcl->yBottom);
1052
1053 if (rgnRect.crcReturned > 1)
1054 {
1055 int i;
1056 HRGN temp;
1057 temp = O32_CreateRectRgn (0, 0, 1, 1);
1058
1059 for (i = 1, pRcl++; rc && (i < rgnRect.crcReturned); i++, pRcl++)
1060 {
1061 rc = O32_SetRectRgn (temp, pRcl->xLeft,
1062 pRcl->xRight,
1063 height - pRcl->yTop,
1064 height - pRcl->yBottom);
1065 rc &= O32_CombineRgn (hrgnWin, hrgnWin, temp, RGN_OR_W);
1066 }
1067 O32_DeleteObject (temp);
1068 }
1069 delete[] Rcls;
1070 }
1071 else
1072 {
1073 rc = FALSE;
1074 }
1075 }
1076 else
1077 {
1078 rc = O32_SetRectRgn (hrgnWin, 0, 0, 0, 0);
1079 }
1080
1081 WinReleasePS (hps);
1082 return (rc);
1083}
1084
1085BOOL WIN32API ScrollDC (HDC hDC, int dx, int dy, const RECT *pScroll,
1086 const RECT *pClip, HRGN hrgnUpdate, LPRECT pRectUpdate)
1087{
1088 BOOL rc = TRUE;
1089
1090 dprintf (("USER32: ScrollDC"));
1091
1092 if (!hDC)
1093 {
1094 return (FALSE);
1095 }
1096
1097 pDCData pHps = (pDCData)GpiQueryDCData ((HPS)hDC);
1098 HWND hwnd = pHps->hwnd;
1099 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
1100
1101 if ((hwnd == NULLHANDLE) || !wnd)
1102 {
1103 return (FALSE);
1104 }
1105
1106 POINTL ptl[2] = { 0, 0, dx, dy };
1107
1108 GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, ptl);
1109 dx = (int)(ptl[1].x - ptl[0].x);
1110 dy = (int)(ptl[1].y - ptl[0].y);
1111
1112 RECTL scrollRect;
1113 RECTL clipRect;
1114
1115 if (pClip)
1116 {
1117 clipRect.xLeft = min (pClip->left, pClip->right);
1118 clipRect.xRight = max (pClip->left, pClip->right);
1119 clipRect.yTop = max (pClip->top, pClip->bottom);
1120 clipRect.yBottom = min (pClip->top, pClip->bottom);
1121
1122 if ((pHps->graphicsMode == GM_COMPATIBLE_W) &&
1123 (clipRect.xLeft != clipRect.xRight) &&
1124 (clipRect.yBottom != clipRect.yTop))
1125 {
1126 if (abs((int)pHps->viewportXExt) <= abs((int)pHps->windowExt.cx))
1127 clipRect.xRight -= abs(pHps->worldXDeltaFor1Pixel);
1128 else
1129 clipRect.xLeft += abs(pHps->worldXDeltaFor1Pixel);
1130
1131 if (abs((int)pHps->viewportYExt) <= abs((int)pHps->windowExt.cy))
1132 clipRect.yTop -= abs(pHps->worldYDeltaFor1Pixel);
1133 else
1134 clipRect.yBottom += abs(pHps->worldYDeltaFor1Pixel);
1135 }
1136 GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, (PPOINTL)&clipRect);
1137 if (clipRect.xRight < clipRect.xLeft) {
1138 ULONG temp = clipRect.xLeft;
1139 clipRect.xLeft = clipRect.xRight;
1140 clipRect.xRight = temp;
1141 }
1142 if (clipRect.yTop < clipRect.yBottom) {
1143 ULONG temp = clipRect.yBottom;
1144 clipRect.yBottom = clipRect.yTop;
1145 clipRect.yTop = temp;
1146 }
1147 }
1148
1149 if (pScroll)
1150 {
1151 scrollRect.xLeft = min (pScroll->left, pScroll->right);
1152 scrollRect.xRight = max (pScroll->left, pScroll->right);
1153 scrollRect.yTop = max (pScroll->top, pScroll->bottom);
1154 scrollRect.yBottom = min (pScroll->top, pScroll->bottom);
1155
1156 if ((pHps->graphicsMode == GM_COMPATIBLE_W) &&
1157 (scrollRect.xLeft != scrollRect.xRight) &&
1158 (scrollRect.yBottom != scrollRect.yTop))
1159 {
1160 if (abs((int)pHps->viewportXExt) <= abs((int)pHps->windowExt.cx))
1161 scrollRect.xRight -= abs(pHps->worldXDeltaFor1Pixel);
1162 else
1163 scrollRect.xLeft += abs(pHps->worldXDeltaFor1Pixel);
1164
1165 if (abs((int)pHps->viewportYExt) <= abs((int)pHps->windowExt.cy))
1166 scrollRect.yTop -= abs(pHps->worldYDeltaFor1Pixel);
1167 else
1168 scrollRect.yBottom += abs(pHps->worldYDeltaFor1Pixel);
1169 }
1170 GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, (PPOINTL)&scrollRect);
1171 if (scrollRect.xRight < scrollRect.xLeft) {
1172 ULONG temp = scrollRect.xLeft;
1173 scrollRect.xLeft = scrollRect.xRight;
1174 scrollRect.xRight = temp;
1175 }
1176 if (scrollRect.yTop < scrollRect.yBottom) {
1177 ULONG temp = scrollRect.yBottom;
1178 scrollRect.yBottom = scrollRect.yTop;
1179 scrollRect.yTop = temp;
1180 }
1181 }
1182 RECTL rectlUpdate;
1183 HRGN hrgn;
1184
1185 LONG lComplexity = WinScrollWindow (hwnd, dx, dy, (pScroll) ? &scrollRect : NULL, (pClip) ? &clipRect : NULL, hrgn, &rectlUpdate, 0);
1186 if (lComplexity == RGN_ERROR)
1187 {
1188 return (FALSE);
1189 }
1190
1191 RECT winRectUpdate;
1192 LONG height = wnd->getWindowHeight();
1193
1194 winRectUpdate.left = rectlUpdate.xLeft;
1195 winRectUpdate.right = rectlUpdate.xRight;
1196 winRectUpdate.top = height - rectlUpdate.yTop;
1197 winRectUpdate.bottom = height - rectlUpdate.yBottom;
1198
1199 if (pRectUpdate)
1200 *pRectUpdate = winRectUpdate;
1201
1202 if (hrgnUpdate)
1203 rc = setPMRgnIntoWinRgn (hrgn, hrgnUpdate, height);
1204
1205 return (rc);
1206}
1207
1208//******************************************************************************
1209//******************************************************************************
1210BOOL WIN32API ScrollWindow(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip)
1211{
1212 Win32BaseWindow *window;
1213 APIRET rc;
1214 RECTL clientRect;
1215 RECTL scrollRect;
1216 RECTL clipRect;
1217 PRECTL pScrollRect = NULL;
1218 PRECTL pClipRect = NULL;
1219 ULONG scrollFlags = SW_INVALIDATERGN;
1220
1221 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1222 if(!window) {
1223 dprintf(("ScrollWindow, window %x not found", hwnd));
1224 return 0;
1225 }
1226 dprintf(("ScrollWindow %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip));
1227 MapWin32ToOS2Rectl(window->getOS2WindowHandle(),window->getClientRect(), (PRECTLOS2)&clientRect);
1228 //Rectangle could be relative to parent window, so fix this
1229 if(clientRect.yBottom != 0) {
1230 clientRect.yTop -= clientRect.yBottom;
1231 clientRect.yBottom = 0;
1232 }
1233 if(clientRect.xLeft != 0) {
1234 clientRect.xRight -= clientRect.xLeft;
1235 clientRect.xLeft = 0;
1236 }
1237 if(pScroll) {
1238 MapWin32ToOS2Rectl(window->getOS2WindowHandle(),(RECT *)pScroll, (PRECTLOS2)&scrollRect);
1239 pScrollRect = &scrollRect;
1240
1241 //Scroll rectangle relative to client area
1242 pScrollRect->xLeft += clientRect.xLeft;
1243 pScrollRect->xRight += clientRect.xLeft;
1244 pScrollRect->yTop += clientRect.yBottom;
1245 pScrollRect->yBottom += clientRect.yBottom;
1246 WinIntersectRect ((HAB) 0, pScrollRect, pScrollRect, &clientRect);
1247 }
1248 else scrollFlags |= SW_SCROLLCHILDREN;
1249
1250 if(pClip) {
1251 MapWin32ToOS2Rectl(window->getOS2WindowHandle(),(RECT *)pClip, (PRECTLOS2)&clipRect);
1252 pClipRect = &clipRect;
1253
1254 //Clip rectangle relative to client area
1255 pClipRect->xLeft += clientRect.xLeft;
1256 pClipRect->xRight += clientRect.xLeft;
1257 pClipRect->yTop += clientRect.yBottom;
1258 pClipRect->yBottom += clientRect.yBottom;
1259 WinIntersectRect ((HAB) 0, pClipRect, pClipRect, &clientRect);
1260 }
1261
1262 dy = revertDy (window, dy);
1263
1264 rc = WinScrollWindow(window->getOS2WindowHandle(), dx, dy,
1265 pScrollRect, pClipRect, NULLHANDLE,
1266 NULL, scrollFlags);
1267
1268 return (rc != RGN_ERROR);
1269}
1270//******************************************************************************
1271//******************************************************************************
1272INT WIN32API ScrollWindowEx(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip,
1273 HRGN hrgnUpdate, PRECT pRectUpdate, UINT scrollFlag)
1274{
1275 Win32BaseWindow *window;
1276 APIRET rc;
1277 RECTL scrollRect;
1278 RECTL clipRect;
1279 ULONG scrollFlags = 0;
1280 int regionType = ERROR_W;
1281
1282 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1283 if(!window) {
1284 dprintf(("ScrollWindowEx, window %x not found", hwnd));
1285 return 0;
1286 }
1287
1288 dprintf(("ScrollWindowEx %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip));
1289
1290 dy = revertDy (window, dy);
1291
1292 if (scrollFlag & SW_INVALIDATE_W) scrollFlags |= SW_INVALIDATERGN;
1293 if (scrollFlag & SW_SCROLLCHILDREN_W) scrollFlags |= SW_SCROLLCHILDREN;
1294
1295 if(pScroll) MapWin32ToOS2Rectl(window->getOS2WindowHandle(),(RECT *)pScroll, (PRECTLOS2)&scrollRect);
1296 if(pClip) MapWin32ToOS2Rectl(window->getOS2WindowHandle(),(RECT *)pClip, (PRECTLOS2)&clipRect);
1297
1298 RECTL rectlUpdate;
1299 HRGN hrgn;
1300
1301 if (scrollFlag & SW_SMOOTHSCROLL_W)
1302 {
1303 INT time = (scrollFlag >> 16) & 0xFFFF;
1304
1305 //CB: todo, scroll in several steps
1306 // is time in ms? time <-> iteration count?
1307 }
1308
1309 LONG lComplexity = WinScrollWindow (window->getOS2WindowHandle(), dx, dy,
1310 (pScroll) ? &scrollRect : NULL,
1311 (pClip) ? &clipRect : NULL,
1312 hrgn, &rectlUpdate, scrollFlags);
1313 if (lComplexity == RGN_ERROR)
1314 {
1315 return (0);
1316 }
1317
1318 RECT winRectUpdate;
1319 LONG height = window->getWindowHeight();
1320
1321 winRectUpdate.left = rectlUpdate.xLeft;
1322 winRectUpdate.right = rectlUpdate.xRight;
1323 winRectUpdate.top = height - rectlUpdate.yTop;
1324 winRectUpdate.bottom = height - rectlUpdate.yBottom;
1325
1326 if (pRectUpdate)
1327 *pRectUpdate = winRectUpdate;
1328
1329 if (hrgnUpdate)
1330 rc = setPMRgnIntoWinRgn (hrgn, hrgnUpdate, height);
1331
1332 if ((scrollFlag & SW_INVALIDATE_W) &&
1333 ((lComplexity == RGN_RECT) || (lComplexity == RGN_COMPLEX)))
1334 {
1335 rc = InvalidateRect (hwnd, &winRectUpdate, scrollFlag & SW_ERASE_W);
1336 if (rc == FALSE)
1337 {
1338 return (0);
1339 }
1340 }
1341
1342 switch (lComplexity)
1343 {
1344 case RGN_NULL:
1345 regionType = NULLREGION_W;
1346 break;
1347 case RGN_RECT:
1348 regionType = SIMPLEREGION_W;
1349 break;
1350 case RGN_COMPLEX:
1351 regionType = COMPLEXREGION_W;
1352 break;
1353 default:
1354 regionType = ERROR_W;
1355 break;
1356 }
1357
1358 return (regionType);
1359}
1360//******************************************************************************
1361//******************************************************************************
1362HWND WIN32API WindowFromDC(HDC hdc)
1363{
1364 pDCData pHps = (pDCData)GpiQueryDCData( (HPS)hdc );
1365
1366 dprintf2(("USER32: WindowFromDC %x", hdc));
1367 if ( pHps )
1368 return Win32BaseWindow::OS2ToWin32Handle(pHps->hwnd);
1369 else
1370 return 0;
1371}
1372//******************************************************************************
1373//******************************************************************************
1374INT WIN32API ExcludeUpdateRgn( HDC hDC, HWND hWnd)
1375{
1376 dprintf(("USER32: ExcludeUpdateRgn\n"));
1377 hWnd = Win32BaseWindow::Win32ToOS2Handle(hWnd);
1378
1379 return O32_ExcludeUpdateRgn(hDC,hWnd);
1380}
1381//******************************************************************************
1382//******************************************************************************
Note: See TracBrowser for help on using the repository browser.