Ignore:
Timestamp:
Feb 6, 2000, 11:00:25 PM (26 years ago)
Author:
sandervl
Message:

DC changes + commented out shell position update

File:
1 edited

Legend:

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

    r2663 r2672  
    1 /* $Id: dc.cpp,v 1.42 2000-02-05 16:24:57 sandervl Exp $ */
     1/* $Id: dc.cpp,v 1.43 2000-02-06 22:00:22 sandervl Exp $ */
    22
    33/*
     
    2929#include <limits.h>
    3030#include "oslibwin.h"
     31#include "oslibmsg.h"
    3132#include <dcdata.h>
    3233
     
    7172HWND WIN32API GetDesktopWindow(void);
    7273INT  WIN32API GetUpdateRgn(HWND, HRGN, BOOL);
     74BOOL WIN32API HideCaret(HWND hwnd);
     75BOOL WIN32API ShowCaret(HWND hwnd);
     76HDC  WIN32API GetDCEx(HWND hwnd, HRGN hrgn, ULONG flags);
     77int  WIN32API ReleaseDC(HWND hwnd, HDC hdc);
     78BOOL WIN32API PostMessageA(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
    7379
    7480//******************************************************************************
     
    427433      if (pHps->hdc)
    428434         DevCloseDC(pHps->hdc);
    429 
    430 // how can a memory chunk allocated by GpiAllocateDCData freed by delete?
    431 //      delete pHps;
    432435   }
    433436}
     
    436439HDC WIN32API BeginPaint (HWND hWnd, PPAINTSTRUCT_W lpps)
    437440{
    438    HWND     hwnd = hWnd ? hWnd : HWND_DESKTOP;
    439    pDCData  pHps = NULLHANDLE;
    440    RECTL    rect;
    441    HPS      hPS_ownDC = NULLHANDLE;
    442 
    443    if ( !lpps )
    444    {
     441 HWND     hwnd = hWnd ? hWnd : HWND_DESKTOP;
     442 pDCData  pHps = NULLHANDLE;
     443 HPS      hPS_ownDC = NULLHANDLE, hpsPaint = 0;
     444 RECTL    rectl = {0, 0, 1, 1};
     445 HRGN     hrgnUpdate, hrgnOld;
     446 LONG     lComplexity;
     447
     448   Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
     449   if(!lpps || !wnd) {
    445450        dprintf (("USER32: BeginPaint %x invalid parameter %x", hWnd, lpps));
    446451        O32_SetLastError (ERROR_INVALID_PARAMETER);
    447         return (HDC)NULLHANDLE;
    448    }
    449 
    450    Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
    451 
    452    if ((hwnd != HWND_DESKTOP) && wnd->isOwnDC())
     452        return (HDC)0;
     453   }
     454   HWND hwndClient = wnd->getOS2WindowHandle();
     455
     456   if(hwnd != HWND_DESKTOP && wnd->isOwnDC())
    453457   {
    454458        hPS_ownDC = wnd->getOwnDC();
     
    462466                        return (HDC)NULLHANDLE;
    463467                }
     468                hpsPaint = hPS_ownDC;
    464469        }
    465470   }
    466 
    467    //SvL: Get update region for WM_ERASEBACKGROUND handling in the def wndproc
    468    GetUpdateRgn(hWnd, wnd->GetUpdateRegion(), FALSE);
    469 
    470    HWND hwndClient = wnd->getOS2WindowHandle();
     471   if(!hpsPaint) {
     472        hpsPaint = GetDCEx(hwnd, 0, DCX_CACHE_W);
     473        pHps = (pDCData)GpiQueryDCData(hpsPaint);
     474        if (!pHps)
     475        {
     476                dprintf (("USER32: BeginPaint %x invalid parameter %x", hWnd, lpps));
     477                O32_SetLastError (ERROR_INVALID_PARAMETER);
     478                return (HDC)NULLHANDLE;
     479        }
     480   } 
     481
     482#if 0
    471483   HPS  hps = WinBeginPaint(hwndClient, hPS_ownDC, &rect);
    472484
     
    476488      pHps = (pDCData)GpiQueryDCData(hps);
    477489   }
     490#endif
    478491
    479492   if (hPS_ownDC == 0)
     
    483496
    484497   pHps->hdcType = TYPE_3;
    485    lpps->hdc = (HDC)hps;
    486 
    487    if(!wnd->isSuppressErase()) {
     498
     499   hrgnUpdate  = GpiCreateRegion(pHps->hps, 1, &rectl);
     500   lComplexity = WinQueryUpdateRegion(hwndClient, hrgnUpdate);
     501   if(lComplexity == RGN_ERROR) {
     502        dprintf (("USER32: BeginPaint update region error!!"));
     503        O32_SetLastError (ERROR_INVALID_PARAMETER);
     504        return 0;
     505   }
     506   WinQueryUpdateRect(hwndClient, &rectl);
     507
     508   if(lComplexity != RGN_NULL) {
     509        WinValidateRegion(hwndClient, hrgnUpdate, FALSE);
     510
     511        GpiSetClipRegion(pHps->hps, hrgnUpdate, &hrgnOld);
     512        //save old clip region (restored for CS_OWNDC windows in EndPaint)
     513        wnd->SetClipRegion(hrgnOld);
     514   }
     515
     516   if(!wnd->isSuppressErase() && lComplexity != RGN_NULL) {
    488517        wnd->setSuppressErase(TRUE);
    489         wnd->setEraseBkgnd (FALSE, !wnd->MsgEraseBackGround(lpps->hdc));
    490    }
    491    lpps->fErase = wnd->isPSErase();
    492 
    493    if (!hPS_ownDC)
    494    {
    495       long height  = wnd->getClientHeight();
    496       rect.yTop    = height - rect.yTop;
    497       rect.yBottom = height - rect.yBottom;
    498    }
    499    else
    500    {
    501       rect.yTop--;
    502       rect.yBottom--;
    503       GpiConvert(pHps->hps, CVTC_DEVICE, CVTC_WORLD, 2, (PPOINTL)&rect);
    504    }
    505 
    506    WINRECT_FROM_PMRECT(lpps->rcPaint, rect);
     518        wnd->setEraseBkgnd (FALSE, !wnd->MsgEraseBackGround(pHps->hps));
     519   }
     520   lpps->fErase = wnd->isPSErase(); //correct ??
     521   lpps->hdc    = (HDC)pHps->hps;
     522   
     523   if(lComplexity != RGN_NULL) {
     524        long height  = wnd->getClientHeight();
     525        lpps->rcPaint.top    = height - rectl.yTop;
     526        lpps->rcPaint.left   = rectl.xLeft;
     527        lpps->rcPaint.bottom = height - rectl.yBottom;
     528        lpps->rcPaint.right  = rectl.xRight;
     529   }
     530   else {
     531        lpps->rcPaint.bottom = lpps->rcPaint.top = 0;
     532        lpps->rcPaint.right = lpps->rcPaint.left = 0;
     533   }
     534   
     535   HideCaret(hwnd);
    507536
    508537   O32_SetLastError(0);
    509    dprintf(("USER32: BeginPaint %x -> hdc %x", hWnd, pHps->hps));
     538   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));
    510539   return (HDC)pHps->hps;
    511540}
    512541//******************************************************************************
    513542//******************************************************************************
    514 BOOL WIN32API EndPaint (HWND hwnd, const PAINTSTRUCT_W *pPaint)
    515 {
     543BOOL WIN32API EndPaint (HWND hWnd, const PAINTSTRUCT_W *pPaint)
     544{
     545  HWND    hwnd = hWnd ? hWnd : HWND_DESKTOP;
     546  HRGN    hrgnOld;
     547  pDCData pHps;
     548
    516549   dprintf (("USER32: EndPaint(%x)", hwnd));
    517550
     
    523556   if (!wnd) goto exit;
    524557
    525    //SvL: Hack for memory.exe (doesn't get repainted properly otherwise)
    526    if(wnd->isOwnDC() && wnd->getOwnDC())
    527 //   if(wnd->isOwnDC())
    528    {
    529        pDCData pHps = (pDCData)GpiQueryDCData((HPS)pPaint->hdc);
    530        if (pHps && (pHps->hdcType == TYPE_3))
    531        {
    532           WinEndPaint (pHps->hps);
    533        }
    534    }
    535    else
    536    {
    537        O32_EndPaint (HWND_DESKTOP, pPaint);
     558   pHps = (pDCData)GpiQueryDCData((HPS)pPaint->hdc);
     559   if (pHps && (pHps->hdcType == TYPE_3))
     560   {
     561        GpiSetClipRegion(pHps->hps, NULLHANDLE, &hrgnOld);
     562        if(hrgnOld) {
     563                GpiDestroyRegion(pHps->hps, hrgnOld);
     564        }
     565        //todo restore old clip region for CS_OWNDC windows
     566        if(hwnd == HWND_DESKTOP || !wnd->isOwnDC()) {
     567                ReleaseDC(hwnd, pPaint->hdc);
     568        }
     569        else
     570        if(wnd->GetClipRegion()) {
     571                //TODO: What else do we need to restore here???
     572                GpiSetClipRegion(pHps->hps, wnd->GetClipRegion(), &hrgnOld);
     573                wnd->SetClipRegion(0);
     574                pHps->hdcType = TYPE_1;
     575        }
     576
     577////    WinEndPaint (pHps->hps);
     578   }
     579   else {
     580        dprintf(("EndPaint: wrong hdc %x!!", pPaint->hdc));
    538581   }
    539582   wnd->setSuppressErase(FALSE);
     583   ShowCaret(hwnd);
    540584
    541585exit:
     
    569613   if (updateRegionExists)
    570614   {
    571       //CB: for PM empty rect is valid
    572       if ((rectl.xLeft == rectl.xRight) || (rectl.yTop == rectl.yBottom)) return FALSE;
    573       //SvL: Hack for memory.exe (doesn't get repainted properly otherwise)
     615        //CB: for PM empty rect is valid
     616        if ((rectl.xLeft == rectl.xRight) || (rectl.yTop == rectl.yBottom)) {
     617                if(pRect) {
     618                        pRect->left = pRect->top = pRect->right = pRect->bottom = 0;
     619                }
     620                return FALSE;
     621        }
     622#if 0
     623        //SvL: Hack for memory.exe (doesn't get repainted properly otherwise)
    574624//      if (wnd->isOwnDC() && wnd->getOwnDC())
    575       if (wnd->isOwnDC())
    576       {
    577          pDCData pHps = NULL;
    578          pHps = (pDCData)GpiQueryDCData(wnd->getOwnDC());
    579          if (!pHps)
    580          {
    581             O32_SetLastError (ERROR_INVALID_HANDLE);
    582             return FALSE;
    583          }
    584          GpiConvert (pHps->hps, CVTC_DEVICE, CVTC_WORLD, 2, (PPOINTL)&rectl);
    585       }
    586       else
    587       {
    588          long height   = wnd->getClientHeight();
    589          rectl.yTop    = height - rectl.yTop;
    590          rectl.yBottom = height - rectl.yBottom;
    591       }
    592 
    593       if (pRect)
    594          WINRECT_FROM_PMRECT (*pRect, rectl);
    595 
    596       if (erase)
    597          sendEraseBkgnd (wnd);
     625        if (wnd->isOwnDC())
     626        {
     627                pDCData pHps = NULL;
     628                pHps = (pDCData)GpiQueryDCData(wnd->getOwnDC());
     629                if (!pHps)
     630                {
     631                        O32_SetLastError (ERROR_INVALID_HANDLE);
     632                        return FALSE;
     633                }
     634                GpiConvert (pHps->hps, CVTC_DEVICE, CVTC_WORLD, 2, (PPOINTL)&rectl);
     635        }
     636        else
     637        {
     638#endif
     639                long height   = wnd->getClientHeight();
     640                rectl.yTop    = height - rectl.yTop;
     641                rectl.yBottom = height - rectl.yBottom;
     642//////////              }
     643
     644        if (pRect)
     645                WINRECT_FROM_PMRECT (*pRect, rectl);
     646
     647        if (erase)
     648                sendEraseBkgnd (wnd);
    598649   }
    599650   else
    600651   {
    601       if (pRect)
    602          pRect->left = pRect->top = pRect->right = pRect->bottom = 0;
     652        if(pRect) {
     653                pRect->left = pRect->top = pRect->right = pRect->bottom = 0;
     654        }
    603655   }
    604656
     
    627679     if ((rectl.xLeft == rectl.xRight) || (rectl.yTop == rectl.yBottom)) return FALSE;
    628680     mapOS2ToWin32Rect(hwnd,(PRECTLOS2)&rectl,pRect);
    629    } else
     681   }
     682   else
    630683       pRect->left = pRect->top = pRect->right = pRect->bottom = 0;
    631684
     
    647700
    648701   Complexity = O32_GetUpdateRgn (wnd->getOS2WindowHandle(), hrgn, FALSE);
    649    if (erase && (Complexity > NULLREGION_W)) sendEraseBkgnd (wnd);
     702   if (erase && (Complexity > NULLREGION_W)) sendEraseBkgnd(wnd);
    650703
    651704   return Complexity;
     
    696749   }
    697750
    698    //SvL: Hack for memory.exe (doesn't get repainted properly otherwise)
    699 //   isWindowOwnDC = (((hWindow == HWND_DESKTOP) ? FALSE : (wnd->isOwnDC() && wnd->getOwnDC()))
    700751   isWindowOwnDC = (((hWindow == HWND_DESKTOP) ? FALSE : (wnd->isOwnDC()))
    701752                 && !(flags & DCX_CACHE_W|DCX_WINDOW_W));
     
    768819      {
    769820#if 0 //CB: todo
     821         long height;
     822         if (flags & DCX_WINDOW_W)
     823                height = wnd->getWindowHeight();
     824         else   height = wnd->getClientHeight();
     825
    770826         for (; (i > 0) && success; i--, pr++) {
    771827            LONG y = pr->yBottom;
     
    776832         }
    777833#endif
    778       } else //DCX_INTERSECTRGN_W
     834      }
     835      else //DCX_INTERSECTRGN_W
    779836      {
    780837        O32_SelectClipRgn(pHps->hps,hrgn); //CB: works so far
     
    855912   dprintf(("ReleaseDC %x %x", hwnd, hdc));
    856913   return (rc);
    857 }
    858 //******************************************************************************
    859 //******************************************************************************
    860 BOOL WIN32API UpdateWindow (HWND hwnd)
    861 {
    862   Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
    863 
    864    if(!wnd) {
    865         O32_SetLastError(ERROR_INVALID_WINDOW_HANDLE);
    866         return FALSE;
    867    }
    868 
    869    dprintf (("User32: UpdateWindow hwnd %x", hwnd));
    870 
    871    //SvL: Should update client window, not the frame
    872    WinUpdateWindow(wnd->getOS2WindowHandle());
    873 
    874    return (TRUE);
    875914}
    876915//******************************************************************************
     
    941980   if (redraw & RDW_UPDATENOW_W) redraw &= ~RDW_ERASENOW_W;
    942981
    943    if (redraw & RDW_NOERASE_W)
    944       wnd->setEraseBkgnd (FALSE);
     982   if (redraw & RDW_NOERASE_W || !(redraw & (RDW_ERASE_W|RDW_ERASENOW_W))) {
     983        wnd->setSuppressErase(TRUE);
     984   }
     985   else wnd->setSuppressErase(FALSE);
     986
     987//   if (redraw & RDW_NOERASE_W)
     988//      wnd->setEraseBkgnd (FALSE);
    945989
    946990//SvL: Test
     
    10141058   }
    10151059
    1016    if (WinQueryUpdateRect (hwnd, NULL))
    1017    {
    1018       if (redraw & RDW_UPDATENOW_W)
    1019          wnd->MsgPaint (0, FALSE);
    1020 
    1021       else if ((redraw & RDW_ERASE_W) && (redraw & RDW_ERASENOW_W))
    1022          wnd->setEraseBkgnd (FALSE, !sendEraseBkgnd (wnd));
    1023    }
    1024    else if ((redraw & RDW_INTERNALPAINT_W) && !(redraw & RDW_INVALIDATE_W))
    1025    {
    1026       if (redraw & RDW_UPDATENOW_W)
    1027          wnd->MsgPaint (0, FALSE);
    1028 //      else
    1029 //         WinPostMsg( hwnd, WM_VIRTUAL_INTERNALPAINT, MPVOID, MPVOID );
     1060   if(WinQueryUpdateRect(hwnd, NULL))
     1061   {
     1062        if(redraw & RDW_UPDATENOW_W) {
     1063                wnd->MsgPaint (0, FALSE);
     1064        }
     1065        else
     1066        if((redraw & RDW_ERASE_W) && (redraw & RDW_ERASENOW_W))
     1067                wnd->setEraseBkgnd (FALSE, !sendEraseBkgnd (wnd));
     1068   }
     1069   else if((redraw & RDW_INTERNALPAINT_W) && !(redraw & RDW_INVALIDATE_W))
     1070   {
     1071        if(redraw & RDW_UPDATENOW_W)
     1072                wnd->MsgPaint (0, FALSE);
     1073        else    PostMessageA(hwnd, WINWM_PAINT, 0, 0);
    10301074   }
    10311075
     
    10481092
    10491093   return (success);
     1094}
     1095//******************************************************************************
     1096//******************************************************************************
     1097BOOL WIN32API UpdateWindow (HWND hwnd)
     1098{
     1099  Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
     1100
     1101   if(!wnd) {
     1102        O32_SetLastError(ERROR_INVALID_WINDOW_HANDLE);
     1103        return FALSE;
     1104   }
     1105
     1106   dprintf (("User32: UpdateWindow hwnd %x", hwnd));
     1107////SvL: This doesn't work right (it's what Wine does) -> TODO
     1108////   return RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW_W | RDW_NOCHILDREN_W);
     1109   WinUpdateWindow(wnd->getOS2WindowHandle());
     1110   return TRUE;
    10501111}
    10511112//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.