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