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

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

region changes

File size: 8.6 KB
Line 
1/* $Id: dcrgn.cpp,v 1.2 2000-06-14 13:15:24 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//******************************************************************************
124int WIN32API GetUpdateRgn(HWND hwnd, HRGN hrgn, BOOL erase)
125{
126 LONG lComplexity;
127 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
128
129 hrgn = ObjWinToOS2Region(hrgn);
130 if(!wnd || !hrgn)
131 {
132 dprintf(("WARNING: GetUpdateRgn %x %x %d; invalid handle", hwnd, hrgn, erase));
133 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
134 return ERROR_W;
135 }
136 lComplexity = WinQueryUpdateRegion(wnd->getOS2WindowHandle(), hrgn);
137 if(lComplexity == RGN_ERROR) {
138 dprintf(("WARNING: GetUpdateRgn %x %x %d; RGN_ERROR", hwnd, hrgn, erase));
139 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
140 return ERROR_W;
141 }
142
143 if(lComplexity != RGN_NULL)
144 {
145 if(!setWinDeviceRegionFromPMDeviceRegion(hrgn, hrgn, NULL, wnd->getOS2WindowHandle()))
146 {
147 dprintf(("WARNING: GetUpdateRgn %x %x %d; setWinDeviceRegionFromPMDeviceRegion failed!", hwnd, hrgn, erase));
148 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
149 return ERROR_W;
150 }
151
152 if(erase) sendEraseBkgnd(wnd);
153 }
154
155 return lComplexity;
156}
157//******************************************************************************
158//TODO: Check
159//******************************************************************************
160INT WIN32API ExcludeUpdateRgn(HDC hdc, HWND hwnd)
161{
162 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
163 pDCData pHps = (pDCData)GpiQueryDCData((HPS)hdc);
164 LONG lComplexity;
165
166 if(!wnd || !pHps)
167 {
168 dprintf(("WARNING: ExcludeUpdateRgn %x %x; invalid handle", hdc, hwnd));
169 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
170 return ERROR_W;
171 }
172 dprintf(("USER32: ExcludeUpdateRgn %x %x", hdc, hwnd));
173
174 lComplexity = WinExcludeUpdateRegion(pHps->hps, wnd->getOS2WindowHandle());
175 if(lComplexity == RGN_ERROR) {
176 SetLastError(ERROR_INVALID_HANDLE_W); //todo: correct error
177 }
178 else SetLastError(ERROR_SUCCESS_W);
179 return lComplexity; // windows and PM values are identical
180}
181/*****************************************************************************
182 * Name : int WIN32API GetWindowRgn
183 * Purpose : The GetWindowRgn function obtains a copy of the window region of a window.
184 * Parameters: HWND hWnd handle to window whose window region is to be obtained
185 * HRGN hRgn handle to region that receives a copy of the window region
186 * Variables :
187 * Result : NULLREGION, SIMPLEREGION, COMPLEXREGION, ERROR
188 * Remark :
189 * Status : UNTESTED STUB
190 *
191 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
192 *****************************************************************************/
193
194int WIN32API GetWindowRgn(HWND hwnd, HRGN hRgn)
195{
196 Win32BaseWindow *window;
197 HRGN hWindowRegion;
198
199 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
200 if(!window) {
201 dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
202 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
203 return 0;
204 }
205 dprintf(("USER32:GetWindowRgn (%x,%x)", hwnd, hRgn));
206 hWindowRegion = window->GetWindowRegion();
207
208 return O32_CombineRgn(hRgn, hWindowRegion, 0, RGN_COPY_W);
209}
210/*****************************************************************************
211 * Name : int WIN32API SetWindowRgn
212 * Purpose : The SetWindowRgn function sets the window region of a window. The
213 * window region determines the area within the window where the
214 * operating system permits drawing. The operating system does not
215 * display any portion of a window that lies outside of the window region
216 * When this function is called, the system sends the WM_WINDOWPOSCHANGING and
217 * WM_WINDOWPOSCHANGED messages to the window.
218 *
219 * Parameters: HWND hWnd handle to window whose window region is to be set
220 * HRGN hRgn handle to region
221 * BOOL bRedraw window redraw flag
222 * Variables :
223 * Result : If the function succeeds, the return value is non-zero.
224 * If the function fails, the return value is zero.
225 * Remark :
226 * Status : UNTESTED STUB
227 *
228 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
229 *****************************************************************************/
230
231int WIN32API SetWindowRgn(HWND hwnd,
232 HRGN hRgn,
233 BOOL bRedraw)
234{
235 Win32BaseWindow *window;
236 HRGN hWindowRegion;
237
238 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
239 if(!window) {
240 dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
241 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
242 return 0;
243 }
244 dprintf(("USER32:SetWindowRgn (%x,%x,%d)", hwnd, hRgn, bRedraw));
245 if(window->GetWindowRegion()) {
246 O32_DeleteObject(window->GetWindowRegion());
247 }
248 window->SetWindowRegion(hRgn);
249 if(bRedraw) {
250 RedrawWindow(hwnd, 0, 0, RDW_UPDATENOW_W);
251 }
252//TODO:
253// When this function is called, the system sends the WM_WINDOWPOSCHANGING and
254// WM_WINDOWPOSCHANGED messages to the window.
255 return 1;
256}
257//******************************************************************************
258//******************************************************************************
Note: See TracBrowser for help on using the repository browser.