1 | /* $Id: dc.cpp,v 1.1 1999-09-09 18:05:45 dengert 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 |
|
---|
26 | #ifndef OPEN32API
|
---|
27 | #define OPEN32API _System
|
---|
28 | #endif
|
---|
29 |
|
---|
30 | /*********************/
|
---|
31 | typedef struct _tagXFORM
|
---|
32 | {
|
---|
33 | FLOAT eM11;
|
---|
34 | FLOAT eM12;
|
---|
35 | FLOAT eM21;
|
---|
36 | FLOAT eM22;
|
---|
37 | FLOAT eDx;
|
---|
38 | FLOAT eDy;
|
---|
39 | } XFORM_W, *PXFORM_W, *LPXFORM_W;
|
---|
40 |
|
---|
41 | typedef struct
|
---|
42 | {
|
---|
43 | HDC hdc;
|
---|
44 | BOOL fErase;
|
---|
45 | RECT rcPaint;
|
---|
46 | BOOL fRestore;
|
---|
47 | BOOL fIncUpdate;
|
---|
48 | BYTE rgbReserved[32];
|
---|
49 | } PAINTSTRUCT_W, *PPAINTSTRUCT_W, *LPPAINTSTRUCT_W;
|
---|
50 |
|
---|
51 | #define PS_SOLID_W 0x00000000
|
---|
52 | #define PS_DASH_W 0x00000001
|
---|
53 | #define PS_DOT_W 0x00000002
|
---|
54 | #define PS_DASHDOT_W 0x00000003
|
---|
55 | #define PS_DASHDOTDOT_W 0x00000004
|
---|
56 | #define PS_NULL_W 0x00000005
|
---|
57 | #define PS_INSIDEFRAME_W 0x00000006
|
---|
58 | #define PS_USERSTYLE_W 0x00000007
|
---|
59 | #define PS_ALTERNATE_W 0x00000008
|
---|
60 | #define PS_STYLE_MASK_W 0x0000000f
|
---|
61 |
|
---|
62 | typedef struct
|
---|
63 | {
|
---|
64 | UINT lopnStyle;
|
---|
65 | POINT lopnWidth;
|
---|
66 | ULONG lopnColor;
|
---|
67 | } LOGPEN_W, *LPLOGPEN_W;
|
---|
68 |
|
---|
69 | typedef struct tagEXTLOGPEN
|
---|
70 | {
|
---|
71 | DWORD elpPenStyle;
|
---|
72 | DWORD elpWidth;
|
---|
73 | DWORD elpBrushStyle;
|
---|
74 | DWORD elpColor;
|
---|
75 | DWORD elpNumEntries;
|
---|
76 | DWORD elpStyleEntry[1];
|
---|
77 | } EXTLOGPEN_W, *PEXTLOGPEN_W, *NPEXTLOGPEN_W, *LPEXTLOGPEN_W;
|
---|
78 |
|
---|
79 | typedef struct
|
---|
80 | {
|
---|
81 | UINT lbStyle;
|
---|
82 | ULONG lbColor;
|
---|
83 | INT lbHatch;
|
---|
84 | } LOGBRUSH_W, *LPLOGBRUSH_W;
|
---|
85 |
|
---|
86 | typedef struct _penobject
|
---|
87 | {
|
---|
88 | ULONG filler[9];
|
---|
89 | union {
|
---|
90 | struct {
|
---|
91 | PEXTLOGPEN_W pExtLogPen;
|
---|
92 | LOGBRUSH_W logbrush;
|
---|
93 | LOGPEN_W logpen;
|
---|
94 | } ExtPen;
|
---|
95 | struct {
|
---|
96 | LOGPEN_W logpen;
|
---|
97 | } Pen;
|
---|
98 | };
|
---|
99 | } tPenObject, *pPenObject;
|
---|
100 |
|
---|
101 | /* DC Graphics Mode */
|
---|
102 | #define GM_COMPATIBLE_W 1
|
---|
103 | #define GM_ADVANCED_W 2
|
---|
104 |
|
---|
105 | #define DCX_WINDOW 0x00000001L
|
---|
106 | #define DCX_CACHE 0x00000002L
|
---|
107 | #define DCX_NORESETATTRS 0x00000004L
|
---|
108 | #define DCX_CLIPCHILDREN 0x00000008L
|
---|
109 | #define DCX_CLIPSIBLINGS 0x00000010L
|
---|
110 | #define DCX_PARENTCLIP 0x00000020L
|
---|
111 | #define DCX_EXCLUDERGN 0x00000040L
|
---|
112 | #define DCX_INTERSECTRGN 0x00000080L
|
---|
113 | #define DCX_EXCLUDEUPDATE 0x00000100L
|
---|
114 | #define DCX_INTERSECTUPDATE 0x00000200L
|
---|
115 | #define DCX_LOCKWINDOWUPDATE 0x00000400L
|
---|
116 | #define DCX_VALIDATE 0x00200000L
|
---|
117 |
|
---|
118 | /* Xform FLAGS */
|
---|
119 | #define MWT_IDENTITY_W 1
|
---|
120 | #define MWT_LEFTMULTIPLY_W 2
|
---|
121 | #define MWT_RIGHTMULTIPLY_W 3
|
---|
122 |
|
---|
123 | /* Mapping Modes */
|
---|
124 | #define MM_TEXT_W 1
|
---|
125 | #define MM_LOMETRIC_W 2
|
---|
126 | #define MM_HIMETRIC_W 3
|
---|
127 | #define MM_LOENGLISH_W 4
|
---|
128 | #define MM_HIENGLISH_W 5
|
---|
129 | #define MM_TWIPS_W 6
|
---|
130 | #define MM_ISOTROPIC_W 7
|
---|
131 | #define MM_ANISOTROPIC_W 8
|
---|
132 |
|
---|
133 | enum PS_Type { MICRO_CACHED, MICRO, NORMAL };
|
---|
134 | enum HDC_Type{ TYPE_0, TYPE_1, TYPE_2, TYPE_3, TYPE_4 };
|
---|
135 |
|
---|
136 | typedef struct _DCData
|
---|
137 | {
|
---|
138 | HDC hdc;
|
---|
139 | HWND hwnd;
|
---|
140 | HPS hps;
|
---|
141 |
|
---|
142 | UINT lastBrushHandle;
|
---|
143 | PVOID lastBrushObject;
|
---|
144 | UINT lastPenHandle;
|
---|
145 | pPenObject lastPenObject;
|
---|
146 | UINT lastFontHandle;
|
---|
147 | PVOID lastFontObject;
|
---|
148 | UINT lastBitmapHandle;
|
---|
149 | PVOID lastBitmapObject;
|
---|
150 | UINT lastPaletteHandle;
|
---|
151 | PVOID lastPaletteObject;
|
---|
152 |
|
---|
153 | UINT nullBitmapHandle;
|
---|
154 |
|
---|
155 | ULONG BkColor;
|
---|
156 | ULONG TextColor;
|
---|
157 | ULONG BkColor_PM;
|
---|
158 | ULONG TextColor_PM;
|
---|
159 |
|
---|
160 | int BkMode;
|
---|
161 | ULONG BkMode_PM;
|
---|
162 |
|
---|
163 | int ROP2Mode;
|
---|
164 | int ROP2Mode_PM;
|
---|
165 |
|
---|
166 | unsigned isMemoryPS:1;
|
---|
167 | unsigned isMetaPS:1;
|
---|
168 | unsigned isPrinter:1;
|
---|
169 | unsigned isFrameWindow:1;
|
---|
170 | unsigned isOD_QUEUED:1;
|
---|
171 | unsigned isOD_INFO:1;
|
---|
172 | unsigned isClient:1;
|
---|
173 | unsigned isClientArea:1;
|
---|
174 | unsigned isLeftLeft:1;
|
---|
175 | unsigned isTopTop:1;
|
---|
176 | unsigned isWideLine:1;
|
---|
177 | unsigned alignUpdateCP:1;
|
---|
178 | unsigned isCacheable:1;
|
---|
179 | unsigned penIsExtPen:1;
|
---|
180 | unsigned isValid:1;
|
---|
181 | unsigned inPath:1;
|
---|
182 | unsigned isStartDoc:1;
|
---|
183 | unsigned resetStockFonts:1;
|
---|
184 | unsigned unused:14;
|
---|
185 |
|
---|
186 | ULONG MapMode;
|
---|
187 | HBITMAP bitmapHandle;
|
---|
188 | ULONG bitmapHeight;
|
---|
189 | ULONG bitmapWidth;
|
---|
190 | ULONG hMeta;
|
---|
191 | PVOID pMetaFileObject;
|
---|
192 | int polyFillMode;
|
---|
193 | int arcDirection;
|
---|
194 | int stretchBltMode;
|
---|
195 | int graphicsMode;
|
---|
196 | HRGN hrgnHDC;
|
---|
197 |
|
---|
198 | PS_Type psType;
|
---|
199 |
|
---|
200 | HDC_Type hdcType;
|
---|
201 | USHORT usFiller;
|
---|
202 | POINTL viewportOrg;
|
---|
203 | double viewportXExt;
|
---|
204 | double viewportYExt;
|
---|
205 | POINTL windowOrg;
|
---|
206 | SIZEL windowExt;
|
---|
207 | HRGN hrgnVis;
|
---|
208 | POINTL ptlOrigin;
|
---|
209 | ULONG printPageHeight;
|
---|
210 | PVOID printerObject;
|
---|
211 |
|
---|
212 | LONG taMode;
|
---|
213 | XFORM_W xform;
|
---|
214 |
|
---|
215 | INT worldYDeltaFor1Pixel;
|
---|
216 | INT worldXDeltaFor1Pixel;
|
---|
217 | ULONG colorMode;
|
---|
218 | PULONG pLogColorTable;
|
---|
219 |
|
---|
220 | ULONG lcidBitfield;
|
---|
221 |
|
---|
222 | HWND hwndRealize;
|
---|
223 | ULONG cpeMap;
|
---|
224 |
|
---|
225 | LONG lTechnology;
|
---|
226 |
|
---|
227 | LONG lWndXExtSave, lWndYExtSave,
|
---|
228 | lVwpXExtSave, lVwpYExtSave;
|
---|
229 |
|
---|
230 | int height;
|
---|
231 |
|
---|
232 | POINTL brushOrgPoint;
|
---|
233 |
|
---|
234 | PVOID pEnhMetaPalette;
|
---|
235 | PVOID lpAbortProc;
|
---|
236 | ULONG HPStoHDCInversionHeight;
|
---|
237 |
|
---|
238 | int saveLevel;
|
---|
239 |
|
---|
240 | struct _DCData *nextDCData;
|
---|
241 | } tDCData, *pDCData;
|
---|
242 |
|
---|
243 | /*********************/
|
---|
244 |
|
---|
245 | BOOL APIENTRY GpiEnableYInversion (HPS hps, LONG lHeight);
|
---|
246 | LONG APIENTRY GpiQueryYInversion (HPS hps);
|
---|
247 | PVOID APIENTRY GpiAllocateDCData (HPS GpiH, ULONG size);
|
---|
248 | PVOID APIENTRY GpiQueryDCData (HPS hps);
|
---|
249 | HDC OPEN32API HPSToHDC (HWND hwnd, HPS hps, HDC hdc, PVOID);
|
---|
250 | void OPEN32API DeleteHDC (HDC hdc);
|
---|
251 | BOOL OPEN32API _O32_EndPaint (HWND hwnd, const PAINTSTRUCT_W *lpps);
|
---|
252 |
|
---|
253 | #define FLOAT_TO_FIXED(x) ((FIXED) ((x) * 65536.0))
|
---|
254 | #define MICRO_HPS_TO_HDC(x) ((x) & 0xFFFFFFFE)
|
---|
255 |
|
---|
256 | #define PMRECT_FROM_WINRECT( pmRect, winRect ) \
|
---|
257 | { \
|
---|
258 | (pmRect).xLeft = (winRect).left; \
|
---|
259 | (pmRect).yBottom = (winRect).bottom; \
|
---|
260 | (pmRect).xRight = (winRect).right; \
|
---|
261 | (pmRect).yTop = (winRect).top; \
|
---|
262 | }
|
---|
263 |
|
---|
264 | #define WINRECT_FROM_PMRECT( winRect, pmRect ) \
|
---|
265 | { \
|
---|
266 | (winRect).left = (pmRect).xLeft; \
|
---|
267 | (winRect).top = (pmRect).yTop; \
|
---|
268 | (winRect).right = (pmRect).xRight; \
|
---|
269 | (winRect).bottom = (pmRect).yBottom; \
|
---|
270 | }
|
---|
271 |
|
---|
272 | #define MEM_HPS_MAX 768
|
---|
273 |
|
---|
274 | const XFORM_W XFORMIdentity = { 1.0, 0.0, 0.0, 1.0, 0, 0 };
|
---|
275 | const MATRIXLF matrixlfIdentity = { 0x10000, 0, 0, 0, 0x10000, 0, 0, 0, 0};
|
---|
276 |
|
---|
277 | BOOL setPageXForm(pDCData pHps);
|
---|
278 | BOOL changePageXForm(pDCData pHps, PPOINTL pValue, int x, int y, PPOINTL pPrev);
|
---|
279 | LONG clientHeight(HWND hwnd, pDCData pHps);
|
---|
280 |
|
---|
281 | void TestWideLine (pDCData pHps)
|
---|
282 | {
|
---|
283 | const LOGPEN_W *pLogPen;
|
---|
284 |
|
---|
285 | pHps->isWideLine = FALSE;
|
---|
286 | pLogPen = pHps->penIsExtPen ?
|
---|
287 | &(pHps->lastPenObject->ExtPen.logpen) :
|
---|
288 | &(pHps->lastPenObject->Pen.logpen);
|
---|
289 |
|
---|
290 | if (((pLogPen->lopnStyle & PS_STYLE_MASK_W) != PS_NULL_W) &&
|
---|
291 | (pLogPen->lopnWidth.x > 0))
|
---|
292 | {
|
---|
293 | POINTL aptl[2] = { 0, 0, pLogPen->lopnWidth.x, pLogPen->lopnWidth.x };
|
---|
294 |
|
---|
295 | GpiConvert(pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, aptl);
|
---|
296 |
|
---|
297 | ULONG dx = abs(aptl[0].x - aptl[1].x);
|
---|
298 | ULONG dy = abs(aptl[0].y - aptl[1].y);
|
---|
299 |
|
---|
300 | pHps->isWideLine = (dx > 1) || (dy > 1);
|
---|
301 | }
|
---|
302 | }
|
---|
303 |
|
---|
304 | void Calculate1PixelDelta(pDCData pHps)
|
---|
305 | {
|
---|
306 | POINTL aptl[2] = {0, 0, 1, 1};
|
---|
307 |
|
---|
308 | GpiConvert(pHps->hps, CVTC_DEVICE, CVTC_WORLD, 2, aptl);
|
---|
309 | pHps->worldYDeltaFor1Pixel = (int)(aptl[1].y - aptl[0].y);
|
---|
310 | pHps->worldXDeltaFor1Pixel = (int)(aptl[1].x - aptl[0].x); // 171182
|
---|
311 | }
|
---|
312 |
|
---|
313 | //******************************************************************************
|
---|
314 |
|
---|
315 | int setMapMode(pDCData pHps, int mode)
|
---|
316 | {
|
---|
317 | int prevMode = 0;
|
---|
318 | ULONG flOptions;
|
---|
319 |
|
---|
320 | switch (mode)
|
---|
321 | {
|
---|
322 | case MM_HIENGLISH_W : flOptions = PU_HIENGLISH; break;
|
---|
323 | case MM_LOENGLISH_W : flOptions = PU_LOENGLISH; break;
|
---|
324 | case MM_HIMETRIC_W : flOptions = PU_HIMETRIC ; break;
|
---|
325 | case MM_LOMETRIC_W : flOptions = PU_LOMETRIC ; break;
|
---|
326 | case MM_TEXT_W : flOptions = PU_PELS ; break;
|
---|
327 | case MM_TWIPS_W : flOptions = PU_TWIPS ; break;
|
---|
328 | case MM_ANISOTROPIC_W: flOptions = PU_PELS ; break;
|
---|
329 | case MM_ISOTROPIC_W : flOptions = PU_LOMETRIC ; break;
|
---|
330 | default:
|
---|
331 | // SET_ERROR_WIN(ERROR_INVALID_PARAMETER_W);
|
---|
332 | return FALSE;
|
---|
333 | }
|
---|
334 |
|
---|
335 | prevMode = pHps->MapMode; /* store previous mode */
|
---|
336 | pHps->MapMode = mode;
|
---|
337 |
|
---|
338 | if (mode == MM_TEXT_W)
|
---|
339 | {
|
---|
340 | pHps->viewportXExt =
|
---|
341 | pHps->viewportYExt = 1.0;
|
---|
342 | pHps->windowExt.cx =
|
---|
343 | pHps->windowExt.cy = 1;
|
---|
344 | }
|
---|
345 | else if (mode != MM_ANISOTROPIC_W)
|
---|
346 | {
|
---|
347 | RECTL rectl;
|
---|
348 | SIZEL sizel;
|
---|
349 | ULONG data[3];
|
---|
350 |
|
---|
351 | data[0] = flOptions;
|
---|
352 | data[1] = data[2] = 0;
|
---|
353 |
|
---|
354 | if (DevEscape(pHps->hdc ? pHps->hdc : pHps->hps, DEVESC_SETPS, 12, (PBYTE)data, 0, 0) == DEVESC_ERROR)
|
---|
355 | {
|
---|
356 | // SET_ERROR_LAST();
|
---|
357 | return 0;
|
---|
358 | }
|
---|
359 |
|
---|
360 | GpiQueryPageViewport(pHps->hps, &rectl);
|
---|
361 | pHps->viewportXExt = (double)rectl.xRight;
|
---|
362 | pHps->viewportYExt = -(double)rectl.yTop;
|
---|
363 |
|
---|
364 | GreGetPageUnits(pHps->hdc? pHps->hdc : pHps->hps, &sizel);
|
---|
365 | pHps->windowExt.cx = sizel.cx;
|
---|
366 | pHps->windowExt.cy = sizel.cy;
|
---|
367 |
|
---|
368 | data[0] = PU_PELS;
|
---|
369 | DevEscape(pHps->hdc ? pHps->hdc : pHps->hps, DEVESC_SETPS, 12, (PBYTE)data, 0, 0);
|
---|
370 | }
|
---|
371 |
|
---|
372 | if (((prevMode != MM_ISOTROPIC_W) && (prevMode != MM_ANISOTROPIC_W)) &&
|
---|
373 | ((mode == MM_ISOTROPIC_W) || (mode == MM_ANISOTROPIC_W)))
|
---|
374 | {
|
---|
375 | if (pHps->lWndXExtSave && pHps->lWndYExtSave)
|
---|
376 | {
|
---|
377 | changePageXForm( pHps, (PPOINTL)&pHps->windowExt,
|
---|
378 | pHps->lWndXExtSave, pHps->lWndYExtSave, NULL );
|
---|
379 | pHps->lWndXExtSave = pHps->lWndYExtSave = 0;
|
---|
380 | }
|
---|
381 | if (pHps->lVwpXExtSave && pHps->lVwpYExtSave)
|
---|
382 | {
|
---|
383 | changePageXForm( pHps, NULL,
|
---|
384 | pHps->lVwpXExtSave, pHps->lVwpYExtSave, NULL );
|
---|
385 | pHps->lVwpXExtSave = pHps->lVwpYExtSave = 0;
|
---|
386 | }
|
---|
387 | }
|
---|
388 |
|
---|
389 | setPageXForm(pHps);
|
---|
390 |
|
---|
391 | return prevMode;
|
---|
392 | }
|
---|
393 |
|
---|
394 | BOOL setPageXForm(pDCData pHps)
|
---|
395 | {
|
---|
396 | MATRIXLF mlf;
|
---|
397 | BOOL rc = TRUE;
|
---|
398 |
|
---|
399 | pHps->height = clientHeight(0, pHps) - 1;
|
---|
400 |
|
---|
401 | double xScale = pHps->viewportXExt / (double)pHps->windowExt.cx;
|
---|
402 | double yScale = pHps->viewportYExt / (double)pHps->windowExt.cy;
|
---|
403 |
|
---|
404 | mlf.fxM11 = FLOAT_TO_FIXED(xScale);
|
---|
405 | mlf.fxM12 = 0;
|
---|
406 | mlf.lM13 = 0;
|
---|
407 | mlf.fxM21 = 0;
|
---|
408 | mlf.fxM22 = FLOAT_TO_FIXED(yScale);
|
---|
409 | mlf.lM23 = 0;
|
---|
410 | mlf.lM31 = pHps->viewportOrg.x - (LONG)(pHps->windowOrg.x * xScale);
|
---|
411 | mlf.lM32 = pHps->viewportOrg.y - (LONG)(pHps->windowOrg.y * yScale);
|
---|
412 |
|
---|
413 | pHps->isLeftLeft = mlf.fxM11 >= 0;
|
---|
414 | pHps->isTopTop = mlf.fxM22 >= 0;
|
---|
415 |
|
---|
416 | BOOL bEnableYInversion = FALSE;
|
---|
417 | if ((mlf.fxM22 > 0) ||
|
---|
418 | ((pHps->graphicsMode == GM_ADVANCED_W) &&
|
---|
419 | ((pHps->MapMode == MM_ANISOTROPIC_W) ||
|
---|
420 | (pHps->MapMode == MM_ISOTROPIC_W))))
|
---|
421 | {
|
---|
422 | bEnableYInversion = TRUE;
|
---|
423 | }
|
---|
424 | else
|
---|
425 | {
|
---|
426 | bEnableYInversion = FALSE;
|
---|
427 | mlf.lM32 = pHps->HPStoHDCInversionHeight + pHps->height - mlf.lM32;
|
---|
428 | mlf.fxM22 = -mlf.fxM22;
|
---|
429 | }
|
---|
430 |
|
---|
431 | if (!pHps->isMetaPS)
|
---|
432 | // if ((!pHps->isMetaPS) ||
|
---|
433 | // (pHps->pMetaFileObject && pHps->pMetaFileObject->isEnhanced()))
|
---|
434 | rc = GpiSetDefaultViewMatrix(pHps->hps, 8, &mlf, TRANSFORM_REPLACE);
|
---|
435 |
|
---|
436 | if (bEnableYInversion)
|
---|
437 | GpiEnableYInversion(pHps->hps, pHps->height + pHps->HPStoHDCInversionHeight);
|
---|
438 | else
|
---|
439 | GpiEnableYInversion(pHps->hps, 0);
|
---|
440 |
|
---|
441 | TestWideLine(pHps);
|
---|
442 | Calculate1PixelDelta(pHps);
|
---|
443 | return rc;
|
---|
444 | }
|
---|
445 |
|
---|
446 | BOOL changePageXForm(pDCData pHps, PPOINTL pValue, int x, int y, PPOINTL pPrev)
|
---|
447 | {
|
---|
448 | BOOL result = FALSE;
|
---|
449 |
|
---|
450 | if (pValue)
|
---|
451 | {
|
---|
452 | if (pPrev)
|
---|
453 | *pPrev = *pValue;
|
---|
454 |
|
---|
455 | if ((pValue->x == x) && (pValue->y == y)) {
|
---|
456 | return TRUE;
|
---|
457 | }
|
---|
458 | pValue->x = x;
|
---|
459 | pValue->y = y;
|
---|
460 | }
|
---|
461 | else
|
---|
462 | {
|
---|
463 | if (pPrev)
|
---|
464 | {
|
---|
465 | pPrev->x = (int)pHps->viewportXExt;
|
---|
466 | pPrev->y = (int)pHps->viewportYExt;
|
---|
467 | }
|
---|
468 | pHps->viewportXExt = (double)x;
|
---|
469 | pHps->viewportYExt = (double)y;
|
---|
470 | }
|
---|
471 |
|
---|
472 | if (pHps->MapMode == MM_ISOTROPIC_W)
|
---|
473 | {
|
---|
474 | double xExt = fabs(pHps->viewportXExt);
|
---|
475 | double yExt = fabs(pHps->viewportYExt);
|
---|
476 | double sf = fabs((double)pHps->windowExt.cx / pHps->windowExt.cy);
|
---|
477 |
|
---|
478 | if (xExt > (yExt * sf))
|
---|
479 | {
|
---|
480 | xExt = yExt * sf;
|
---|
481 |
|
---|
482 | if ((double)LONG_MAX <= xExt) return (result);
|
---|
483 |
|
---|
484 | if (pHps->viewportXExt < 0.0)
|
---|
485 | pHps->viewportXExt = -xExt;
|
---|
486 | else
|
---|
487 | pHps->viewportXExt = xExt;
|
---|
488 | }
|
---|
489 | else
|
---|
490 | {
|
---|
491 | yExt = xExt / sf;
|
---|
492 |
|
---|
493 | if ((double)LONG_MAX <= yExt) return (result);
|
---|
494 |
|
---|
495 | if (pHps->viewportYExt < 0.0)
|
---|
496 | pHps->viewportYExt = -yExt;
|
---|
497 | else
|
---|
498 | pHps->viewportYExt = yExt;
|
---|
499 | }
|
---|
500 | }
|
---|
501 | result = setPageXForm(pHps);
|
---|
502 |
|
---|
503 | return (result);
|
---|
504 | }
|
---|
505 |
|
---|
506 | LONG clientHeight(HWND hwnd, pDCData pHps)
|
---|
507 | {
|
---|
508 | if ((hwnd == 0) && (pHps != 0))
|
---|
509 | hwnd = pHps->hwnd;
|
---|
510 |
|
---|
511 | if ((hwnd != 0) || (pHps == 0))
|
---|
512 | {
|
---|
513 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
|
---|
514 | return (wnd->getWindowHeight());
|
---|
515 | }
|
---|
516 | else if (pHps->bitmapHandle)
|
---|
517 | {
|
---|
518 | return pHps->bitmapHeight;
|
---|
519 | }
|
---|
520 | else if (pHps->isMetaPS)
|
---|
521 | {
|
---|
522 | return 0;
|
---|
523 | }
|
---|
524 | else if (pHps->isPrinter)
|
---|
525 | {
|
---|
526 | return pHps->printPageHeight;
|
---|
527 | }
|
---|
528 | else
|
---|
529 | {
|
---|
530 | return MEM_HPS_MAX;
|
---|
531 | }
|
---|
532 | }
|
---|
533 |
|
---|
534 | VOID removeClientArea(pDCData pHps)
|
---|
535 | {
|
---|
536 | pHps->isClient = FALSE;
|
---|
537 |
|
---|
538 | if (pHps->isClientArea)
|
---|
539 | {
|
---|
540 | pHps->isClientArea = FALSE;
|
---|
541 | GreSetupDC(pHps->hps,
|
---|
542 | pHps->hrgnVis,
|
---|
543 | pHps->ptlOrigin.x,
|
---|
544 | pHps->ptlOrigin.y,
|
---|
545 | 0,
|
---|
546 | SETUPDC_ORIGIN | SETUPDC_VISRGN | SETUPDC_RECALCCLIP);
|
---|
547 | }
|
---|
548 | }
|
---|
549 |
|
---|
550 | void selectClientArea(Win32BaseWindow *wnd, pDCData pHps, PRECTL prclPaint)
|
---|
551 | {
|
---|
552 | RECTL rcl;
|
---|
553 | HRGN hrgnRect;
|
---|
554 | HWND hwnd;
|
---|
555 |
|
---|
556 | pHps->isClient = TRUE;
|
---|
557 | hwnd = pHps->hwnd;
|
---|
558 |
|
---|
559 | rcl.xLeft = rcl.yBottom = 0;
|
---|
560 | rcl.xRight = wnd->getWindowWidth();
|
---|
561 | rcl.yTop = wnd->getWindowHeight();
|
---|
562 |
|
---|
563 | WinMapWindowPoints(hwnd, HWND_DESKTOP, (PPOINTL) &rcl, 2);
|
---|
564 | pHps->ptlOrigin = *((PPOINTL) &rcl);
|
---|
565 |
|
---|
566 | if (pHps->hrgnVis == 0)
|
---|
567 | pHps->hrgnVis = GreCreateRectRegion(pHps->hps, &rcl, 1);
|
---|
568 |
|
---|
569 | hrgnRect = GreCreateRectRegion(pHps->hps, &rcl, 1);
|
---|
570 |
|
---|
571 | if (!pHps->isClientArea)
|
---|
572 | GreCopyClipRegion(pHps->hps, pHps->hrgnVis, 0, COPYCRGN_VISRGN);
|
---|
573 |
|
---|
574 | GreCombineRegion(pHps->hps, hrgnRect, pHps->hrgnVis, hrgnRect, CRGN_AND);
|
---|
575 | GreSetupDC(pHps->hps,
|
---|
576 | hrgnRect,
|
---|
577 | rcl.xLeft,
|
---|
578 | rcl.yBottom,
|
---|
579 | prclPaint,
|
---|
580 | SETUPDC_ORIGIN | SETUPDC_VISRGN | SETUPDC_RECALCCLIP);
|
---|
581 |
|
---|
582 | pHps->isClientArea = TRUE;
|
---|
583 | GreDestroyRegion(pHps->hps, hrgnRect);
|
---|
584 | }
|
---|
585 |
|
---|
586 | HDC sendEraseBkgnd (Win32BaseWindow *wnd)
|
---|
587 | {
|
---|
588 | BOOL erased;
|
---|
589 | HWND hwnd;
|
---|
590 | HDC hdc;
|
---|
591 | HPS hps;
|
---|
592 | HRGN hrgnUpdate, hrgnOld, hrgnClip, hrgnCombined;
|
---|
593 | RECTL rectl = { 1, 1, 2, 2 };
|
---|
594 |
|
---|
595 | hwnd = wnd->getOS2WindowHandle();
|
---|
596 | hps = WinGetPS(hwnd);
|
---|
597 |
|
---|
598 | hrgnUpdate = GpiCreateRegion (hps, 1, &rectl);
|
---|
599 | WinQueryUpdateRegion (hwnd, hrgnUpdate);
|
---|
600 | hrgnClip = GpiQueryClipRegion (hps);
|
---|
601 |
|
---|
602 | if (hrgnClip == NULLHANDLE)
|
---|
603 | {
|
---|
604 | GpiSetClipRegion (hps, hrgnUpdate, &hrgnOld);
|
---|
605 | }
|
---|
606 | else
|
---|
607 | {
|
---|
608 | hrgnCombined = GpiCreateRegion (hps, 1, &rectl);
|
---|
609 | GpiCombineRegion (hps, hrgnCombined, hrgnClip, hrgnUpdate, CRGN_AND);
|
---|
610 | GpiSetClipRegion (hps, hrgnCombined, &hrgnOld);
|
---|
611 | GpiDestroyRegion (hps, hrgnUpdate);
|
---|
612 | GpiDestroyRegion (hps, hrgnClip);
|
---|
613 | }
|
---|
614 | if (hrgnOld != NULLHANDLE)
|
---|
615 | GpiDestroyRegion (hps, hrgnOld);
|
---|
616 |
|
---|
617 | hdc = HPSToHDC (hwnd, hps, NULL, NULL);
|
---|
618 |
|
---|
619 | erased = wnd->MsgEraseBackGround (hdc);
|
---|
620 |
|
---|
621 | DeleteHDC (hdc);
|
---|
622 | WinReleasePS (hps);
|
---|
623 |
|
---|
624 | return erased;
|
---|
625 | }
|
---|
626 |
|
---|
627 | HDC WIN32API BeginPaint (HWND hWnd, PPAINTSTRUCT_W lpps)
|
---|
628 | {
|
---|
629 | HWND hwnd = hWnd ? hWnd : HWND_DESKTOP;
|
---|
630 | pDCData pHps = NULLHANDLE;
|
---|
631 | RECTL rect;
|
---|
632 | HPS hPS_ownDC = NULLHANDLE;
|
---|
633 |
|
---|
634 | dprintf (("USER32: BeginPaint(%x)", hWnd));
|
---|
635 |
|
---|
636 | if ( !lpps )
|
---|
637 | {
|
---|
638 | // SET_ERROR_WIN( ERROR_INVALID_PARAMETER_W );
|
---|
639 | return (HDC)NULLHANDLE;
|
---|
640 | }
|
---|
641 |
|
---|
642 | USHORT sel = RestoreOS2FS();
|
---|
643 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
644 |
|
---|
645 | if ((hwnd != HWND_DESKTOP) && wnd->isOwnDC())
|
---|
646 | {
|
---|
647 | hPS_ownDC = wnd->getOwnDC();
|
---|
648 | pHps = (pDCData)GpiQueryDCData(hPS_ownDC);
|
---|
649 | if (!pHps)
|
---|
650 | {
|
---|
651 | // SET_ERROR_LAST();
|
---|
652 | SetFS(sel);
|
---|
653 | return (HDC)NULLHANDLE;
|
---|
654 | }
|
---|
655 | }
|
---|
656 |
|
---|
657 | HWND hwndClient = wnd->getOS2WindowHandle();
|
---|
658 | HPS hps = WinBeginPaint(hwndClient, hPS_ownDC, &rect);
|
---|
659 |
|
---|
660 | if (!pHps)
|
---|
661 | {
|
---|
662 | HDC hdc = HPSToHDC (hwndClient, hps, NULL, NULL);
|
---|
663 | pHps = (pDCData)GpiQueryDCData(hps);
|
---|
664 | }
|
---|
665 |
|
---|
666 | if (wnd->isFrameWindow())
|
---|
667 | {
|
---|
668 | // WinSendMsg( hwnd, /* WM_DRAW */ 0x20D, (MPARAM)hps, MPVOID );
|
---|
669 | selectClientArea(wnd, pHps, &rect);
|
---|
670 | }
|
---|
671 |
|
---|
672 | if (hPS_ownDC == 0)
|
---|
673 | setMapMode(pHps, MM_TEXT_W);
|
---|
674 | else
|
---|
675 | setPageXForm(pHps);
|
---|
676 |
|
---|
677 | pHps->hdcType = TYPE_3;
|
---|
678 | lpps->hdc = (HDC)hps;
|
---|
679 | lpps->fErase = !wnd->MsgEraseBackGround(lpps->hdc);
|
---|
680 |
|
---|
681 | if (!hPS_ownDC)
|
---|
682 | {
|
---|
683 | long height = wnd->getWindowHeight();
|
---|
684 | rect.yTop = height - rect.yTop;
|
---|
685 | rect.yBottom = height - rect.yBottom;
|
---|
686 | }
|
---|
687 | else
|
---|
688 | {
|
---|
689 | rect.yTop--;
|
---|
690 | rect.yBottom--;
|
---|
691 | GpiConvert(pHps->hps, CVTC_DEVICE, CVTC_WORLD, 2, (PPOINTL)&rect);
|
---|
692 | }
|
---|
693 |
|
---|
694 | WINRECT_FROM_PMRECT(lpps->rcPaint, rect);
|
---|
695 |
|
---|
696 | SetFS(sel);
|
---|
697 | return (HDC)pHps->hps;
|
---|
698 | }
|
---|
699 |
|
---|
700 | BOOL WIN32API EndPaint (HWND hwnd, const PAINTSTRUCT_W *pPaint)
|
---|
701 | {
|
---|
702 | dprintf (("USER32: EndPaint(%x)", hwnd));
|
---|
703 |
|
---|
704 | if (!pPaint || !pPaint->hdc )
|
---|
705 | return TRUE;
|
---|
706 |
|
---|
707 | USHORT sel = RestoreOS2FS();
|
---|
708 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
709 |
|
---|
710 | if (!wnd) goto exit;
|
---|
711 |
|
---|
712 | if (wnd->isOwnDC())
|
---|
713 | {
|
---|
714 | pDCData pHps = (pDCData)GpiQueryDCData((HPS)pPaint->hdc);
|
---|
715 | if (pHps && (pHps->hdcType == TYPE_3))
|
---|
716 | {
|
---|
717 | removeClientArea (pHps);
|
---|
718 | WinEndPaint (pHps->hps);
|
---|
719 | }
|
---|
720 | }
|
---|
721 | else
|
---|
722 | {
|
---|
723 | _O32_EndPaint (HWND_DESKTOP, pPaint);
|
---|
724 | }
|
---|
725 |
|
---|
726 | exit:
|
---|
727 | SetFS(sel);
|
---|
728 | return TRUE;
|
---|
729 | }
|
---|
730 | //******************************************************************************
|
---|
731 | //******************************************************************************
|
---|
732 |
|
---|