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