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