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