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