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

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

DC changes + commented out shell position update

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