Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

dcrgn.cpp

Go to the documentation of this file.
00001 /* $Id: dcrgn.cpp,v 1.7 2001/09/30 22:24:41 sandervl Exp $ */
00002 
00003 /*
00004  * DC functions for USER32
00005  *
00006  * Project Odin Software License can be found in LICENSE.TXT
00007  *
00008  */
00009 
00010 /*****************************************************************************
00011  * Includes                                                                  *
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 //#include <pmddi.h>
00022 #include <stdlib.h>
00023 
00024 #include <string.h>
00025 #include <win32type.h>
00026 #include <win32api.h>
00027 #include <winconst.h>
00028 #include <misc.h>
00029 #include <win32wbase.h>
00030 #include <math.h>
00031 #include <limits.h>
00032 #include "oslibwin.h"
00033 #include "oslibmsg.h"
00034 #include <dcdata.h>
00035 #include <objhandle.h>
00036 #include <wingdi32.h>
00037 
00038 #define INCLUDED_BY_DC
00039 #include "dc.h"
00040 
00041 #define DBG_LOCALLOG    DBG_dcrgn
00042 #include "dbglocal.h"
00043 
00044 //******************************************************************************
00045 //******************************************************************************
00046 BOOL WIN32API GetUpdateRect(HWND hwnd, LPRECT pRect, BOOL erase)
00047 {
00048     if (!hwnd)
00049     {
00050         dprintf(("GetUpdateRect %x %x %d -> invalid handle!!", hwnd, pRect, erase));
00051         SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
00052         return FALSE;
00053     }
00054 
00055     RECTL rectl, rectlClient;
00056     Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
00057 
00058     if (!wnd)
00059     {
00060         SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
00061         dprintf(("GetUpdateRect %x %x %d -> invalid handle!!", hwnd, pRect, erase));
00062         return FALSE;
00063     }
00064 
00065     dprintf(("GetUpdateRect %x %x %d", hwnd, pRect, erase));
00066 
00067     BOOL updateRegionExists = WinQueryUpdateRect(wnd->getOS2WindowHandle(), pRect ? &rectl : NULL);
00068     if (!pRect) {
00069         dprintf(("GetUpdateRect returned %d", updateRegionExists));
00070         RELEASE_WNDOBJ(wnd);
00071         return (updateRegionExists);
00072     }
00073 
00074     if(updateRegionExists)
00075     {
00076         //CB: for PM empty rect is valid
00077         if ((rectl.xLeft == rectl.xRight) || (rectl.yTop == rectl.yBottom)) {
00078             if(pRect) {
00079                 pRect->left = pRect->top = pRect->right = pRect->bottom = 0;
00080             }
00081             RELEASE_WNDOBJ(wnd);
00082             return FALSE;
00083         }
00084         mapOS2ToWin32Rect(wnd->getClientHeight(), (PRECTLOS2)&rectl, pRect);
00085 
00086         if(wnd->isOwnDC() && GetMapMode(wnd->getOwnDC()) != MM_TEXT_W)
00087         {
00088             DPtoLP(wnd->getOwnDC(), (LPPOINT)pRect, 2);
00089         }
00090         if (erase)
00091             sendEraseBkgnd (wnd);
00092    }
00093    else
00094    {
00095         if(pRect) {
00096             pRect->left = pRect->top = pRect->right = pRect->bottom = 0;
00097         }
00098    }
00099 
00100    dprintf(("GetUpdateRect returned (%d,%d)(%d,%d)", pRect->left, pRect->top, pRect->right, pRect->bottom));
00101    RELEASE_WNDOBJ(wnd);
00102    return updateRegionExists;
00103 }
00104 //******************************************************************************
00105 //TODO: Seems to return region in window coordinates instead of client coordinates
00106 //******************************************************************************
00107 int WIN32API GetUpdateRgn(HWND hwnd, HRGN hrgn, BOOL erase)
00108 {
00109     LONG lComplexity;
00110     Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
00111 
00112     hrgn = ObjWinToOS2Region(hrgn);
00113     if(!wnd || !hrgn)
00114     {
00115         dprintf(("WARNING: GetUpdateRgn %x %x %d; invalid handle", hwnd, hrgn, erase));
00116         SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
00117         if(wnd) RELEASE_WNDOBJ(wnd);
00118         return ERROR_W;
00119     }
00120     lComplexity = WinQueryUpdateRegion(wnd->getOS2WindowHandle(), hrgn);
00121     if(lComplexity == RGN_ERROR) {
00122         dprintf(("WARNING: GetUpdateRgn %x %x %d; RGN_ERROR", hwnd, hrgn, erase));
00123         SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
00124         RELEASE_WNDOBJ(wnd);
00125         return ERROR_W;
00126     }
00127 
00128     if(lComplexity != RGN_NULL)
00129     {
00130         if(!setWinDeviceRegionFromPMDeviceRegion(hrgn, hrgn, NULL, wnd->getOS2WindowHandle()))
00131         {
00132             dprintf(("WARNING: GetUpdateRgn %x %x %d; setWinDeviceRegionFromPMDeviceRegion failed!", hwnd, hrgn, erase));
00133             SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
00134             RELEASE_WNDOBJ(wnd);
00135             return ERROR_W;
00136         }
00137         if(erase) sendEraseBkgnd(wnd);
00138     }
00139     RELEASE_WNDOBJ(wnd);
00140     return lComplexity;
00141 }
00142 //******************************************************************************
00143 //TODO: Check
00144 //******************************************************************************
00145 INT WIN32API ExcludeUpdateRgn(HDC hdc, HWND hwnd)
00146 {
00147     Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
00148     pDCData          pHps = (pDCData)GpiQueryDCData((HPS)hdc);
00149     LONG             lComplexity;
00150 
00151     if(!wnd || !pHps)
00152     {
00153         dprintf(("WARNING: ExcludeUpdateRgn %x %x; invalid handle", hdc, hwnd));
00154         SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
00155         if(wnd) RELEASE_WNDOBJ(wnd);
00156         return ERROR_W;
00157     }
00158     dprintf(("USER32: ExcludeUpdateRgn %x %x", hdc, hwnd));
00159 
00160     lComplexity = WinExcludeUpdateRegion(pHps->hps, wnd->getOS2WindowHandle());
00161     if(lComplexity == RGN_ERROR) {
00162          SetLastError(ERROR_INVALID_HANDLE_W); //todo: correct error
00163     }
00164     else SetLastError(ERROR_SUCCESS_W);
00165 
00166     RELEASE_WNDOBJ(wnd);
00167     return lComplexity;      // windows and PM values are identical
00168 }
00169 /*****************************************************************************
00170  * Name      : int WIN32API GetWindowRgn
00171  * Purpose   : The GetWindowRgn function obtains a copy of the window region of a window.
00172  * Parameters: HWND hWnd handle to window whose window region is to be obtained
00173  *             HRGN hRgn handle to region that receives a copy of the window region
00174  * Variables :
00175  * Result    : NULLREGION, SIMPLEREGION, COMPLEXREGION, ERROR
00176  * Remark    :
00177  * Status    : UNTESTED STUB
00178  *
00179  * Author    : Patrick Haller [Thu, 1998/02/26 11:55]
00180  *****************************************************************************/
00181 
00182 int WIN32API GetWindowRgn(HWND hwnd, HRGN hRgn)
00183 {
00184     Win32BaseWindow *window;
00185     HRGN hWindowRegion;
00186 
00187     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
00188     if(!window) {
00189         dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
00190         SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
00191         return 0;
00192     }
00193     dprintf(("USER32:GetWindowRgn (%x,%x)", hwnd, hRgn));
00194     hWindowRegion = window->GetWindowRegion();
00195     RELEASE_WNDOBJ(window);
00196     return CombineRgn(hRgn, hWindowRegion, 0, RGN_COPY_W);
00197 }
00198 /*****************************************************************************
00199  * Name      : int WIN32API SetWindowRgn
00200  * Purpose   : The SetWindowRgn function sets the window region of a window. The
00201  *             window region determines the area within the window where the
00202  *             operating system permits drawing. The operating system does not
00203  *             display any portion of a window that lies outside of the window region
00204  *             When this function is called, the system sends the WM_WINDOWPOSCHANGING and
00205  *             WM_WINDOWPOSCHANGED messages to the window.
00206  *
00207  * Parameters: HWND  hWnd    handle to window whose window region is to be set
00208  *             HRGN  hRgn    handle to region
00209  *             BOOL  bRedraw window redraw flag
00210  * Variables :
00211  * Result    : If the function succeeds, the return value is non-zero.
00212  *             If the function fails, the return value is zero.
00213  * Remark    :
00214  * Status    : UNTESTED STUB
00215  *
00216  * Author    : Patrick Haller [Thu, 1998/02/26 11:55]
00217  *****************************************************************************/
00218 
00219 int WIN32API SetWindowRgn(HWND hwnd,
00220                           HRGN hRgn,
00221                           BOOL bRedraw)
00222 {
00223     Win32BaseWindow *window;
00224     HRGN hWindowRegion;
00225 
00226     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
00227     if(!window) {
00228         dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
00229         SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
00230         return 0;
00231     }
00232     dprintf(("USER32:SetWindowRgn (%x,%x,%d)", hwnd, hRgn, bRedraw));
00233     if(window->GetWindowRegion()) {
00234         DeleteObject(window->GetWindowRegion());
00235     }
00236     window->SetWindowRegion(hRgn);
00237     if(bRedraw) {
00238         RedrawWindow(hwnd, 0, 0, RDW_UPDATENOW_W);
00239     }
00240     RELEASE_WNDOBJ(window);
00241 //TODO:
00242 //  When this function is called, the system sends the WM_WINDOWPOSCHANGING and
00243 //  WM_WINDOWPOSCHANGED messages to the window.
00244     return 1;
00245 }
00246 //******************************************************************************
00247 // WinSetVisibleRgnNotifyProc
00248 //   To set a notification procedure for visible region changes of a specific window.
00249 //   The procedure will be called when a WM_VRNENABLED message is posted
00250 //   with ffVisRgnChanged set to TRUE
00251 //
00252 // Parameters:
00253 //   HWND hwnd                          window handle
00254 //   VISRGN_NOTIFY_PROC lpNotifyProc    notification proc or NULL to clear proc
00255 //   DWORD dwUserData                   value used as 3rd parameter during
00256 //                                      visible region callback
00257 //
00258 // NOTE: Internal API
00259 //******************************************************************************
00260 BOOL WIN32API WinSetVisibleRgnNotifyProc(HWND hwnd, VISRGN_NOTIFY_PROC lpNotifyProc, 
00261                                          DWORD dwUserData)
00262 {
00263   Win32BaseWindow *window;
00264 
00265     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
00266     if(!window) {
00267         dprintf(("WinSetVisibleRgnNotifyProc, window %x not found", hwnd));
00268         return FALSE;
00269     }
00270     BOOL ret = window->setVisibleRgnNotifyProc(lpNotifyProc, dwUserData);
00271     RELEASE_WNDOBJ(window);
00272     return ret;
00273 }
00274 //******************************************************************************
00275 //******************************************************************************

Generated on Wed Jan 23 23:17:29 2002 for ODIN-user32 by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001