[User32]
[reactos.git] / reactos / win32ss / user / user32 / windows / rect.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 1998, 1999, 2000, 2001 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 /*
20 * PROJECT: ReactOS user32.dll
21 * FILE: lib/user32/windows/input.c
22 * PURPOSE: Input
23 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
24 * UPDATE HISTORY:
25 * 09-05-2001 CSH Created
26 */
27
28 /* INCLUDES ******************************************************************/
29
30 #include <user32.h>
31
32 #include <wine/debug.h>
33
34 /* FUNCTIONS *****************************************************************/
35
36 /*
37 * @implemented
38 */
39 BOOL
40 WINAPI
41 CopyRect(LPRECT lprcDst,
42 CONST RECT *lprcSrc)
43 {
44 if(lprcDst == NULL || lprcSrc == NULL)
45 return(FALSE);
46
47 *lprcDst = *lprcSrc;
48 return(TRUE);
49 }
50
51
52 /*
53 * @implemented
54 */
55 BOOL
56 WINAPI
57 EqualRect(CONST RECT *lprc1,
58 CONST RECT *lprc2)
59 {
60 if (lprc1 == NULL || lprc2 == NULL)
61 return FALSE;
62
63 return (lprc1->left == lprc2->left) && (lprc1->top == lprc2->top) &&
64 (lprc1->right == lprc2->right) && (lprc1->bottom == lprc2->bottom);
65 }
66
67
68 /*
69 * @implemented
70 */
71 BOOL
72 WINAPI
73 InflateRect(LPRECT rect,
74 int dx,
75 int dy)
76 {
77 rect->left -= dx;
78 rect->top -= dy;
79 rect->right += dx;
80 rect->bottom += dy;
81 return(TRUE);
82 }
83
84
85 /*
86 * @implemented
87 */
88 BOOL
89 WINAPI
90 IntersectRect(LPRECT lprcDst,
91 CONST RECT *lprcSrc1,
92 CONST RECT *lprcSrc2)
93 {
94 if (IsRectEmpty(lprcSrc1) || IsRectEmpty(lprcSrc2) ||
95 lprcSrc1->left >= lprcSrc2->right ||
96 lprcSrc2->left >= lprcSrc1->right ||
97 lprcSrc1->top >= lprcSrc2->bottom ||
98 lprcSrc2->top >= lprcSrc1->bottom)
99 {
100 SetRectEmpty(lprcDst);
101 return(FALSE);
102 }
103 lprcDst->left = max(lprcSrc1->left, lprcSrc2->left);
104 lprcDst->right = min(lprcSrc1->right, lprcSrc2->right);
105 lprcDst->top = max(lprcSrc1->top, lprcSrc2->top);
106 lprcDst->bottom = min(lprcSrc1->bottom, lprcSrc2->bottom);
107 return(TRUE);
108 }
109
110
111 /*
112 * @implemented
113 */
114 BOOL
115 WINAPI
116 IsRectEmpty(CONST RECT *lprc)
117 {
118 return((lprc->left >= lprc->right) || (lprc->top >= lprc->bottom));
119 }
120
121
122 /*
123 * @implemented
124 */
125 BOOL
126 WINAPI
127 OffsetRect(LPRECT rect,
128 int dx,
129 int dy)
130 {
131 if(rect == NULL)
132 return(FALSE);
133
134 rect->left += dx;
135 rect->top += dy;
136 rect->right += dx;
137 rect->bottom += dy;
138 return(TRUE);
139 }
140
141
142 /*
143 * @implemented
144 */
145 BOOL
146 WINAPI
147 PtInRect(CONST RECT *lprc,
148 POINT pt)
149 {
150 return((pt.x >= lprc->left) && (pt.x < lprc->right) &&
151 (pt.y >= lprc->top) && (pt.y < lprc->bottom));
152 }
153
154 BOOL
155 WINAPI
156 SetRect(LPRECT lprc,
157 int xLeft,
158 int yTop,
159 int xRight,
160 int yBottom)
161 {
162 lprc->left = xLeft;
163 lprc->top = yTop;
164 lprc->right = xRight;
165 lprc->bottom = yBottom;
166 return(TRUE);
167 }
168
169
170 /*
171 * @implemented
172 */
173 BOOL
174 WINAPI
175 SetRectEmpty(LPRECT lprc)
176 {
177 lprc->left = lprc->right = lprc->top = lprc->bottom = 0;
178 return(TRUE);
179 }
180
181
182 /*
183 * @implemented
184 */
185 BOOL
186 WINAPI
187 SubtractRect(LPRECT lprcDst,
188 CONST RECT *lprcSrc1,
189 CONST RECT *lprcSrc2)
190 {
191 RECT tempRect;
192
193 if(lprcDst == NULL || lprcSrc1 == NULL || lprcSrc2 == NULL)
194 return(FALSE);
195
196 if(!IntersectRect(&tempRect, lprcSrc1, lprcSrc2))
197 {
198 *lprcDst = *lprcSrc1;
199 return(TRUE);
200 }
201
202 if (EqualRect(&tempRect, lprcSrc1))
203 {
204 SetRectEmpty(lprcDst);
205 return FALSE;
206 }
207
208 *lprcDst = *lprcSrc1;
209
210 if(lprcDst->top == tempRect.top && lprcDst->bottom == tempRect.bottom)
211 {
212 if(lprcDst->left == tempRect.left)
213 lprcDst->left = tempRect.right;
214 else if(lprcDst->right == tempRect.right)
215 lprcDst->right = tempRect.left;
216 }
217 else if(lprcDst->left == tempRect.left && lprcDst->right == tempRect.right)
218 {
219 if(lprcDst->top == tempRect.top)
220 lprcDst->top = tempRect.bottom;
221 else if(lprcDst->right == tempRect.right)
222 lprcDst->right = tempRect.left;
223 }
224
225 return(TRUE);
226 }
227
228
229 /*
230 * @implemented
231 */
232 BOOL
233 WINAPI
234 UnionRect(LPRECT lprcDst,
235 CONST RECT *lprcSrc1,
236 CONST RECT *lprcSrc2)
237 {
238 if (IsRectEmpty(lprcSrc1))
239 {
240 if (IsRectEmpty(lprcSrc2))
241 {
242 SetRectEmpty(lprcDst);
243 return(FALSE);
244 }
245 else
246 {
247 *lprcDst = *lprcSrc2;
248 }
249 }
250 else
251 {
252 if (IsRectEmpty(lprcSrc2))
253 {
254 *lprcDst = *lprcSrc1;
255 }
256 else
257 {
258 lprcDst->left = min(lprcSrc1->left, lprcSrc2->left);
259 lprcDst->top = min(lprcSrc1->top, lprcSrc2->top);
260 lprcDst->right = max(lprcSrc1->right, lprcSrc2->right);
261 lprcDst->bottom = max(lprcSrc1->bottom, lprcSrc2->bottom);
262 }
263 }
264
265 return(TRUE);
266 }