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