| 1 | /* $Id: dc.cpp,v 1.3 1999-09-12 15:44:20 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 | #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 fIncUpdate;
|
|---|
| 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 | typedef struct _RGNDATAHEADER_W {
|
|---|
| 120 | DWORD dwSize;
|
|---|
| 121 | DWORD iType;
|
|---|
| 122 | DWORD nCount;
|
|---|
| 123 | DWORD nRgnSize;
|
|---|
| 124 | RECT rcBound;
|
|---|
| 125 | } RGNDATAHEADER_W, *LPRGNDATAHEADER_W;
|
|---|
| 126 |
|
|---|
| 127 | typedef struct _RGNDATA_W {
|
|---|
| 128 | RGNDATAHEADER_W rdh;
|
|---|
| 129 | char Buffer[1];
|
|---|
| 130 | } RGNDATA_W , *PRGNDATA_W , *LPRGNDATA_W ;
|
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 | /* Xform FLAGS */
|
|---|
| 134 | #define MWT_IDENTITY_W 1
|
|---|
| 135 | #define MWT_LEFTMULTIPLY_W 2
|
|---|
| 136 | #define MWT_RIGHTMULTIPLY_W 3
|
|---|
| 137 |
|
|---|
| 138 | /* Mapping Modes */
|
|---|
| 139 | #define MM_TEXT_W 1
|
|---|
| 140 | #define MM_LOMETRIC_W 2
|
|---|
| 141 | #define MM_HIMETRIC_W 3
|
|---|
| 142 | #define MM_LOENGLISH_W 4
|
|---|
| 143 | #define MM_HIENGLISH_W 5
|
|---|
| 144 | #define MM_TWIPS_W 6
|
|---|
| 145 | #define MM_ISOTROPIC_W 7
|
|---|
| 146 | #define MM_ANISOTROPIC_W 8
|
|---|
| 147 |
|
|---|
| 148 | enum PS_Type { MICRO_CACHED, MICRO, NORMAL };
|
|---|
| 149 | enum HDC_Type{ TYPE_0, TYPE_1, TYPE_2, TYPE_3, TYPE_4 };
|
|---|
| 150 |
|
|---|
| 151 | typedef struct _DCData
|
|---|
| 152 | {
|
|---|
| 153 | HDC hdc;
|
|---|
| 154 | HWND hwnd;
|
|---|
| 155 | HPS hps;
|
|---|
| 156 |
|
|---|
| 157 | UINT lastBrushHandle;
|
|---|
| 158 | PVOID lastBrushObject;
|
|---|
| 159 | UINT lastPenHandle;
|
|---|
| 160 | pPenObject lastPenObject;
|
|---|
| 161 | UINT lastFontHandle;
|
|---|
| 162 | PVOID lastFontObject;
|
|---|
| 163 | UINT lastBitmapHandle;
|
|---|
| 164 | PVOID lastBitmapObject;
|
|---|
| 165 | UINT lastPaletteHandle;
|
|---|
| 166 | PVOID lastPaletteObject;
|
|---|
| 167 |
|
|---|
| 168 | UINT nullBitmapHandle;
|
|---|
| 169 |
|
|---|
| 170 | ULONG BkColor;
|
|---|
| 171 | ULONG TextColor;
|
|---|
| 172 | ULONG BkColor_PM;
|
|---|
| 173 | ULONG TextColor_PM;
|
|---|
| 174 |
|
|---|
| 175 | int BkMode;
|
|---|
| 176 | ULONG BkMode_PM;
|
|---|
| 177 |
|
|---|
| 178 | int ROP2Mode;
|
|---|
| 179 | int ROP2Mode_PM;
|
|---|
| 180 |
|
|---|
| 181 | unsigned isMemoryPS:1;
|
|---|
| 182 | unsigned isMetaPS:1;
|
|---|
| 183 | unsigned isPrinter:1;
|
|---|
| 184 | unsigned isFrameWindow:1;
|
|---|
| 185 | unsigned isOD_QUEUED:1;
|
|---|
| 186 | unsigned isOD_INFO:1;
|
|---|
| 187 | unsigned isClient:1;
|
|---|
| 188 | unsigned isClientArea:1;
|
|---|
| 189 | unsigned isLeftLeft:1;
|
|---|
| 190 | unsigned isTopTop:1;
|
|---|
| 191 | unsigned isWideLine:1;
|
|---|
| 192 | unsigned alignUpdateCP:1;
|
|---|
| 193 | unsigned isCacheable:1;
|
|---|
| 194 | unsigned penIsExtPen:1;
|
|---|
| 195 | unsigned isValid:1;
|
|---|
| 196 | unsigned inPath:1;
|
|---|
| 197 | unsigned isStartDoc:1;
|
|---|
| 198 | unsigned resetStockFonts:1;
|
|---|
| 199 | unsigned unused:14;
|
|---|
| 200 |
|
|---|
| 201 | ULONG MapMode;
|
|---|
| 202 | HBITMAP bitmapHandle;
|
|---|
| 203 | ULONG bitmapHeight;
|
|---|
| 204 | ULONG bitmapWidth;
|
|---|
| 205 | ULONG hMeta;
|
|---|
| 206 | PVOID pMetaFileObject;
|
|---|
| 207 | int polyFillMode;
|
|---|
| 208 | int arcDirection;
|
|---|
| 209 | int stretchBltMode;
|
|---|
| 210 | int graphicsMode;
|
|---|
| 211 | HRGN hrgnHDC;
|
|---|
| 212 |
|
|---|
| 213 | PS_Type psType;
|
|---|
| 214 |
|
|---|
| 215 | HDC_Type hdcType;
|
|---|
| 216 | USHORT usFiller;
|
|---|
| 217 | POINTL viewportOrg;
|
|---|
| 218 | double viewportXExt;
|
|---|
| 219 | double viewportYExt;
|
|---|
| 220 | POINTL windowOrg;
|
|---|
| 221 | SIZEL windowExt;
|
|---|
| 222 | HRGN hrgnVis;
|
|---|
| 223 | POINTL ptlOrigin;
|
|---|
| 224 | ULONG printPageHeight;
|
|---|
| 225 | PVOID printerObject;
|
|---|
| 226 |
|
|---|
| 227 | LONG taMode;
|
|---|
| 228 | XFORM_W xform;
|
|---|
| 229 |
|
|---|
| 230 | INT worldYDeltaFor1Pixel;
|
|---|
| 231 | INT worldXDeltaFor1Pixel;
|
|---|
| 232 | ULONG colorMode;
|
|---|
| 233 | PULONG pLogColorTable;
|
|---|
| 234 |
|
|---|
| 235 | ULONG lcidBitfield;
|
|---|
| 236 |
|
|---|
| 237 | HWND hwndRealize;
|
|---|
| 238 | ULONG cpeMap;
|
|---|
| 239 |
|
|---|
| 240 | LONG lTechnology;
|
|---|
| 241 |
|
|---|
| 242 | LONG lWndXExtSave, lWndYExtSave,
|
|---|
| 243 | lVwpXExtSave, lVwpYExtSave;
|
|---|
| 244 |
|
|---|
| 245 | int height;
|
|---|
| 246 |
|
|---|
| 247 | POINTL brushOrgPoint;
|
|---|
| 248 |
|
|---|
| 249 | PVOID pEnhMetaPalette;
|
|---|
| 250 | PVOID lpAbortProc;
|
|---|
| 251 | ULONG HPStoHDCInversionHeight;
|
|---|
| 252 |
|
|---|
| 253 | int saveLevel;
|
|---|
| 254 |
|
|---|
| 255 | struct _DCData *nextDCData;
|
|---|
| 256 | } tDCData, *pDCData;
|
|---|
| 257 |
|
|---|
| 258 | /*********************/
|
|---|
| 259 |
|
|---|
| 260 | BOOL APIENTRY GpiEnableYInversion (HPS hps, LONG lHeight);
|
|---|
| 261 | LONG APIENTRY GpiQueryYInversion (HPS hps);
|
|---|
| 262 | PVOID APIENTRY GpiAllocateDCData (HPS GpiH, ULONG size);
|
|---|
| 263 | PVOID APIENTRY GpiQueryDCData (HPS hps);
|
|---|
| 264 | HDC OPEN32API HPSToHDC (HWND hwnd, HPS hps, HDC hdc, PVOID);
|
|---|
| 265 | void OPEN32API DeleteHDC (HDC hdc);
|
|---|
| 266 | BOOL OPEN32API _O32_EndPaint (HWND hwnd, const PAINTSTRUCT_W *lpps);
|
|---|
| 267 | int OPEN32API _O32_GetUpdateRgn (HWND hwnd, HRGN hrgn, BOOL erase);
|
|---|
| 268 | ULONG OPEN32API _O32_GetRegionData (HRGN hrgn, ULONG count, PRGNDATA_W pData);
|
|---|
| 269 | BOOL OPEN32API _O32_DeleteObject (LHANDLE hgdiobj);
|
|---|
| 270 |
|
|---|
| 271 | #define FLOAT_TO_FIXED(x) ((FIXED) ((x) * 65536.0))
|
|---|
| 272 | #define MICRO_HPS_TO_HDC(x) ((x) & 0xFFFFFFFE)
|
|---|
| 273 |
|
|---|
| 274 | #define PMRECT_FROM_WINRECT( pmRect, winRect ) \
|
|---|
| 275 | { \
|
|---|
| 276 | (pmRect).xLeft = (winRect).left; \
|
|---|
| 277 | (pmRect).yBottom = (winRect).bottom; \
|
|---|
| 278 | (pmRect).xRight = (winRect).right; \
|
|---|
| 279 | (pmRect).yTop = (winRect).top; \
|
|---|
| 280 | }
|
|---|
| 281 |
|
|---|
| 282 | #define WINRECT_FROM_PMRECT( winRect, pmRect ) \
|
|---|
| 283 | { \
|
|---|
| 284 | (winRect).left = (pmRect).xLeft; \
|
|---|
| 285 | (winRect).top = (pmRect).yTop; \
|
|---|
| 286 | (winRect).right = (pmRect).xRight; \
|
|---|
| 287 | (winRect).bottom = (pmRect).yBottom; \
|
|---|
| 288 | }
|
|---|
| 289 |
|
|---|
| 290 | #define MEM_HPS_MAX 768
|
|---|
| 291 |
|
|---|
| 292 | const XFORM_W XFORMIdentity = { 1.0, 0.0, 0.0, 1.0, 0, 0 };
|
|---|
| 293 | const MATRIXLF matrixlfIdentity = { 0x10000, 0, 0, 0, 0x10000, 0, 0, 0, 0};
|
|---|
| 294 |
|
|---|
| 295 | BOOL setPageXForm(Win32BaseWindow *wnd, pDCData pHps);
|
|---|
| 296 | BOOL changePageXForm(Win32BaseWindow *wnd, pDCData pHps, PPOINTL pValue, int x, int y, PPOINTL pPrev);
|
|---|
| 297 | LONG clientHeight(Win32BaseWindow *wnd, HWND hwnd, pDCData pHps);
|
|---|
| 298 |
|
|---|
| 299 | void TestWideLine (pDCData pHps)
|
|---|
| 300 | {
|
|---|
| 301 | const LOGPEN_W *pLogPen;
|
|---|
| 302 |
|
|---|
| 303 | pHps->isWideLine = FALSE;
|
|---|
| 304 | pLogPen = pHps->penIsExtPen ?
|
|---|
| 305 | &(pHps->lastPenObject->ExtPen.logpen) :
|
|---|
| 306 | &(pHps->lastPenObject->Pen.logpen);
|
|---|
| 307 |
|
|---|
| 308 | if (((pLogPen->lopnStyle & PS_STYLE_MASK_W) != PS_NULL_W) &&
|
|---|
| 309 | (pLogPen->lopnWidth.x > 0))
|
|---|
| 310 | {
|
|---|
| 311 | POINTL aptl[2] = { 0, 0, pLogPen->lopnWidth.x, pLogPen->lopnWidth.x };
|
|---|
| 312 |
|
|---|
| 313 | GpiConvert(pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, aptl);
|
|---|
| 314 |
|
|---|
| 315 | ULONG dx = abs(aptl[0].x - aptl[1].x);
|
|---|
| 316 | ULONG dy = abs(aptl[0].y - aptl[1].y);
|
|---|
| 317 |
|
|---|
| 318 | pHps->isWideLine = (dx > 1) || (dy > 1);
|
|---|
| 319 | }
|
|---|
| 320 | }
|
|---|
| 321 |
|
|---|
| 322 | void Calculate1PixelDelta(pDCData pHps)
|
|---|
| 323 | {
|
|---|
| 324 | POINTL aptl[2] = {0, 0, 1, 1};
|
|---|
| 325 |
|
|---|
| 326 | GpiConvert(pHps->hps, CVTC_DEVICE, CVTC_WORLD, 2, aptl);
|
|---|
| 327 | pHps->worldYDeltaFor1Pixel = (int)(aptl[1].y - aptl[0].y);
|
|---|
| 328 | pHps->worldXDeltaFor1Pixel = (int)(aptl[1].x - aptl[0].x); // 171182
|
|---|
| 329 | }
|
|---|
| 330 |
|
|---|
| 331 | //******************************************************************************
|
|---|
| 332 |
|
|---|
| 333 | int setMapMode(Win32BaseWindow *wnd, pDCData pHps, int mode)
|
|---|
| 334 | {
|
|---|
| 335 | int prevMode = 0;
|
|---|
| 336 | ULONG flOptions;
|
|---|
| 337 |
|
|---|
| 338 | switch (mode)
|
|---|
| 339 | {
|
|---|
| 340 | case MM_HIENGLISH_W : flOptions = PU_HIENGLISH; break;
|
|---|
| 341 | case MM_LOENGLISH_W : flOptions = PU_LOENGLISH; break;
|
|---|
| 342 | case MM_HIMETRIC_W : flOptions = PU_HIMETRIC ; break;
|
|---|
| 343 | case MM_LOMETRIC_W : flOptions = PU_LOMETRIC ; break;
|
|---|
| 344 | case MM_TEXT_W : flOptions = PU_PELS ; break;
|
|---|
| 345 | case MM_TWIPS_W : flOptions = PU_TWIPS ; break;
|
|---|
| 346 | case MM_ANISOTROPIC_W: flOptions = PU_PELS ; break;
|
|---|
| 347 | case MM_ISOTROPIC_W : flOptions = PU_LOMETRIC ; break;
|
|---|
| 348 | default:
|
|---|
| 349 | // SET_ERROR_WIN(ERROR_INVALID_PARAMETER_W);
|
|---|
| 350 | return FALSE;
|
|---|
| 351 | }
|
|---|
| 352 |
|
|---|
| 353 | prevMode = pHps->MapMode; /* store previous mode */
|
|---|
| 354 | pHps->MapMode = mode;
|
|---|
| 355 |
|
|---|
| 356 | if (mode == MM_TEXT_W)
|
|---|
| 357 | {
|
|---|
| 358 | pHps->viewportXExt =
|
|---|
| 359 | pHps->viewportYExt = 1.0;
|
|---|
| 360 | pHps->windowExt.cx =
|
|---|
| 361 | pHps->windowExt.cy = 1;
|
|---|
| 362 | }
|
|---|
| 363 | else if (mode != MM_ANISOTROPIC_W)
|
|---|
| 364 | {
|
|---|
| 365 | RECTL rectl;
|
|---|
| 366 | SIZEL sizel;
|
|---|
| 367 | ULONG data[3];
|
|---|
| 368 |
|
|---|
| 369 | data[0] = flOptions;
|
|---|
| 370 | data[1] = data[2] = 0;
|
|---|
| 371 |
|
|---|
| 372 | if (DevEscape(pHps->hdc ? pHps->hdc : pHps->hps, DEVESC_SETPS, 12, (PBYTE)data, 0, 0) == DEVESC_ERROR)
|
|---|
| 373 | {
|
|---|
| 374 | // SET_ERROR_LAST();
|
|---|
| 375 | return 0;
|
|---|
| 376 | }
|
|---|
| 377 |
|
|---|
| 378 | GpiQueryPageViewport(pHps->hps, &rectl);
|
|---|
| 379 | pHps->viewportXExt = (double)rectl.xRight;
|
|---|
| 380 | pHps->viewportYExt = -(double)rectl.yTop;
|
|---|
| 381 |
|
|---|
| 382 | GreGetPageUnits(pHps->hdc? pHps->hdc : pHps->hps, &sizel);
|
|---|
| 383 | pHps->windowExt.cx = sizel.cx;
|
|---|
| 384 | pHps->windowExt.cy = sizel.cy;
|
|---|
| 385 |
|
|---|
| 386 | data[0] = PU_PELS;
|
|---|
| 387 | DevEscape(pHps->hdc ? pHps->hdc : pHps->hps, DEVESC_SETPS, 12, (PBYTE)data, 0, 0);
|
|---|
| 388 | }
|
|---|
| 389 |
|
|---|
| 390 | if (((prevMode != MM_ISOTROPIC_W) && (prevMode != MM_ANISOTROPIC_W)) &&
|
|---|
| 391 | ((mode == MM_ISOTROPIC_W) || (mode == MM_ANISOTROPIC_W)))
|
|---|
| 392 | {
|
|---|
| 393 | if (pHps->lWndXExtSave && pHps->lWndYExtSave)
|
|---|
| 394 | {
|
|---|
| 395 | changePageXForm (wnd, pHps, (PPOINTL)&pHps->windowExt,
|
|---|
| 396 | pHps->lWndXExtSave, pHps->lWndYExtSave, NULL );
|
|---|
| 397 | pHps->lWndXExtSave = pHps->lWndYExtSave = 0;
|
|---|
| 398 | }
|
|---|
| 399 | if (pHps->lVwpXExtSave && pHps->lVwpYExtSave)
|
|---|
| 400 | {
|
|---|
| 401 | changePageXForm (wnd, pHps, NULL,
|
|---|
| 402 | pHps->lVwpXExtSave, pHps->lVwpYExtSave, NULL );
|
|---|
| 403 | pHps->lVwpXExtSave = pHps->lVwpYExtSave = 0;
|
|---|
| 404 | }
|
|---|
| 405 | }
|
|---|
| 406 |
|
|---|
| 407 | setPageXForm(wnd, pHps);
|
|---|
| 408 |
|
|---|
| 409 | return prevMode;
|
|---|
| 410 | }
|
|---|
| 411 |
|
|---|
| 412 | BOOL setPageXForm(Win32BaseWindow *wnd, pDCData pHps)
|
|---|
| 413 | {
|
|---|
| 414 | MATRIXLF mlf;
|
|---|
| 415 | BOOL rc = TRUE;
|
|---|
| 416 |
|
|---|
| 417 | pHps->height = clientHeight(wnd, 0, pHps) - 1;
|
|---|
| 418 |
|
|---|
| 419 | double xScale = pHps->viewportXExt / (double)pHps->windowExt.cx;
|
|---|
| 420 | double yScale = pHps->viewportYExt / (double)pHps->windowExt.cy;
|
|---|
| 421 |
|
|---|
| 422 | mlf.fxM11 = FLOAT_TO_FIXED(xScale);
|
|---|
| 423 | mlf.fxM12 = 0;
|
|---|
| 424 | mlf.lM13 = 0;
|
|---|
| 425 | mlf.fxM21 = 0;
|
|---|
| 426 | mlf.fxM22 = FLOAT_TO_FIXED(yScale);
|
|---|
| 427 | mlf.lM23 = 0;
|
|---|
| 428 | mlf.lM31 = pHps->viewportOrg.x - (LONG)(pHps->windowOrg.x * xScale);
|
|---|
| 429 | mlf.lM32 = pHps->viewportOrg.y - (LONG)(pHps->windowOrg.y * yScale);
|
|---|
| 430 |
|
|---|
| 431 | pHps->isLeftLeft = mlf.fxM11 >= 0;
|
|---|
| 432 | pHps->isTopTop = mlf.fxM22 >= 0;
|
|---|
| 433 |
|
|---|
| 434 | BOOL bEnableYInversion = FALSE;
|
|---|
| 435 | if ((mlf.fxM22 > 0) ||
|
|---|
| 436 | ((pHps->graphicsMode == GM_ADVANCED_W) &&
|
|---|
| 437 | ((pHps->MapMode == MM_ANISOTROPIC_W) ||
|
|---|
| 438 | (pHps->MapMode == MM_ISOTROPIC_W))))
|
|---|
| 439 | {
|
|---|
| 440 | bEnableYInversion = TRUE;
|
|---|
| 441 | }
|
|---|
| 442 | else
|
|---|
| 443 | {
|
|---|
| 444 | bEnableYInversion = FALSE;
|
|---|
| 445 | mlf.lM32 = pHps->HPStoHDCInversionHeight + pHps->height - mlf.lM32;
|
|---|
| 446 | mlf.fxM22 = -mlf.fxM22;
|
|---|
| 447 | }
|
|---|
| 448 |
|
|---|
| 449 | if (!pHps->isMetaPS)
|
|---|
| 450 | // if ((!pHps->isMetaPS) ||
|
|---|
| 451 | // (pHps->pMetaFileObject && pHps->pMetaFileObject->isEnhanced()))
|
|---|
| 452 | rc = GpiSetDefaultViewMatrix(pHps->hps, 8, &mlf, TRANSFORM_REPLACE);
|
|---|
| 453 |
|
|---|
| 454 | if (bEnableYInversion)
|
|---|
| 455 | GpiEnableYInversion(pHps->hps, pHps->height + pHps->HPStoHDCInversionHeight);
|
|---|
| 456 | else
|
|---|
| 457 | GpiEnableYInversion(pHps->hps, 0);
|
|---|
| 458 |
|
|---|
| 459 | TestWideLine(pHps);
|
|---|
| 460 | Calculate1PixelDelta(pHps);
|
|---|
| 461 | return rc;
|
|---|
| 462 | }
|
|---|
| 463 |
|
|---|
| 464 | BOOL changePageXForm(Win32BaseWindow *wnd, pDCData pHps, PPOINTL pValue, int x, int y, PPOINTL pPrev)
|
|---|
| 465 | {
|
|---|
| 466 | BOOL result = FALSE;
|
|---|
| 467 |
|
|---|
| 468 | if (pValue)
|
|---|
| 469 | {
|
|---|
| 470 | if (pPrev)
|
|---|
| 471 | *pPrev = *pValue;
|
|---|
| 472 |
|
|---|
| 473 | if ((pValue->x == x) && (pValue->y == y)) {
|
|---|
| 474 | return TRUE;
|
|---|
| 475 | }
|
|---|
| 476 | pValue->x = x;
|
|---|
| 477 | pValue->y = y;
|
|---|
| 478 | }
|
|---|
| 479 | else
|
|---|
| 480 | {
|
|---|
| 481 | if (pPrev)
|
|---|
| 482 | {
|
|---|
| 483 | pPrev->x = (int)pHps->viewportXExt;
|
|---|
| 484 | pPrev->y = (int)pHps->viewportYExt;
|
|---|
| 485 | }
|
|---|
| 486 | pHps->viewportXExt = (double)x;
|
|---|
| 487 | pHps->viewportYExt = (double)y;
|
|---|
| 488 | }
|
|---|
| 489 |
|
|---|
| 490 | if (pHps->MapMode == MM_ISOTROPIC_W)
|
|---|
| 491 | {
|
|---|
| 492 | double xExt = fabs(pHps->viewportXExt);
|
|---|
| 493 | double yExt = fabs(pHps->viewportYExt);
|
|---|
| 494 | double sf = fabs((double)pHps->windowExt.cx / pHps->windowExt.cy);
|
|---|
| 495 |
|
|---|
| 496 | if (xExt > (yExt * sf))
|
|---|
| 497 | {
|
|---|
| 498 | xExt = yExt * sf;
|
|---|
| 499 |
|
|---|
| 500 | if ((double)LONG_MAX <= xExt) return (result);
|
|---|
| 501 |
|
|---|
| 502 | if (pHps->viewportXExt < 0.0)
|
|---|
| 503 | pHps->viewportXExt = -xExt;
|
|---|
| 504 | else
|
|---|
| 505 | pHps->viewportXExt = xExt;
|
|---|
| 506 | }
|
|---|
| 507 | else
|
|---|
| 508 | {
|
|---|
| 509 | yExt = xExt / sf;
|
|---|
| 510 |
|
|---|
| 511 | if ((double)LONG_MAX <= yExt) return (result);
|
|---|
| 512 |
|
|---|
| 513 | if (pHps->viewportYExt < 0.0)
|
|---|
| 514 | pHps->viewportYExt = -yExt;
|
|---|
| 515 | else
|
|---|
| 516 | pHps->viewportYExt = yExt;
|
|---|
| 517 | }
|
|---|
| 518 | }
|
|---|
| 519 | result = setPageXForm(wnd, pHps);
|
|---|
| 520 |
|
|---|
| 521 | return (result);
|
|---|
| 522 | }
|
|---|
| 523 |
|
|---|
| 524 | LONG clientHeight(Win32BaseWindow *wnd, HWND hwnd, pDCData pHps)
|
|---|
| 525 | {
|
|---|
| 526 | if ((hwnd == 0) && (pHps != 0))
|
|---|
| 527 | hwnd = pHps->hwnd;
|
|---|
| 528 |
|
|---|
| 529 | if ((hwnd != 0) || (pHps == 0))
|
|---|
| 530 | {
|
|---|
| 531 | if (wnd)
|
|---|
| 532 | return (wnd->getWindowHeight());
|
|---|
| 533 | else
|
|---|
| 534 | return OSLibQueryScreenHeight();
|
|---|
| 535 | }
|
|---|
| 536 | else if (pHps->bitmapHandle)
|
|---|
| 537 | {
|
|---|
| 538 | return pHps->bitmapHeight;
|
|---|
| 539 | }
|
|---|
| 540 | else if (pHps->isMetaPS)
|
|---|
| 541 | {
|
|---|
| 542 | return 0;
|
|---|
| 543 | }
|
|---|
| 544 | else if (pHps->isPrinter)
|
|---|
| 545 | {
|
|---|
| 546 | return pHps->printPageHeight;
|
|---|
| 547 | }
|
|---|
| 548 | else
|
|---|
| 549 | {
|
|---|
| 550 | return MEM_HPS_MAX;
|
|---|
| 551 | }
|
|---|
| 552 | }
|
|---|
| 553 |
|
|---|
| 554 | VOID removeClientArea(pDCData pHps)
|
|---|
| 555 | {
|
|---|
| 556 | pHps->isClient = FALSE;
|
|---|
| 557 |
|
|---|
| 558 | if (pHps->isClientArea)
|
|---|
| 559 | {
|
|---|
| 560 | pHps->isClientArea = FALSE;
|
|---|
| 561 | GreSetupDC(pHps->hps,
|
|---|
| 562 | pHps->hrgnVis,
|
|---|
| 563 | pHps->ptlOrigin.x,
|
|---|
| 564 | pHps->ptlOrigin.y,
|
|---|
| 565 | 0,
|
|---|
| 566 | SETUPDC_ORIGIN | SETUPDC_VISRGN | SETUPDC_RECALCCLIP);
|
|---|
| 567 | }
|
|---|
| 568 | }
|
|---|
| 569 |
|
|---|
| 570 | BOOL selectClientArea(Win32BaseWindow *wnd, pDCData pHps, PRECTL prclPaint)
|
|---|
| 571 | {
|
|---|
| 572 | RECTL rcl;
|
|---|
| 573 | HRGN hrgnRect;
|
|---|
| 574 | HWND hwnd;
|
|---|
| 575 |
|
|---|
| 576 | if (!wnd) return (FALSE);
|
|---|
| 577 |
|
|---|
| 578 | pHps->isClient = TRUE;
|
|---|
| 579 | hwnd = pHps->hwnd;
|
|---|
| 580 |
|
|---|
| 581 | rcl.xLeft = rcl.yBottom = 0;
|
|---|
| 582 | rcl.xRight = wnd->getWindowWidth();
|
|---|
| 583 | rcl.yTop = wnd->getWindowHeight();
|
|---|
| 584 |
|
|---|
| 585 | WinMapWindowPoints(hwnd, HWND_DESKTOP, (PPOINTL) &rcl, 2);
|
|---|
| 586 | pHps->ptlOrigin = *((PPOINTL) &rcl);
|
|---|
| 587 |
|
|---|
| 588 | if (pHps->hrgnVis == 0)
|
|---|
| 589 | pHps->hrgnVis = GreCreateRectRegion(pHps->hps, &rcl, 1);
|
|---|
| 590 |
|
|---|
| 591 | hrgnRect = GreCreateRectRegion(pHps->hps, &rcl, 1);
|
|---|
| 592 |
|
|---|
| 593 | if (!pHps->isClientArea)
|
|---|
| 594 | GreCopyClipRegion(pHps->hps, pHps->hrgnVis, 0, COPYCRGN_VISRGN);
|
|---|
| 595 |
|
|---|
| 596 | GreCombineRegion(pHps->hps, hrgnRect, pHps->hrgnVis, hrgnRect, CRGN_AND);
|
|---|
| 597 | GreSetupDC(pHps->hps,
|
|---|
| 598 | hrgnRect,
|
|---|
| 599 | rcl.xLeft,
|
|---|
| 600 | rcl.yBottom,
|
|---|
| 601 | prclPaint,
|
|---|
| 602 | SETUPDC_ORIGIN | SETUPDC_VISRGN | SETUPDC_RECALCCLIP);
|
|---|
| 603 |
|
|---|
| 604 | pHps->isClientArea = TRUE;
|
|---|
| 605 | GreDestroyRegion(pHps->hps, hrgnRect);
|
|---|
| 606 |
|
|---|
| 607 | return (TRUE);
|
|---|
| 608 | }
|
|---|
| 609 |
|
|---|
| 610 | HDC sendEraseBkgnd (Win32BaseWindow *wnd)
|
|---|
| 611 | {
|
|---|
| 612 | BOOL erased;
|
|---|
| 613 | HWND hwnd;
|
|---|
| 614 | HDC hdc;
|
|---|
| 615 | HPS hps;
|
|---|
| 616 | HRGN hrgnUpdate, hrgnOld, hrgnClip, hrgnCombined;
|
|---|
| 617 | RECTL rectl = { 1, 1, 2, 2 };
|
|---|
| 618 |
|
|---|
| 619 | hwnd = wnd->getOS2WindowHandle();
|
|---|
| 620 | hps = WinGetPS(hwnd);
|
|---|
| 621 |
|
|---|
| 622 | hrgnUpdate = GpiCreateRegion (hps, 1, &rectl);
|
|---|
| 623 | WinQueryUpdateRegion (hwnd, hrgnUpdate);
|
|---|
| 624 | hrgnClip = GpiQueryClipRegion (hps);
|
|---|
| 625 |
|
|---|
| 626 | if (hrgnClip == NULLHANDLE)
|
|---|
| 627 | {
|
|---|
| 628 | GpiSetClipRegion (hps, hrgnUpdate, &hrgnOld);
|
|---|
| 629 | }
|
|---|
| 630 | else
|
|---|
| 631 | {
|
|---|
| 632 | hrgnCombined = GpiCreateRegion (hps, 1, &rectl);
|
|---|
| 633 | GpiCombineRegion (hps, hrgnCombined, hrgnClip, hrgnUpdate, CRGN_AND);
|
|---|
| 634 | GpiSetClipRegion (hps, hrgnCombined, &hrgnOld);
|
|---|
| 635 | GpiDestroyRegion (hps, hrgnUpdate);
|
|---|
| 636 | GpiDestroyRegion (hps, hrgnClip);
|
|---|
| 637 | }
|
|---|
| 638 | if (hrgnOld != NULLHANDLE)
|
|---|
| 639 | GpiDestroyRegion (hps, hrgnOld);
|
|---|
| 640 |
|
|---|
| 641 | hdc = HPSToHDC (hwnd, hps, NULL, NULL);
|
|---|
| 642 |
|
|---|
| 643 | erased = wnd->MsgEraseBackGround (hdc);
|
|---|
| 644 |
|
|---|
| 645 | DeleteHDC (hdc);
|
|---|
| 646 | WinReleasePS (hps);
|
|---|
| 647 |
|
|---|
| 648 | return erased;
|
|---|
| 649 | }
|
|---|
| 650 |
|
|---|
| 651 | HDC WIN32API BeginPaint (HWND hWnd, PPAINTSTRUCT_W lpps)
|
|---|
| 652 | {
|
|---|
| 653 | HWND hwnd = hWnd ? hWnd : HWND_DESKTOP;
|
|---|
| 654 | pDCData pHps = NULLHANDLE;
|
|---|
| 655 | RECTL rect;
|
|---|
| 656 | HPS hPS_ownDC = NULLHANDLE;
|
|---|
| 657 |
|
|---|
| 658 | dprintf (("USER32: BeginPaint(%x)", hWnd));
|
|---|
| 659 |
|
|---|
| 660 | if ( !lpps )
|
|---|
| 661 | {
|
|---|
| 662 | // SET_ERROR_WIN( ERROR_INVALID_PARAMETER_W );
|
|---|
| 663 | return (HDC)NULLHANDLE;
|
|---|
| 664 | }
|
|---|
| 665 |
|
|---|
| 666 | USHORT sel = RestoreOS2FS();
|
|---|
| 667 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 668 |
|
|---|
| 669 | if ((hwnd != HWND_DESKTOP) && wnd->isOwnDC())
|
|---|
| 670 | {
|
|---|
| 671 | hPS_ownDC = wnd->getOwnDC();
|
|---|
| 672 | pHps = (pDCData)GpiQueryDCData(hPS_ownDC);
|
|---|
| 673 | if (!pHps)
|
|---|
| 674 | {
|
|---|
| 675 | // SET_ERROR_LAST();
|
|---|
| 676 | SetFS(sel);
|
|---|
| 677 | return (HDC)NULLHANDLE;
|
|---|
| 678 | }
|
|---|
| 679 | }
|
|---|
| 680 |
|
|---|
| 681 | HWND hwndClient = wnd->getOS2WindowHandle();
|
|---|
| 682 | HPS hps = WinBeginPaint(hwndClient, hPS_ownDC, &rect);
|
|---|
| 683 |
|
|---|
| 684 | if (!pHps)
|
|---|
| 685 | {
|
|---|
| 686 | HDC hdc = HPSToHDC (hwndClient, hps, NULL, NULL);
|
|---|
| 687 | pHps = (pDCData)GpiQueryDCData(hps);
|
|---|
| 688 | }
|
|---|
| 689 |
|
|---|
| 690 | if (wnd->isFrameWindow())
|
|---|
| 691 | {
|
|---|
| 692 | // WinSendMsg( hwnd, /* WM_DRAW */ 0x20D, (MPARAM)hps, MPVOID );
|
|---|
| 693 | selectClientArea(wnd, pHps, &rect);
|
|---|
| 694 | }
|
|---|
| 695 |
|
|---|
| 696 | if (hPS_ownDC == 0)
|
|---|
| 697 | setMapMode (wnd, pHps, MM_TEXT_W);
|
|---|
| 698 | else
|
|---|
| 699 | setPageXForm (wnd, pHps);
|
|---|
| 700 |
|
|---|
| 701 | pHps->hdcType = TYPE_3;
|
|---|
| 702 | lpps->hdc = (HDC)hps;
|
|---|
| 703 | lpps->fErase = !wnd->MsgEraseBackGround(lpps->hdc);
|
|---|
| 704 |
|
|---|
| 705 | if (!hPS_ownDC)
|
|---|
| 706 | {
|
|---|
| 707 | long height = wnd->getWindowHeight();
|
|---|
| 708 | rect.yTop = height - rect.yTop;
|
|---|
| 709 | rect.yBottom = height - rect.yBottom;
|
|---|
| 710 | }
|
|---|
| 711 | else
|
|---|
| 712 | {
|
|---|
| 713 | rect.yTop--;
|
|---|
| 714 | rect.yBottom--;
|
|---|
| 715 | GpiConvert(pHps->hps, CVTC_DEVICE, CVTC_WORLD, 2, (PPOINTL)&rect);
|
|---|
| 716 | }
|
|---|
| 717 |
|
|---|
| 718 | WINRECT_FROM_PMRECT(lpps->rcPaint, rect);
|
|---|
| 719 |
|
|---|
| 720 | SetFS(sel);
|
|---|
| 721 | return (HDC)pHps->hps;
|
|---|
| 722 | }
|
|---|
| 723 |
|
|---|
| 724 | BOOL WIN32API EndPaint (HWND hwnd, const PAINTSTRUCT_W *pPaint)
|
|---|
| 725 | {
|
|---|
| 726 | dprintf (("USER32: EndPaint(%x)", hwnd));
|
|---|
| 727 |
|
|---|
| 728 | if (!pPaint || !pPaint->hdc )
|
|---|
| 729 | return TRUE;
|
|---|
| 730 |
|
|---|
| 731 | USHORT sel = RestoreOS2FS();
|
|---|
| 732 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 733 |
|
|---|
| 734 | if (!wnd) goto exit;
|
|---|
| 735 |
|
|---|
| 736 | if (wnd->isOwnDC())
|
|---|
| 737 | {
|
|---|
| 738 | pDCData pHps = (pDCData)GpiQueryDCData((HPS)pPaint->hdc);
|
|---|
| 739 | if (pHps && (pHps->hdcType == TYPE_3))
|
|---|
| 740 | {
|
|---|
| 741 | removeClientArea (pHps);
|
|---|
| 742 | WinEndPaint (pHps->hps);
|
|---|
| 743 | }
|
|---|
| 744 | }
|
|---|
| 745 | else
|
|---|
| 746 | {
|
|---|
| 747 | _O32_EndPaint (HWND_DESKTOP, pPaint);
|
|---|
| 748 | }
|
|---|
| 749 |
|
|---|
| 750 | exit:
|
|---|
| 751 | SetFS(sel);
|
|---|
| 752 | return TRUE;
|
|---|
| 753 | }
|
|---|
| 754 |
|
|---|
| 755 | BOOL WIN32API GetUpdateRect (HWND hwnd, LPRECT pRect, BOOL erase)
|
|---|
| 756 | {
|
|---|
| 757 | if (hwnd)
|
|---|
| 758 | {
|
|---|
| 759 | // SET_ERROR_WIN( ERROR_INVALID_HANDLE_W );
|
|---|
| 760 | return FALSE;
|
|---|
| 761 | }
|
|---|
| 762 |
|
|---|
| 763 | RECTL rectl;
|
|---|
| 764 | USHORT sel = RestoreOS2FS();
|
|---|
| 765 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 766 |
|
|---|
| 767 | BOOL updateRegionExists = WinQueryUpdateRect (hwnd, pRect ? &rectl : NULL);
|
|---|
| 768 | if (!pRect) {
|
|---|
| 769 | SetFS(sel);
|
|---|
| 770 | return (updateRegionExists);
|
|---|
| 771 | }
|
|---|
| 772 |
|
|---|
| 773 | if (updateRegionExists)
|
|---|
| 774 | {
|
|---|
| 775 | if (wnd->isOwnDC())
|
|---|
| 776 | {
|
|---|
| 777 | pDCData pHps = NULL;
|
|---|
| 778 | pHps = (pDCData)GpiQueryDCData(wnd->getOwnDC());
|
|---|
| 779 | if (!pHps)
|
|---|
| 780 | {
|
|---|
| 781 | // SET_ERROR_WIN(ERROR_INVALID_HANDLE_W);
|
|---|
| 782 | SetFS(sel);
|
|---|
| 783 | return FALSE;
|
|---|
| 784 | }
|
|---|
| 785 | GpiConvert (pHps->hps, CVTC_DEVICE, CVTC_WORLD, 2, (PPOINTL)&rectl);
|
|---|
| 786 | }
|
|---|
| 787 | else
|
|---|
| 788 | {
|
|---|
| 789 | long height = wnd->getWindowHeight();
|
|---|
| 790 | rectl.yTop = height - rectl.yTop;
|
|---|
| 791 | rectl.yBottom = height - rectl.yBottom;
|
|---|
| 792 | }
|
|---|
| 793 |
|
|---|
| 794 | if (pRect)
|
|---|
| 795 | WINRECT_FROM_PMRECT (*pRect, rectl);
|
|---|
| 796 |
|
|---|
| 797 | if (erase)
|
|---|
| 798 | sendEraseBkgnd (wnd);
|
|---|
| 799 | }
|
|---|
| 800 | else
|
|---|
| 801 | {
|
|---|
| 802 | if (pRect)
|
|---|
| 803 | pRect->left = pRect->top = pRect->right = pRect->bottom = 0;
|
|---|
| 804 | }
|
|---|
| 805 |
|
|---|
| 806 | SetFS(sel);
|
|---|
| 807 | return updateRegionExists;
|
|---|
| 808 | }
|
|---|
| 809 |
|
|---|
| 810 | int WIN32API GetUpdateRgn (HWND hwnd, HRGN hrgn, BOOL erase)
|
|---|
| 811 | {
|
|---|
| 812 | USHORT sel = RestoreOS2FS();
|
|---|
| 813 | LONG Complexity;
|
|---|
| 814 |
|
|---|
| 815 | Complexity = _O32_GetUpdateRgn (hwnd, hrgn, FALSE);
|
|---|
| 816 | if (erase && (Complexity > NULLREGION_W)) {
|
|---|
| 817 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 818 | sendEraseBkgnd (wnd);
|
|---|
| 819 | }
|
|---|
| 820 |
|
|---|
| 821 | SetFS(sel);
|
|---|
| 822 | return Complexity;
|
|---|
| 823 | }
|
|---|
| 824 |
|
|---|
| 825 | // This implementation of GetDCEx supports
|
|---|
| 826 | // DCX_WINDOW
|
|---|
| 827 | // DCX_CACHE
|
|---|
| 828 | // DCX_EXCLUDERGN (complex regions allowed)
|
|---|
| 829 | // DCX_INTERSECTRGN (complex regions allowed)
|
|---|
| 830 |
|
|---|
| 831 | HDC WIN32API GetDCEx (HWND hwnd, HRGN hrgn, ULONG flags)
|
|---|
| 832 | {
|
|---|
| 833 | USHORT sel = RestoreOS2FS();
|
|---|
| 834 | Win32BaseWindow *wnd = NULL;
|
|---|
| 835 | HWND hWindow;
|
|---|
| 836 | BOOL success;
|
|---|
| 837 | pDCData pHps = NULL;
|
|---|
| 838 | HPS hps = NULLHANDLE;
|
|---|
| 839 | BOOL drawingAllowed = TRUE;
|
|---|
| 840 | BOOL isWindowOwnDC;
|
|---|
| 841 | BOOL creatingOwnDC = FALSE;
|
|---|
| 842 | PS_Type psType;
|
|---|
| 843 |
|
|---|
| 844 | if (hwnd)
|
|---|
| 845 | {
|
|---|
| 846 | wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 847 | if (flags & DCX_WINDOW_W)
|
|---|
| 848 | hWindow = wnd->getOS2FrameWindowHandle();
|
|---|
| 849 | else
|
|---|
| 850 | hWindow = wnd->getOS2WindowHandle();
|
|---|
| 851 | }
|
|---|
| 852 | else
|
|---|
| 853 | hWindow = HWND_DESKTOP;
|
|---|
| 854 |
|
|---|
| 855 | dprintf (("User32: GetDCEx hwnd %x (%x %x) -> wnd %x", hwnd, hrgn, flags, wnd));
|
|---|
| 856 |
|
|---|
| 857 | isWindowOwnDC = (((hWindow == HWND_DESKTOP) ? FALSE : wnd->isOwnDC())
|
|---|
| 858 | && !(flags & DCX_CACHE_W));
|
|---|
| 859 | if (isWindowOwnDC)
|
|---|
| 860 | {
|
|---|
| 861 | hps = wnd->getOwnDC();
|
|---|
| 862 | if (hps)
|
|---|
| 863 | {
|
|---|
| 864 | pDCData pHps = (pDCData)GpiQueryDCData (hps);
|
|---|
| 865 | if (!pHps)
|
|---|
| 866 | goto error;
|
|---|
| 867 |
|
|---|
| 868 | if (flags & DCX_WINDOW_W)
|
|---|
| 869 | removeClientArea (pHps);
|
|---|
| 870 | else
|
|---|
| 871 | selectClientArea (wnd, pHps, 0);
|
|---|
| 872 |
|
|---|
| 873 | setPageXForm (wnd, pHps);
|
|---|
| 874 |
|
|---|
| 875 | pHps->hdcType = TYPE_1;
|
|---|
| 876 | SetFS(sel);
|
|---|
| 877 | return (HDC)hps;
|
|---|
| 878 | }
|
|---|
| 879 | else
|
|---|
| 880 | creatingOwnDC = TRUE;
|
|---|
| 881 | }
|
|---|
| 882 |
|
|---|
| 883 | if (isWindowOwnDC)
|
|---|
| 884 | {
|
|---|
| 885 | SIZEL sizel = {0,0};
|
|---|
| 886 | hps = GpiCreatePS (WinQueryAnchorBlock (hWindow),
|
|---|
| 887 | WinOpenWindowDC (hWindow),
|
|---|
| 888 | &sizel, PU_PELS | GPIT_MICRO | GPIA_ASSOC );
|
|---|
| 889 | psType = MICRO;
|
|---|
| 890 | }
|
|---|
| 891 | else
|
|---|
| 892 | {
|
|---|
| 893 | if (hWindow == HWND_DESKTOP)
|
|---|
| 894 | hps = WinGetScreenPS (hWindow);
|
|---|
| 895 | else
|
|---|
| 896 | hps = WinGetPS (hWindow);
|
|---|
| 897 |
|
|---|
| 898 | psType = MICRO_CACHED;
|
|---|
| 899 | }
|
|---|
| 900 |
|
|---|
| 901 | if (!hps)
|
|---|
| 902 | goto error;
|
|---|
| 903 |
|
|---|
| 904 | HPSToHDC (hWindow, hps, NULL, NULL);
|
|---|
| 905 | pHps = (pDCData)GpiQueryDCData (hps);
|
|---|
| 906 |
|
|---|
| 907 | if (!(flags & DCX_WINDOW_W)) {
|
|---|
| 908 | if (selectClientArea (wnd, pHps, 0))
|
|---|
| 909 | setMapMode (wnd, pHps, MM_TEXT_W);
|
|---|
| 910 | }
|
|---|
| 911 |
|
|---|
| 912 | if ((flags & DCX_EXCLUDERGN_W) || (flags & DCX_INTERSECTRGN_W))
|
|---|
| 913 | {
|
|---|
| 914 | ULONG BytesNeeded;
|
|---|
| 915 | PRGNDATA_W RgnData;
|
|---|
| 916 | PRECTL pr;
|
|---|
| 917 | int i;
|
|---|
| 918 |
|
|---|
| 919 | if (!hrgn)
|
|---|
| 920 | goto error;
|
|---|
| 921 |
|
|---|
| 922 | BytesNeeded = _O32_GetRegionData (hrgn, 0, NULL);
|
|---|
| 923 | RgnData = (PRGNDATA_W)_alloca (BytesNeeded);
|
|---|
| 924 | if (RgnData == NULL)
|
|---|
| 925 | goto error;
|
|---|
| 926 | _O32_GetRegionData (hrgn, BytesNeeded, RgnData);
|
|---|
| 927 |
|
|---|
| 928 | i = RgnData->rdh.nCount;
|
|---|
| 929 | pr = (PRECTL)(RgnData->Buffer);
|
|---|
| 930 |
|
|---|
| 931 | success = TRUE;
|
|---|
| 932 | if (flags & DCX_EXCLUDERGN_W)
|
|---|
| 933 | for (; (i > 0) && success; i--, pr++)
|
|---|
| 934 | success &= GpiExcludeClipRectangle (pHps->hps, pr);
|
|---|
| 935 | else
|
|---|
| 936 | for (; (i > 0) && success; i--, pr++)
|
|---|
| 937 | success &= GpiIntersectClipRectangle (pHps->hps, pr);
|
|---|
| 938 | if (!success)
|
|---|
| 939 | goto error;
|
|---|
| 940 | }
|
|---|
| 941 |
|
|---|
| 942 | if (creatingOwnDC)
|
|---|
| 943 | wnd->setOwnDC ((HDC)hps);
|
|---|
| 944 |
|
|---|
| 945 | pHps->psType = psType;
|
|---|
| 946 | pHps->hdcType = TYPE_1;
|
|---|
| 947 | GpiSetDrawControl (hps, DCTL_DISPLAY, drawingAllowed ? DCTL_ON : DCTL_OFF);
|
|---|
| 948 |
|
|---|
| 949 | SetFS(sel);
|
|---|
| 950 | return (HDC)pHps->hps;
|
|---|
| 951 |
|
|---|
| 952 | error:
|
|---|
| 953 | /* Something went wrong; clean up
|
|---|
| 954 | */
|
|---|
| 955 | if (pHps)
|
|---|
| 956 | {
|
|---|
| 957 | if (pHps->hps)
|
|---|
| 958 | {
|
|---|
| 959 | if(pHps->psType == MICRO_CACHED)
|
|---|
| 960 | WinReleasePS(pHps->hps);
|
|---|
| 961 | else
|
|---|
| 962 | GpiDestroyPS(pHps->hps);
|
|---|
| 963 | }
|
|---|
| 964 |
|
|---|
| 965 | if (pHps->hdc) DevCloseDC(pHps->hdc);
|
|---|
| 966 | if (pHps->hrgnHDC) GpiDestroyRegion(pHps->hps, pHps->hrgnHDC);
|
|---|
| 967 |
|
|---|
| 968 | _O32_DeleteObject (pHps->nullBitmapHandle);
|
|---|
| 969 | }
|
|---|
| 970 | // SET_ERROR_LAST();
|
|---|
| 971 | SetFS(sel);
|
|---|
| 972 | return NULL;
|
|---|
| 973 | }
|
|---|
| 974 |
|
|---|
| 975 | HDC WIN32API GetDC (HWND hwnd)
|
|---|
| 976 | {
|
|---|
| 977 | return GetDCEx (hwnd, NULL, 0);
|
|---|
| 978 | }
|
|---|
| 979 |
|
|---|
| 980 |
|
|---|
| 981 | //******************************************************************************
|
|---|
| 982 | //******************************************************************************
|
|---|
| 983 |
|
|---|