Use free Windows DDK and compile with latest MinGW releases.
[reactos.git] / reactos / lib / 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 /* $Id: rect.c,v 1.9 2002/09/07 15:12:45 chorns Exp $
20 *
21 * PROJECT: ReactOS user32.dll
22 * FILE: lib/user32/windows/input.c
23 * PURPOSE: Input
24 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
25 * UPDATE HISTORY:
26 * 09-05-2001 CSH Created
27 */
28
29 /* INCLUDES ******************************************************************/
30
31 #include <user32.h>
32
33 /* FUNCTIONS *****************************************************************/
34
35 WINBOOL STDCALL
36 CopyRect(LPRECT lprcDst, CONST RECT *lprcSrc)
37 {
38 *lprcDst = *lprcSrc;
39 return(TRUE);
40 }
41
42 WINBOOL
43 STDCALL
44 EqualRect(
45 CONST RECT *lprc1,
46 CONST RECT *lprc2)
47 {
48 if ((lprc1->left == lprc2->left)
49 && (lprc1->top == lprc2->top)
50 && (lprc1->right == lprc2->right)
51 && (lprc1->bottom == lprc2->bottom))
52 {
53 return TRUE;
54 }
55 /* TODO: return the correct error code. */
56 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
57 return FALSE;
58 }
59
60 WINBOOL STDCALL
61 InflateRect(LPRECT rect, int dx, int dy)
62 {
63 rect->left -= dx;
64 rect->top -= dy;
65 rect->right -= dx;
66 rect->bottom -= dy;
67 return(TRUE);
68 }
69
70 WINBOOL STDCALL
71 IntersectRect(LPRECT lprcDst,
72 CONST RECT *lprcSrc1,
73 CONST RECT *lprcSrc2)
74 {
75 if (IsRectEmpty(lprcSrc1) || IsRectEmpty(lprcSrc2) ||
76 lprcSrc1->left >= lprcSrc2->right ||
77 lprcSrc2->left >= lprcSrc1->right ||
78 lprcSrc1->top >= lprcSrc2->bottom ||
79 lprcSrc2->top >= lprcSrc1->bottom)
80 {
81 SetRectEmpty(lprcDst);
82 return(FALSE);
83 }
84 lprcDst->left = max(lprcSrc1->left, lprcSrc2->left);
85 lprcDst->right = min(lprcSrc1->right, lprcSrc2->right);
86 lprcDst->top = max(lprcSrc1->top, lprcSrc2->top);
87 lprcDst->bottom = min(lprcSrc1->bottom, lprcSrc2->bottom);
88 }
89
90 WINBOOL STDCALL
91 IsRectEmpty(CONST RECT *lprc)
92 {
93 return((lprc->left >= lprc->right) || (lprc->top >= lprc->bottom));
94 }
95
96 WINBOOL STDCALL
97 OffsetRect(LPRECT rect, int dx, int dy)
98 {
99 rect->left += dx;
100 rect->top += dy;
101 rect->right += dx;
102 rect->bottom += dy;
103 return(TRUE);
104 }
105
106 WINBOOL STDCALL
107 PtInRect(CONST RECT *lprc, POINT pt)
108 {
109 return((pt.x >= lprc->left) && (pt.x < lprc->right) &&
110 (pt.y >= lprc->top) && (pt.y < lprc->bottom));
111 }
112
113 WINBOOL STDCALL
114 SetRect(LPRECT lprc, int xLeft, int yTop, int xRight, int yBottom)
115 {
116 lprc->left = xLeft;
117 lprc->top = yTop;
118 lprc->right = xRight;
119 lprc->bottom = yBottom;
120 return(TRUE);
121 }
122
123 BOOL STDCALL
124 SetRectEmpty(LPRECT lprc)
125 {
126 lprc->left = lprc->right = lprc->top = lprc->bottom = 0;
127 return(TRUE);
128 }
129
130 WINBOOL STDCALL
131 SubtractRect(LPRECT lprcDst, CONST RECT *lprcSrc1, CONST RECT *lprcSrc2)
132 {
133 UNIMPLEMENTED;
134 return FALSE;
135 }
136
137 WINBOOL STDCALL
138 UnionRect(LPRECT lprcDst, CONST RECT *lprcSrc1, CONST RECT *lprcSrc2)
139 {
140 if (IsRectEmpty(lprcSrc1))
141 {
142 if (IsRectEmpty(lprcSrc2))
143 {
144 SetRectEmpty(lprcDst);
145 return(FALSE);
146 }
147 else
148 {
149 *lprcDst = *lprcSrc2;
150 }
151 }
152 else
153 {
154 if (IsRectEmpty(lprcSrc2))
155 {
156 *lprcDst = *lprcSrc1;
157 }
158 else
159 {
160 lprcDst->left = min(lprcSrc1->left, lprcSrc2->left);
161 lprcDst->top = min(lprcSrc1->top, lprcSrc2->top);
162 lprcDst->right = max(lprcSrc1->right, lprcSrc2->right);
163 lprcDst->bottom = max(lprcSrc1->bottom, lprcSrc2->bottom);
164 }
165 }
166 return(TRUE);
167 }