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

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

* empty log message *

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