| 1 | /* $Id: dc.cpp,v 1.14 2000-01-15 15:05:36 sandervl Exp $ */ | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 4 | * DC functions for USER32 | 
|---|
| 5 | * | 
|---|
| 6 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 7 | * | 
|---|
| 8 | */ | 
|---|
| 9 |  | 
|---|
| 10 | /***************************************************************************** | 
|---|
| 11 | * Includes                                                                  * | 
|---|
| 12 | *****************************************************************************/ | 
|---|
| 13 |  | 
|---|
| 14 | #include <odin.h> | 
|---|
| 15 |  | 
|---|
| 16 | #define INCL_WIN | 
|---|
| 17 | #define INCL_GPI | 
|---|
| 18 | #define INCL_GREALL | 
|---|
| 19 | #define INCL_DEV | 
|---|
| 20 | #include <os2wrap.h> | 
|---|
| 21 | //#include <pmddi.h> | 
|---|
| 22 | #include <stdlib.h> | 
|---|
| 23 |  | 
|---|
| 24 | #include "win32type.h" | 
|---|
| 25 | #include <winconst.h> | 
|---|
| 26 | #include <misc.h> | 
|---|
| 27 | #include <win32wbase.h> | 
|---|
| 28 | #include <math.h> | 
|---|
| 29 | #include <limits.h> | 
|---|
| 30 | #include "oslibwin.h" | 
|---|
| 31 | #include "dcdata.h" | 
|---|
| 32 |  | 
|---|
| 33 | #define INCLUDED_BY_DC | 
|---|
| 34 | #include "dc.h" | 
|---|
| 35 |  | 
|---|
| 36 | #undef SEVERITY_ERROR | 
|---|
| 37 | #include <winerror.h> | 
|---|
| 38 |  | 
|---|
| 39 | #ifndef DEVESC_SETPS | 
|---|
| 40 | #define DEVESC_SETPS  49149L | 
|---|
| 41 | #endif | 
|---|
| 42 |  | 
|---|
| 43 | #define FLOAT_TO_FIXED(x) ((FIXED) ((x) * 65536.0)) | 
|---|
| 44 | #define MICRO_HPS_TO_HDC(x) ((x) & 0xFFFFFFFE) | 
|---|
| 45 |  | 
|---|
| 46 | #define PMRECT_FROM_WINRECT( pmRect, winRect )  \ | 
|---|
| 47 | {                                               \ | 
|---|
| 48 | (pmRect).xLeft   = (winRect).left;           \ | 
|---|
| 49 | (pmRect).yBottom = (winRect).bottom;         \ | 
|---|
| 50 | (pmRect).xRight  = (winRect).right;          \ | 
|---|
| 51 | (pmRect).yTop    = (winRect).top;            \ | 
|---|
| 52 | } | 
|---|
| 53 |  | 
|---|
| 54 | #define WINRECT_FROM_PMRECT( winRect, pmRect )  \ | 
|---|
| 55 | {                                               \ | 
|---|
| 56 | (winRect).left   = (pmRect).xLeft;           \ | 
|---|
| 57 | (winRect).top    = (pmRect).yTop;            \ | 
|---|
| 58 | (winRect).right  = (pmRect).xRight;          \ | 
|---|
| 59 | (winRect).bottom = (pmRect).yBottom;         \ | 
|---|
| 60 | } | 
|---|
| 61 |  | 
|---|
| 62 | #define MEM_HPS_MAX 768 | 
|---|
| 63 |  | 
|---|
| 64 | const XFORM_W XFORMIdentity = { 1.0, 0.0, 0.0, 1.0, 0, 0 }; | 
|---|
| 65 | const MATRIXLF matrixlfIdentity = { 0x10000, 0, 0, 0, 0x10000, 0, 0, 0, 0}; | 
|---|
| 66 |  | 
|---|
| 67 | BOOL setPageXForm(Win32BaseWindow *wnd, pDCData pHps); | 
|---|
| 68 | BOOL changePageXForm(Win32BaseWindow *wnd, pDCData pHps, PPOINTL pValue, int x, int y, PPOINTL pPrev); | 
|---|
| 69 | LONG clientHeight(Win32BaseWindow *wnd, HWND hwnd, pDCData pHps); | 
|---|
| 70 |  | 
|---|
| 71 | //****************************************************************************** | 
|---|
| 72 | //****************************************************************************** | 
|---|
| 73 | void TestWideLine (pDCData pHps) | 
|---|
| 74 | { | 
|---|
| 75 | const LOGPEN_W *pLogPen; | 
|---|
| 76 |  | 
|---|
| 77 | pHps->isWideLine = FALSE; | 
|---|
| 78 | pLogPen = pHps->penIsExtPen ? | 
|---|
| 79 | &(pHps->lastPenObject->ExtPen.logpen) : | 
|---|
| 80 | &(pHps->lastPenObject->Pen.logpen); | 
|---|
| 81 |  | 
|---|
| 82 | if (((pLogPen->lopnStyle & PS_STYLE_MASK_W) != PS_NULL_W) && | 
|---|
| 83 | (pLogPen->lopnWidth.x > 0)) | 
|---|
| 84 | { | 
|---|
| 85 | POINTL aptl[2] = { 0, 0, pLogPen->lopnWidth.x, pLogPen->lopnWidth.x }; | 
|---|
| 86 |  | 
|---|
| 87 | GpiConvert(pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, aptl); | 
|---|
| 88 |  | 
|---|
| 89 | ULONG dx = abs(aptl[0].x - aptl[1].x); | 
|---|
| 90 | ULONG dy = abs(aptl[0].y - aptl[1].y); | 
|---|
| 91 |  | 
|---|
| 92 | pHps->isWideLine = (dx > 1) || (dy > 1); | 
|---|
| 93 | } | 
|---|
| 94 | } | 
|---|
| 95 | //****************************************************************************** | 
|---|
| 96 | //****************************************************************************** | 
|---|
| 97 | void Calculate1PixelDelta(pDCData pHps) | 
|---|
| 98 | { | 
|---|
| 99 | POINTL aptl[2] = {0, 0, 1, 1}; | 
|---|
| 100 |  | 
|---|
| 101 | GpiConvert(pHps->hps, CVTC_DEVICE, CVTC_WORLD, 2, aptl); | 
|---|
| 102 | pHps->worldYDeltaFor1Pixel = (int)(aptl[1].y - aptl[0].y); | 
|---|
| 103 | pHps->worldXDeltaFor1Pixel = (int)(aptl[1].x - aptl[0].x);                   // 171182 | 
|---|
| 104 | } | 
|---|
| 105 | //****************************************************************************** | 
|---|
| 106 | //****************************************************************************** | 
|---|
| 107 | int setMapMode(Win32BaseWindow *wnd, pDCData pHps, int mode) | 
|---|
| 108 | { | 
|---|
| 109 | int    prevMode = 0; | 
|---|
| 110 | ULONG  flOptions; | 
|---|
| 111 |  | 
|---|
| 112 | switch (mode) | 
|---|
| 113 | { | 
|---|
| 114 | case MM_HIENGLISH_W  : flOptions = PU_HIENGLISH; break; | 
|---|
| 115 | case MM_LOENGLISH_W  : flOptions = PU_LOENGLISH; break; | 
|---|
| 116 | case MM_HIMETRIC_W   : flOptions = PU_HIMETRIC ; break; | 
|---|
| 117 | case MM_LOMETRIC_W   : flOptions = PU_LOMETRIC ; break; | 
|---|
| 118 | case MM_TEXT_W       : flOptions = PU_PELS     ; break; | 
|---|
| 119 | case MM_TWIPS_W      : flOptions = PU_TWIPS    ; break; | 
|---|
| 120 | case MM_ANISOTROPIC_W: flOptions = PU_PELS     ; break; | 
|---|
| 121 | case MM_ISOTROPIC_W  : flOptions = PU_LOMETRIC ; break; | 
|---|
| 122 | default: | 
|---|
| 123 | O32_SetLastError (ERROR_INVALID_PARAMETER); | 
|---|
| 124 | return FALSE; | 
|---|
| 125 | } | 
|---|
| 126 |  | 
|---|
| 127 | prevMode = pHps->MapMode;  /* store previous mode */ | 
|---|
| 128 | pHps->MapMode = mode; | 
|---|
| 129 |  | 
|---|
| 130 | if (mode == MM_TEXT_W) | 
|---|
| 131 | { | 
|---|
| 132 | pHps->viewportXExt = | 
|---|
| 133 | pHps->viewportYExt = 1.0; | 
|---|
| 134 | pHps->windowExt.cx = | 
|---|
| 135 | pHps->windowExt.cy = 1; | 
|---|
| 136 | } | 
|---|
| 137 | else if (mode != MM_ANISOTROPIC_W) | 
|---|
| 138 | { | 
|---|
| 139 | RECTL rectl; | 
|---|
| 140 | SIZEL sizel; | 
|---|
| 141 | ULONG data[3]; | 
|---|
| 142 |  | 
|---|
| 143 | data[0] = flOptions; | 
|---|
| 144 | data[1] = data[2] = 0; | 
|---|
| 145 |  | 
|---|
| 146 | if (DevEscape(pHps->hdc ? pHps->hdc : pHps->hps, DEVESC_SETPS, 12, (PBYTE)data, 0, 0) == DEVESC_ERROR) | 
|---|
| 147 | { | 
|---|
| 148 | O32_SetLastError (ERROR_INVALID_PARAMETER); | 
|---|
| 149 | return 0; | 
|---|
| 150 | } | 
|---|
| 151 |  | 
|---|
| 152 | GpiQueryPageViewport(pHps->hps, &rectl); | 
|---|
| 153 | pHps->viewportXExt = (double)rectl.xRight; | 
|---|
| 154 | pHps->viewportYExt = -(double)rectl.yTop; | 
|---|
| 155 |  | 
|---|
| 156 | GreGetPageUnits(pHps->hdc? pHps->hdc : pHps->hps, &sizel); | 
|---|
| 157 | pHps->windowExt.cx = sizel.cx; | 
|---|
| 158 | pHps->windowExt.cy = sizel.cy; | 
|---|
| 159 |  | 
|---|
| 160 | data[0] = PU_PELS; | 
|---|
| 161 | DevEscape(pHps->hdc ? pHps->hdc : pHps->hps, DEVESC_SETPS, 12, (PBYTE)data, 0, 0); | 
|---|
| 162 | } | 
|---|
| 163 |  | 
|---|
| 164 | if (((prevMode != MM_ISOTROPIC_W) && (prevMode != MM_ANISOTROPIC_W)) && | 
|---|
| 165 | ((mode == MM_ISOTROPIC_W) || (mode == MM_ANISOTROPIC_W))) | 
|---|
| 166 | { | 
|---|
| 167 | if (pHps->lWndXExtSave && pHps->lWndYExtSave) | 
|---|
| 168 | { | 
|---|
| 169 | changePageXForm (wnd, pHps, (PPOINTL)&pHps->windowExt, | 
|---|
| 170 | pHps->lWndXExtSave, pHps->lWndYExtSave, NULL ); | 
|---|
| 171 | pHps->lWndXExtSave = pHps->lWndYExtSave = 0; | 
|---|
| 172 | } | 
|---|
| 173 | if (pHps->lVwpXExtSave && pHps->lVwpYExtSave) | 
|---|
| 174 | { | 
|---|
| 175 | changePageXForm (wnd, pHps, NULL, | 
|---|
| 176 | pHps->lVwpXExtSave, pHps->lVwpYExtSave, NULL ); | 
|---|
| 177 | pHps->lVwpXExtSave = pHps->lVwpYExtSave = 0; | 
|---|
| 178 | } | 
|---|
| 179 | } | 
|---|
| 180 |  | 
|---|
| 181 | setPageXForm(wnd, pHps); | 
|---|
| 182 |  | 
|---|
| 183 | return prevMode; | 
|---|
| 184 | } | 
|---|
| 185 | //****************************************************************************** | 
|---|
| 186 | //****************************************************************************** | 
|---|
| 187 | BOOL setPageXForm(Win32BaseWindow *wnd, pDCData pHps) | 
|---|
| 188 | { | 
|---|
| 189 | MATRIXLF mlf; | 
|---|
| 190 | BOOL rc = TRUE; | 
|---|
| 191 |  | 
|---|
| 192 | pHps->height = clientHeight(wnd, 0, pHps) - 1; | 
|---|
| 193 |  | 
|---|
| 194 | double xScale =  pHps->viewportXExt / (double)pHps->windowExt.cx; | 
|---|
| 195 | double yScale =  pHps->viewportYExt / (double)pHps->windowExt.cy; | 
|---|
| 196 |  | 
|---|
| 197 | mlf.fxM11 = FLOAT_TO_FIXED(xScale); | 
|---|
| 198 | mlf.fxM12 = 0; | 
|---|
| 199 | mlf.lM13  = 0; | 
|---|
| 200 | mlf.fxM21 = 0; | 
|---|
| 201 | mlf.fxM22 = FLOAT_TO_FIXED(yScale); | 
|---|
| 202 | mlf.lM23  = 0; | 
|---|
| 203 | mlf.lM31  = pHps->viewportOrg.x - (LONG)(pHps->windowOrg.x * xScale); | 
|---|
| 204 | mlf.lM32  = pHps->viewportOrg.y - (LONG)(pHps->windowOrg.y * yScale); | 
|---|
| 205 |  | 
|---|
| 206 | pHps->isLeftLeft = mlf.fxM11 >= 0; | 
|---|
| 207 | pHps->isTopTop = mlf.fxM22 >= 0; | 
|---|
| 208 |  | 
|---|
| 209 | BOOL bEnableYInversion = FALSE; | 
|---|
| 210 | if ((mlf.fxM22 > 0) || | 
|---|
| 211 | ((pHps->graphicsMode == GM_ADVANCED_W) && | 
|---|
| 212 | ((pHps->MapMode == MM_ANISOTROPIC_W) || | 
|---|
| 213 | (pHps->MapMode == MM_ISOTROPIC_W)))) | 
|---|
| 214 | { | 
|---|
| 215 | bEnableYInversion = TRUE; | 
|---|
| 216 | } | 
|---|
| 217 | else | 
|---|
| 218 | { | 
|---|
| 219 | bEnableYInversion = FALSE; | 
|---|
| 220 | mlf.lM32 = pHps->HPStoHDCInversionHeight + pHps->height - mlf.lM32; | 
|---|
| 221 | mlf.fxM22 = -mlf.fxM22; | 
|---|
| 222 | } | 
|---|
| 223 |  | 
|---|
| 224 | if (!pHps->isMetaPS) | 
|---|
| 225 | //   if ((!pHps->isMetaPS) || | 
|---|
| 226 | //      (pHps->pMetaFileObject && pHps->pMetaFileObject->isEnhanced())) | 
|---|
| 227 | rc = GpiSetDefaultViewMatrix(pHps->hps, 8, &mlf, TRANSFORM_REPLACE); | 
|---|
| 228 |  | 
|---|
| 229 | if (bEnableYInversion) | 
|---|
| 230 | GpiEnableYInversion(pHps->hps, pHps->height + pHps->HPStoHDCInversionHeight); | 
|---|
| 231 | else | 
|---|
| 232 | GpiEnableYInversion(pHps->hps, 0); | 
|---|
| 233 |  | 
|---|
| 234 | TestWideLine(pHps); | 
|---|
| 235 | Calculate1PixelDelta(pHps); | 
|---|
| 236 | return rc; | 
|---|
| 237 | } | 
|---|
| 238 | //****************************************************************************** | 
|---|
| 239 | //****************************************************************************** | 
|---|
| 240 | BOOL changePageXForm(Win32BaseWindow *wnd, pDCData pHps, PPOINTL pValue, int x, int y, PPOINTL pPrev) | 
|---|
| 241 | { | 
|---|
| 242 | BOOL result = FALSE; | 
|---|
| 243 |  | 
|---|
| 244 | if (pValue) | 
|---|
| 245 | { | 
|---|
| 246 | if (pPrev) | 
|---|
| 247 | *pPrev = *pValue; | 
|---|
| 248 |  | 
|---|
| 249 | if ((pValue->x == x) && (pValue->y == y)) { | 
|---|
| 250 | return TRUE; | 
|---|
| 251 | } | 
|---|
| 252 | pValue->x = x; | 
|---|
| 253 | pValue->y = y; | 
|---|
| 254 | } | 
|---|
| 255 | else | 
|---|
| 256 | { | 
|---|
| 257 | if (pPrev) | 
|---|
| 258 | { | 
|---|
| 259 | pPrev->x = (int)pHps->viewportXExt; | 
|---|
| 260 | pPrev->y = (int)pHps->viewportYExt; | 
|---|
| 261 | } | 
|---|
| 262 | pHps->viewportXExt = (double)x; | 
|---|
| 263 | pHps->viewportYExt = (double)y; | 
|---|
| 264 | } | 
|---|
| 265 |  | 
|---|
| 266 | if (pHps->MapMode == MM_ISOTROPIC_W) | 
|---|
| 267 | { | 
|---|
| 268 | double xExt = fabs(pHps->viewportXExt); | 
|---|
| 269 | double yExt = fabs(pHps->viewportYExt); | 
|---|
| 270 | double sf = fabs((double)pHps->windowExt.cx / pHps->windowExt.cy); | 
|---|
| 271 |  | 
|---|
| 272 | if (xExt > (yExt * sf)) | 
|---|
| 273 | { | 
|---|
| 274 | xExt = yExt * sf; | 
|---|
| 275 |  | 
|---|
| 276 | if ((double)LONG_MAX <= xExt) return (result); | 
|---|
| 277 |  | 
|---|
| 278 | if (pHps->viewportXExt < 0.0) | 
|---|
| 279 | pHps->viewportXExt = -xExt; | 
|---|
| 280 | else | 
|---|
| 281 | pHps->viewportXExt = xExt; | 
|---|
| 282 | } | 
|---|
| 283 | else | 
|---|
| 284 | { | 
|---|
| 285 | yExt = xExt / sf; | 
|---|
| 286 |  | 
|---|
| 287 | if ((double)LONG_MAX <= yExt) return (result); | 
|---|
| 288 |  | 
|---|
| 289 | if (pHps->viewportYExt < 0.0) | 
|---|
| 290 | pHps->viewportYExt = -yExt; | 
|---|
| 291 | else | 
|---|
| 292 | pHps->viewportYExt = yExt; | 
|---|
| 293 | } | 
|---|
| 294 | } | 
|---|
| 295 | result = setPageXForm(wnd, pHps); | 
|---|
| 296 |  | 
|---|
| 297 | return (result); | 
|---|
| 298 | } | 
|---|
| 299 | //****************************************************************************** | 
|---|
| 300 | //****************************************************************************** | 
|---|
| 301 | LONG clientHeight(Win32BaseWindow *wnd, HWND hwnd, pDCData pHps) | 
|---|
| 302 | { | 
|---|
| 303 | if ((hwnd == 0) && (pHps != 0)) | 
|---|
| 304 | hwnd = pHps->hwnd; | 
|---|
| 305 |  | 
|---|
| 306 | if ((hwnd != 0) || (pHps == 0)) | 
|---|
| 307 | { | 
|---|
| 308 | if (wnd) | 
|---|
| 309 | return (wnd->getClientHeight()); | 
|---|
| 310 | else | 
|---|
| 311 | return OSLibQueryScreenHeight(); | 
|---|
| 312 | } | 
|---|
| 313 | else if (pHps->bitmapHandle) | 
|---|
| 314 | { | 
|---|
| 315 | return pHps->bitmapHeight; | 
|---|
| 316 | } | 
|---|
| 317 | else if (pHps->isMetaPS) | 
|---|
| 318 | { | 
|---|
| 319 | return 0; | 
|---|
| 320 | } | 
|---|
| 321 | else if (pHps->isPrinter) | 
|---|
| 322 | { | 
|---|
| 323 | return pHps->printPageHeight; | 
|---|
| 324 | } | 
|---|
| 325 | else | 
|---|
| 326 | { | 
|---|
| 327 | return MEM_HPS_MAX; | 
|---|
| 328 | } | 
|---|
| 329 | } | 
|---|
| 330 | //****************************************************************************** | 
|---|
| 331 | //****************************************************************************** | 
|---|
| 332 | BOOL isYup (pDCData pHps) | 
|---|
| 333 | { | 
|---|
| 334 | if (((pHps->windowExt.cy < 0) && (pHps->viewportYExt > 0.0)) || | 
|---|
| 335 | ((pHps->windowExt.cy > 0) && (pHps->viewportYExt < 0.0))) | 
|---|
| 336 | { | 
|---|
| 337 | if ((pHps->graphicsMode == GM_COMPATIBLE_W) || | 
|---|
| 338 | ((pHps->graphicsMode == GM_ADVANCED_W) && (pHps->xform.eM22 >= 0.0))) | 
|---|
| 339 | return TRUE; | 
|---|
| 340 | } | 
|---|
| 341 | else | 
|---|
| 342 | { | 
|---|
| 343 | if ((pHps->graphicsMode == GM_ADVANCED_W) && (pHps->xform.eM22 < 0.0)) | 
|---|
| 344 | return TRUE; | 
|---|
| 345 | } | 
|---|
| 346 | return FALSE; | 
|---|
| 347 | } | 
|---|
| 348 | //****************************************************************************** | 
|---|
| 349 | //****************************************************************************** | 
|---|
| 350 | INT revertDy (Win32BaseWindow *wnd, INT dy) | 
|---|
| 351 | { | 
|---|
| 352 | //SvL: Hack for memory.exe (doesn't get repainted properly otherwise) | 
|---|
| 353 | //   if (wnd->isOwnDC() && wnd->getOwnDC()) | 
|---|
| 354 | if (wnd->isOwnDC()) | 
|---|
| 355 | { | 
|---|
| 356 | pDCData pHps = (pDCData)GpiQueryDCData (wnd->getOwnDC()); | 
|---|
| 357 |  | 
|---|
| 358 | if (pHps != NULLHANDLE) | 
|---|
| 359 | if (!isYup (pHps)) | 
|---|
| 360 | dy = -dy; | 
|---|
| 361 | } | 
|---|
| 362 | else | 
|---|
| 363 | { | 
|---|
| 364 | dy = -dy; | 
|---|
| 365 | } | 
|---|
| 366 | return (dy); | 
|---|
| 367 | } | 
|---|
| 368 | //****************************************************************************** | 
|---|
| 369 | //****************************************************************************** | 
|---|
| 370 | HDC sendEraseBkgnd (Win32BaseWindow *wnd) | 
|---|
| 371 | { | 
|---|
| 372 | BOOL  erased; | 
|---|
| 373 | HWND  hwnd; | 
|---|
| 374 | HDC   hdc; | 
|---|
| 375 | HPS   hps; | 
|---|
| 376 | HRGN  hrgnUpdate, hrgnOld, hrgnClip, hrgnCombined; | 
|---|
| 377 | RECTL rectl = { 1, 1, 2, 2 }; | 
|---|
| 378 |  | 
|---|
| 379 | hwnd = wnd->getOS2WindowHandle(); | 
|---|
| 380 | hps = WinGetPS(hwnd); | 
|---|
| 381 |  | 
|---|
| 382 | hrgnUpdate = GpiCreateRegion (hps, 1, &rectl); | 
|---|
| 383 | WinQueryUpdateRegion (hwnd, hrgnUpdate); | 
|---|
| 384 | hrgnClip = GpiQueryClipRegion (hps); | 
|---|
| 385 |  | 
|---|
| 386 | if (hrgnClip == NULLHANDLE) | 
|---|
| 387 | { | 
|---|
| 388 | GpiSetClipRegion (hps, hrgnUpdate, &hrgnOld); | 
|---|
| 389 | } | 
|---|
| 390 | else | 
|---|
| 391 | { | 
|---|
| 392 | hrgnCombined = GpiCreateRegion (hps, 1, &rectl); | 
|---|
| 393 | GpiCombineRegion (hps, hrgnCombined, hrgnClip, hrgnUpdate, CRGN_AND); | 
|---|
| 394 | GpiSetClipRegion (hps, hrgnCombined, &hrgnOld); | 
|---|
| 395 | GpiDestroyRegion (hps, hrgnUpdate); | 
|---|
| 396 | GpiDestroyRegion (hps, hrgnClip); | 
|---|
| 397 | } | 
|---|
| 398 | if (hrgnOld != NULLHANDLE) | 
|---|
| 399 | GpiDestroyRegion (hps, hrgnOld); | 
|---|
| 400 |  | 
|---|
| 401 | hdc = HPSToHDC (hwnd, hps, NULL, NULL); | 
|---|
| 402 |  | 
|---|
| 403 | erased = wnd->MsgEraseBackGround (hdc); | 
|---|
| 404 |  | 
|---|
| 405 | DeleteHDC (hdc); | 
|---|
| 406 | WinReleasePS (hps); | 
|---|
| 407 |  | 
|---|
| 408 | return erased; | 
|---|
| 409 | } | 
|---|
| 410 | //****************************************************************************** | 
|---|
| 411 | //****************************************************************************** | 
|---|
| 412 | void releaseOwnDC (HDC hps) | 
|---|
| 413 | { | 
|---|
| 414 | pDCData pHps = (pDCData)GpiQueryDCData ((HPS)hps); | 
|---|
| 415 |  | 
|---|
| 416 | if (pHps) { | 
|---|
| 417 | if (pHps->hrgnHDC) | 
|---|
| 418 | GpiDestroyRegion (pHps->hps, pHps->hrgnHDC); | 
|---|
| 419 |  | 
|---|
| 420 | GpiSetBitmap (pHps->hps, NULL); | 
|---|
| 421 | O32_DeleteObject (pHps->nullBitmapHandle); | 
|---|
| 422 | GpiDestroyPS(pHps->hps); | 
|---|
| 423 |  | 
|---|
| 424 | if (pHps->hdc) | 
|---|
| 425 | DevCloseDC(pHps->hdc); | 
|---|
| 426 |  | 
|---|
| 427 | // how can a memory chunk allocated by GpiAllocateDCData freed by delete? | 
|---|
| 428 | //      delete pHps; | 
|---|
| 429 | } | 
|---|
| 430 | } | 
|---|
| 431 | //****************************************************************************** | 
|---|
| 432 | //****************************************************************************** | 
|---|
| 433 | HDC WIN32API BeginPaint (HWND hWnd, PPAINTSTRUCT_W lpps) | 
|---|
| 434 | { | 
|---|
| 435 | HWND     hwnd = hWnd ? hWnd : HWND_DESKTOP; | 
|---|
| 436 | pDCData  pHps = NULLHANDLE; | 
|---|
| 437 | RECTL    rect; | 
|---|
| 438 | HPS      hPS_ownDC = NULLHANDLE; | 
|---|
| 439 |  | 
|---|
| 440 | dprintf (("USER32: BeginPaint(%x)", hWnd)); | 
|---|
| 441 |  | 
|---|
| 442 | if ( !lpps ) | 
|---|
| 443 | { | 
|---|
| 444 | O32_SetLastError (ERROR_INVALID_PARAMETER); | 
|---|
| 445 | return (HDC)NULLHANDLE; | 
|---|
| 446 | } | 
|---|
| 447 |  | 
|---|
| 448 | if(hWnd == 0x6800003a) { | 
|---|
| 449 | hwnd = 0x6800003a; | 
|---|
| 450 | } | 
|---|
| 451 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd); | 
|---|
| 452 |  | 
|---|
| 453 | if ((hwnd != HWND_DESKTOP) && wnd->isOwnDC()) | 
|---|
| 454 | { | 
|---|
| 455 | hPS_ownDC = wnd->getOwnDC(); | 
|---|
| 456 | //SvL: Hack for memory.exe (doesn't get repainted properly otherwise) | 
|---|
| 457 | if(hPS_ownDC) { | 
|---|
| 458 | pHps = (pDCData)GpiQueryDCData(hPS_ownDC); | 
|---|
| 459 | if (!pHps) | 
|---|
| 460 | { | 
|---|
| 461 | O32_SetLastError (ERROR_INVALID_PARAMETER); | 
|---|
| 462 | return (HDC)NULLHANDLE; | 
|---|
| 463 | } | 
|---|
| 464 | } | 
|---|
| 465 | } | 
|---|
| 466 |  | 
|---|
| 467 | HWND hwndClient = wnd->getOS2WindowHandle(); | 
|---|
| 468 | HPS  hps = WinBeginPaint(hwndClient, hPS_ownDC, &rect); | 
|---|
| 469 |  | 
|---|
| 470 | if (!pHps) | 
|---|
| 471 | { | 
|---|
| 472 | HDC hdc = HPSToHDC (hwndClient, hps, NULL, NULL); | 
|---|
| 473 | pHps = (pDCData)GpiQueryDCData(hps); | 
|---|
| 474 | } | 
|---|
| 475 |  | 
|---|
| 476 | if (hPS_ownDC == 0) | 
|---|
| 477 | setMapMode (wnd, pHps, MM_TEXT_W); | 
|---|
| 478 | else | 
|---|
| 479 | setPageXForm (wnd, pHps); | 
|---|
| 480 |  | 
|---|
| 481 | pHps->hdcType = TYPE_3; | 
|---|
| 482 | lpps->hdc = (HDC)hps; | 
|---|
| 483 |  | 
|---|
| 484 | if(!wnd->isSuppressErase()) { | 
|---|
| 485 | wnd->setSuppressErase(TRUE); | 
|---|
| 486 | wnd->setEraseBkgnd (FALSE, !wnd->MsgEraseBackGround(lpps->hdc)); | 
|---|
| 487 | } | 
|---|
| 488 | lpps->fErase = wnd->isPSErase(); | 
|---|
| 489 |  | 
|---|
| 490 | if (!hPS_ownDC) | 
|---|
| 491 | { | 
|---|
| 492 | long height  = wnd->getClientHeight(); | 
|---|
| 493 | rect.yTop    = height - rect.yTop; | 
|---|
| 494 | rect.yBottom = height - rect.yBottom; | 
|---|
| 495 | } | 
|---|
| 496 | else | 
|---|
| 497 | { | 
|---|
| 498 | rect.yTop--; | 
|---|
| 499 | rect.yBottom--; | 
|---|
| 500 | GpiConvert(pHps->hps, CVTC_DEVICE, CVTC_WORLD, 2, (PPOINTL)&rect); | 
|---|
| 501 | } | 
|---|
| 502 |  | 
|---|
| 503 | WINRECT_FROM_PMRECT(lpps->rcPaint, rect); | 
|---|
| 504 |  | 
|---|
| 505 | O32_SetLastError(0); | 
|---|
| 506 | return (HDC)pHps->hps; | 
|---|
| 507 | } | 
|---|
| 508 | //****************************************************************************** | 
|---|
| 509 | //****************************************************************************** | 
|---|
| 510 | BOOL WIN32API EndPaint (HWND hwnd, const PAINTSTRUCT_W *pPaint) | 
|---|
| 511 | { | 
|---|
| 512 | dprintf (("USER32: EndPaint(%x)", hwnd)); | 
|---|
| 513 |  | 
|---|
| 514 | if (!pPaint || !pPaint->hdc ) | 
|---|
| 515 | return TRUE; | 
|---|
| 516 |  | 
|---|
| 517 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd); | 
|---|
| 518 |  | 
|---|
| 519 | if (!wnd) goto exit; | 
|---|
| 520 |  | 
|---|
| 521 | //SvL: Hack for memory.exe (doesn't get repainted properly otherwise) | 
|---|
| 522 | if(wnd->isOwnDC() && wnd->getOwnDC()) | 
|---|
| 523 | //   if(wnd->isOwnDC()) | 
|---|
| 524 | { | 
|---|
| 525 | pDCData pHps = (pDCData)GpiQueryDCData((HPS)pPaint->hdc); | 
|---|
| 526 | if (pHps && (pHps->hdcType == TYPE_3)) | 
|---|
| 527 | { | 
|---|
| 528 | WinEndPaint (pHps->hps); | 
|---|
| 529 | } | 
|---|
| 530 | } | 
|---|
| 531 | else | 
|---|
| 532 | { | 
|---|
| 533 | O32_EndPaint (HWND_DESKTOP, pPaint); | 
|---|
| 534 | } | 
|---|
| 535 | wnd->setSuppressErase(FALSE); | 
|---|
| 536 |  | 
|---|
| 537 | exit: | 
|---|
| 538 | O32_SetLastError(0); | 
|---|
| 539 | return TRUE; | 
|---|
| 540 | } | 
|---|
| 541 | //****************************************************************************** | 
|---|
| 542 | //****************************************************************************** | 
|---|
| 543 | BOOL WIN32API GetUpdateRect (HWND hwnd, LPRECT pRect, BOOL erase) | 
|---|
| 544 | { | 
|---|
| 545 | if (!hwnd) | 
|---|
| 546 | { | 
|---|
| 547 | O32_SetLastError (ERROR_INVALID_HANDLE); | 
|---|
| 548 | return FALSE; | 
|---|
| 549 | } | 
|---|
| 550 |  | 
|---|
| 551 | RECTL rectl; | 
|---|
| 552 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd); | 
|---|
| 553 |  | 
|---|
| 554 | if (!wnd) | 
|---|
| 555 | { | 
|---|
| 556 | O32_SetLastError (ERROR_INVALID_HANDLE); | 
|---|
| 557 | return FALSE; | 
|---|
| 558 | } | 
|---|
| 559 |  | 
|---|
| 560 | BOOL updateRegionExists = WinQueryUpdateRect (wnd->getOS2WindowHandle(), pRect ? &rectl : NULL); | 
|---|
| 561 | if (!pRect) { | 
|---|
| 562 | return (updateRegionExists); | 
|---|
| 563 | } | 
|---|
| 564 |  | 
|---|
| 565 | if (updateRegionExists) | 
|---|
| 566 | { | 
|---|
| 567 | //CB: for PM empty rect is valid | 
|---|
| 568 | if ((rectl.xLeft == rectl.xRight) || (rectl.yTop == rectl.yBottom)) return FALSE; | 
|---|
| 569 | //SvL: Hack for memory.exe (doesn't get repainted properly otherwise) | 
|---|
| 570 | //      if (wnd->isOwnDC() && wnd->getOwnDC()) | 
|---|
| 571 | if (wnd->isOwnDC()) | 
|---|
| 572 | { | 
|---|
| 573 | pDCData pHps = NULL; | 
|---|
| 574 | pHps = (pDCData)GpiQueryDCData(wnd->getOwnDC()); | 
|---|
| 575 | if (!pHps) | 
|---|
| 576 | { | 
|---|
| 577 | O32_SetLastError (ERROR_INVALID_HANDLE); | 
|---|
| 578 | return FALSE; | 
|---|
| 579 | } | 
|---|
| 580 | GpiConvert (pHps->hps, CVTC_DEVICE, CVTC_WORLD, 2, (PPOINTL)&rectl); | 
|---|
| 581 | } | 
|---|
| 582 | else | 
|---|
| 583 | { | 
|---|
| 584 | long height   = wnd->getClientHeight(); | 
|---|
| 585 | rectl.yTop    = height - rectl.yTop; | 
|---|
| 586 | rectl.yBottom = height - rectl.yBottom; | 
|---|
| 587 | } | 
|---|
| 588 |  | 
|---|
| 589 | if (pRect) | 
|---|
| 590 | WINRECT_FROM_PMRECT (*pRect, rectl); | 
|---|
| 591 |  | 
|---|
| 592 | if (erase) | 
|---|
| 593 | sendEraseBkgnd (wnd); | 
|---|
| 594 | } | 
|---|
| 595 | else | 
|---|
| 596 | { | 
|---|
| 597 | if (pRect) | 
|---|
| 598 | pRect->left = pRect->top = pRect->right = pRect->bottom = 0; | 
|---|
| 599 | } | 
|---|
| 600 |  | 
|---|
| 601 | return updateRegionExists; | 
|---|
| 602 | } | 
|---|
| 603 | //****************************************************************************** | 
|---|
| 604 | //functions for WM_NCPAINT | 
|---|
| 605 | //****************************************************************************** | 
|---|
| 606 | INT SYSTEM GetOS2UpdateRgn(HWND hwnd,HRGN hrgn) | 
|---|
| 607 | { | 
|---|
| 608 | return O32_GetUpdateRgn(hwnd,hrgn,FALSE); | 
|---|
| 609 | } | 
|---|
| 610 | //****************************************************************************** | 
|---|
| 611 | //****************************************************************************** | 
|---|
| 612 | BOOL SYSTEM GetOS2UpdateRect(HWND hwnd,LPRECT pRect) | 
|---|
| 613 | { | 
|---|
| 614 | RECTL rectl; | 
|---|
| 615 | BOOL updateRegionExists = WinQueryUpdateRect(hwnd,pRect ? &rectl:NULL); | 
|---|
| 616 |  | 
|---|
| 617 | if (!pRect) | 
|---|
| 618 | return (updateRegionExists); | 
|---|
| 619 |  | 
|---|
| 620 | if (updateRegionExists) | 
|---|
| 621 | { | 
|---|
| 622 | //CB: for PM empty rect is valid | 
|---|
| 623 | if ((rectl.xLeft == rectl.xRight) || (rectl.yTop == rectl.yBottom)) return FALSE; | 
|---|
| 624 | mapOS2ToWin32Rect(hwnd,(PRECTLOS2)&rectl,pRect); | 
|---|
| 625 | } else | 
|---|
| 626 | pRect->left = pRect->top = pRect->right = pRect->bottom = 0; | 
|---|
| 627 |  | 
|---|
| 628 | return updateRegionExists; | 
|---|
| 629 | } | 
|---|
| 630 | //****************************************************************************** | 
|---|
| 631 | //****************************************************************************** | 
|---|
| 632 | int WIN32API GetUpdateRgn (HWND hwnd, HRGN hrgn, BOOL erase) | 
|---|
| 633 | { | 
|---|
| 634 | LONG Complexity; | 
|---|
| 635 |  | 
|---|
| 636 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd); | 
|---|
| 637 |  | 
|---|
| 638 | if (!wnd) | 
|---|
| 639 | { | 
|---|
| 640 | O32_SetLastError (ERROR_INVALID_HANDLE); | 
|---|
| 641 | return ERROR_W; | 
|---|
| 642 | } | 
|---|
| 643 |  | 
|---|
| 644 | Complexity = O32_GetUpdateRgn (wnd->getOS2WindowHandle(), hrgn, FALSE); | 
|---|
| 645 | if (erase && (Complexity > NULLREGION_W)) sendEraseBkgnd (wnd); | 
|---|
| 646 |  | 
|---|
| 647 | return Complexity; | 
|---|
| 648 | } | 
|---|
| 649 | //****************************************************************************** | 
|---|
| 650 | // This implementation of GetDCEx supports | 
|---|
| 651 | // DCX_WINDOW | 
|---|
| 652 | // DCX_CACHE | 
|---|
| 653 | // DCX_EXCLUDERGN (complex regions allowed) | 
|---|
| 654 | // DCX_INTERSECTRGN (complex regions allowed) | 
|---|
| 655 | //****************************************************************************** | 
|---|
| 656 | HDC WIN32API GetDCEx (HWND hwnd, HRGN hrgn, ULONG flags) | 
|---|
| 657 | { | 
|---|
| 658 | Win32BaseWindow *wnd = NULL; | 
|---|
| 659 | HWND     hWindow; | 
|---|
| 660 | BOOL     success; | 
|---|
| 661 | pDCData  pHps = NULL; | 
|---|
| 662 | HPS      hps  = NULLHANDLE; | 
|---|
| 663 | BOOL     drawingAllowed = TRUE; | 
|---|
| 664 | BOOL     isWindowOwnDC; | 
|---|
| 665 | BOOL     creatingOwnDC = FALSE; | 
|---|
| 666 | PS_Type  psType; | 
|---|
| 667 |  | 
|---|
| 668 | if (hwnd) | 
|---|
| 669 | { | 
|---|
| 670 | wnd = Win32BaseWindow::GetWindowFromHandle(hwnd); | 
|---|
| 671 | if(wnd == NULL) { | 
|---|
| 672 | dprintf (("ERROR: User32: GetDCEx bad window handle %X!!!!!", hwnd)); | 
|---|
| 673 | O32_SetLastError(ERROR_INVALID_WINDOW_HANDLE_W); | 
|---|
| 674 | return 0; | 
|---|
| 675 | } | 
|---|
| 676 | //SvL: Experimental change (doesn't work right) | 
|---|
| 677 | #if 0 | 
|---|
| 678 | if(wnd->fHasParentDC() && wnd->getParent()) { | 
|---|
| 679 | wnd = wnd->getParent(); | 
|---|
| 680 | } | 
|---|
| 681 | #endif | 
|---|
| 682 | if (flags & DCX_WINDOW_W) | 
|---|
| 683 | hWindow = wnd->getOS2FrameWindowHandle(); | 
|---|
| 684 | else | 
|---|
| 685 | hWindow = wnd->getOS2WindowHandle(); | 
|---|
| 686 | } | 
|---|
| 687 | else | 
|---|
| 688 | hWindow = HWND_DESKTOP; | 
|---|
| 689 |  | 
|---|
| 690 | dprintf (("User32: GetDCEx hwnd %x (%x %x) -> wnd %x", hwnd, hrgn, flags, wnd)); | 
|---|
| 691 |  | 
|---|
| 692 | //SvL: Hack for memory.exe (doesn't get repainted properly otherwise) | 
|---|
| 693 | //   isWindowOwnDC = (((hWindow == HWND_DESKTOP) ? FALSE : (wnd->isOwnDC() && wnd->getOwnDC())) | 
|---|
| 694 | isWindowOwnDC = (((hWindow == HWND_DESKTOP) ? FALSE : (wnd->isOwnDC())) | 
|---|
| 695 | && !(flags & DCX_CACHE_W|DCX_WINDOW_W)); | 
|---|
| 696 |  | 
|---|
| 697 | if (isWindowOwnDC) | 
|---|
| 698 | { | 
|---|
| 699 | hps = wnd->getOwnDC(); | 
|---|
| 700 | if (hps) | 
|---|
| 701 | { | 
|---|
| 702 | pDCData pHps = (pDCData)GpiQueryDCData (hps); | 
|---|
| 703 | if (!pHps) | 
|---|
| 704 | goto error; | 
|---|
| 705 |  | 
|---|
| 706 | setPageXForm (wnd, pHps); | 
|---|
| 707 |  | 
|---|
| 708 | pHps->hdcType = TYPE_1; | 
|---|
| 709 | return (HDC)hps; | 
|---|
| 710 | } | 
|---|
| 711 | else | 
|---|
| 712 | creatingOwnDC = TRUE; | 
|---|
| 713 | } | 
|---|
| 714 |  | 
|---|
| 715 | if (isWindowOwnDC) | 
|---|
| 716 | { | 
|---|
| 717 | SIZEL sizel = {0,0}; | 
|---|
| 718 | hps = GpiCreatePS (WinQueryAnchorBlock (hWindow), | 
|---|
| 719 | WinOpenWindowDC (hWindow), | 
|---|
| 720 | &sizel, PU_PELS | GPIT_MICRO | GPIA_ASSOC ); | 
|---|
| 721 | psType = MICRO; | 
|---|
| 722 | } | 
|---|
| 723 | else | 
|---|
| 724 | { | 
|---|
| 725 | if (hWindow == HWND_DESKTOP) | 
|---|
| 726 | hps = WinGetScreenPS (hWindow); | 
|---|
| 727 | else | 
|---|
| 728 | hps = WinGetPS (hWindow); | 
|---|
| 729 |  | 
|---|
| 730 | psType = MICRO_CACHED; | 
|---|
| 731 | } | 
|---|
| 732 |  | 
|---|
| 733 | if (!hps) | 
|---|
| 734 | goto error; | 
|---|
| 735 |  | 
|---|
| 736 | HPSToHDC (hWindow, hps, NULL, NULL); | 
|---|
| 737 | pHps = (pDCData)GpiQueryDCData (hps); | 
|---|
| 738 |  | 
|---|
| 739 | if ((flags & DCX_EXCLUDERGN_W) || (flags & DCX_INTERSECTRGN_W)) | 
|---|
| 740 | { | 
|---|
| 741 | ULONG BytesNeeded; | 
|---|
| 742 | PRGNDATA_W RgnData; | 
|---|
| 743 | PRECT pr; | 
|---|
| 744 | int i; | 
|---|
| 745 | RECTL rectl; | 
|---|
| 746 |  | 
|---|
| 747 | if (!hrgn) | 
|---|
| 748 | goto error; | 
|---|
| 749 |  | 
|---|
| 750 | BytesNeeded = O32_GetRegionData (hrgn, 0, NULL); | 
|---|
| 751 | RgnData = (PRGNDATA_W)_alloca (BytesNeeded); | 
|---|
| 752 | if (RgnData == NULL) | 
|---|
| 753 | goto error; | 
|---|
| 754 | O32_GetRegionData (hrgn, BytesNeeded, RgnData); | 
|---|
| 755 |  | 
|---|
| 756 | i = RgnData->rdh.nCount; | 
|---|
| 757 | pr = (PRECT)(RgnData->Buffer); | 
|---|
| 758 |  | 
|---|
| 759 | success = TRUE; | 
|---|
| 760 | if (flags & DCX_EXCLUDERGN_W) | 
|---|
| 761 | { | 
|---|
| 762 | #if 0 //CB: todo | 
|---|
| 763 | for (; (i > 0) && success; i--, pr++) { | 
|---|
| 764 | LONG y = pr->yBottom; | 
|---|
| 765 |  | 
|---|
| 766 | pr->yBottom = height - pr->yTop; | 
|---|
| 767 | pr->yTop    = height - y; | 
|---|
| 768 | success &= GpiExcludeClipRectangle (pHps->hps, pr); | 
|---|
| 769 | } | 
|---|
| 770 | #endif | 
|---|
| 771 | } else //DCX_INTERSECTRGN_W | 
|---|
| 772 | { | 
|---|
| 773 | O32_SelectClipRgn(pHps->hps,hrgn); //CB: works so far | 
|---|
| 774 | } | 
|---|
| 775 | if (!success) | 
|---|
| 776 | goto error; | 
|---|
| 777 | } | 
|---|
| 778 |  | 
|---|
| 779 | if (creatingOwnDC) | 
|---|
| 780 | wnd->setOwnDC ((HDC)hps); | 
|---|
| 781 |  | 
|---|
| 782 | pHps->psType  = psType; | 
|---|
| 783 | pHps->hdcType = TYPE_1; | 
|---|
| 784 | GpiSetDrawControl (hps, DCTL_DISPLAY, drawingAllowed ? DCTL_ON : DCTL_OFF); | 
|---|
| 785 |  | 
|---|
| 786 | return (HDC)pHps->hps; | 
|---|
| 787 |  | 
|---|
| 788 | error: | 
|---|
| 789 | /* Something went wrong; clean up | 
|---|
| 790 | */ | 
|---|
| 791 | if (pHps) | 
|---|
| 792 | { | 
|---|
| 793 | if (pHps->hps) | 
|---|
| 794 | { | 
|---|
| 795 | if(pHps->psType == MICRO_CACHED) | 
|---|
| 796 | WinReleasePS(pHps->hps); | 
|---|
| 797 | else | 
|---|
| 798 | GpiDestroyPS(pHps->hps); | 
|---|
| 799 | } | 
|---|
| 800 |  | 
|---|
| 801 | if (pHps->hdc)     DevCloseDC(pHps->hdc); | 
|---|
| 802 | if (pHps->hrgnHDC) GpiDestroyRegion(pHps->hps, pHps->hrgnHDC); | 
|---|
| 803 |  | 
|---|
| 804 | O32_DeleteObject (pHps->nullBitmapHandle); | 
|---|
| 805 | } | 
|---|
| 806 | O32_SetLastError (ERROR_INVALID_PARAMETER); | 
|---|
| 807 | return NULL; | 
|---|
| 808 | } | 
|---|
| 809 | //****************************************************************************** | 
|---|
| 810 | //****************************************************************************** | 
|---|
| 811 | HDC WIN32API GetDC (HWND hwnd) | 
|---|
| 812 | { | 
|---|
| 813 | return GetDCEx (hwnd, NULL, 0); | 
|---|
| 814 | } | 
|---|
| 815 | //****************************************************************************** | 
|---|
| 816 | //****************************************************************************** | 
|---|
| 817 | HDC WIN32API GetWindowDC (HWND hwnd) | 
|---|
| 818 | { | 
|---|
| 819 | return GetDCEx (hwnd, NULL, DCX_WINDOW_W); | 
|---|
| 820 | } | 
|---|
| 821 | //****************************************************************************** | 
|---|
| 822 | //****************************************************************************** | 
|---|
| 823 | int WIN32API ReleaseDC (HWND hwnd, HDC hdc) | 
|---|
| 824 | { | 
|---|
| 825 | BOOL isOwnDC = FALSE; | 
|---|
| 826 | int rc; | 
|---|
| 827 |  | 
|---|
| 828 | if (hwnd) | 
|---|
| 829 | { | 
|---|
| 830 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd); | 
|---|
| 831 | //SvL: Hack for memory.exe (doesn't get repainted properly otherwise) | 
|---|
| 832 | //      isOwnDC = wnd->isOwnDC() && wnd->getOwnDC(); | 
|---|
| 833 | isOwnDC = wnd->isOwnDC() && (wnd->getOwnDC() == hdc); | 
|---|
| 834 | } | 
|---|
| 835 | if (isOwnDC) | 
|---|
| 836 | rc = TRUE; | 
|---|
| 837 | else | 
|---|
| 838 | rc = O32_ReleaseDC (0, hdc); | 
|---|
| 839 |  | 
|---|
| 840 | dprintf(("ReleaseDC %x %x", hwnd, hdc)); | 
|---|
| 841 | return (rc); | 
|---|
| 842 | } | 
|---|
| 843 | //****************************************************************************** | 
|---|
| 844 | //****************************************************************************** | 
|---|
| 845 | BOOL WIN32API UpdateWindow (HWND hwnd) | 
|---|
| 846 | { | 
|---|
| 847 | if (!hwnd) | 
|---|
| 848 | return FALSE; | 
|---|
| 849 |  | 
|---|
| 850 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd); | 
|---|
| 851 |  | 
|---|
| 852 | dprintf (("User32: UpdateWindow hwnd %x -> wnd %x", hwnd, wnd)); | 
|---|
| 853 |  | 
|---|
| 854 | #if 0 | 
|---|
| 855 | if (WinQueryUpdateRect (wnd->getOS2WindowHandle(), NULL)) | 
|---|
| 856 | sendEraseBkgnd (wnd); | 
|---|
| 857 | #endif | 
|---|
| 858 |  | 
|---|
| 859 | WinUpdateWindow(wnd->getOS2FrameWindowHandle()); | 
|---|
| 860 |  | 
|---|
| 861 | return (TRUE); | 
|---|
| 862 | } | 
|---|
| 863 | //****************************************************************************** | 
|---|
| 864 | // This implementation of RedrawWindow supports | 
|---|
| 865 | // RDW_ERASE | 
|---|
| 866 | // RDW_NOERASE | 
|---|
| 867 | // RDW_INTERNALPAINT | 
|---|
| 868 | // RDW_NOINTERNALPAINT | 
|---|
| 869 | // RDW_INVALIDATE | 
|---|
| 870 | // RDW_VALIDATE | 
|---|
| 871 | // RDW_ERASENOW | 
|---|
| 872 | // RDW_UPDATENOW | 
|---|
| 873 | //****************************************************************************** | 
|---|
| 874 | BOOL WIN32API RedrawWindow(HWND hwnd, const RECT* pRect, HRGN hrgn, DWORD redraw) | 
|---|
| 875 | { | 
|---|
| 876 | Win32BaseWindow *wnd; | 
|---|
| 877 |  | 
|---|
| 878 | if (redraw & (RDW_FRAME_W | RDW_NOFRAME_W)) | 
|---|
| 879 | { | 
|---|
| 880 | O32_SetLastError (ERROR_NOT_SUPPORTED); | 
|---|
| 881 | return FALSE; | 
|---|
| 882 | } | 
|---|
| 883 |  | 
|---|
| 884 | if (hwnd == NULLHANDLE) | 
|---|
| 885 | { | 
|---|
| 886 | #if 1 | 
|---|
| 887 | // Don't do this for now (causes lots of desktop repaints in WordPad) | 
|---|
| 888 | O32_SetLastError (ERROR_INVALID_PARAMETER); | 
|---|
| 889 | return FALSE; | 
|---|
| 890 | #else | 
|---|
| 891 | hwnd = HWND_DESKTOP; | 
|---|
| 892 | wnd  = Win32BaseWindow::GetWindowFromOS2Handle(OSLIB_HWND_DESKTOP); | 
|---|
| 893 |  | 
|---|
| 894 | if (!wnd) | 
|---|
| 895 | { | 
|---|
| 896 | dprintf(("USER32:dc: RedrawWindow can't find desktop window %08xh\n", | 
|---|
| 897 | hwnd)); | 
|---|
| 898 | O32_SetLastError (ERROR_INVALID_PARAMETER); | 
|---|
| 899 | return FALSE; | 
|---|
| 900 | } | 
|---|
| 901 | #endif | 
|---|
| 902 | } | 
|---|
| 903 | else | 
|---|
| 904 | { | 
|---|
| 905 | wnd = Win32BaseWindow::GetWindowFromHandle (hwnd); | 
|---|
| 906 |  | 
|---|
| 907 | if (!wnd) | 
|---|
| 908 | { | 
|---|
| 909 | dprintf(("USER32:dc: RedrawWindow can't find window %08xh\n", | 
|---|
| 910 | hwnd)); | 
|---|
| 911 | O32_SetLastError (ERROR_INVALID_PARAMETER); | 
|---|
| 912 | return FALSE; | 
|---|
| 913 | } | 
|---|
| 914 | hwnd = wnd->getOS2WindowHandle(); | 
|---|
| 915 | } | 
|---|
| 916 |  | 
|---|
| 917 | BOOL  IncludeChildren = redraw & RDW_ALLCHILDREN_W ? TRUE : FALSE; | 
|---|
| 918 | BOOL  success = TRUE; | 
|---|
| 919 | HPS   hpsTemp = NULLHANDLE; | 
|---|
| 920 | HRGN  hrgnTemp = NULLHANDLE; | 
|---|
| 921 | RECTL rectl; | 
|---|
| 922 |  | 
|---|
| 923 | if (redraw & RDW_UPDATENOW_W) redraw &= ~RDW_ERASENOW_W; | 
|---|
| 924 |  | 
|---|
| 925 | if (redraw & RDW_NOERASE_W) | 
|---|
| 926 | wnd->setEraseBkgnd (FALSE); | 
|---|
| 927 |  | 
|---|
| 928 | //SvL: Test | 
|---|
| 929 | //   if (redraw & RDW_UPDATENOW_W) | 
|---|
| 930 | //      wnd->setSuppressErase (FALSE); | 
|---|
| 931 | //   else if (redraw & RDW_ERASENOW_W) | 
|---|
| 932 | //      wnd->setSuppressErase (FALSE); | 
|---|
| 933 |  | 
|---|
| 934 | if (hrgn) | 
|---|
| 935 | { | 
|---|
| 936 | ULONG BytesNeeded; | 
|---|
| 937 | PRGNDATA_W RgnData; | 
|---|
| 938 | PRECTL pr; | 
|---|
| 939 | int i; | 
|---|
| 940 | LONG height = wnd ? wnd->getClientHeight() : OSLibQueryScreenHeight(); | 
|---|
| 941 |  | 
|---|
| 942 | if (!hrgn) | 
|---|
| 943 | goto error; | 
|---|
| 944 |  | 
|---|
| 945 | BytesNeeded = O32_GetRegionData (hrgn, 0, NULL); | 
|---|
| 946 | RgnData = (PRGNDATA_W)_alloca (BytesNeeded); | 
|---|
| 947 | if (RgnData == NULL) | 
|---|
| 948 | goto error; | 
|---|
| 949 | O32_GetRegionData (hrgn, BytesNeeded, RgnData); | 
|---|
| 950 |  | 
|---|
| 951 | pr = (PRECTL)(RgnData->Buffer); | 
|---|
| 952 | for (i = RgnData->rdh.nCount; i > 0; i--, pr++) { | 
|---|
| 953 | LONG temp = pr->yTop; | 
|---|
| 954 | pr->yTop = height - pr->yBottom; | 
|---|
| 955 | pr->yBottom = height - temp; | 
|---|
| 956 | } | 
|---|
| 957 |  | 
|---|
| 958 | hpsTemp = WinGetScreenPS (HWND_DESKTOP); | 
|---|
| 959 | hrgnTemp = GpiCreateRegion (hpsTemp, RgnData->rdh.nCount, (PRECTL)(RgnData->Buffer)); | 
|---|
| 960 | if (!hrgnTemp) goto error; | 
|---|
| 961 | } | 
|---|
| 962 | else if (pRect) | 
|---|
| 963 | { | 
|---|
| 964 | LONG height = wnd ? wnd->getClientHeight() : OSLibQueryScreenHeight(); | 
|---|
| 965 |  | 
|---|
| 966 | PMRECT_FROM_WINRECT (rectl, *pRect); | 
|---|
| 967 | rectl.yTop    = height - rectl.yTop; | 
|---|
| 968 | rectl.yBottom = height - rectl.yBottom; | 
|---|
| 969 | } | 
|---|
| 970 |  | 
|---|
| 971 | if (redraw & RDW_INVALIDATE_W) | 
|---|
| 972 | { | 
|---|
| 973 | if (redraw & RDW_ERASE_W) | 
|---|
| 974 | wnd->setEraseBkgnd (TRUE, TRUE); | 
|---|
| 975 |  | 
|---|
| 976 | if (!pRect && !hrgn) | 
|---|
| 977 | success = WinInvalidateRect (hwnd, NULL, IncludeChildren); | 
|---|
| 978 | else if (hrgn) | 
|---|
| 979 | success = WinInvalidateRegion (hwnd, hrgnTemp, IncludeChildren); | 
|---|
| 980 | else | 
|---|
| 981 | success = WinInvalidateRect (hwnd, &rectl, IncludeChildren); | 
|---|
| 982 | if (!success) goto error; | 
|---|
| 983 | } | 
|---|
| 984 | else if (redraw & RDW_VALIDATE_W) | 
|---|
| 985 | { | 
|---|
| 986 | if (WinQueryUpdateRect (hwnd, NULL)) | 
|---|
| 987 | { | 
|---|
| 988 | if (!pRect && !hrgn) | 
|---|
| 989 | success = WinValidateRect (hwnd, NULL, IncludeChildren); | 
|---|
| 990 | else if (hrgn) | 
|---|
| 991 | success = WinValidateRegion (hwnd, hrgnTemp, IncludeChildren); | 
|---|
| 992 | else | 
|---|
| 993 | success = WinValidateRect (hwnd, &rectl, IncludeChildren); | 
|---|
| 994 | if (!success) goto error; | 
|---|
| 995 | } | 
|---|
| 996 | } | 
|---|
| 997 |  | 
|---|
| 998 | if (WinQueryUpdateRect (hwnd, NULL)) | 
|---|
| 999 | { | 
|---|
| 1000 | if (redraw & RDW_UPDATENOW_W) | 
|---|
| 1001 | wnd->MsgPaint (0, FALSE); | 
|---|
| 1002 |  | 
|---|
| 1003 | else if ((redraw & RDW_ERASE_W) && (redraw & RDW_ERASENOW_W)) | 
|---|
| 1004 | wnd->setEraseBkgnd (FALSE, !sendEraseBkgnd (wnd)); | 
|---|
| 1005 | } | 
|---|
| 1006 | else if ((redraw & RDW_INTERNALPAINT_W) && !(redraw & RDW_INVALIDATE_W)) | 
|---|
| 1007 | { | 
|---|
| 1008 | if (redraw & RDW_UPDATENOW_W) | 
|---|
| 1009 | wnd->MsgPaint (0, FALSE); | 
|---|
| 1010 | //      else | 
|---|
| 1011 | //         WinPostMsg( hwnd, WM_VIRTUAL_INTERNALPAINT, MPVOID, MPVOID ); | 
|---|
| 1012 | } | 
|---|
| 1013 |  | 
|---|
| 1014 | error: | 
|---|
| 1015 | /* clean up */ | 
|---|
| 1016 | if (hrgnTemp) | 
|---|
| 1017 | GpiDestroyRegion (hpsTemp, hrgnTemp); | 
|---|
| 1018 |  | 
|---|
| 1019 | if (hpsTemp) | 
|---|
| 1020 | WinReleasePS (hpsTemp); | 
|---|
| 1021 |  | 
|---|
| 1022 | //SvL: Test | 
|---|
| 1023 | //   if ((redraw & RDW_INVALIDATE_W) == 0) | 
|---|
| 1024 | //      wnd->setSuppressErase (FALSE); | 
|---|
| 1025 | //   else if ((redraw & RDW_ERASENOW_W) == RDW_ERASENOW_W) | 
|---|
| 1026 | //      wnd->setSuppressErase (TRUE); | 
|---|
| 1027 |  | 
|---|
| 1028 | if (!success) | 
|---|
| 1029 | O32_SetLastError (ERROR_INVALID_PARAMETER); | 
|---|
| 1030 |  | 
|---|
| 1031 | return (success); | 
|---|
| 1032 | } | 
|---|
| 1033 | //****************************************************************************** | 
|---|
| 1034 | //****************************************************************************** | 
|---|
| 1035 | BOOL WIN32API InvalidateRect (HWND hwnd, const RECT *pRect, BOOL erase) | 
|---|
| 1036 | { | 
|---|
| 1037 | BOOL result; | 
|---|
| 1038 |  | 
|---|
| 1039 | result = RedrawWindow (hwnd, pRect, NULLHANDLE, | 
|---|
| 1040 | RDW_ALLCHILDREN_W | RDW_INVALIDATE_W | | 
|---|
| 1041 | (erase ? RDW_ERASE_W : 0) | | 
|---|
| 1042 | (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0)); | 
|---|
| 1043 | return (result); | 
|---|
| 1044 | } | 
|---|
| 1045 | //****************************************************************************** | 
|---|
| 1046 | //****************************************************************************** | 
|---|
| 1047 | BOOL WIN32API InvalidateRgn (HWND hwnd, HRGN hrgn, BOOL erase) | 
|---|
| 1048 | { | 
|---|
| 1049 | BOOL result; | 
|---|
| 1050 |  | 
|---|
| 1051 | result = RedrawWindow (hwnd, NULL, hrgn, | 
|---|
| 1052 | RDW_ALLCHILDREN_W | RDW_INVALIDATE_W | | 
|---|
| 1053 | (erase ? RDW_ERASE_W : 0) | | 
|---|
| 1054 | (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0)); | 
|---|
| 1055 | return (result); | 
|---|
| 1056 | } | 
|---|
| 1057 | //****************************************************************************** | 
|---|
| 1058 | //****************************************************************************** | 
|---|
| 1059 | BOOL setPMRgnIntoWinRgn (HRGN hrgnPM, HRGN hrgnWin, LONG height) | 
|---|
| 1060 | { | 
|---|
| 1061 | BOOL    rc; | 
|---|
| 1062 | HPS     hps = WinGetScreenPS (HWND_DESKTOP); | 
|---|
| 1063 | RGNRECT rgnRect; | 
|---|
| 1064 | rgnRect.ircStart    = 1; | 
|---|
| 1065 | rgnRect.crc         = 0; | 
|---|
| 1066 | rgnRect.ulDirection = RECTDIR_LFRT_TOPBOT;     // doesn't make a difference because we're getting them all | 
|---|
| 1067 |  | 
|---|
| 1068 | rc = GpiQueryRegionRects (hps, hrgnPM, NULL, &rgnRect, NULL); | 
|---|
| 1069 |  | 
|---|
| 1070 | if (rc && (rgnRect.crcReturned > 0)) | 
|---|
| 1071 | { | 
|---|
| 1072 | PRECTL Rcls = new RECTL[rgnRect.crcReturned]; | 
|---|
| 1073 | PRECTL pRcl = Rcls; | 
|---|
| 1074 |  | 
|---|
| 1075 | if (Rcls != NULL) | 
|---|
| 1076 | { | 
|---|
| 1077 | rgnRect.crc = rgnRect.crcReturned; | 
|---|
| 1078 | rc = GpiQueryRegionRects (hps, hrgnPM, NULL, &rgnRect, Rcls); | 
|---|
| 1079 |  | 
|---|
| 1080 | rc = O32_SetRectRgn (hrgnWin, pRcl->xLeft, | 
|---|
| 1081 | pRcl->xRight, | 
|---|
| 1082 | height - pRcl->yTop, | 
|---|
| 1083 | height - pRcl->yBottom); | 
|---|
| 1084 |  | 
|---|
| 1085 | if (rgnRect.crcReturned > 1) | 
|---|
| 1086 | { | 
|---|
| 1087 | int i; | 
|---|
| 1088 | HRGN temp; | 
|---|
| 1089 | temp = O32_CreateRectRgn (0, 0, 1, 1); | 
|---|
| 1090 |  | 
|---|
| 1091 | for (i = 1, pRcl++; rc && (i < rgnRect.crcReturned); i++, pRcl++) | 
|---|
| 1092 | { | 
|---|
| 1093 | rc = O32_SetRectRgn (temp, pRcl->xLeft, | 
|---|
| 1094 | pRcl->xRight, | 
|---|
| 1095 | height - pRcl->yTop, | 
|---|
| 1096 | height - pRcl->yBottom); | 
|---|
| 1097 | rc &= O32_CombineRgn (hrgnWin, hrgnWin, temp, RGN_OR_W); | 
|---|
| 1098 | } | 
|---|
| 1099 | O32_DeleteObject (temp); | 
|---|
| 1100 | } | 
|---|
| 1101 | delete[] Rcls; | 
|---|
| 1102 | } | 
|---|
| 1103 | else | 
|---|
| 1104 | { | 
|---|
| 1105 | rc = FALSE; | 
|---|
| 1106 | } | 
|---|
| 1107 | } | 
|---|
| 1108 | else | 
|---|
| 1109 | { | 
|---|
| 1110 | rc = O32_SetRectRgn (hrgnWin, 0, 0, 0, 0); | 
|---|
| 1111 | } | 
|---|
| 1112 |  | 
|---|
| 1113 | WinReleasePS (hps); | 
|---|
| 1114 | return (rc); | 
|---|
| 1115 | } | 
|---|
| 1116 | //****************************************************************************** | 
|---|
| 1117 | //****************************************************************************** | 
|---|
| 1118 | BOOL WIN32API ScrollDC (HDC hDC, int dx, int dy, const RECT *pScroll, | 
|---|
| 1119 | const RECT *pClip, HRGN hrgnUpdate, LPRECT pRectUpdate) | 
|---|
| 1120 | { | 
|---|
| 1121 | BOOL rc = TRUE; | 
|---|
| 1122 |  | 
|---|
| 1123 | dprintf (("USER32:  ScrollDC")); | 
|---|
| 1124 |  | 
|---|
| 1125 | if (!hDC) | 
|---|
| 1126 | { | 
|---|
| 1127 | return (FALSE); | 
|---|
| 1128 | } | 
|---|
| 1129 |  | 
|---|
| 1130 | pDCData pHps         = (pDCData)GpiQueryDCData ((HPS)hDC); | 
|---|
| 1131 | HWND    hwnd         = pHps->hwnd; | 
|---|
| 1132 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd); | 
|---|
| 1133 |  | 
|---|
| 1134 | if ((hwnd == NULLHANDLE) || !wnd) | 
|---|
| 1135 | { | 
|---|
| 1136 | return (FALSE); | 
|---|
| 1137 | } | 
|---|
| 1138 |  | 
|---|
| 1139 | POINTL ptl[2] = { 0, 0, dx, dy }; | 
|---|
| 1140 |  | 
|---|
| 1141 | GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, ptl); | 
|---|
| 1142 | dx = (int)(ptl[1].x - ptl[0].x); | 
|---|
| 1143 | dy = (int)(ptl[1].y - ptl[0].y); | 
|---|
| 1144 |  | 
|---|
| 1145 | RECTL scrollRect; | 
|---|
| 1146 | RECTL clipRect; | 
|---|
| 1147 |  | 
|---|
| 1148 | if (pClip) | 
|---|
| 1149 | { | 
|---|
| 1150 | clipRect.xLeft   = min (pClip->left, pClip->right); | 
|---|
| 1151 | clipRect.xRight  = max (pClip->left, pClip->right); | 
|---|
| 1152 | clipRect.yTop    = max (pClip->top,  pClip->bottom); | 
|---|
| 1153 | clipRect.yBottom = min (pClip->top,  pClip->bottom); | 
|---|
| 1154 |  | 
|---|
| 1155 | if ((pHps->graphicsMode == GM_COMPATIBLE_W) && | 
|---|
| 1156 | (clipRect.xLeft   != clipRect.xRight)   && | 
|---|
| 1157 | (clipRect.yBottom != clipRect.yTop)) | 
|---|
| 1158 | { | 
|---|
| 1159 | if (abs((int)pHps->viewportXExt) <= abs((int)pHps->windowExt.cx)) | 
|---|
| 1160 | clipRect.xRight -= abs(pHps->worldXDeltaFor1Pixel); | 
|---|
| 1161 | else | 
|---|
| 1162 | clipRect.xLeft  += abs(pHps->worldXDeltaFor1Pixel); | 
|---|
| 1163 |  | 
|---|
| 1164 | if (abs((int)pHps->viewportYExt) <= abs((int)pHps->windowExt.cy)) | 
|---|
| 1165 | clipRect.yTop    -= abs(pHps->worldYDeltaFor1Pixel); | 
|---|
| 1166 | else | 
|---|
| 1167 | clipRect.yBottom += abs(pHps->worldYDeltaFor1Pixel); | 
|---|
| 1168 | } | 
|---|
| 1169 | GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, (PPOINTL)&clipRect); | 
|---|
| 1170 | if (clipRect.xRight < clipRect.xLeft) { | 
|---|
| 1171 | ULONG temp      = clipRect.xLeft; | 
|---|
| 1172 | clipRect.xLeft  = clipRect.xRight; | 
|---|
| 1173 | clipRect.xRight = temp; | 
|---|
| 1174 | } | 
|---|
| 1175 | if (clipRect.yTop < clipRect.yBottom) { | 
|---|
| 1176 | ULONG temp       = clipRect.yBottom; | 
|---|
| 1177 | clipRect.yBottom = clipRect.yTop; | 
|---|
| 1178 | clipRect.yTop    = temp; | 
|---|
| 1179 | } | 
|---|
| 1180 | } | 
|---|
| 1181 |  | 
|---|
| 1182 | if (pScroll) | 
|---|
| 1183 | { | 
|---|
| 1184 | scrollRect.xLeft   = min (pScroll->left, pScroll->right); | 
|---|
| 1185 | scrollRect.xRight  = max (pScroll->left, pScroll->right); | 
|---|
| 1186 | scrollRect.yTop    = max (pScroll->top,  pScroll->bottom); | 
|---|
| 1187 | scrollRect.yBottom = min (pScroll->top,  pScroll->bottom); | 
|---|
| 1188 |  | 
|---|
| 1189 | if ((pHps->graphicsMode == GM_COMPATIBLE_W) && | 
|---|
| 1190 | (scrollRect.xLeft   != scrollRect.xRight)   && | 
|---|
| 1191 | (scrollRect.yBottom != scrollRect.yTop)) | 
|---|
| 1192 | { | 
|---|
| 1193 | if (abs((int)pHps->viewportXExt) <= abs((int)pHps->windowExt.cx)) | 
|---|
| 1194 | scrollRect.xRight -= abs(pHps->worldXDeltaFor1Pixel); | 
|---|
| 1195 | else | 
|---|
| 1196 | scrollRect.xLeft  += abs(pHps->worldXDeltaFor1Pixel); | 
|---|
| 1197 |  | 
|---|
| 1198 | if (abs((int)pHps->viewportYExt) <= abs((int)pHps->windowExt.cy)) | 
|---|
| 1199 | scrollRect.yTop    -= abs(pHps->worldYDeltaFor1Pixel); | 
|---|
| 1200 | else | 
|---|
| 1201 | scrollRect.yBottom += abs(pHps->worldYDeltaFor1Pixel); | 
|---|
| 1202 | } | 
|---|
| 1203 | GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, (PPOINTL)&scrollRect); | 
|---|
| 1204 | if (scrollRect.xRight < scrollRect.xLeft) { | 
|---|
| 1205 | ULONG temp        = scrollRect.xLeft; | 
|---|
| 1206 | scrollRect.xLeft  = scrollRect.xRight; | 
|---|
| 1207 | scrollRect.xRight = temp; | 
|---|
| 1208 | } | 
|---|
| 1209 | if (scrollRect.yTop < scrollRect.yBottom) { | 
|---|
| 1210 | ULONG temp         = scrollRect.yBottom; | 
|---|
| 1211 | scrollRect.yBottom = scrollRect.yTop; | 
|---|
| 1212 | scrollRect.yTop    = temp; | 
|---|
| 1213 | } | 
|---|
| 1214 | } | 
|---|
| 1215 | RECTL rectlUpdate; | 
|---|
| 1216 | HRGN  hrgn; | 
|---|
| 1217 |  | 
|---|
| 1218 | LONG lComplexity = WinScrollWindow (hwnd, dx, dy, (pScroll) ? &scrollRect : NULL, (pClip) ? &clipRect : NULL, hrgn, &rectlUpdate, 0); | 
|---|
| 1219 | if (lComplexity == RGN_ERROR) | 
|---|
| 1220 | { | 
|---|
| 1221 | return (FALSE); | 
|---|
| 1222 | } | 
|---|
| 1223 |  | 
|---|
| 1224 | RECT winRectUpdate; | 
|---|
| 1225 | LONG height = wnd->getClientHeight(); | 
|---|
| 1226 |  | 
|---|
| 1227 | winRectUpdate.left   = rectlUpdate.xLeft; | 
|---|
| 1228 | winRectUpdate.right  = rectlUpdate.xRight; | 
|---|
| 1229 | winRectUpdate.top    = height - rectlUpdate.yTop; | 
|---|
| 1230 | winRectUpdate.bottom = height - rectlUpdate.yBottom; | 
|---|
| 1231 |  | 
|---|
| 1232 | if (pRectUpdate) | 
|---|
| 1233 | *pRectUpdate = winRectUpdate; | 
|---|
| 1234 |  | 
|---|
| 1235 | if (hrgnUpdate) | 
|---|
| 1236 | rc = setPMRgnIntoWinRgn (hrgn, hrgnUpdate, height); | 
|---|
| 1237 |  | 
|---|
| 1238 | return (rc); | 
|---|
| 1239 | } | 
|---|
| 1240 | //****************************************************************************** | 
|---|
| 1241 | //****************************************************************************** | 
|---|
| 1242 | #if 1 | 
|---|
| 1243 | BOOL WIN32API ScrollWindow(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip) | 
|---|
| 1244 | { | 
|---|
| 1245 | Win32BaseWindow *window; | 
|---|
| 1246 | APIRET  rc; | 
|---|
| 1247 | RECTL   clientRect; | 
|---|
| 1248 | RECTL   scrollRect; | 
|---|
| 1249 | RECTL   clipRect; | 
|---|
| 1250 | PRECT   pClientRect; | 
|---|
| 1251 | PRECTL  pScrollRect = NULL; | 
|---|
| 1252 | PRECTL  pClipRect   = NULL; | 
|---|
| 1253 | ULONG   scrollFlags = SW_INVALIDATERGN; | 
|---|
| 1254 |  | 
|---|
| 1255 | window = Win32BaseWindow::GetWindowFromHandle(hwnd); | 
|---|
| 1256 | if(!window) { | 
|---|
| 1257 | dprintf(("ScrollWindow, window %x not found", hwnd)); | 
|---|
| 1258 | return 0; | 
|---|
| 1259 | } | 
|---|
| 1260 | dprintf(("ScrollWindow %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip)); | 
|---|
| 1261 | pClientRect = window->getClientRectPtr(); | 
|---|
| 1262 | clientRect.xLeft   = 0; | 
|---|
| 1263 | clientRect.yBottom = 0; | 
|---|
| 1264 | clientRect.xRight  = pClientRect->right - pClientRect->left; | 
|---|
| 1265 | clientRect.yTop    = pClientRect->bottom - pClientRect->top; | 
|---|
| 1266 | if(pScroll) { | 
|---|
| 1267 | mapWin32ToOS2Rect(window,(RECT *)pScroll, (PRECTLOS2)&scrollRect); | 
|---|
| 1268 | pScrollRect = &scrollRect; | 
|---|
| 1269 |  | 
|---|
| 1270 | //Scroll rectangle relative to client area | 
|---|
| 1271 | WinIntersectRect ((HAB) 0, pScrollRect, pScrollRect, &clientRect); | 
|---|
| 1272 | } | 
|---|
| 1273 | else scrollFlags |= SW_SCROLLCHILDREN; | 
|---|
| 1274 |  | 
|---|
| 1275 | if(pClip) { | 
|---|
| 1276 | mapWin32ToOS2Rect(window,(RECT *)pClip, (PRECTLOS2)&clipRect); | 
|---|
| 1277 | pClipRect = &clipRect; | 
|---|
| 1278 |  | 
|---|
| 1279 | //Clip rectangle relative to client area | 
|---|
| 1280 | WinIntersectRect ((HAB) 0, pClipRect, pClipRect, &clientRect); | 
|---|
| 1281 | } | 
|---|
| 1282 |  | 
|---|
| 1283 | dy = revertDy (window, dy); | 
|---|
| 1284 |  | 
|---|
| 1285 | rc = WinScrollWindow(window->getOS2WindowHandle(), dx, dy, | 
|---|
| 1286 | pScrollRect, pClipRect, NULLHANDLE, | 
|---|
| 1287 | NULL, scrollFlags); | 
|---|
| 1288 |  | 
|---|
| 1289 | return (rc != RGN_ERROR); | 
|---|
| 1290 | } | 
|---|
| 1291 | #else | 
|---|
| 1292 | BOOL WIN32API ScrollWindow(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip) | 
|---|
| 1293 | { | 
|---|
| 1294 | Win32BaseWindow *window; | 
|---|
| 1295 | APIRET  rc; | 
|---|
| 1296 | RECTL   clientRect; | 
|---|
| 1297 | RECTL   scrollRect; | 
|---|
| 1298 | RECTL   clipRect; | 
|---|
| 1299 | PRECTL  pScrollRect = NULL; | 
|---|
| 1300 | PRECTL  pClipRect   = NULL; | 
|---|
| 1301 | ULONG   scrollFlags = SW_INVALIDATERGN; | 
|---|
| 1302 |  | 
|---|
| 1303 | window = Win32BaseWindow::GetWindowFromHandle(hwnd); | 
|---|
| 1304 | if(!window) { | 
|---|
| 1305 | dprintf(("ScrollWindow, window %x not found", hwnd)); | 
|---|
| 1306 | return 0; | 
|---|
| 1307 | } | 
|---|
| 1308 | dprintf(("ScrollWindow %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip)); | 
|---|
| 1309 | mapWin32ToOS2Rect(window,window->getClientRectPtr(),(PRECTLOS2)&clientRect); | 
|---|
| 1310 | #if 0 | 
|---|
| 1311 | //Rectangle could be relative to parent window, so fix this | 
|---|
| 1312 | if(clientRect.yBottom != 0) { | 
|---|
| 1313 | clientRect.yTop   -= clientRect.yBottom; | 
|---|
| 1314 | clientRect.yBottom = 0; | 
|---|
| 1315 | } | 
|---|
| 1316 | if(clientRect.xLeft != 0) { | 
|---|
| 1317 | clientRect.xRight -= clientRect.xLeft; | 
|---|
| 1318 | clientRect.xLeft   = 0; | 
|---|
| 1319 | } | 
|---|
| 1320 | #endif | 
|---|
| 1321 | if(pScroll) { | 
|---|
| 1322 | mapWin32ToOS2Rect(window,(RECT *)pScroll, (PRECTLOS2)&scrollRect); | 
|---|
| 1323 | pScrollRect = &scrollRect; | 
|---|
| 1324 |  | 
|---|
| 1325 | //Scroll rectangle relative to client area | 
|---|
| 1326 | pScrollRect->xLeft   += clientRect.xLeft; | 
|---|
| 1327 | pScrollRect->xRight  += clientRect.xLeft; | 
|---|
| 1328 | pScrollRect->yTop    += clientRect.yBottom; | 
|---|
| 1329 | pScrollRect->yBottom += clientRect.yBottom; | 
|---|
| 1330 | WinIntersectRect ((HAB) 0, pScrollRect, pScrollRect, &clientRect); | 
|---|
| 1331 | } | 
|---|
| 1332 | else scrollFlags |= SW_SCROLLCHILDREN; | 
|---|
| 1333 |  | 
|---|
| 1334 | if(pClip) { | 
|---|
| 1335 | mapWin32ToOS2Rect(window,(RECT *)pClip, (PRECTLOS2)&clipRect); | 
|---|
| 1336 | pClipRect = &clipRect; | 
|---|
| 1337 |  | 
|---|
| 1338 | //Clip rectangle relative to client area | 
|---|
| 1339 | pClipRect->xLeft     += clientRect.xLeft; | 
|---|
| 1340 | pClipRect->xRight    += clientRect.xLeft; | 
|---|
| 1341 | pClipRect->yTop      += clientRect.yBottom; | 
|---|
| 1342 | pClipRect->yBottom   += clientRect.yBottom; | 
|---|
| 1343 | WinIntersectRect ((HAB) 0, pClipRect, pClipRect, &clientRect); | 
|---|
| 1344 | } | 
|---|
| 1345 |  | 
|---|
| 1346 | dy = revertDy (window, dy); | 
|---|
| 1347 |  | 
|---|
| 1348 | rc = WinScrollWindow(window->getOS2WindowHandle(), dx, dy, | 
|---|
| 1349 | pScrollRect, pClipRect, NULLHANDLE, | 
|---|
| 1350 | NULL, scrollFlags); | 
|---|
| 1351 |  | 
|---|
| 1352 | return (rc != RGN_ERROR); | 
|---|
| 1353 | } | 
|---|
| 1354 | #endif | 
|---|
| 1355 | //****************************************************************************** | 
|---|
| 1356 | //****************************************************************************** | 
|---|
| 1357 | INT WIN32API ScrollWindowEx(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip, | 
|---|
| 1358 | HRGN hrgnUpdate, PRECT pRectUpdate, UINT scrollFlag) | 
|---|
| 1359 | { | 
|---|
| 1360 | Win32BaseWindow *window; | 
|---|
| 1361 | APIRET  rc; | 
|---|
| 1362 | RECTL   scrollRect; | 
|---|
| 1363 | RECTL   clipRect; | 
|---|
| 1364 | ULONG   scrollFlags = 0; | 
|---|
| 1365 | int     regionType = ERROR_W; | 
|---|
| 1366 |  | 
|---|
| 1367 | window = Win32BaseWindow::GetWindowFromHandle(hwnd); | 
|---|
| 1368 | if(!window) { | 
|---|
| 1369 | dprintf(("ScrollWindowEx, window %x not found", hwnd)); | 
|---|
| 1370 | return 0; | 
|---|
| 1371 | } | 
|---|
| 1372 |  | 
|---|
| 1373 | dprintf(("ScrollWindowEx %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip)); | 
|---|
| 1374 |  | 
|---|
| 1375 | dy = revertDy (window, dy); | 
|---|
| 1376 |  | 
|---|
| 1377 | if (scrollFlag & SW_INVALIDATE_W)      scrollFlags |= SW_INVALIDATERGN; | 
|---|
| 1378 | if (scrollFlag & SW_SCROLLCHILDREN_W)  scrollFlags |= SW_SCROLLCHILDREN; | 
|---|
| 1379 |  | 
|---|
| 1380 | if(pScroll) mapWin32ToOS2Rect(window,(RECT *)pScroll, (PRECTLOS2)&scrollRect); | 
|---|
| 1381 | if(pClip)   mapWin32ToOS2Rect(window,(RECT *)pClip, (PRECTLOS2)&clipRect); | 
|---|
| 1382 |  | 
|---|
| 1383 | RECTL rectlUpdate; | 
|---|
| 1384 | HRGN  hrgn; | 
|---|
| 1385 |  | 
|---|
| 1386 | if (scrollFlag & SW_SMOOTHSCROLL_W) | 
|---|
| 1387 | { | 
|---|
| 1388 | INT time = (scrollFlag >> 16) & 0xFFFF; | 
|---|
| 1389 |  | 
|---|
| 1390 | //CB: todo, scroll in several steps | 
|---|
| 1391 | //    is time in ms? time <-> iteration count? | 
|---|
| 1392 | } | 
|---|
| 1393 |  | 
|---|
| 1394 | LONG lComplexity = WinScrollWindow (window->getOS2WindowHandle(), dx, dy, | 
|---|
| 1395 | (pScroll) ? &scrollRect : NULL, | 
|---|
| 1396 | (pClip) ? &clipRect : NULL, | 
|---|
| 1397 | hrgn, &rectlUpdate, scrollFlags); | 
|---|
| 1398 | if (lComplexity == RGN_ERROR) | 
|---|
| 1399 | { | 
|---|
| 1400 | return ERROR_W; | 
|---|
| 1401 | } | 
|---|
| 1402 |  | 
|---|
| 1403 | RECT winRectUpdate; | 
|---|
| 1404 | LONG height = window->getClientHeight(); | 
|---|
| 1405 |  | 
|---|
| 1406 | winRectUpdate.left   = rectlUpdate.xLeft; | 
|---|
| 1407 | winRectUpdate.right  = rectlUpdate.xRight; | 
|---|
| 1408 | winRectUpdate.top    = height - rectlUpdate.yTop; | 
|---|
| 1409 | winRectUpdate.bottom = height - rectlUpdate.yBottom; | 
|---|
| 1410 |  | 
|---|
| 1411 | if (pRectUpdate) | 
|---|
| 1412 | *pRectUpdate = winRectUpdate; | 
|---|
| 1413 |  | 
|---|
| 1414 | if (hrgnUpdate) | 
|---|
| 1415 | rc = setPMRgnIntoWinRgn (hrgn, hrgnUpdate, height); | 
|---|
| 1416 |  | 
|---|
| 1417 | if ((scrollFlag & SW_INVALIDATE_W) && | 
|---|
| 1418 | ((lComplexity == RGN_RECT) || (lComplexity == RGN_COMPLEX))) | 
|---|
| 1419 | { | 
|---|
| 1420 | rc = InvalidateRect (hwnd, &winRectUpdate, (scrollFlag & SW_ERASE_W) ? 1 : 0); | 
|---|
| 1421 | if (rc == FALSE) | 
|---|
| 1422 | { | 
|---|
| 1423 | return (0); | 
|---|
| 1424 | } | 
|---|
| 1425 | } | 
|---|
| 1426 |  | 
|---|
| 1427 | switch (lComplexity) | 
|---|
| 1428 | { | 
|---|
| 1429 | case RGN_NULL: | 
|---|
| 1430 | regionType = NULLREGION_W; | 
|---|
| 1431 | break; | 
|---|
| 1432 | case RGN_RECT: | 
|---|
| 1433 | regionType = SIMPLEREGION_W; | 
|---|
| 1434 | break; | 
|---|
| 1435 | case RGN_COMPLEX: | 
|---|
| 1436 | regionType = COMPLEXREGION_W; | 
|---|
| 1437 | break; | 
|---|
| 1438 | default: | 
|---|
| 1439 | regionType = ERROR_W; | 
|---|
| 1440 | break; | 
|---|
| 1441 | } | 
|---|
| 1442 |  | 
|---|
| 1443 | return (regionType); | 
|---|
| 1444 | } | 
|---|
| 1445 | //****************************************************************************** | 
|---|
| 1446 | //****************************************************************************** | 
|---|
| 1447 | HWND WIN32API WindowFromDC(HDC hdc) | 
|---|
| 1448 | { | 
|---|
| 1449 | pDCData pHps = (pDCData)GpiQueryDCData( (HPS)hdc ); | 
|---|
| 1450 |  | 
|---|
| 1451 | dprintf2(("USER32:  WindowFromDC %x", hdc)); | 
|---|
| 1452 | if ( pHps ) | 
|---|
| 1453 | return Win32BaseWindow::OS2ToWin32Handle(pHps->hwnd); | 
|---|
| 1454 | else | 
|---|
| 1455 | return 0; | 
|---|
| 1456 | } | 
|---|
| 1457 | //****************************************************************************** | 
|---|
| 1458 | //****************************************************************************** | 
|---|
| 1459 | INT WIN32API ExcludeUpdateRgn( HDC hDC, HWND  hWnd) | 
|---|
| 1460 | { | 
|---|
| 1461 | dprintf(("USER32:  ExcludeUpdateRgn\n")); | 
|---|
| 1462 | hWnd = Win32BaseWindow::Win32ToOS2Handle(hWnd); | 
|---|
| 1463 |  | 
|---|
| 1464 | return O32_ExcludeUpdateRgn(hDC,hWnd); | 
|---|
| 1465 | } | 
|---|
| 1466 | //****************************************************************************** | 
|---|
| 1467 | //****************************************************************************** | 
|---|
| 1468 | BOOL WIN32API ValidateRect( HWND hwnd, const RECT * lprc) | 
|---|
| 1469 | { | 
|---|
| 1470 | if(lprc) { | 
|---|
| 1471 | dprintf(("USER32: ValidateRect %x (%d,%d)(%d,%d)", hwnd, lprc->left, lprc->top, lprc->right, lprc->bottom)); | 
|---|
| 1472 | } | 
|---|
| 1473 | else dprintf(("USER32: ValidateRect %x", hwnd)); | 
|---|
| 1474 |  | 
|---|
| 1475 | return RedrawWindow( hwnd, lprc, 0, RDW_VALIDATE_W | RDW_NOCHILDREN_W | (hwnd==0 ? RDW_UPDATENOW_W : 0)); | 
|---|
| 1476 | } | 
|---|
| 1477 | //****************************************************************************** | 
|---|
| 1478 | //****************************************************************************** | 
|---|
| 1479 | BOOL WIN32API ValidateRgn( HWND hwnd, HRGN  hrgn) | 
|---|
| 1480 | { | 
|---|
| 1481 | dprintf(("USER32: ValidateRgn %x %x", hwnd, hrgn)); | 
|---|
| 1482 | return RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE_W | RDW_NOCHILDREN_W | (hwnd==0 ? RDW_UPDATENOW_W : 0)); | 
|---|
| 1483 | } | 
|---|
| 1484 | /***************************************************************************** | 
|---|
| 1485 | * Name      : int WIN32API GetWindowRgn | 
|---|
| 1486 | * Purpose   : The GetWindowRgn function obtains a copy of the window region of a window. | 
|---|
| 1487 | * Parameters: HWND hWnd handle to window whose window region is to be obtained | 
|---|
| 1488 | *             HRGN hRgn handle to region that receives a copy of the window region | 
|---|
| 1489 | * Variables : | 
|---|
| 1490 | * Result    : NULLREGION, SIMPLEREGION, COMPLEXREGION, ERROR | 
|---|
| 1491 | * Remark    : | 
|---|
| 1492 | * Status    : UNTESTED STUB | 
|---|
| 1493 | * | 
|---|
| 1494 | * Author    : Patrick Haller [Thu, 1998/02/26 11:55] | 
|---|
| 1495 | *****************************************************************************/ | 
|---|
| 1496 |  | 
|---|
| 1497 | int WIN32API GetWindowRgn(HWND hwnd, HRGN hRgn) | 
|---|
| 1498 | { | 
|---|
| 1499 | Win32BaseWindow *window; | 
|---|
| 1500 | HRGN hWindowRegion; | 
|---|
| 1501 |  | 
|---|
| 1502 | window = Win32BaseWindow::GetWindowFromHandle(hwnd); | 
|---|
| 1503 | if(!window) { | 
|---|
| 1504 | dprintf(("SetWindowContextHelpId, window %x not found", hwnd)); | 
|---|
| 1505 | O32_SetLastError(ERROR_INVALID_WINDOW_HANDLE); | 
|---|
| 1506 | return 0; | 
|---|
| 1507 | } | 
|---|
| 1508 | dprintf(("USER32:GetWindowRgn (%x,%x)", hwnd, hRgn)); | 
|---|
| 1509 | hWindowRegion = window->GetWindowRegion(); | 
|---|
| 1510 |  | 
|---|
| 1511 | return O32_CombineRgn(hRgn, hWindowRegion, 0, RGN_COPY_W); | 
|---|
| 1512 | } | 
|---|
| 1513 | /***************************************************************************** | 
|---|
| 1514 | * Name      : int WIN32API SetWindowRgn | 
|---|
| 1515 | * Purpose   : The SetWindowRgn function sets the window region of a window. The | 
|---|
| 1516 | *             window region determines the area within the window where the | 
|---|
| 1517 | *             operating system permits drawing. The operating system does not | 
|---|
| 1518 | *             display any portion of a window that lies outside of the window region | 
|---|
| 1519 | *             When this function is called, the system sends the WM_WINDOWPOSCHANGING and | 
|---|
| 1520 | *             WM_WINDOWPOSCHANGED messages to the window. | 
|---|
| 1521 | * | 
|---|
| 1522 | * Parameters: HWND  hWnd    handle to window whose window region is to be set | 
|---|
| 1523 | *             HRGN  hRgn    handle to region | 
|---|
| 1524 | *             BOOL  bRedraw window redraw flag | 
|---|
| 1525 | * Variables : | 
|---|
| 1526 | * Result    : If the function succeeds, the return value is non-zero. | 
|---|
| 1527 | *             If the function fails, the return value is zero. | 
|---|
| 1528 | * Remark    : | 
|---|
| 1529 | * Status    : UNTESTED STUB | 
|---|
| 1530 | * | 
|---|
| 1531 | * Author    : Patrick Haller [Thu, 1998/02/26 11:55] | 
|---|
| 1532 | *****************************************************************************/ | 
|---|
| 1533 |  | 
|---|
| 1534 | int WIN32API SetWindowRgn(HWND hwnd, | 
|---|
| 1535 | HRGN hRgn, | 
|---|
| 1536 | BOOL bRedraw) | 
|---|
| 1537 | { | 
|---|
| 1538 | Win32BaseWindow *window; | 
|---|
| 1539 | HRGN hWindowRegion; | 
|---|
| 1540 |  | 
|---|
| 1541 | window = Win32BaseWindow::GetWindowFromHandle(hwnd); | 
|---|
| 1542 | if(!window) { | 
|---|
| 1543 | dprintf(("SetWindowContextHelpId, window %x not found", hwnd)); | 
|---|
| 1544 | O32_SetLastError(ERROR_INVALID_WINDOW_HANDLE); | 
|---|
| 1545 | return 0; | 
|---|
| 1546 | } | 
|---|
| 1547 | dprintf(("USER32:SetWindowRgn (%x,%x,%d)", hwnd, hRgn, bRedraw)); | 
|---|
| 1548 | if(window->GetWindowRegion()) { | 
|---|
| 1549 | O32_DeleteObject(window->GetWindowRegion()); | 
|---|
| 1550 | } | 
|---|
| 1551 | window->SetWindowRegion(hRgn); | 
|---|
| 1552 | if(bRedraw) { | 
|---|
| 1553 | RedrawWindow(hwnd, 0, 0, RDW_UPDATENOW_W); | 
|---|
| 1554 | } | 
|---|
| 1555 | //TODO: | 
|---|
| 1556 | //  When this function is called, the system sends the WM_WINDOWPOSCHANGING and | 
|---|
| 1557 | //  WM_WINDOWPOSCHANGED messages to the window. | 
|---|
| 1558 | return 1; | 
|---|
| 1559 | } | 
|---|
| 1560 | //****************************************************************************** | 
|---|
| 1561 | //****************************************************************************** | 
|---|