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