Ignore:
Timestamp:
May 11, 2001, 10:39:46 AM (24 years ago)
Author:
sandervl
Message:

client/frame rewrite

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/user32/dc.cpp

    r5655 r5685  
    1 /* $Id: dc.cpp,v 1.98 2001-05-04 17:02:50 sandervl Exp $ */
     1/* $Id: dc.cpp,v 1.99 2001-05-11 08:39:41 sandervl Exp $ */
    22
    33/*
     
    387387VOID removeClientArea(Win32BaseWindow *window, pDCData pHps)
    388388{
    389  POINTL point;
    390 
    391    // This function checks to see if a client area is currently selected, if
    392    // it is the origin plus the visible region of the frame are restored.
    393 
    394389   pHps->isClient = FALSE;
    395 
    396 ////   dprintfOrigin(pHps->hps);
    397 
    398    if(pHps->isClientArea)
    399    {
    400         dprintf2(("removeClientArea %x: (%d,%d) -> (%d,%d)", window->getWindowHandle(), point.x, point.y, pHps->ptlOrigin.x, pHps->ptlOrigin.y));
    401         pHps->isClientArea = FALSE;
    402         GreSetupDC(pHps->hps,
    403                    pHps->hrgnVis,
    404                    pHps->ptlOrigin.x,
    405                    pHps->ptlOrigin.y,
    406                    0,
    407                    SETUPDC_ORIGIN | SETUPDC_VISRGN | SETUPDC_RECALCCLIP);
    408    }
    409 ////   else dprintf2(("removeClientArea: %x (%d,%d) (%d,%d)", window->getWindowHandle(), point.x, point.y, pHps->ptlOrigin.x, pHps->ptlOrigin.y));
    410 
     390   pHps->isClientArea = FALSE;
    411391}
    412392//******************************************************************************
     
    414394void selectClientArea(Win32BaseWindow *window, pDCData pHps)
    415395{
    416    // This function checks to see if the DC needs to be adjusted to a client
    417    // area and makes the adjustment.
    418    RECTL rcl, rcltemp;
    419    HRGN  hrgnRect, hrgnClip, hrgnOldClip = 0;
    420    HWND  hwnd;
    421    LONG  rc;
    422    PRECT pClient = window->getClientRectPtr();
    423    PRECT pWindow = window->getWindowRect();
    424    RECT  rectWindow;
    425    RECTL rectWindowOS2;
    426 
    427    if(!window->isOwnDCDirty() && (pClient->left == 0 && pClient->top == 0 &&
    428       window->getClientHeight() == window->getWindowHeight() &&
    429       window->getClientWidth()  == window->getWindowWidth()))
    430    {
    431         //client rectangle = frame rectangle -> no change necessary
    432         return;
    433    }
    434396   pHps->isClient = TRUE;
    435 
    436    hwnd = window->getOS2WindowHandle();
    437 
    438    mapWin32ToOS2Rect(window->getWindowHeight(), window->getClientRectPtr(), (PRECTLOS2)&rcl);
    439 
    440    GetWindowRect(window->getWindowHandle(), &rectWindow);
    441    mapWin32ToOS2Rect(GetScreenHeight(), &rectWindow, (PRECTLOS2)&rectWindowOS2);
    442    dprintf2(("frame (%d,%d)(%d,%d) hps height %d", rectWindowOS2.xLeft, rectWindowOS2.yBottom, rectWindowOS2.xRight, rectWindowOS2.yTop, pHps->height));
    443 
    444    //convert to screen coordinates
    445    GreGetDCOrigin(pHps->hps, (PPOINTL)&rcltemp);
    446 
    447    if(pHps->isClientArea)
    448    {
    449         //TODO: counter
    450         dprintf2(("WARNING: selectClientArea %x; already selected! origin (%d,%d) original origin (%d,%d)", window->getWindowHandle(), rcltemp.xLeft, rcltemp.yBottom, pHps->ptlOrigin.x, pHps->ptlOrigin.y));
    451         GetWindowRect(window->getWindowHandle(), &rectWindow);
    452         mapWin32ToOS2Rect(GetScreenHeight(), &rectWindow, (PRECTLOS2)&rectWindowOS2);
    453         if(rectWindowOS2.xLeft + rcl.xLeft != rcltemp.xLeft ||
    454            rectWindowOS2.yBottom + rcl.yBottom != rcltemp.yBottom)
    455         {
    456                 dprintf2(("WARNING: origin changed (%d,%d) instead of (%d,%d)!", rcltemp.xLeft, rcltemp.yBottom, rectWindowOS2.xLeft + rcl.xLeft, rectWindowOS2.yBottom + rcl.yBottom));
    457                 rcl.xLeft   += rectWindowOS2.xLeft;
    458                 rcl.xRight  += rectWindowOS2.xLeft;
    459                 rcl.yTop    += rectWindowOS2.yBottom;
    460                 rcl.yBottom += rectWindowOS2.yBottom;
    461         }
    462         else    return;
    463    }
    464    else {
    465         rcl.xLeft   += rcltemp.xLeft;
    466         rcl.xRight  += rcltemp.xLeft;
    467         rcl.yTop    += rcltemp.yBottom;
    468         rcl.yBottom += rcltemp.yBottom;
    469 
    470         pHps->ptlOrigin.x = rcltemp.xLeft;
    471         pHps->ptlOrigin.y = rcltemp.yBottom;
    472    }
    473    dprintf2(("selectClientArea %x: (%d,%d) -> (%d,%d)", window->getWindowHandle(), rcltemp.xLeft, rcltemp.yBottom, rcl.xLeft, rcl.yBottom));
    474 
    475    if(pHps->hrgnVis == 0)
    476         pHps->hrgnVis = GreCreateRectRegion(pHps->hps, &rcl, 1);
    477 
    478    hrgnRect = GreCreateRectRegion(pHps->hps, &rcl, 1);
    479 #if 0
    480    if(window->getParent())
    481    {
    482      HRGN hrgnParentClip;
    483 
    484         pClient = window->getParent()->getClientRectPtr();
    485         GetWindowRect(window->getParent()->getWindowHandle(), &rectWindow);
    486         rectWindow.right   = rectWindow.left + pClient->right;
    487         rectWindow.left   += pClient->left;
    488         rectWindow.bottom  = rectWindow.top + pClient->bottom;
    489         rectWindow.top    += pClient->top;
    490         mapWin32ToOS2Rect(GetScreenHeight(), &rectWindow, (PRECTLOS2)&rectWindowOS2);
    491 
    492         hrgnParentClip = GreCreateRectRegion(pHps->hps, &rectWindowOS2, 1);
    493 #ifdef DEBUG
    494         dprintf(("Combining client & parent client regions"));
    495         dprintfRegion1(pHps->hps, window->getWindowHandle(), hrgnParentClip);
    496         dprintfRegion1(pHps->hps, window->getWindowHandle(), hrgnRect);
    497 #endif
    498 
    499         GreCombineRegion(pHps->hps, hrgnRect, hrgnParentClip, hrgnRect, CRGN_AND);
    500         GreDestroyRegion(pHps->hps, hrgnParentClip);
    501    }
    502 #endif
    503 
    504    // Query the visible region
    505    GreCopyClipRegion(pHps->hps, pHps->hrgnVis, 0, COPYCRGN_VISRGN);
    506    GpiQueryRegionBox(pHps->hps, pHps->hrgnVis, &rcltemp);
    507    // And the visible region of the frame with the client rectangle
    508    // to get the new visible region
    509    GreCombineRegion(pHps->hps, hrgnRect, pHps->hrgnVis, hrgnRect, CRGN_AND);
    510 #ifdef DEBUG
    511    dprintfRegion1(pHps->hps, window->getWindowHandle(), hrgnRect);
    512 #endif
    513 
    514    // Set the new origin plus visible region in the DC
    515    GreSetupDC(pHps->hps,
    516               hrgnRect,
    517               rcl.xLeft,
    518               rcl.yBottom,
    519               NULL,
    520               SETUPDC_ORIGIN | SETUPDC_VISRGN | SETUPDC_RECALCCLIP);
    521 
    522    // Destroy the region now we have finished with it.
    523    GreDestroyRegion(pHps->hps, hrgnRect);
    524 
    525397   pHps->isClientArea = TRUE;
    526 
    527    if(pClient->left == 0 && pClient->top == 0 &&
    528       window->getClientHeight() == window->getWindowHeight() &&
    529       window->getClientWidth()  == window->getWindowWidth())
    530    {
    531        //client = frame, so no changes are necessary when switching between the two
    532        pHps->isClient = FALSE;
    533        pHps->isClientArea = FALSE;
    534    }
    535    if(window->isOwnDCDirty()) {
    536        window->validateOwnDC();
    537        setPageXForm(window, pHps);
    538    }
    539 
    540 //testestest
    541 #if 0
    542    GpiQueryViewingLimits(pHps->hps, &rectWindowOS2);
    543    dprintf2(("view limits (%d,%d)(%d,%d)", rectWindowOS2.xLeft, rectWindowOS2.yBottom, rectWindowOS2.xRight, rectWindowOS2.yTop));
    544    GpiQueryDefViewingLimits(pHps->hps, &rectWindowOS2);
    545    dprintf2(("def view limits (%d,%d)(%d,%d)", rectWindowOS2.xLeft, rectWindowOS2.yBottom, rectWindowOS2.xRight, rectWindowOS2.yTop));
    546    GpiQueryPageViewport(pHps->hps, &rectWindowOS2);
    547    dprintf2(("page viewport (%d,%d)(%d,%d)", rectWindowOS2.xLeft, rectWindowOS2.yBottom, rectWindowOS2.xRight, rectWindowOS2.yTop));
    548 
    549    GpiQueryBoundaryData(pHps->hps, &rectWindowOS2);
    550    dprintf2(("boundary data (%d,%d)(%d,%d)", rectWindowOS2.xLeft, rectWindowOS2.yBottom, rectWindowOS2.xRight, rectWindowOS2.yTop));
    551 
    552    GpiQueryGraphicsField(pHps->hps, &rectWindowOS2);
    553    dprintf2(("graphics field (%d,%d)(%d,%d)", rectWindowOS2.xLeft, rectWindowOS2.yBottom, rectWindowOS2.xRight, rectWindowOS2.yTop));
    554 
    555    SIZEL size;
    556    GpiQueryPickApertureSize(pHps->hps, &size);
    557    dprintf2(("page viewport (%d,%d)", size.cx, size.cy));
    558 
    559    GpiQueryPS(pHps->hps, &size);
    560    dprintf2(("page space (%d,%d)", size.cx, size.cy));
    561 #endif
    562 //testestest
    563 
    564398}
    565399//******************************************************************************
     
    576410LONG clientHeight(Win32BaseWindow *wnd, HWND hwnd, pDCData pHps)
    577411{
    578    if ((hwnd == 0) && (pHps != 0))
    579       hwnd = pHps->hwnd;
    580 
    581    if ((hwnd != 0) || (pHps == 0))
    582    {
     412    if ((hwnd == 0) && (pHps != 0))
     413        hwnd = pHps->hwnd;
     414
     415    if ((hwnd != 0) || (pHps == 0))
     416    {
    583417        if(wnd) {
    584                 if(pHps && !pHps->isClientArea) {
    585                         return (wnd->getWindowHeight());
    586                 }
    587                 else    return (wnd->getClientHeight());
    588         }
    589         else    return OSLibQueryScreenHeight();
    590    }
    591    else if (pHps->bitmapHandle)
    592    {
    593       return pHps->bitmapHeight;
    594    }
    595    else if (pHps->isMetaPS)
    596    {
    597       return 0;
    598    }
    599    else if (pHps->isPrinter)
    600    {
    601       return pHps->printPageHeight;
    602    }
    603    else
    604    {
    605       return MEM_HPS_MAX;
    606    }
    607 }
    608 //******************************************************************************
    609 //******************************************************************************
    610 BOOL   WIN32API changePageXForm(pDCData pHps, PPOINTL pValue, int x, int y, PPOINTL pPrev)
     418            if(pHps && !pHps->isClientArea) {
     419                return (wnd->getWindowHeight());
     420            }
     421            else return (wnd->getClientHeight());
     422        }
     423        else return OSLibQueryScreenHeight();
     424    }
     425    else if (pHps->bitmapHandle)
     426    {
     427        return pHps->bitmapHeight;
     428    }
     429    else if (pHps->isMetaPS)
     430    {
     431        return 0;
     432    }
     433    else if (pHps->isPrinter)
     434    {
     435        return pHps->printPageHeight;
     436    }
     437    else
     438    {
     439        return MEM_HPS_MAX;
     440    }
     441}
     442//******************************************************************************
     443//******************************************************************************
     444BOOL WIN32API changePageXForm(pDCData pHps, PPOINTL pValue, int x, int y, PPOINTL pPrev)
    611445{
    612446 Win32BaseWindow *wnd;
    613447
    614    wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
     448   if(pHps->isClient) {
     449        wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
     450   }
     451   else wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(pHps->hwnd);
    615452   return changePageXForm(wnd, pHps, pValue, x, y, pPrev);
    616453}
    617454//******************************************************************************
    618455//******************************************************************************
    619 BOOL   WIN32API setPageXForm(pDCData pHps)
     456BOOL WIN32API setPageXForm(pDCData pHps)
    620457{
    621458 Win32BaseWindow *wnd;
    622459
    623    wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
     460   if(pHps->isClient) {
     461        wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
     462   }
     463   else wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(pHps->hwnd);
    624464   return setPageXForm(wnd, pHps);
    625465}
    626466//******************************************************************************
    627467//******************************************************************************
    628 VOID   WIN32API removeClientArea(pDCData pHps)
     468VOID WIN32API removeClientArea(pDCData pHps)
    629469{
    630470 Win32BaseWindow *wnd;
    631471
    632    wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
     472   if(pHps->isClient) {
     473        wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
     474   }
     475   else wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(pHps->hwnd);
    633476   if(wnd) {
    634477      removeClientArea(wnd, pHps);
     
    641484 Win32BaseWindow *wnd;
    642485
    643    wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
     486   if(pHps->isClient) {
     487        wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
     488   }
     489   else wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(pHps->hwnd);
    644490   if(wnd) {
    645491      selectClientArea(wnd, pHps);
     
    652498 Win32BaseWindow *wnd;
    653499
    654    wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
     500   if(pHps->isClient) {
     501        wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
     502   }
     503   else wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(pHps->hwnd);
    655504   if(wnd) {
    656       dprintfOrigin(pHps->hps);
    657505      if(pHps->isClient)
    658506          selectClientArea(wnd, pHps);
     
    661509//******************************************************************************
    662510//******************************************************************************
    663 LONG   WIN32API clientHeight(HWND hwnd, pDCData pHps)
     511LONG WIN32API clientHeight(HWND hwnd, pDCData pHps)
    664512{
    665513 Win32BaseWindow *wnd;
    666514
    667    wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
     515   if(pHps->isClient) {
     516        wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
     517   }
     518   else wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(pHps->hwnd);
    668519   return clientHeight(wnd, hwnd, pHps);
    669520}
    670521//******************************************************************************
    671522//******************************************************************************
    672 int  WIN32API setMapMode(pDCData pHps, int mode)
     523int WIN32API setMapMode(pDCData pHps, int mode)
    673524{
    674525 Win32BaseWindow *wnd;
    675526
    676    wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
     527   if(pHps->isClient) {
     528        wnd = Win32BaseWindow::GetWindowFromOS2Handle(pHps->hwnd);
     529   }
     530   else wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(pHps->hwnd);
    677531   return setMapMode(wnd, pHps, mode);
    678532}
     
    790644 RECTL    rectlClip;
    791645
    792    if(lpps == NULL) {
     646    if(lpps == NULL) {
    793647        //BeginPaint does NOT change last error in this case
    794648        //(verified in NT4, SP6)
    795649        dprintf (("USER32: BeginPaint %x NULL PAINTSTRUCT pointer", hWnd));
    796650        return 0;
    797    }
    798    memset(lpps, 0, sizeof(*lpps));
    799 
    800    Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
    801    if(!wnd) {
     651    }
     652    memset(lpps, 0, sizeof(*lpps));
     653
     654    Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
     655    if(!wnd) {
    802656        dprintf (("USER32: BeginPaint %x %x: invalid window handle!!", hWnd, lpps));
    803657        SetLastError(ERROR_INVALID_WINDOW_HANDLE_W); //(verified in NT4, SP6)
    804658        return (HDC)0;
    805    }
    806    HWND hwndClient = wnd->getOS2WindowHandle();
    807 
    808    if(hwnd != HWND_DESKTOP && wnd->isOwnDC())
    809    {
     659    }
     660    HWND hwndClient = wnd->getOS2WindowHandle();
     661
     662    if(hwnd != HWND_DESKTOP && wnd->isOwnDC())
     663    {
    810664        hPS_ownDC = wnd->getOwnDC();
    811665        //SvL: Hack for memory.exe (doesn't get repainted properly otherwise)
    812666        if(hPS_ownDC) {
    813                 pHps = (pDCData)GpiQueryDCData(hPS_ownDC);
    814                 if (!pHps)
    815                 {
    816                         dprintf (("USER32: BeginPaint %x invalid parameter %x", hWnd, lpps));
    817                         SetLastError(ERROR_INVALID_PARAMETER_W);
    818                         return (HDC)NULLHANDLE;
    819                 }
    820                 hpsPaint = hPS_ownDC;
    821         }
    822    }
    823    if(!hpsPaint) {
    824         hpsPaint = GetDCEx(hwnd, 0, (DCX_CACHE_W|DCX_WINDOW_W|DCX_USESTYLE_W));
     667            pHps = (pDCData)GpiQueryDCData(hPS_ownDC);
     668            if (!pHps)
     669            {
     670                dprintf (("USER32: BeginPaint %x invalid parameter %x", hWnd, lpps));
     671                SetLastError(ERROR_INVALID_PARAMETER_W);
     672                return (HDC)NULLHANDLE;
     673            }
     674            hpsPaint = hPS_ownDC;
     675        }
     676    }
     677    if(!hpsPaint) {
     678        hpsPaint = GetDCEx(hwnd, 0, (DCX_CACHE_W|DCX_USESTYLE_W));
    825679        pHps = (pDCData)GpiQueryDCData(hpsPaint);
    826680        if (!pHps)
    827681        {
    828                 dprintf (("USER32: BeginPaint %x invalid parameter %x", hWnd, lpps));
    829                 SetLastError(ERROR_INVALID_PARAMETER_W);
    830                 return (HDC)NULLHANDLE;
    831         }
    832    }
    833 
    834    if(WinQueryUpdateRect(hwndClient, &rectl) == FALSE) {
     682            dprintf (("USER32: BeginPaint %x invalid parameter %x", hWnd, lpps));
     683            SetLastError(ERROR_INVALID_PARAMETER_W);
     684            return (HDC)NULLHANDLE;
     685        }
     686    }
     687
     688    if(WinQueryUpdateRect(hwndClient, &rectl) == FALSE)
     689    {
    835690        memset(&rectl, 0, sizeof(rectl));
    836691        dprintf (("USER32: WARNING: WinQueryUpdateRect failed (error or no update rectangle)!!"));
     
    844699        wnd->SetClipRegion(hrgnOldClip);
    845700        lComplexity = RGN_NULL;
    846    }
    847    else {
     701    }
     702    else {
    848703        rectlClip.yBottom = rectlClip.xLeft = 0;
    849704        rectlClip.yTop = rectlClip.xRight = 1;
     
    854709        WinValidateRegion(hwndClient, hrgnClip, FALSE);
    855710
    856         mapWin32ToOS2Rect(wnd->getWindowHeight(), wnd->getClientRectPtr(), (PRECTLOS2)&rectlClient);
    857         WinIntersectRect(NULL, &rectlClip, &rectl, &rectlClient);
    858         WinOffsetRect(NULL, &rectlClip, -rectlClient.xLeft, -rectlClient.yBottom);
    859 
    860         //clip update region with client window rectangle
    861         HRGN hrgnClient = GpiCreateRegion(pHps->hps, 1, &rectlClient);
    862         GpiCombineRegion(pHps->hps, hrgnClip, hrgnClip, hrgnClient, CRGN_AND);
    863         GpiDestroyRegion(pHps->hps, hrgnClient);
    864 
    865         //change origin of clip region (window -> client)
    866         POINTL point = {-rectlClient.xLeft, -rectlClient.yBottom};
    867         GpiOffsetRegion(pHps->hps, hrgnClip, &point);
     711        dprintfRegion(pHps->hps, wnd->getWindowHandle(), hrgnClip);
     712
    868713#ifdef DEBUG
    869         dprintfRegion1(pHps->hps, hWnd, hrgnClip);
     714        lComplexity = GpiQueryClipBox(pHps->hps, &rectlClip);
     715        dprintf(("ClipBox (%d): (%d,%d)(%d,%d)", lComplexity, rectlClip.xLeft, rectlClip.yBottom, rectlClip.xRight, rectlClip.yTop));
    870716#endif
     717
    871718        //set clip region
    872719        lComplexity = GpiSetClipRegion(pHps->hps, hrgnClip, &hrgnOldClip);
    873720
    874         //change presentation space for client window
    875         //NOTE: MUST do this after GpiSetClipRegion call!
    876         //      When a window with CS_OWNDC looses focus, for some reason
    877         //      GpiSetClipRegion resets the window dc origin back to (0,0)
     721        if(lComplexity == RGN_NULL) {
     722            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())));
     723        }
    878724        selectClientArea(wnd, pHps);
    879725
    880         GpiQueryClipBox(pHps->hps, &rectl);
    881         dprintf(("ClipBox (%d): (%d,%d)(%d,%d)", lComplexity, rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop));
    882 
     726#ifdef DEBUG
     727        GpiQueryClipBox(pHps->hps, &rectlClip);
     728        dprintf(("ClipBox (%d): (%d,%d)(%d,%d)", lComplexity, rectlClip.xLeft, rectlClip.yBottom, rectlClip.xRight, rectlClip.yTop));
     729#endif
    883730        //save old clip region (restored for CS_OWNDC windows in EndPaint)
    884731        wnd->SetClipRegion(hrgnOldClip);
    885         memcpy(&rectl, &rectlClip, sizeof(RECTL));
    886         lComplexity = RGN_RECT;
    887    }
    888 
    889    if(hPS_ownDC == 0)
    890       setMapMode (wnd, pHps, MM_TEXT_W);
    891    else
    892       setPageXForm(wnd, pHps);
    893 
    894    pHps->hdcType = TYPE_3;
    895 
    896    HideCaret(hwnd);
    897    WinShowTrackRect(wnd->getOS2WindowHandle(), FALSE);
    898 
    899    if(wnd->needsEraseBkgnd() && lComplexity != RGN_NULL) {
     732    }
     733
     734    if(hPS_ownDC == 0)
     735        setMapMode (wnd, pHps, MM_TEXT_W);
     736    else
     737        setPageXForm(wnd, pHps);
     738
     739    pHps->hdcType = TYPE_3;
     740
     741    HideCaret(hwnd);
     742    WinShowTrackRect(wnd->getOS2WindowHandle(), FALSE);
     743
     744    if((wnd->needsEraseBkgnd() || wnd->IsVisibleRegionChanged()) && lComplexity != RGN_NULL) {
    900745        wnd->setEraseBkgnd(FALSE);
     746        wnd->SetVisibleRegionChanged(FALSE);
    901747        lpps->fErase = (wnd->MsgEraseBackGround(pHps->hps) == 0);
    902    }
    903    else lpps->fErase = TRUE;
    904 
    905    dprintfOrigin(pHps->hps);
    906 
    907    lpps->hdc    = (HDC)pHps->hps;
    908 
    909    if(lComplexity != RGN_NULL) {
     748    }
     749    else lpps->fErase = TRUE;
     750
     751    lpps->hdc    = (HDC)pHps->hps;
     752
     753    if(lComplexity != RGN_NULL) {
    910754        long height  = wnd->getClientHeight();
    911755        lpps->rcPaint.top    = height - rectl.yTop;
     
    913757        lpps->rcPaint.bottom = height - rectl.yBottom;
    914758        lpps->rcPaint.right  = rectl.xRight;
    915    }
    916    else {
     759    }
     760    else {
    917761        lpps->rcPaint.bottom = lpps->rcPaint.top = 0;
    918762        lpps->rcPaint.right = lpps->rcPaint.left = 0;
    919    }
    920 
    921    SetLastError(0);
    922    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));
    923    return (HDC)pHps->hps;
     763    }
     764
     765    SetLastError(0);
     766    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));
     767    return (HDC)pHps->hps;
    924768}
    925769//******************************************************************************
     
    931775  pDCData pHps;
    932776
    933    dprintf (("USER32: EndPaint(%x)", hwnd));
    934 
    935    if (!pPaint || !pPaint->hdc )
    936       return TRUE;
    937 
    938    Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
    939 
    940    if (!wnd) goto exit;
    941 
    942    pHps = (pDCData)GpiQueryDCData((HPS)pPaint->hdc);
    943    if (pHps && (pHps->hdcType == TYPE_3))
    944    {
    945         dprintfOrigin(pHps->hps);
    946 
     777    dprintf (("USER32: EndPaint(%x)", hwnd));
     778
     779    if (!pPaint || !pPaint->hdc )
     780        return TRUE;
     781
     782    Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
     783
     784    if (!wnd) goto exit;
     785
     786    pHps = (pDCData)GpiQueryDCData((HPS)pPaint->hdc);
     787    if (pHps && (pHps->hdcType == TYPE_3))
     788    {
    947789        GpiSetClipRegion(pHps->hps, wnd->GetClipRegion(), &hrgnOld);
    948790        wnd->SetClipRegion(0);
    949791        if(hrgnOld) {
    950                 GpiDestroyRegion(pHps->hps, hrgnOld);
     792            GpiDestroyRegion(pHps->hps, hrgnOld);
    951793        }
    952794        pHps->hdcType = TYPE_1; //otherwise Open32's ReleaseDC fails
    953795        ReleaseDC(hwnd, pPaint->hdc);
    954    }
    955    else {
     796    }
     797    else {
    956798        dprintf(("EndPaint: wrong hdc %x!!", pPaint->hdc));
    957    }
    958    wnd->setEraseBkgnd(TRUE);
    959    ShowCaret(hwnd);
    960    WinShowTrackRect(wnd->getOS2WindowHandle(), TRUE);
     799    }
     800    wnd->setEraseBkgnd(TRUE);
     801    ShowCaret(hwnd);
     802    WinShowTrackRect(wnd->getOS2WindowHandle(), TRUE);
    961803
    962804exit:
    963    SetLastError(0);
    964    return TRUE;
     805    SetLastError(0);
     806    return TRUE;
    965807}
    966808//******************************************************************************
     
    971813   int rc;
    972814
    973    if (hwnd)
    974    {
     815    if (hwnd)
     816    {
    975817        Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
    976818        if(wnd == NULL) {
    977                 dprintf(("ERROR: ReleaseDC %x %x failed", hwnd, hdc));
    978                 return 0;
     819            dprintf(("ERROR: ReleaseDC %x %x failed", hwnd, hdc));
     820            return 0;
    979821        }
    980822        isOwnDC = wnd->isOwnDC() && (wnd->getOwnDC() == hdc);
    981823        if(!isOwnDC)
    982824        {
    983                 pDCData  pHps = (pDCData)GpiQueryDCData((HPS)hdc);
    984                 if(pHps && pHps->psType == MICRO_CACHED) {
    985                         removeClientArea(wnd, pHps);
    986                         if(pHps->hrgnVis) {
    987                                 GreDestroyRegion(pHps->hps, pHps->hrgnVis);
    988                                 pHps->hrgnVis = 0;
    989                         }
     825            pDCData  pHps = (pDCData)GpiQueryDCData((HPS)hdc);
     826            if(pHps && pHps->psType == MICRO_CACHED) {
     827                removeClientArea(wnd, pHps);
     828                if(pHps->hrgnVis) {
     829                    GreDestroyRegion(pHps->hps, pHps->hrgnVis);
     830                    pHps->hrgnVis = 0;
    990831                }
    991                 else {
    992                         dprintf(("ERROR: ReleaseDC: pHps == NULL!!"));
    993                         DebugInt3();
    994                 }
     832            }
     833            else {
     834                dprintf(("ERROR: ReleaseDC: pHps == NULL!!"));
     835                DebugInt3();
     836            }
    995837        }
    996838        else {
    997                 dprintf2(("ReleaseDC: CS_OWNDC, not released"));
    998         }
    999    }
    1000 
    1001    if(isOwnDC) {
     839            dprintf2(("ReleaseDC: CS_OWNDC, not released"));
     840        }
     841    }
     842
     843    if(isOwnDC) {
    1002844        rc = TRUE;
    1003    }
    1004    else {
     845    }
     846    else {
    1005847        UnselectGDIObjects(hdc);
    1006848        rc = O32_ReleaseDC (0, hdc);
    1007    }
    1008 
    1009    dprintf(("ReleaseDC %x %x", hwnd, hdc));
    1010    return (rc);
     849    }
     850
     851    dprintf(("ReleaseDC %x %x", hwnd, hdc));
     852    return (rc);
    1011853}
    1012854//******************************************************************************
     
    1035877   PS_Type  psType;
    1036878
    1037    if(hwnd == 0) {
     879    if(hwnd == 0) {
    1038880        dprintf(("error: GetDCEx window %x not found", hwnd));
    1039881        SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
    1040882        return 0;
    1041    }
    1042 
    1043    if (hwnd)
    1044    {
     883    }
     884
     885    if(hwnd)
     886    {
    1045887        wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
    1046888        if(wnd == NULL) {
     
    1049891                return 0;
    1050892        }
    1051         hWindow = wnd->getOS2WindowHandle();
    1052    }
    1053 
    1054    isWindowOwnDC = (((hWindow == HWND_DESKTOP) ? FALSE : (wnd->isOwnDC()))
    1055                  && !(flags & (DCX_CACHE_W|DCX_WINDOW_W)));
    1056 
    1057    if(isWindowOwnDC) //own dc always for client area
    1058    {
    1059       hps = wnd->getOwnDC();
    1060       if (hps)
    1061       {
    1062         pDCData pHps = (pDCData)GpiQueryDCData (hps);
    1063         if (!pHps)
    1064             goto error;
    1065 
    1066         selectClientArea(wnd, pHps);
    1067 
    1068         //TODO: Is this always necessary??
    1069         setPageXForm (wnd, pHps);
    1070         pHps->hdcType = TYPE_1;
    1071 
    1072         //TODO: intersect/exclude clip region?
    1073         dprintf (("User32: GetDCEx hwnd %x (%x %x) -> wnd %x hdc %x", hwnd, hrgn, flags, wnd, hps));
    1074         return (HDC)hps;
    1075       }
    1076       else
    1077         creatingOwnDC = TRUE;
    1078    }
    1079 
    1080    if(isWindowOwnDC)
    1081    {
    1082       SIZEL sizel = {0,0};
    1083       hps = GpiCreatePS (WinQueryAnchorBlock (hWindow),
    1084                          WinOpenWindowDC (hWindow),
    1085                          &sizel, PU_PELS | GPIT_MICRO | GPIA_ASSOC );
    1086       psType = MICRO;
    1087       // default cp is OS/2 one: set to windows default (ODIN.INI)
    1088       GpiSetCp(hps, GetDisplayCodepage());
    1089    }
    1090    else
    1091    {
    1092       if (hWindow == HWND_DESKTOP) {
    1093          hps = WinGetScreenPS (hWindow);
    1094       }
    1095       else {
    1096         int clipstyle = 0;
    1097         int clipwnd   = HWND_TOP;
    1098         if(flags & (DCX_USESTYLE_W)) {
     893        if(flags & DCX_WINDOW_W) {
     894             hWindow = wnd->getOS2FrameWindowHandle();
     895        }
     896        else hWindow = wnd->getOS2WindowHandle();
     897    }
     898
     899    isWindowOwnDC = (((hWindow == HWND_DESKTOP) ? FALSE : (wnd->isOwnDC()))
     900                    && !(flags & (DCX_CACHE_W|DCX_WINDOW_W)));
     901
     902    if(isWindowOwnDC) //own dc always for client area
     903    {
     904        hps = wnd->getOwnDC();
     905        if (hps)
     906        {
     907            pDCData pHps = (pDCData)GpiQueryDCData (hps);
     908            if (!pHps)
     909                goto error;
     910
     911            selectClientArea(wnd, pHps);
     912
     913            //TODO: Is this always necessary??
     914            setPageXForm (wnd, pHps);
     915            pHps->hdcType = TYPE_1;
     916
     917            //TODO: intersect/exclude clip region?
     918            dprintf (("User32: GetDCEx hwnd %x (%x %x) -> wnd %x hdc %x", hwnd, hrgn, flags, wnd, hps));
     919            return (HDC)hps;
     920        }
     921        else creatingOwnDC = TRUE;
     922    }
     923
     924    if(isWindowOwnDC)
     925    {
     926        SIZEL sizel = {0,0};
     927        hps = GpiCreatePS (WinQueryAnchorBlock (hWindow),
     928                           WinOpenWindowDC (hWindow),
     929                           &sizel, PU_PELS | GPIT_MICRO | GPIA_ASSOC );
     930        psType = MICRO;
     931        // default cp is OS/2 one: set to windows default (ODIN.INI)
     932        GpiSetCp(hps, GetDisplayCodepage());
     933    }
     934    else
     935    {
     936        if (hWindow == HWND_DESKTOP) {
     937            hps = WinGetScreenPS (hWindow);
     938        }
     939        else {
     940            int clipstyle = 0;
     941            int clipwnd   = HWND_TOP;
     942            if(flags & (DCX_USESTYLE_W)) {
    1099943                int style = wnd->getStyle();
    1100944                if(style & WS_CLIPCHILDREN_W) {
    1101                         clipstyle |= PSF_CLIPCHILDREN;
     945                    clipstyle |= PSF_CLIPCHILDREN;
    1102946                }
    1103947                if(style & WS_CLIPSIBLINGS_W) {
    1104                         clipstyle |= PSF_CLIPSIBLINGS;
     948                    clipstyle |= PSF_CLIPSIBLINGS;
    1105949                }
    1106950                if(wnd->fHasParentDC()) {
    1107                         clipstyle |= PSF_PARENTCLIP;
     951                    clipstyle |= PSF_PARENTCLIP;
    1108952                }
    1109         }
    1110         if(flags & DCX_CLIPSIBLINGS_W) {
     953            }
     954            if(flags & DCX_CLIPSIBLINGS_W) {
    1111955                clipstyle |= PSF_CLIPSIBLINGS;
    1112         }
    1113         if(flags & DCX_CLIPCHILDREN_W) {
     956            }
     957            if(flags & DCX_CLIPCHILDREN_W) {
    1114958                clipstyle |= PSF_CLIPCHILDREN;
    1115         }
    1116         if(flags & DCX_PARENTCLIP_W) {
     959            }
     960            if(flags & DCX_PARENTCLIP_W) {
    1117961                clipstyle |= PSF_PARENTCLIP;
    1118         }
    1119         if(clipstyle) {
    1120                 dprintf2(("WinGetClipPS style %x", clipstyle));
    1121                 hps = WinGetClipPS(hWindow, clipwnd, clipstyle);
    1122         }
    1123         else    hps = WinGetPS (hWindow);
    1124 
    1125         // default cp is OS/2 one: set to windows default (ODIN.INI)
    1126         GpiSetCp(hps, GetDisplayCodepage());
    1127       }
    1128       psType = MICRO_CACHED;
    1129    }
    1130 
    1131    if (!hps)
    1132       goto error;
    1133 
    1134    HPSToHDC (hWindow, hps, NULL, NULL);
    1135    pHps = (pDCData)GpiQueryDCData (hps);
    1136 
    1137    if(!(flags & DCX_WINDOW_W))
    1138    {
    1139         selectClientArea(wnd, pHps);
    1140    }
    1141    else removeClientArea(wnd, pHps);
    1142 
    1143    setMapMode(wnd, pHps, MM_TEXT_W);
    1144 
    1145    if ((flags & DCX_EXCLUDERGN_W) || (flags & DCX_INTERSECTRGN_W))
    1146    {
    1147       ULONG BytesNeeded;
    1148       PRGNDATA RgnData;
    1149       PRECT pr;
    1150       int i;
    1151       RECTL rectl;
    1152 
    1153       if (!hrgn)
    1154          goto error;
    1155 
    1156       success = TRUE;
    1157       if (flags & DCX_EXCLUDERGN_W)
    1158       {
     962            }
     963            if(clipstyle) {
     964                 dprintf2(("WinGetClipPS style %x", clipstyle));
     965                 hps = WinGetClipPS(hWindow, clipwnd, clipstyle);
     966            }
     967            else hps = WinGetPS (hWindow);
     968
     969            // default cp is OS/2 one: set to windows default (ODIN.INI)
     970            GpiSetCp(hps, GetDisplayCodepage());
     971        }
     972        psType = MICRO_CACHED;
     973    }
     974
     975    if (!hps)
     976        goto error;
     977
     978    HPSToHDC (hWindow, hps, NULL, NULL);
     979    pHps = (pDCData)GpiQueryDCData (hps);
     980
     981    if(flags & DCX_WINDOW_W) {
     982         removeClientArea(wnd, pHps);
     983    }
     984    else selectClientArea(wnd, pHps);
     985
     986    setMapMode(wnd, pHps, MM_TEXT_W);
     987
     988    if ((flags & DCX_EXCLUDERGN_W) || (flags & DCX_INTERSECTRGN_W))
     989    {
     990        ULONG BytesNeeded;
     991        PRGNDATA RgnData;
     992        PRECT pr;
     993        int i;
     994        RECTL rectl;
     995
     996        if (!hrgn)
     997            goto error;
     998
     999        success = TRUE;
     1000        if (flags & DCX_EXCLUDERGN_W)
     1001        {
    11591002#if 0 //CB: todo
    11601003         long height;
     
    11811024         }
    11821025#endif
    1183       }
    1184       else //DCX_INTERSECTRGN_W
    1185       {
    1186          //SvL: I'm getting paint problems when clipping a dc created in GetDCEx
    1187          //     with a region that covers the entire window (RealPlayer 7 Update 1)
    1188          //     Using SelectClipRgn here doesn't make any difference.
    1189          if(ExtSelectClipRgn(pHps->hps, hrgn, RGN_AND_W) == ERROR_W) {
     1026        }
     1027        else //DCX_INTERSECTRGN_W
     1028        {
     1029            //SvL: I'm getting paint problems when clipping a dc created in GetDCEx
     1030            //     with a region that covers the entire window (RealPlayer 7 Update 1)
     1031            //     Using SelectClipRgn here doesn't make any difference.
     1032            if(ExtSelectClipRgn(pHps->hps, hrgn, RGN_AND_W) == ERROR_W) {
    11901033                dprintf(("ExtSelectClipRgn failed!!"));
    1191          }
    1192       }
    1193       if (!success)
    1194          goto error;
    1195    }
    1196 
    1197    if (creatingOwnDC)
    1198       wnd->setOwnDC ((HDC)hps);
    1199 
    1200    pHps->psType  = psType;
    1201    pHps->hdcType = TYPE_1;
    1202    //TODO: WM_SETREDRAW affects drawingAllowed flag!!
    1203    GpiSetDrawControl (hps, DCTL_DISPLAY, drawingAllowed ? DCTL_ON : DCTL_OFF);
    1204 
    1205    dprintf (("User32: GetDCEx hwnd %x (%x %x) -> hdc %x", hwnd, hrgn, flags, pHps->hps));
    1206    return (HDC)pHps->hps;
     1034            }
     1035        }
     1036        if (!success)
     1037            goto error;
     1038    }
     1039
     1040    if (creatingOwnDC)
     1041        wnd->setOwnDC ((HDC)hps);
     1042
     1043    pHps->psType  = psType;
     1044    pHps->hdcType = TYPE_1;
     1045    //TODO: WM_SETREDRAW affects drawingAllowed flag!!
     1046    GpiSetDrawControl (hps, DCTL_DISPLAY, drawingAllowed ? DCTL_ON : DCTL_OFF);
     1047
     1048    dprintf (("User32: GetDCEx hwnd %x (%x %x) -> hdc %x", hwnd, hrgn, flags, pHps->hps));
     1049    return (HDC)pHps->hps;
    12071050
    12081051error:
    1209    /* Something went wrong; clean up
    1210     */
    1211    dprintf(("ERROR: GetDCEx hwnd %x (%x %x) FAILED!", hwnd, hrgn, flags));
    1212    DebugInt3();
    1213    if (pHps)
    1214    {
    1215       if (pHps->hps)
    1216       {
    1217          if(pHps->psType == MICRO_CACHED)
    1218             WinReleasePS(pHps->hps);
    1219          else
    1220             GpiDestroyPS(pHps->hps);
    1221       }
    1222 
    1223       if (pHps->hdc)     DevCloseDC(pHps->hdc);
    1224       if (pHps->hrgnHDC) GpiDestroyRegion(pHps->hps, pHps->hrgnHDC);
    1225 
    1226       O32_DeleteObject (pHps->nullBitmapHandle);
    1227    }
    1228    SetLastError(ERROR_INVALID_PARAMETER_W);
    1229    return NULL;
     1052    /* Something went wrong; clean up
     1053     */
     1054    dprintf(("ERROR: GetDCEx hwnd %x (%x %x) FAILED!", hwnd, hrgn, flags));
     1055    DebugInt3();
     1056    if (pHps)
     1057    {
     1058        if (pHps->hps)
     1059        {
     1060            if(pHps->psType == MICRO_CACHED)
     1061                WinReleasePS(pHps->hps);
     1062            else
     1063                GpiDestroyPS(pHps->hps);
     1064        }
     1065
     1066        if (pHps->hdc)     DevCloseDC(pHps->hdc);
     1067        if (pHps->hrgnHDC) GpiDestroyRegion(pHps->hps, pHps->hrgnHDC);
     1068
     1069        O32_DeleteObject (pHps->nullBitmapHandle);
     1070    }
     1071    SetLastError(ERROR_INVALID_PARAMETER_W);
     1072    return NULL;
    12301073}
    12311074//******************************************************************************
     
    12331076HDC WIN32API GetDC (HWND hwnd)
    12341077{
    1235   if(!hwnd)
    1236        return GetDCEx( GetDesktopWindow(), 0, DCX_CACHE_W | DCX_WINDOW_W );
    1237   return GetDCEx (hwnd, NULL, 0);
     1078    if(!hwnd)
     1079        return GetDCEx( GetDesktopWindow(), 0, DCX_CACHE_W | DCX_WINDOW_W );
     1080
     1081    return GetDCEx (hwnd, NULL, 0);
    12381082}
    12391083//******************************************************************************
     
    12411085HDC WIN32API GetWindowDC (HWND hwnd)
    12421086{
    1243   if (!hwnd) hwnd = GetDesktopWindow();
    1244   return GetDCEx (hwnd, NULL, DCX_WINDOW_W);
     1087    if (!hwnd) hwnd = GetDesktopWindow();
     1088    return GetDCEx (hwnd, NULL, DCX_WINDOW_W);
    12451089}
    12461090//******************************************************************************
     
    12491093LRESULT WIN32API RedrawChildEnumProc(HWND hwnd, LPARAM lParam)
    12501094{
    1251   RedrawWindow(hwnd, NULL, 0, lParam);
    1252   return TRUE;
     1095    RedrawWindow(hwnd, NULL, 0, lParam);
     1096    return TRUE;
    12531097}
    12541098//******************************************************************************
     
    12651109//
    12661110//TODO: Works ok for RDW_FRAME??
     1111//      SDK docs say RDW_FRAME is only valid for RDW_INVALIDATE...
    12671112//******************************************************************************
    12681113BOOL WIN32API RedrawWindow(HWND hwnd, const RECT* pRect, HRGN hrgn, DWORD redraw)
    12691114{
    1270    Win32BaseWindow *wnd;
    1271 
    1272    if(pRect) {
    1273           dprintf(("RedrawWindow %x (%d,%d)(%d,%d) %x %x", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom, hrgn, redraw));
    1274    }
    1275    else  dprintf(("RedrawWindow %x %x %x %x", hwnd, pRect, hrgn, redraw));
    1276 
    1277    if (hwnd == NULLHANDLE)
    1278    {
     1115    Win32BaseWindow *wnd;
     1116
     1117    if(pRect) {
     1118         dprintf(("RedrawWindow %x (%d,%d)(%d,%d) %x %x", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom, hrgn, redraw));
     1119    }
     1120    else dprintf(("RedrawWindow %x %x %x %x", hwnd, pRect, hrgn, redraw));
     1121
     1122    if (hwnd == NULLHANDLE)
     1123    {
    12791124#if 1
    12801125        // Don't do this for now (causes lots of desktop repaints in WordPad)
    1281          SetLastError(ERROR_INVALID_PARAMETER_W);
    1282          return FALSE;
     1126        SetLastError(ERROR_INVALID_PARAMETER_W);
     1127        return FALSE;
    12831128#else
    12841129        hwnd = HWND_DESKTOP;
     
    12931138        }
    12941139#endif
    1295    }
    1296    else
    1297    {
     1140    }
     1141    else
     1142    {
    12981143        wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
    12991144
     
    13051150            return FALSE;
    13061151        }
    1307         hwnd = wnd->getOS2WindowHandle();
    1308    }
    1309 
    1310    BOOL  IncludeChildren = (redraw & RDW_ALLCHILDREN_W) ? TRUE : FALSE;
    1311    BOOL  success = TRUE;
    1312    HPS   hpsTemp = NULLHANDLE;
    1313    HRGN  hrgnTemp = NULLHANDLE;
    1314    RECTL rectl;
    1315 
    1316    if (hrgn)
    1317    {
    1318       ULONG BytesNeeded;
    1319       PRGNDATA RgnData;
    1320       PRECTL pr;
    1321       int i;
    1322       LONG height;
    1323 
    1324       if(wnd) {
    1325                 height = (redraw & RDW_FRAME_W) ? wnd->getWindowHeight() : wnd->getClientHeight();
    1326       }
    1327       else      height = OSLibQueryScreenHeight();
    1328 
    1329       if (!hrgn)
    1330          goto error;
    1331 
    1332       BytesNeeded = GetRegionData (hrgn, 0, NULL);
    1333       RgnData = (PRGNDATA)_alloca (BytesNeeded);
    1334       if (RgnData == NULL)
     1152        if(redraw & RDW_FRAME_W) {
     1153             hwnd = wnd->getOS2FrameWindowHandle();
     1154        }
     1155        else hwnd = wnd->getOS2WindowHandle();
     1156    }
     1157
     1158    BOOL  IncludeChildren = (redraw & RDW_ALLCHILDREN_W) ? TRUE : FALSE;
     1159    BOOL  success = TRUE;
     1160    HPS   hpsTemp = NULLHANDLE;
     1161    HRGN  hrgnTemp = NULLHANDLE;
     1162    RECTL rectl;
     1163
     1164    if (hrgn)
     1165    {
     1166        ULONG BytesNeeded;
     1167        PRGNDATA RgnData;
     1168        PRECTL pr;
     1169        int i;
     1170        LONG height;
     1171
     1172        if(wnd) {
     1173             height = (redraw & RDW_FRAME_W) ? wnd->getWindowHeight() : wnd->getClientHeight();
     1174        }
     1175        else height = OSLibQueryScreenHeight();
     1176
     1177        if (!hrgn)
     1178            goto error;
     1179
     1180        BytesNeeded = GetRegionData (hrgn, 0, NULL);
     1181        RgnData = (PRGNDATA)_alloca (BytesNeeded);
     1182        if (RgnData == NULL)
    13351183          goto error;
    1336       GetRegionData (hrgn, BytesNeeded, RgnData);
    1337 
    1338       pr = (PRECTL)(RgnData->Buffer);
    1339       for (i = RgnData->rdh.nCount; i > 0; i--, pr++) {
    1340          LONG temp = pr->yTop;
    1341          pr->yTop = height - pr->yBottom;
    1342          pr->yBottom = height - temp;
    1343          dprintf2(("RedrawWindow: region (%d,%d) (%d,%d)", pr->xLeft, pr->yBottom, pr->xRight, pr->yTop));
    1344       }
    1345 
    1346       hpsTemp = WinGetScreenPS (HWND_DESKTOP);
    1347       hrgnTemp = GpiCreateRegion (hpsTemp, RgnData->rdh.nCount, (PRECTL)(RgnData->Buffer));
    1348       if (!hrgnTemp) goto error;
    1349    }
    1350    else if (pRect)
    1351    {
    1352       if(wnd) {
    1353                 if(redraw & RDW_FRAME_W) {
    1354                         mapWin32ToOS2Rect(wnd->getWindowHeight(), (PRECT)pRect, (PRECTLOS2)&rectl);
    1355                 }
    1356                 else    mapWin32ToOS2RectClientToFrame(wnd, (PRECT)pRect, (PRECTLOS2)&rectl);
    1357       }
    1358       else      mapWin32ToOS2Rect(OSLibQueryScreenHeight(), (PRECT)pRect, (PRECTLOS2)&rectl);
    1359    }
    1360 
    1361    if (redraw & RDW_INVALIDATE_W)
    1362    {
     1184        GetRegionData (hrgn, BytesNeeded, RgnData);
     1185
     1186        pr = (PRECTL)(RgnData->Buffer);
     1187        for (i = RgnData->rdh.nCount; i > 0; i--, pr++) {
     1188            LONG temp = pr->yTop;
     1189            pr->yTop = height - pr->yBottom;
     1190            pr->yBottom = height - temp;
     1191            dprintf2(("RedrawWindow: region (%d,%d) (%d,%d)", pr->xLeft, pr->yBottom, pr->xRight, pr->yTop));
     1192        }
     1193
     1194        hpsTemp = WinGetScreenPS (HWND_DESKTOP);
     1195        hrgnTemp = GpiCreateRegion (hpsTemp, RgnData->rdh.nCount, (PRECTL)(RgnData->Buffer));
     1196        if (!hrgnTemp) goto error;
     1197    }
     1198    else if (pRect)
     1199    {
     1200        if(wnd) {
     1201            if(redraw & RDW_FRAME_W) {
     1202                 mapWin32ToOS2Rect(wnd->getWindowHeight(), (PRECT)pRect, (PRECTLOS2)&rectl);
     1203            }
     1204            else mapWin32ToOS2Rect(wnd->getClientHeight(), (PRECT)pRect, (PRECTLOS2)&rectl);
     1205        }
     1206        else mapWin32ToOS2Rect(OSLibQueryScreenHeight(), (PRECT)pRect, (PRECTLOS2)&rectl);
     1207    }
     1208
     1209    if (redraw & RDW_INVALIDATE_W)
     1210    {
    13631211        //TODO: SvL: pingpong.exe doesn't have RDW_NOERASE, but doesn't want WM_ERASEBKGND msgs
    13641212        if (redraw & RDW_ERASE_W) {
    13651213             wnd->setEraseBkgnd(TRUE);
    13661214        }
    1367         else
    1368         if (redraw & RDW_NOERASE_W)
    1369             wnd->setEraseBkgnd(FALSE);
     1215        else wnd->setEraseBkgnd(FALSE);
    13701216
    13711217        if (!pRect && !hrgn)
     
    14031249
    14041250        if (!success) goto error;
    1405    }
    1406    else if (redraw & RDW_VALIDATE_W)
    1407    {
     1251    }
     1252    else if (redraw & RDW_VALIDATE_W)
     1253    {
    14081254        if (redraw & RDW_NOERASE_W)
    14091255            wnd->setEraseBkgnd(FALSE);
     
    14231269            if(!success) goto error;
    14241270        }
    1425    }
    1426 
    1427    if(WinQueryUpdateRect(hwnd, NULL))
    1428    {
     1271    }
     1272
     1273    if(WinQueryUpdateRect(hwnd, &rectl))
     1274    {
    14291275        //TODO: Does this work if RDW_ALLCHILDREN is set??
    14301276        if(redraw & RDW_UPDATENOW_W) {
    1431                 wnd->MsgNCPaint();
    1432                 wnd->MsgPaint(0, FALSE);
     1277            RECT rectUpdate;
     1278
     1279            if(redraw & RDW_FRAME_W) {
     1280                mapOS2ToWin32Rect(wnd->getWindowHeight(), (PRECTLOS2)&rectl, &rectUpdate);
     1281                wnd->MsgNCPaint(&rectUpdate);
     1282            }
     1283
     1284            wnd->MsgPaint(0, FALSE);
    14331285        }
    14341286        else
    14351287//        if((redraw & RDW_ERASE_W) && (redraw & RDW_ERASENOW_W))
    14361288        if(redraw & RDW_ERASENOW_W && wnd->needsEraseBkgnd())
    1437                 wnd->setEraseBkgnd(sendEraseBkgnd(wnd) == 0);
     1289            wnd->setEraseBkgnd(sendEraseBkgnd(wnd) == 0);
    14381290//      if(redraw & RDW_ALLCHILDREN_W) {
    14391291//              EnumChildWindows(wnd->getWindowHandle(), RedrawChildEnumProc, redraw);
    14401292//      }
    1441    }
    1442    else if((redraw & RDW_INTERNALPAINT_W) && !(redraw & RDW_INVALIDATE_W))
    1443    {
     1293    }
     1294    else if((redraw & RDW_INTERNALPAINT_W) && !(redraw & RDW_INVALIDATE_W))
     1295    {
    14441296        if(redraw & RDW_UPDATENOW_W) {
    1445                 wnd->MsgNCPaint();
    1446                 wnd->MsgPaint (0, FALSE);
    1447         }
    1448         else    PostMessageA(hwnd, WINWM_PAINT, 0, 0);
    1449    }
     1297            wnd->MsgPaint(0, FALSE);
     1298        }
     1299        else PostMessageA(hwnd, WINWM_PAINT, 0, 0);
     1300    }
    14501301
    14511302error:
    1452    /* clean up */
    1453    if (hrgnTemp)
    1454       GpiDestroyRegion (hpsTemp, hrgnTemp);
    1455 
    1456    if (hpsTemp)
    1457       WinReleasePS (hpsTemp);
    1458 
    1459    if (!success) {
     1303    /* clean up */
     1304    if (hrgnTemp)
     1305        GpiDestroyRegion (hpsTemp, hrgnTemp);
     1306
     1307    if (hpsTemp)
     1308        WinReleasePS (hpsTemp);
     1309
     1310    if (!success) {
    14601311        dprintf(("RedrawWindow failure!"));
    14611312        SetLastError(ERROR_INVALID_PARAMETER_W);
    1462    }
    1463    return (success);
     1313    }
     1314    return (success);
    14641315}
    14651316//******************************************************************************
     
    14681319{
    14691320  Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
    1470 
    1471    if(!wnd) {
     1321  RECTL rectl;
     1322  BOOL  rc;
     1323
     1324    if(!wnd) {
     1325        dprintf (("ERROR: User32: UpdateWindow INVALID hwnd %x", hwnd));
    14721326        SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
    14731327        return FALSE;
    1474    }
    1475 
    1476    dprintf (("User32: UpdateWindow hwnd %x", hwnd));
    1477 //SvL: This doesn't work right (Wine uses RDW_NOCHILDREN_W -> doesn't work here)
    1478 //     Breaks vpbuddy
    1479 //   return RedrawWindow(hwnd, NULL, 0, RDW_UPDATENOW_W | RDW_ALLCHILDREN_W);
    1480 //   -> RDW_UPDATENOW causes WM_PAINT messages to be directy posted to window
    1481 //   handler; possibly bypassing queued WM_PAINT messages for parent window(s)
    1482 //   -> out of sync painting (i.e. parent paints over child)
    1483    WinUpdateWindow(wnd->getOS2WindowHandle());
    1484    return TRUE;
     1328    }
     1329
     1330#ifdef DEBUG
     1331    if(WinQueryUpdateRect(wnd->getOS2WindowHandle(), &rectl))
     1332    {
     1333         RECT rectUpdate;
     1334         mapOS2ToWin32Rect(wnd->getClientHeight(), (PRECTLOS2)&rectl, &rectUpdate);
     1335
     1336         dprintf (("User32: UpdateWindow hwnd %x: update rectangle (%d,%d)(%d,%d)", hwnd, rectUpdate.left, rectUpdate.top, rectUpdate.right, rectUpdate.bottom));
     1337    }
     1338    else dprintf (("User32: UpdateWindow hwnd %x; EMPTY update rectangle (vis=%d/%d)", hwnd, WinIsWindowVisible(wnd->getOS2FrameWindowHandle()), WinIsWindowVisible(wnd->getOS2WindowHandle())));
     1339#endif
     1340    //SvL: This doesn't work right (Wine uses RDW_NOCHILDREN_W -> doesn't work here)
     1341    //     Breaks vpbuddy
     1342    //rc = RedrawWindow(hwnd, NULL, 0, RDW_UPDATENOW_W | RDW_ALLCHILDREN_W);
     1343    //   -> RDW_UPDATENOW causes WM_PAINT messages to be directy posted to window
     1344    //   handler; possibly bypassing queued WM_PAINT messages for parent window(s)
     1345    //   -> out of sync painting (i.e. parent paints over child)
     1346
     1347//    if(!WinIsWindowShowing(wnd->getOS2FrameWindowHandle()) || !WinIsWindowShowing(wnd->getOS2WindowHandle())) {
     1348//        dprintf(("UpdateWindow: window not showing %d/%d", WinIsWindowShowing(wnd->getOS2FrameWindowHandle()), WinIsWindowShowing(wnd->getOS2WindowHandle()) ));
     1349//        return FALSE;
     1350//    }
     1351    //Must use frame window here. If the frame window has a valid update region and we call
     1352    //WinUpdateWindow for the client window, then no WM_PAINT messages will be sent.
     1353    rc = WinUpdateWindow(wnd->getOS2FrameWindowHandle());
     1354#ifdef DEBUG
     1355    if(WinQueryUpdateRect(wnd->getOS2WindowHandle(), NULL))
     1356    {
     1357        //if parent has valid update region then WinUpdateWindow will still fail..
     1358        //might be harmless and happen even in windows
     1359        dprintf (("ERROR: User32: UpdateWindow didn't send WM_PAINT messages!!"));
     1360    }
     1361#endif
     1362    return rc;
    14851363}
    14861364//******************************************************************************
     
    15081386   BOOL result;
    15091387
    1510    if(pRect) {
     1388    if(pRect) {
    15111389        dprintf(("InvalidateRect %x (%d,%d)(%d,%d) erase=%d", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom, erase));
    1512    }
    1513    else dprintf(("InvalidateRect %x NULL erase=%d", hwnd, erase));
     1390    }
     1391    else dprintf(("InvalidateRect %x NULL erase=%d", hwnd, erase));
    15141392#if 1
    1515    result = RedrawWindow (hwnd, pRect, NULLHANDLE,
    1516                           RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
     1393    result = RedrawWindow (hwnd, pRect, NULLHANDLE,
     1394                           RDW_INVALIDATE_W |
     1395                           (erase ? RDW_ERASE_W : 0) |
     1396                           (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
     1397#else
     1398    result = RedrawWindow (hwnd, pRect, NULLHANDLE,
     1399                           RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
     1400                           (erase ? RDW_ERASE_W : RDW_NOERASE_W) |
     1401                           (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
     1402#endif
     1403    return (result);
     1404}
     1405//******************************************************************************
     1406//******************************************************************************
     1407BOOL WIN32API InvalidateRgn (HWND hwnd, HRGN hrgn, BOOL erase)
     1408{
     1409    BOOL result;
     1410
     1411    dprintf(("InvalidateRgn %x %x erase=%d", hwnd, hrgn, erase));
     1412#if 1
     1413    result = RedrawWindow (hwnd, NULL, hrgn,
     1414                          RDW_INVALIDATE_W |
    15171415                          (erase ? RDW_ERASE_W : 0) |
    15181416                          (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
    15191417#else
    1520    result = RedrawWindow (hwnd, pRect, NULLHANDLE,
     1418    result = RedrawWindow (hwnd, NULL, hrgn,
    15211419                          RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
    15221420                          (erase ? RDW_ERASE_W : RDW_NOERASE_W) |
    15231421                          (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
    15241422#endif
    1525    return (result);
    1526 }
    1527 //******************************************************************************
    1528 //******************************************************************************
    1529 BOOL WIN32API InvalidateRgn (HWND hwnd, HRGN hrgn, BOOL erase)
    1530 {
    1531    BOOL result;
    1532 
    1533    dprintf(("InvalidateRgn %x %x erase=%d", hwnd, hrgn, erase));
    1534 #if 1
    1535    result = RedrawWindow (hwnd, NULL, hrgn,
    1536                           RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
    1537                           (erase ? RDW_ERASE_W : 0) |
    1538                           (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
    1539 #else
    1540    result = RedrawWindow (hwnd, NULL, hrgn,
    1541                           RDW_ALLCHILDREN_W | RDW_INVALIDATE_W |
    1542                           (erase ? RDW_ERASE_W : RDW_NOERASE_W) |
    1543                           (hwnd == NULLHANDLE ? RDW_UPDATENOW_W : 0));
    1544 #endif
    1545    return (result);
     1423    return (result);
    15461424}
    15471425//******************************************************************************
     
    16251503   Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
    16261504
    1627    if ((hwnd == NULLHANDLE) || !wnd)
     1505   if((hwnd == NULLHANDLE) || !wnd)
    16281506   {
    16291507      return (FALSE);
     
    17021580   RECTL  rectlUpdate;
    17031581   HRGN   hrgn;
    1704    RECTL  clientRect;
    17051582   RECTL  clipOS2;
    17061583   RECTL  scrollOS2;
     
    17081585   PRECTL pClipOS2   = NULL;
    17091586
    1710    mapWin32ToOS2Rect(wnd->getWindowHeight(), wnd->getClientRectPtr(), (PRECTLOS2)&clientRect);
    1711 
    17121587   if(pScroll) {
    1713         mapWin32ToOS2RectClientToFrame(wnd, &scrollRect, (PRECTLOS2)&scrollOS2);
     1588        mapWin32ToOS2Rect(wnd->getClientHeight(), &scrollRect, (PRECTLOS2)&scrollOS2);
    17141589        pScrollOS2 = &scrollOS2;
    1715 
    1716         //Scroll rectangle relative to client area
    1717         WinIntersectRect ((HAB) 0, pScrollOS2, pScrollOS2, &clientRect);
    1718    }
    1719    else {
    1720         pScrollOS2 = &clientRect;
    17211590   }
    17221591
    17231592   if(pClip) {
    1724          mapWin32ToOS2RectClientToFrame(wnd, &clipRect, (PRECTLOS2)&clipOS2);
    1725          pClipOS2 = &clipOS2;
    1726 
    1727          //Clip rectangle relative to client area
    1728          WinIntersectRect((HAB) 0, pClipOS2, pClipOS2, &clientRect);
    1729    }
    1730    else {
    1731          pClipOS2 = &clientRect;
     1593        mapWin32ToOS2Rect(wnd->getClientHeight(), &clipRect, (PRECTLOS2)&clipOS2);
     1594        pClipOS2 = &clipOS2;
    17321595   }
    17331596
     
    17411604   RECT winRectUpdate;
    17421605
    1743    mapOS2ToWin32Rect(wnd->getWindowHeight(), (PRECTLOS2)&rectlUpdate, &winRectUpdate);
     1606   mapOS2ToWin32Rect(wnd->getClientHeight(), (PRECTLOS2)&rectlUpdate, &winRectUpdate);
    17441607
    17451608   if (pRectUpdate)
     
    17471610
    17481611   if (hrgnUpdate)
    1749       rc = setPMRgnIntoWinRgn(hrgn, hrgnUpdate, wnd->getWindowHeight());
     1612      rc = setPMRgnIntoWinRgn(hrgn, hrgnUpdate, wnd->getClientHeight());
    17501613
    17511614   return (rc);
    17521615}
    17531616//******************************************************************************
    1754 //SvL: Using WinScrollWindow to scroll child windows is better (smoother).
     1617//Using WinScrollWindow to scroll child windows is better (smoother).
    17551618//******************************************************************************
    17561619INT WIN32API ScrollWindowEx(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip,
     
    17591622 Win32BaseWindow *window;
    17601623 APIRET  rc;
    1761  RECTL   clientRect;
    17621624 RECTL   scrollRect;
    17631625 RECTL   clipRect;
     
    17811643    if (scrollFlag & SW_SCROLLCHILDREN_W)  scrollFlagsOS2 |= SW_SCROLLCHILDREN;
    17821644
    1783     mapWin32ToOS2Rect(window->getWindowHeight(), window->getClientRectPtr(), (PRECTLOS2)&clientRect);
    1784 
    17851645    if(pScroll) {
    1786         mapWin32ToOS2RectClientToFrame(window,(RECT *)pScroll, (PRECTLOS2)&scrollRect);
     1646        mapWin32ToOS2Rect(window->getClientHeight(), (RECT *)pScroll, (PRECTLOS2)&scrollRect);
    17871647        pScrollOS2 = &scrollRect;
    1788 
    1789         //Scroll rectangle relative to client area
    1790         WinIntersectRect ((HAB) 0, pScrollOS2, pScrollOS2, &clientRect);
    1791     }
    1792     else {
    1793         pScrollOS2 = &clientRect;
    17941648    }
    17951649
    17961650    if(pClip) {
    1797          mapWin32ToOS2RectClientToFrame(window,(RECT *)pClip, (PRECTLOS2)&clipRect);
    1798          pClipOS2 = &clipRect;
    1799 
    1800          //Clip rectangle relative to client area
    1801          WinIntersectRect ((HAB) 0, pClipOS2, pClipOS2, &clientRect);
    1802     }
    1803     else {
    1804          pClipOS2 = &clientRect;
     1651        mapWin32ToOS2Rect(window->getClientHeight(), (RECT *)pClip, (PRECTLOS2)&clipRect);
     1652        pClipOS2 = &clipRect;
    18051653    }
    18061654
     
    18161664    }
    18171665
    1818     LONG lComplexity = WinScrollWindow (window->getOS2WindowHandle(), dx, dy,
    1819                                         pScrollOS2,
    1820                                         pClipOS2,
    1821                                         hrgn, &rectlUpdate, scrollFlagsOS2);
     1666    LONG lComplexity = WinScrollWindow(window->getOS2WindowHandle(), dx, dy,
     1667                                       pScrollOS2, pClipOS2,
     1668                                       hrgn, &rectlUpdate, scrollFlagsOS2);
    18221669    if (lComplexity == RGN_ERROR)
    18231670    {
     
    18501697                }
    18511698                rectChild = *child->getWindowRect();
    1852                 if(!pRectUpdate || IntersectRect(&rectChild, &rectChild, &rc))
     1699                if(!pScroll || IntersectRect(&rectChild, &rectChild, &rc))
    18531700                {
    18541701                     dprintf(("ScrollWindowEx: Scroll child window %x", hwndChild));
     
    18621709    RECT winRectUpdate;
    18631710
    1864     mapOS2ToWin32Rect(window->getWindowHeight(), (PRECTLOS2)&rectlUpdate, &winRectUpdate);
     1711    mapOS2ToWin32Rect(window->getClientHeight(), (PRECTLOS2)&rectlUpdate, &winRectUpdate);
    18651712
    18661713    if (pRectUpdate)
     
    18681715
    18691716    if (hrgnUpdate)
    1870        rc = setPMRgnIntoWinRgn (hrgn, hrgnUpdate, window->getWindowHeight());
     1717       rc = setPMRgnIntoWinRgn(hrgn, hrgnUpdate, window->getClientHeight());
    18711718
    18721719#if 0
     
    18911738    switch (lComplexity)
    18921739    {
    1893        case RGN_NULL:
    1894          regionType = NULLREGION_W;
    1895          break;
    1896        case RGN_RECT:
    1897          regionType = SIMPLEREGION_W;
    1898          break;
    1899        case RGN_COMPLEX:
    1900          regionType = COMPLEXREGION_W;
    1901          break;
    1902        default:
    1903          regionType = ERROR_W;
    1904          break;
     1740    case RGN_NULL:
     1741        regionType = NULLREGION_W;
     1742        break;
     1743    case RGN_RECT:
     1744        regionType = SIMPLEREGION_W;
     1745        break;
     1746    case RGN_COMPLEX:
     1747        regionType = COMPLEXREGION_W;
     1748        break;
     1749    default:
     1750        regionType = ERROR_W;
     1751        break;
    19051752    }
    19061753
     
    19371784//******************************************************************************
    19381785//******************************************************************************
    1939 #ifdef DEBUG
    1940 void dprintfOrigin(HDC hdc)
    1941 {
    1942    POINTL point;
    1943 
    1944     pDCData  pHps = (pDCData)GpiQueryDCData((HPS)hdc);
    1945     if(!pHps)
    1946     {
    1947         return;
    1948     }
    1949 
    1950     GreGetDCOrigin(pHps->hps, &point);
    1951     dprintf(("HDC %x origin (%d,%d) org (%d,%d)", hdc, point.x, point.y, pHps->ptlOrigin.x, pHps->ptlOrigin.y));
    1952 }
    1953 #endif
    1954 //******************************************************************************
    1955 //******************************************************************************
     1786
Note: See TracChangeset for help on using the changeset viewer.