source: trunk/src/user32/dcrgn.cpp@ 5087

Last change on this file since 5087 was 3725, checked in by sandervl, 25 years ago

region fixes

File size: 8.7 KB
Line 
1/* $Id: dcrgn.cpp,v 1.3 2000-06-17 11:56:14 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//******************************************************************************
46BOOL 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 return (updateRegionExists);
70 }
71
72 if(updateRegionExists)
73 {
74 //CB: for PM empty rect is valid
75 if ((rectl.xLeft == rectl.xRight) || (rectl.yTop == rectl.yBottom)) {
76 if(pRect) {
77 pRect->left = pRect->top = pRect->right = pRect->bottom = 0;
78 }
79 return FALSE;
80 }
81 mapWin32ToOS2Rect(wnd->getWindowHeight(), wnd->getClientRectPtr(), (PRECTLOS2)&rectlClient);
82 WinIntersectRect(NULL, &rectl, &rectl, &rectlClient);
83 mapOS2ToWin32RectFrameToClient(wnd, (PRECTLOS2)&rectl, pRect);
84
85 if(wnd->isOwnDC() && GetMapMode(wnd->getOwnDC()) != MM_TEXT_W)
86 {
87 DPtoLP(wnd->getOwnDC(), (LPPOINT)pRect, 2);
88 }
89 if (erase)
90 sendEraseBkgnd (wnd);
91 }
92 else
93 {
94 if(pRect) {
95 pRect->left = pRect->top = pRect->right = pRect->bottom = 0;
96 }
97 }
98
99 return updateRegionExists;
100}
101//******************************************************************************
102//******************************************************************************
103BOOL GetOS2UpdateRect(Win32BaseWindow *window, LPRECT pRect)
104{
105 RECTL rectl;
106 BOOL updateRegionExists = WinQueryUpdateRect(window->getOS2WindowHandle(),pRect ? &rectl:NULL);
107
108 if (!pRect)
109 return (updateRegionExists);
110
111 if (updateRegionExists)
112 {
113 //CB: for PM empty rect is valid
114 if ((rectl.xLeft == rectl.xRight) || (rectl.yTop == rectl.yBottom)) return FALSE;
115 mapOS2ToWin32Rect(window->getWindowHeight(), (PRECTLOS2)&rectl,pRect);
116 }
117 else
118 pRect->left = pRect->top = pRect->right = pRect->bottom = 0;
119
120 return updateRegionExists;
121}
122//******************************************************************************
123//TODO: Seems to return region in window coordinates instead of client coordinates
124//******************************************************************************
125int WIN32API GetUpdateRgn(HWND hwnd, HRGN hrgn, BOOL erase)
126{
127 LONG lComplexity;
128 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
129
130 hrgn = ObjWinToOS2Region(hrgn);
131 if(!wnd || !hrgn)
132 {
133 dprintf(("WARNING: GetUpdateRgn %x %x %d; invalid handle", hwnd, hrgn, erase));
134 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
135 return ERROR_W;
136 }
137 lComplexity = WinQueryUpdateRegion(wnd->getOS2WindowHandle(), hrgn);
138 if(lComplexity == RGN_ERROR) {
139 dprintf(("WARNING: GetUpdateRgn %x %x %d; RGN_ERROR", hwnd, hrgn, erase));
140 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
141 return ERROR_W;
142 }
143
144 if(lComplexity != RGN_NULL)
145 {
146 if(!setWinDeviceRegionFromPMDeviceRegion(hrgn, hrgn, NULL, wnd->getOS2WindowHandle()))
147 {
148 dprintf(("WARNING: GetUpdateRgn %x %x %d; setWinDeviceRegionFromPMDeviceRegion failed!", hwnd, hrgn, erase));
149 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
150 return ERROR_W;
151 }
152
153 if(erase) sendEraseBkgnd(wnd);
154 }
155
156 return lComplexity;
157}
158//******************************************************************************
159//TODO: Check
160//******************************************************************************
161INT WIN32API ExcludeUpdateRgn(HDC hdc, HWND hwnd)
162{
163 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
164 pDCData pHps = (pDCData)GpiQueryDCData((HPS)hdc);
165 LONG lComplexity;
166
167 if(!wnd || !pHps)
168 {
169 dprintf(("WARNING: ExcludeUpdateRgn %x %x; invalid handle", hdc, hwnd));
170 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
171 return ERROR_W;
172 }
173 dprintf(("USER32: ExcludeUpdateRgn %x %x", hdc, hwnd));
174
175 lComplexity = WinExcludeUpdateRegion(pHps->hps, wnd->getOS2WindowHandle());
176 if(lComplexity == RGN_ERROR) {
177 SetLastError(ERROR_INVALID_HANDLE_W); //todo: correct error
178 }
179 else SetLastError(ERROR_SUCCESS_W);
180 return lComplexity; // windows and PM values are identical
181}
182/*****************************************************************************
183 * Name : int WIN32API GetWindowRgn
184 * Purpose : The GetWindowRgn function obtains a copy of the window region of a window.
185 * Parameters: HWND hWnd handle to window whose window region is to be obtained
186 * HRGN hRgn handle to region that receives a copy of the window region
187 * Variables :
188 * Result : NULLREGION, SIMPLEREGION, COMPLEXREGION, ERROR
189 * Remark :
190 * Status : UNTESTED STUB
191 *
192 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
193 *****************************************************************************/
194
195int WIN32API GetWindowRgn(HWND hwnd, HRGN hRgn)
196{
197 Win32BaseWindow *window;
198 HRGN hWindowRegion;
199
200 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
201 if(!window) {
202 dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
203 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
204 return 0;
205 }
206 dprintf(("USER32:GetWindowRgn (%x,%x)", hwnd, hRgn));
207 hWindowRegion = window->GetWindowRegion();
208
209 return CombineRgn(hRgn, hWindowRegion, 0, RGN_COPY_W);
210}
211/*****************************************************************************
212 * Name : int WIN32API SetWindowRgn
213 * Purpose : The SetWindowRgn function sets the window region of a window. The
214 * window region determines the area within the window where the
215 * operating system permits drawing. The operating system does not
216 * display any portion of a window that lies outside of the window region
217 * When this function is called, the system sends the WM_WINDOWPOSCHANGING and
218 * WM_WINDOWPOSCHANGED messages to the window.
219 *
220 * Parameters: HWND hWnd handle to window whose window region is to be set
221 * HRGN hRgn handle to region
222 * BOOL bRedraw window redraw flag
223 * Variables :
224 * Result : If the function succeeds, the return value is non-zero.
225 * If the function fails, the return value is zero.
226 * Remark :
227 * Status : UNTESTED STUB
228 *
229 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
230 *****************************************************************************/
231
232int WIN32API SetWindowRgn(HWND hwnd,
233 HRGN hRgn,
234 BOOL bRedraw)
235{
236 Win32BaseWindow *window;
237 HRGN hWindowRegion;
238
239 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
240 if(!window) {
241 dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
242 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
243 return 0;
244 }
245 dprintf(("USER32:SetWindowRgn (%x,%x,%d)", hwnd, hRgn, bRedraw));
246 if(window->GetWindowRegion()) {
247 DeleteObject(window->GetWindowRegion());
248 }
249 window->SetWindowRegion(hRgn);
250 if(bRedraw) {
251 RedrawWindow(hwnd, 0, 0, RDW_UPDATENOW_W);
252 }
253//TODO:
254// When this function is called, the system sends the WM_WINDOWPOSCHANGING and
255// WM_WINDOWPOSCHANGED messages to the window.
256 return 1;
257}
258//******************************************************************************
259//******************************************************************************
Note: See TracBrowser for help on using the repository browser.