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

Last change on this file since 3294 was 3294, checked in by sandervl, 25 years ago

dc.cpp cleanup

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