Do not clear the drawing area for etched static controls.
[wine.git] / windows / rect.c
blobb0c8f2728945cb92d69bf5c15b661e9d9676f3a6
1 /*
2 * Rectangle-related functions
4 * Copyright 1993, 1996 Alexandre Julliard
6 */
8 #include "wine/winuser16.h"
9 #include "winuser.h"
11 /***********************************************************************
12 * SetRect16 (USER.72)
14 void WINAPI SetRect16( LPRECT16 rect, INT16 left, INT16 top,
15 INT16 right, INT16 bottom )
17 rect->left = left;
18 rect->right = right;
19 rect->top = top;
20 rect->bottom = bottom;
24 /***********************************************************************
25 * SetRect32 (USER32.499)
27 BOOL WINAPI SetRect( LPRECT rect, INT left, INT top,
28 INT right, INT bottom )
30 rect->left = left;
31 rect->right = right;
32 rect->top = top;
33 rect->bottom = bottom;
34 return TRUE;
38 /***********************************************************************
39 * SetRectEmpty16 (USER.73)
41 void WINAPI SetRectEmpty16( LPRECT16 rect )
43 rect->left = rect->right = rect->top = rect->bottom = 0;
47 /***********************************************************************
48 * SetRectEmpty32 (USER32.500)
50 BOOL WINAPI SetRectEmpty( LPRECT rect )
52 rect->left = rect->right = rect->top = rect->bottom = 0;
53 return TRUE;
57 /***********************************************************************
58 * CopyRect16 (USER.74)
60 BOOL16 WINAPI CopyRect16( RECT16 *dest, const RECT16 *src )
62 *dest = *src;
63 return TRUE;
67 /***********************************************************************
68 * CopyRect32 (USER32.62)
70 BOOL WINAPI CopyRect( RECT *dest, const RECT *src )
72 *dest = *src;
73 return TRUE;
77 /***********************************************************************
78 * IsRectEmpty16 (USER.75)
80 BOOL16 WINAPI IsRectEmpty16( const RECT16 *rect )
82 return ((rect->left == rect->right) || (rect->top == rect->bottom));
86 /***********************************************************************
87 * IsRectEmpty32 (USER32.347)
89 BOOL WINAPI IsRectEmpty( const RECT *rect )
91 return ((rect->left == rect->right) || (rect->top == rect->bottom));
95 /***********************************************************************
96 * PtInRect16 (USER.76)
98 BOOL16 WINAPI PtInRect16( const RECT16 *rect, POINT16 pt )
100 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
101 (pt.y >= rect->top) && (pt.y < rect->bottom));
105 /***********************************************************************
106 * PtInRect32 (USER32.424)
108 BOOL WINAPI PtInRect( const RECT *rect, POINT pt )
110 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
111 (pt.y >= rect->top) && (pt.y < rect->bottom));
115 /***********************************************************************
116 * OffsetRect16 (USER.77)
118 void WINAPI OffsetRect16( LPRECT16 rect, INT16 x, INT16 y )
120 rect->left += x;
121 rect->right += x;
122 rect->top += y;
123 rect->bottom += y;
127 /***********************************************************************
128 * OffsetRect32 (USER32.406)
130 BOOL WINAPI OffsetRect( LPRECT rect, INT x, INT y )
132 rect->left += x;
133 rect->right += x;
134 rect->top += y;
135 rect->bottom += y;
136 return TRUE;
140 /***********************************************************************
141 * InflateRect16 (USER.78)
143 void WINAPI InflateRect16( LPRECT16 rect, INT16 x, INT16 y )
145 rect->left -= x;
146 rect->top -= y;
147 rect->right += x;
148 rect->bottom += y;
152 /***********************************************************************
153 * InflateRect32 (USER32.321)
155 BOOL WINAPI InflateRect( LPRECT rect, INT x, INT y )
157 rect->left -= x;
158 rect->top -= y;
159 rect->right += x;
160 rect->bottom += y;
161 return TRUE;
165 /***********************************************************************
166 * IntersectRect16 (USER.79)
168 BOOL16 WINAPI IntersectRect16( LPRECT16 dest, const RECT16 *src1,
169 const RECT16 *src2 )
171 if (IsRectEmpty16(src1) || IsRectEmpty16(src2) ||
172 (src1->left >= src2->right) || (src2->left >= src1->right) ||
173 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
175 SetRectEmpty16( dest );
176 return FALSE;
178 dest->left = MAX( src1->left, src2->left );
179 dest->right = MIN( src1->right, src2->right );
180 dest->top = MAX( src1->top, src2->top );
181 dest->bottom = MIN( src1->bottom, src2->bottom );
182 return TRUE;
186 /***********************************************************************
187 * IntersectRect32 (USER32.327)
189 BOOL WINAPI IntersectRect( LPRECT dest, const RECT *src1,
190 const RECT *src2 )
192 if (IsRectEmpty(src1) || IsRectEmpty(src2) ||
193 (src1->left >= src2->right) || (src2->left >= src1->right) ||
194 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
196 SetRectEmpty( dest );
197 return FALSE;
199 dest->left = MAX( src1->left, src2->left );
200 dest->right = MIN( src1->right, src2->right );
201 dest->top = MAX( src1->top, src2->top );
202 dest->bottom = MIN( src1->bottom, src2->bottom );
203 return TRUE;
207 /***********************************************************************
208 * UnionRect16 (USER.80)
210 BOOL16 WINAPI UnionRect16( LPRECT16 dest, const RECT16 *src1,
211 const RECT16 *src2 )
213 if (IsRectEmpty16(src1))
215 if (IsRectEmpty16(src2))
217 SetRectEmpty16( dest );
218 return FALSE;
220 else *dest = *src2;
222 else
224 if (IsRectEmpty16(src2)) *dest = *src1;
225 else
227 dest->left = MIN( src1->left, src2->left );
228 dest->right = MAX( src1->right, src2->right );
229 dest->top = MIN( src1->top, src2->top );
230 dest->bottom = MAX( src1->bottom, src2->bottom );
233 return TRUE;
237 /***********************************************************************
238 * UnionRect32 (USER32.559)
240 BOOL WINAPI UnionRect( LPRECT dest, const RECT *src1,
241 const RECT *src2 )
243 if (IsRectEmpty(src1))
245 if (IsRectEmpty(src2))
247 SetRectEmpty( dest );
248 return FALSE;
250 else *dest = *src2;
252 else
254 if (IsRectEmpty(src2)) *dest = *src1;
255 else
257 dest->left = MIN( src1->left, src2->left );
258 dest->right = MAX( src1->right, src2->right );
259 dest->top = MIN( src1->top, src2->top );
260 dest->bottom = MAX( src1->bottom, src2->bottom );
263 return TRUE;
267 /***********************************************************************
268 * EqualRect16 (USER.244)
270 BOOL16 WINAPI EqualRect16( const RECT16* rect1, const RECT16* rect2 )
272 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
273 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
277 /***********************************************************************
278 * EqualRect32 (USER32.194)
280 BOOL WINAPI EqualRect( const RECT* rect1, const RECT* rect2 )
282 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
283 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
287 /***********************************************************************
288 * SubtractRect16 (USER.373)
290 BOOL16 WINAPI SubtractRect16( LPRECT16 dest, const RECT16 *src1,
291 const RECT16 *src2 )
293 RECT16 tmp;
295 if (IsRectEmpty16( src1 ))
297 SetRectEmpty16( dest );
298 return FALSE;
300 *dest = *src1;
301 if (IntersectRect16( &tmp, src1, src2 ))
303 if (EqualRect16( &tmp, dest ))
305 SetRectEmpty16( dest );
306 return FALSE;
308 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
310 if (tmp.left == dest->left) dest->left = tmp.right;
311 else if (tmp.right == dest->right) dest->right = tmp.left;
313 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
315 if (tmp.top == dest->top) dest->top = tmp.bottom;
316 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
319 return TRUE;
323 /***********************************************************************
324 * SubtractRect32 (USER32.536)
326 BOOL WINAPI SubtractRect( LPRECT dest, const RECT *src1,
327 const RECT *src2 )
329 RECT tmp;
331 if (IsRectEmpty( src1 ))
333 SetRectEmpty( dest );
334 return FALSE;
336 *dest = *src1;
337 if (IntersectRect( &tmp, src1, src2 ))
339 if (EqualRect( &tmp, dest ))
341 SetRectEmpty( dest );
342 return FALSE;
344 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
346 if (tmp.left == dest->left) dest->left = tmp.right;
347 else if (tmp.right == dest->right) dest->right = tmp.left;
349 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
351 if (tmp.top == dest->top) dest->top = tmp.bottom;
352 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
355 return TRUE;