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

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

Call DrawTextA in uitools.cpp, not Open32's DrawText.

File size: 47.2 KB
Line 
1/* $Id: dc.cpp,v 1.39 2000-01-29 14:23:32 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 if (!hwnd)
850 return FALSE;
851
852 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
853
854 dprintf (("User32: UpdateWindow hwnd %x -> wnd %x", hwnd, wnd));
855
856#if 0
857 if (WinQueryUpdateRect (wnd->getOS2WindowHandle(), NULL))
858 sendEraseBkgnd (wnd);
859#endif
860
861 WinUpdateWindow(wnd->getOS2FrameWindowHandle());
862
863 return (TRUE);
864}
865//******************************************************************************
866// This implementation of RedrawWindow supports
867// RDW_ERASE
868// RDW_NOERASE
869// RDW_INTERNALPAINT
870// RDW_NOINTERNALPAINT
871// RDW_INVALIDATE
872// RDW_VALIDATE
873// RDW_ERASENOW
874// RDW_UPDATENOW
875//******************************************************************************
876BOOL WIN32API RedrawWindow(HWND hwnd, const RECT* pRect, HRGN hrgn, DWORD redraw)
877{
878 Win32BaseWindow *wnd;
879
880 if (redraw & (RDW_FRAME_W | RDW_NOFRAME_W))
881 {
882 O32_SetLastError (ERROR_NOT_SUPPORTED);
883 return FALSE;
884 }
885
886 if (hwnd == NULLHANDLE)
887 {
888#if 1
889 // Don't do this for now (causes lots of desktop repaints in WordPad)
890 O32_SetLastError (ERROR_INVALID_PARAMETER);
891 return FALSE;
892#else
893 hwnd = HWND_DESKTOP;
894 wnd = Win32BaseWindow::GetWindowFromOS2Handle(OSLIB_HWND_DESKTOP);
895
896 if (!wnd)
897 {
898 dprintf(("USER32:dc: RedrawWindow can't find desktop window %08xh\n",
899 hwnd));
900 O32_SetLastError (ERROR_INVALID_PARAMETER);
901 return FALSE;
902 }
903#endif
904 }
905 else
906 {
907 wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
908
909 if (!wnd)
910 {
911 dprintf(("USER32:dc: RedrawWindow can't find window %08xh\n",
912 hwnd));
913 O32_SetLastError (ERROR_INVALID_PARAMETER);
914 return FALSE;
915 }
916 hwnd = wnd->getOS2WindowHandle();
917 }
918
919 BOOL IncludeChildren = redraw & RDW_ALLCHILDREN_W ? TRUE : FALSE;
920 BOOL success = TRUE;
921 HPS hpsTemp = NULLHANDLE;
922 HRGN hrgnTemp = NULLHANDLE;
923 RECTL rectl;
924
925 if (redraw & RDW_UPDATENOW_W) redraw &= ~RDW_ERASENOW_W;
926
927 if (redraw & RDW_NOERASE_W)
928 wnd->setEraseBkgnd (FALSE);
929
930//SvL: Test
931// if (redraw & RDW_UPDATENOW_W)
932// wnd->setSuppressErase (FALSE);
933// else if (redraw & RDW_ERASENOW_W)
934// wnd->setSuppressErase (FALSE);
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//******************************************************************************
1036//******************************************************************************
1037BOOL WIN32API InvalidateRect (HWND hwnd, const RECT *pRect, BOOL erase)
1038{
1039 BOOL result;
1040
1041 result = RedrawWindow (hwnd, pRect, NULLHANDLE,
1042 RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
1043 (erase ? RDW_ERASE_W : 0) |
1044 (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
1045 return (result);
1046}
1047//******************************************************************************
1048//******************************************************************************
1049BOOL WIN32API InvalidateRgn (HWND hwnd, HRGN hrgn, BOOL erase)
1050{
1051 BOOL result;
1052
1053 result = RedrawWindow (hwnd, NULL, hrgn,
1054 RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
1055 (erase ? RDW_ERASE_W : 0) |
1056 (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
1057 return (result);
1058}
1059//******************************************************************************
1060//******************************************************************************
1061BOOL setPMRgnIntoWinRgn (HRGN hrgnPM, HRGN hrgnWin, LONG height)
1062{
1063 BOOL rc;
1064 HPS hps = WinGetScreenPS (HWND_DESKTOP);
1065 RGNRECT rgnRect;
1066 rgnRect.ircStart = 1;
1067 rgnRect.crc = 0;
1068 rgnRect.ulDirection = RECTDIR_LFRT_TOPBOT; // doesn't make a difference because we're getting them all
1069
1070 rc = GpiQueryRegionRects (hps, hrgnPM, NULL, &rgnRect, NULL);
1071
1072 if (rc && (rgnRect.crcReturned > 0))
1073 {
1074 PRECTL Rcls = new RECTL[rgnRect.crcReturned];
1075 PRECTL pRcl = Rcls;
1076
1077 if (Rcls != NULL)
1078 {
1079 rgnRect.crc = rgnRect.crcReturned;
1080 rc = GpiQueryRegionRects (hps, hrgnPM, NULL, &rgnRect, Rcls);
1081
1082 rc = O32_SetRectRgn (hrgnWin, pRcl->xLeft,
1083 pRcl->xRight,
1084 height - pRcl->yTop,
1085 height - pRcl->yBottom);
1086
1087 if (rgnRect.crcReturned > 1)
1088 {
1089 int i;
1090 HRGN temp;
1091 temp = O32_CreateRectRgn (0, 0, 1, 1);
1092
1093 for (i = 1, pRcl++; rc && (i < rgnRect.crcReturned); i++, pRcl++)
1094 {
1095 rc = O32_SetRectRgn (temp, pRcl->xLeft,
1096 pRcl->xRight,
1097 height - pRcl->yTop,
1098 height - pRcl->yBottom);
1099 rc &= O32_CombineRgn (hrgnWin, hrgnWin, temp, RGN_OR_W);
1100 }
1101 O32_DeleteObject (temp);
1102 }
1103 delete[] Rcls;
1104 }
1105 else
1106 {
1107 rc = FALSE;
1108 }
1109 }
1110 else
1111 {
1112 rc = O32_SetRectRgn (hrgnWin, 0, 0, 0, 0);
1113 }
1114
1115 WinReleasePS (hps);
1116 return (rc);
1117}
1118//******************************************************************************
1119//******************************************************************************
1120BOOL WIN32API ScrollDC (HDC hDC, int dx, int dy, const RECT *pScroll,
1121 const RECT *pClip, HRGN hrgnUpdate, LPRECT pRectUpdate)
1122{
1123 BOOL rc = TRUE;
1124
1125 dprintf (("USER32: ScrollDC"));
1126
1127 if (!hDC)
1128 {
1129 return (FALSE);
1130 }
1131
1132 pDCData pHps = (pDCData)GpiQueryDCData ((HPS)hDC);
1133 HWND hwnd = pHps->hwnd;
1134 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
1135
1136 if ((hwnd == NULLHANDLE) || !wnd)
1137 {
1138 return (FALSE);
1139 }
1140
1141 POINTL ptl[2] = { 0, 0, dx, dy };
1142
1143 GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, ptl);
1144 dx = (int)(ptl[1].x - ptl[0].x);
1145 dy = (int)(ptl[1].y - ptl[0].y);
1146
1147 RECTL scrollRect;
1148 RECTL clipRect;
1149
1150 if (pClip)
1151 {
1152 clipRect.xLeft = min (pClip->left, pClip->right);
1153 clipRect.xRight = max (pClip->left, pClip->right);
1154 clipRect.yTop = max (pClip->top, pClip->bottom);
1155 clipRect.yBottom = min (pClip->top, pClip->bottom);
1156
1157 if ((pHps->graphicsMode == GM_COMPATIBLE_W) &&
1158 (clipRect.xLeft != clipRect.xRight) &&
1159 (clipRect.yBottom != clipRect.yTop))
1160 {
1161 if (abs((int)pHps->viewportXExt) <= abs((int)pHps->windowExt.cx))
1162 clipRect.xRight -= abs(pHps->worldXDeltaFor1Pixel);
1163 else
1164 clipRect.xLeft += abs(pHps->worldXDeltaFor1Pixel);
1165
1166 if (abs((int)pHps->viewportYExt) <= abs((int)pHps->windowExt.cy))
1167 clipRect.yTop -= abs(pHps->worldYDeltaFor1Pixel);
1168 else
1169 clipRect.yBottom += abs(pHps->worldYDeltaFor1Pixel);
1170 }
1171 GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, (PPOINTL)&clipRect);
1172 if (clipRect.xRight < clipRect.xLeft) {
1173 ULONG temp = clipRect.xLeft;
1174 clipRect.xLeft = clipRect.xRight;
1175 clipRect.xRight = temp;
1176 }
1177 if (clipRect.yTop < clipRect.yBottom) {
1178 ULONG temp = clipRect.yBottom;
1179 clipRect.yBottom = clipRect.yTop;
1180 clipRect.yTop = temp;
1181 }
1182 }
1183
1184 if (pScroll)
1185 {
1186 scrollRect.xLeft = min (pScroll->left, pScroll->right);
1187 scrollRect.xRight = max (pScroll->left, pScroll->right);
1188 scrollRect.yTop = max (pScroll->top, pScroll->bottom);
1189 scrollRect.yBottom = min (pScroll->top, pScroll->bottom);
1190
1191 if ((pHps->graphicsMode == GM_COMPATIBLE_W) &&
1192 (scrollRect.xLeft != scrollRect.xRight) &&
1193 (scrollRect.yBottom != scrollRect.yTop))
1194 {
1195 if (abs((int)pHps->viewportXExt) <= abs((int)pHps->windowExt.cx))
1196 scrollRect.xRight -= abs(pHps->worldXDeltaFor1Pixel);
1197 else
1198 scrollRect.xLeft += abs(pHps->worldXDeltaFor1Pixel);
1199
1200 if (abs((int)pHps->viewportYExt) <= abs((int)pHps->windowExt.cy))
1201 scrollRect.yTop -= abs(pHps->worldYDeltaFor1Pixel);
1202 else
1203 scrollRect.yBottom += abs(pHps->worldYDeltaFor1Pixel);
1204 }
1205 GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, (PPOINTL)&scrollRect);
1206 if (scrollRect.xRight < scrollRect.xLeft) {
1207 ULONG temp = scrollRect.xLeft;
1208 scrollRect.xLeft = scrollRect.xRight;
1209 scrollRect.xRight = temp;
1210 }
1211 if (scrollRect.yTop < scrollRect.yBottom) {
1212 ULONG temp = scrollRect.yBottom;
1213 scrollRect.yBottom = scrollRect.yTop;
1214 scrollRect.yTop = temp;
1215 }
1216 }
1217 RECTL rectlUpdate;
1218 HRGN hrgn;
1219
1220 LONG lComplexity = WinScrollWindow (hwnd, dx, dy, (pScroll) ? &scrollRect : NULL, (pClip) ? &clipRect : NULL, hrgn, &rectlUpdate, 0);
1221 if (lComplexity == RGN_ERROR)
1222 {
1223 return (FALSE);
1224 }
1225
1226 RECT winRectUpdate;
1227 LONG height = wnd->getClientHeight();
1228
1229 winRectUpdate.left = rectlUpdate.xLeft;
1230 winRectUpdate.right = rectlUpdate.xRight;
1231 winRectUpdate.top = height - rectlUpdate.yTop;
1232 winRectUpdate.bottom = height - rectlUpdate.yBottom;
1233
1234 if (pRectUpdate)
1235 *pRectUpdate = winRectUpdate;
1236
1237 if (hrgnUpdate)
1238 rc = setPMRgnIntoWinRgn (hrgn, hrgnUpdate, height);
1239
1240 return (rc);
1241}
1242//******************************************************************************
1243//******************************************************************************
1244#if 1
1245BOOL WIN32API ScrollWindow(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip)
1246{
1247 Win32BaseWindow *window;
1248 APIRET rc;
1249 RECTL clientRect;
1250 PRECT pClientRect;
1251 RECTL scrollRect;
1252 RECTL clipRect;
1253 PRECTL pScrollRect = NULL;
1254 PRECTL pClipRect = NULL;
1255 ULONG scrollFlags = SW_INVALIDATERGN;
1256
1257 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1258 if(!window) {
1259 dprintf(("ScrollWindow, window %x not found", hwnd));
1260 return 0;
1261 }
1262 dprintf(("ScrollWindow %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip));
1263
1264 pClientRect = window->getClientRectPtr();
1265 clientRect.xLeft = 0;
1266 clientRect.yBottom = 0;
1267 clientRect.xRight = pClientRect->right - pClientRect->left;
1268 clientRect.yTop = pClientRect->bottom - pClientRect->top;
1269
1270 if(pScroll) {
1271 mapWin32ToOS2Rect(window,(RECT *)pScroll, (PRECTLOS2)&scrollRect);
1272 pScrollRect = &scrollRect;
1273
1274 //Scroll rectangle relative to client area
1275 WinIntersectRect ((HAB) 0, pScrollRect, pScrollRect, &clientRect);
1276 }
1277 else scrollFlags |= SW_SCROLLCHILDREN;
1278
1279 if(pClip) {
1280 mapWin32ToOS2Rect(window,(RECT *)pClip, (PRECTLOS2)&clipRect);
1281 pClipRect = &clipRect;
1282
1283 //Clip rectangle relative to client area
1284 WinIntersectRect ((HAB) 0, pClipRect, pClipRect, &clientRect);
1285 }
1286
1287 dy = revertDy (window, dy);
1288
1289 rc = WinScrollWindow(window->getOS2WindowHandle(), dx, dy,
1290 pScrollRect, pClipRect, NULLHANDLE,
1291 NULL, scrollFlags);
1292
1293 return (rc != RGN_ERROR);
1294}
1295#else
1296BOOL WIN32API ScrollWindow(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip)
1297{
1298 Win32BaseWindow *window;
1299 APIRET rc;
1300 RECTL clientRect;
1301 RECTL scrollRect;
1302 RECTL clipRect;
1303 PRECTL pScrollRect = NULL;
1304 PRECTL pClipRect = NULL;
1305 ULONG scrollFlags = SW_INVALIDATERGN;
1306
1307 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1308 if(!window) {
1309 dprintf(("ScrollWindow, window %x not found", hwnd));
1310 return 0;
1311 }
1312 dprintf(("ScrollWindow %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip));
1313 mapWin32ToOS2Rect(window,window->getClientRectPtr(),(PRECTLOS2)&clientRect);
1314#if 0
1315 //Rectangle could be relative to parent window, so fix this
1316 if(clientRect.yBottom != 0) {
1317 clientRect.yTop -= clientRect.yBottom;
1318 clientRect.yBottom = 0;
1319 }
1320 if(clientRect.xLeft != 0) {
1321 clientRect.xRight -= clientRect.xLeft;
1322 clientRect.xLeft = 0;
1323 }
1324#endif
1325 if(pScroll) {
1326 mapWin32ToOS2Rect(window,(RECT *)pScroll, (PRECTLOS2)&scrollRect);
1327 pScrollRect = &scrollRect;
1328
1329 //Scroll rectangle relative to client area
1330 pScrollRect->xLeft += clientRect.xLeft;
1331 pScrollRect->xRight += clientRect.xLeft;
1332 pScrollRect->yTop += clientRect.yBottom;
1333 pScrollRect->yBottom += clientRect.yBottom;
1334 WinIntersectRect ((HAB) 0, pScrollRect, pScrollRect, &clientRect);
1335 }
1336 else scrollFlags |= SW_SCROLLCHILDREN;
1337
1338 if(pClip) {
1339 mapWin32ToOS2Rect(window,(RECT *)pClip, (PRECTLOS2)&clipRect);
1340 pClipRect = &clipRect;
1341
1342 //Clip rectangle relative to client area
1343 pClipRect->xLeft += clientRect.xLeft;
1344 pClipRect->xRight += clientRect.xLeft;
1345 pClipRect->yTop += clientRect.yBottom;
1346 pClipRect->yBottom += clientRect.yBottom;
1347 WinIntersectRect ((HAB) 0, pClipRect, pClipRect, &clientRect);
1348 }
1349
1350 dy = revertDy (window, dy);
1351
1352 rc = WinScrollWindow(window->getOS2WindowHandle(), dx, dy,
1353 pScrollRect, pClipRect, NULLHANDLE,
1354 NULL, scrollFlags);
1355
1356 return (rc != RGN_ERROR);
1357}
1358#endif
1359//******************************************************************************
1360//******************************************************************************
1361INT WIN32API ScrollWindowEx(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip,
1362 HRGN hrgnUpdate, PRECT pRectUpdate, UINT scrollFlag)
1363{
1364 Win32BaseWindow *window;
1365 APIRET rc;
1366 RECTL scrollRect;
1367 RECTL clipRect;
1368 ULONG scrollFlags = 0;
1369 int regionType = ERROR_W;
1370
1371 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1372 if(!window) {
1373 dprintf(("ScrollWindowEx, window %x not found", hwnd));
1374 return 0;
1375 }
1376
1377 dprintf(("ScrollWindowEx %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip));
1378
1379 dy = revertDy (window, dy);
1380
1381 if (scrollFlag & SW_INVALIDATE_W) scrollFlags |= SW_INVALIDATERGN;
1382 if (scrollFlag & SW_SCROLLCHILDREN_W) scrollFlags |= SW_SCROLLCHILDREN;
1383
1384 if(pScroll) mapWin32ToOS2Rect(window,(RECT *)pScroll, (PRECTLOS2)&scrollRect);
1385 if(pClip) mapWin32ToOS2Rect(window,(RECT *)pClip, (PRECTLOS2)&clipRect);
1386
1387 RECTL rectlUpdate;
1388 HRGN hrgn;
1389
1390 if (scrollFlag & SW_SMOOTHSCROLL_W)
1391 {
1392 INT time = (scrollFlag >> 16) & 0xFFFF;
1393
1394 //CB: todo, scroll in several steps
1395 // is time in ms? time <-> iteration count?
1396 }
1397
1398 LONG lComplexity = WinScrollWindow (window->getOS2WindowHandle(), dx, dy,
1399 (pScroll) ? &scrollRect : NULL,
1400 (pClip) ? &clipRect : NULL,
1401 hrgn, &rectlUpdate, scrollFlags);
1402 if (lComplexity == RGN_ERROR)
1403 {
1404 return ERROR_W;
1405 }
1406
1407 RECT winRectUpdate;
1408 LONG height = window->getClientHeight();
1409
1410 winRectUpdate.left = rectlUpdate.xLeft;
1411 winRectUpdate.right = rectlUpdate.xRight;
1412 winRectUpdate.top = height - rectlUpdate.yTop;
1413 winRectUpdate.bottom = height - rectlUpdate.yBottom;
1414
1415 if (pRectUpdate)
1416 *pRectUpdate = winRectUpdate;
1417
1418 if (hrgnUpdate)
1419 rc = setPMRgnIntoWinRgn (hrgn, hrgnUpdate, height);
1420
1421 if ((scrollFlag & SW_INVALIDATE_W) &&
1422 ((lComplexity == RGN_RECT) || (lComplexity == RGN_COMPLEX)))
1423 {
1424 rc = InvalidateRect (hwnd, &winRectUpdate, (scrollFlag & SW_ERASE_W) ? 1 : 0);
1425 if (rc == FALSE)
1426 {
1427 return (0);
1428 }
1429 }
1430
1431 switch (lComplexity)
1432 {
1433 case RGN_NULL:
1434 regionType = NULLREGION_W;
1435 break;
1436 case RGN_RECT:
1437 regionType = SIMPLEREGION_W;
1438 break;
1439 case RGN_COMPLEX:
1440 regionType = COMPLEXREGION_W;
1441 break;
1442 default:
1443 regionType = ERROR_W;
1444 break;
1445 }
1446
1447 return (regionType);
1448}
1449//******************************************************************************
1450//******************************************************************************
1451HWND WIN32API WindowFromDC(HDC hdc)
1452{
1453 pDCData pHps = (pDCData)GpiQueryDCData( (HPS)hdc );
1454
1455 dprintf2(("USER32: WindowFromDC %x", hdc));
1456 if ( pHps )
1457 return Win32BaseWindow::OS2ToWin32Handle(pHps->hwnd);
1458 else
1459 return 0;
1460}
1461//******************************************************************************
1462//******************************************************************************
1463INT WIN32API ExcludeUpdateRgn( HDC hDC, HWND hWnd)
1464{
1465 dprintf(("USER32: ExcludeUpdateRgn\n"));
1466 hWnd = Win32BaseWindow::Win32ToOS2Handle(hWnd);
1467
1468 return O32_ExcludeUpdateRgn(hDC,hWnd);
1469}
1470//******************************************************************************
1471//******************************************************************************
1472BOOL WIN32API ValidateRect( HWND hwnd, const RECT * lprc)
1473{
1474 if(lprc) {
1475 dprintf(("USER32: ValidateRect %x (%d,%d)(%d,%d)", hwnd, lprc->left, lprc->top, lprc->right, lprc->bottom));
1476 }
1477 else dprintf(("USER32: ValidateRect %x", hwnd));
1478
1479 return RedrawWindow( hwnd, lprc, 0, RDW_VALIDATE_W | RDW_NOCHILDREN_W | (hwnd==0 ? RDW_UPDATENOW_W : 0));
1480}
1481//******************************************************************************
1482//******************************************************************************
1483BOOL WIN32API ValidateRgn( HWND hwnd, HRGN hrgn)
1484{
1485 dprintf(("USER32: ValidateRgn %x %x", hwnd, hrgn));
1486 return RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE_W | RDW_NOCHILDREN_W | (hwnd==0 ? RDW_UPDATENOW_W : 0));
1487}
1488/*****************************************************************************
1489 * Name : int WIN32API GetWindowRgn
1490 * Purpose : The GetWindowRgn function obtains a copy of the window region of a window.
1491 * Parameters: HWND hWnd handle to window whose window region is to be obtained
1492 * HRGN hRgn handle to region that receives a copy of the window region
1493 * Variables :
1494 * Result : NULLREGION, SIMPLEREGION, COMPLEXREGION, ERROR
1495 * Remark :
1496 * Status : UNTESTED STUB
1497 *
1498 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
1499 *****************************************************************************/
1500
1501int WIN32API GetWindowRgn(HWND hwnd, HRGN hRgn)
1502{
1503 Win32BaseWindow *window;
1504 HRGN hWindowRegion;
1505
1506 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1507 if(!window) {
1508 dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
1509 O32_SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1510 return 0;
1511 }
1512 dprintf(("USER32:GetWindowRgn (%x,%x)", hwnd, hRgn));
1513 hWindowRegion = window->GetWindowRegion();
1514
1515 return O32_CombineRgn(hRgn, hWindowRegion, 0, RGN_COPY_W);
1516}
1517/*****************************************************************************
1518 * Name : int WIN32API SetWindowRgn
1519 * Purpose : The SetWindowRgn function sets the window region of a window. The
1520 * window region determines the area within the window where the
1521 * operating system permits drawing. The operating system does not
1522 * display any portion of a window that lies outside of the window region
1523 * When this function is called, the system sends the WM_WINDOWPOSCHANGING and
1524 * WM_WINDOWPOSCHANGED messages to the window.
1525 *
1526 * Parameters: HWND hWnd handle to window whose window region is to be set
1527 * HRGN hRgn handle to region
1528 * BOOL bRedraw window redraw flag
1529 * Variables :
1530 * Result : If the function succeeds, the return value is non-zero.
1531 * If the function fails, the return value is zero.
1532 * Remark :
1533 * Status : UNTESTED STUB
1534 *
1535 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
1536 *****************************************************************************/
1537
1538int WIN32API SetWindowRgn(HWND hwnd,
1539 HRGN hRgn,
1540 BOOL bRedraw)
1541{
1542 Win32BaseWindow *window;
1543 HRGN hWindowRegion;
1544
1545 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1546 if(!window) {
1547 dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
1548 O32_SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1549 return 0;
1550 }
1551 dprintf(("USER32:SetWindowRgn (%x,%x,%d)", hwnd, hRgn, bRedraw));
1552 if(window->GetWindowRegion()) {
1553 O32_DeleteObject(window->GetWindowRegion());
1554 }
1555 window->SetWindowRegion(hRgn);
1556 if(bRedraw) {
1557 RedrawWindow(hwnd, 0, 0, RDW_UPDATENOW_W);
1558 }
1559//TODO:
1560// When this function is called, the system sends the WM_WINDOWPOSCHANGING and
1561// WM_WINDOWPOSCHANGED messages to the window.
1562 return 1;
1563}
1564//******************************************************************************
1565//******************************************************************************
Note: See TracBrowser for help on using the repository browser.