source: trunk/src/user32/new/dc.cpp@ 2292

Last change on this file since 2292 was 2292, checked in by cbratschi, 26 years ago

* empty log message *

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