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

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

SetWindowPos, UpdateWindow & WS_VISIBLE fixes/changes

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