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