| 1 | /* $Id: dc.cpp,v 1.4 1999-09-13 16:13:46 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 | int OPEN32API _O32_ReleaseDC (HWND hwnd, HDC hdc);
|
|---|
| 271 |
|
|---|
| 272 | #ifndef DEVESC_SETPS
|
|---|
| 273 | #define DEVESC_SETPS 49149L
|
|---|
| 274 | #endif
|
|---|
| 275 |
|
|---|
| 276 | #define FLOAT_TO_FIXED(x) ((FIXED) ((x) * 65536.0))
|
|---|
| 277 | #define MICRO_HPS_TO_HDC(x) ((x) & 0xFFFFFFFE)
|
|---|
| 278 |
|
|---|
| 279 | #define PMRECT_FROM_WINRECT( pmRect, winRect ) \
|
|---|
| 280 | { \
|
|---|
| 281 | (pmRect).xLeft = (winRect).left; \
|
|---|
| 282 | (pmRect).yBottom = (winRect).bottom; \
|
|---|
| 283 | (pmRect).xRight = (winRect).right; \
|
|---|
| 284 | (pmRect).yTop = (winRect).top; \
|
|---|
| 285 | }
|
|---|
| 286 |
|
|---|
| 287 | #define WINRECT_FROM_PMRECT( winRect, pmRect ) \
|
|---|
| 288 | { \
|
|---|
| 289 | (winRect).left = (pmRect).xLeft; \
|
|---|
| 290 | (winRect).top = (pmRect).yTop; \
|
|---|
| 291 | (winRect).right = (pmRect).xRight; \
|
|---|
| 292 | (winRect).bottom = (pmRect).yBottom; \
|
|---|
| 293 | }
|
|---|
| 294 |
|
|---|
| 295 | #define MEM_HPS_MAX 768
|
|---|
| 296 |
|
|---|
| 297 | const XFORM_W XFORMIdentity = { 1.0, 0.0, 0.0, 1.0, 0, 0 };
|
|---|
| 298 | const MATRIXLF matrixlfIdentity = { 0x10000, 0, 0, 0, 0x10000, 0, 0, 0, 0};
|
|---|
| 299 |
|
|---|
| 300 | BOOL setPageXForm(Win32BaseWindow *wnd, pDCData pHps);
|
|---|
| 301 | BOOL changePageXForm(Win32BaseWindow *wnd, pDCData pHps, PPOINTL pValue, int x, int y, PPOINTL pPrev);
|
|---|
| 302 | LONG clientHeight(Win32BaseWindow *wnd, HWND hwnd, pDCData pHps);
|
|---|
| 303 |
|
|---|
| 304 | void TestWideLine (pDCData pHps)
|
|---|
| 305 | {
|
|---|
| 306 | const LOGPEN_W *pLogPen;
|
|---|
| 307 |
|
|---|
| 308 | pHps->isWideLine = FALSE;
|
|---|
| 309 | pLogPen = pHps->penIsExtPen ?
|
|---|
| 310 | &(pHps->lastPenObject->ExtPen.logpen) :
|
|---|
| 311 | &(pHps->lastPenObject->Pen.logpen);
|
|---|
| 312 |
|
|---|
| 313 | if (((pLogPen->lopnStyle & PS_STYLE_MASK_W) != PS_NULL_W) &&
|
|---|
| 314 | (pLogPen->lopnWidth.x > 0))
|
|---|
| 315 | {
|
|---|
| 316 | POINTL aptl[2] = { 0, 0, pLogPen->lopnWidth.x, pLogPen->lopnWidth.x };
|
|---|
| 317 |
|
|---|
| 318 | GpiConvert(pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, aptl);
|
|---|
| 319 |
|
|---|
| 320 | ULONG dx = abs(aptl[0].x - aptl[1].x);
|
|---|
| 321 | ULONG dy = abs(aptl[0].y - aptl[1].y);
|
|---|
| 322 |
|
|---|
| 323 | pHps->isWideLine = (dx > 1) || (dy > 1);
|
|---|
| 324 | }
|
|---|
| 325 | }
|
|---|
| 326 |
|
|---|
| 327 | void Calculate1PixelDelta(pDCData pHps)
|
|---|
| 328 | {
|
|---|
| 329 | POINTL aptl[2] = {0, 0, 1, 1};
|
|---|
| 330 |
|
|---|
| 331 | GpiConvert(pHps->hps, CVTC_DEVICE, CVTC_WORLD, 2, aptl);
|
|---|
| 332 | pHps->worldYDeltaFor1Pixel = (int)(aptl[1].y - aptl[0].y);
|
|---|
| 333 | pHps->worldXDeltaFor1Pixel = (int)(aptl[1].x - aptl[0].x); // 171182
|
|---|
| 334 | }
|
|---|
| 335 |
|
|---|
| 336 | //******************************************************************************
|
|---|
| 337 |
|
|---|
| 338 | int setMapMode(Win32BaseWindow *wnd, pDCData pHps, int mode)
|
|---|
| 339 | {
|
|---|
| 340 | int prevMode = 0;
|
|---|
| 341 | ULONG flOptions;
|
|---|
| 342 |
|
|---|
| 343 | switch (mode)
|
|---|
| 344 | {
|
|---|
| 345 | case MM_HIENGLISH_W : flOptions = PU_HIENGLISH; break;
|
|---|
| 346 | case MM_LOENGLISH_W : flOptions = PU_LOENGLISH; break;
|
|---|
| 347 | case MM_HIMETRIC_W : flOptions = PU_HIMETRIC ; break;
|
|---|
| 348 | case MM_LOMETRIC_W : flOptions = PU_LOMETRIC ; break;
|
|---|
| 349 | case MM_TEXT_W : flOptions = PU_PELS ; break;
|
|---|
| 350 | case MM_TWIPS_W : flOptions = PU_TWIPS ; break;
|
|---|
| 351 | case MM_ANISOTROPIC_W: flOptions = PU_PELS ; break;
|
|---|
| 352 | case MM_ISOTROPIC_W : flOptions = PU_LOMETRIC ; break;
|
|---|
| 353 | default:
|
|---|
| 354 | // SET_ERROR_WIN(ERROR_INVALID_PARAMETER_W);
|
|---|
| 355 | return FALSE;
|
|---|
| 356 | }
|
|---|
| 357 |
|
|---|
| 358 | prevMode = pHps->MapMode; /* store previous mode */
|
|---|
| 359 | pHps->MapMode = mode;
|
|---|
| 360 |
|
|---|
| 361 | if (mode == MM_TEXT_W)
|
|---|
| 362 | {
|
|---|
| 363 | pHps->viewportXExt =
|
|---|
| 364 | pHps->viewportYExt = 1.0;
|
|---|
| 365 | pHps->windowExt.cx =
|
|---|
| 366 | pHps->windowExt.cy = 1;
|
|---|
| 367 | }
|
|---|
| 368 | else if (mode != MM_ANISOTROPIC_W)
|
|---|
| 369 | {
|
|---|
| 370 | RECTL rectl;
|
|---|
| 371 | SIZEL sizel;
|
|---|
| 372 | ULONG data[3];
|
|---|
| 373 |
|
|---|
| 374 | data[0] = flOptions;
|
|---|
| 375 | data[1] = data[2] = 0;
|
|---|
| 376 |
|
|---|
| 377 | if (DevEscape(pHps->hdc ? pHps->hdc : pHps->hps, DEVESC_SETPS, 12, (PBYTE)data, 0, 0) == DEVESC_ERROR)
|
|---|
| 378 | {
|
|---|
| 379 | // SET_ERROR_LAST();
|
|---|
| 380 | return 0;
|
|---|
| 381 | }
|
|---|
| 382 |
|
|---|
| 383 | GpiQueryPageViewport(pHps->hps, &rectl);
|
|---|
| 384 | pHps->viewportXExt = (double)rectl.xRight;
|
|---|
| 385 | pHps->viewportYExt = -(double)rectl.yTop;
|
|---|
| 386 |
|
|---|
| 387 | GreGetPageUnits(pHps->hdc? pHps->hdc : pHps->hps, &sizel);
|
|---|
| 388 | pHps->windowExt.cx = sizel.cx;
|
|---|
| 389 | pHps->windowExt.cy = sizel.cy;
|
|---|
| 390 |
|
|---|
| 391 | data[0] = PU_PELS;
|
|---|
| 392 | DevEscape(pHps->hdc ? pHps->hdc : pHps->hps, DEVESC_SETPS, 12, (PBYTE)data, 0, 0);
|
|---|
| 393 | }
|
|---|
| 394 |
|
|---|
| 395 | if (((prevMode != MM_ISOTROPIC_W) && (prevMode != MM_ANISOTROPIC_W)) &&
|
|---|
| 396 | ((mode == MM_ISOTROPIC_W) || (mode == MM_ANISOTROPIC_W)))
|
|---|
| 397 | {
|
|---|
| 398 | if (pHps->lWndXExtSave && pHps->lWndYExtSave)
|
|---|
| 399 | {
|
|---|
| 400 | changePageXForm (wnd, pHps, (PPOINTL)&pHps->windowExt,
|
|---|
| 401 | pHps->lWndXExtSave, pHps->lWndYExtSave, NULL );
|
|---|
| 402 | pHps->lWndXExtSave = pHps->lWndYExtSave = 0;
|
|---|
| 403 | }
|
|---|
| 404 | if (pHps->lVwpXExtSave && pHps->lVwpYExtSave)
|
|---|
| 405 | {
|
|---|
| 406 | changePageXForm (wnd, pHps, NULL,
|
|---|
| 407 | pHps->lVwpXExtSave, pHps->lVwpYExtSave, NULL );
|
|---|
| 408 | pHps->lVwpXExtSave = pHps->lVwpYExtSave = 0;
|
|---|
| 409 | }
|
|---|
| 410 | }
|
|---|
| 411 |
|
|---|
| 412 | setPageXForm(wnd, pHps);
|
|---|
| 413 |
|
|---|
| 414 | return prevMode;
|
|---|
| 415 | }
|
|---|
| 416 |
|
|---|
| 417 | BOOL setPageXForm(Win32BaseWindow *wnd, pDCData pHps)
|
|---|
| 418 | {
|
|---|
| 419 | MATRIXLF mlf;
|
|---|
| 420 | BOOL rc = TRUE;
|
|---|
| 421 |
|
|---|
| 422 | pHps->height = clientHeight(wnd, 0, pHps) - 1;
|
|---|
| 423 |
|
|---|
| 424 | double xScale = pHps->viewportXExt / (double)pHps->windowExt.cx;
|
|---|
| 425 | double yScale = pHps->viewportYExt / (double)pHps->windowExt.cy;
|
|---|
| 426 |
|
|---|
| 427 | mlf.fxM11 = FLOAT_TO_FIXED(xScale);
|
|---|
| 428 | mlf.fxM12 = 0;
|
|---|
| 429 | mlf.lM13 = 0;
|
|---|
| 430 | mlf.fxM21 = 0;
|
|---|
| 431 | mlf.fxM22 = FLOAT_TO_FIXED(yScale);
|
|---|
| 432 | mlf.lM23 = 0;
|
|---|
| 433 | mlf.lM31 = pHps->viewportOrg.x - (LONG)(pHps->windowOrg.x * xScale);
|
|---|
| 434 | mlf.lM32 = pHps->viewportOrg.y - (LONG)(pHps->windowOrg.y * yScale);
|
|---|
| 435 |
|
|---|
| 436 | pHps->isLeftLeft = mlf.fxM11 >= 0;
|
|---|
| 437 | pHps->isTopTop = mlf.fxM22 >= 0;
|
|---|
| 438 |
|
|---|
| 439 | BOOL bEnableYInversion = FALSE;
|
|---|
| 440 | if ((mlf.fxM22 > 0) ||
|
|---|
| 441 | ((pHps->graphicsMode == GM_ADVANCED_W) &&
|
|---|
| 442 | ((pHps->MapMode == MM_ANISOTROPIC_W) ||
|
|---|
| 443 | (pHps->MapMode == MM_ISOTROPIC_W))))
|
|---|
| 444 | {
|
|---|
| 445 | bEnableYInversion = TRUE;
|
|---|
| 446 | }
|
|---|
| 447 | else
|
|---|
| 448 | {
|
|---|
| 449 | bEnableYInversion = FALSE;
|
|---|
| 450 | mlf.lM32 = pHps->HPStoHDCInversionHeight + pHps->height - mlf.lM32;
|
|---|
| 451 | mlf.fxM22 = -mlf.fxM22;
|
|---|
| 452 | }
|
|---|
| 453 |
|
|---|
| 454 | if (!pHps->isMetaPS)
|
|---|
| 455 | // if ((!pHps->isMetaPS) ||
|
|---|
| 456 | // (pHps->pMetaFileObject && pHps->pMetaFileObject->isEnhanced()))
|
|---|
| 457 | rc = GpiSetDefaultViewMatrix(pHps->hps, 8, &mlf, TRANSFORM_REPLACE);
|
|---|
| 458 |
|
|---|
| 459 | if (bEnableYInversion)
|
|---|
| 460 | GpiEnableYInversion(pHps->hps, pHps->height + pHps->HPStoHDCInversionHeight);
|
|---|
| 461 | else
|
|---|
| 462 | GpiEnableYInversion(pHps->hps, 0);
|
|---|
| 463 |
|
|---|
| 464 | TestWideLine(pHps);
|
|---|
| 465 | Calculate1PixelDelta(pHps);
|
|---|
| 466 | return rc;
|
|---|
| 467 | }
|
|---|
| 468 |
|
|---|
| 469 | BOOL changePageXForm(Win32BaseWindow *wnd, pDCData pHps, PPOINTL pValue, int x, int y, PPOINTL pPrev)
|
|---|
| 470 | {
|
|---|
| 471 | BOOL result = FALSE;
|
|---|
| 472 |
|
|---|
| 473 | if (pValue)
|
|---|
| 474 | {
|
|---|
| 475 | if (pPrev)
|
|---|
| 476 | *pPrev = *pValue;
|
|---|
| 477 |
|
|---|
| 478 | if ((pValue->x == x) && (pValue->y == y)) {
|
|---|
| 479 | return TRUE;
|
|---|
| 480 | }
|
|---|
| 481 | pValue->x = x;
|
|---|
| 482 | pValue->y = y;
|
|---|
| 483 | }
|
|---|
| 484 | else
|
|---|
| 485 | {
|
|---|
| 486 | if (pPrev)
|
|---|
| 487 | {
|
|---|
| 488 | pPrev->x = (int)pHps->viewportXExt;
|
|---|
| 489 | pPrev->y = (int)pHps->viewportYExt;
|
|---|
| 490 | }
|
|---|
| 491 | pHps->viewportXExt = (double)x;
|
|---|
| 492 | pHps->viewportYExt = (double)y;
|
|---|
| 493 | }
|
|---|
| 494 |
|
|---|
| 495 | if (pHps->MapMode == MM_ISOTROPIC_W)
|
|---|
| 496 | {
|
|---|
| 497 | double xExt = fabs(pHps->viewportXExt);
|
|---|
| 498 | double yExt = fabs(pHps->viewportYExt);
|
|---|
| 499 | double sf = fabs((double)pHps->windowExt.cx / pHps->windowExt.cy);
|
|---|
| 500 |
|
|---|
| 501 | if (xExt > (yExt * sf))
|
|---|
| 502 | {
|
|---|
| 503 | xExt = yExt * sf;
|
|---|
| 504 |
|
|---|
| 505 | if ((double)LONG_MAX <= xExt) return (result);
|
|---|
| 506 |
|
|---|
| 507 | if (pHps->viewportXExt < 0.0)
|
|---|
| 508 | pHps->viewportXExt = -xExt;
|
|---|
| 509 | else
|
|---|
| 510 | pHps->viewportXExt = xExt;
|
|---|
| 511 | }
|
|---|
| 512 | else
|
|---|
| 513 | {
|
|---|
| 514 | yExt = xExt / sf;
|
|---|
| 515 |
|
|---|
| 516 | if ((double)LONG_MAX <= yExt) return (result);
|
|---|
| 517 |
|
|---|
| 518 | if (pHps->viewportYExt < 0.0)
|
|---|
| 519 | pHps->viewportYExt = -yExt;
|
|---|
| 520 | else
|
|---|
| 521 | pHps->viewportYExt = yExt;
|
|---|
| 522 | }
|
|---|
| 523 | }
|
|---|
| 524 | result = setPageXForm(wnd, pHps);
|
|---|
| 525 |
|
|---|
| 526 | return (result);
|
|---|
| 527 | }
|
|---|
| 528 |
|
|---|
| 529 | LONG clientHeight(Win32BaseWindow *wnd, HWND hwnd, pDCData pHps)
|
|---|
| 530 | {
|
|---|
| 531 | if ((hwnd == 0) && (pHps != 0))
|
|---|
| 532 | hwnd = pHps->hwnd;
|
|---|
| 533 |
|
|---|
| 534 | if ((hwnd != 0) || (pHps == 0))
|
|---|
| 535 | {
|
|---|
| 536 | if (wnd)
|
|---|
| 537 | return (wnd->getWindowHeight());
|
|---|
| 538 | else
|
|---|
| 539 | return OSLibQueryScreenHeight();
|
|---|
| 540 | }
|
|---|
| 541 | else if (pHps->bitmapHandle)
|
|---|
| 542 | {
|
|---|
| 543 | return pHps->bitmapHeight;
|
|---|
| 544 | }
|
|---|
| 545 | else if (pHps->isMetaPS)
|
|---|
| 546 | {
|
|---|
| 547 | return 0;
|
|---|
| 548 | }
|
|---|
| 549 | else if (pHps->isPrinter)
|
|---|
| 550 | {
|
|---|
| 551 | return pHps->printPageHeight;
|
|---|
| 552 | }
|
|---|
| 553 | else
|
|---|
| 554 | {
|
|---|
| 555 | return MEM_HPS_MAX;
|
|---|
| 556 | }
|
|---|
| 557 | }
|
|---|
| 558 |
|
|---|
| 559 | VOID removeClientArea(pDCData pHps)
|
|---|
| 560 | {
|
|---|
| 561 | pHps->isClient = FALSE;
|
|---|
| 562 |
|
|---|
| 563 | if (pHps->isClientArea)
|
|---|
| 564 | {
|
|---|
| 565 | pHps->isClientArea = FALSE;
|
|---|
| 566 | GreSetupDC(pHps->hps,
|
|---|
| 567 | pHps->hrgnVis,
|
|---|
| 568 | pHps->ptlOrigin.x,
|
|---|
| 569 | pHps->ptlOrigin.y,
|
|---|
| 570 | 0,
|
|---|
| 571 | SETUPDC_ORIGIN | SETUPDC_VISRGN | SETUPDC_RECALCCLIP);
|
|---|
| 572 | }
|
|---|
| 573 | }
|
|---|
| 574 |
|
|---|
| 575 | BOOL selectClientArea(Win32BaseWindow *wnd, pDCData pHps, PRECTL prclPaint)
|
|---|
| 576 | {
|
|---|
| 577 | RECTL rcl;
|
|---|
| 578 | HRGN hrgnRect;
|
|---|
| 579 | HWND hwnd;
|
|---|
| 580 |
|
|---|
| 581 | if (!wnd) return (FALSE);
|
|---|
| 582 |
|
|---|
| 583 | pHps->isClient = TRUE;
|
|---|
| 584 | hwnd = pHps->hwnd;
|
|---|
| 585 |
|
|---|
| 586 | rcl.xLeft = rcl.yBottom = 0;
|
|---|
| 587 | rcl.xRight = wnd->getWindowWidth();
|
|---|
| 588 | rcl.yTop = wnd->getWindowHeight();
|
|---|
| 589 |
|
|---|
| 590 | WinMapWindowPoints(hwnd, HWND_DESKTOP, (PPOINTL) &rcl, 2);
|
|---|
| 591 | pHps->ptlOrigin = *((PPOINTL) &rcl);
|
|---|
| 592 |
|
|---|
| 593 | if (pHps->hrgnVis == 0)
|
|---|
| 594 | pHps->hrgnVis = GreCreateRectRegion(pHps->hps, &rcl, 1);
|
|---|
| 595 |
|
|---|
| 596 | hrgnRect = GreCreateRectRegion(pHps->hps, &rcl, 1);
|
|---|
| 597 |
|
|---|
| 598 | if (!pHps->isClientArea)
|
|---|
| 599 | GreCopyClipRegion(pHps->hps, pHps->hrgnVis, 0, COPYCRGN_VISRGN);
|
|---|
| 600 |
|
|---|
| 601 | GreCombineRegion(pHps->hps, hrgnRect, pHps->hrgnVis, hrgnRect, CRGN_AND);
|
|---|
| 602 | GreSetupDC(pHps->hps,
|
|---|
| 603 | hrgnRect,
|
|---|
| 604 | rcl.xLeft,
|
|---|
| 605 | rcl.yBottom,
|
|---|
| 606 | prclPaint,
|
|---|
| 607 | SETUPDC_ORIGIN | SETUPDC_VISRGN | SETUPDC_RECALCCLIP);
|
|---|
| 608 |
|
|---|
| 609 | pHps->isClientArea = TRUE;
|
|---|
| 610 | GreDestroyRegion(pHps->hps, hrgnRect);
|
|---|
| 611 |
|
|---|
| 612 | return (TRUE);
|
|---|
| 613 | }
|
|---|
| 614 |
|
|---|
| 615 | HDC sendEraseBkgnd (Win32BaseWindow *wnd)
|
|---|
| 616 | {
|
|---|
| 617 | BOOL erased;
|
|---|
| 618 | HWND hwnd;
|
|---|
| 619 | HDC hdc;
|
|---|
| 620 | HPS hps;
|
|---|
| 621 | HRGN hrgnUpdate, hrgnOld, hrgnClip, hrgnCombined;
|
|---|
| 622 | RECTL rectl = { 1, 1, 2, 2 };
|
|---|
| 623 |
|
|---|
| 624 | hwnd = wnd->getOS2WindowHandle();
|
|---|
| 625 | hps = WinGetPS(hwnd);
|
|---|
| 626 |
|
|---|
| 627 | hrgnUpdate = GpiCreateRegion (hps, 1, &rectl);
|
|---|
| 628 | WinQueryUpdateRegion (hwnd, hrgnUpdate);
|
|---|
| 629 | hrgnClip = GpiQueryClipRegion (hps);
|
|---|
| 630 |
|
|---|
| 631 | if (hrgnClip == NULLHANDLE)
|
|---|
| 632 | {
|
|---|
| 633 | GpiSetClipRegion (hps, hrgnUpdate, &hrgnOld);
|
|---|
| 634 | }
|
|---|
| 635 | else
|
|---|
| 636 | {
|
|---|
| 637 | hrgnCombined = GpiCreateRegion (hps, 1, &rectl);
|
|---|
| 638 | GpiCombineRegion (hps, hrgnCombined, hrgnClip, hrgnUpdate, CRGN_AND);
|
|---|
| 639 | GpiSetClipRegion (hps, hrgnCombined, &hrgnOld);
|
|---|
| 640 | GpiDestroyRegion (hps, hrgnUpdate);
|
|---|
| 641 | GpiDestroyRegion (hps, hrgnClip);
|
|---|
| 642 | }
|
|---|
| 643 | if (hrgnOld != NULLHANDLE)
|
|---|
| 644 | GpiDestroyRegion (hps, hrgnOld);
|
|---|
| 645 |
|
|---|
| 646 | hdc = HPSToHDC (hwnd, hps, NULL, NULL);
|
|---|
| 647 |
|
|---|
| 648 | erased = wnd->MsgEraseBackGround (hdc);
|
|---|
| 649 |
|
|---|
| 650 | DeleteHDC (hdc);
|
|---|
| 651 | WinReleasePS (hps);
|
|---|
| 652 |
|
|---|
| 653 | return erased;
|
|---|
| 654 | }
|
|---|
| 655 |
|
|---|
| 656 | void releaseOwnDC (HDC hps)
|
|---|
| 657 | {
|
|---|
| 658 | pDCData pHps = (pDCData)GpiQueryDCData ((HPS)hps);
|
|---|
| 659 |
|
|---|
| 660 | if (pHps) {
|
|---|
| 661 | if (pHps->hrgnHDC)
|
|---|
| 662 | GpiDestroyRegion (pHps->hps, pHps->hrgnHDC);
|
|---|
| 663 |
|
|---|
| 664 | GpiSetBitmap (pHps->hps, NULL);
|
|---|
| 665 | _O32_DeleteObject (pHps->nullBitmapHandle);
|
|---|
| 666 | GpiDestroyPS(pHps->hps);
|
|---|
| 667 |
|
|---|
| 668 | if (pHps->hdc)
|
|---|
| 669 | DevCloseDC(pHps->hdc);
|
|---|
| 670 |
|
|---|
| 671 | // how can a memory chunk allocated by GpiAllocateDCData freed by delete?
|
|---|
| 672 | // delete pHps;
|
|---|
| 673 | }
|
|---|
| 674 | }
|
|---|
| 675 |
|
|---|
| 676 | HDC WIN32API BeginPaint (HWND hWnd, PPAINTSTRUCT_W lpps)
|
|---|
| 677 | {
|
|---|
| 678 | HWND hwnd = hWnd ? hWnd : HWND_DESKTOP;
|
|---|
| 679 | pDCData pHps = NULLHANDLE;
|
|---|
| 680 | RECTL rect;
|
|---|
| 681 | HPS hPS_ownDC = NULLHANDLE;
|
|---|
| 682 |
|
|---|
| 683 | dprintf (("USER32: BeginPaint(%x)", hWnd));
|
|---|
| 684 |
|
|---|
| 685 | if ( !lpps )
|
|---|
| 686 | {
|
|---|
| 687 | // SET_ERROR_WIN( ERROR_INVALID_PARAMETER_W );
|
|---|
| 688 | return (HDC)NULLHANDLE;
|
|---|
| 689 | }
|
|---|
| 690 |
|
|---|
| 691 | USHORT sel = RestoreOS2FS();
|
|---|
| 692 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 693 |
|
|---|
| 694 | if ((hwnd != HWND_DESKTOP) && wnd->isOwnDC())
|
|---|
| 695 | {
|
|---|
| 696 | hPS_ownDC = wnd->getOwnDC();
|
|---|
| 697 | pHps = (pDCData)GpiQueryDCData(hPS_ownDC);
|
|---|
| 698 | if (!pHps)
|
|---|
| 699 | {
|
|---|
| 700 | // SET_ERROR_LAST();
|
|---|
| 701 | SetFS(sel);
|
|---|
| 702 | return (HDC)NULLHANDLE;
|
|---|
| 703 | }
|
|---|
| 704 | }
|
|---|
| 705 |
|
|---|
| 706 | HWND hwndClient = wnd->getOS2WindowHandle();
|
|---|
| 707 | HPS hps = WinBeginPaint(hwndClient, hPS_ownDC, &rect);
|
|---|
| 708 |
|
|---|
| 709 | if (!pHps)
|
|---|
| 710 | {
|
|---|
| 711 | HDC hdc = HPSToHDC (hwndClient, hps, NULL, NULL);
|
|---|
| 712 | pHps = (pDCData)GpiQueryDCData(hps);
|
|---|
| 713 | }
|
|---|
| 714 |
|
|---|
| 715 | if (wnd->isFrameWindow())
|
|---|
| 716 | {
|
|---|
| 717 | // WinSendMsg( hwnd, /* WM_DRAW */ 0x20D, (MPARAM)hps, MPVOID );
|
|---|
| 718 | selectClientArea(wnd, pHps, &rect);
|
|---|
| 719 | }
|
|---|
| 720 |
|
|---|
| 721 | if (hPS_ownDC == 0)
|
|---|
| 722 | setMapMode (wnd, pHps, MM_TEXT_W);
|
|---|
| 723 | else
|
|---|
| 724 | setPageXForm (wnd, pHps);
|
|---|
| 725 |
|
|---|
| 726 | pHps->hdcType = TYPE_3;
|
|---|
| 727 | lpps->hdc = (HDC)hps;
|
|---|
| 728 | lpps->fErase = !wnd->MsgEraseBackGround(lpps->hdc);
|
|---|
| 729 |
|
|---|
| 730 | if (!hPS_ownDC)
|
|---|
| 731 | {
|
|---|
| 732 | long height = wnd->getWindowHeight();
|
|---|
| 733 | rect.yTop = height - rect.yTop;
|
|---|
| 734 | rect.yBottom = height - rect.yBottom;
|
|---|
| 735 | }
|
|---|
| 736 | else
|
|---|
| 737 | {
|
|---|
| 738 | rect.yTop--;
|
|---|
| 739 | rect.yBottom--;
|
|---|
| 740 | GpiConvert(pHps->hps, CVTC_DEVICE, CVTC_WORLD, 2, (PPOINTL)&rect);
|
|---|
| 741 | }
|
|---|
| 742 |
|
|---|
| 743 | WINRECT_FROM_PMRECT(lpps->rcPaint, rect);
|
|---|
| 744 |
|
|---|
| 745 | SetFS(sel);
|
|---|
| 746 | return (HDC)pHps->hps;
|
|---|
| 747 | }
|
|---|
| 748 |
|
|---|
| 749 | BOOL WIN32API EndPaint (HWND hwnd, const PAINTSTRUCT_W *pPaint)
|
|---|
| 750 | {
|
|---|
| 751 | dprintf (("USER32: EndPaint(%x)", hwnd));
|
|---|
| 752 |
|
|---|
| 753 | if (!pPaint || !pPaint->hdc )
|
|---|
| 754 | return TRUE;
|
|---|
| 755 |
|
|---|
| 756 | USHORT sel = RestoreOS2FS();
|
|---|
| 757 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 758 |
|
|---|
| 759 | if (!wnd) goto exit;
|
|---|
| 760 |
|
|---|
| 761 | if (wnd->isOwnDC())
|
|---|
| 762 | {
|
|---|
| 763 | pDCData pHps = (pDCData)GpiQueryDCData((HPS)pPaint->hdc);
|
|---|
| 764 | if (pHps && (pHps->hdcType == TYPE_3))
|
|---|
| 765 | {
|
|---|
| 766 | removeClientArea (pHps);
|
|---|
| 767 | WinEndPaint (pHps->hps);
|
|---|
| 768 | }
|
|---|
| 769 | }
|
|---|
| 770 | else
|
|---|
| 771 | {
|
|---|
| 772 | _O32_EndPaint (HWND_DESKTOP, pPaint);
|
|---|
| 773 | }
|
|---|
| 774 |
|
|---|
| 775 | exit:
|
|---|
| 776 | SetFS(sel);
|
|---|
| 777 | return TRUE;
|
|---|
| 778 | }
|
|---|
| 779 |
|
|---|
| 780 | BOOL WIN32API GetUpdateRect (HWND hwnd, LPRECT pRect, BOOL erase)
|
|---|
| 781 | {
|
|---|
| 782 | if (hwnd)
|
|---|
| 783 | {
|
|---|
| 784 | // SET_ERROR_WIN( ERROR_INVALID_HANDLE_W );
|
|---|
| 785 | return FALSE;
|
|---|
| 786 | }
|
|---|
| 787 |
|
|---|
| 788 | RECTL rectl;
|
|---|
| 789 | USHORT sel = RestoreOS2FS();
|
|---|
| 790 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 791 |
|
|---|
| 792 | BOOL updateRegionExists = WinQueryUpdateRect (hwnd, pRect ? &rectl : NULL);
|
|---|
| 793 | if (!pRect) {
|
|---|
| 794 | SetFS(sel);
|
|---|
| 795 | return (updateRegionExists);
|
|---|
| 796 | }
|
|---|
| 797 |
|
|---|
| 798 | if (updateRegionExists)
|
|---|
| 799 | {
|
|---|
| 800 | if (wnd->isOwnDC())
|
|---|
| 801 | {
|
|---|
| 802 | pDCData pHps = NULL;
|
|---|
| 803 | pHps = (pDCData)GpiQueryDCData(wnd->getOwnDC());
|
|---|
| 804 | if (!pHps)
|
|---|
| 805 | {
|
|---|
| 806 | // SET_ERROR_WIN(ERROR_INVALID_HANDLE_W);
|
|---|
| 807 | SetFS(sel);
|
|---|
| 808 | return FALSE;
|
|---|
| 809 | }
|
|---|
| 810 | GpiConvert (pHps->hps, CVTC_DEVICE, CVTC_WORLD, 2, (PPOINTL)&rectl);
|
|---|
| 811 | }
|
|---|
| 812 | else
|
|---|
| 813 | {
|
|---|
| 814 | long height = wnd->getWindowHeight();
|
|---|
| 815 | rectl.yTop = height - rectl.yTop;
|
|---|
| 816 | rectl.yBottom = height - rectl.yBottom;
|
|---|
| 817 | }
|
|---|
| 818 |
|
|---|
| 819 | if (pRect)
|
|---|
| 820 | WINRECT_FROM_PMRECT (*pRect, rectl);
|
|---|
| 821 |
|
|---|
| 822 | if (erase)
|
|---|
| 823 | sendEraseBkgnd (wnd);
|
|---|
| 824 | }
|
|---|
| 825 | else
|
|---|
| 826 | {
|
|---|
| 827 | if (pRect)
|
|---|
| 828 | pRect->left = pRect->top = pRect->right = pRect->bottom = 0;
|
|---|
| 829 | }
|
|---|
| 830 |
|
|---|
| 831 | SetFS(sel);
|
|---|
| 832 | return updateRegionExists;
|
|---|
| 833 | }
|
|---|
| 834 |
|
|---|
| 835 | int WIN32API GetUpdateRgn (HWND hwnd, HRGN hrgn, BOOL erase)
|
|---|
| 836 | {
|
|---|
| 837 | USHORT sel = RestoreOS2FS();
|
|---|
| 838 | LONG Complexity;
|
|---|
| 839 |
|
|---|
| 840 | Complexity = _O32_GetUpdateRgn (hwnd, hrgn, FALSE);
|
|---|
| 841 | if (erase && (Complexity > NULLREGION_W)) {
|
|---|
| 842 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 843 | sendEraseBkgnd (wnd);
|
|---|
| 844 | }
|
|---|
| 845 |
|
|---|
| 846 | SetFS(sel);
|
|---|
| 847 | return Complexity;
|
|---|
| 848 | }
|
|---|
| 849 |
|
|---|
| 850 | // This implementation of GetDCEx supports
|
|---|
| 851 | // DCX_WINDOW
|
|---|
| 852 | // DCX_CACHE
|
|---|
| 853 | // DCX_EXCLUDERGN (complex regions allowed)
|
|---|
| 854 | // DCX_INTERSECTRGN (complex regions allowed)
|
|---|
| 855 |
|
|---|
| 856 | HDC WIN32API GetDCEx (HWND hwnd, HRGN hrgn, ULONG flags)
|
|---|
| 857 | {
|
|---|
| 858 | USHORT sel = RestoreOS2FS();
|
|---|
| 859 | Win32BaseWindow *wnd = NULL;
|
|---|
| 860 | HWND hWindow;
|
|---|
| 861 | BOOL success;
|
|---|
| 862 | pDCData pHps = NULL;
|
|---|
| 863 | HPS hps = NULLHANDLE;
|
|---|
| 864 | BOOL drawingAllowed = TRUE;
|
|---|
| 865 | BOOL isWindowOwnDC;
|
|---|
| 866 | BOOL creatingOwnDC = FALSE;
|
|---|
| 867 | PS_Type psType;
|
|---|
| 868 |
|
|---|
| 869 | if (hwnd)
|
|---|
| 870 | {
|
|---|
| 871 | wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 872 | if (flags & DCX_WINDOW_W)
|
|---|
| 873 | hWindow = wnd->getOS2FrameWindowHandle();
|
|---|
| 874 | else
|
|---|
| 875 | hWindow = wnd->getOS2WindowHandle();
|
|---|
| 876 | }
|
|---|
| 877 | else
|
|---|
| 878 | hWindow = HWND_DESKTOP;
|
|---|
| 879 |
|
|---|
| 880 | dprintf (("User32: GetDCEx hwnd %x (%x %x) -> wnd %x", hwnd, hrgn, flags, wnd));
|
|---|
| 881 |
|
|---|
| 882 | isWindowOwnDC = (((hWindow == HWND_DESKTOP) ? FALSE : wnd->isOwnDC())
|
|---|
| 883 | && !(flags & DCX_CACHE_W));
|
|---|
| 884 | if (isWindowOwnDC)
|
|---|
| 885 | {
|
|---|
| 886 | hps = wnd->getOwnDC();
|
|---|
| 887 | if (hps)
|
|---|
| 888 | {
|
|---|
| 889 | pDCData pHps = (pDCData)GpiQueryDCData (hps);
|
|---|
| 890 | if (!pHps)
|
|---|
| 891 | goto error;
|
|---|
| 892 |
|
|---|
| 893 | if (flags & DCX_WINDOW_W)
|
|---|
| 894 | removeClientArea (pHps);
|
|---|
| 895 | else
|
|---|
| 896 | selectClientArea (wnd, pHps, 0);
|
|---|
| 897 |
|
|---|
| 898 | setPageXForm (wnd, pHps);
|
|---|
| 899 |
|
|---|
| 900 | pHps->hdcType = TYPE_1;
|
|---|
| 901 | SetFS(sel);
|
|---|
| 902 | return (HDC)hps;
|
|---|
| 903 | }
|
|---|
| 904 | else
|
|---|
| 905 | creatingOwnDC = TRUE;
|
|---|
| 906 | }
|
|---|
| 907 |
|
|---|
| 908 | if (isWindowOwnDC)
|
|---|
| 909 | {
|
|---|
| 910 | SIZEL sizel = {0,0};
|
|---|
| 911 | hps = GpiCreatePS (WinQueryAnchorBlock (hWindow),
|
|---|
| 912 | WinOpenWindowDC (hWindow),
|
|---|
| 913 | &sizel, PU_PELS | GPIT_MICRO | GPIA_ASSOC );
|
|---|
| 914 | psType = MICRO;
|
|---|
| 915 | }
|
|---|
| 916 | else
|
|---|
| 917 | {
|
|---|
| 918 | if (hWindow == HWND_DESKTOP)
|
|---|
| 919 | hps = WinGetScreenPS (hWindow);
|
|---|
| 920 | else
|
|---|
| 921 | hps = WinGetPS (hWindow);
|
|---|
| 922 |
|
|---|
| 923 | psType = MICRO_CACHED;
|
|---|
| 924 | }
|
|---|
| 925 |
|
|---|
| 926 | if (!hps)
|
|---|
| 927 | goto error;
|
|---|
| 928 |
|
|---|
| 929 | HPSToHDC (hWindow, hps, NULL, NULL);
|
|---|
| 930 | pHps = (pDCData)GpiQueryDCData (hps);
|
|---|
| 931 |
|
|---|
| 932 | if (!(flags & DCX_WINDOW_W)) {
|
|---|
| 933 | if (selectClientArea (wnd, pHps, 0))
|
|---|
| 934 | setMapMode (wnd, pHps, MM_TEXT_W);
|
|---|
| 935 | }
|
|---|
| 936 |
|
|---|
| 937 | if ((flags & DCX_EXCLUDERGN_W) || (flags & DCX_INTERSECTRGN_W))
|
|---|
| 938 | {
|
|---|
| 939 | ULONG BytesNeeded;
|
|---|
| 940 | PRGNDATA_W RgnData;
|
|---|
| 941 | PRECTL pr;
|
|---|
| 942 | int i;
|
|---|
| 943 | LONG height = OSLibQueryScreenHeight();
|
|---|
| 944 |
|
|---|
| 945 | if (!hrgn)
|
|---|
| 946 | goto error;
|
|---|
| 947 |
|
|---|
| 948 | BytesNeeded = _O32_GetRegionData (hrgn, 0, NULL);
|
|---|
| 949 | RgnData = (PRGNDATA_W)_alloca (BytesNeeded);
|
|---|
| 950 | if (RgnData == NULL)
|
|---|
| 951 | goto error;
|
|---|
| 952 | _O32_GetRegionData (hrgn, BytesNeeded, RgnData);
|
|---|
| 953 |
|
|---|
| 954 | i = RgnData->rdh.nCount;
|
|---|
| 955 | pr = (PRECTL)(RgnData->Buffer);
|
|---|
| 956 |
|
|---|
| 957 | success = TRUE;
|
|---|
| 958 | if (flags & DCX_EXCLUDERGN_W)
|
|---|
| 959 | for (; (i > 0) && success; i--, pr++) {
|
|---|
| 960 | LONG y = pr->yBottom;
|
|---|
| 961 |
|
|---|
| 962 | pr->yBottom = height - pr->yTop;
|
|---|
| 963 | pr->yTop = height - y;
|
|---|
| 964 | success &= GpiExcludeClipRectangle (pHps->hps, pr);
|
|---|
| 965 | }
|
|---|
| 966 | else
|
|---|
| 967 | for (; (i > 0) && success; i--, pr++) {
|
|---|
| 968 | LONG y = pr->yBottom;
|
|---|
| 969 |
|
|---|
| 970 | pr->yBottom = height - pr->yTop;
|
|---|
| 971 | pr->yTop = height - y;
|
|---|
| 972 | success &= GpiIntersectClipRectangle (pHps->hps, pr);
|
|---|
| 973 | }
|
|---|
| 974 | if (!success)
|
|---|
| 975 | goto error;
|
|---|
| 976 | }
|
|---|
| 977 |
|
|---|
| 978 | if (creatingOwnDC)
|
|---|
| 979 | wnd->setOwnDC ((HDC)hps);
|
|---|
| 980 |
|
|---|
| 981 | pHps->psType = psType;
|
|---|
| 982 | pHps->hdcType = TYPE_1;
|
|---|
| 983 | GpiSetDrawControl (hps, DCTL_DISPLAY, drawingAllowed ? DCTL_ON : DCTL_OFF);
|
|---|
| 984 |
|
|---|
| 985 | SetFS(sel);
|
|---|
| 986 | return (HDC)pHps->hps;
|
|---|
| 987 |
|
|---|
| 988 | error:
|
|---|
| 989 | /* Something went wrong; clean up
|
|---|
| 990 | */
|
|---|
| 991 | if (pHps)
|
|---|
| 992 | {
|
|---|
| 993 | if (pHps->hps)
|
|---|
| 994 | {
|
|---|
| 995 | if(pHps->psType == MICRO_CACHED)
|
|---|
| 996 | WinReleasePS(pHps->hps);
|
|---|
| 997 | else
|
|---|
| 998 | GpiDestroyPS(pHps->hps);
|
|---|
| 999 | }
|
|---|
| 1000 |
|
|---|
| 1001 | if (pHps->hdc) DevCloseDC(pHps->hdc);
|
|---|
| 1002 | if (pHps->hrgnHDC) GpiDestroyRegion(pHps->hps, pHps->hrgnHDC);
|
|---|
| 1003 |
|
|---|
| 1004 | _O32_DeleteObject (pHps->nullBitmapHandle);
|
|---|
| 1005 | }
|
|---|
| 1006 | // SET_ERROR_LAST();
|
|---|
| 1007 | SetFS(sel);
|
|---|
| 1008 | return NULL;
|
|---|
| 1009 | }
|
|---|
| 1010 |
|
|---|
| 1011 | HDC WIN32API GetDC (HWND hwnd)
|
|---|
| 1012 | {
|
|---|
| 1013 | return GetDCEx (hwnd, NULL, 0);
|
|---|
| 1014 | }
|
|---|
| 1015 |
|
|---|
| 1016 | HDC WIN32API GetWindowDC (HWND hwnd)
|
|---|
| 1017 | {
|
|---|
| 1018 | return GetDCEx (hwnd, NULL, DCX_WINDOW_W);
|
|---|
| 1019 | }
|
|---|
| 1020 |
|
|---|
| 1021 | int WIN32API ReleaseDC (HWND hwnd, HDC hdc)
|
|---|
| 1022 | {
|
|---|
| 1023 | USHORT sel = RestoreOS2FS();
|
|---|
| 1024 | BOOL isOwnDC = FALSE;
|
|---|
| 1025 | int rc;
|
|---|
| 1026 |
|
|---|
| 1027 | if (hwnd)
|
|---|
| 1028 | {
|
|---|
| 1029 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
|
|---|
| 1030 | isOwnDC = wnd->isOwnDC();
|
|---|
| 1031 | }
|
|---|
| 1032 | if (isOwnDC)
|
|---|
| 1033 | rc = TRUE;
|
|---|
| 1034 | else
|
|---|
| 1035 | rc = _O32_ReleaseDC (0, hdc);
|
|---|
| 1036 |
|
|---|
| 1037 | SetFS(sel);
|
|---|
| 1038 | return (rc);
|
|---|
| 1039 | }
|
|---|
| 1040 | //******************************************************************************
|
|---|
| 1041 | //******************************************************************************
|
|---|
| 1042 |
|
|---|