| 1 | /* $Id: dcrgn.cpp,v 1.7 2001-09-30 22:24:41 sandervl Exp $ */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * DC functions for USER32
|
|---|
| 5 | *
|
|---|
| 6 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 7 | *
|
|---|
| 8 | */
|
|---|
| 9 |
|
|---|
| 10 | /*****************************************************************************
|
|---|
| 11 | * Includes *
|
|---|
| 12 | *****************************************************************************/
|
|---|
| 13 |
|
|---|
| 14 | #include <odin.h>
|
|---|
| 15 |
|
|---|
| 16 | #define INCL_WIN
|
|---|
| 17 | #define INCL_GPI
|
|---|
| 18 | #define INCL_GREALL
|
|---|
| 19 | #define INCL_DEV
|
|---|
| 20 | #include <os2wrap.h>
|
|---|
| 21 | //#include <pmddi.h>
|
|---|
| 22 | #include <stdlib.h>
|
|---|
| 23 |
|
|---|
| 24 | #include <string.h>
|
|---|
| 25 | #include <win32type.h>
|
|---|
| 26 | #include <win32api.h>
|
|---|
| 27 | #include <winconst.h>
|
|---|
| 28 | #include <misc.h>
|
|---|
| 29 | #include <win32wbase.h>
|
|---|
| 30 | #include <math.h>
|
|---|
| 31 | #include <limits.h>
|
|---|
| 32 | #include "oslibwin.h"
|
|---|
| 33 | #include "oslibmsg.h"
|
|---|
| 34 | #include <dcdata.h>
|
|---|
| 35 | #include <objhandle.h>
|
|---|
| 36 | #include <wingdi32.h>
|
|---|
| 37 |
|
|---|
| 38 | #define INCLUDED_BY_DC
|
|---|
| 39 | #include "dc.h"
|
|---|
| 40 |
|
|---|
| 41 | #define DBG_LOCALLOG DBG_dcrgn
|
|---|
| 42 | #include "dbglocal.h"
|
|---|
| 43 |
|
|---|
| 44 | //******************************************************************************
|
|---|
| 45 | //******************************************************************************
|
|---|
| 46 | BOOL WIN32API GetUpdateRect(HWND hwnd, LPRECT pRect, BOOL erase)
|
|---|
| 47 | {
|
|---|
| 48 | if (!hwnd)
|
|---|
| 49 | {
|
|---|
| 50 | dprintf(("GetUpdateRect %x %x %d -> invalid handle!!", hwnd, pRect, erase));
|
|---|
| 51 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
|
|---|
| 52 | return FALSE;
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | RECTL rectl, rectlClient;
|
|---|
| 56 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 57 |
|
|---|
| 58 | if (!wnd)
|
|---|
| 59 | {
|
|---|
| 60 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
|
|---|
| 61 | dprintf(("GetUpdateRect %x %x %d -> invalid handle!!", hwnd, pRect, erase));
|
|---|
| 62 | return FALSE;
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | dprintf(("GetUpdateRect %x %x %d", hwnd, pRect, erase));
|
|---|
| 66 |
|
|---|
| 67 | BOOL updateRegionExists = WinQueryUpdateRect(wnd->getOS2WindowHandle(), pRect ? &rectl : NULL);
|
|---|
| 68 | if (!pRect) {
|
|---|
| 69 | dprintf(("GetUpdateRect returned %d", updateRegionExists));
|
|---|
| 70 | RELEASE_WNDOBJ(wnd);
|
|---|
| 71 | return (updateRegionExists);
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | if(updateRegionExists)
|
|---|
| 75 | {
|
|---|
| 76 | //CB: for PM empty rect is valid
|
|---|
| 77 | if ((rectl.xLeft == rectl.xRight) || (rectl.yTop == rectl.yBottom)) {
|
|---|
| 78 | if(pRect) {
|
|---|
| 79 | pRect->left = pRect->top = pRect->right = pRect->bottom = 0;
|
|---|
| 80 | }
|
|---|
| 81 | RELEASE_WNDOBJ(wnd);
|
|---|
| 82 | return FALSE;
|
|---|
| 83 | }
|
|---|
| 84 | mapOS2ToWin32Rect(wnd->getClientHeight(), (PRECTLOS2)&rectl, pRect);
|
|---|
| 85 |
|
|---|
| 86 | if(wnd->isOwnDC() && GetMapMode(wnd->getOwnDC()) != MM_TEXT_W)
|
|---|
| 87 | {
|
|---|
| 88 | DPtoLP(wnd->getOwnDC(), (LPPOINT)pRect, 2);
|
|---|
| 89 | }
|
|---|
| 90 | if (erase)
|
|---|
| 91 | sendEraseBkgnd (wnd);
|
|---|
| 92 | }
|
|---|
| 93 | else
|
|---|
| 94 | {
|
|---|
| 95 | if(pRect) {
|
|---|
| 96 | pRect->left = pRect->top = pRect->right = pRect->bottom = 0;
|
|---|
| 97 | }
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | dprintf(("GetUpdateRect returned (%d,%d)(%d,%d)", pRect->left, pRect->top, pRect->right, pRect->bottom));
|
|---|
| 101 | RELEASE_WNDOBJ(wnd);
|
|---|
| 102 | return updateRegionExists;
|
|---|
| 103 | }
|
|---|
| 104 | //******************************************************************************
|
|---|
| 105 | //TODO: Seems to return region in window coordinates instead of client coordinates
|
|---|
| 106 | //******************************************************************************
|
|---|
| 107 | int WIN32API GetUpdateRgn(HWND hwnd, HRGN hrgn, BOOL erase)
|
|---|
| 108 | {
|
|---|
| 109 | LONG lComplexity;
|
|---|
| 110 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 111 |
|
|---|
| 112 | hrgn = ObjWinToOS2Region(hrgn);
|
|---|
| 113 | if(!wnd || !hrgn)
|
|---|
| 114 | {
|
|---|
| 115 | dprintf(("WARNING: GetUpdateRgn %x %x %d; invalid handle", hwnd, hrgn, erase));
|
|---|
| 116 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
|
|---|
| 117 | if(wnd) RELEASE_WNDOBJ(wnd);
|
|---|
| 118 | return ERROR_W;
|
|---|
| 119 | }
|
|---|
| 120 | lComplexity = WinQueryUpdateRegion(wnd->getOS2WindowHandle(), hrgn);
|
|---|
| 121 | if(lComplexity == RGN_ERROR) {
|
|---|
| 122 | dprintf(("WARNING: GetUpdateRgn %x %x %d; RGN_ERROR", hwnd, hrgn, erase));
|
|---|
| 123 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
|
|---|
| 124 | RELEASE_WNDOBJ(wnd);
|
|---|
| 125 | return ERROR_W;
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | if(lComplexity != RGN_NULL)
|
|---|
| 129 | {
|
|---|
| 130 | if(!setWinDeviceRegionFromPMDeviceRegion(hrgn, hrgn, NULL, wnd->getOS2WindowHandle()))
|
|---|
| 131 | {
|
|---|
| 132 | dprintf(("WARNING: GetUpdateRgn %x %x %d; setWinDeviceRegionFromPMDeviceRegion failed!", hwnd, hrgn, erase));
|
|---|
| 133 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
|
|---|
| 134 | RELEASE_WNDOBJ(wnd);
|
|---|
| 135 | return ERROR_W;
|
|---|
| 136 | }
|
|---|
| 137 | if(erase) sendEraseBkgnd(wnd);
|
|---|
| 138 | }
|
|---|
| 139 | RELEASE_WNDOBJ(wnd);
|
|---|
| 140 | return lComplexity;
|
|---|
| 141 | }
|
|---|
| 142 | //******************************************************************************
|
|---|
| 143 | //TODO: Check
|
|---|
| 144 | //******************************************************************************
|
|---|
| 145 | INT WIN32API ExcludeUpdateRgn(HDC hdc, HWND hwnd)
|
|---|
| 146 | {
|
|---|
| 147 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 148 | pDCData pHps = (pDCData)GpiQueryDCData((HPS)hdc);
|
|---|
| 149 | LONG lComplexity;
|
|---|
| 150 |
|
|---|
| 151 | if(!wnd || !pHps)
|
|---|
| 152 | {
|
|---|
| 153 | dprintf(("WARNING: ExcludeUpdateRgn %x %x; invalid handle", hdc, hwnd));
|
|---|
| 154 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
|
|---|
| 155 | if(wnd) RELEASE_WNDOBJ(wnd);
|
|---|
| 156 | return ERROR_W;
|
|---|
| 157 | }
|
|---|
| 158 | dprintf(("USER32: ExcludeUpdateRgn %x %x", hdc, hwnd));
|
|---|
| 159 |
|
|---|
| 160 | lComplexity = WinExcludeUpdateRegion(pHps->hps, wnd->getOS2WindowHandle());
|
|---|
| 161 | if(lComplexity == RGN_ERROR) {
|
|---|
| 162 | SetLastError(ERROR_INVALID_HANDLE_W); //todo: correct error
|
|---|
| 163 | }
|
|---|
| 164 | else SetLastError(ERROR_SUCCESS_W);
|
|---|
| 165 |
|
|---|
| 166 | RELEASE_WNDOBJ(wnd);
|
|---|
| 167 | return lComplexity; // windows and PM values are identical
|
|---|
| 168 | }
|
|---|
| 169 | /*****************************************************************************
|
|---|
| 170 | * Name : int WIN32API GetWindowRgn
|
|---|
| 171 | * Purpose : The GetWindowRgn function obtains a copy of the window region of a window.
|
|---|
| 172 | * Parameters: HWND hWnd handle to window whose window region is to be obtained
|
|---|
| 173 | * HRGN hRgn handle to region that receives a copy of the window region
|
|---|
| 174 | * Variables :
|
|---|
| 175 | * Result : NULLREGION, SIMPLEREGION, COMPLEXREGION, ERROR
|
|---|
| 176 | * Remark :
|
|---|
| 177 | * Status : UNTESTED STUB
|
|---|
| 178 | *
|
|---|
| 179 | * Author : Patrick Haller [Thu, 1998/02/26 11:55]
|
|---|
| 180 | *****************************************************************************/
|
|---|
| 181 |
|
|---|
| 182 | int WIN32API GetWindowRgn(HWND hwnd, HRGN hRgn)
|
|---|
| 183 | {
|
|---|
| 184 | Win32BaseWindow *window;
|
|---|
| 185 | HRGN hWindowRegion;
|
|---|
| 186 |
|
|---|
| 187 | window = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 188 | if(!window) {
|
|---|
| 189 | dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
|
|---|
| 190 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
|
|---|
| 191 | return 0;
|
|---|
| 192 | }
|
|---|
| 193 | dprintf(("USER32:GetWindowRgn (%x,%x)", hwnd, hRgn));
|
|---|
| 194 | hWindowRegion = window->GetWindowRegion();
|
|---|
| 195 | RELEASE_WNDOBJ(window);
|
|---|
| 196 | return CombineRgn(hRgn, hWindowRegion, 0, RGN_COPY_W);
|
|---|
| 197 | }
|
|---|
| 198 | /*****************************************************************************
|
|---|
| 199 | * Name : int WIN32API SetWindowRgn
|
|---|
| 200 | * Purpose : The SetWindowRgn function sets the window region of a window. The
|
|---|
| 201 | * window region determines the area within the window where the
|
|---|
| 202 | * operating system permits drawing. The operating system does not
|
|---|
| 203 | * display any portion of a window that lies outside of the window region
|
|---|
| 204 | * When this function is called, the system sends the WM_WINDOWPOSCHANGING and
|
|---|
| 205 | * WM_WINDOWPOSCHANGED messages to the window.
|
|---|
| 206 | *
|
|---|
| 207 | * Parameters: HWND hWnd handle to window whose window region is to be set
|
|---|
| 208 | * HRGN hRgn handle to region
|
|---|
| 209 | * BOOL bRedraw window redraw flag
|
|---|
| 210 | * Variables :
|
|---|
| 211 | * Result : If the function succeeds, the return value is non-zero.
|
|---|
| 212 | * If the function fails, the return value is zero.
|
|---|
| 213 | * Remark :
|
|---|
| 214 | * Status : UNTESTED STUB
|
|---|
| 215 | *
|
|---|
| 216 | * Author : Patrick Haller [Thu, 1998/02/26 11:55]
|
|---|
| 217 | *****************************************************************************/
|
|---|
| 218 |
|
|---|
| 219 | int WIN32API SetWindowRgn(HWND hwnd,
|
|---|
| 220 | HRGN hRgn,
|
|---|
| 221 | BOOL bRedraw)
|
|---|
| 222 | {
|
|---|
| 223 | Win32BaseWindow *window;
|
|---|
| 224 | HRGN hWindowRegion;
|
|---|
| 225 |
|
|---|
| 226 | window = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 227 | if(!window) {
|
|---|
| 228 | dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
|
|---|
| 229 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
|
|---|
| 230 | return 0;
|
|---|
| 231 | }
|
|---|
| 232 | dprintf(("USER32:SetWindowRgn (%x,%x,%d)", hwnd, hRgn, bRedraw));
|
|---|
| 233 | if(window->GetWindowRegion()) {
|
|---|
| 234 | DeleteObject(window->GetWindowRegion());
|
|---|
| 235 | }
|
|---|
| 236 | window->SetWindowRegion(hRgn);
|
|---|
| 237 | if(bRedraw) {
|
|---|
| 238 | RedrawWindow(hwnd, 0, 0, RDW_UPDATENOW_W);
|
|---|
| 239 | }
|
|---|
| 240 | RELEASE_WNDOBJ(window);
|
|---|
| 241 | //TODO:
|
|---|
| 242 | // When this function is called, the system sends the WM_WINDOWPOSCHANGING and
|
|---|
| 243 | // WM_WINDOWPOSCHANGED messages to the window.
|
|---|
| 244 | return 1;
|
|---|
| 245 | }
|
|---|
| 246 | //******************************************************************************
|
|---|
| 247 | // WinSetVisibleRgnNotifyProc
|
|---|
| 248 | // To set a notification procedure for visible region changes of a specific window.
|
|---|
| 249 | // The procedure will be called when a WM_VRNENABLED message is posted
|
|---|
| 250 | // with ffVisRgnChanged set to TRUE
|
|---|
| 251 | //
|
|---|
| 252 | // Parameters:
|
|---|
| 253 | // HWND hwnd window handle
|
|---|
| 254 | // VISRGN_NOTIFY_PROC lpNotifyProc notification proc or NULL to clear proc
|
|---|
| 255 | // DWORD dwUserData value used as 3rd parameter during
|
|---|
| 256 | // visible region callback
|
|---|
| 257 | //
|
|---|
| 258 | // NOTE: Internal API
|
|---|
| 259 | //******************************************************************************
|
|---|
| 260 | BOOL WIN32API WinSetVisibleRgnNotifyProc(HWND hwnd, VISRGN_NOTIFY_PROC lpNotifyProc,
|
|---|
| 261 | DWORD dwUserData)
|
|---|
| 262 | {
|
|---|
| 263 | Win32BaseWindow *window;
|
|---|
| 264 |
|
|---|
| 265 | window = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 266 | if(!window) {
|
|---|
| 267 | dprintf(("WinSetVisibleRgnNotifyProc, window %x not found", hwnd));
|
|---|
| 268 | return FALSE;
|
|---|
| 269 | }
|
|---|
| 270 | BOOL ret = window->setVisibleRgnNotifyProc(lpNotifyProc, dwUserData);
|
|---|
| 271 | RELEASE_WNDOBJ(window);
|
|---|
| 272 | return ret;
|
|---|
| 273 | }
|
|---|
| 274 | //******************************************************************************
|
|---|
| 275 | //******************************************************************************
|
|---|