Protect against an interrupt-pending signal recursion.
[wine/multimedia.git] / windows / rect.c
blob73c516bb42462a78e0468a33283c98b3048d07ab
1 /*
2 * Rectangle-related functions
4 * Copyright 1993, 1996 Alexandre Julliard
6 */
8 #include "windef.h"
9 #include "wingdi.h"
10 #include "wine/winuser16.h"
11 #include "winuser.h"
13 /***********************************************************************
14 * SetRect (USER.72)
16 void WINAPI SetRect16( LPRECT16 rect, INT16 left, INT16 top,
17 INT16 right, INT16 bottom )
19 rect->left = left;
20 rect->right = right;
21 rect->top = top;
22 rect->bottom = bottom;
26 /***********************************************************************
27 * SetRect (USER32.@)
29 BOOL WINAPI SetRect( LPRECT rect, INT left, INT top,
30 INT right, INT bottom )
32 rect->left = left;
33 rect->right = right;
34 rect->top = top;
35 rect->bottom = bottom;
36 return TRUE;
40 /***********************************************************************
41 * SetRectEmpty (USER.73)
43 void WINAPI SetRectEmpty16( LPRECT16 rect )
45 rect->left = rect->right = rect->top = rect->bottom = 0;
49 /***********************************************************************
50 * SetRectEmpty (USER32.@)
52 BOOL WINAPI SetRectEmpty( LPRECT rect )
54 rect->left = rect->right = rect->top = rect->bottom = 0;
55 return TRUE;
59 /***********************************************************************
60 * CopyRect (USER.74)
62 BOOL16 WINAPI CopyRect16( RECT16 *dest, const RECT16 *src )
64 *dest = *src;
65 return TRUE;
69 /***********************************************************************
70 * CopyRect (USER32.@)
72 BOOL WINAPI CopyRect( RECT *dest, const RECT *src )
74 if (!dest || !src)
75 return FALSE;
76 *dest = *src;
77 return TRUE;
81 /***********************************************************************
82 * IsRectEmpty (USER.75)
84 * Bug compat: Windows checks for 0 or negative width/height.
86 BOOL16 WINAPI IsRectEmpty16( const RECT16 *rect )
88 return ((rect->left >= rect->right) || (rect->top >= rect->bottom));
92 /***********************************************************************
93 * IsRectEmpty (USER32.@)
95 * Bug compat: Windows checks for 0 or negative width/height.
97 BOOL WINAPI IsRectEmpty( const RECT *rect )
99 return ((rect->left >= rect->right) || (rect->top >= rect->bottom));
103 /***********************************************************************
104 * PtInRect (USER.76)
106 BOOL16 WINAPI PtInRect16( const RECT16 *rect, POINT16 pt )
108 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
109 (pt.y >= rect->top) && (pt.y < rect->bottom));
113 /***********************************************************************
114 * PtInRect (USER32.@)
116 BOOL WINAPI PtInRect( const RECT *rect, POINT pt )
118 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
119 (pt.y >= rect->top) && (pt.y < rect->bottom));
123 /***********************************************************************
124 * OffsetRect (USER.77)
126 void WINAPI OffsetRect16( LPRECT16 rect, INT16 x, INT16 y )
128 rect->left += x;
129 rect->right += x;
130 rect->top += y;
131 rect->bottom += y;
135 /***********************************************************************
136 * OffsetRect (USER32.@)
138 BOOL WINAPI OffsetRect( LPRECT rect, INT x, INT y )
140 rect->left += x;
141 rect->right += x;
142 rect->top += y;
143 rect->bottom += y;
144 return TRUE;
148 /***********************************************************************
149 * InflateRect (USER.78)
151 void WINAPI InflateRect16( LPRECT16 rect, INT16 x, INT16 y )
153 rect->left -= x;
154 rect->top -= y;
155 rect->right += x;
156 rect->bottom += y;
160 /***********************************************************************
161 * InflateRect (USER32.@)
163 BOOL WINAPI InflateRect( LPRECT rect, INT x, INT y )
165 rect->left -= x;
166 rect->top -= y;
167 rect->right += x;
168 rect->bottom += y;
169 return TRUE;
173 /***********************************************************************
174 * IntersectRect (USER.79)
176 BOOL16 WINAPI IntersectRect16( LPRECT16 dest, const RECT16 *src1,
177 const RECT16 *src2 )
179 if (IsRectEmpty16(src1) || IsRectEmpty16(src2) ||
180 (src1->left >= src2->right) || (src2->left >= src1->right) ||
181 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
183 SetRectEmpty16( dest );
184 return FALSE;
186 dest->left = max( src1->left, src2->left );
187 dest->right = min( src1->right, src2->right );
188 dest->top = max( src1->top, src2->top );
189 dest->bottom = min( src1->bottom, src2->bottom );
190 return TRUE;
194 /***********************************************************************
195 * IntersectRect (USER32.@)
197 BOOL WINAPI IntersectRect( LPRECT dest, const RECT *src1,
198 const RECT *src2 )
200 if (IsRectEmpty(src1) || IsRectEmpty(src2) ||
201 (src1->left >= src2->right) || (src2->left >= src1->right) ||
202 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
204 SetRectEmpty( dest );
205 return FALSE;
207 dest->left = max( src1->left, src2->left );
208 dest->right = min( src1->right, src2->right );
209 dest->top = max( src1->top, src2->top );
210 dest->bottom = min( src1->bottom, src2->bottom );
211 return TRUE;
215 /***********************************************************************
216 * UnionRect (USER.80)
218 BOOL16 WINAPI UnionRect16( LPRECT16 dest, const RECT16 *src1,
219 const RECT16 *src2 )
221 if (IsRectEmpty16(src1))
223 if (IsRectEmpty16(src2))
225 SetRectEmpty16( dest );
226 return FALSE;
228 else *dest = *src2;
230 else
232 if (IsRectEmpty16(src2)) *dest = *src1;
233 else
235 dest->left = min( src1->left, src2->left );
236 dest->right = max( src1->right, src2->right );
237 dest->top = min( src1->top, src2->top );
238 dest->bottom = max( src1->bottom, src2->bottom );
241 return TRUE;
245 /***********************************************************************
246 * UnionRect (USER32.@)
248 BOOL WINAPI UnionRect( LPRECT dest, const RECT *src1,
249 const RECT *src2 )
251 if (IsRectEmpty(src1))
253 if (IsRectEmpty(src2))
255 SetRectEmpty( dest );
256 return FALSE;
258 else *dest = *src2;
260 else
262 if (IsRectEmpty(src2)) *dest = *src1;
263 else
265 dest->left = min( src1->left, src2->left );
266 dest->right = max( src1->right, src2->right );
267 dest->top = min( src1->top, src2->top );
268 dest->bottom = max( src1->bottom, src2->bottom );
271 return TRUE;
275 /***********************************************************************
276 * EqualRect (USER.244)
278 BOOL16 WINAPI EqualRect16( const RECT16* rect1, const RECT16* rect2 )
280 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
281 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
285 /***********************************************************************
286 * EqualRect (USER32.@)
288 BOOL WINAPI EqualRect( const RECT* rect1, const RECT* rect2 )
290 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
291 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
295 /***********************************************************************
296 * SubtractRect (USER.373)
298 BOOL16 WINAPI SubtractRect16( LPRECT16 dest, const RECT16 *src1,
299 const RECT16 *src2 )
301 RECT16 tmp;
303 if (IsRectEmpty16( src1 ))
305 SetRectEmpty16( dest );
306 return FALSE;
308 *dest = *src1;
309 if (IntersectRect16( &tmp, src1, src2 ))
311 if (EqualRect16( &tmp, dest ))
313 SetRectEmpty16( dest );
314 return FALSE;
316 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
318 if (tmp.left == dest->left) dest->left = tmp.right;
319 else if (tmp.right == dest->right) dest->right = tmp.left;
321 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
323 if (tmp.top == dest->top) dest->top = tmp.bottom;
324 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
327 return TRUE;
331 /***********************************************************************
332 * SubtractRect (USER32.@)
334 BOOL WINAPI SubtractRect( LPRECT dest, const RECT *src1,
335 const RECT *src2 )
337 RECT tmp;
339 if (IsRectEmpty( src1 ))
341 SetRectEmpty( dest );
342 return FALSE;
344 *dest = *src1;
345 if (IntersectRect( &tmp, src1, src2 ))
347 if (EqualRect( &tmp, dest ))
349 SetRectEmpty( dest );
350 return FALSE;
352 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
354 if (tmp.left == dest->left) dest->left = tmp.right;
355 else if (tmp.right == dest->right) dest->right = tmp.left;
357 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
359 if (tmp.top == dest->top) dest->top = tmp.bottom;
360 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
363 return TRUE;