00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <odin.h>
00015
00016 #define INCL_WIN
00017 #define INCL_GPI
00018 #define INCL_GREALL
00019 #define INCL_DEV
00020 #include <os2wrap.h>
00021
00022 #include <stdlib.h>
00023
00024 #include <string.h>
00025 #include <win32type.h>
00026 #include <win32api.h>
00027 #include <winuser32.h>
00028 #include <winconst.h>
00029 #include <misc.h>
00030 #include <win32wbase.h>
00031 #include <math.h>
00032 #include <limits.h>
00033 #include "oslibwin.h"
00034 #include "oslibmsg.h"
00035 #include <dcdata.h>
00036 #include <codepage.h>
00037 #include <wingdi32.h>
00038 #include <stats.h>
00039
00040 #define INCLUDED_BY_DC
00041 #include "dc.h"
00042
00043 #define DBG_LOCALLOG DBG_dc
00044 #include "dbglocal.h"
00045
00046 #ifndef DEVESC_SETPS
00047 #define DEVESC_SETPS 49149L
00048 #endif
00049
00050 #define FLOAT_TO_FIXED(x) ((FIXED) ((x) * 65536.0))
00051 #define MICRO_HPS_TO_HDC(x) ((x) & 0xFFFFFFFE)
00052
00053 #define PMRECT_FROM_WINRECT( pmRect, winRect ) \
00054 { \
00055 (pmRect).xLeft = (winRect).left; \
00056 (pmRect).yBottom = (winRect).bottom; \
00057 (pmRect).xRight = (winRect).right; \
00058 (pmRect).yTop = (winRect).top; \
00059 }
00060
00061 #define WINRECT_FROM_PMRECT( winRect, pmRect ) \
00062 { \
00063 (winRect).left = (pmRect).xLeft; \
00064 (winRect).top = (pmRect).yTop; \
00065 (winRect).right = (pmRect).xRight; \
00066 (winRect).bottom = (pmRect).yBottom; \
00067 }
00068
00069 #define MEM_HPS_MAX 768
00070
00071 const XFORM_W XFORMIdentity = { 1.0, 0.0, 0.0, 1.0, 0, 0 };
00072 const MATRIXLF matrixlfIdentity = { 0x10000, 0, 0, 0, 0x10000, 0, 0, 0, 0};
00073
00074 BOOL setPageXForm(Win32BaseWindow *wnd, pDCData pHps);
00075 BOOL changePageXForm(Win32BaseWindow *wnd, pDCData pHps, PPOINTL pValue, int x, int y, PPOINTL pPrev);
00076 LONG clientHeight(Win32BaseWindow *wnd, HWND hwnd, pDCData pHps);
00077
00078 #ifdef DEBUG
00079 #define dprintfRegion(a,b,c) if(DbgEnabledLvl2USER32[DBG_LOCALLOG] == 1) dprintfRegion1(a,b,c)
00080
00081
00082 void dprintfRegion1(HPS hps, HWND hWnd, HRGN hrgnClip)
00083 {
00084 RGNRECT rgnRect = {0, 16, 0, RECTDIR_LFRT_TOPBOT};
00085 RECTL rectRegion[16];
00086 APIRET rc;
00087
00088 dprintf(("dprintfRegion %x %x", hWnd, hps));
00089 rc = GpiQueryRegionRects(hps, hrgnClip, NULL, &rgnRect, &rectRegion[0]);
00090 for(int i=0;i<rgnRect.crcReturned;i++) {
00091 dprintf(("(%d,%d)(%d,%d)", rectRegion[i].xLeft, rectRegion[i].yBottom, rectRegion[i].xRight, rectRegion[i].yTop));
00092 }
00093 }
00094 #else
00095 #define dprintfRegion(a,b,c)
00096 #endif
00097
00098
00099
00100 void WIN32API TestWideLine (pDCData pHps)
00101 {
00102 const LOGPEN_W *pLogPen;
00103
00104 pHps->isWideLine = FALSE;
00105 pLogPen = pHps->penIsExtPen ?
00106 &(pHps->lastPenObject->ExtPen.logpen) :
00107 &(pHps->lastPenObject->Pen.logpen);
00108
00109 if (((pLogPen->lopnStyle & PS_STYLE_MASK_W) != PS_NULL_W) &&
00110 (pLogPen->lopnWidth.x > 0))
00111 {
00112 POINTL aptl[2] = { 0, 0, pLogPen->lopnWidth.x, pLogPen->lopnWidth.x };
00113
00114 GpiConvert(pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, aptl);
00115
00116 ULONG dx = abs(aptl[0].x - aptl[1].x);
00117 ULONG dy = abs(aptl[0].y - aptl[1].y);
00118
00119 pHps->isWideLine = (dx > 1) || (dy > 1);
00120 }
00121 }
00122
00123
00124 void WIN32API Calculate1PixelDelta(pDCData pHps)
00125 {
00126 POINTL aptl[2] = {0, 0, 1, 1};
00127
00128 GpiConvert(pHps->hps, CVTC_DEVICE, CVTC_WORLD, 2, aptl);
00129 pHps->worldYDeltaFor1Pixel = (int)(aptl[1].y - aptl[0].y);
00130 pHps->worldXDeltaFor1Pixel = (int)(aptl[1].x - aptl[0].x);
00131 }
00132
00133
00134 int setMapMode(Win32BaseWindow *wnd, pDCData pHps, int mode)
00135 {
00136 int prevMode = 0;
00137 ULONG flOptions;
00138
00139 switch (mode)
00140 {
00141 case MM_HIENGLISH_W : flOptions = PU_HIENGLISH; break;
00142 case MM_LOENGLISH_W : flOptions = PU_LOENGLISH; break;
00143 case MM_HIMETRIC_W : flOptions = PU_HIMETRIC ; break;
00144 case MM_LOMETRIC_W : flOptions = PU_LOMETRIC ; break;
00145 case MM_TEXT_W : flOptions = PU_PELS ; break;
00146 case MM_TWIPS_W : flOptions = PU_TWIPS ; break;
00147 case MM_ANISOTROPIC_W: flOptions = PU_PELS ; break;
00148 case MM_ISOTROPIC_W : flOptions = PU_LOMETRIC ; break;
00149 default:
00150 SetLastError(ERROR_INVALID_PARAMETER_W);
00151 return FALSE;
00152 }
00153
00154 prevMode = pHps->MapMode;
00155 pHps->MapMode = mode;
00156
00157 if (mode == MM_TEXT_W)
00158 {
00159 pHps->viewportXExt =
00160 pHps->viewportYExt = 1.0;
00161 pHps->windowExt.cx =
00162 pHps->windowExt.cy = 1;
00163 }
00164 else if (mode != MM_ANISOTROPIC_W)
00165 {
00166 RECTL rectl;
00167 SIZEL sizel;
00168 ULONG data[3];
00169
00170 data[0] = flOptions;
00171 data[1] = data[2] = 0;
00172
00173 if (DevEscape(pHps->hdc ? pHps->hdc : pHps->hps, DEVESC_SETPS, 12, (PBYTE)data, 0, 0) == DEVESC_ERROR)
00174 {
00175 SetLastError(ERROR_INVALID_PARAMETER_W);
00176 return 0;
00177 }
00178
00179 GpiQueryPageViewport(pHps->hps, &rectl);
00180 pHps->viewportXExt = (double)rectl.xRight;
00181 pHps->viewportYExt = -(double)rectl.yTop;
00182
00183 GreGetPageUnits(pHps->hdc? pHps->hdc : pHps->hps, &sizel);
00184 pHps->windowExt.cx = sizel.cx;
00185 pHps->windowExt.cy = sizel.cy;
00186
00187 data[0] = PU_PELS;
00188 DevEscape(pHps->hdc ? pHps->hdc : pHps->hps, DEVESC_SETPS, 12, (PBYTE)data, 0, 0);
00189 }
00190
00191 if (((prevMode != MM_ISOTROPIC_W) && (prevMode != MM_ANISOTROPIC_W)) &&
00192 ((mode == MM_ISOTROPIC_W) || (mode == MM_ANISOTROPIC_W)))
00193 {
00194 if (pHps->lWndXExtSave && pHps->lWndYExtSave)
00195 {
00196 changePageXForm (wnd, pHps, (PPOINTL)&pHps->windowExt,
00197 pHps->lWndXExtSave, pHps->lWndYExtSave, NULL );
00198 pHps->lWndXExtSave = pHps->lWndYExtSave = 0;
00199 }
00200 if (pHps->lVwpXExtSave && pHps->lVwpYExtSave)
00201 {
00202 changePageXForm (wnd, pHps, NULL,
00203 pHps->lVwpXExtSave, pHps->lVwpYExtSave, NULL );
00204 pHps->lVwpXExtSave = pHps->lVwpYExtSave = 0;
00205 }
00206 }
00207
00208 setPageXForm(wnd, pHps);
00209
00210 return prevMode;
00211 }
00212
00213
00214 BOOL setPageXForm(Win32BaseWindow *wnd, pDCData pHps)
00215 {
00216 MATRIXLF mlf;
00217 BOOL rc = TRUE;
00218
00219 pHps->height = clientHeight(wnd, 0, pHps) - 1;
00220
00221 double xScale = pHps->viewportXExt / (double)pHps->windowExt.cx;
00222 double yScale = pHps->viewportYExt / (double)pHps->windowExt.cy;
00223
00224 #if 0
00225 mlf.fxM11 = FLOAT_TO_FIXED(1.0);
00226 mlf.fxM12 = 0;
00227 mlf.lM13 = 0;
00228 mlf.fxM21 = 0;
00229 mlf.fxM22 = FLOAT_TO_FIXED(1.0);
00230 mlf.lM23 = 0;
00231 mlf.lM31 = pHps->viewportOrg.x - (LONG)(pHps->windowOrg.x * xScale);
00232 mlf.lM32 = pHps->viewportOrg.y - (LONG)(pHps->windowOrg.y * yScale);
00233 mlf.lM33 = 1;
00234
00235
00236 if(wnd && wnd->getWindowWidth() && wnd->getWindowHeight())
00237 {
00238 RECTL recttmp, rectviewold;
00239
00240 rc = GpiQueryPageViewport(pHps->hps, &rectviewold);
00241 if(rc == 0) {
00242 dprintf(("WARNING: GpiQueryPageViewport returned FALSE!!"));
00243 }
00244 recttmp.xLeft = 0;
00245 recttmp.xRight = ((double)GetScreenWidth() / xScale);
00246 recttmp.yBottom = 0;
00247 recttmp.yTop = ((double)GetScreenHeight() / yScale);
00248
00249 if(recttmp.yTop != rectviewold.yTop ||
00250 recttmp.xRight != rectviewold.xRight)
00251 {
00252 if(pHps->viewportYExt > pHps->windowExt.cy) {
00253 recttmp.yBottom = GetScreenHeight() - recttmp.yTop;
00254 recttmp.yTop = GetScreenHeight();
00255 }
00256 dprintf(("GpiSetPageViewport %x (%d,%d)(%d,%d) %f %f", pHps->hps, recttmp.xLeft, recttmp.yBottom, recttmp.xRight, recttmp.yTop, xScale, yScale));
00257 rc = GpiSetPageViewport(pHps->hps, &recttmp);
00258 if(rc == 0) {
00259 dprintf(("WARNING: GpiSetPageViewport returned FALSE!!"));
00260 }
00261 }
00262 }
00263
00264
00265 #else
00266 mlf.fxM11 = FLOAT_TO_FIXED(xScale);
00267 mlf.fxM12 = 0;
00268 mlf.lM13 = 0;
00269 mlf.fxM21 = 0;
00270 mlf.fxM22 = FLOAT_TO_FIXED(yScale);
00271 mlf.lM23 = 0;
00272 mlf.lM31 = pHps->viewportOrg.x - (LONG)(pHps->windowOrg.x * xScale);
00273 mlf.lM32 = pHps->viewportOrg.y - (LONG)(pHps->windowOrg.y * yScale);
00274 mlf.lM33 = 1;
00275 #endif
00276
00277 pHps->isLeftLeft = mlf.fxM11 >= 0;
00278 pHps->isTopTop = mlf.fxM22 >= 0;
00279
00280 BOOL bEnableYInversion = FALSE;
00281 if ((mlf.fxM22 > 0) ||
00282 ((pHps->graphicsMode == GM_ADVANCED_W) &&
00283 ((pHps->MapMode == MM_ANISOTROPIC_W) ||
00284 (pHps->MapMode == MM_ISOTROPIC_W))))
00285 {
00286 bEnableYInversion = TRUE;
00287 }
00288 else
00289 {
00290 bEnableYInversion = FALSE;
00291 mlf.lM32 = pHps->HPStoHDCInversionHeight + pHps->height - mlf.lM32;
00292 mlf.fxM22 = -mlf.fxM22;
00293 }
00294
00295 if (!pHps->isMetaPS)
00296
00297
00298 rc = GpiSetDefaultViewMatrix(pHps->hps, 8, &mlf, TRANSFORM_REPLACE);
00299 if(rc == 0) {
00300 dprintf(("WARNING: GpiSetDefaultViewMatrix returned FALSE!!"));
00301 }
00302 #ifdef INVERT
00303 if (bEnableYInversion)
00304 GpiEnableYInversion(pHps->hps, pHps->height + pHps->HPStoHDCInversionHeight);
00305 else
00306 GpiEnableYInversion(pHps->hps, 0);
00307 #else
00308 pHps->yInvert = 0;
00309 if(bEnableYInversion)
00310 {
00311 pHps->yInvert4Enable = pHps->height + pHps->HPStoHDCInversionHeight;
00312 if(pHps->isPrinter)
00313 {
00314 pHps->yInvert = pHps->yInvert4Enable
00315 * (pHps->windowExt.cy / (double)pHps->viewportYExt);
00316 } else {
00317 pHps->yInvert = pHps->yInvert4Enable;
00318 }
00319 }
00320 #endif
00321
00322 TestWideLine(pHps);
00323 Calculate1PixelDelta(pHps);
00324 return rc;
00325 }
00326
00327
00328 BOOL changePageXForm(Win32BaseWindow *wnd, pDCData pHps, PPOINTL pValue, int x, int y, PPOINTL pPrev)
00329 {
00330 BOOL result = FALSE;
00331
00332 if (pValue)
00333 {
00334 if (pPrev)
00335 *pPrev = *pValue;
00336
00337 if ((pValue->x == x) && (pValue->y == y)) {
00338 return TRUE;
00339 }
00340 pValue->x = x;
00341 pValue->y = y;
00342 }
00343 else
00344 {
00345 if (pPrev)
00346 {
00347 pPrev->x = (int)pHps->viewportXExt;
00348 pPrev->y = (int)pHps->viewportYExt;
00349 }
00350 pHps->viewportXExt = (double)x;
00351 pHps->viewportYExt = (double)y;
00352 }
00353
00354 if (pHps->MapMode == MM_ISOTROPIC_W)
00355 {
00356 double xExt = fabs(pHps->viewportXExt);
00357 double yExt = fabs(pHps->viewportYExt);
00358 double sf = fabs((double)pHps->windowExt.cx / pHps->windowExt.cy);
00359
00360 if (xExt > (yExt * sf))
00361 {
00362 xExt = yExt * sf;
00363
00364 if ((double)LONG_MAX <= xExt) return (result);
00365
00366 if (pHps->viewportXExt < 0.0)
00367 pHps->viewportXExt = -xExt;
00368 else
00369 pHps->viewportXExt = xExt;
00370 }
00371 else
00372 {
00373 yExt = xExt / sf;
00374
00375 if ((double)LONG_MAX <= yExt) return (result);
00376
00377 if (pHps->viewportYExt < 0.0)
00378 pHps->viewportYExt = -yExt;
00379 else
00380 pHps->viewportYExt = yExt;
00381 }
00382 }
00383 result = setPageXForm(wnd, pHps);
00384
00385 return (result);
00386 }
00387
00388
00389 VOID removeClientArea(Win32BaseWindow *window, pDCData pHps)
00390 {
00391 pHps->isClient = FALSE;
00392 pHps->isClientArea = FALSE;
00393 }
00394
00395
00396 void selectClientArea(Win32BaseWindow *window, pDCData pHps)
00397 {
00398 pHps->isClient = TRUE;
00399 pHps->isClientArea = TRUE;
00400 }
00401
00402
00403 void selectClientArea(Win32BaseWindow *wnd, HDC hdc)
00404 {
00405 pDCData pHps = (pDCData)GpiQueryDCData (wnd->getOwnDC());
00406
00407 if (pHps != NULLHANDLE)
00408 selectClientArea(wnd, pHps);
00409 }
00410
00411
00412 LONG clientHeight(Win32BaseWindow *wnd, HWND hwnd, pDCData pHps)
00413 {
00414 if ((hwnd == 0) && (pHps != 0))
00415 hwnd = pHps->hwnd;
00416
00417 if ((hwnd != 0) || (pHps == 0))
00418 {
00419 if(wnd) {
00420 if(pHps && !pHps->isClientArea) {
00421 return (wnd->getWindowHeight());
00422 }
00423 else return (wnd->getClientHeight());
00424 }
00425 else return OSLibQueryScreenHeight();
00426 }
00427 else if (pHps->bitmapHandle)
00428 {
00429 return pHps->bitmapHeight;
00430 }
00431 else if (pHps->isMetaPS)
00432 {
00433 return 0;
00434 }
00435 else if (pHps->isPrinter)
00436 {
00437 return pHps->printPageHeight;
00438 }
00439 else
00440 {
00441 return MEM_HPS_MAX;
00442 }
00443 }
00444
00445
00446 BOOL WIN32API changePageXForm(pDCData pHps, PPOINTL pValue, int x, int y, PPOINTL pPrev)
00447 {
00448 Win32BaseWindow *wnd;
00449
00450 if(pHps->isClient) {
00451 wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
00452 }
00453 else wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(pHps->hwnd);
00454 BOOL ret = changePageXForm(wnd, pHps, pValue, x, y, pPrev);
00455 if(wnd) RELEASE_WNDOBJ(wnd);
00456 return ret;
00457 }
00458
00459
00460 BOOL WIN32API setPageXForm(pDCData pHps)
00461 {
00462 Win32BaseWindow *wnd;
00463
00464 if(pHps->isClient) {
00465 wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
00466 }
00467 else wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(pHps->hwnd);
00468 BOOL ret = setPageXForm(wnd, pHps);
00469 if(wnd) RELEASE_WNDOBJ(wnd);
00470 return ret;
00471 }
00472
00473
00474 VOID WIN32API removeClientArea(pDCData pHps)
00475 {
00476 Win32BaseWindow *wnd;
00477
00478 if(pHps->isClient) {
00479 wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
00480 }
00481 else wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(pHps->hwnd);
00482 if(wnd) {
00483 removeClientArea(wnd, pHps);
00484 RELEASE_WNDOBJ(wnd);
00485 }
00486 }
00487
00488
00489 VOID WIN32API selectClientArea(pDCData pHps)
00490 {
00491 Win32BaseWindow *wnd;
00492
00493 if(pHps->isClient) {
00494 wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
00495 }
00496 else wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(pHps->hwnd);
00497 if(wnd) {
00498 selectClientArea(wnd, pHps);
00499 RELEASE_WNDOBJ(wnd);
00500 }
00501 }
00502
00503
00504 VOID WIN32API checkOrigin(pDCData pHps)
00505 {
00506 Win32BaseWindow *wnd;
00507
00508 if(pHps->isClient) {
00509 wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
00510 }
00511 else wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(pHps->hwnd);
00512 if(wnd) {
00513 if(pHps->isClient)
00514 selectClientArea(wnd, pHps);
00515 RELEASE_WNDOBJ(wnd);
00516 }
00517 }
00518
00519
00520 LONG WIN32API clientHeight(HWND hwnd, pDCData pHps)
00521 {
00522 Win32BaseWindow *wnd;
00523
00524 if(!pHps) {
00525 wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
00526 }
00527 else
00528 if(pHps->isClient) {
00529 wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
00530 }
00531 else wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(pHps->hwnd);
00532 LONG ret = clientHeight(wnd, hwnd, pHps);
00533 if(wnd) RELEASE_WNDOBJ(wnd);
00534 return ret;
00535 }
00536
00537
00538 int WIN32API setMapModeDC(pDCData pHps, int mode)
00539 {
00540 Win32BaseWindow *wnd;
00541
00542 if(pHps->isClient) {
00543 wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
00544 }
00545 else wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(pHps->hwnd);
00546 int ret = setMapMode(wnd, pHps, mode);
00547 if(wnd) RELEASE_WNDOBJ(wnd);
00548 return ret;
00549 }
00550
00551
00552 BOOL isYup (pDCData pHps)
00553 {
00554 if (((pHps->windowExt.cy < 0) && (pHps->viewportYExt > 0.0)) ||
00555 ((pHps->windowExt.cy > 0) && (pHps->viewportYExt < 0.0)))
00556 {
00557 if ((pHps->graphicsMode == GM_COMPATIBLE_W) ||
00558 ((pHps->graphicsMode == GM_ADVANCED_W) && (pHps->xform.eM22 >= 0.0)))
00559 return TRUE;
00560 }
00561 else
00562 {
00563 if ((pHps->graphicsMode == GM_ADVANCED_W) && (pHps->xform.eM22 < 0.0))
00564 return TRUE;
00565 }
00566 return FALSE;
00567 }
00568
00569
00570 INT revertDy (Win32BaseWindow *wnd, INT dy)
00571 {
00572
00573
00574 if (wnd->isOwnDC())
00575 {
00576 pDCData pHps = (pDCData)GpiQueryDCData (wnd->getOwnDC());
00577
00578 if (pHps != NULLHANDLE)
00579 if (!isYup (pHps))
00580 dy = -dy;
00581 }
00582 else
00583 {
00584 dy = -dy;
00585 }
00586 return (dy);
00587 }
00588
00589
00590 HDC sendEraseBkgnd (Win32BaseWindow *wnd)
00591 {
00592 BOOL erased;
00593 HWND hwnd;
00594 HDC hdc;
00595 HPS hps;
00596 HRGN hrgnUpdate, hrgnOld, hrgnClip, hrgnCombined;
00597 RECTL rectl = { 1, 1, 2, 2 };
00598
00599 hwnd = wnd->getOS2WindowHandle();
00600 hps = WinGetPS(hwnd);
00601
00602 hrgnUpdate = GpiCreateRegion (hps, 1, &rectl);
00603 WinQueryUpdateRegion (hwnd, hrgnUpdate);
00604 hrgnClip = GpiQueryClipRegion (hps);
00605
00606 if (hrgnClip == NULLHANDLE)
00607 {
00608 GpiSetClipRegion (hps, hrgnUpdate, &hrgnOld);
00609 }
00610 else
00611 {
00612 hrgnCombined = GpiCreateRegion (hps, 1, &rectl);
00613 GpiCombineRegion (hps, hrgnCombined, hrgnClip, hrgnUpdate, CRGN_AND);
00614 GpiSetClipRegion (hps, hrgnCombined, &hrgnOld);
00615 GpiDestroyRegion (hps, hrgnUpdate);
00616 GpiDestroyRegion (hps, hrgnClip);
00617 }
00618 if (hrgnOld != NULLHANDLE)
00619 GpiDestroyRegion (hps, hrgnOld);
00620
00621 hdc = HPSToHDC (hwnd, hps, NULL, NULL);
00622
00623 erased = wnd->MsgEraseBackGround (hdc);
00624
00625 DeleteHDC (hdc);
00626 WinReleasePS (hps);
00627
00628 return erased;
00629 }
00630
00631
00632 void releaseOwnDC (HDC hps)
00633 {
00634 pDCData pHps = (pDCData)GpiQueryDCData ((HPS)hps);
00635
00636 dprintf2(("releaseOwnDC %x", hps));
00637
00638 if (pHps) {
00639 if (pHps->hrgnHDC)
00640 GpiDestroyRegion (pHps->hps, pHps->hrgnHDC);
00641
00642 GpiSetBitmap (pHps->hps, NULL);
00643 O32_DeleteObject (pHps->nullBitmapHandle);
00644 GpiDestroyPS(pHps->hps);
00645
00646 if (pHps->hdc)
00647 DevCloseDC(pHps->hdc);
00648 }
00649 }
00650
00651
00652 HDC WIN32API BeginPaint (HWND hWnd, PPAINTSTRUCT_W lpps)
00653 {
00654 HWND hwnd = hWnd ? hWnd : HWND_DESKTOP;
00655 pDCData pHps = NULLHANDLE;
00656 HPS hPS_ownDC = NULLHANDLE, hpsPaint = 0;
00657 RECTL rectl = {0, 0, 1, 1};
00658 HRGN hrgnOldClip;
00659 LONG lComplexity;
00660 RECTL rectlClient;
00661 RECTL rectlClip;
00662
00663 if(lpps == NULL) {
00664
00665
00666 dprintf (("USER32: BeginPaint %x NULL PAINTSTRUCT pointer", hWnd));
00667 return 0;
00668 }
00669 memset(lpps, 0, sizeof(*lpps));
00670
00671 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
00672 if(!wnd) {
00673 dprintf (("USER32: BeginPaint %x %x: invalid window handle!!", hWnd, lpps));
00674 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
00675 return (HDC)0;
00676 }
00677 HWND hwndClient = wnd->getOS2WindowHandle();
00678
00679 if(hwnd != HWND_DESKTOP && wnd->isOwnDC())
00680 {
00681 hPS_ownDC = wnd->getOwnDC();
00682
00683 if(hPS_ownDC) {
00684 pHps = (pDCData)GpiQueryDCData(hPS_ownDC);
00685 if (!pHps)
00686 {
00687 dprintf (("USER32: BeginPaint %x invalid parameter %x", hWnd, lpps));
00688 RELEASE_WNDOBJ(wnd);
00689 SetLastError(ERROR_INVALID_PARAMETER_W);
00690 return (HDC)NULLHANDLE;
00691 }
00692 hpsPaint = hPS_ownDC;
00693 }
00694 }
00695 if(!hpsPaint) {
00696 hpsPaint = GetDCEx(hwnd, 0, (DCX_CACHE_W|DCX_USESTYLE_W));
00697 pHps = (pDCData)GpiQueryDCData(hpsPaint);
00698 if (!pHps)
00699 {
00700 dprintf (("USER32: BeginPaint %x invalid parameter %x", hWnd, lpps));
00701 RELEASE_WNDOBJ(wnd);
00702 SetLastError(ERROR_INVALID_PARAMETER_W);
00703 return (HDC)NULLHANDLE;
00704 }
00705 }
00706
00707 if(WinQueryUpdateRect(hwndClient, &rectl) == FALSE)
00708 {
00709 memset(&rectl, 0, sizeof(rectl));
00710 dprintf (("USER32: WARNING: WinQueryUpdateRect failed (error or no update rectangle)!!"));
00711
00712 HRGN hrgnClip = GpiCreateRegion(pHps->hps, 1, &rectl);
00713 GpiSetClipRegion(pHps->hps, hrgnClip, &hrgnOldClip);
00714
00715 selectClientArea(wnd, pHps);
00716
00717
00718 wnd->SetClipRegion(hrgnOldClip);
00719 lComplexity = RGN_NULL;
00720 }
00721 else {
00722 rectlClip.yBottom = rectlClip.xLeft = 0;
00723 rectlClip.yTop = rectlClip.xRight = 1;
00724
00725
00726 HRGN hrgnClip = GpiCreateRegion(pHps->hps, 1, &rectlClip);
00727 WinQueryUpdateRegion(hwndClient, hrgnClip);
00728 WinValidateRegion(hwndClient, hrgnClip, FALSE);
00729
00730 dprintfRegion(pHps->hps, wnd->getWindowHandle(), hrgnClip);
00731
00732 #ifdef DEBUG
00733
00734 lComplexity = GpiQueryClipBox(pHps->hps, &rectlClip);
00735 dprintf(("ClipBox (%d): (%d,%d)(%d,%d)", lComplexity, rectlClip.xLeft, rectlClip.yBottom, rectlClip.xRight, rectlClip.yTop));
00736 #endif
00737
00738
00739 lComplexity = GpiSetClipRegion(pHps->hps, hrgnClip, &hrgnOldClip);
00740
00741 if(lComplexity == RGN_NULL) {
00742 dprintf (("BeginPaint %x: EMPTY update rectangle (show=%d/%d vis=%d/%d", hWnd, WinIsWindowVisible(wnd->getOS2FrameWindowHandle()), WinIsWindowVisible(wnd->getOS2WindowHandle()), WinIsWindowShowing(wnd->getOS2FrameWindowHandle()), WinIsWindowShowing(wnd->getOS2WindowHandle())));
00743 }
00744 else dprintf (("BeginPaint %x: (show=%d/%d vis=%d/%d)", hWnd, WinIsWindowVisible(wnd->getOS2FrameWindowHandle()), WinIsWindowVisible(wnd->getOS2WindowHandle()), WinIsWindowShowing(wnd->getOS2FrameWindowHandle()), WinIsWindowShowing(wnd->getOS2WindowHandle())));
00745
00746 selectClientArea(wnd, pHps);
00747
00748 #ifdef DEBUG
00749
00750 GpiQueryClipBox(pHps->hps, &rectlClip);
00751 dprintf(("ClipBox (%d): (%d,%d)(%d,%d)", lComplexity, rectlClip.xLeft, rectlClip.yBottom, rectlClip.xRight, rectlClip.yTop));
00752 #endif
00753
00754 wnd->SetClipRegion(hrgnOldClip);
00755 }
00756
00757 if(hPS_ownDC == 0)
00758 setMapMode (wnd, pHps, MM_TEXT_W);
00759 else
00760 setPageXForm(wnd, pHps);
00761
00762 pHps->hdcType = TYPE_3;
00763
00764 HideCaret(hwnd);
00765 WinShowTrackRect(wnd->getOS2WindowHandle(), FALSE);
00766
00767 if((wnd->needsEraseBkgnd() || wnd->IsVisibleRegionChanged()) && lComplexity != RGN_NULL) {
00768 wnd->setEraseBkgnd(FALSE);
00769 wnd->SetVisibleRegionChanged(FALSE);
00770 lpps->fErase = (wnd->MsgEraseBackGround(pHps->hps) == 0);
00771 }
00772 else lpps->fErase = TRUE;
00773
00774 lpps->hdc = (HDC)pHps->hps;
00775
00776 if(lComplexity != RGN_NULL) {
00777 long height = wnd->getClientHeight();
00778 lpps->rcPaint.top = height - rectl.yTop;
00779 lpps->rcPaint.left = rectl.xLeft;
00780 lpps->rcPaint.bottom = height - rectl.yBottom;
00781 lpps->rcPaint.right = rectl.xRight;
00782
00783
00784 DPtoLP(lpps->hdc, (LPPOINT)&lpps->rcPaint, 2);
00785 }
00786 else {
00787 lpps->rcPaint.bottom = lpps->rcPaint.top = 0;
00788 lpps->rcPaint.right = lpps->rcPaint.left = 0;
00789 }
00790 RELEASE_WNDOBJ(wnd);
00791
00792 SetLastError(0);
00793 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));
00794 return (HDC)pHps->hps;
00795 }
00796
00797
00798 BOOL WIN32API EndPaint (HWND hWnd, const PAINTSTRUCT_W *pPaint)
00799 {
00800 HWND hwnd = hWnd ? hWnd : HWND_DESKTOP;
00801 HRGN hrgnOld;
00802 pDCData pHps;
00803
00804 dprintf (("USER32: EndPaint(%x)", hwnd));
00805
00806 if (!pPaint || !pPaint->hdc )
00807 return TRUE;
00808
00809 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
00810
00811 if (!wnd) goto exit;
00812
00813 pHps = (pDCData)GpiQueryDCData((HPS)pPaint->hdc);
00814 if (pHps && (pHps->hdcType == TYPE_3))
00815 {
00816 GpiSetClipRegion(pHps->hps, wnd->GetClipRegion(), &hrgnOld);
00817 wnd->SetClipRegion(0);
00818 if(hrgnOld) {
00819 GpiDestroyRegion(pHps->hps, hrgnOld);
00820 }
00821 pHps->hdcType = TYPE_1;
00822 ReleaseDC(hwnd, pPaint->hdc);
00823 }
00824 else {
00825 dprintf(("EndPaint: wrong hdc %x!!", pPaint->hdc));
00826 }
00827 wnd->setEraseBkgnd(TRUE);
00828 ShowCaret(hwnd);
00829 WinShowTrackRect(wnd->getOS2WindowHandle(), TRUE);
00830
00831 exit:
00832 if(wnd) RELEASE_WNDOBJ(wnd);
00833 SetLastError(0);
00834 return TRUE;
00835 }
00836
00837
00838 int WIN32API ReleaseDC (HWND hwnd, HDC hdc)
00839 {
00840 BOOL isOwnDC = FALSE;
00841 int rc;
00842
00843 if (hwnd)
00844 {
00845 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
00846 if(wnd == NULL) {
00847 dprintf(("ERROR: ReleaseDC %x %x failed", hwnd, hdc));
00848 return 0;
00849 }
00850 isOwnDC = wnd->isOwnDC() && (wnd->getOwnDC() == hdc);
00851 if(!isOwnDC)
00852 {
00853 pDCData pHps = (pDCData)GpiQueryDCData((HPS)hdc);
00854 if(pHps && pHps->psType == MICRO_CACHED) {
00855 removeClientArea(wnd, pHps);
00856 if(pHps->hrgnVis) {
00857 GreDestroyRegion(pHps->hps, pHps->hrgnVis);
00858 pHps->hrgnVis = 0;
00859 }
00860 }
00861 else {
00862 dprintf(("ERROR: ReleaseDC: pHps == NULL!!"));
00863 DebugInt3();
00864 }
00865 }
00866 else {
00867 dprintf2(("ReleaseDC: CS_OWNDC, not released"));
00868 }
00869 RELEASE_WNDOBJ(wnd);
00870 }
00871
00872 if(isOwnDC) {
00873 rc = TRUE;
00874 }
00875 else {
00876 UnselectGDIObjects(hdc);
00877 rc = O32_ReleaseDC (0, hdc);
00878 STATS_ReleaseDC(hwnd, hdc);
00879 }
00880
00881 dprintf(("ReleaseDC %x %x", hwnd, hdc));
00882 return (rc);
00883 }
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897 HDC WIN32API GetDCEx (HWND hwnd, HRGN hrgn, ULONG flags)
00898 {
00899 Win32BaseWindow *wnd = NULL;
00900 HWND hWindow;
00901 BOOL success;
00902 pDCData pHps = NULL;
00903 HPS hps = NULLHANDLE;
00904 BOOL drawingAllowed = TRUE;
00905 BOOL isWindowOwnDC;
00906 BOOL creatingOwnDC = FALSE;
00907 PS_Type psType;
00908
00909 if(hwnd == 0) {
00910 dprintf(("error: GetDCEx window %x not found", hwnd));
00911 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
00912 return 0;
00913 }
00914
00915 if(hwnd)
00916 {
00917 wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
00918 if(wnd == NULL) {
00919 dprintf (("ERROR: User32: GetDCEx bad window handle %X!!!!!", hwnd));
00920 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
00921 return 0;
00922 }
00923 if(flags & DCX_WINDOW_W) {
00924 hWindow = wnd->getOS2FrameWindowHandle();
00925 }
00926 else hWindow = wnd->getOS2WindowHandle();
00927 }
00928
00929 isWindowOwnDC = (((hWindow == HWND_DESKTOP) ? FALSE : (wnd->isOwnDC()))
00930 && !(flags & (DCX_CACHE_W|DCX_WINDOW_W)));
00931
00932 if(isWindowOwnDC)
00933 {
00934 hps = wnd->getOwnDC();
00935 if (hps)
00936 {
00937 pDCData pHps = (pDCData)GpiQueryDCData (hps);
00938 if (!pHps)
00939 goto error;
00940
00941 selectClientArea(wnd, pHps);
00942
00943
00944 setPageXForm (wnd, pHps);
00945 pHps->hdcType = TYPE_1;
00946
00947
00948 dprintf (("User32: GetDCEx hwnd %x (%x %x) -> wnd %x hdc %x", hwnd, hrgn, flags, wnd, hps));
00949
00950 RELEASE_WNDOBJ(wnd);
00951
00952 STATS_GetDCEx(hwnd, hps, hrgn, flags);
00953
00954 return (HDC)hps;
00955 }
00956 else creatingOwnDC = TRUE;
00957 }
00958
00959 if(isWindowOwnDC)
00960 {
00961 SIZEL sizel = {0,0};
00962 hps = GpiCreatePS (WinQueryAnchorBlock (hWindow),
00963 WinOpenWindowDC (hWindow),
00964 &sizel, PU_PELS | GPIT_MICRO | GPIA_ASSOC );
00965 psType = MICRO;
00966
00967 GpiSetCp(hps, GetDisplayCodepage());
00968 }
00969 else
00970 {
00971 if (hWindow == HWND_DESKTOP) {
00972 hps = WinGetScreenPS (hWindow);
00973 }
00974 else {
00975 int clipstyle = 0;
00976 int clipwnd = HWND_TOP;
00977 if(flags & (DCX_USESTYLE_W))
00978 {
00979 int style = wnd->getStyle();
00980 if(style & WS_CLIPCHILDREN_W) {
00981 clipstyle |= PSF_CLIPCHILDREN;
00982 }
00983 if(style & WS_CLIPSIBLINGS_W) {
00984 clipstyle |= PSF_CLIPSIBLINGS;
00985 }
00986 if(wnd->fHasParentDC()) {
00987 clipstyle |= PSF_PARENTCLIP;
00988 }
00989 }
00990 if(flags & DCX_CLIPSIBLINGS_W) {
00991 clipstyle |= PSF_CLIPSIBLINGS;
00992 }
00993 if(flags & DCX_CLIPCHILDREN_W) {
00994 clipstyle |= PSF_CLIPCHILDREN;
00995 }
00996 if(flags & DCX_PARENTCLIP_W) {
00997 clipstyle |= PSF_PARENTCLIP;
00998 }
00999
01000
01001
01002 dprintf2(("WinGetClipPS style %x", clipstyle));
01003 hps = WinGetClipPS(hWindow, clipwnd, clipstyle);
01004
01005
01006
01007
01008 GpiSetCp(hps, GetDisplayCodepage());
01009 }
01010 psType = MICRO_CACHED;
01011 }
01012
01013 if (!hps)
01014 goto error;
01015
01016 HPSToHDC (hWindow, hps, NULL, NULL);
01017 pHps = (pDCData)GpiQueryDCData (hps);
01018
01019 if(flags & DCX_WINDOW_W) {
01020 removeClientArea(wnd, pHps);
01021 }
01022 else selectClientArea(wnd, pHps);
01023
01024 setMapMode(wnd, pHps, MM_TEXT_W);
01025
01026 if ((flags & DCX_EXCLUDERGN_W) || (flags & DCX_INTERSECTRGN_W))
01027 {
01028 ULONG BytesNeeded;
01029 PRGNDATA RgnData;
01030 PRECT pr;
01031 int i;
01032 RECTL rectl;
01033
01034 if (!hrgn)
01035 goto error;
01036
01037 success = TRUE;
01038 if (flags & DCX_EXCLUDERGN_W)
01039 {
01040 #if 0 //CB: todo
01041 long height;
01042
01043 BytesNeeded = GetRegionData (hrgn, 0, NULL);
01044 RgnData = (PRGNDATA_W)_alloca (BytesNeeded);
01045 if (RgnData == NULL)
01046 goto error;
01047 GetRegionData (hrgn, BytesNeeded, RgnData);
01048
01049 i = RgnData->rdh.nCount;
01050 pr = (PRECT)(RgnData->Buffer);
01051
01052 if (flags & DCX_WINDOW_W)
01053 height = wnd->getWindowHeight();
01054 else height = wnd->getClientHeight();
01055
01056 for (; (i > 0) && success; i--, pr++) {
01057 LONG y = pr->yBottom;
01058
01059 pr->yBottom = height - pr->yTop;
01060 pr->yTop = height - y;
01061 success &= GpiExcludeClipRectangle (pHps->hps, pr);
01062 }
01063 #endif
01064 }
01065 else
01066 {
01067
01068
01069
01070 if(ExtSelectClipRgn(pHps->hps, hrgn, RGN_AND_W) == ERROR_W) {
01071 dprintf(("ExtSelectClipRgn failed!!"));
01072 }
01073 }
01074 if (!success)
01075 goto error;
01076 }
01077
01078 if (creatingOwnDC)
01079 wnd->setOwnDC ((HDC)hps);
01080
01081 pHps->psType = psType;
01082 pHps->hdcType = TYPE_1;
01083
01084 GpiSetDrawControl (hps, DCTL_DISPLAY, drawingAllowed ? DCTL_ON : DCTL_OFF);
01085
01086 dprintf (("User32: GetDCEx hwnd %x (%x %x) -> hdc %x", hwnd, hrgn, flags, pHps->hps));
01087 RELEASE_WNDOBJ(wnd);
01088
01089
01090 STATS_GetDCEx(hwnd, pHps->hps, hrgn, flags);
01091 return (HDC)pHps->hps;
01092
01093 error:
01094
01095
01096 dprintf(("ERROR: GetDCEx hwnd %x (%x %x) FAILED!", hwnd, hrgn, flags));
01097 DebugInt3();
01098 if (pHps)
01099 {
01100 if (pHps->hps)
01101 {
01102 if(pHps->psType == MICRO_CACHED)
01103 WinReleasePS(pHps->hps);
01104 else
01105 GpiDestroyPS(pHps->hps);
01106 }
01107
01108 if (pHps->hdc) DevCloseDC(pHps->hdc);
01109 if (pHps->hrgnHDC) GpiDestroyRegion(pHps->hps, pHps->hrgnHDC);
01110
01111 O32_DeleteObject (pHps->nullBitmapHandle);
01112 }
01113 if(wnd) RELEASE_WNDOBJ(wnd);
01114 SetLastError(ERROR_INVALID_PARAMETER_W);
01115 return NULL;
01116 }
01117
01118
01119 HDC WIN32API GetDC (HWND hwnd)
01120 {
01121 if(!hwnd)
01122 return GetDCEx( GetDesktopWindow(), 0, DCX_CACHE_W | DCX_WINDOW_W );
01123
01124 return GetDCEx (hwnd, NULL, DCX_USESTYLE_W);
01125 }
01126
01127
01128 HDC WIN32API GetWindowDC (HWND hwnd)
01129 {
01130 if (!hwnd) hwnd = GetDesktopWindow();
01131 return GetDCEx (hwnd, NULL, DCX_WINDOW_W | DCX_USESTYLE_W);
01132 }
01133
01134
01135
01136 LRESULT WIN32API RedrawChildEnumProc(HWND hwnd, LPARAM lParam)
01137 {
01138 RedrawWindow(hwnd, NULL, 0, lParam);
01139 return TRUE;
01140 }
01141
01142
01143
01144
01145
01146
01147
01148
01149
01150
01151
01152
01153
01154
01155
01156 BOOL WIN32API RedrawWindow(HWND hwnd, const RECT* pRect, HRGN hrgn, DWORD redraw)
01157 {
01158 Win32BaseWindow *wnd;
01159
01160 if(pRect) {
01161 dprintf(("RedrawWindow %x (%d,%d)(%d,%d) %x %x", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom, hrgn, redraw));
01162 }
01163 else dprintf(("RedrawWindow %x %x %x %x", hwnd, pRect, hrgn, redraw));
01164
01165 if (hwnd == NULLHANDLE)
01166 {
01167 hwnd = HWND_DESKTOP;
01168 wnd = Win32BaseWindow::GetWindowFromOS2Handle(OSLIB_HWND_DESKTOP);
01169
01170 if (!wnd)
01171 {
01172 dprintf(("USER32:dc: RedrawWindow can't find desktop window %08xh\n",
01173 hwnd));
01174 SetLastError(ERROR_INVALID_PARAMETER_W);
01175 return FALSE;
01176 }
01177 }
01178 else
01179 {
01180 wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
01181
01182 if (!wnd)
01183 {
01184 dprintf(("USER32:dc: RedrawWindow can't find window %08xh\n",
01185 hwnd));
01186 SetLastError(ERROR_INVALID_PARAMETER_W);
01187 return FALSE;
01188 }
01189 if(redraw & RDW_FRAME_W) {
01190 hwnd = wnd->getOS2FrameWindowHandle();
01191 }
01192 else hwnd = wnd->getOS2WindowHandle();
01193 }
01194
01195 BOOL IncludeChildren = (redraw & RDW_ALLCHILDREN_W) ? TRUE : FALSE;
01196 BOOL success = TRUE;
01197 HPS hpsTemp = NULLHANDLE;
01198 HRGN hrgnTemp = NULLHANDLE;
01199 RECTL rectl;
01200
01201 if (hrgn)
01202 {
01203 ULONG BytesNeeded;
01204 PRGNDATA RgnData;
01205 PRECTL pr;
01206 int i;
01207 LONG height;
01208
01209 if(wnd) {
01210 height = (redraw & RDW_FRAME_W) ? wnd->getWindowHeight() : wnd->getClientHeight();
01211 }
01212 else height = OSLibQueryScreenHeight();
01213
01214 if (!hrgn)
01215 goto error;
01216
01217 BytesNeeded = GetRegionData (hrgn, 0, NULL);
01218 RgnData = (PRGNDATA)_alloca (BytesNeeded);
01219 if (RgnData == NULL)
01220 goto error;
01221 GetRegionData (hrgn, BytesNeeded, RgnData);
01222
01223 pr = (PRECTL)(RgnData->Buffer);
01224 for (i = RgnData->rdh.nCount; i > 0; i--, pr++) {
01225 LONG temp = pr->yTop;
01226 pr->yTop = height - pr->yBottom;
01227 pr->yBottom = height - temp;
01228 dprintf2(("RedrawWindow: region (%d,%d) (%d,%d)", pr->xLeft, pr->yBottom, pr->xRight, pr->yTop));
01229 }
01230
01231 hpsTemp = WinGetScreenPS (HWND_DESKTOP);
01232 hrgnTemp = GpiCreateRegion (hpsTemp, RgnData->rdh.nCount, (PRECTL)(RgnData->Buffer));
01233 if (!hrgnTemp) goto error;
01234 }
01235 else if (pRect)
01236 {
01237 if(wnd) {
01238 if(redraw & RDW_FRAME_W) {
01239 mapWin32ToOS2Rect(wnd->getWindowHeight(), (PRECT)pRect, (PRECTLOS2)&rectl);
01240 }
01241 else mapWin32ToOS2Rect(wnd->getClientHeight(), (PRECT)pRect, (PRECTLOS2)&rectl);
01242 }
01243 else mapWin32ToOS2Rect(OSLibQueryScreenHeight(), (PRECT)pRect, (PRECTLOS2)&rectl);
01244 }
01245
01246 if (redraw & RDW_INVALIDATE_W)
01247 {
01248
01249 if (redraw & RDW_ERASE_W) {
01250 wnd->setEraseBkgnd(TRUE);
01251 }
01252 else
01253
01254
01255 if (!WinQueryUpdateRect (hwnd, NULL)) {
01256 wnd->setEraseBkgnd(FALSE);
01257 }
01258
01259 if (!pRect && !hrgn)
01260 success = WinInvalidateRect (hwnd, NULL, IncludeChildren);
01261 else
01262 if (hrgn) {
01263 success = WinInvalidateRegion (hwnd, hrgnTemp, IncludeChildren);
01264 if(IncludeChildren && WinQueryUpdateRect(hwnd, NULL) == FALSE) {
01265 dprintf(("WARNING: WinQueryUpdateRect %x region %x returned false even though we just invalidated part of a window!!!", hwnd, hrgnTemp));
01266 success = success = WinInvalidateRegion (hwnd, hrgnTemp, FALSE);
01267 }
01268 }
01269 else {
01270 dprintf2(("WinInvalidateRect (%d,%d)(%d,%d)", rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop));
01271 success = WinInvalidateRect (hwnd, &rectl, IncludeChildren);
01272
01273
01274
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284
01285
01286 if(IncludeChildren && WinQueryUpdateRect(hwnd, NULL) == FALSE) {
01287 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));
01288 success = WinInvalidateRect (hwnd, &rectl, FALSE);
01289 }
01290 }
01291
01292 if (!success) goto error;
01293 }
01294 else if (redraw & RDW_VALIDATE_W)
01295 {
01296 if (redraw & RDW_NOERASE_W)
01297 wnd->setEraseBkgnd(FALSE);
01298
01299 if (WinQueryUpdateRect (hwnd, NULL))
01300 {
01301 if(!pRect && !hrgn) {
01302 success = WinValidateRect (hwnd, NULL, IncludeChildren);
01303 }
01304 else
01305 if(hrgn) {
01306 success = WinValidateRegion (hwnd, hrgnTemp, IncludeChildren);
01307 }
01308 else {
01309 success = WinValidateRect (hwnd, &rectl, IncludeChildren);
01310 }
01311 if(!success) goto error;
01312 }
01313 }
01314
01315 if(WinQueryUpdateRect(hwnd, &rectl))
01316 {
01317 dprintf2(("Update region (%d,%d)(%d,%d)", rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop));
01318
01319 if(redraw & RDW_UPDATENOW_W)
01320 {
01321 dprintf(("RDW_UPDATENOW -> UpdateWindow"));
01322 UpdateWindow(wnd->getWindowHandle());
01323 }
01324 else
01325
01326 if(redraw & RDW_ERASENOW_W && wnd->needsEraseBkgnd())
01327 wnd->setEraseBkgnd(sendEraseBkgnd(wnd) == 0);
01328
01329
01330
01331 }
01332 else if((redraw & RDW_INTERNALPAINT_W) && !(redraw & RDW_INVALIDATE_W))
01333 {
01334 dprintf(("Manual redraw"));
01335 if(redraw & RDW_UPDATENOW_W) {
01336 wnd->MsgPaint(0, FALSE);
01337 }
01338 else PostMessageA(hwnd, WINWM_PAINT, 0, 0);
01339 }
01340
01341 error:
01342
01343 if (hrgnTemp)
01344 GpiDestroyRegion (hpsTemp, hrgnTemp);
01345
01346 if (hpsTemp)
01347 WinReleasePS (hpsTemp);
01348
01349 if (!success) {
01350 dprintf(("RedrawWindow failure!"));
01351 SetLastError(ERROR_INVALID_PARAMETER_W);
01352 }
01353 if(wnd) RELEASE_WNDOBJ(wnd);
01354 return (success);
01355 }
01356
01357
01358 BOOL WIN32API UpdateWindow (HWND hwnd)
01359 {
01360 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
01361 RECTL rectl;
01362 BOOL rc;
01363
01364 if(!wnd) {
01365 dprintf (("ERROR: User32: UpdateWindow INVALID hwnd %x", hwnd));
01366 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
01367 return FALSE;
01368 }
01369
01370 #ifdef DEBUG
01371 if(WinQueryUpdateRect(wnd->getOS2WindowHandle(), &rectl))
01372 {
01373 RECT rectUpdate;
01374 mapOS2ToWin32Rect(wnd->getClientHeight(), (PRECTLOS2)&rectl, &rectUpdate);
01375
01376 dprintf (("User32: UpdateWindow hwnd %x: update rectangle (%d,%d)(%d,%d)", hwnd, rectUpdate.left, rectUpdate.top, rectUpdate.right, rectUpdate.bottom));
01377 }
01378 else dprintf (("User32: UpdateWindow hwnd %x; EMPTY update rectangle (vis=%d/%d, show=%d/%d, vis parent=%d)", hwnd, WinIsWindowVisible(wnd->getOS2FrameWindowHandle()), WinIsWindowVisible(wnd->getOS2WindowHandle()), WinIsWindowShowing(wnd->getOS2FrameWindowHandle()), WinIsWindowShowing(wnd->getOS2WindowHandle()), IsWindowVisible(GetParent(hwnd))));
01379 #endif
01380
01381
01382
01383
01384
01385
01386
01387
01388
01389
01390
01391
01392
01393
01394 rc = WinUpdateWindow(wnd->getOS2FrameWindowHandle());
01395 #ifdef DEBUG
01396 if(WinQueryUpdateRect(wnd->getOS2WindowHandle(), NULL))
01397 {
01398
01399
01400 dprintf (("ERROR: User32: UpdateWindow didn't send WM_PAINT messages!!"));
01401 }
01402 #endif
01403 RELEASE_WNDOBJ(wnd);
01404 return rc;
01405 }
01406
01407
01408 BOOL WIN32API ValidateRect( HWND hwnd, const RECT * lprc)
01409 {
01410 if(lprc) {
01411 dprintf(("USER32: ValidateRect %x (%d,%d)(%d,%d)", hwnd, lprc->left, lprc->top, lprc->right, lprc->bottom));
01412 }
01413 else dprintf(("USER32: ValidateRect %x", hwnd));
01414
01415 return RedrawWindow( hwnd, lprc, 0, RDW_VALIDATE_W | RDW_NOCHILDREN_W | (hwnd==0 ? RDW_UPDATENOW_W : 0));
01416 }
01417
01418
01419 BOOL WIN32API ValidateRgn( HWND hwnd, HRGN hrgn)
01420 {
01421 dprintf(("USER32: ValidateRgn %x %x", hwnd, hrgn));
01422 return RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE_W | RDW_NOCHILDREN_W | (hwnd==0 ? RDW_UPDATENOW_W : 0));
01423 }
01424
01425
01426 BOOL WIN32API InvalidateRect (HWND hwnd, const RECT *pRect, BOOL erase)
01427 {
01428 BOOL result;
01429
01430 if(pRect) {
01431 dprintf(("InvalidateRect %x (%d,%d)(%d,%d) erase=%d", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom, erase));
01432 }
01433 else dprintf(("InvalidateRect %x NULL erase=%d", hwnd, erase));
01434 #if 1
01435 result = RedrawWindow (hwnd, pRect, NULLHANDLE,
01436 RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
01437 (erase ? RDW_ERASE_W : 0) |
01438 (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
01439 #else
01440 result = RedrawWindow (hwnd, pRect, NULLHANDLE,
01441 RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
01442 (erase ? RDW_ERASE_W : RDW_NOERASE_W) |
01443 (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
01444 #endif
01445 return (result);
01446 }
01447
01448
01449 BOOL WIN32API InvalidateRgn (HWND hwnd, HRGN hrgn, BOOL erase)
01450 {
01451 BOOL result;
01452
01453 dprintf(("InvalidateRgn %x %x erase=%d", hwnd, hrgn, erase));
01454 #if 1
01455 result = RedrawWindow (hwnd, NULL, hrgn,
01456 RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
01457 (erase ? RDW_ERASE_W : 0) |
01458 (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
01459 #else
01460 result = RedrawWindow (hwnd, NULL, hrgn,
01461 RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
01462 (erase ? RDW_ERASE_W : RDW_NOERASE_W) |
01463 (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
01464 #endif
01465 return (result);
01466 }
01467
01468
01469
01470 BOOL setPMRgnIntoWinRgn (HPS hps, HRGN hrgnPM, HRGN hrgnWin, LONG height)
01471 {
01472 BOOL rc;
01473 RGNRECT rgnRect;
01474 rgnRect.ircStart = 1;
01475 rgnRect.crc = 0;
01476 rgnRect.ulDirection = RECTDIR_LFRT_TOPBOT;
01477
01478 rc = GpiQueryRegionRects (hps, hrgnPM, NULL, &rgnRect, NULL);
01479
01480 if (rc && (rgnRect.crcReturned > 0))
01481 {
01482 PRECTL Rcls = new RECTL[rgnRect.crcReturned];
01483 PRECTL pRcl = Rcls;
01484
01485 if (Rcls != NULL)
01486 {
01487 rgnRect.crc = rgnRect.crcReturned;
01488 rc = GpiQueryRegionRects (hps, hrgnPM, NULL, &rgnRect, Rcls);
01489
01490 rc = SetRectRgn(hrgnWin, pRcl->xLeft, height - pRcl->yTop,
01491 pRcl->xRight, height - pRcl->yBottom);
01492
01493 if (rgnRect.crcReturned > 1)
01494 {
01495 int i;
01496 HRGN temp;
01497 temp = CreateRectRgn (0, 0, 1, 1);
01498
01499 for (i = 1, pRcl++; rc && (i < rgnRect.crcReturned); i++, pRcl++)
01500 {
01501 rc = SetRectRgn (temp, pRcl->xLeft, height - pRcl->yTop,
01502 pRcl->xRight, height - pRcl->yBottom);
01503 rc &= CombineRgn (hrgnWin, hrgnWin, temp, RGN_OR_W);
01504 }
01505 DeleteObject (temp);
01506 }
01507 delete[] Rcls;
01508 }
01509 else
01510 {
01511 rc = FALSE;
01512 }
01513 }
01514 else
01515 {
01516 rc = SetRectRgn (hrgnWin, 0, 0, 0, 0);
01517 }
01518
01519 return (rc);
01520 }
01521
01522
01523
01524 INT WIN32API ScrollWindowEx(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip,
01525 HRGN hrgnUpdate, PRECT pRectUpdate, UINT scrollFlag)
01526 {
01527 Win32BaseWindow *window;
01528 APIRET rc;
01529 RECTL scrollRect;
01530 RECTL clipRect;
01531 PRECTL pScrollOS2 = NULL;
01532 PRECTL pClipOS2 = NULL;
01533 ULONG scrollFlagsOS2 = 0;
01534 int orgdy = dy;
01535 int regionType = ERROR_W;
01536
01537 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
01538 if(!window) {
01539 dprintf(("ScrollWindowEx, window %x not found", hwnd));
01540 return 0;
01541 }
01542
01543 dprintf(("ScrollWindowEx %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip));
01544
01545 dy = revertDy (window, dy);
01546
01547 if (scrollFlag & SW_INVALIDATE_W) scrollFlagsOS2 |= SW_INVALIDATERGN;
01548 if (scrollFlag & SW_SCROLLCHILDREN_W) scrollFlagsOS2 |= SW_SCROLLCHILDREN;
01549
01550 if(pScroll) {
01551 mapWin32ToOS2Rect(window->getClientHeight(), (RECT *)pScroll, (PRECTLOS2)&scrollRect);
01552 pScrollOS2 = &scrollRect;
01553 }
01554
01555 if(pClip) {
01556 mapWin32ToOS2Rect(window->getClientHeight(), (RECT *)pClip, (PRECTLOS2)&clipRect);
01557 pClipOS2 = &clipRect;
01558 }
01559
01560 RECTL rectlUpdate;
01561 HRGN hrgn = NULLHANDLE;
01562 HPS hpsScreen = 0;
01563
01564 if(hrgnUpdate) {
01565 RECTL rectl = { 1, 1, 2, 2 };
01566
01567 hpsScreen = WinGetScreenPS (HWND_DESKTOP);
01568 hrgn = GpiCreateRegion(hpsScreen, 1, &rectl);
01569 }
01570
01571 if (scrollFlag & SW_SMOOTHSCROLL_W)
01572 {
01573 INT time = (scrollFlag >> 16) & 0xFFFF;
01574
01575
01576
01577 }
01578
01579 LONG lComplexity = WinScrollWindow(window->getOS2WindowHandle(), dx, dy,
01580 pScrollOS2, pClipOS2,
01581 hrgn, &rectlUpdate, scrollFlagsOS2);
01582 if (lComplexity == RGN_ERROR)
01583 {
01584 RELEASE_WNDOBJ(window);
01585 return ERROR_W;
01586 }
01587
01588
01589
01590
01591
01592 if (scrollFlag & SW_SCROLLCHILDREN_W)
01593 {
01594 HWND hwndChild;
01595 RECT rectChild, rc;
01596
01597 dprintf(("ScrollWindowEx: Scroll child windows"));
01598 GetClientRect(hwnd, &rc);
01599 if (pScroll) IntersectRect(&rc, &rc, pScroll);
01600
01601 hwndChild = GetWindow(hwnd, GW_CHILD_W);
01602
01603 while(hwndChild)
01604 {
01605 Win32BaseWindow *child;
01606
01607 child = Win32BaseWindow::GetWindowFromHandle(hwndChild);
01608 if(!child) {
01609 dprintf(("ERROR: ScrollWindowEx, child %x not found", hwnd));
01610 RELEASE_WNDOBJ(window);
01611 return 0;
01612 }
01613 rectChild = *child->getWindowRect();
01614 if(!pScroll || IntersectRect(&rectChild, &rectChild, &rc))
01615 {
01616 dprintf(("ScrollWindowEx: Scroll child window %x", hwndChild));
01617 child->ScrollWindow(dx, orgdy);
01618 }
01619 RELEASE_WNDOBJ(child);
01620 hwndChild = GetWindow(hwndChild, GW_HWNDNEXT_W);
01621 }
01622 dprintf(("***ScrollWindowEx: Scroll child windows DONE"));
01623 }
01624
01625 RECT winRectUpdate;
01626
01627 mapOS2ToWin32Rect(window->getClientHeight(), (PRECTLOS2)&rectlUpdate, &winRectUpdate);
01628
01629 if (pRectUpdate)
01630 *pRectUpdate = winRectUpdate;
01631
01632 if (hrgnUpdate) {
01633 rc = setPMRgnIntoWinRgn(hpsScreen, hrgn, hrgnUpdate, window->getClientHeight());
01634 GpiDestroyRegion(hpsScreen, hrgn);
01635 WinReleasePS(hpsScreen);
01636 }
01637
01638 #if 0
01639
01640
01641 if ((scrollFlag & SW_INVALIDATE_W) &&
01642 ((lComplexity == RGN_RECT) || (lComplexity == RGN_COMPLEX)))
01643 {
01644 rc = RedrawWindow (hwnd, &winRectUpdate, NULLHANDLE,
01645 RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
01646 ((scrollFlag & SW_ERASE_W) ? RDW_ERASE_W : 0) |
01647 RDW_UPDATENOW_W);
01648
01649
01650 if (rc == FALSE)
01651 {
01652 RELEASE_WNDOBJ(window);
01653 return (0);
01654 }
01655 }
01656 #endif
01657
01658 switch (lComplexity)
01659 {
01660 case RGN_NULL:
01661 regionType = NULLREGION_W;
01662 break;
01663 case RGN_RECT:
01664 regionType = SIMPLEREGION_W;
01665 break;
01666 case RGN_COMPLEX:
01667 regionType = COMPLEXREGION_W;
01668 break;
01669 default:
01670 regionType = ERROR_W;
01671 break;
01672 }
01673
01674 RELEASE_WNDOBJ(window);
01675 return (regionType);
01676 }
01677
01678
01679 BOOL WIN32API ScrollWindow(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip)
01680 {
01681 dprintf(("ScrollWindow %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip));
01682 return (ERROR_W != ScrollWindowEx(hwnd, dx, dy, pScroll, pClip, 0, NULL,
01683 (pScroll ? 0 : SW_SCROLLCHILDREN_W) |
01684 SW_INVALIDATE_W ));
01685 }
01686
01687
01688 HWND WIN32API WindowFromDC(HDC hdc)
01689 {
01690 pDCData pHps = (pDCData)GpiQueryDCData( (HPS)hdc );
01691
01692 dprintf2(("USER32: WindowFromDC %x", hdc));
01693 if ( pHps )
01694 return OS2ToWin32Handle(pHps->hwnd);
01695 else
01696 return 0;
01697 }
01698
01699
01700