| 1 | /* $Id: dc.cpp,v 1.2 1999-09-10 19:00:10 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 | int OPEN32API _O32_GetUpdateRgn (HWND hwnd, HRGN hrgn, BOOL erase);
|
|---|
| 253 |
|
|---|
| 254 | #define FLOAT_TO_FIXED(x) ((FIXED) ((x) * 65536.0))
|
|---|
| 255 | #define MICRO_HPS_TO_HDC(x) ((x) & 0xFFFFFFFE)
|
|---|
| 256 |
|
|---|
| 257 | #define PMRECT_FROM_WINRECT( pmRect, winRect ) \
|
|---|
| 258 | { \
|
|---|
| 259 | (pmRect).xLeft = (winRect).left; \
|
|---|
| 260 | (pmRect).yBottom = (winRect).bottom; \
|
|---|
| 261 | (pmRect).xRight = (winRect).right; \
|
|---|
| 262 | (pmRect).yTop = (winRect).top; \
|
|---|
| 263 | }
|
|---|
| 264 |
|
|---|
| 265 | #define WINRECT_FROM_PMRECT( winRect, pmRect ) \
|
|---|
| 266 | { \
|
|---|
| 267 | (winRect).left = (pmRect).xLeft; \
|
|---|
| 268 | (winRect).top = (pmRect).yTop; \
|
|---|
| 269 | (winRect).right = (pmRect).xRight; \
|
|---|
| 270 | (winRect).bottom = (pmRect).yBottom; \
|
|---|
| 271 | }
|
|---|
| 272 |
|
|---|
| 273 | #define MEM_HPS_MAX 768
|
|---|
| 274 |
|
|---|
| 275 | const XFORM_W XFORMIdentity = { 1.0, 0.0, 0.0, 1.0, 0, 0 };
|
|---|
| 276 | const MATRIXLF matrixlfIdentity = { 0x10000, 0, 0, 0, 0x10000, 0, 0, 0, 0};
|
|---|
| 277 |
|
|---|
| 278 | BOOL setPageXForm(pDCData pHps);
|
|---|
| 279 | BOOL changePageXForm(pDCData pHps, PPOINTL pValue, int x, int y, PPOINTL pPrev);
|
|---|
| 280 | LONG clientHeight(HWND hwnd, pDCData pHps);
|
|---|
| 281 |
|
|---|
| 282 | void TestWideLine (pDCData pHps)
|
|---|
| 283 | {
|
|---|
| 284 | const LOGPEN_W *pLogPen;
|
|---|
| 285 |
|
|---|
| 286 | pHps->isWideLine = FALSE;
|
|---|
| 287 | pLogPen = pHps->penIsExtPen ?
|
|---|
| 288 | &(pHps->lastPenObject->ExtPen.logpen) :
|
|---|
| 289 | &(pHps->lastPenObject->Pen.logpen);
|
|---|
| 290 |
|
|---|
| 291 | if (((pLogPen->lopnStyle & PS_STYLE_MASK_W) != PS_NULL_W) &&
|
|---|
| 292 | (pLogPen->lopnWidth.x > 0))
|
|---|
| 293 | {
|
|---|
| 294 | POINTL aptl[2] = { 0, 0, pLogPen->lopnWidth.x, pLogPen->lopnWidth.x };
|
|---|
| 295 |
|
|---|
| 296 | GpiConvert(pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, aptl);
|
|---|
| 297 |
|
|---|
| 298 | ULONG dx = abs(aptl[0].x - aptl[1].x);
|
|---|
| 299 | ULONG dy = abs(aptl[0].y - aptl[1].y);
|
|---|
| 300 |
|
|---|
| 301 | pHps->isWideLine = (dx > 1) || (dy > 1);
|
|---|
| 302 | }
|
|---|
| 303 | }
|
|---|
| 304 |
|
|---|
| 305 | void Calculate1PixelDelta(pDCData pHps)
|
|---|
| 306 | {
|
|---|
| 307 | POINTL aptl[2] = {0, 0, 1, 1};
|
|---|
| 308 |
|
|---|
| 309 | GpiConvert(pHps->hps, CVTC_DEVICE, CVTC_WORLD, 2, aptl);
|
|---|
| 310 | pHps->worldYDeltaFor1Pixel = (int)(aptl[1].y - aptl[0].y);
|
|---|
| 311 | pHps->worldXDeltaFor1Pixel = (int)(aptl[1].x - aptl[0].x); // 171182
|
|---|
| 312 | }
|
|---|
| 313 |
|
|---|
| 314 | //******************************************************************************
|
|---|
| 315 |
|
|---|
| 316 | int setMapMode(pDCData pHps, int mode)
|
|---|
| 317 | {
|
|---|
| 318 | int prevMode = 0;
|
|---|
| 319 | ULONG flOptions;
|
|---|
| 320 |
|
|---|
| 321 | switch (mode)
|
|---|
| 322 | {
|
|---|
| 323 | case MM_HIENGLISH_W : flOptions = PU_HIENGLISH; break;
|
|---|
| 324 | case MM_LOENGLISH_W : flOptions = PU_LOENGLISH; break;
|
|---|
| 325 | case MM_HIMETRIC_W : flOptions = PU_HIMETRIC ; break;
|
|---|
| 326 | case MM_LOMETRIC_W : flOptions = PU_LOMETRIC ; break;
|
|---|
| 327 | case MM_TEXT_W : flOptions = PU_PELS ; break;
|
|---|
| 328 | case MM_TWIPS_W : flOptions = PU_TWIPS ; break;
|
|---|
| 329 | case MM_ANISOTROPIC_W: flOptions = PU_PELS ; break;
|
|---|
| 330 | case MM_ISOTROPIC_W : flOptions = PU_LOMETRIC ; break;
|
|---|
| 331 | default:
|
|---|
| 332 | // SET_ERROR_WIN(ERROR_INVALID_PARAMETER_W);
|
|---|
| 333 | return FALSE;
|
|---|
| 334 | }
|
|---|
| 335 |
|
|---|
| 336 | prevMode = pHps->MapMode; /* store previous mode */
|
|---|
| 337 | pHps->MapMode = mode;
|
|---|
| 338 |
|
|---|
| 339 | if (mode == MM_TEXT_W)
|
|---|
| 340 | {
|
|---|
| 341 | pHps->viewportXExt =
|
|---|
| 342 | pHps->viewportYExt = 1.0;
|
|---|
| 343 | pHps->windowExt.cx =
|
|---|
| 344 | pHps->windowExt.cy = 1;
|
|---|
| 345 | }
|
|---|
| 346 | else if (mode != MM_ANISOTROPIC_W)
|
|---|
| 347 | {
|
|---|
| 348 | RECTL rectl;
|
|---|
| 349 | SIZEL sizel;
|
|---|
| 350 | ULONG data[3];
|
|---|
| 351 |
|
|---|
| 352 | data[0] = flOptions;
|
|---|
| 353 | data[1] = data[2] = 0;
|
|---|
| 354 |
|
|---|
| 355 | if (DevEscape(pHps->hdc ? pHps->hdc : pHps->hps, DEVESC_SETPS, 12, (PBYTE)data, 0, 0) == DEVESC_ERROR)
|
|---|
| 356 | {
|
|---|
| 357 | // SET_ERROR_LAST();
|
|---|
| 358 | return 0;
|
|---|
| 359 | }
|
|---|
| 360 |
|
|---|
| 361 | GpiQueryPageViewport(pHps->hps, &rectl);
|
|---|
| 362 | pHps->viewportXExt = (double)rectl.xRight;
|
|---|
| 363 | pHps->viewportYExt = -(double)rectl.yTop;
|
|---|
| 364 |
|
|---|
| 365 | GreGetPageUnits(pHps->hdc? pHps->hdc : pHps->hps, &sizel);
|
|---|
| 366 | pHps->windowExt.cx = sizel.cx;
|
|---|
| 367 | pHps->windowExt.cy = sizel.cy;
|
|---|
| 368 |
|
|---|
| 369 | data[0] = PU_PELS;
|
|---|
| 370 | DevEscape(pHps->hdc ? pHps->hdc : pHps->hps, DEVESC_SETPS, 12, (PBYTE)data, 0, 0);
|
|---|
| 371 | }
|
|---|
| 372 |
|
|---|
| 373 | if (((prevMode != MM_ISOTROPIC_W) && (prevMode != MM_ANISOTROPIC_W)) &&
|
|---|
| 374 | ((mode == MM_ISOTROPIC_W) || (mode == MM_ANISOTROPIC_W)))
|
|---|
| 375 | {
|
|---|
| 376 | if (pHps->lWndXExtSave && pHps->lWndYExtSave)
|
|---|
| 377 | {
|
|---|
| 378 | changePageXForm( pHps, (PPOINTL)&pHps->windowExt,
|
|---|
| 379 | pHps->lWndXExtSave, pHps->lWndYExtSave, NULL );
|
|---|
| 380 | pHps->lWndXExtSave = pHps->lWndYExtSave = 0;
|
|---|
| 381 | }
|
|---|
| 382 | if (pHps->lVwpXExtSave && pHps->lVwpYExtSave)
|
|---|
| 383 | {
|
|---|
| 384 | changePageXForm( pHps, NULL,
|
|---|
| 385 | pHps->lVwpXExtSave, pHps->lVwpYExtSave, NULL );
|
|---|
| 386 | pHps->lVwpXExtSave = pHps->lVwpYExtSave = 0;
|
|---|
| 387 | }
|
|---|
| 388 | }
|
|---|
| 389 |
|
|---|
| 390 | setPageXForm(pHps);
|
|---|
| 391 |
|
|---|
| 392 | return prevMode;
|
|---|
| 393 | }
|
|---|
| 394 |
|
|---|
| 395 | BOOL setPageXForm(pDCData pHps)
|
|---|
| 396 | {
|
|---|
| 397 | MATRIXLF mlf;
|
|---|
| 398 | BOOL rc = TRUE;
|
|---|
| 399 |
|
|---|
| 400 | pHps->height = clientHeight(0, pHps) - 1;
|
|---|
| 401 |
|
|---|
| 402 | double xScale = pHps->viewportXExt / (double)pHps->windowExt.cx;
|
|---|
| 403 | double yScale = pHps->viewportYExt / (double)pHps->windowExt.cy;
|
|---|
| 404 |
|
|---|
| 405 | mlf.fxM11 = FLOAT_TO_FIXED(xScale);
|
|---|
| 406 | mlf.fxM12 = 0;
|
|---|
| 407 | mlf.lM13 = 0;
|
|---|
| 408 | mlf.fxM21 = 0;
|
|---|
| 409 | mlf.fxM22 = FLOAT_TO_FIXED(yScale);
|
|---|
| 410 | mlf.lM23 = 0;
|
|---|
| 411 | mlf.lM31 = pHps->viewportOrg.x - (LONG)(pHps->windowOrg.x * xScale);
|
|---|
| 412 | mlf.lM32 = pHps->viewportOrg.y - (LONG)(pHps->windowOrg.y * yScale);
|
|---|
| 413 |
|
|---|
| 414 | pHps->isLeftLeft = mlf.fxM11 >= 0;
|
|---|
| 415 | pHps->isTopTop = mlf.fxM22 >= 0;
|
|---|
| 416 |
|
|---|
| 417 | BOOL bEnableYInversion = FALSE;
|
|---|
| 418 | if ((mlf.fxM22 > 0) ||
|
|---|
| 419 | ((pHps->graphicsMode == GM_ADVANCED_W) &&
|
|---|
| 420 | ((pHps->MapMode == MM_ANISOTROPIC_W) ||
|
|---|
| 421 | (pHps->MapMode == MM_ISOTROPIC_W))))
|
|---|
| 422 | {
|
|---|
| 423 | bEnableYInversion = TRUE;
|
|---|
| 424 | }
|
|---|
| 425 | else
|
|---|
| 426 | {
|
|---|
| 427 | bEnableYInversion = FALSE;
|
|---|
| 428 | mlf.lM32 = pHps->HPStoHDCInversionHeight + pHps->height - mlf.lM32;
|
|---|
| 429 | mlf.fxM22 = -mlf.fxM22;
|
|---|
| 430 | }
|
|---|
| 431 |
|
|---|
| 432 | if (!pHps->isMetaPS)
|
|---|
| 433 | // if ((!pHps->isMetaPS) ||
|
|---|
| 434 | // (pHps->pMetaFileObject && pHps->pMetaFileObject->isEnhanced()))
|
|---|
| 435 | rc = GpiSetDefaultViewMatrix(pHps->hps, 8, &mlf, TRANSFORM_REPLACE);
|
|---|
| 436 |
|
|---|
| 437 | if (bEnableYInversion)
|
|---|
| 438 | GpiEnableYInversion(pHps->hps, pHps->height + pHps->HPStoHDCInversionHeight);
|
|---|
| 439 | else
|
|---|
| 440 | GpiEnableYInversion(pHps->hps, 0);
|
|---|
| 441 |
|
|---|
| 442 | TestWideLine(pHps);
|
|---|
| 443 | Calculate1PixelDelta(pHps);
|
|---|
| 444 | return rc;
|
|---|
| 445 | }
|
|---|
| 446 |
|
|---|
| 447 | BOOL changePageXForm(pDCData pHps, PPOINTL pValue, int x, int y, PPOINTL pPrev)
|
|---|
| 448 | {
|
|---|
| 449 | BOOL result = FALSE;
|
|---|
| 450 |
|
|---|
| 451 | if (pValue)
|
|---|
| 452 | {
|
|---|
| 453 | if (pPrev)
|
|---|
| 454 | *pPrev = *pValue;
|
|---|
| 455 |
|
|---|
| 456 | if ((pValue->x == x) && (pValue->y == y)) {
|
|---|
| 457 | return TRUE;
|
|---|
| 458 | }
|
|---|
| 459 | pValue->x = x;
|
|---|
| 460 | pValue->y = y;
|
|---|
| 461 | }
|
|---|
| 462 | else
|
|---|
| 463 | {
|
|---|
| 464 | if (pPrev)
|
|---|
| 465 | {
|
|---|
| 466 | pPrev->x = (int)pHps->viewportXExt;
|
|---|
| 467 | pPrev->y = (int)pHps->viewportYExt;
|
|---|
| 468 | }
|
|---|
| 469 | pHps->viewportXExt = (double)x;
|
|---|
| 470 | pHps->viewportYExt = (double)y;
|
|---|
| 471 | }
|
|---|
| 472 |
|
|---|
| 473 | if (pHps->MapMode == MM_ISOTROPIC_W)
|
|---|
| 474 | {
|
|---|
| 475 | double xExt = fabs(pHps->viewportXExt);
|
|---|
| 476 | double yExt = fabs(pHps->viewportYExt);
|
|---|
| 477 | double sf = fabs((double)pHps->windowExt.cx / pHps->windowExt.cy);
|
|---|
| 478 |
|
|---|
| 479 | if (xExt > (yExt * sf))
|
|---|
| 480 | {
|
|---|
| 481 | xExt = yExt * sf;
|
|---|
| 482 |
|
|---|
| 483 | if ((double)LONG_MAX <= xExt) return (result);
|
|---|
| 484 |
|
|---|
| 485 | if (pHps->viewportXExt < 0.0)
|
|---|
| 486 | pHps->viewportXExt = -xExt;
|
|---|
| 487 | else
|
|---|
| 488 | pHps->viewportXExt = xExt;
|
|---|
| 489 | }
|
|---|
| 490 | else
|
|---|
| 491 | {
|
|---|
| 492 | yExt = xExt / sf;
|
|---|
| 493 |
|
|---|
| 494 | if ((double)LONG_MAX <= yExt) return (result);
|
|---|
| 495 |
|
|---|
| 496 | if (pHps->viewportYExt < 0.0)
|
|---|
| 497 | pHps->viewportYExt = -yExt;
|
|---|
| 498 | else
|
|---|
| 499 | pHps->viewportYExt = yExt;
|
|---|
| 500 | }
|
|---|
| 501 | }
|
|---|
| 502 | result = setPageXForm(pHps);
|
|---|
| 503 |
|
|---|
| 504 | return (result);
|
|---|
| 505 | }
|
|---|
| 506 |
|
|---|
| 507 | LONG clientHeight(HWND hwnd, pDCData pHps)
|
|---|
| 508 | {
|
|---|
| 509 | if ((hwnd == 0) && (pHps != 0))
|
|---|
| 510 | hwnd = pHps->hwnd;
|
|---|
| 511 |
|
|---|
| 512 | if ((hwnd != 0) || (pHps == 0))
|
|---|
| 513 | {
|
|---|
| 514 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
|
|---|
| 515 | return (wnd->getWindowHeight());
|
|---|
| 516 | }
|
|---|
| 517 | else if (pHps->bitmapHandle)
|
|---|
| 518 | {
|
|---|
| 519 | return pHps->bitmapHeight;
|
|---|
| 520 | }
|
|---|
| 521 | else if (pHps->isMetaPS)
|
|---|
| 522 | {
|
|---|
| 523 | return 0;
|
|---|
| 524 | }
|
|---|
| 525 | else if (pHps->isPrinter)
|
|---|
| 526 | {
|
|---|
| 527 | return pHps->printPageHeight;
|
|---|
| 528 | }
|
|---|
| 529 | else
|
|---|
| 530 | {
|
|---|
| 531 | return MEM_HPS_MAX;
|
|---|
| 532 | }
|
|---|
| 533 | }
|
|---|
| 534 |
|
|---|
| 535 | VOID removeClientArea(pDCData pHps)
|
|---|
| 536 | {
|
|---|
| 537 | pHps->isClient = FALSE;
|
|---|
| 538 |
|
|---|
| 539 | if (pHps->isClientArea)
|
|---|
| 540 | {
|
|---|
| 541 | pHps->isClientArea = FALSE;
|
|---|
| 542 | GreSetupDC(pHps->hps,
|
|---|
| 543 | pHps->hrgnVis,
|
|---|
| 544 | pHps->ptlOrigin.x,
|
|---|
| 545 | pHps->ptlOrigin.y,
|
|---|
| 546 | 0,
|
|---|
| 547 | SETUPDC_ORIGIN | SETUPDC_VISRGN | SETUPDC_RECALCCLIP);
|
|---|
| 548 | }
|
|---|
| 549 | }
|
|---|
| 550 |
|
|---|
| 551 | void selectClientArea(Win32BaseWindow *wnd, pDCData pHps, PRECTL prclPaint)
|
|---|
| 552 | {
|
|---|
| 553 | RECTL rcl;
|
|---|
| 554 | HRGN hrgnRect;
|
|---|
| 555 | HWND hwnd;
|
|---|
| 556 |
|
|---|
| 557 | pHps->isClient = TRUE;
|
|---|
| 558 | hwnd = pHps->hwnd;
|
|---|
| 559 |
|
|---|
| 560 | rcl.xLeft = rcl.yBottom = 0;
|
|---|
| 561 | rcl.xRight = wnd->getWindowWidth();
|
|---|
| 562 | rcl.yTop = wnd->getWindowHeight();
|
|---|
| 563 |
|
|---|
| 564 | WinMapWindowPoints(hwnd, HWND_DESKTOP, (PPOINTL) &rcl, 2);
|
|---|
| 565 | pHps->ptlOrigin = *((PPOINTL) &rcl);
|
|---|
| 566 |
|
|---|
| 567 | if (pHps->hrgnVis == 0)
|
|---|
| 568 | pHps->hrgnVis = GreCreateRectRegion(pHps->hps, &rcl, 1);
|
|---|
| 569 |
|
|---|
| 570 | hrgnRect = GreCreateRectRegion(pHps->hps, &rcl, 1);
|
|---|
| 571 |
|
|---|
| 572 | if (!pHps->isClientArea)
|
|---|
| 573 | GreCopyClipRegion(pHps->hps, pHps->hrgnVis, 0, COPYCRGN_VISRGN);
|
|---|
| 574 |
|
|---|
| 575 | GreCombineRegion(pHps->hps, hrgnRect, pHps->hrgnVis, hrgnRect, CRGN_AND);
|
|---|
| 576 | GreSetupDC(pHps->hps,
|
|---|
| 577 | hrgnRect,
|
|---|
| 578 | rcl.xLeft,
|
|---|
| 579 | rcl.yBottom,
|
|---|
| 580 | prclPaint,
|
|---|
| 581 | SETUPDC_ORIGIN | SETUPDC_VISRGN | SETUPDC_RECALCCLIP);
|
|---|
| 582 |
|
|---|
| 583 | pHps->isClientArea = TRUE;
|
|---|
| 584 | GreDestroyRegion(pHps->hps, hrgnRect);
|
|---|
| 585 | }
|
|---|
| 586 |
|
|---|
| 587 | HDC sendEraseBkgnd (Win32BaseWindow *wnd)
|
|---|
| 588 | {
|
|---|
| 589 | BOOL erased;
|
|---|
| 590 | HWND hwnd;
|
|---|
| 591 | HDC hdc;
|
|---|
| 592 | HPS hps;
|
|---|
| 593 | HRGN hrgnUpdate, hrgnOld, hrgnClip, hrgnCombined;
|
|---|
| 594 | RECTL rectl = { 1, 1, 2, 2 };
|
|---|
| 595 |
|
|---|
| 596 | hwnd = wnd->getOS2WindowHandle();
|
|---|
| 597 | hps = WinGetPS(hwnd);
|
|---|
| 598 |
|
|---|
| 599 | hrgnUpdate = GpiCreateRegion (hps, 1, &rectl);
|
|---|
| 600 | WinQueryUpdateRegion (hwnd, hrgnUpdate);
|
|---|
| 601 | hrgnClip = GpiQueryClipRegion (hps);
|
|---|
| 602 |
|
|---|
| 603 | if (hrgnClip == NULLHANDLE)
|
|---|
| 604 | {
|
|---|
| 605 | GpiSetClipRegion (hps, hrgnUpdate, &hrgnOld);
|
|---|
| 606 | }
|
|---|
| 607 | else
|
|---|
| 608 | {
|
|---|
| 609 | hrgnCombined = GpiCreateRegion (hps, 1, &rectl);
|
|---|
| 610 | GpiCombineRegion (hps, hrgnCombined, hrgnClip, hrgnUpdate, CRGN_AND);
|
|---|
| 611 | GpiSetClipRegion (hps, hrgnCombined, &hrgnOld);
|
|---|
| 612 | GpiDestroyRegion (hps, hrgnUpdate);
|
|---|
| 613 | GpiDestroyRegion (hps, hrgnClip);
|
|---|
| 614 | }
|
|---|
| 615 | if (hrgnOld != NULLHANDLE)
|
|---|
| 616 | GpiDestroyRegion (hps, hrgnOld);
|
|---|
| 617 |
|
|---|
| 618 | hdc = HPSToHDC (hwnd, hps, NULL, NULL);
|
|---|
| 619 |
|
|---|
| 620 | erased = wnd->MsgEraseBackGround (hdc);
|
|---|
| 621 |
|
|---|
| 622 | DeleteHDC (hdc);
|
|---|
| 623 | WinReleasePS (hps);
|
|---|
| 624 |
|
|---|
| 625 | return erased;
|
|---|
| 626 | }
|
|---|
| 627 |
|
|---|
| 628 | HDC WIN32API BeginPaint (HWND hWnd, PPAINTSTRUCT_W lpps)
|
|---|
| 629 | {
|
|---|
| 630 | HWND hwnd = hWnd ? hWnd : HWND_DESKTOP;
|
|---|
| 631 | pDCData pHps = NULLHANDLE;
|
|---|
| 632 | RECTL rect;
|
|---|
| 633 | HPS hPS_ownDC = NULLHANDLE;
|
|---|
| 634 |
|
|---|
| 635 | dprintf (("USER32: BeginPaint(%x)", hWnd));
|
|---|
| 636 |
|
|---|
| 637 | if ( !lpps )
|
|---|
| 638 | {
|
|---|
| 639 | // SET_ERROR_WIN( ERROR_INVALID_PARAMETER_W );
|
|---|
| 640 | return (HDC)NULLHANDLE;
|
|---|
| 641 | }
|
|---|
| 642 |
|
|---|
| 643 | USHORT sel = RestoreOS2FS();
|
|---|
| 644 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 645 |
|
|---|
| 646 | if ((hwnd != HWND_DESKTOP) && wnd->isOwnDC())
|
|---|
| 647 | {
|
|---|
| 648 | hPS_ownDC = wnd->getOwnDC();
|
|---|
| 649 | pHps = (pDCData)GpiQueryDCData(hPS_ownDC);
|
|---|
| 650 | if (!pHps)
|
|---|
| 651 | {
|
|---|
| 652 | // SET_ERROR_LAST();
|
|---|
| 653 | SetFS(sel);
|
|---|
| 654 | return (HDC)NULLHANDLE;
|
|---|
| 655 | }
|
|---|
| 656 | }
|
|---|
| 657 |
|
|---|
| 658 | HWND hwndClient = wnd->getOS2WindowHandle();
|
|---|
| 659 | HPS hps = WinBeginPaint(hwndClient, hPS_ownDC, &rect);
|
|---|
| 660 |
|
|---|
| 661 | if (!pHps)
|
|---|
| 662 | {
|
|---|
| 663 | HDC hdc = HPSToHDC (hwndClient, hps, NULL, NULL);
|
|---|
| 664 | pHps = (pDCData)GpiQueryDCData(hps);
|
|---|
| 665 | }
|
|---|
| 666 |
|
|---|
| 667 | if (wnd->isFrameWindow())
|
|---|
| 668 | {
|
|---|
| 669 | // WinSendMsg( hwnd, /* WM_DRAW */ 0x20D, (MPARAM)hps, MPVOID );
|
|---|
| 670 | selectClientArea(wnd, pHps, &rect);
|
|---|
| 671 | }
|
|---|
| 672 |
|
|---|
| 673 | if (hPS_ownDC == 0)
|
|---|
| 674 | setMapMode(pHps, MM_TEXT_W);
|
|---|
| 675 | else
|
|---|
| 676 | setPageXForm(pHps);
|
|---|
| 677 |
|
|---|
| 678 | pHps->hdcType = TYPE_3;
|
|---|
| 679 | lpps->hdc = (HDC)hps;
|
|---|
| 680 | lpps->fErase = !wnd->MsgEraseBackGround(lpps->hdc);
|
|---|
| 681 |
|
|---|
| 682 | if (!hPS_ownDC)
|
|---|
| 683 | {
|
|---|
| 684 | long height = wnd->getWindowHeight();
|
|---|
| 685 | rect.yTop = height - rect.yTop;
|
|---|
| 686 | rect.yBottom = height - rect.yBottom;
|
|---|
| 687 | }
|
|---|
| 688 | else
|
|---|
| 689 | {
|
|---|
| 690 | rect.yTop--;
|
|---|
| 691 | rect.yBottom--;
|
|---|
| 692 | GpiConvert(pHps->hps, CVTC_DEVICE, CVTC_WORLD, 2, (PPOINTL)&rect);
|
|---|
| 693 | }
|
|---|
| 694 |
|
|---|
| 695 | WINRECT_FROM_PMRECT(lpps->rcPaint, rect);
|
|---|
| 696 |
|
|---|
| 697 | SetFS(sel);
|
|---|
| 698 | return (HDC)pHps->hps;
|
|---|
| 699 | }
|
|---|
| 700 |
|
|---|
| 701 | BOOL WIN32API EndPaint (HWND hwnd, const PAINTSTRUCT_W *pPaint)
|
|---|
| 702 | {
|
|---|
| 703 | dprintf (("USER32: EndPaint(%x)", hwnd));
|
|---|
| 704 |
|
|---|
| 705 | if (!pPaint || !pPaint->hdc )
|
|---|
| 706 | return TRUE;
|
|---|
| 707 |
|
|---|
| 708 | USHORT sel = RestoreOS2FS();
|
|---|
| 709 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 710 |
|
|---|
| 711 | if (!wnd) goto exit;
|
|---|
| 712 |
|
|---|
| 713 | if (wnd->isOwnDC())
|
|---|
| 714 | {
|
|---|
| 715 | pDCData pHps = (pDCData)GpiQueryDCData((HPS)pPaint->hdc);
|
|---|
| 716 | if (pHps && (pHps->hdcType == TYPE_3))
|
|---|
| 717 | {
|
|---|
| 718 | removeClientArea (pHps);
|
|---|
| 719 | WinEndPaint (pHps->hps);
|
|---|
| 720 | }
|
|---|
| 721 | }
|
|---|
| 722 | else
|
|---|
| 723 | {
|
|---|
| 724 | _O32_EndPaint (HWND_DESKTOP, pPaint);
|
|---|
| 725 | }
|
|---|
| 726 |
|
|---|
| 727 | exit:
|
|---|
| 728 | SetFS(sel);
|
|---|
| 729 | return TRUE;
|
|---|
| 730 | }
|
|---|
| 731 |
|
|---|
| 732 | BOOL WIN32API GetUpdateRect (HWND hwnd, LPRECT pRect, BOOL erase)
|
|---|
| 733 | {
|
|---|
| 734 | if (hwnd)
|
|---|
| 735 | {
|
|---|
| 736 | // SET_ERROR_WIN( ERROR_INVALID_HANDLE_W );
|
|---|
| 737 | return FALSE;
|
|---|
| 738 | }
|
|---|
| 739 |
|
|---|
| 740 | RECTL rectl;
|
|---|
| 741 | USHORT sel = RestoreOS2FS();
|
|---|
| 742 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 743 |
|
|---|
| 744 | BOOL updateRegionExists = WinQueryUpdateRect (hwnd, pRect ? &rectl : NULL);
|
|---|
| 745 | if (!pRect) {
|
|---|
| 746 | SetFS(sel);
|
|---|
| 747 | return (updateRegionExists);
|
|---|
| 748 | }
|
|---|
| 749 |
|
|---|
| 750 | if (updateRegionExists)
|
|---|
| 751 | {
|
|---|
| 752 | if (wnd->isOwnDC())
|
|---|
| 753 | {
|
|---|
| 754 | pDCData pHps = NULL;
|
|---|
| 755 | pHps = (pDCData)GpiQueryDCData(wnd->getOwnDC());
|
|---|
| 756 | if (!pHps)
|
|---|
| 757 | {
|
|---|
| 758 | // SET_ERROR_WIN(ERROR_INVALID_HANDLE_W);
|
|---|
| 759 | SetFS(sel);
|
|---|
| 760 | return FALSE;
|
|---|
| 761 | }
|
|---|
| 762 | GpiConvert (pHps->hps, CVTC_DEVICE, CVTC_WORLD, 2, (PPOINTL)&rectl);
|
|---|
| 763 | }
|
|---|
| 764 | else
|
|---|
| 765 | {
|
|---|
| 766 | long height = wnd->getWindowHeight();
|
|---|
| 767 | rectl.yTop = height - rectl.yTop;
|
|---|
| 768 | rectl.yBottom = height - rectl.yBottom;
|
|---|
| 769 | }
|
|---|
| 770 |
|
|---|
| 771 | if (pRect)
|
|---|
| 772 | WINRECT_FROM_PMRECT (*pRect, rectl);
|
|---|
| 773 |
|
|---|
| 774 | if (erase)
|
|---|
| 775 | sendEraseBkgnd (wnd);
|
|---|
| 776 | }
|
|---|
| 777 | else
|
|---|
| 778 | {
|
|---|
| 779 | if (pRect)
|
|---|
| 780 | pRect->left = pRect->top = pRect->right = pRect->bottom = 0;
|
|---|
| 781 | }
|
|---|
| 782 |
|
|---|
| 783 | SetFS(sel);
|
|---|
| 784 | return updateRegionExists;
|
|---|
| 785 | }
|
|---|
| 786 |
|
|---|
| 787 | int WIN32API GetUpdateRgn (HWND hwnd, HRGN hrgn, BOOL erase)
|
|---|
| 788 | {
|
|---|
| 789 | USHORT sel = RestoreOS2FS();
|
|---|
| 790 | LONG Complexity;
|
|---|
| 791 |
|
|---|
| 792 | Complexity = _O32_GetUpdateRgn (hwnd, hrgn, FALSE);
|
|---|
| 793 | if (erase && (Complexity > NULLREGION_W)) {
|
|---|
| 794 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 795 | sendEraseBkgnd (wnd);
|
|---|
| 796 | }
|
|---|
| 797 |
|
|---|
| 798 | SetFS(sel);
|
|---|
| 799 | return Complexity;
|
|---|
| 800 | }
|
|---|
| 801 |
|
|---|
| 802 | //******************************************************************************
|
|---|
| 803 | //******************************************************************************
|
|---|
| 804 |
|
|---|