some gcc 3.4.5 fixed; but not all we need
[reactos.git] / reactos / subsystems / win32 / win32k / objects / rect.c
1 /*
2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /* $Id$ */
20
21 #include <w32k.h>
22
23 #define NDEBUG
24 #include <debug.h>
25
26 /* FUNCTIONS *****************************************************************/
27
28 VOID FASTCALL
29 IntGdiSetEmptyRect(PRECT Rect)
30 {
31 Rect->left = Rect->right = Rect->top = Rect->bottom = 0;
32 }
33
34 BOOL STDCALL
35 NtGdiSetEmptyRect(PRECT UnsafeRect)
36 {
37 RECT Rect;
38 NTSTATUS Status = STATUS_SUCCESS;
39
40 IntGdiSetEmptyRect(&Rect);
41
42 _SEH_TRY
43 {
44 ProbeForWrite(UnsafeRect,
45 sizeof(RECT),
46 1);
47 *UnsafeRect = Rect;
48 }
49 _SEH_HANDLE
50 {
51 Status = _SEH_GetExceptionCode();
52 }
53 _SEH_END;
54
55 if (! NT_SUCCESS(Status))
56 {
57 SetLastNtError(Status);
58 return FALSE;
59 }
60
61 return TRUE;
62 }
63
64 BOOL FASTCALL
65 IntGdiIsEmptyRect(const RECT* Rect)
66 {
67 return(Rect->left >= Rect->right || Rect->top >= Rect->bottom);
68 }
69
70 BOOL STDCALL
71 NtGdiIsEmptyRect(const RECT* UnsafeRect)
72 {
73 RECT Rect = {0};
74 NTSTATUS Status = STATUS_SUCCESS;
75
76 _SEH_TRY
77 {
78 ProbeForRead(UnsafeRect,
79 sizeof(RECT),
80 1);
81 Rect = *UnsafeRect;
82 }
83 _SEH_HANDLE
84 {
85 Status = _SEH_GetExceptionCode();
86 }
87 _SEH_END;
88 if (! NT_SUCCESS(Status))
89 {
90 SetLastNtError(Status);
91 return FALSE;
92 }
93
94 return IntGdiIsEmptyRect(&Rect);
95 }
96
97 VOID FASTCALL
98 IntGdiOffsetRect(LPRECT Rect, INT x, INT y)
99 {
100 Rect->left += x;
101 Rect->right += x;
102 Rect->top += y;
103 Rect->bottom += y;
104 }
105
106 BOOL STDCALL
107 NtGdiOffsetRect(LPRECT UnsafeRect, INT x, INT y)
108 {
109 RECT Rect = {0};
110 NTSTATUS Status = STATUS_SUCCESS;
111
112 _SEH_TRY
113 {
114 ProbeForRead(UnsafeRect,
115 sizeof(RECT),
116 1);
117 Rect = *UnsafeRect;
118 }
119 _SEH_HANDLE
120 {
121 Status = _SEH_GetExceptionCode();
122 }
123 _SEH_END;
124 if (! NT_SUCCESS(Status))
125 {
126 SetLastNtError(Status);
127 return FALSE;
128 }
129
130 IntGdiOffsetRect(&Rect, x, y);
131
132 _SEH_TRY
133 {
134 ProbeForWrite(UnsafeRect,
135 sizeof(RECT),
136 1);
137 *UnsafeRect = Rect;
138 }
139 _SEH_HANDLE
140 {
141 Status = _SEH_GetExceptionCode();
142 }
143 _SEH_END;
144 if (! NT_SUCCESS(Status))
145 {
146 SetLastNtError(Status);
147 return FALSE;
148 }
149
150 return TRUE;
151 }
152
153 BOOL FASTCALL
154 IntGdiUnionRect(PRECT Dest, const RECT* Src1, const RECT* Src2)
155 {
156 if (IntGdiIsEmptyRect(Src1))
157 {
158 if (IntGdiIsEmptyRect(Src2))
159 {
160 IntGdiSetEmptyRect(Dest);
161 return FALSE;
162 }
163 else
164 {
165 *Dest = *Src2;
166 }
167 }
168 else
169 {
170 if (IntGdiIsEmptyRect(Src2))
171 {
172 *Dest = *Src1;
173 }
174 else
175 {
176 Dest->left = min(Src1->left, Src2->left);
177 Dest->top = min(Src1->top, Src2->top);
178 Dest->right = max(Src1->right, Src2->right);
179 Dest->bottom = max(Src1->bottom, Src2->bottom);
180 }
181 }
182
183 return TRUE;
184 }
185
186 BOOL STDCALL
187 NtGdiUnionRect(PRECT UnsafeDest, const RECT* UnsafeSrc1, const RECT* UnsafeSrc2)
188 {
189 RECT Dest, Src1 = {0}, Src2 = {0};
190 NTSTATUS Status = STATUS_SUCCESS;
191 BOOL Ret = FALSE;
192
193 _SEH_TRY
194 {
195 ProbeForRead(UnsafeSrc1,
196 sizeof(RECT),
197 1);
198 ProbeForRead(UnsafeSrc2,
199 sizeof(RECT),
200 1);
201 Src1 = *UnsafeSrc1;
202 Src2 = *UnsafeSrc2;
203 }
204 _SEH_HANDLE
205 {
206 Status = _SEH_GetExceptionCode();
207 }
208 _SEH_END;
209 if (! NT_SUCCESS(Status))
210 {
211 SetLastNtError(Status);
212 return FALSE;
213 }
214
215 Ret = IntGdiUnionRect(&Dest, &Src1, &Src2);
216
217 if (Ret)
218 {
219 _SEH_TRY
220 {
221 ProbeForWrite(UnsafeDest,
222 sizeof(RECT),
223 1);
224 *UnsafeDest = Dest;
225 }
226 _SEH_HANDLE
227 {
228 Status = _SEH_GetExceptionCode();
229 }
230 _SEH_END;
231 if (! NT_SUCCESS(Status))
232 {
233 SetLastNtError(Status);
234 return FALSE;
235 }
236 }
237
238 return Ret;
239 }
240
241 VOID FASTCALL
242 IntGdiSetRect(PRECT Rect, INT left, INT top, INT right, INT bottom)
243 {
244 Rect->left = left;
245 Rect->top = top;
246 Rect->right = right;
247 Rect->bottom = bottom;
248 }
249
250 BOOL STDCALL
251 NtGdiSetRect(PRECT UnsafeRect, INT left, INT top, INT right, INT bottom)
252 {
253 RECT Rect;
254 NTSTATUS Status = STATUS_SUCCESS;
255
256 IntGdiSetRect(&Rect, left, top, right, bottom);
257
258 _SEH_TRY
259 {
260 ProbeForWrite(UnsafeRect,
261 sizeof(RECT),
262 1);
263 *UnsafeRect = Rect;
264 }
265 _SEH_HANDLE
266 {
267 Status = _SEH_GetExceptionCode();
268 }
269 _SEH_END;
270 if (! NT_SUCCESS(Status))
271 {
272 SetLastNtError(Status);
273 return FALSE;
274 }
275
276 return TRUE;
277 }
278
279 BOOL FASTCALL
280 IntGdiIntersectRect(PRECT Dest, const RECT* Src1, const RECT* Src2)
281 {
282 if (IntGdiIsEmptyRect(Src1) || IntGdiIsEmptyRect(Src2) ||
283 Src1->left >= Src2->right || Src2->left >= Src1->right ||
284 Src1->top >= Src2->bottom || Src2->top >= Src1->bottom)
285 {
286 IntGdiSetEmptyRect(Dest);
287 return FALSE;
288 }
289
290 Dest->left = max(Src1->left, Src2->left);
291 Dest->right = min(Src1->right, Src2->right);
292 Dest->top = max(Src1->top, Src2->top);
293 Dest->bottom = min(Src1->bottom, Src2->bottom);
294
295 return TRUE;
296 }
297
298 BOOL STDCALL
299 NtGdiIntersectRect(PRECT UnsafeDest, const RECT* UnsafeSrc1, const RECT* UnsafeSrc2)
300 {
301 RECT Dest, Src1, Src2 = {0};
302 NTSTATUS Status = STATUS_SUCCESS;
303 BOOL Ret = FALSE;
304
305 _SEH_TRY
306 {
307 ProbeForRead(UnsafeSrc1,
308 sizeof(RECT),
309 1);
310 ProbeForRead(UnsafeSrc2,
311 sizeof(RECT),
312 1);
313 Src1 = *UnsafeSrc1;
314 Src2 = *UnsafeSrc2;
315 }
316 _SEH_HANDLE
317 {
318 Status = _SEH_GetExceptionCode();
319 }
320 _SEH_END;
321 if (! NT_SUCCESS(Status))
322 {
323 SetLastNtError(Status);
324 return FALSE;
325 }
326
327 Ret = IntGdiIntersectRect(&Dest, &Src2, &Src2);
328
329 if (Ret)
330 {
331 _SEH_TRY
332 {
333 ProbeForWrite(UnsafeDest,
334 sizeof(RECT),
335 1);
336 *UnsafeDest = Dest;
337 }
338 _SEH_HANDLE
339 {
340 Status = _SEH_GetExceptionCode();
341 }
342 _SEH_END;
343 if (! NT_SUCCESS(Status))
344 {
345 SetLastNtError(Status);
346 return FALSE;
347 }
348 }
349
350 return Ret;
351 }
352
353 /* EOF */