[10316] | 1 | /* $Id: dcrgn.cpp,v 1.9 2003-11-12 14:10:19 sandervl Exp $ */
|
---|
[3679] | 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 <math.h>
|
---|
| 30 | #include <limits.h>
|
---|
[21916] | 31 | #include "win32wbase.h"
|
---|
[3679] | 32 | #include "oslibwin.h"
|
---|
| 33 | #include "oslibmsg.h"
|
---|
| 34 | #include <dcdata.h>
|
---|
[3705] | 35 | #include <objhandle.h>
|
---|
| 36 | #include <wingdi32.h>
|
---|
[3679] | 37 |
|
---|
| 38 | #define INCLUDED_BY_DC
|
---|
| 39 | #include "dc.h"
|
---|
| 40 |
|
---|
| 41 | #define DBG_LOCALLOG DBG_dcrgn
|
---|
| 42 | #include "dbglocal.h"
|
---|
| 43 |
|
---|
[10316] | 44 | #ifdef DEBUG
|
---|
| 45 | //#define dprintfRegion(a,b,c) if(DbgEnabledLvl2USER32[DBG_LOCALLOG] == 1) dprintfRegion1(a,b,c)
|
---|
| 46 | //#define dprintfRegion(a,b,c) dprintfRegion1(a,b,c)
|
---|
| 47 |
|
---|
| 48 | static void dprintfRegion(HWND hWnd, HRGN hrgnClip)
|
---|
| 49 | {
|
---|
| 50 | RGNRECT rgnRect = {0, 16, 0, RECTDIR_LFRT_TOPBOT};
|
---|
| 51 | RECTL rectRegion[16];
|
---|
| 52 | APIRET rc;
|
---|
| 53 | HDC hdc;
|
---|
| 54 |
|
---|
| 55 | hdc = GetDCEx(hWnd, NULL, DCX_CACHE_W|DCX_USESTYLE_W);
|
---|
| 56 | dprintf(("dprintfRegion %x %x", hWnd, hdc));
|
---|
| 57 | rc = GpiQueryRegionRects(hdc, hrgnClip, NULL, &rgnRect, &rectRegion[0]);
|
---|
| 58 | for(int i=0;i<rgnRect.crcReturned;i++) {
|
---|
| 59 | dprintf(("(%d,%d)(%d,%d)", rectRegion[i].xLeft, rectRegion[i].yBottom, rectRegion[i].xRight, rectRegion[i].yTop));
|
---|
| 60 | }
|
---|
| 61 | ReleaseDC(hWnd, hdc);
|
---|
| 62 | }
|
---|
| 63 | #else
|
---|
| 64 | #define dprintfRegion(b,c)
|
---|
| 65 | #endif
|
---|
| 66 |
|
---|
[21916] | 67 | extern "C" {
|
---|
| 68 |
|
---|
[3679] | 69 | //******************************************************************************
|
---|
| 70 | //******************************************************************************
|
---|
[3705] | 71 | BOOL WIN32API GetUpdateRect(HWND hwnd, LPRECT pRect, BOOL erase)
|
---|
[3679] | 72 | {
|
---|
[5685] | 73 | if (!hwnd)
|
---|
| 74 | {
|
---|
| 75 | dprintf(("GetUpdateRect %x %x %d -> invalid handle!!", hwnd, pRect, erase));
|
---|
| 76 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
|
---|
| 77 | return FALSE;
|
---|
| 78 | }
|
---|
[3679] | 79 |
|
---|
[5685] | 80 | RECTL rectl, rectlClient;
|
---|
| 81 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
[3679] | 82 |
|
---|
[5685] | 83 | if (!wnd)
|
---|
| 84 | {
|
---|
| 85 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
|
---|
| 86 | dprintf(("GetUpdateRect %x %x %d -> invalid handle!!", hwnd, pRect, erase));
|
---|
| 87 | return FALSE;
|
---|
| 88 | }
|
---|
[3679] | 89 |
|
---|
[5685] | 90 | dprintf(("GetUpdateRect %x %x %d", hwnd, pRect, erase));
|
---|
[3679] | 91 |
|
---|
[9933] | 92 | //check if the application previously didn't handle a WM_PAINT msg properly
|
---|
| 93 | wnd->checkForDirtyUpdateRegion();
|
---|
| 94 |
|
---|
[5685] | 95 | BOOL updateRegionExists = WinQueryUpdateRect(wnd->getOS2WindowHandle(), pRect ? &rectl : NULL);
|
---|
| 96 | if (!pRect) {
|
---|
[5687] | 97 | dprintf(("GetUpdateRect returned %d", updateRegionExists));
|
---|
[5935] | 98 | RELEASE_WNDOBJ(wnd);
|
---|
[5685] | 99 | return (updateRegionExists);
|
---|
| 100 | }
|
---|
[3679] | 101 |
|
---|
[5685] | 102 | if(updateRegionExists)
|
---|
| 103 | {
|
---|
[3679] | 104 | //CB: for PM empty rect is valid
|
---|
| 105 | if ((rectl.xLeft == rectl.xRight) || (rectl.yTop == rectl.yBottom)) {
|
---|
[5685] | 106 | if(pRect) {
|
---|
| 107 | pRect->left = pRect->top = pRect->right = pRect->bottom = 0;
|
---|
| 108 | }
|
---|
[5935] | 109 | RELEASE_WNDOBJ(wnd);
|
---|
[5685] | 110 | return FALSE;
|
---|
[3679] | 111 | }
|
---|
[5685] | 112 | mapOS2ToWin32Rect(wnd->getClientHeight(), (PRECTLOS2)&rectl, pRect);
|
---|
[3679] | 113 |
|
---|
| 114 | if(wnd->isOwnDC() && GetMapMode(wnd->getOwnDC()) != MM_TEXT_W)
|
---|
| 115 | {
|
---|
[5685] | 116 | DPtoLP(wnd->getOwnDC(), (LPPOINT)pRect, 2);
|
---|
[3679] | 117 | }
|
---|
| 118 | if (erase)
|
---|
[5685] | 119 | sendEraseBkgnd (wnd);
|
---|
[3679] | 120 | }
|
---|
| 121 | else
|
---|
| 122 | {
|
---|
| 123 | if(pRect) {
|
---|
[5685] | 124 | pRect->left = pRect->top = pRect->right = pRect->bottom = 0;
|
---|
[3679] | 125 | }
|
---|
| 126 | }
|
---|
| 127 |
|
---|
[5687] | 128 | dprintf(("GetUpdateRect returned (%d,%d)(%d,%d)", pRect->left, pRect->top, pRect->right, pRect->bottom));
|
---|
[5935] | 129 | RELEASE_WNDOBJ(wnd);
|
---|
[3679] | 130 | return updateRegionExists;
|
---|
| 131 | }
|
---|
| 132 | //******************************************************************************
|
---|
[3725] | 133 | //TODO: Seems to return region in window coordinates instead of client coordinates
|
---|
[3679] | 134 | //******************************************************************************
|
---|
[3705] | 135 | int WIN32API GetUpdateRgn(HWND hwnd, HRGN hrgn, BOOL erase)
|
---|
[3679] | 136 | {
|
---|
[5685] | 137 | LONG lComplexity;
|
---|
| 138 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
[3679] | 139 |
|
---|
[5685] | 140 | hrgn = ObjWinToOS2Region(hrgn);
|
---|
| 141 | if(!wnd || !hrgn)
|
---|
| 142 | {
|
---|
| 143 | dprintf(("WARNING: GetUpdateRgn %x %x %d; invalid handle", hwnd, hrgn, erase));
|
---|
| 144 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
|
---|
[5935] | 145 | if(wnd) RELEASE_WNDOBJ(wnd);
|
---|
[5685] | 146 | return ERROR_W;
|
---|
| 147 | }
|
---|
[9933] | 148 | //check if the application previously didn't handle a WM_PAINT msg properly
|
---|
| 149 | wnd->checkForDirtyUpdateRegion();
|
---|
| 150 |
|
---|
[5685] | 151 | lComplexity = WinQueryUpdateRegion(wnd->getOS2WindowHandle(), hrgn);
|
---|
| 152 | if(lComplexity == RGN_ERROR) {
|
---|
| 153 | dprintf(("WARNING: GetUpdateRgn %x %x %d; RGN_ERROR", hwnd, hrgn, erase));
|
---|
| 154 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
|
---|
[5935] | 155 | RELEASE_WNDOBJ(wnd);
|
---|
[5685] | 156 | return ERROR_W;
|
---|
| 157 | }
|
---|
[3679] | 158 |
|
---|
[5685] | 159 | if(lComplexity != RGN_NULL)
|
---|
| 160 | {
|
---|
[10316] | 161 | dprintfRegion(hwnd, hrgn);
|
---|
[5685] | 162 | if(!setWinDeviceRegionFromPMDeviceRegion(hrgn, hrgn, NULL, wnd->getOS2WindowHandle()))
|
---|
| 163 | {
|
---|
| 164 | dprintf(("WARNING: GetUpdateRgn %x %x %d; setWinDeviceRegionFromPMDeviceRegion failed!", hwnd, hrgn, erase));
|
---|
| 165 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
|
---|
[5935] | 166 | RELEASE_WNDOBJ(wnd);
|
---|
[5685] | 167 | return ERROR_W;
|
---|
| 168 | }
|
---|
[3705] | 169 | if(erase) sendEraseBkgnd(wnd);
|
---|
[5685] | 170 | }
|
---|
[5935] | 171 | RELEASE_WNDOBJ(wnd);
|
---|
[5685] | 172 | return lComplexity;
|
---|
[3679] | 173 | }
|
---|
| 174 | //******************************************************************************
|
---|
[10316] | 175 | //TODO: Seems to return region in window coordinates instead of client coordinates
|
---|
| 176 | //******************************************************************************
|
---|
| 177 | int WIN32API GetUpdateRgnFrame(HWND hwnd, HRGN hrgn)
|
---|
| 178 | {
|
---|
| 179 | LONG lComplexity;
|
---|
| 180 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
| 181 |
|
---|
| 182 | hrgn = ObjWinToOS2Region(hrgn);
|
---|
| 183 | if(!wnd || !hrgn)
|
---|
| 184 | {
|
---|
| 185 | dprintf(("WARNING: GetUpdateRgnFrame %x %x invalid handle", hwnd, hrgn));
|
---|
| 186 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
|
---|
| 187 | if(wnd) RELEASE_WNDOBJ(wnd);
|
---|
| 188 | return ERROR_W;
|
---|
| 189 | }
|
---|
| 190 | lComplexity = WinQueryUpdateRegion(wnd->getOS2FrameWindowHandle(), hrgn);
|
---|
| 191 | if(lComplexity == RGN_ERROR) {
|
---|
| 192 | dprintf(("WARNING: GetUpdateRgnFrame %x %x RGN_ERROR", hwnd, hrgn));
|
---|
| 193 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
|
---|
| 194 | RELEASE_WNDOBJ(wnd);
|
---|
| 195 | return ERROR_W;
|
---|
| 196 | }
|
---|
| 197 |
|
---|
| 198 | if(lComplexity != RGN_NULL)
|
---|
| 199 | {
|
---|
| 200 | dprintfRegion(hwnd, hrgn);
|
---|
| 201 | if(!setWinDeviceRegionFromPMDeviceRegion(hrgn, hrgn, NULL, wnd->getOS2FrameWindowHandle()))
|
---|
| 202 | {
|
---|
| 203 | dprintf(("WARNING: GetUpdateRgnFrame %x %x; setWinDeviceRegionFromPMDeviceRegion failed!", hwnd, hrgn));
|
---|
| 204 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
|
---|
| 205 | RELEASE_WNDOBJ(wnd);
|
---|
| 206 | return ERROR_W;
|
---|
| 207 | }
|
---|
| 208 | }
|
---|
| 209 | RELEASE_WNDOBJ(wnd);
|
---|
| 210 | return lComplexity;
|
---|
| 211 | }
|
---|
| 212 | //******************************************************************************
|
---|
[3705] | 213 | //TODO: Check
|
---|
[3679] | 214 | //******************************************************************************
|
---|
[3705] | 215 | INT WIN32API ExcludeUpdateRgn(HDC hdc, HWND hwnd)
|
---|
[3679] | 216 | {
|
---|
[5685] | 217 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
| 218 | pDCData pHps = (pDCData)GpiQueryDCData((HPS)hdc);
|
---|
| 219 | LONG lComplexity;
|
---|
[3679] | 220 |
|
---|
[5685] | 221 | if(!wnd || !pHps)
|
---|
| 222 | {
|
---|
| 223 | dprintf(("WARNING: ExcludeUpdateRgn %x %x; invalid handle", hdc, hwnd));
|
---|
| 224 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
|
---|
[5935] | 225 | if(wnd) RELEASE_WNDOBJ(wnd);
|
---|
[5685] | 226 | return ERROR_W;
|
---|
| 227 | }
|
---|
| 228 | dprintf(("USER32: ExcludeUpdateRgn %x %x", hdc, hwnd));
|
---|
[3705] | 229 |
|
---|
[5685] | 230 | lComplexity = WinExcludeUpdateRegion(pHps->hps, wnd->getOS2WindowHandle());
|
---|
| 231 | if(lComplexity == RGN_ERROR) {
|
---|
| 232 | SetLastError(ERROR_INVALID_HANDLE_W); //todo: correct error
|
---|
| 233 | }
|
---|
| 234 | else SetLastError(ERROR_SUCCESS_W);
|
---|
[5935] | 235 |
|
---|
| 236 | RELEASE_WNDOBJ(wnd);
|
---|
[5685] | 237 | return lComplexity; // windows and PM values are identical
|
---|
[3679] | 238 | }
|
---|
| 239 | /*****************************************************************************
|
---|
| 240 | * Name : int WIN32API GetWindowRgn
|
---|
| 241 | * Purpose : The GetWindowRgn function obtains a copy of the window region of a window.
|
---|
| 242 | * Parameters: HWND hWnd handle to window whose window region is to be obtained
|
---|
| 243 | * HRGN hRgn handle to region that receives a copy of the window region
|
---|
| 244 | * Variables :
|
---|
| 245 | * Result : NULLREGION, SIMPLEREGION, COMPLEXREGION, ERROR
|
---|
| 246 | * Remark :
|
---|
| 247 | * Status : UNTESTED STUB
|
---|
| 248 | *
|
---|
| 249 | * Author : Patrick Haller [Thu, 1998/02/26 11:55]
|
---|
| 250 | *****************************************************************************/
|
---|
| 251 |
|
---|
| 252 | int WIN32API GetWindowRgn(HWND hwnd, HRGN hRgn)
|
---|
| 253 | {
|
---|
[5685] | 254 | Win32BaseWindow *window;
|
---|
| 255 | HRGN hWindowRegion;
|
---|
[3679] | 256 |
|
---|
| 257 | window = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
| 258 | if(!window) {
|
---|
| 259 | dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
|
---|
| 260 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
|
---|
| 261 | return 0;
|
---|
| 262 | }
|
---|
| 263 | dprintf(("USER32:GetWindowRgn (%x,%x)", hwnd, hRgn));
|
---|
| 264 | hWindowRegion = window->GetWindowRegion();
|
---|
[5935] | 265 | RELEASE_WNDOBJ(window);
|
---|
[3725] | 266 | return CombineRgn(hRgn, hWindowRegion, 0, RGN_COPY_W);
|
---|
[3679] | 267 | }
|
---|
| 268 | /*****************************************************************************
|
---|
| 269 | * Name : int WIN32API SetWindowRgn
|
---|
| 270 | * Purpose : The SetWindowRgn function sets the window region of a window. The
|
---|
| 271 | * window region determines the area within the window where the
|
---|
| 272 | * operating system permits drawing. The operating system does not
|
---|
| 273 | * display any portion of a window that lies outside of the window region
|
---|
| 274 | * When this function is called, the system sends the WM_WINDOWPOSCHANGING and
|
---|
| 275 | * WM_WINDOWPOSCHANGED messages to the window.
|
---|
| 276 | *
|
---|
| 277 | * Parameters: HWND hWnd handle to window whose window region is to be set
|
---|
| 278 | * HRGN hRgn handle to region
|
---|
| 279 | * BOOL bRedraw window redraw flag
|
---|
| 280 | * Variables :
|
---|
| 281 | * Result : If the function succeeds, the return value is non-zero.
|
---|
| 282 | * If the function fails, the return value is zero.
|
---|
| 283 | * Remark :
|
---|
| 284 | * Status : UNTESTED STUB
|
---|
| 285 | *
|
---|
| 286 | * Author : Patrick Haller [Thu, 1998/02/26 11:55]
|
---|
| 287 | *****************************************************************************/
|
---|
| 288 |
|
---|
| 289 | int WIN32API SetWindowRgn(HWND hwnd,
|
---|
| 290 | HRGN hRgn,
|
---|
| 291 | BOOL bRedraw)
|
---|
| 292 | {
|
---|
[5685] | 293 | Win32BaseWindow *window;
|
---|
| 294 | HRGN hWindowRegion;
|
---|
[3679] | 295 |
|
---|
| 296 | window = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
| 297 | if(!window) {
|
---|
| 298 | dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
|
---|
| 299 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
|
---|
| 300 | return 0;
|
---|
| 301 | }
|
---|
| 302 | dprintf(("USER32:SetWindowRgn (%x,%x,%d)", hwnd, hRgn, bRedraw));
|
---|
| 303 | if(window->GetWindowRegion()) {
|
---|
[3725] | 304 | DeleteObject(window->GetWindowRegion());
|
---|
[3679] | 305 | }
|
---|
| 306 | window->SetWindowRegion(hRgn);
|
---|
| 307 | if(bRedraw) {
|
---|
| 308 | RedrawWindow(hwnd, 0, 0, RDW_UPDATENOW_W);
|
---|
| 309 | }
|
---|
[5935] | 310 | RELEASE_WNDOBJ(window);
|
---|
[3679] | 311 | //TODO:
|
---|
| 312 | // When this function is called, the system sends the WM_WINDOWPOSCHANGING and
|
---|
| 313 | // WM_WINDOWPOSCHANGED messages to the window.
|
---|
| 314 | return 1;
|
---|
| 315 | }
|
---|
| 316 | //******************************************************************************
|
---|
[6902] | 317 | // WinSetVisibleRgnNotifyProc
|
---|
| 318 | // To set a notification procedure for visible region changes of a specific window.
|
---|
| 319 | // The procedure will be called when a WM_VRNENABLED message is posted
|
---|
| 320 | // with ffVisRgnChanged set to TRUE
|
---|
| 321 | //
|
---|
| 322 | // Parameters:
|
---|
| 323 | // HWND hwnd window handle
|
---|
| 324 | // VISRGN_NOTIFY_PROC lpNotifyProc notification proc or NULL to clear proc
|
---|
| 325 | // DWORD dwUserData value used as 3rd parameter during
|
---|
| 326 | // visible region callback
|
---|
| 327 | //
|
---|
| 328 | // NOTE: Internal API
|
---|
[3679] | 329 | //******************************************************************************
|
---|
[6902] | 330 | BOOL WIN32API WinSetVisibleRgnNotifyProc(HWND hwnd, VISRGN_NOTIFY_PROC lpNotifyProc,
|
---|
| 331 | DWORD dwUserData)
|
---|
| 332 | {
|
---|
| 333 | Win32BaseWindow *window;
|
---|
| 334 |
|
---|
| 335 | window = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
| 336 | if(!window) {
|
---|
| 337 | dprintf(("WinSetVisibleRgnNotifyProc, window %x not found", hwnd));
|
---|
| 338 | return FALSE;
|
---|
| 339 | }
|
---|
| 340 | BOOL ret = window->setVisibleRgnNotifyProc(lpNotifyProc, dwUserData);
|
---|
| 341 | RELEASE_WNDOBJ(window);
|
---|
| 342 | return ret;
|
---|
| 343 | }
|
---|
| 344 | //******************************************************************************
|
---|
| 345 | //******************************************************************************
|
---|
[21916] | 346 |
|
---|
| 347 | } // extern "C"
|
---|