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