[CMAKE]
[reactos.git] / dll / win32 / user32 / windows / winpos.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS user32.dll
4 * FILE: dll/win32/user32/windows/winpos.c
5 * PURPOSE: Window management
6 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
7 * UPDATE HISTORY:
8 * 06-06-2001 CSH Created
9 */
10
11 /* INCLUDES ******************************************************************/
12
13 #include <user32.h>
14
15 #include <wine/debug.h>
16 WINE_DEFAULT_DEBUG_CHANNEL(user32);
17
18 /* FUNCTIONS *****************************************************************/
19
20 /*******************************************************************
21 * can_activate_window
22 *
23 * Check if we can activate the specified window.
24 */
25 static BOOL can_activate_window( HWND hwnd )
26 {
27 LONG style;
28
29 if (!hwnd) return FALSE;
30 style = GetWindowLongPtrW( hwnd, GWL_STYLE );
31 if (!(style & WS_VISIBLE)) return FALSE;
32 if ((style & (WS_POPUP|WS_CHILD)) == WS_CHILD) return FALSE;
33 return !(style & WS_DISABLED);
34 }
35
36
37 /*******************************************************************
38 * WINPOS_ActivateOtherWindow
39 *
40 * Activates window other than pWnd.
41 */
42 void
43 WINAPI
44 WinPosActivateOtherWindow(HWND hwnd)
45 {
46 HWND hwndTo, fg;
47
48 if ((GetWindowLongPtrW( hwnd, GWL_STYLE ) & WS_POPUP) && (hwndTo = GetWindow( hwnd, GW_OWNER )))
49 {
50 hwndTo = GetAncestor( hwndTo, GA_ROOT );
51 if (can_activate_window( hwndTo )) goto done;
52 }
53
54 hwndTo = hwnd;
55 for (;;)
56 {
57 if (!(hwndTo = GetWindow( hwndTo, GW_HWNDNEXT ))) break;
58 if (can_activate_window( hwndTo )) break;
59 }
60
61 done:
62 fg = GetForegroundWindow();
63 TRACE("win = %p fg = %p\n", hwndTo, fg);
64 if (!fg || (hwnd == fg))
65 {
66 if (SetForegroundWindow( hwndTo )) return;
67 }
68 if (!SetActiveWindow( hwndTo )) SetActiveWindow(0);
69 }
70
71
72
73 UINT WINAPI
74 WinPosGetMinMaxInfo(HWND hWnd, POINT* MaxSize, POINT* MaxPos,
75 POINT* MinTrack, POINT* MaxTrack)
76 {
77 MINMAXINFO MinMax;
78
79 if(NtUserGetMinMaxInfo(hWnd, &MinMax, TRUE))
80 {
81 MinMax.ptMaxTrackSize.x = max(MinMax.ptMaxTrackSize.x,
82 MinMax.ptMinTrackSize.x);
83 MinMax.ptMaxTrackSize.y = max(MinMax.ptMaxTrackSize.y,
84 MinMax.ptMinTrackSize.y);
85
86 if (MaxSize) *MaxSize = MinMax.ptMaxSize;
87 if (MaxPos) *MaxPos = MinMax.ptMaxPosition;
88 if (MinTrack) *MinTrack = MinMax.ptMinTrackSize;
89 if (MaxTrack) *MaxTrack = MinMax.ptMaxTrackSize;
90 }
91 return 0; //FIXME: what does it return?
92 }
93
94
95 /*
96 * @implemented
97 */
98 HWND WINAPI
99 GetActiveWindow(VOID)
100 {
101 return (HWND)NtUserGetThreadState(THREADSTATE_ACTIVEWINDOW);
102 }
103
104
105 /*
106 * @unimplemented
107 */
108 UINT WINAPI
109 ArrangeIconicWindows(HWND hWnd)
110 {
111 return NtUserCallHwndLock( hWnd, HWNDLOCK_ROUTINE_ARRANGEICONICWINDOWS);
112 }
113
114 /*
115 * @implemented
116 */
117 HWND WINAPI
118 WindowFromPoint(POINT Point)
119 {
120 //TODO: Determine what the actual parameters to
121 // NtUserWindowFromPoint are.
122 return NtUserWindowFromPoint(Point.x, Point.y);
123 }
124
125
126 /*
127 * @implemented
128 */
129 int WINAPI
130 MapWindowPoints(HWND hWndFrom, HWND hWndTo, LPPOINT lpPoints, UINT cPoints)
131 {
132 PWND FromWnd = NULL, ToWnd = NULL;
133 BOOL mirror_from, mirror_to;
134 POINT Delta;
135 UINT i;
136
137 if (hWndFrom)
138 {
139 FromWnd = ValidateHwnd(hWndFrom);
140 if (!FromWnd)
141 return 0;
142 }
143 if (hWndTo)
144 {
145 ToWnd = ValidateHwnd(hWndTo);
146 if (!ToWnd)
147 return 0;
148 }
149
150 /* Note: Desktop Top and Left is always 0! */
151 Delta.x = Delta.y = 0;
152 mirror_from = mirror_to = FALSE;
153
154 if (FromWnd && FromWnd->fnid != FNID_DESKTOP)
155 {
156 if (FromWnd->ExStyle & WS_EX_LAYOUTRTL)
157 {
158 mirror_from = TRUE;
159 Delta.x = FromWnd->rcClient.right - FromWnd->rcClient.left;
160 }
161 else
162 Delta.x = FromWnd->rcClient.left;
163 Delta.y = FromWnd->rcClient.top;
164 }
165
166 if (ToWnd && ToWnd->fnid != FNID_DESKTOP)
167 {
168 if (ToWnd->ExStyle & WS_EX_LAYOUTRTL)
169 {
170 mirror_to = TRUE;
171 Delta.x -= ToWnd->rcClient.right - ToWnd->rcClient.left;
172 }
173 else
174 Delta.x -= ToWnd->rcClient.left;
175 Delta.y -= ToWnd->rcClient.top;
176 }
177
178 if (mirror_from) Delta.x = -Delta.x;
179
180 for (i = 0; i != cPoints; i++)
181 {
182 lpPoints[i].x += Delta.x;
183 lpPoints[i].y += Delta.y;
184 if (mirror_from || mirror_to) lpPoints[i].x = -lpPoints[i].x;
185 }
186
187 if ((mirror_from || mirror_to) && cPoints == 2) /* special case for rectangle */
188 {
189 int tmp = lpPoints[0].x;
190 lpPoints[0].x = lpPoints[1].x;
191 lpPoints[1].x = tmp;
192 }
193
194 return MAKELONG(LOWORD(Delta.x), LOWORD(Delta.y));
195 }
196
197
198 /*
199 * @implemented
200 */
201 BOOL WINAPI
202 ScreenToClient(HWND hWnd, LPPOINT lpPoint)
203 {
204 PWND Wnd;
205 /* Note: Desktop Top and Left is always 0! */
206 Wnd = ValidateHwnd(hWnd);
207 if (!Wnd)
208 return FALSE;
209
210 if (Wnd->fnid != FNID_DESKTOP)
211 {
212 if (Wnd->ExStyle & WS_EX_LAYOUTRTL)
213 lpPoint->x = Wnd->rcClient.right - lpPoint->x;
214 else
215 lpPoint->x -= Wnd->rcClient.left;
216 lpPoint->y -= Wnd->rcClient.top;
217 }
218 return TRUE;
219 }
220
221
222 /*
223 * @implemented
224 */
225 BOOL WINAPI
226 ClientToScreen(HWND hWnd, LPPOINT lpPoint)
227 {
228 PWND Wnd;
229 /* Note: Desktop Top and Left is always 0! */
230 Wnd = ValidateHwnd(hWnd);
231 if (!Wnd)
232 return FALSE;
233
234 if (Wnd->fnid != FNID_DESKTOP)
235 {
236 if (Wnd->ExStyle & WS_EX_LAYOUTRTL)
237 lpPoint->x = Wnd->rcClient.right - lpPoint->x;
238 else
239 lpPoint->x += Wnd->rcClient.left;
240 lpPoint->y += Wnd->rcClient.top;
241 }
242 return TRUE;
243 }
244