| 1 | /* $Id: dc.cpp,v 1.82 2001-01-20 16:57:00 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 <string.h> | 
|---|
| 25 | #include <win32type.h> | 
|---|
| 26 | #include <win32api.h> | 
|---|
| 27 | #include <winuser32.h> | 
|---|
| 28 | #include <winconst.h> | 
|---|
| 29 | #include <misc.h> | 
|---|
| 30 | #include <win32wbase.h> | 
|---|
| 31 | #include <math.h> | 
|---|
| 32 | #include <limits.h> | 
|---|
| 33 | #include "oslibwin.h" | 
|---|
| 34 | #include "oslibmsg.h" | 
|---|
| 35 | #include <dcdata.h> | 
|---|
| 36 | #include <codepage.h> | 
|---|
| 37 |  | 
|---|
| 38 | #define INCLUDED_BY_DC | 
|---|
| 39 | #include "dc.h" | 
|---|
| 40 |  | 
|---|
| 41 | #define DBG_LOCALLOG    DBG_dc | 
|---|
| 42 | #include "dbglocal.h" | 
|---|
| 43 |  | 
|---|
| 44 | #ifndef DEVESC_SETPS | 
|---|
| 45 | #define DEVESC_SETPS  49149L | 
|---|
| 46 | #endif | 
|---|
| 47 |  | 
|---|
| 48 | #define FLOAT_TO_FIXED(x) ((FIXED) ((x) * 65536.0)) | 
|---|
| 49 | #define MICRO_HPS_TO_HDC(x) ((x) & 0xFFFFFFFE) | 
|---|
| 50 |  | 
|---|
| 51 | #define PMRECT_FROM_WINRECT( pmRect, winRect )  \ | 
|---|
| 52 | {                                               \ | 
|---|
| 53 | (pmRect).xLeft   = (winRect).left;           \ | 
|---|
| 54 | (pmRect).yBottom = (winRect).bottom;         \ | 
|---|
| 55 | (pmRect).xRight  = (winRect).right;          \ | 
|---|
| 56 | (pmRect).yTop    = (winRect).top;            \ | 
|---|
| 57 | } | 
|---|
| 58 |  | 
|---|
| 59 | #define WINRECT_FROM_PMRECT( winRect, pmRect )  \ | 
|---|
| 60 | {                                               \ | 
|---|
| 61 | (winRect).left   = (pmRect).xLeft;           \ | 
|---|
| 62 | (winRect).top    = (pmRect).yTop;            \ | 
|---|
| 63 | (winRect).right  = (pmRect).xRight;          \ | 
|---|
| 64 | (winRect).bottom = (pmRect).yBottom;         \ | 
|---|
| 65 | } | 
|---|
| 66 |  | 
|---|
| 67 | #define MEM_HPS_MAX 768 | 
|---|
| 68 |  | 
|---|
| 69 | const XFORM_W XFORMIdentity = { 1.0, 0.0, 0.0, 1.0, 0, 0 }; | 
|---|
| 70 | const MATRIXLF matrixlfIdentity = { 0x10000, 0, 0, 0, 0x10000, 0, 0, 0, 0}; | 
|---|
| 71 |  | 
|---|
| 72 | BOOL setPageXForm(Win32BaseWindow *wnd, pDCData pHps); | 
|---|
| 73 | BOOL changePageXForm(Win32BaseWindow *wnd, pDCData pHps, PPOINTL pValue, int x, int y, PPOINTL pPrev); | 
|---|
| 74 | LONG clientHeight(Win32BaseWindow *wnd, HWND hwnd, pDCData pHps); | 
|---|
| 75 |  | 
|---|
| 76 | #ifdef DEBUG | 
|---|
| 77 | #define dprintfRegion(a,b,c) if(DbgEnabledLvl2[DBG_LOCALLOG] == 1) dprintfRegion1(a,b,c) | 
|---|
| 78 |  | 
|---|
| 79 | void dprintfRegion1(HPS hps, HWND hWnd, HRGN hrgnClip) | 
|---|
| 80 | { | 
|---|
| 81 | RGNRECT rgnRect = {0, 16, 0, RECTDIR_LFRT_TOPBOT}; | 
|---|
| 82 | RECTL   rectRegion[16]; | 
|---|
| 83 | APIRET  rc; | 
|---|
| 84 |  | 
|---|
| 85 | dprintf(("dprintfRegion %x %x", hWnd, hps)); | 
|---|
| 86 | rc = GpiQueryRegionRects(hps, hrgnClip, NULL, &rgnRect, &rectRegion[0]); | 
|---|
| 87 | for(int i=0;i<rgnRect.crcReturned;i++) { | 
|---|
| 88 | dprintf(("(%d,%d)(%d,%d)", rectRegion[i].xLeft, rectRegion[i].yBottom, rectRegion[i].xRight, rectRegion[i].yTop)); | 
|---|
| 89 | } | 
|---|
| 90 | } | 
|---|
| 91 | #else | 
|---|
| 92 | #define dprintfRegion(a,b,c) | 
|---|
| 93 | #endif | 
|---|
| 94 |  | 
|---|
| 95 | //****************************************************************************** | 
|---|
| 96 | //****************************************************************************** | 
|---|
| 97 | void WIN32API TestWideLine (pDCData pHps) | 
|---|
| 98 | { | 
|---|
| 99 | const LOGPEN_W *pLogPen; | 
|---|
| 100 |  | 
|---|
| 101 | pHps->isWideLine = FALSE; | 
|---|
| 102 | pLogPen = pHps->penIsExtPen ? | 
|---|
| 103 | &(pHps->lastPenObject->ExtPen.logpen) : | 
|---|
| 104 | &(pHps->lastPenObject->Pen.logpen); | 
|---|
| 105 |  | 
|---|
| 106 | if (((pLogPen->lopnStyle & PS_STYLE_MASK_W) != PS_NULL_W) && | 
|---|
| 107 | (pLogPen->lopnWidth.x > 0)) | 
|---|
| 108 | { | 
|---|
| 109 | POINTL aptl[2] = { 0, 0, pLogPen->lopnWidth.x, pLogPen->lopnWidth.x }; | 
|---|
| 110 |  | 
|---|
| 111 | GpiConvert(pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, aptl); | 
|---|
| 112 |  | 
|---|
| 113 | ULONG dx = abs(aptl[0].x - aptl[1].x); | 
|---|
| 114 | ULONG dy = abs(aptl[0].y - aptl[1].y); | 
|---|
| 115 |  | 
|---|
| 116 | pHps->isWideLine = (dx > 1) || (dy > 1); | 
|---|
| 117 | } | 
|---|
| 118 | } | 
|---|
| 119 | //****************************************************************************** | 
|---|
| 120 | //****************************************************************************** | 
|---|
| 121 | void WIN32API Calculate1PixelDelta(pDCData pHps) | 
|---|
| 122 | { | 
|---|
| 123 | POINTL aptl[2] = {0, 0, 1, 1}; | 
|---|
| 124 |  | 
|---|
| 125 | GpiConvert(pHps->hps, CVTC_DEVICE, CVTC_WORLD, 2, aptl); | 
|---|
| 126 | pHps->worldYDeltaFor1Pixel = (int)(aptl[1].y - aptl[0].y); | 
|---|
| 127 | pHps->worldXDeltaFor1Pixel = (int)(aptl[1].x - aptl[0].x);                   // 171182 | 
|---|
| 128 | } | 
|---|
| 129 | //****************************************************************************** | 
|---|
| 130 | //****************************************************************************** | 
|---|
| 131 | int setMapMode(Win32BaseWindow *wnd, pDCData pHps, int mode) | 
|---|
| 132 | { | 
|---|
| 133 | int    prevMode = 0; | 
|---|
| 134 | ULONG  flOptions; | 
|---|
| 135 |  | 
|---|
| 136 | switch (mode) | 
|---|
| 137 | { | 
|---|
| 138 | case MM_HIENGLISH_W  : flOptions = PU_HIENGLISH; break; | 
|---|
| 139 | case MM_LOENGLISH_W  : flOptions = PU_LOENGLISH; break; | 
|---|
| 140 | case MM_HIMETRIC_W   : flOptions = PU_HIMETRIC ; break; | 
|---|
| 141 | case MM_LOMETRIC_W   : flOptions = PU_LOMETRIC ; break; | 
|---|
| 142 | case MM_TEXT_W       : flOptions = PU_PELS     ; break; | 
|---|
| 143 | case MM_TWIPS_W      : flOptions = PU_TWIPS    ; break; | 
|---|
| 144 | case MM_ANISOTROPIC_W: flOptions = PU_PELS     ; break; | 
|---|
| 145 | case MM_ISOTROPIC_W  : flOptions = PU_LOMETRIC ; break; | 
|---|
| 146 | default: | 
|---|
| 147 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 148 | return FALSE; | 
|---|
| 149 | } | 
|---|
| 150 |  | 
|---|
| 151 | prevMode = pHps->MapMode;  /* store previous mode */ | 
|---|
| 152 | pHps->MapMode = mode; | 
|---|
| 153 |  | 
|---|
| 154 | if (mode == MM_TEXT_W) | 
|---|
| 155 | { | 
|---|
| 156 | pHps->viewportXExt = | 
|---|
| 157 | pHps->viewportYExt = 1.0; | 
|---|
| 158 | pHps->windowExt.cx = | 
|---|
| 159 | pHps->windowExt.cy = 1; | 
|---|
| 160 | } | 
|---|
| 161 | else if (mode != MM_ANISOTROPIC_W) | 
|---|
| 162 | { | 
|---|
| 163 | RECTL rectl; | 
|---|
| 164 | SIZEL sizel; | 
|---|
| 165 | ULONG data[3]; | 
|---|
| 166 |  | 
|---|
| 167 | data[0] = flOptions; | 
|---|
| 168 | data[1] = data[2] = 0; | 
|---|
| 169 |  | 
|---|
| 170 | if (DevEscape(pHps->hdc ? pHps->hdc : pHps->hps, DEVESC_SETPS, 12, (PBYTE)data, 0, 0) == DEVESC_ERROR) | 
|---|
| 171 | { | 
|---|
| 172 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 173 | return 0; | 
|---|
| 174 | } | 
|---|
| 175 |  | 
|---|
| 176 | GpiQueryPageViewport(pHps->hps, &rectl); | 
|---|
| 177 | pHps->viewportXExt = (double)rectl.xRight; | 
|---|
| 178 | pHps->viewportYExt = -(double)rectl.yTop; | 
|---|
| 179 |  | 
|---|
| 180 | GreGetPageUnits(pHps->hdc? pHps->hdc : pHps->hps, &sizel); | 
|---|
| 181 | pHps->windowExt.cx = sizel.cx; | 
|---|
| 182 | pHps->windowExt.cy = sizel.cy; | 
|---|
| 183 |  | 
|---|
| 184 | data[0] = PU_PELS; | 
|---|
| 185 | DevEscape(pHps->hdc ? pHps->hdc : pHps->hps, DEVESC_SETPS, 12, (PBYTE)data, 0, 0); | 
|---|
| 186 | } | 
|---|
| 187 |  | 
|---|
| 188 | if (((prevMode != MM_ISOTROPIC_W) && (prevMode != MM_ANISOTROPIC_W)) && | 
|---|
| 189 | ((mode == MM_ISOTROPIC_W) || (mode == MM_ANISOTROPIC_W))) | 
|---|
| 190 | { | 
|---|
| 191 | if (pHps->lWndXExtSave && pHps->lWndYExtSave) | 
|---|
| 192 | { | 
|---|
| 193 | changePageXForm (wnd, pHps, (PPOINTL)&pHps->windowExt, | 
|---|
| 194 | pHps->lWndXExtSave, pHps->lWndYExtSave, NULL ); | 
|---|
| 195 | pHps->lWndXExtSave = pHps->lWndYExtSave = 0; | 
|---|
| 196 | } | 
|---|
| 197 | if (pHps->lVwpXExtSave && pHps->lVwpYExtSave) | 
|---|
| 198 | { | 
|---|
| 199 | changePageXForm (wnd, pHps, NULL, | 
|---|
| 200 | pHps->lVwpXExtSave, pHps->lVwpYExtSave, NULL ); | 
|---|
| 201 | pHps->lVwpXExtSave = pHps->lVwpYExtSave = 0; | 
|---|
| 202 | } | 
|---|
| 203 | } | 
|---|
| 204 |  | 
|---|
| 205 | setPageXForm(wnd, pHps); | 
|---|
| 206 |  | 
|---|
| 207 | return prevMode; | 
|---|
| 208 | } | 
|---|
| 209 | //****************************************************************************** | 
|---|
| 210 | //****************************************************************************** | 
|---|
| 211 | BOOL setPageXForm(Win32BaseWindow *wnd, pDCData pHps) | 
|---|
| 212 | { | 
|---|
| 213 | MATRIXLF mlf; | 
|---|
| 214 | BOOL rc = TRUE; | 
|---|
| 215 |  | 
|---|
| 216 | pHps->height = clientHeight(wnd, 0, pHps) - 1; | 
|---|
| 217 |  | 
|---|
| 218 | double xScale =  pHps->viewportXExt / (double)pHps->windowExt.cx; | 
|---|
| 219 | double yScale =  pHps->viewportYExt / (double)pHps->windowExt.cy; | 
|---|
| 220 |  | 
|---|
| 221 | mlf.fxM11 = FLOAT_TO_FIXED(xScale); | 
|---|
| 222 | mlf.fxM12 = 0; | 
|---|
| 223 | mlf.lM13  = 0; | 
|---|
| 224 | mlf.fxM21 = 0; | 
|---|
| 225 | mlf.fxM22 = FLOAT_TO_FIXED(yScale); | 
|---|
| 226 | mlf.lM23  = 0; | 
|---|
| 227 | mlf.lM31  = pHps->viewportOrg.x - (LONG)(pHps->windowOrg.x * xScale); | 
|---|
| 228 | mlf.lM32  = pHps->viewportOrg.y - (LONG)(pHps->windowOrg.y * yScale); | 
|---|
| 229 | mlf.lM33  = 1; | 
|---|
| 230 |  | 
|---|
| 231 | pHps->isLeftLeft = mlf.fxM11 >= 0; | 
|---|
| 232 | pHps->isTopTop = mlf.fxM22 >= 0; | 
|---|
| 233 |  | 
|---|
| 234 | BOOL bEnableYInversion = FALSE; | 
|---|
| 235 | if ((mlf.fxM22 > 0) || | 
|---|
| 236 | ((pHps->graphicsMode == GM_ADVANCED_W) && | 
|---|
| 237 | ((pHps->MapMode == MM_ANISOTROPIC_W) || | 
|---|
| 238 | (pHps->MapMode == MM_ISOTROPIC_W)))) | 
|---|
| 239 | { | 
|---|
| 240 | bEnableYInversion = TRUE; | 
|---|
| 241 | } | 
|---|
| 242 | else | 
|---|
| 243 | { | 
|---|
| 244 | bEnableYInversion = FALSE; | 
|---|
| 245 | mlf.lM32 = pHps->HPStoHDCInversionHeight + pHps->height - mlf.lM32; | 
|---|
| 246 | mlf.fxM22 = -mlf.fxM22; | 
|---|
| 247 | } | 
|---|
| 248 |  | 
|---|
| 249 | if (!pHps->isMetaPS) | 
|---|
| 250 | //   if ((!pHps->isMetaPS) || | 
|---|
| 251 | //      (pHps->pMetaFileObject && pHps->pMetaFileObject->isEnhanced())) | 
|---|
| 252 | rc = GpiSetDefaultViewMatrix(pHps->hps, 8, &mlf, TRANSFORM_REPLACE); | 
|---|
| 253 |  | 
|---|
| 254 | #ifdef INVERT | 
|---|
| 255 | if (bEnableYInversion) | 
|---|
| 256 | GpiEnableYInversion(pHps->hps, pHps->height + pHps->HPStoHDCInversionHeight); | 
|---|
| 257 | else | 
|---|
| 258 | GpiEnableYInversion(pHps->hps, 0); | 
|---|
| 259 | #else | 
|---|
| 260 | pHps->yInvert = 0; | 
|---|
| 261 | if(bEnableYInversion) | 
|---|
| 262 | { | 
|---|
| 263 | pHps->yInvert4Enable = pHps->height + pHps->HPStoHDCInversionHeight; | 
|---|
| 264 | if(pHps->isPrinter) | 
|---|
| 265 | { | 
|---|
| 266 | pHps->yInvert = pHps->yInvert4Enable | 
|---|
| 267 | * (pHps->windowExt.cy / (double)pHps->viewportYExt); | 
|---|
| 268 | } else { | 
|---|
| 269 | pHps->yInvert = pHps->yInvert4Enable; | 
|---|
| 270 | } | 
|---|
| 271 | } | 
|---|
| 272 | #endif | 
|---|
| 273 |  | 
|---|
| 274 | TestWideLine(pHps); | 
|---|
| 275 | Calculate1PixelDelta(pHps); | 
|---|
| 276 | return rc; | 
|---|
| 277 | } | 
|---|
| 278 | //****************************************************************************** | 
|---|
| 279 | //****************************************************************************** | 
|---|
| 280 | BOOL changePageXForm(Win32BaseWindow *wnd, pDCData pHps, PPOINTL pValue, int x, int y, PPOINTL pPrev) | 
|---|
| 281 | { | 
|---|
| 282 | BOOL result = FALSE; | 
|---|
| 283 |  | 
|---|
| 284 | if (pValue) | 
|---|
| 285 | { | 
|---|
| 286 | if (pPrev) | 
|---|
| 287 | *pPrev = *pValue; | 
|---|
| 288 |  | 
|---|
| 289 | if ((pValue->x == x) && (pValue->y == y)) { | 
|---|
| 290 | return TRUE; | 
|---|
| 291 | } | 
|---|
| 292 | pValue->x = x; | 
|---|
| 293 | pValue->y = y; | 
|---|
| 294 | } | 
|---|
| 295 | else | 
|---|
| 296 | { | 
|---|
| 297 | if (pPrev) | 
|---|
| 298 | { | 
|---|
| 299 | pPrev->x = (int)pHps->viewportXExt; | 
|---|
| 300 | pPrev->y = (int)pHps->viewportYExt; | 
|---|
| 301 | } | 
|---|
| 302 | pHps->viewportXExt = (double)x; | 
|---|
| 303 | pHps->viewportYExt = (double)y; | 
|---|
| 304 | } | 
|---|
| 305 |  | 
|---|
| 306 | if (pHps->MapMode == MM_ISOTROPIC_W) | 
|---|
| 307 | { | 
|---|
| 308 | double xExt = fabs(pHps->viewportXExt); | 
|---|
| 309 | double yExt = fabs(pHps->viewportYExt); | 
|---|
| 310 | double sf = fabs((double)pHps->windowExt.cx / pHps->windowExt.cy); | 
|---|
| 311 |  | 
|---|
| 312 | if (xExt > (yExt * sf)) | 
|---|
| 313 | { | 
|---|
| 314 | xExt = yExt * sf; | 
|---|
| 315 |  | 
|---|
| 316 | if ((double)LONG_MAX <= xExt) return (result); | 
|---|
| 317 |  | 
|---|
| 318 | if (pHps->viewportXExt < 0.0) | 
|---|
| 319 | pHps->viewportXExt = -xExt; | 
|---|
| 320 | else | 
|---|
| 321 | pHps->viewportXExt = xExt; | 
|---|
| 322 | } | 
|---|
| 323 | else | 
|---|
| 324 | { | 
|---|
| 325 | yExt = xExt / sf; | 
|---|
| 326 |  | 
|---|
| 327 | if ((double)LONG_MAX <= yExt) return (result); | 
|---|
| 328 |  | 
|---|
| 329 | if (pHps->viewportYExt < 0.0) | 
|---|
| 330 | pHps->viewportYExt = -yExt; | 
|---|
| 331 | else | 
|---|
| 332 | pHps->viewportYExt = yExt; | 
|---|
| 333 | } | 
|---|
| 334 | } | 
|---|
| 335 | result = setPageXForm(wnd, pHps); | 
|---|
| 336 |  | 
|---|
| 337 | return (result); | 
|---|
| 338 | } | 
|---|
| 339 | //****************************************************************************** | 
|---|
| 340 | //****************************************************************************** | 
|---|
| 341 | VOID removeClientArea(Win32BaseWindow *window, pDCData pHps) | 
|---|
| 342 | { | 
|---|
| 343 | POINTL point; | 
|---|
| 344 |  | 
|---|
| 345 | // This function checks to see if a client area is currently selected, if | 
|---|
| 346 | // it is the origin plus the visible region of the frame are restored. | 
|---|
| 347 |  | 
|---|
| 348 | pHps->isClient = FALSE; | 
|---|
| 349 |  | 
|---|
| 350 | #ifdef DEBUG | 
|---|
| 351 | GreGetDCOrigin(pHps->hps, &point); | 
|---|
| 352 | #endif | 
|---|
| 353 |  | 
|---|
| 354 | if(pHps->isClientArea) | 
|---|
| 355 | { | 
|---|
| 356 | dprintf2(("removeClientArea %x: (%d,%d) -> (%d,%d)", window->getWindowHandle(), point.x, point.y, pHps->ptlOrigin.x, pHps->ptlOrigin.y)); | 
|---|
| 357 | pHps->isClientArea = FALSE; | 
|---|
| 358 | GreSetupDC(pHps->hps, | 
|---|
| 359 | pHps->hrgnVis, | 
|---|
| 360 | pHps->ptlOrigin.x, | 
|---|
| 361 | pHps->ptlOrigin.y, | 
|---|
| 362 | 0, | 
|---|
| 363 | SETUPDC_ORIGIN | SETUPDC_VISRGN | SETUPDC_RECALCCLIP); | 
|---|
| 364 | } | 
|---|
| 365 | else dprintf2(("removeClientArea: %x (%d,%d) (%d,%d)", window->getWindowHandle(), point.x, point.y, pHps->ptlOrigin.x, pHps->ptlOrigin.y)); | 
|---|
| 366 |  | 
|---|
| 367 | } | 
|---|
| 368 | //****************************************************************************** | 
|---|
| 369 | //****************************************************************************** | 
|---|
| 370 | void selectClientArea(Win32BaseWindow *window, pDCData pHps) | 
|---|
| 371 | { | 
|---|
| 372 | // This function checks to see if the DC needs to be adjusted to a client | 
|---|
| 373 | // area and makes the adjustment. | 
|---|
| 374 | RECTL rcl, rcltemp; | 
|---|
| 375 | HRGN  hrgnRect, hrgnClip, hrgnOldClip = 0; | 
|---|
| 376 | HWND  hwnd; | 
|---|
| 377 | LONG  rc; | 
|---|
| 378 | PRECT pClient = window->getClientRectPtr(); | 
|---|
| 379 | PRECT pWindow = window->getWindowRect(); | 
|---|
| 380 |  | 
|---|
| 381 | if(pClient->left == 0 && pClient->top == 0 && | 
|---|
| 382 | window->getClientHeight() == window->getWindowHeight() && | 
|---|
| 383 | window->getClientWidth()  == window->getWindowWidth()) | 
|---|
| 384 | { | 
|---|
| 385 | //client rectangle = frame rectangle -> no change necessary | 
|---|
| 386 | return; | 
|---|
| 387 | } | 
|---|
| 388 | pHps->isClient = TRUE; | 
|---|
| 389 |  | 
|---|
| 390 | hwnd = window->getOS2WindowHandle(); | 
|---|
| 391 |  | 
|---|
| 392 | mapWin32ToOS2Rect(window->getWindowHeight(), window->getClientRectPtr(), (PRECTLOS2)&rcl); | 
|---|
| 393 |  | 
|---|
| 394 | //convert to screen coordinates | 
|---|
| 395 | GreGetDCOrigin(pHps->hps, (PPOINTL)&rcltemp); | 
|---|
| 396 |  | 
|---|
| 397 | if(pHps->isClientArea) | 
|---|
| 398 | { | 
|---|
| 399 | //TODO: counter | 
|---|
| 400 | dprintf2(("WARNING: selectClientArea %x; already selected! origin (%d,%d) original origin (%d,%d)", window->getWindowHandle(), rcltemp.xLeft, rcltemp.yBottom, pHps->ptlOrigin.x, pHps->ptlOrigin.y)); | 
|---|
| 401 | RECT rectWindow; | 
|---|
| 402 | RECTL rectWindowOS2; | 
|---|
| 403 | GetWindowRect(window->getWindowHandle(), &rectWindow); | 
|---|
| 404 | mapWin32ToOS2Rect(OSLibGetScreenHeight(), &rectWindow, (PRECTLOS2)&rectWindowOS2); | 
|---|
| 405 | if(rectWindowOS2.xLeft + rcl.xLeft != rcltemp.xLeft || | 
|---|
| 406 | rectWindowOS2.yBottom + rcl.yBottom != rcltemp.yBottom) | 
|---|
| 407 | { | 
|---|
| 408 | dprintf2(("WARNING: origin changed (%d,%d) instead of (%d,%d)!", rcltemp.xLeft, rcltemp.yBottom, rectWindowOS2.xLeft + rcl.xLeft, rectWindowOS2.yBottom + rcl.yBottom)); | 
|---|
| 409 | rcl.xLeft   += rectWindowOS2.xLeft; | 
|---|
| 410 | rcl.xRight  += rectWindowOS2.xLeft; | 
|---|
| 411 | rcl.yTop    += rectWindowOS2.yBottom; | 
|---|
| 412 | rcl.yBottom += rectWindowOS2.yBottom; | 
|---|
| 413 | } | 
|---|
| 414 | else    return; | 
|---|
| 415 | } | 
|---|
| 416 | else { | 
|---|
| 417 | rcl.xLeft   += rcltemp.xLeft; | 
|---|
| 418 | rcl.xRight  += rcltemp.xLeft; | 
|---|
| 419 | rcl.yTop    += rcltemp.yBottom; | 
|---|
| 420 | rcl.yBottom += rcltemp.yBottom; | 
|---|
| 421 |  | 
|---|
| 422 | pHps->ptlOrigin.x = rcltemp.xLeft; | 
|---|
| 423 | pHps->ptlOrigin.y = rcltemp.yBottom; | 
|---|
| 424 | } | 
|---|
| 425 |  | 
|---|
| 426 | dprintf2(("selectClientArea %x: (%d,%d) -> (%d,%d)", window->getWindowHandle(), rcltemp.xLeft, rcltemp.yBottom, rcl.xLeft, rcl.yBottom)); | 
|---|
| 427 |  | 
|---|
| 428 | if(pHps->hrgnVis == 0) | 
|---|
| 429 | pHps->hrgnVis = GreCreateRectRegion(pHps->hps, &rcl, 1); | 
|---|
| 430 |  | 
|---|
| 431 | hrgnRect = GreCreateRectRegion(pHps->hps, &rcl, 1); | 
|---|
| 432 |  | 
|---|
| 433 | // Query the visible region | 
|---|
| 434 | GreCopyClipRegion(pHps->hps, pHps->hrgnVis, 0, COPYCRGN_VISRGN); | 
|---|
| 435 | GpiQueryRegionBox(pHps->hps, pHps->hrgnVis, &rcltemp); | 
|---|
| 436 | // And the visible region of the frame with the client rectangle | 
|---|
| 437 | // to get the new visible region | 
|---|
| 438 | GreCombineRegion(pHps->hps, hrgnRect, pHps->hrgnVis, hrgnRect, CRGN_AND); | 
|---|
| 439 | #ifdef DEBUG | 
|---|
| 440 | dprintfRegion1(pHps->hps, window->getWindowHandle(), hrgnRect); | 
|---|
| 441 | #endif | 
|---|
| 442 |  | 
|---|
| 443 | // Set the new origin plus visible region in the DC | 
|---|
| 444 | GreSetupDC(pHps->hps, | 
|---|
| 445 | hrgnRect, | 
|---|
| 446 | rcl.xLeft, | 
|---|
| 447 | rcl.yBottom, | 
|---|
| 448 | NULL, | 
|---|
| 449 | SETUPDC_ORIGIN | SETUPDC_VISRGN | SETUPDC_RECALCCLIP); | 
|---|
| 450 |  | 
|---|
| 451 | pHps->isClientArea = TRUE; | 
|---|
| 452 |  | 
|---|
| 453 | // Destroy the region now we have finished with it. | 
|---|
| 454 | GreDestroyRegion(pHps->hps, hrgnRect); | 
|---|
| 455 | } | 
|---|
| 456 | //****************************************************************************** | 
|---|
| 457 | //****************************************************************************** | 
|---|
| 458 | LONG clientHeight(Win32BaseWindow *wnd, HWND hwnd, pDCData pHps) | 
|---|
| 459 | { | 
|---|
| 460 | if ((hwnd == 0) && (pHps != 0)) | 
|---|
| 461 | hwnd = pHps->hwnd; | 
|---|
| 462 |  | 
|---|
| 463 | if ((hwnd != 0) || (pHps == 0)) | 
|---|
| 464 | { | 
|---|
| 465 | if(wnd) { | 
|---|
| 466 | if(pHps && !pHps->isClientArea) { | 
|---|
| 467 | return (wnd->getWindowHeight()); | 
|---|
| 468 | } | 
|---|
| 469 | else    return (wnd->getClientHeight()); | 
|---|
| 470 | } | 
|---|
| 471 | else    return OSLibQueryScreenHeight(); | 
|---|
| 472 | } | 
|---|
| 473 | else if (pHps->bitmapHandle) | 
|---|
| 474 | { | 
|---|
| 475 | return pHps->bitmapHeight; | 
|---|
| 476 | } | 
|---|
| 477 | else if (pHps->isMetaPS) | 
|---|
| 478 | { | 
|---|
| 479 | return 0; | 
|---|
| 480 | } | 
|---|
| 481 | else if (pHps->isPrinter) | 
|---|
| 482 | { | 
|---|
| 483 | return pHps->printPageHeight; | 
|---|
| 484 | } | 
|---|
| 485 | else | 
|---|
| 486 | { | 
|---|
| 487 | return MEM_HPS_MAX; | 
|---|
| 488 | } | 
|---|
| 489 | } | 
|---|
| 490 | //****************************************************************************** | 
|---|
| 491 | //****************************************************************************** | 
|---|
| 492 | BOOL   WIN32API changePageXForm(pDCData pHps, PPOINTL pValue, int x, int y, PPOINTL pPrev) | 
|---|
| 493 | { | 
|---|
| 494 | Win32BaseWindow *wnd; | 
|---|
| 495 |  | 
|---|
| 496 | wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd); | 
|---|
| 497 | return changePageXForm(wnd, pHps, pValue, x, y, pPrev); | 
|---|
| 498 | } | 
|---|
| 499 | //****************************************************************************** | 
|---|
| 500 | //****************************************************************************** | 
|---|
| 501 | BOOL   WIN32API setPageXForm(pDCData pHps) | 
|---|
| 502 | { | 
|---|
| 503 | Win32BaseWindow *wnd; | 
|---|
| 504 |  | 
|---|
| 505 | wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd); | 
|---|
| 506 | return setPageXForm(wnd, pHps); | 
|---|
| 507 | } | 
|---|
| 508 | //****************************************************************************** | 
|---|
| 509 | //****************************************************************************** | 
|---|
| 510 | VOID   WIN32API removeClientArea(pDCData pHps) | 
|---|
| 511 | { | 
|---|
| 512 | Win32BaseWindow *wnd; | 
|---|
| 513 |  | 
|---|
| 514 | wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd); | 
|---|
| 515 | if(wnd) { | 
|---|
| 516 | removeClientArea(wnd, pHps); | 
|---|
| 517 | } | 
|---|
| 518 | } | 
|---|
| 519 | //****************************************************************************** | 
|---|
| 520 | //****************************************************************************** | 
|---|
| 521 | VOID WIN32API selectClientArea(pDCData pHps) | 
|---|
| 522 | { | 
|---|
| 523 | Win32BaseWindow *wnd; | 
|---|
| 524 |  | 
|---|
| 525 | wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd); | 
|---|
| 526 | if(wnd) { | 
|---|
| 527 | selectClientArea(wnd, pHps); | 
|---|
| 528 | } | 
|---|
| 529 | } | 
|---|
| 530 | //****************************************************************************** | 
|---|
| 531 | //****************************************************************************** | 
|---|
| 532 | LONG   WIN32API clientHeight(HWND hwnd, pDCData pHps) | 
|---|
| 533 | { | 
|---|
| 534 | Win32BaseWindow *wnd; | 
|---|
| 535 |  | 
|---|
| 536 | wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd); | 
|---|
| 537 | return clientHeight(wnd, hwnd, pHps); | 
|---|
| 538 | } | 
|---|
| 539 | //****************************************************************************** | 
|---|
| 540 | //****************************************************************************** | 
|---|
| 541 | int  WIN32API setMapMode(pDCData pHps, int mode) | 
|---|
| 542 | { | 
|---|
| 543 | Win32BaseWindow *wnd; | 
|---|
| 544 |  | 
|---|
| 545 | wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd); | 
|---|
| 546 | return setMapMode(wnd, pHps, mode); | 
|---|
| 547 | } | 
|---|
| 548 | //****************************************************************************** | 
|---|
| 549 | //****************************************************************************** | 
|---|
| 550 | BOOL isYup (pDCData pHps) | 
|---|
| 551 | { | 
|---|
| 552 | if (((pHps->windowExt.cy < 0) && (pHps->viewportYExt > 0.0)) || | 
|---|
| 553 | ((pHps->windowExt.cy > 0) && (pHps->viewportYExt < 0.0))) | 
|---|
| 554 | { | 
|---|
| 555 | if ((pHps->graphicsMode == GM_COMPATIBLE_W) || | 
|---|
| 556 | ((pHps->graphicsMode == GM_ADVANCED_W) && (pHps->xform.eM22 >= 0.0))) | 
|---|
| 557 | return TRUE; | 
|---|
| 558 | } | 
|---|
| 559 | else | 
|---|
| 560 | { | 
|---|
| 561 | if ((pHps->graphicsMode == GM_ADVANCED_W) && (pHps->xform.eM22 < 0.0)) | 
|---|
| 562 | return TRUE; | 
|---|
| 563 | } | 
|---|
| 564 | return FALSE; | 
|---|
| 565 | } | 
|---|
| 566 | //****************************************************************************** | 
|---|
| 567 | //****************************************************************************** | 
|---|
| 568 | INT revertDy (Win32BaseWindow *wnd, INT dy) | 
|---|
| 569 | { | 
|---|
| 570 | //SvL: Hack for memory.exe (doesn't get repainted properly otherwise) | 
|---|
| 571 | //   if (wnd->isOwnDC() && wnd->getOwnDC()) | 
|---|
| 572 | if (wnd->isOwnDC()) | 
|---|
| 573 | { | 
|---|
| 574 | pDCData pHps = (pDCData)GpiQueryDCData (wnd->getOwnDC()); | 
|---|
| 575 |  | 
|---|
| 576 | if (pHps != NULLHANDLE) | 
|---|
| 577 | if (!isYup (pHps)) | 
|---|
| 578 | dy = -dy; | 
|---|
| 579 | } | 
|---|
| 580 | else | 
|---|
| 581 | { | 
|---|
| 582 | dy = -dy; | 
|---|
| 583 | } | 
|---|
| 584 | return (dy); | 
|---|
| 585 | } | 
|---|
| 586 | //****************************************************************************** | 
|---|
| 587 | //****************************************************************************** | 
|---|
| 588 | HDC sendEraseBkgnd (Win32BaseWindow *wnd) | 
|---|
| 589 | { | 
|---|
| 590 | BOOL  erased; | 
|---|
| 591 | HWND  hwnd; | 
|---|
| 592 | HDC   hdc; | 
|---|
| 593 | HPS   hps; | 
|---|
| 594 | HRGN  hrgnUpdate, hrgnOld, hrgnClip, hrgnCombined; | 
|---|
| 595 | RECTL rectl = { 1, 1, 2, 2 }; | 
|---|
| 596 |  | 
|---|
| 597 | hwnd = wnd->getOS2WindowHandle(); | 
|---|
| 598 | hps = WinGetPS(hwnd); | 
|---|
| 599 |  | 
|---|
| 600 | hrgnUpdate = GpiCreateRegion (hps, 1, &rectl); | 
|---|
| 601 | WinQueryUpdateRegion (hwnd, hrgnUpdate); | 
|---|
| 602 | hrgnClip = GpiQueryClipRegion (hps); | 
|---|
| 603 |  | 
|---|
| 604 | if (hrgnClip == NULLHANDLE) | 
|---|
| 605 | { | 
|---|
| 606 | GpiSetClipRegion (hps, hrgnUpdate, &hrgnOld); | 
|---|
| 607 | } | 
|---|
| 608 | else | 
|---|
| 609 | { | 
|---|
| 610 | hrgnCombined = GpiCreateRegion (hps, 1, &rectl); | 
|---|
| 611 | GpiCombineRegion (hps, hrgnCombined, hrgnClip, hrgnUpdate, CRGN_AND); | 
|---|
| 612 | GpiSetClipRegion (hps, hrgnCombined, &hrgnOld); | 
|---|
| 613 | GpiDestroyRegion (hps, hrgnUpdate); | 
|---|
| 614 | GpiDestroyRegion (hps, hrgnClip); | 
|---|
| 615 | } | 
|---|
| 616 | if (hrgnOld != NULLHANDLE) | 
|---|
| 617 | GpiDestroyRegion (hps, hrgnOld); | 
|---|
| 618 |  | 
|---|
| 619 | hdc = HPSToHDC (hwnd, hps, NULL, NULL); | 
|---|
| 620 |  | 
|---|
| 621 | erased = wnd->MsgEraseBackGround (hdc); | 
|---|
| 622 |  | 
|---|
| 623 | DeleteHDC (hdc); | 
|---|
| 624 | WinReleasePS (hps); | 
|---|
| 625 |  | 
|---|
| 626 | return erased; | 
|---|
| 627 | } | 
|---|
| 628 | //****************************************************************************** | 
|---|
| 629 | //****************************************************************************** | 
|---|
| 630 | void releaseOwnDC (HDC hps) | 
|---|
| 631 | { | 
|---|
| 632 | pDCData pHps = (pDCData)GpiQueryDCData ((HPS)hps); | 
|---|
| 633 |  | 
|---|
| 634 | dprintf2(("releaseOwnDC %x", hps)); | 
|---|
| 635 |  | 
|---|
| 636 | if (pHps) { | 
|---|
| 637 | if (pHps->hrgnHDC) | 
|---|
| 638 | GpiDestroyRegion (pHps->hps, pHps->hrgnHDC); | 
|---|
| 639 |  | 
|---|
| 640 | GpiSetBitmap (pHps->hps, NULL); | 
|---|
| 641 | O32_DeleteObject (pHps->nullBitmapHandle); | 
|---|
| 642 | GpiDestroyPS(pHps->hps); | 
|---|
| 643 |  | 
|---|
| 644 | if (pHps->hdc) | 
|---|
| 645 | DevCloseDC(pHps->hdc); | 
|---|
| 646 | } | 
|---|
| 647 | } | 
|---|
| 648 | //****************************************************************************** | 
|---|
| 649 | //****************************************************************************** | 
|---|
| 650 | HDC WIN32API BeginPaint (HWND hWnd, PPAINTSTRUCT_W lpps) | 
|---|
| 651 | { | 
|---|
| 652 | HWND     hwnd = hWnd ? hWnd : HWND_DESKTOP; | 
|---|
| 653 | pDCData  pHps = NULLHANDLE; | 
|---|
| 654 | HPS      hPS_ownDC = NULLHANDLE, hpsPaint = 0; | 
|---|
| 655 | RECTL    rectl = {0, 0, 1, 1}; | 
|---|
| 656 | HRGN     hrgnOldClip; | 
|---|
| 657 | LONG     lComplexity; | 
|---|
| 658 | RECTL    rectlClient; | 
|---|
| 659 | RECTL    rectlClip; | 
|---|
| 660 |  | 
|---|
| 661 | memset(lpps, 0, sizeof(*lpps)); | 
|---|
| 662 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd); | 
|---|
| 663 | if(!lpps || !wnd) { | 
|---|
| 664 | dprintf (("USER32: BeginPaint %x invalid parameter %x", hWnd, lpps)); | 
|---|
| 665 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 666 | return (HDC)0; | 
|---|
| 667 | } | 
|---|
| 668 | HWND hwndClient = wnd->getOS2WindowHandle(); | 
|---|
| 669 |  | 
|---|
| 670 | if(hwnd != HWND_DESKTOP && wnd->isOwnDC()) | 
|---|
| 671 | { | 
|---|
| 672 | hPS_ownDC = wnd->getOwnDC(); | 
|---|
| 673 | //SvL: Hack for memory.exe (doesn't get repainted properly otherwise) | 
|---|
| 674 | if(hPS_ownDC) { | 
|---|
| 675 | pHps = (pDCData)GpiQueryDCData(hPS_ownDC); | 
|---|
| 676 | if (!pHps) | 
|---|
| 677 | { | 
|---|
| 678 | dprintf (("USER32: BeginPaint %x invalid parameter %x", hWnd, lpps)); | 
|---|
| 679 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 680 | return (HDC)NULLHANDLE; | 
|---|
| 681 | } | 
|---|
| 682 | hpsPaint = hPS_ownDC; | 
|---|
| 683 | } | 
|---|
| 684 | } | 
|---|
| 685 | if(!hpsPaint) { | 
|---|
| 686 | hpsPaint = GetDCEx(hwnd, 0, (DCX_CACHE_W|DCX_WINDOW_W|DCX_USESTYLE_W)); | 
|---|
| 687 | pHps = (pDCData)GpiQueryDCData(hpsPaint); | 
|---|
| 688 | if (!pHps) | 
|---|
| 689 | { | 
|---|
| 690 | dprintf (("USER32: BeginPaint %x invalid parameter %x", hWnd, lpps)); | 
|---|
| 691 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 692 | return (HDC)NULLHANDLE; | 
|---|
| 693 | } | 
|---|
| 694 | } | 
|---|
| 695 |  | 
|---|
| 696 | if(WinQueryUpdateRect(hwndClient, &rectl) == FALSE) { | 
|---|
| 697 | memset(&rectl, 0, sizeof(rectl)); | 
|---|
| 698 | dprintf (("USER32: WARNING: WinQueryUpdateRect failed (error or no update rectangle)!!")); | 
|---|
| 699 |  | 
|---|
| 700 | HRGN hrgnClip = GpiCreateRegion(pHps->hps, 1, &rectl); | 
|---|
| 701 | GpiSetClipRegion(pHps->hps, hrgnClip, &hrgnOldClip); | 
|---|
| 702 |  | 
|---|
| 703 | selectClientArea(wnd, pHps); | 
|---|
| 704 |  | 
|---|
| 705 | //save old clip region (restored for CS_OWNDC windows in EndPaint) | 
|---|
| 706 | wnd->SetClipRegion(hrgnOldClip); | 
|---|
| 707 | lComplexity = RGN_NULL; | 
|---|
| 708 | } | 
|---|
| 709 | else { | 
|---|
| 710 | rectlClip.yBottom = rectlClip.xLeft = 0; | 
|---|
| 711 | rectlClip.yTop = rectlClip.xRight = 1; | 
|---|
| 712 |  | 
|---|
| 713 | //Query update region | 
|---|
| 714 | HRGN hrgnClip = GpiCreateRegion(pHps->hps, 1, &rectlClip); | 
|---|
| 715 | WinQueryUpdateRegion(hwndClient, hrgnClip); | 
|---|
| 716 | WinValidateRegion(hwndClient, hrgnClip, FALSE); | 
|---|
| 717 |  | 
|---|
| 718 | mapWin32ToOS2Rect(wnd->getWindowHeight(), wnd->getClientRectPtr(), (PRECTLOS2)&rectlClient); | 
|---|
| 719 | WinIntersectRect(NULL, &rectlClip, &rectl, &rectlClient); | 
|---|
| 720 | WinOffsetRect(NULL, &rectlClip, -rectlClient.xLeft, -rectlClient.yBottom); | 
|---|
| 721 |  | 
|---|
| 722 | //clip update region with client window rectangle | 
|---|
| 723 | HRGN hrgnClient = GpiCreateRegion(pHps->hps, 1, &rectlClient); | 
|---|
| 724 | GpiCombineRegion(pHps->hps, hrgnClip, hrgnClip, hrgnClient, CRGN_AND); | 
|---|
| 725 | GpiDestroyRegion(pHps->hps, hrgnClient); | 
|---|
| 726 |  | 
|---|
| 727 | //change origin of clip region (window -> client) | 
|---|
| 728 | POINTL point = {-rectlClient.xLeft, -rectlClient.yBottom}; | 
|---|
| 729 | GpiOffsetRegion(pHps->hps, hrgnClip, &point); | 
|---|
| 730 | #ifdef DEBUG | 
|---|
| 731 | dprintfRegion1(pHps->hps, hWnd, hrgnClip); | 
|---|
| 732 | #endif | 
|---|
| 733 | //set clip region | 
|---|
| 734 | lComplexity = GpiSetClipRegion(pHps->hps, hrgnClip, &hrgnOldClip); | 
|---|
| 735 |  | 
|---|
| 736 | //change presentation space for client window | 
|---|
| 737 | //NOTE: MUST do this after GpiSetClipRegion call! | 
|---|
| 738 | //      When a window with CS_OWNDC looses focus, for some reason | 
|---|
| 739 | //      GpiSetClipRegion resets the window dc origin back to (0,0) | 
|---|
| 740 | selectClientArea(wnd, pHps); | 
|---|
| 741 |  | 
|---|
| 742 | GpiQueryClipBox(pHps->hps, &rectl); | 
|---|
| 743 | dprintf(("ClipBox (%d): (%d,%d)(%d,%d)", lComplexity, rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop)); | 
|---|
| 744 |  | 
|---|
| 745 | //save old clip region (restored for CS_OWNDC windows in EndPaint) | 
|---|
| 746 | wnd->SetClipRegion(hrgnOldClip); | 
|---|
| 747 | memcpy(&rectl, &rectlClip, sizeof(RECTL)); | 
|---|
| 748 | lComplexity = RGN_RECT; | 
|---|
| 749 | } | 
|---|
| 750 |  | 
|---|
| 751 | if(hPS_ownDC == 0) | 
|---|
| 752 | setMapMode (wnd, pHps, MM_TEXT_W); | 
|---|
| 753 | else | 
|---|
| 754 | setPageXForm(wnd, pHps); | 
|---|
| 755 |  | 
|---|
| 756 | pHps->hdcType = TYPE_3; | 
|---|
| 757 |  | 
|---|
| 758 | HideCaret(hwnd); | 
|---|
| 759 | WinShowTrackRect(wnd->getOS2WindowHandle(), FALSE); | 
|---|
| 760 |  | 
|---|
| 761 | if(wnd->needsEraseBkgnd() && lComplexity != RGN_NULL) { | 
|---|
| 762 | wnd->setEraseBkgnd(FALSE); | 
|---|
| 763 | lpps->fErase = (wnd->MsgEraseBackGround(pHps->hps) != 0); | 
|---|
| 764 | } | 
|---|
| 765 | else lpps->fErase = TRUE; | 
|---|
| 766 |  | 
|---|
| 767 | #ifdef DEBUG | 
|---|
| 768 | POINTL point; | 
|---|
| 769 | GreGetDCOrigin(pHps->hps, &point); | 
|---|
| 770 | dprintf(("dc origin (%d,%d)", point.x, point.y)); | 
|---|
| 771 | #endif | 
|---|
| 772 |  | 
|---|
| 773 | lpps->hdc    = (HDC)pHps->hps; | 
|---|
| 774 |  | 
|---|
| 775 | if(lComplexity != RGN_NULL) { | 
|---|
| 776 | long height  = wnd->getClientHeight(); | 
|---|
| 777 | lpps->rcPaint.top    = height - rectl.yTop; | 
|---|
| 778 | lpps->rcPaint.left   = rectl.xLeft; | 
|---|
| 779 | lpps->rcPaint.bottom = height - rectl.yBottom; | 
|---|
| 780 | lpps->rcPaint.right  = rectl.xRight; | 
|---|
| 781 | } | 
|---|
| 782 | else { | 
|---|
| 783 | lpps->rcPaint.bottom = lpps->rcPaint.top = 0; | 
|---|
| 784 | lpps->rcPaint.right = lpps->rcPaint.left = 0; | 
|---|
| 785 | } | 
|---|
| 786 |  | 
|---|
| 787 | SetLastError(0); | 
|---|
| 788 | dprintf(("USER32: BeginPaint %x -> hdc %x (%d,%d)(%d,%d)", hWnd, pHps->hps, lpps->rcPaint.left, lpps->rcPaint.top, lpps->rcPaint.right, lpps->rcPaint.bottom)); | 
|---|
| 789 | return (HDC)pHps->hps; | 
|---|
| 790 | } | 
|---|
| 791 | //****************************************************************************** | 
|---|
| 792 | //****************************************************************************** | 
|---|
| 793 | BOOL WIN32API EndPaint (HWND hWnd, const PAINTSTRUCT_W *pPaint) | 
|---|
| 794 | { | 
|---|
| 795 | HWND    hwnd = hWnd ? hWnd : HWND_DESKTOP; | 
|---|
| 796 | HRGN    hrgnOld; | 
|---|
| 797 | pDCData pHps; | 
|---|
| 798 |  | 
|---|
| 799 | dprintf (("USER32: EndPaint(%x)", hwnd)); | 
|---|
| 800 |  | 
|---|
| 801 | if (!pPaint || !pPaint->hdc ) | 
|---|
| 802 | return TRUE; | 
|---|
| 803 |  | 
|---|
| 804 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd); | 
|---|
| 805 |  | 
|---|
| 806 | if (!wnd) goto exit; | 
|---|
| 807 |  | 
|---|
| 808 | pHps = (pDCData)GpiQueryDCData((HPS)pPaint->hdc); | 
|---|
| 809 | if (pHps && (pHps->hdcType == TYPE_3)) | 
|---|
| 810 | { | 
|---|
| 811 | GpiSetClipRegion(pHps->hps, wnd->GetClipRegion(), &hrgnOld); | 
|---|
| 812 | wnd->SetClipRegion(0); | 
|---|
| 813 | if(hrgnOld) { | 
|---|
| 814 | GpiDestroyRegion(pHps->hps, hrgnOld); | 
|---|
| 815 | } | 
|---|
| 816 | pHps->hdcType = TYPE_1; //otherwise Open32's ReleaseDC fails | 
|---|
| 817 | ReleaseDC(hwnd, pPaint->hdc); | 
|---|
| 818 | } | 
|---|
| 819 | else { | 
|---|
| 820 | dprintf(("EndPaint: wrong hdc %x!!", pPaint->hdc)); | 
|---|
| 821 | } | 
|---|
| 822 | wnd->setEraseBkgnd(TRUE); | 
|---|
| 823 | ShowCaret(hwnd); | 
|---|
| 824 | WinShowTrackRect(wnd->getOS2WindowHandle(), TRUE); | 
|---|
| 825 |  | 
|---|
| 826 | exit: | 
|---|
| 827 | SetLastError(0); | 
|---|
| 828 | return TRUE; | 
|---|
| 829 | } | 
|---|
| 830 | //****************************************************************************** | 
|---|
| 831 | //****************************************************************************** | 
|---|
| 832 | int WIN32API ReleaseDC (HWND hwnd, HDC hdc) | 
|---|
| 833 | { | 
|---|
| 834 | BOOL isOwnDC = FALSE; | 
|---|
| 835 | int rc; | 
|---|
| 836 |  | 
|---|
| 837 | if (hwnd) | 
|---|
| 838 | { | 
|---|
| 839 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd); | 
|---|
| 840 | if(wnd == NULL) { | 
|---|
| 841 | dprintf(("ERROR: ReleaseDC %x %x failed", hwnd, hdc)); | 
|---|
| 842 | return 0; | 
|---|
| 843 | } | 
|---|
| 844 | isOwnDC = wnd->isOwnDC() && (wnd->getOwnDC() == hdc); | 
|---|
| 845 | if(!isOwnDC) | 
|---|
| 846 | { | 
|---|
| 847 | pDCData  pHps = (pDCData)GpiQueryDCData((HPS)hdc); | 
|---|
| 848 | if(pHps && pHps->psType == MICRO_CACHED) { | 
|---|
| 849 | removeClientArea(wnd, pHps); | 
|---|
| 850 | if(pHps->hrgnVis) { | 
|---|
| 851 | GreDestroyRegion(pHps->hps, pHps->hrgnVis); | 
|---|
| 852 | pHps->hrgnVis = 0; | 
|---|
| 853 | } | 
|---|
| 854 | } | 
|---|
| 855 | else { | 
|---|
| 856 | dprintf(("ERROR: ReleaseDC: pHps == NULL!!")); | 
|---|
| 857 | DebugInt3(); | 
|---|
| 858 | } | 
|---|
| 859 | } | 
|---|
| 860 | else { | 
|---|
| 861 | dprintf2(("ReleaseDC: CS_OWNDC, not released")); | 
|---|
| 862 | } | 
|---|
| 863 | } | 
|---|
| 864 |  | 
|---|
| 865 | if(isOwnDC) { | 
|---|
| 866 | rc = TRUE; | 
|---|
| 867 | } | 
|---|
| 868 | else { | 
|---|
| 869 | rc = O32_ReleaseDC (0, hdc); | 
|---|
| 870 | } | 
|---|
| 871 |  | 
|---|
| 872 | dprintf(("ReleaseDC %x %x", hwnd, hdc)); | 
|---|
| 873 | return (rc); | 
|---|
| 874 | } | 
|---|
| 875 | //****************************************************************************** | 
|---|
| 876 | // This implementation of GetDCEx supports | 
|---|
| 877 | // DCX_WINDOW | 
|---|
| 878 | // DCX_CACHE | 
|---|
| 879 | // DCX_EXCLUDERGN (complex regions allowed) | 
|---|
| 880 | // DCX_INTERSECTRGN (complex regions allowed) | 
|---|
| 881 | // DCX_USESTYLE | 
|---|
| 882 | // DCX_CLIPSIBLINGS | 
|---|
| 883 | // DCX_CLIPCHILDREN | 
|---|
| 884 | // DCX_PARENTCLIP | 
|---|
| 885 | // | 
|---|
| 886 | //TODO: WM_SETREDRAW affects drawingAllowed flag!! | 
|---|
| 887 | //****************************************************************************** | 
|---|
| 888 | HDC WIN32API GetDCEx (HWND hwnd, HRGN hrgn, ULONG flags) | 
|---|
| 889 | { | 
|---|
| 890 | Win32BaseWindow *wnd = NULL; | 
|---|
| 891 | HWND     hWindow; | 
|---|
| 892 | BOOL     success; | 
|---|
| 893 | pDCData  pHps = NULL; | 
|---|
| 894 | HPS      hps  = NULLHANDLE; | 
|---|
| 895 | BOOL     drawingAllowed = TRUE; | 
|---|
| 896 | BOOL     isWindowOwnDC; | 
|---|
| 897 | BOOL     creatingOwnDC = FALSE; | 
|---|
| 898 | PS_Type  psType; | 
|---|
| 899 |  | 
|---|
| 900 | if(hwnd == 0) { | 
|---|
| 901 | dprintf(("error: GetDCEx window %x not found", hwnd)); | 
|---|
| 902 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W); | 
|---|
| 903 | return 0; | 
|---|
| 904 | } | 
|---|
| 905 |  | 
|---|
| 906 | if (hwnd) | 
|---|
| 907 | { | 
|---|
| 908 | wnd = Win32BaseWindow::GetWindowFromHandle(hwnd); | 
|---|
| 909 | if(wnd == NULL) { | 
|---|
| 910 | dprintf (("ERROR: User32: GetDCEx bad window handle %X!!!!!", hwnd)); | 
|---|
| 911 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W); | 
|---|
| 912 | return 0; | 
|---|
| 913 | } | 
|---|
| 914 | hWindow = wnd->getOS2WindowHandle(); | 
|---|
| 915 | } | 
|---|
| 916 |  | 
|---|
| 917 | isWindowOwnDC = (((hWindow == HWND_DESKTOP) ? FALSE : (wnd->isOwnDC())) | 
|---|
| 918 | && !(flags & (DCX_CACHE_W|DCX_WINDOW_W))); | 
|---|
| 919 |  | 
|---|
| 920 | if(isWindowOwnDC) //own dc always for client area | 
|---|
| 921 | { | 
|---|
| 922 | hps = wnd->getOwnDC(); | 
|---|
| 923 | if (hps) | 
|---|
| 924 | { | 
|---|
| 925 | pDCData pHps = (pDCData)GpiQueryDCData (hps); | 
|---|
| 926 | if (!pHps) | 
|---|
| 927 | goto error; | 
|---|
| 928 |  | 
|---|
| 929 | selectClientArea(wnd, pHps); | 
|---|
| 930 |  | 
|---|
| 931 | //TODO: Is this always necessary?? | 
|---|
| 932 | setPageXForm (wnd, pHps); | 
|---|
| 933 | pHps->hdcType = TYPE_1; | 
|---|
| 934 |  | 
|---|
| 935 | //TODO: intersect/exclude clip region? | 
|---|
| 936 | dprintf (("User32: GetDCEx hwnd %x (%x %x) -> wnd %x hdc %x", hwnd, hrgn, flags, wnd, hps)); | 
|---|
| 937 | return (HDC)hps; | 
|---|
| 938 | } | 
|---|
| 939 | else | 
|---|
| 940 | creatingOwnDC = TRUE; | 
|---|
| 941 | } | 
|---|
| 942 |  | 
|---|
| 943 | if(isWindowOwnDC) | 
|---|
| 944 | { | 
|---|
| 945 | SIZEL sizel = {0,0}; | 
|---|
| 946 | hps = GpiCreatePS (WinQueryAnchorBlock (hWindow), | 
|---|
| 947 | WinOpenWindowDC (hWindow), | 
|---|
| 948 | &sizel, PU_PELS | GPIT_MICRO | GPIA_ASSOC ); | 
|---|
| 949 | psType = MICRO; | 
|---|
| 950 | // default cp is OS/2 one: set to windows default (ODIN.INI) | 
|---|
| 951 | GpiSetCp(hps, GetDisplayCodepage()); | 
|---|
| 952 | } | 
|---|
| 953 | else | 
|---|
| 954 | { | 
|---|
| 955 | if (hWindow == HWND_DESKTOP) { | 
|---|
| 956 | hps = WinGetScreenPS (hWindow); | 
|---|
| 957 | } | 
|---|
| 958 | else { | 
|---|
| 959 | int clipstyle = 0; | 
|---|
| 960 | int clipwnd   = HWND_TOP; | 
|---|
| 961 | if(flags & (DCX_USESTYLE_W)) { | 
|---|
| 962 | int style = wnd->getStyle(); | 
|---|
| 963 | if(style & WS_CLIPCHILDREN_W) { | 
|---|
| 964 | clipstyle |= PSF_CLIPCHILDREN; | 
|---|
| 965 | } | 
|---|
| 966 | if(style & WS_CLIPSIBLINGS_W) { | 
|---|
| 967 | clipstyle |= PSF_CLIPSIBLINGS; | 
|---|
| 968 | } | 
|---|
| 969 | if(wnd->fHasParentDC()) { | 
|---|
| 970 | clipstyle |= PSF_PARENTCLIP; | 
|---|
| 971 | } | 
|---|
| 972 | } | 
|---|
| 973 | if(flags & DCX_CLIPSIBLINGS_W) { | 
|---|
| 974 | clipstyle |= PSF_CLIPSIBLINGS; | 
|---|
| 975 | } | 
|---|
| 976 | if(flags & DCX_CLIPCHILDREN_W) { | 
|---|
| 977 | clipstyle |= PSF_CLIPCHILDREN; | 
|---|
| 978 | } | 
|---|
| 979 | if(flags & DCX_PARENTCLIP_W) { | 
|---|
| 980 | clipstyle |= PSF_PARENTCLIP; | 
|---|
| 981 | } | 
|---|
| 982 | if(clipstyle) { | 
|---|
| 983 | dprintf2(("WinGetClipPS style %x", clipstyle)); | 
|---|
| 984 | hps = WinGetClipPS(hWindow, clipwnd, clipstyle); | 
|---|
| 985 | } | 
|---|
| 986 | else    hps = WinGetPS (hWindow); | 
|---|
| 987 |  | 
|---|
| 988 | // default cp is OS/2 one: set to windows default (ODIN.INI) | 
|---|
| 989 | GpiSetCp(hps, GetDisplayCodepage()); | 
|---|
| 990 | } | 
|---|
| 991 | psType = MICRO_CACHED; | 
|---|
| 992 | } | 
|---|
| 993 |  | 
|---|
| 994 | if (!hps) | 
|---|
| 995 | goto error; | 
|---|
| 996 |  | 
|---|
| 997 | HPSToHDC (hWindow, hps, NULL, NULL); | 
|---|
| 998 | pHps = (pDCData)GpiQueryDCData (hps); | 
|---|
| 999 |  | 
|---|
| 1000 | if(!(flags & DCX_WINDOW_W)) | 
|---|
| 1001 | { | 
|---|
| 1002 | selectClientArea(wnd, pHps); | 
|---|
| 1003 | } | 
|---|
| 1004 | else removeClientArea(wnd, pHps); | 
|---|
| 1005 |  | 
|---|
| 1006 | setMapMode(wnd, pHps, MM_TEXT_W); | 
|---|
| 1007 |  | 
|---|
| 1008 | if ((flags & DCX_EXCLUDERGN_W) || (flags & DCX_INTERSECTRGN_W)) | 
|---|
| 1009 | { | 
|---|
| 1010 | ULONG BytesNeeded; | 
|---|
| 1011 | PRGNDATA RgnData; | 
|---|
| 1012 | PRECT pr; | 
|---|
| 1013 | int i; | 
|---|
| 1014 | RECTL rectl; | 
|---|
| 1015 |  | 
|---|
| 1016 | if (!hrgn) | 
|---|
| 1017 | goto error; | 
|---|
| 1018 |  | 
|---|
| 1019 | success = TRUE; | 
|---|
| 1020 | if (flags & DCX_EXCLUDERGN_W) | 
|---|
| 1021 | { | 
|---|
| 1022 | #if 0 //CB: todo | 
|---|
| 1023 | long height; | 
|---|
| 1024 |  | 
|---|
| 1025 | BytesNeeded = GetRegionData (hrgn, 0, NULL); | 
|---|
| 1026 | RgnData = (PRGNDATA_W)_alloca (BytesNeeded); | 
|---|
| 1027 | if (RgnData == NULL) | 
|---|
| 1028 | goto error; | 
|---|
| 1029 | GetRegionData (hrgn, BytesNeeded, RgnData); | 
|---|
| 1030 |  | 
|---|
| 1031 | i = RgnData->rdh.nCount; | 
|---|
| 1032 | pr = (PRECT)(RgnData->Buffer); | 
|---|
| 1033 |  | 
|---|
| 1034 | if (flags & DCX_WINDOW_W) | 
|---|
| 1035 | height = wnd->getWindowHeight(); | 
|---|
| 1036 | else   height = wnd->getClientHeight(); | 
|---|
| 1037 |  | 
|---|
| 1038 | for (; (i > 0) && success; i--, pr++) { | 
|---|
| 1039 | LONG y = pr->yBottom; | 
|---|
| 1040 |  | 
|---|
| 1041 | pr->yBottom = height - pr->yTop; | 
|---|
| 1042 | pr->yTop    = height - y; | 
|---|
| 1043 | success &= GpiExcludeClipRectangle (pHps->hps, pr); | 
|---|
| 1044 | } | 
|---|
| 1045 | #endif | 
|---|
| 1046 | } | 
|---|
| 1047 | else //DCX_INTERSECTRGN_W | 
|---|
| 1048 | { | 
|---|
| 1049 | //SvL: I'm getting paint problems when clipping a dc created in GetDCEx | 
|---|
| 1050 | //     with a region that covers the entire window (RealPlayer 7 Update 1) | 
|---|
| 1051 | //     Using SelectClipRgn here doesn't make any difference. | 
|---|
| 1052 | if(ExtSelectClipRgn(pHps->hps, hrgn, RGN_AND_W) == ERROR_W) { | 
|---|
| 1053 | dprintf(("ExtSelectClipRgn failed!!")); | 
|---|
| 1054 | } | 
|---|
| 1055 | } | 
|---|
| 1056 | if (!success) | 
|---|
| 1057 | goto error; | 
|---|
| 1058 | } | 
|---|
| 1059 |  | 
|---|
| 1060 | if (creatingOwnDC) | 
|---|
| 1061 | wnd->setOwnDC ((HDC)hps); | 
|---|
| 1062 |  | 
|---|
| 1063 | pHps->psType  = psType; | 
|---|
| 1064 | pHps->hdcType = TYPE_1; | 
|---|
| 1065 | //TODO: WM_SETREDRAW affects drawingAllowed flag!! | 
|---|
| 1066 | GpiSetDrawControl (hps, DCTL_DISPLAY, drawingAllowed ? DCTL_ON : DCTL_OFF); | 
|---|
| 1067 |  | 
|---|
| 1068 | dprintf (("User32: GetDCEx hwnd %x (%x %x) -> hdc %x", hwnd, hrgn, flags, pHps->hps)); | 
|---|
| 1069 | return (HDC)pHps->hps; | 
|---|
| 1070 |  | 
|---|
| 1071 | error: | 
|---|
| 1072 | /* Something went wrong; clean up | 
|---|
| 1073 | */ | 
|---|
| 1074 | dprintf(("ERROR: GetDCEx hwnd %x (%x %x) FAILED!", hwnd, hrgn, flags)); | 
|---|
| 1075 | DebugInt3(); | 
|---|
| 1076 | if (pHps) | 
|---|
| 1077 | { | 
|---|
| 1078 | if (pHps->hps) | 
|---|
| 1079 | { | 
|---|
| 1080 | if(pHps->psType == MICRO_CACHED) | 
|---|
| 1081 | WinReleasePS(pHps->hps); | 
|---|
| 1082 | else | 
|---|
| 1083 | GpiDestroyPS(pHps->hps); | 
|---|
| 1084 | } | 
|---|
| 1085 |  | 
|---|
| 1086 | if (pHps->hdc)     DevCloseDC(pHps->hdc); | 
|---|
| 1087 | if (pHps->hrgnHDC) GpiDestroyRegion(pHps->hps, pHps->hrgnHDC); | 
|---|
| 1088 |  | 
|---|
| 1089 | O32_DeleteObject (pHps->nullBitmapHandle); | 
|---|
| 1090 | } | 
|---|
| 1091 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 1092 | return NULL; | 
|---|
| 1093 | } | 
|---|
| 1094 | //****************************************************************************** | 
|---|
| 1095 | //****************************************************************************** | 
|---|
| 1096 | HDC WIN32API GetDC (HWND hwnd) | 
|---|
| 1097 | { | 
|---|
| 1098 | if(!hwnd) | 
|---|
| 1099 | return GetDCEx( GetDesktopWindow(), 0, DCX_CACHE_W | DCX_WINDOW_W ); | 
|---|
| 1100 | return GetDCEx (hwnd, NULL, 0); | 
|---|
| 1101 | } | 
|---|
| 1102 | //****************************************************************************** | 
|---|
| 1103 | //****************************************************************************** | 
|---|
| 1104 | HDC WIN32API GetWindowDC (HWND hwnd) | 
|---|
| 1105 | { | 
|---|
| 1106 | if (!hwnd) hwnd = GetDesktopWindow(); | 
|---|
| 1107 | return GetDCEx (hwnd, NULL, DCX_WINDOW_W); | 
|---|
| 1108 | } | 
|---|
| 1109 | //****************************************************************************** | 
|---|
| 1110 | //Helper for RedrawWindow (RDW_ALLCHILDREN_W) | 
|---|
| 1111 | //****************************************************************************** | 
|---|
| 1112 | LRESULT WIN32API RedrawChildEnumProc(HWND hwnd, LPARAM lParam) | 
|---|
| 1113 | { | 
|---|
| 1114 | RedrawWindow(hwnd, NULL, 0, lParam); | 
|---|
| 1115 | return TRUE; | 
|---|
| 1116 | } | 
|---|
| 1117 | //****************************************************************************** | 
|---|
| 1118 | // This implementation of RedrawWindow supports | 
|---|
| 1119 | // RDW_ERASE | 
|---|
| 1120 | // RDW_NOERASE | 
|---|
| 1121 | // RDW_INTERNALPAINT | 
|---|
| 1122 | // RDW_NOINTERNALPAINT | 
|---|
| 1123 | // RDW_INVALIDATE | 
|---|
| 1124 | // RDW_VALIDATE | 
|---|
| 1125 | // RDW_ERASENOW | 
|---|
| 1126 | // RDW_UPDATENOW | 
|---|
| 1127 | // RDW_FRAME | 
|---|
| 1128 | // | 
|---|
| 1129 | //TODO: Works ok for RDW_FRAME?? | 
|---|
| 1130 | //****************************************************************************** | 
|---|
| 1131 | BOOL WIN32API RedrawWindow(HWND hwnd, const RECT* pRect, HRGN hrgn, DWORD redraw) | 
|---|
| 1132 | { | 
|---|
| 1133 | Win32BaseWindow *wnd; | 
|---|
| 1134 |  | 
|---|
| 1135 | if(pRect) { | 
|---|
| 1136 | dprintf(("RedrawWindow %x (%d,%d)(%d,%d) %x %x", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom, hrgn, redraw)); | 
|---|
| 1137 | } | 
|---|
| 1138 | else   dprintf(("RedrawWindow %x %x %x %x", hwnd, pRect, hrgn, redraw)); | 
|---|
| 1139 |  | 
|---|
| 1140 | if (hwnd == NULLHANDLE) | 
|---|
| 1141 | { | 
|---|
| 1142 | #if 1 | 
|---|
| 1143 | // Don't do this for now (causes lots of desktop repaints in WordPad) | 
|---|
| 1144 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 1145 | return FALSE; | 
|---|
| 1146 | #else | 
|---|
| 1147 | hwnd = HWND_DESKTOP; | 
|---|
| 1148 | wnd  = Win32BaseWindow::GetWindowFromOS2Handle(OSLIB_HWND_DESKTOP); | 
|---|
| 1149 |  | 
|---|
| 1150 | if (!wnd) | 
|---|
| 1151 | { | 
|---|
| 1152 | dprintf(("USER32:dc: RedrawWindow can't find desktop window %08xh\n", | 
|---|
| 1153 | hwnd)); | 
|---|
| 1154 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 1155 | return FALSE; | 
|---|
| 1156 | } | 
|---|
| 1157 | #endif | 
|---|
| 1158 | } | 
|---|
| 1159 | else | 
|---|
| 1160 | { | 
|---|
| 1161 | wnd = Win32BaseWindow::GetWindowFromHandle (hwnd); | 
|---|
| 1162 |  | 
|---|
| 1163 | if (!wnd) | 
|---|
| 1164 | { | 
|---|
| 1165 | dprintf(("USER32:dc: RedrawWindow can't find window %08xh\n", | 
|---|
| 1166 | hwnd)); | 
|---|
| 1167 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 1168 | return FALSE; | 
|---|
| 1169 | } | 
|---|
| 1170 | hwnd = wnd->getOS2WindowHandle(); | 
|---|
| 1171 | } | 
|---|
| 1172 |  | 
|---|
| 1173 | BOOL  IncludeChildren = (redraw & RDW_ALLCHILDREN_W) ? TRUE : FALSE; | 
|---|
| 1174 | BOOL  success = TRUE; | 
|---|
| 1175 | HPS   hpsTemp = NULLHANDLE; | 
|---|
| 1176 | HRGN  hrgnTemp = NULLHANDLE; | 
|---|
| 1177 | RECTL rectl; | 
|---|
| 1178 |  | 
|---|
| 1179 | if (hrgn) | 
|---|
| 1180 | { | 
|---|
| 1181 | ULONG BytesNeeded; | 
|---|
| 1182 | PRGNDATA RgnData; | 
|---|
| 1183 | PRECTL pr; | 
|---|
| 1184 | int i; | 
|---|
| 1185 | LONG height; | 
|---|
| 1186 |  | 
|---|
| 1187 | if(wnd) { | 
|---|
| 1188 | height = (redraw & RDW_FRAME_W) ? wnd->getWindowHeight() : wnd->getClientHeight(); | 
|---|
| 1189 | } | 
|---|
| 1190 | else      height = OSLibQueryScreenHeight(); | 
|---|
| 1191 |  | 
|---|
| 1192 | if (!hrgn) | 
|---|
| 1193 | goto error; | 
|---|
| 1194 |  | 
|---|
| 1195 | BytesNeeded = GetRegionData (hrgn, 0, NULL); | 
|---|
| 1196 | RgnData = (PRGNDATA)_alloca (BytesNeeded); | 
|---|
| 1197 | if (RgnData == NULL) | 
|---|
| 1198 | goto error; | 
|---|
| 1199 | GetRegionData (hrgn, BytesNeeded, RgnData); | 
|---|
| 1200 |  | 
|---|
| 1201 | pr = (PRECTL)(RgnData->Buffer); | 
|---|
| 1202 | for (i = RgnData->rdh.nCount; i > 0; i--, pr++) { | 
|---|
| 1203 | LONG temp = pr->yTop; | 
|---|
| 1204 | pr->yTop = height - pr->yBottom; | 
|---|
| 1205 | pr->yBottom = height - temp; | 
|---|
| 1206 | } | 
|---|
| 1207 |  | 
|---|
| 1208 | hpsTemp = WinGetScreenPS (HWND_DESKTOP); | 
|---|
| 1209 | hrgnTemp = GpiCreateRegion (hpsTemp, RgnData->rdh.nCount, (PRECTL)(RgnData->Buffer)); | 
|---|
| 1210 | if (!hrgnTemp) goto error; | 
|---|
| 1211 | } | 
|---|
| 1212 | else if (pRect) | 
|---|
| 1213 | { | 
|---|
| 1214 | if(wnd) { | 
|---|
| 1215 | if(redraw & RDW_FRAME_W) { | 
|---|
| 1216 | mapWin32ToOS2Rect(wnd->getWindowHeight(), (PRECT)pRect, (PRECTLOS2)&rectl); | 
|---|
| 1217 | } | 
|---|
| 1218 | else    mapWin32ToOS2RectClientToFrame(wnd, (PRECT)pRect, (PRECTLOS2)&rectl); | 
|---|
| 1219 | } | 
|---|
| 1220 | else      mapWin32ToOS2Rect(OSLibQueryScreenHeight(), (PRECT)pRect, (PRECTLOS2)&rectl); | 
|---|
| 1221 | } | 
|---|
| 1222 |  | 
|---|
| 1223 | if (redraw & RDW_INVALIDATE_W) | 
|---|
| 1224 | { | 
|---|
| 1225 | //TODO: SvL: pingpong.exe doesn't have RDW_NOERASE, but doesn't want WM_ERASEBKGND msgs | 
|---|
| 1226 | if (redraw & RDW_ERASE_W) { | 
|---|
| 1227 | wnd->setEraseBkgnd(TRUE); | 
|---|
| 1228 | } | 
|---|
| 1229 | else | 
|---|
| 1230 | if (redraw & RDW_NOERASE_W) | 
|---|
| 1231 | wnd->setEraseBkgnd(FALSE); | 
|---|
| 1232 |  | 
|---|
| 1233 | if (!pRect && !hrgn) | 
|---|
| 1234 | success = WinInvalidateRect (hwnd, NULL, IncludeChildren); | 
|---|
| 1235 | else | 
|---|
| 1236 | if (hrgn) { | 
|---|
| 1237 | success = WinInvalidateRegion (hwnd, hrgnTemp, IncludeChildren); | 
|---|
| 1238 | if(IncludeChildren && WinQueryUpdateRect(hwnd, NULL) == FALSE) { | 
|---|
| 1239 | dprintf(("WARNING: WinQueryUpdateRect %x region %x returned false even though we just invalidated part of a window!!!", hwnd, hrgnTemp)); | 
|---|
| 1240 | success = success = WinInvalidateRegion (hwnd, hrgnTemp, FALSE); | 
|---|
| 1241 | } | 
|---|
| 1242 | } | 
|---|
| 1243 | else { | 
|---|
| 1244 | dprintf2(("WinInvalidateRect (%d,%d)(%d,%d)", rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop)); | 
|---|
| 1245 | success = WinInvalidateRect (hwnd, &rectl, IncludeChildren); | 
|---|
| 1246 | //SvL: If all children are included, then WinInvalidateRect is called | 
|---|
| 1247 | //     with fIncludeChildren=1 -> rect of hwnd isn't invalidated if child(ren) | 
|---|
| 1248 | //     overlap(s) the specified rectangle completely (EVEN if window doesn't | 
|---|
| 1249 | //     have WS_CLIPCHILREN!) | 
|---|
| 1250 | //     -> example: XWing vs Tie Fighter install window | 
|---|
| 1251 | //     WinInvalidateRect with fIncludeChildren=0 invalidates both the parent | 
|---|
| 1252 | //     and child windows | 
|---|
| 1253 | //SvL: Can't always set fIncludeChildren to FALSE or else some controls in | 
|---|
| 1254 | //     the RealPlayer setup application aren't redrawn when invalidating | 
|---|
| 1255 | //     their parent | 
|---|
| 1256 | //     SO: Check if IncludeChildren is set and part of the window is invalid | 
|---|
| 1257 | //         If not -> call WinInvalidateRect with IncludeChildren=0 to force | 
|---|
| 1258 | //         the window rectangle to be invalidated | 
|---|
| 1259 | // | 
|---|
| 1260 | if(IncludeChildren && WinQueryUpdateRect(hwnd, NULL) == FALSE) { | 
|---|
| 1261 | dprintf(("WARNING: WinQueryUpdateRect %x (%d,%d)(%d,%d) returned false even though we just invalidated part of a window!!!", hwnd, rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop)); | 
|---|
| 1262 | success = WinInvalidateRect (hwnd, &rectl, FALSE); | 
|---|
| 1263 | } | 
|---|
| 1264 | } | 
|---|
| 1265 |  | 
|---|
| 1266 | if (!success) goto error; | 
|---|
| 1267 | } | 
|---|
| 1268 | else if (redraw & RDW_VALIDATE_W) | 
|---|
| 1269 | { | 
|---|
| 1270 | if (redraw & RDW_NOERASE_W) | 
|---|
| 1271 | wnd->setEraseBkgnd(FALSE); | 
|---|
| 1272 |  | 
|---|
| 1273 | if (WinQueryUpdateRect (hwnd, NULL)) | 
|---|
| 1274 | { | 
|---|
| 1275 | if(!pRect && !hrgn) { | 
|---|
| 1276 | success = WinValidateRect (hwnd, NULL, IncludeChildren); | 
|---|
| 1277 | } | 
|---|
| 1278 | else | 
|---|
| 1279 | if(hrgn) { | 
|---|
| 1280 | success = WinValidateRegion (hwnd, hrgnTemp, IncludeChildren); | 
|---|
| 1281 | } | 
|---|
| 1282 | else { | 
|---|
| 1283 | success = WinValidateRect (hwnd, &rectl, IncludeChildren); | 
|---|
| 1284 | } | 
|---|
| 1285 | if(!success) goto error; | 
|---|
| 1286 | } | 
|---|
| 1287 | } | 
|---|
| 1288 |  | 
|---|
| 1289 | if(WinQueryUpdateRect(hwnd, NULL)) | 
|---|
| 1290 | { | 
|---|
| 1291 | //TODO: Does this work if RDW_ALLCHILDREN is set?? | 
|---|
| 1292 | if(redraw & RDW_UPDATENOW_W) { | 
|---|
| 1293 | wnd->MsgNCPaint(); | 
|---|
| 1294 | wnd->MsgPaint(0, FALSE); | 
|---|
| 1295 | } | 
|---|
| 1296 | else | 
|---|
| 1297 | //        if((redraw & RDW_ERASE_W) && (redraw & RDW_ERASENOW_W)) | 
|---|
| 1298 | if(redraw & RDW_ERASENOW_W && wnd->needsEraseBkgnd()) | 
|---|
| 1299 | wnd->setEraseBkgnd(sendEraseBkgnd(wnd) == 0); | 
|---|
| 1300 | //      if(redraw & RDW_ALLCHILDREN_W) { | 
|---|
| 1301 | //              EnumChildWindows(wnd->getWindowHandle(), RedrawChildEnumProc, redraw); | 
|---|
| 1302 | //      } | 
|---|
| 1303 | } | 
|---|
| 1304 | else if((redraw & RDW_INTERNALPAINT_W) && !(redraw & RDW_INVALIDATE_W)) | 
|---|
| 1305 | { | 
|---|
| 1306 | if(redraw & RDW_UPDATENOW_W) { | 
|---|
| 1307 | wnd->MsgNCPaint(); | 
|---|
| 1308 | wnd->MsgPaint (0, FALSE); | 
|---|
| 1309 | } | 
|---|
| 1310 | else    PostMessageA(hwnd, WINWM_PAINT, 0, 0); | 
|---|
| 1311 | } | 
|---|
| 1312 |  | 
|---|
| 1313 | error: | 
|---|
| 1314 | /* clean up */ | 
|---|
| 1315 | if (hrgnTemp) | 
|---|
| 1316 | GpiDestroyRegion (hpsTemp, hrgnTemp); | 
|---|
| 1317 |  | 
|---|
| 1318 | if (hpsTemp) | 
|---|
| 1319 | WinReleasePS (hpsTemp); | 
|---|
| 1320 |  | 
|---|
| 1321 | if (!success) { | 
|---|
| 1322 | dprintf(("RedrawWindow failure!")); | 
|---|
| 1323 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 1324 | } | 
|---|
| 1325 | return (success); | 
|---|
| 1326 | } | 
|---|
| 1327 | //****************************************************************************** | 
|---|
| 1328 | //****************************************************************************** | 
|---|
| 1329 | BOOL WIN32API UpdateWindow (HWND hwnd) | 
|---|
| 1330 | { | 
|---|
| 1331 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd); | 
|---|
| 1332 |  | 
|---|
| 1333 | if(!wnd) { | 
|---|
| 1334 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W); | 
|---|
| 1335 | return FALSE; | 
|---|
| 1336 | } | 
|---|
| 1337 |  | 
|---|
| 1338 | dprintf (("User32: UpdateWindow hwnd %x", hwnd)); | 
|---|
| 1339 | //SvL: This doesn't work right (Wine uses RDW_NOCHILDREN_W -> doesn't work here) | 
|---|
| 1340 | //     Breaks vpbuddy | 
|---|
| 1341 | //   return RedrawWindow(hwnd, NULL, 0, RDW_UPDATENOW_W | RDW_ALLCHILDREN_W); | 
|---|
| 1342 | //   -> RDW_UPDATENOW causes WM_PAINT messages to be directy posted to window | 
|---|
| 1343 | //   handler; possibly bypassing queued WM_PAINT messages for parent window(s) | 
|---|
| 1344 | //   -> out of sync painting (i.e. parent paints over child) | 
|---|
| 1345 | WinUpdateWindow(wnd->getOS2WindowHandle()); | 
|---|
| 1346 | return TRUE; | 
|---|
| 1347 | } | 
|---|
| 1348 | //****************************************************************************** | 
|---|
| 1349 | //****************************************************************************** | 
|---|
| 1350 | BOOL WIN32API ValidateRect( HWND hwnd, const RECT * lprc) | 
|---|
| 1351 | { | 
|---|
| 1352 | if(lprc) { | 
|---|
| 1353 | dprintf(("USER32: ValidateRect %x (%d,%d)(%d,%d)", hwnd, lprc->left, lprc->top, lprc->right, lprc->bottom)); | 
|---|
| 1354 | } | 
|---|
| 1355 | else dprintf(("USER32: ValidateRect %x", hwnd)); | 
|---|
| 1356 |  | 
|---|
| 1357 | return RedrawWindow( hwnd, lprc, 0, RDW_VALIDATE_W | RDW_NOCHILDREN_W | (hwnd==0 ? RDW_UPDATENOW_W : 0)); | 
|---|
| 1358 | } | 
|---|
| 1359 | //****************************************************************************** | 
|---|
| 1360 | //****************************************************************************** | 
|---|
| 1361 | BOOL WIN32API ValidateRgn( HWND hwnd, HRGN  hrgn) | 
|---|
| 1362 | { | 
|---|
| 1363 | dprintf(("USER32: ValidateRgn %x %x", hwnd, hrgn)); | 
|---|
| 1364 | return RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE_W | RDW_NOCHILDREN_W | (hwnd==0 ? RDW_UPDATENOW_W : 0)); | 
|---|
| 1365 | } | 
|---|
| 1366 | //****************************************************************************** | 
|---|
| 1367 | //****************************************************************************** | 
|---|
| 1368 | BOOL WIN32API InvalidateRect (HWND hwnd, const RECT *pRect, BOOL erase) | 
|---|
| 1369 | { | 
|---|
| 1370 | BOOL result; | 
|---|
| 1371 |  | 
|---|
| 1372 | if(pRect) { | 
|---|
| 1373 | dprintf(("InvalidateRect %x (%d,%d)(%d,%d) erase=%d", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom, erase)); | 
|---|
| 1374 | } | 
|---|
| 1375 | else dprintf(("InvalidateRect %x NULL erase=%d", hwnd, erase)); | 
|---|
| 1376 | result = RedrawWindow (hwnd, pRect, NULLHANDLE, | 
|---|
| 1377 | RDW_ALLCHILDREN_W | RDW_INVALIDATE_W | | 
|---|
| 1378 | (erase ? RDW_ERASE_W : RDW_NOERASE_W) | | 
|---|
| 1379 | (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0)); | 
|---|
| 1380 | return (result); | 
|---|
| 1381 | } | 
|---|
| 1382 | //****************************************************************************** | 
|---|
| 1383 | //****************************************************************************** | 
|---|
| 1384 | BOOL WIN32API InvalidateRgn (HWND hwnd, HRGN hrgn, BOOL erase) | 
|---|
| 1385 | { | 
|---|
| 1386 | BOOL result; | 
|---|
| 1387 |  | 
|---|
| 1388 | dprintf(("InvalidateRgn %x %x erase=%d", hwnd, hrgn, erase)); | 
|---|
| 1389 | result = RedrawWindow (hwnd, NULL, hrgn, | 
|---|
| 1390 | RDW_ALLCHILDREN_W | RDW_INVALIDATE_W | | 
|---|
| 1391 | (erase ? RDW_ERASE_W : RDW_NOERASE_W) | | 
|---|
| 1392 | (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0)); | 
|---|
| 1393 | return (result); | 
|---|
| 1394 | } | 
|---|
| 1395 | //****************************************************************************** | 
|---|
| 1396 | //TODO: Change for client rectangle!!!!! | 
|---|
| 1397 | //****************************************************************************** | 
|---|
| 1398 | BOOL setPMRgnIntoWinRgn (HRGN hrgnPM, HRGN hrgnWin, LONG height) | 
|---|
| 1399 | { | 
|---|
| 1400 | BOOL    rc; | 
|---|
| 1401 | HPS     hps = WinGetScreenPS (HWND_DESKTOP); | 
|---|
| 1402 | RGNRECT rgnRect; | 
|---|
| 1403 | rgnRect.ircStart    = 1; | 
|---|
| 1404 | rgnRect.crc         = 0; | 
|---|
| 1405 | rgnRect.ulDirection = RECTDIR_LFRT_TOPBOT;     // doesn't make a difference because we're getting them all | 
|---|
| 1406 |  | 
|---|
| 1407 | rc = GpiQueryRegionRects (hps, hrgnPM, NULL, &rgnRect, NULL); | 
|---|
| 1408 |  | 
|---|
| 1409 | if (rc && (rgnRect.crcReturned > 0)) | 
|---|
| 1410 | { | 
|---|
| 1411 | PRECTL Rcls = new RECTL[rgnRect.crcReturned]; | 
|---|
| 1412 | PRECTL pRcl = Rcls; | 
|---|
| 1413 |  | 
|---|
| 1414 | if (Rcls != NULL) | 
|---|
| 1415 | { | 
|---|
| 1416 | rgnRect.crc = rgnRect.crcReturned; | 
|---|
| 1417 | rc = GpiQueryRegionRects (hps, hrgnPM, NULL, &rgnRect, Rcls); | 
|---|
| 1418 |  | 
|---|
| 1419 | rc = SetRectRgn(hrgnWin, pRcl->xLeft, | 
|---|
| 1420 | pRcl->xRight, | 
|---|
| 1421 | height - pRcl->yTop, | 
|---|
| 1422 | height - pRcl->yBottom); | 
|---|
| 1423 |  | 
|---|
| 1424 | if (rgnRect.crcReturned > 1) | 
|---|
| 1425 | { | 
|---|
| 1426 | int i; | 
|---|
| 1427 | HRGN temp; | 
|---|
| 1428 | temp = CreateRectRgn (0, 0, 1, 1); | 
|---|
| 1429 |  | 
|---|
| 1430 | for (i = 1, pRcl++; rc && (i < rgnRect.crcReturned); i++, pRcl++) | 
|---|
| 1431 | { | 
|---|
| 1432 | rc = SetRectRgn (temp, pRcl->xLeft, | 
|---|
| 1433 | pRcl->xRight, | 
|---|
| 1434 | height - pRcl->yTop, | 
|---|
| 1435 | height - pRcl->yBottom); | 
|---|
| 1436 | rc &= CombineRgn (hrgnWin, hrgnWin, temp, RGN_OR_W); | 
|---|
| 1437 | } | 
|---|
| 1438 | DeleteObject (temp); | 
|---|
| 1439 | } | 
|---|
| 1440 | delete[] Rcls; | 
|---|
| 1441 | } | 
|---|
| 1442 | else | 
|---|
| 1443 | { | 
|---|
| 1444 | rc = FALSE; | 
|---|
| 1445 | } | 
|---|
| 1446 | } | 
|---|
| 1447 | else | 
|---|
| 1448 | { | 
|---|
| 1449 | rc = SetRectRgn (hrgnWin, 0, 0, 0, 0); | 
|---|
| 1450 | } | 
|---|
| 1451 |  | 
|---|
| 1452 | WinReleasePS (hps); | 
|---|
| 1453 | return (rc); | 
|---|
| 1454 | } | 
|---|
| 1455 | //****************************************************************************** | 
|---|
| 1456 | //TODO: Check if this one works correctly... | 
|---|
| 1457 | //Have to check if dc is for frame or client!! | 
|---|
| 1458 | //****************************************************************************** | 
|---|
| 1459 | BOOL WIN32API ScrollDC(HDC hDC, int dx, int dy, const RECT *pScroll, | 
|---|
| 1460 | const RECT *pClip, HRGN hrgnUpdate, LPRECT pRectUpdate) | 
|---|
| 1461 | { | 
|---|
| 1462 | BOOL rc = TRUE; | 
|---|
| 1463 |  | 
|---|
| 1464 | dprintf (("USER32: ScrollDC %x (%d,%d), %x %x %x %x", hDC, dx, dy, pScroll, pClip, hrgnUpdate, pRectUpdate)); | 
|---|
| 1465 |  | 
|---|
| 1466 | if (!hDC) | 
|---|
| 1467 | { | 
|---|
| 1468 | return (FALSE); | 
|---|
| 1469 | } | 
|---|
| 1470 |  | 
|---|
| 1471 | pDCData pHps         = (pDCData)GpiQueryDCData ((HPS)hDC); | 
|---|
| 1472 | HWND    hwnd         = pHps->hwnd; | 
|---|
| 1473 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd); | 
|---|
| 1474 |  | 
|---|
| 1475 | if ((hwnd == NULLHANDLE) || !wnd) | 
|---|
| 1476 | { | 
|---|
| 1477 | return (FALSE); | 
|---|
| 1478 | } | 
|---|
| 1479 |  | 
|---|
| 1480 | POINTL ptl[2] = { 0, 0, dx, dy }; | 
|---|
| 1481 |  | 
|---|
| 1482 | GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, ptl); | 
|---|
| 1483 | dx = (int)(ptl[1].x - ptl[0].x); | 
|---|
| 1484 | dy = (int)(ptl[1].y - ptl[0].y); | 
|---|
| 1485 |  | 
|---|
| 1486 | RECT scrollRect; | 
|---|
| 1487 | RECT clipRect; | 
|---|
| 1488 |  | 
|---|
| 1489 | if (pClip) | 
|---|
| 1490 | { | 
|---|
| 1491 | memcpy(&clipRect, pClip, sizeof(clipRect)); | 
|---|
| 1492 |  | 
|---|
| 1493 | if ((pHps->graphicsMode == GM_COMPATIBLE_W) && | 
|---|
| 1494 | (clipRect.left   != clipRect.right)   && | 
|---|
| 1495 | (clipRect.bottom != clipRect.top)) | 
|---|
| 1496 | { | 
|---|
| 1497 | if (abs((int)pHps->viewportXExt) <= abs((int)pHps->windowExt.cx)) | 
|---|
| 1498 | clipRect.right -= abs(pHps->worldXDeltaFor1Pixel); | 
|---|
| 1499 | else | 
|---|
| 1500 | clipRect.left  += abs(pHps->worldXDeltaFor1Pixel); | 
|---|
| 1501 |  | 
|---|
| 1502 | if (abs((int)pHps->viewportYExt) <= abs((int)pHps->windowExt.cy)) | 
|---|
| 1503 | clipRect.bottom -= abs(pHps->worldYDeltaFor1Pixel); | 
|---|
| 1504 | else | 
|---|
| 1505 | clipRect.top    += abs(pHps->worldYDeltaFor1Pixel); | 
|---|
| 1506 | } | 
|---|
| 1507 | GpiConvert(pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, (PPOINTL)&clipRect); | 
|---|
| 1508 | if (clipRect.right < clipRect.left) { | 
|---|
| 1509 | ULONG temp     = clipRect.left; | 
|---|
| 1510 | clipRect.left  = clipRect.right; | 
|---|
| 1511 | clipRect.right = temp; | 
|---|
| 1512 | } | 
|---|
| 1513 | if (clipRect.bottom < clipRect.top) { | 
|---|
| 1514 | ULONG temp       = clipRect.top; | 
|---|
| 1515 | clipRect.top     = clipRect.bottom; | 
|---|
| 1516 | clipRect.bottom  = temp; | 
|---|
| 1517 | } | 
|---|
| 1518 | } | 
|---|
| 1519 |  | 
|---|
| 1520 | if (pScroll) | 
|---|
| 1521 | { | 
|---|
| 1522 | memcpy(&scrollRect, pScroll, sizeof(scrollRect)); | 
|---|
| 1523 |  | 
|---|
| 1524 | if ((pHps->graphicsMode == GM_COMPATIBLE_W) && | 
|---|
| 1525 | (scrollRect.left != scrollRect.right)   && | 
|---|
| 1526 | (scrollRect.top  != scrollRect.bottom)) | 
|---|
| 1527 | { | 
|---|
| 1528 | if (abs((int)pHps->viewportXExt) <= abs((int)pHps->windowExt.cx)) | 
|---|
| 1529 | scrollRect.right -= abs(pHps->worldXDeltaFor1Pixel); | 
|---|
| 1530 | else | 
|---|
| 1531 | scrollRect.left  += abs(pHps->worldXDeltaFor1Pixel); | 
|---|
| 1532 |  | 
|---|
| 1533 | if (abs((int)pHps->viewportYExt) <= abs((int)pHps->windowExt.cy)) | 
|---|
| 1534 | scrollRect.bottom  -= abs(pHps->worldYDeltaFor1Pixel); | 
|---|
| 1535 | else | 
|---|
| 1536 | scrollRect.top     += abs(pHps->worldYDeltaFor1Pixel); | 
|---|
| 1537 | } | 
|---|
| 1538 | GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, (PPOINTL)&scrollRect); | 
|---|
| 1539 | if (scrollRect.right < scrollRect.left) { | 
|---|
| 1540 | ULONG temp       = scrollRect.left; | 
|---|
| 1541 | scrollRect.left  = scrollRect.right; | 
|---|
| 1542 | scrollRect.right = temp; | 
|---|
| 1543 | } | 
|---|
| 1544 | if (scrollRect.bottom < scrollRect.top) { | 
|---|
| 1545 | ULONG temp        = scrollRect.top; | 
|---|
| 1546 | scrollRect.top    = scrollRect.bottom; | 
|---|
| 1547 | scrollRect.bottom = temp; | 
|---|
| 1548 | } | 
|---|
| 1549 | } | 
|---|
| 1550 | RECTL  rectlUpdate; | 
|---|
| 1551 | HRGN   hrgn; | 
|---|
| 1552 | RECTL  clientRect; | 
|---|
| 1553 | RECTL  clipOS2; | 
|---|
| 1554 | RECTL  scrollOS2; | 
|---|
| 1555 | PRECTL pScrollOS2 = NULL; | 
|---|
| 1556 | PRECTL pClipOS2   = NULL; | 
|---|
| 1557 |  | 
|---|
| 1558 | mapWin32ToOS2Rect(wnd->getWindowHeight(), wnd->getClientRectPtr(), (PRECTLOS2)&clientRect); | 
|---|
| 1559 |  | 
|---|
| 1560 | if(pScroll) { | 
|---|
| 1561 | mapWin32ToOS2RectClientToFrame(wnd, &scrollRect, (PRECTLOS2)&scrollOS2); | 
|---|
| 1562 | pScrollOS2 = &scrollOS2; | 
|---|
| 1563 |  | 
|---|
| 1564 | //Scroll rectangle relative to client area | 
|---|
| 1565 | WinIntersectRect ((HAB) 0, pScrollOS2, pScrollOS2, &clientRect); | 
|---|
| 1566 | } | 
|---|
| 1567 | else { | 
|---|
| 1568 | pScrollOS2 = &clientRect; | 
|---|
| 1569 | } | 
|---|
| 1570 |  | 
|---|
| 1571 | if(pClip) { | 
|---|
| 1572 | mapWin32ToOS2RectClientToFrame(wnd, &clipRect, (PRECTLOS2)&clipOS2); | 
|---|
| 1573 | pClipOS2 = &clipOS2; | 
|---|
| 1574 |  | 
|---|
| 1575 | //Clip rectangle relative to client area | 
|---|
| 1576 | WinIntersectRect((HAB) 0, pClipOS2, pClipOS2, &clientRect); | 
|---|
| 1577 | } | 
|---|
| 1578 | else { | 
|---|
| 1579 | pClipOS2 = &clientRect; | 
|---|
| 1580 | } | 
|---|
| 1581 |  | 
|---|
| 1582 | LONG lComplexity = WinScrollWindow(hwnd, dx, dy, pScrollOS2, | 
|---|
| 1583 | pClipOS2, hrgn, &rectlUpdate, 0); | 
|---|
| 1584 | if (lComplexity == RGN_ERROR) | 
|---|
| 1585 | { | 
|---|
| 1586 | return (FALSE); | 
|---|
| 1587 | } | 
|---|
| 1588 |  | 
|---|
| 1589 | RECT winRectUpdate; | 
|---|
| 1590 |  | 
|---|
| 1591 | mapOS2ToWin32Rect(wnd->getWindowHeight(), (PRECTLOS2)&rectlUpdate, &winRectUpdate); | 
|---|
| 1592 |  | 
|---|
| 1593 | if (pRectUpdate) | 
|---|
| 1594 | *pRectUpdate = winRectUpdate; | 
|---|
| 1595 |  | 
|---|
| 1596 | if (hrgnUpdate) | 
|---|
| 1597 | rc = setPMRgnIntoWinRgn(hrgn, hrgnUpdate, wnd->getWindowHeight()); | 
|---|
| 1598 |  | 
|---|
| 1599 | return (rc); | 
|---|
| 1600 | } | 
|---|
| 1601 | //****************************************************************************** | 
|---|
| 1602 | //****************************************************************************** | 
|---|
| 1603 | BOOL WIN32API ScrollWindow(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip) | 
|---|
| 1604 | { | 
|---|
| 1605 | Win32BaseWindow *window; | 
|---|
| 1606 | APIRET  rc; | 
|---|
| 1607 | RECTL   clientRect; | 
|---|
| 1608 | RECTL   scrollRect; | 
|---|
| 1609 | RECTL   clipRect; | 
|---|
| 1610 | PRECTL  pScrollOS2 = NULL; | 
|---|
| 1611 | PRECTL  pClipOS2   = NULL; | 
|---|
| 1612 | ULONG   scrollFlags = SW_INVALIDATERGN; | 
|---|
| 1613 |  | 
|---|
| 1614 | window = Win32BaseWindow::GetWindowFromHandle(hwnd); | 
|---|
| 1615 | if(!window) { | 
|---|
| 1616 | dprintf(("ScrollWindow, window %x not found", hwnd)); | 
|---|
| 1617 | return 0; | 
|---|
| 1618 | } | 
|---|
| 1619 | dprintf(("ScrollWindow %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip)); | 
|---|
| 1620 |  | 
|---|
| 1621 | mapWin32ToOS2Rect(window->getWindowHeight(), window->getClientRectPtr(), (PRECTLOS2)&clientRect); | 
|---|
| 1622 |  | 
|---|
| 1623 | if(pScroll) { | 
|---|
| 1624 | mapWin32ToOS2RectClientToFrame(window,(RECT *)pScroll, (PRECTLOS2)&scrollRect); | 
|---|
| 1625 | pScrollOS2 = &scrollRect; | 
|---|
| 1626 |  | 
|---|
| 1627 | //Scroll rectangle relative to client area | 
|---|
| 1628 | WinIntersectRect ((HAB) 0, pScrollOS2, pScrollOS2, &clientRect); | 
|---|
| 1629 | } | 
|---|
| 1630 | else { | 
|---|
| 1631 | pScrollOS2 = &clientRect; | 
|---|
| 1632 | scrollFlags |= SW_SCROLLCHILDREN; | 
|---|
| 1633 | } | 
|---|
| 1634 |  | 
|---|
| 1635 | if(pClip) { | 
|---|
| 1636 | mapWin32ToOS2RectClientToFrame(window,(RECT *)pClip, (PRECTLOS2)&clipRect); | 
|---|
| 1637 | pClipOS2 = &clipRect; | 
|---|
| 1638 |  | 
|---|
| 1639 | //Clip rectangle relative to client area | 
|---|
| 1640 | WinIntersectRect ((HAB) 0, pClipOS2, pClipOS2, &clientRect); | 
|---|
| 1641 | } | 
|---|
| 1642 | else { | 
|---|
| 1643 | pClipOS2 = &clientRect; | 
|---|
| 1644 | } | 
|---|
| 1645 |  | 
|---|
| 1646 | dy = revertDy (window, dy); | 
|---|
| 1647 |  | 
|---|
| 1648 | rc = WinScrollWindow(window->getOS2WindowHandle(), dx, dy, | 
|---|
| 1649 | pScrollOS2, pClipOS2, NULLHANDLE, | 
|---|
| 1650 | NULL, scrollFlags); | 
|---|
| 1651 |  | 
|---|
| 1652 | return (rc != RGN_ERROR); | 
|---|
| 1653 | } | 
|---|
| 1654 | //****************************************************************************** | 
|---|
| 1655 | //****************************************************************************** | 
|---|
| 1656 | INT WIN32API ScrollWindowEx(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip, | 
|---|
| 1657 | HRGN hrgnUpdate, PRECT pRectUpdate, UINT scrollFlag) | 
|---|
| 1658 | { | 
|---|
| 1659 | Win32BaseWindow *window; | 
|---|
| 1660 | APIRET  rc; | 
|---|
| 1661 | RECTL   clientRect; | 
|---|
| 1662 | RECTL   scrollRect; | 
|---|
| 1663 | RECTL   clipRect; | 
|---|
| 1664 | PRECTL  pScrollOS2 = NULL; | 
|---|
| 1665 | PRECTL  pClipOS2   = NULL; | 
|---|
| 1666 | ULONG   scrollFlags = 0; | 
|---|
| 1667 | int     regionType = ERROR_W; | 
|---|
| 1668 |  | 
|---|
| 1669 | window = Win32BaseWindow::GetWindowFromHandle(hwnd); | 
|---|
| 1670 | if(!window) { | 
|---|
| 1671 | dprintf(("ScrollWindowEx, window %x not found", hwnd)); | 
|---|
| 1672 | return 0; | 
|---|
| 1673 | } | 
|---|
| 1674 |  | 
|---|
| 1675 | dprintf(("ScrollWindowEx %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip)); | 
|---|
| 1676 |  | 
|---|
| 1677 | dy = revertDy (window, dy); | 
|---|
| 1678 |  | 
|---|
| 1679 | if (scrollFlag & SW_INVALIDATE_W)      scrollFlags |= SW_INVALIDATERGN; | 
|---|
| 1680 | if (scrollFlag & SW_SCROLLCHILDREN_W)  scrollFlags |= SW_SCROLLCHILDREN; | 
|---|
| 1681 |  | 
|---|
| 1682 | mapWin32ToOS2Rect(window->getWindowHeight(), window->getClientRectPtr(), (PRECTLOS2)&clientRect); | 
|---|
| 1683 |  | 
|---|
| 1684 | if(pScroll) { | 
|---|
| 1685 | mapWin32ToOS2RectClientToFrame(window,(RECT *)pScroll, (PRECTLOS2)&scrollRect); | 
|---|
| 1686 | pScrollOS2 = &scrollRect; | 
|---|
| 1687 |  | 
|---|
| 1688 | //Scroll rectangle relative to client area | 
|---|
| 1689 | WinIntersectRect ((HAB) 0, pScrollOS2, pScrollOS2, &clientRect); | 
|---|
| 1690 | } | 
|---|
| 1691 | else { | 
|---|
| 1692 | pScrollOS2 = &clientRect; | 
|---|
| 1693 | scrollFlags |= SW_SCROLLCHILDREN;  //TODO: ????? | 
|---|
| 1694 | } | 
|---|
| 1695 |  | 
|---|
| 1696 | if(pClip) { | 
|---|
| 1697 | mapWin32ToOS2RectClientToFrame(window,(RECT *)pClip, (PRECTLOS2)&clipRect); | 
|---|
| 1698 | pClipOS2 = &clipRect; | 
|---|
| 1699 |  | 
|---|
| 1700 | //Clip rectangle relative to client area | 
|---|
| 1701 | WinIntersectRect ((HAB) 0, pClipOS2, pClipOS2, &clientRect); | 
|---|
| 1702 | } | 
|---|
| 1703 | else { | 
|---|
| 1704 | pClipOS2 = &clientRect; | 
|---|
| 1705 | } | 
|---|
| 1706 |  | 
|---|
| 1707 | RECTL rectlUpdate; | 
|---|
| 1708 | HRGN  hrgn; | 
|---|
| 1709 |  | 
|---|
| 1710 | if (scrollFlag & SW_SMOOTHSCROLL_W) | 
|---|
| 1711 | { | 
|---|
| 1712 | INT time = (scrollFlag >> 16) & 0xFFFF; | 
|---|
| 1713 |  | 
|---|
| 1714 | //CB: todo, scroll in several steps | 
|---|
| 1715 | //    is time in ms? time <-> iteration count? | 
|---|
| 1716 | } | 
|---|
| 1717 |  | 
|---|
| 1718 | LONG lComplexity = WinScrollWindow (window->getOS2WindowHandle(), dx, dy, | 
|---|
| 1719 | pScrollOS2, | 
|---|
| 1720 | pClipOS2, | 
|---|
| 1721 | hrgn, &rectlUpdate, scrollFlags); | 
|---|
| 1722 | if (lComplexity == RGN_ERROR) | 
|---|
| 1723 | { | 
|---|
| 1724 | return ERROR_W; | 
|---|
| 1725 | } | 
|---|
| 1726 |  | 
|---|
| 1727 | RECT winRectUpdate; | 
|---|
| 1728 |  | 
|---|
| 1729 | mapOS2ToWin32Rect(window->getWindowHeight(), (PRECTLOS2)&rectlUpdate, &winRectUpdate); | 
|---|
| 1730 |  | 
|---|
| 1731 | if (pRectUpdate) | 
|---|
| 1732 | *pRectUpdate = winRectUpdate; | 
|---|
| 1733 |  | 
|---|
| 1734 | if (hrgnUpdate) | 
|---|
| 1735 | rc = setPMRgnIntoWinRgn (hrgn, hrgnUpdate, window->getWindowHeight()); | 
|---|
| 1736 |  | 
|---|
| 1737 | #if 0 | 
|---|
| 1738 | //SvL: WinScrollWindow already invalidates the area; no need to do it again | 
|---|
| 1739 | //(call to invalidateRect was wrong; has to include erase flag) | 
|---|
| 1740 | if ((scrollFlag & SW_INVALIDATE_W) && | 
|---|
| 1741 | ((lComplexity == RGN_RECT) || (lComplexity == RGN_COMPLEX))) | 
|---|
| 1742 | { | 
|---|
| 1743 | rc = InvalidateRect (hwnd, &winRectUpdate, (scrollFlag & SW_ERASE_W) ? 1 : 0); | 
|---|
| 1744 | if (rc == FALSE) | 
|---|
| 1745 | { | 
|---|
| 1746 | return (0); | 
|---|
| 1747 | } | 
|---|
| 1748 | } | 
|---|
| 1749 | #endif | 
|---|
| 1750 |  | 
|---|
| 1751 | switch (lComplexity) | 
|---|
| 1752 | { | 
|---|
| 1753 | case RGN_NULL: | 
|---|
| 1754 | regionType = NULLREGION_W; | 
|---|
| 1755 | break; | 
|---|
| 1756 | case RGN_RECT: | 
|---|
| 1757 | regionType = SIMPLEREGION_W; | 
|---|
| 1758 | break; | 
|---|
| 1759 | case RGN_COMPLEX: | 
|---|
| 1760 | regionType = COMPLEXREGION_W; | 
|---|
| 1761 | break; | 
|---|
| 1762 | default: | 
|---|
| 1763 | regionType = ERROR_W; | 
|---|
| 1764 | break; | 
|---|
| 1765 | } | 
|---|
| 1766 |  | 
|---|
| 1767 | return (regionType); | 
|---|
| 1768 | } | 
|---|
| 1769 | //****************************************************************************** | 
|---|
| 1770 | //****************************************************************************** | 
|---|
| 1771 | HWND WIN32API WindowFromDC(HDC hdc) | 
|---|
| 1772 | { | 
|---|
| 1773 | pDCData pHps = (pDCData)GpiQueryDCData( (HPS)hdc ); | 
|---|
| 1774 |  | 
|---|
| 1775 | dprintf2(("USER32:  WindowFromDC %x", hdc)); | 
|---|
| 1776 | if ( pHps ) | 
|---|
| 1777 | return OS2ToWin32Handle(pHps->hwnd); | 
|---|
| 1778 | else | 
|---|
| 1779 | return 0; | 
|---|
| 1780 | } | 
|---|
| 1781 | //****************************************************************************** | 
|---|
| 1782 | //****************************************************************************** | 
|---|