1c2c66affSColin Finck /*
2c2c66affSColin Finck * COPYRIGHT: See COPYING in the top level directory
3c2c66affSColin Finck * PROJECT: ReactOS user32.dll
4c2c66affSColin Finck * FILE: win32ss/user/user32/windows/winpos.c
5c2c66affSColin Finck * PURPOSE: Window management
6c2c66affSColin Finck * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
7c2c66affSColin Finck * UPDATE HISTORY:
8c2c66affSColin Finck * 06-06-2001 CSH Created
9c2c66affSColin Finck */
10c2c66affSColin Finck
11c2c66affSColin Finck #include <user32.h>
12c2c66affSColin Finck
13c2c66affSColin Finck WINE_DEFAULT_DEBUG_CHANNEL(user32);
14c2c66affSColin Finck
mirror_rect(const RECT * window_rect,RECT * rect)15c2c66affSColin Finck void mirror_rect( const RECT *window_rect, RECT *rect )
16c2c66affSColin Finck {
17c2c66affSColin Finck int width = window_rect->right - window_rect->left;
18c2c66affSColin Finck int tmp = rect->left;
19c2c66affSColin Finck rect->left = width - rect->right;
20c2c66affSColin Finck rect->right = width - tmp;
21c2c66affSColin Finck }
22c2c66affSColin Finck
23c2c66affSColin Finck /* FUNCTIONS *****************************************************************/
24c2c66affSColin Finck
25*1f619b27Sjimtabor #if 0 // Keep legacy code. Moved to Win32k:NtUser:WinPos.c.
26c2c66affSColin Finck #define EMPTYPOINT(pt) ((pt).x == -1 && (pt).y == -1)
27c2c66affSColin Finck
28c2c66affSColin Finck UINT WINAPI
29c2c66affSColin Finck WinPosGetMinMaxInfo(HWND hwnd, POINT* maxSize, POINT* maxPos,
30c2c66affSColin Finck POINT* minTrack, POINT* maxTrack)
31c2c66affSColin Finck {
32c2c66affSColin Finck MINMAXINFO MinMax;
33c2c66affSColin Finck HMONITOR monitor;
34c2c66affSColin Finck INT xinc, yinc;
35c2c66affSColin Finck LONG style = GetWindowLongW( hwnd, GWL_STYLE );
36c2c66affSColin Finck LONG adjustedStyle;
37c2c66affSColin Finck LONG exstyle = GetWindowLongW( hwnd, GWL_EXSTYLE );
38c2c66affSColin Finck RECT rc;
39c2c66affSColin Finck WND *win;
40c2c66affSColin Finck
41c2c66affSColin Finck /* Compute default values */
42c2c66affSColin Finck
43c2c66affSColin Finck GetWindowRect(hwnd, &rc);
44c2c66affSColin Finck MinMax.ptReserved.x = rc.left;
45c2c66affSColin Finck MinMax.ptReserved.y = rc.top;
46c2c66affSColin Finck
47c2c66affSColin Finck if ((style & WS_CAPTION) == WS_CAPTION)
48c2c66affSColin Finck adjustedStyle = style & ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
49c2c66affSColin Finck else
50c2c66affSColin Finck adjustedStyle = style;
51c2c66affSColin Finck
52c2c66affSColin Finck GetClientRect(GetAncestor(hwnd,GA_PARENT), &rc);
53c2c66affSColin Finck AdjustWindowRectEx(&rc, adjustedStyle, ((style & WS_POPUP) && GetMenu(hwnd)), exstyle);
54c2c66affSColin Finck
55c2c66affSColin Finck xinc = -rc.left;
56c2c66affSColin Finck yinc = -rc.top;
57c2c66affSColin Finck
58c2c66affSColin Finck MinMax.ptMaxSize.x = rc.right - rc.left;
59c2c66affSColin Finck MinMax.ptMaxSize.y = rc.bottom - rc.top;
60c2c66affSColin Finck if (style & (WS_DLGFRAME | WS_BORDER))
61c2c66affSColin Finck {
62c2c66affSColin Finck MinMax.ptMinTrackSize.x = GetSystemMetrics(SM_CXMINTRACK);
63c2c66affSColin Finck MinMax.ptMinTrackSize.y = GetSystemMetrics(SM_CYMINTRACK);
64c2c66affSColin Finck }
65c2c66affSColin Finck else
66c2c66affSColin Finck {
67c2c66affSColin Finck MinMax.ptMinTrackSize.x = 2 * xinc;
68c2c66affSColin Finck MinMax.ptMinTrackSize.y = 2 * yinc;
69c2c66affSColin Finck }
70c2c66affSColin Finck MinMax.ptMaxTrackSize.x = GetSystemMetrics(SM_CXMAXTRACK);
71c2c66affSColin Finck MinMax.ptMaxTrackSize.y = GetSystemMetrics(SM_CYMAXTRACK);
72c2c66affSColin Finck MinMax.ptMaxPosition.x = -xinc;
73c2c66affSColin Finck MinMax.ptMaxPosition.y = -yinc;
74c2c66affSColin Finck
75c2c66affSColin Finck if ((win = ValidateHwnd( hwnd )) )//&& win != WND_DESKTOP && win != WND_OTHER_PROCESS)
76c2c66affSColin Finck {
77c2c66affSColin Finck if (!EMPTYPOINT(win->InternalPos.MaxPos)) MinMax.ptMaxPosition = win->InternalPos.MaxPos;
78c2c66affSColin Finck }
79c2c66affSColin Finck
80c2c66affSColin Finck SendMessageW( hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&MinMax );
81c2c66affSColin Finck
82c2c66affSColin Finck /* if the app didn't change the values, adapt them for the current monitor */
83c2c66affSColin Finck
84c2c66affSColin Finck if ((monitor = MonitorFromWindow( hwnd, MONITOR_DEFAULTTOPRIMARY )))
85c2c66affSColin Finck {
86c2c66affSColin Finck RECT rc_work;
87c2c66affSColin Finck MONITORINFO mon_info;
88c2c66affSColin Finck
89c2c66affSColin Finck mon_info.cbSize = sizeof(mon_info);
90c2c66affSColin Finck GetMonitorInfoW( monitor, &mon_info );
91c2c66affSColin Finck
92c2c66affSColin Finck rc_work = mon_info.rcMonitor;
93c2c66affSColin Finck
94c2c66affSColin Finck if (style & WS_MAXIMIZEBOX)
95c2c66affSColin Finck {
96c2c66affSColin Finck if ((style & WS_CAPTION) == WS_CAPTION || !(style & (WS_CHILD | WS_POPUP)))
97c2c66affSColin Finck rc_work = mon_info.rcWork;
98c2c66affSColin Finck }
99c2c66affSColin Finck
100c2c66affSColin Finck if (MinMax.ptMaxSize.x == GetSystemMetrics(SM_CXSCREEN) + 2 * xinc &&
101c2c66affSColin Finck MinMax.ptMaxSize.y == GetSystemMetrics(SM_CYSCREEN) + 2 * yinc)
102c2c66affSColin Finck {
103c2c66affSColin Finck MinMax.ptMaxSize.x = (rc_work.right - rc_work.left) + 2 * xinc;
104c2c66affSColin Finck MinMax.ptMaxSize.y = (rc_work.bottom - rc_work.top) + 2 * yinc;
105c2c66affSColin Finck }
106c2c66affSColin Finck if (MinMax.ptMaxPosition.x == -xinc && MinMax.ptMaxPosition.y == -yinc)
107c2c66affSColin Finck {
108c2c66affSColin Finck MinMax.ptMaxPosition.x = rc_work.left - xinc;
109c2c66affSColin Finck MinMax.ptMaxPosition.y = rc_work.top - yinc;
110c2c66affSColin Finck }
111c2c66affSColin Finck }
112c2c66affSColin Finck
113c2c66affSColin Finck /* Some sanity checks */
114c2c66affSColin Finck
115c2c66affSColin Finck TRACE("%d %d / %d %d / %d %d / %d %d\n",
116c2c66affSColin Finck MinMax.ptMaxSize.x, MinMax.ptMaxSize.y,
117c2c66affSColin Finck MinMax.ptMaxPosition.x, MinMax.ptMaxPosition.y,
118c2c66affSColin Finck MinMax.ptMaxTrackSize.x, MinMax.ptMaxTrackSize.y,
119c2c66affSColin Finck MinMax.ptMinTrackSize.x, MinMax.ptMinTrackSize.y);
120c2c66affSColin Finck MinMax.ptMaxTrackSize.x = max( MinMax.ptMaxTrackSize.x,
121c2c66affSColin Finck MinMax.ptMinTrackSize.x );
122c2c66affSColin Finck MinMax.ptMaxTrackSize.y = max( MinMax.ptMaxTrackSize.y,
123c2c66affSColin Finck MinMax.ptMinTrackSize.y );
124c2c66affSColin Finck
125c2c66affSColin Finck if (maxSize) *maxSize = MinMax.ptMaxSize;
126c2c66affSColin Finck if (maxPos) *maxPos = MinMax.ptMaxPosition;
127c2c66affSColin Finck if (minTrack) *minTrack = MinMax.ptMinTrackSize;
128c2c66affSColin Finck if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize;
129c2c66affSColin Finck
130*1f619b27Sjimtabor return 0; //FIXME: what does it return? Wine returns MINMAXINFO.
131c2c66affSColin Finck }
132*1f619b27Sjimtabor #endif
133c2c66affSColin Finck
134c2c66affSColin Finck /*
135c2c66affSColin Finck * @implemented
136c2c66affSColin Finck */
137c2c66affSColin Finck HWND WINAPI
GetActiveWindow(VOID)138c2c66affSColin Finck GetActiveWindow(VOID)
139c2c66affSColin Finck {
140c2c66affSColin Finck return (HWND)NtUserGetThreadState(THREADSTATE_ACTIVEWINDOW);
141c2c66affSColin Finck }
142c2c66affSColin Finck
143c2c66affSColin Finck
144c2c66affSColin Finck /*
145c2c66affSColin Finck * @unimplemented
146c2c66affSColin Finck */
147c2c66affSColin Finck UINT WINAPI
ArrangeIconicWindows(HWND hWnd)148c2c66affSColin Finck ArrangeIconicWindows(HWND hWnd)
149c2c66affSColin Finck {
150c2c66affSColin Finck return NtUserxArrangeIconicWindows( hWnd );
151c2c66affSColin Finck }
152c2c66affSColin Finck
153c2c66affSColin Finck /*
154c2c66affSColin Finck * @implemented
155c2c66affSColin Finck */
156c2c66affSColin Finck HWND WINAPI
WindowFromPoint(POINT Point)157c2c66affSColin Finck WindowFromPoint(POINT Point)
158c2c66affSColin Finck {
159c2c66affSColin Finck //TODO: Determine what the actual parameters to
160c2c66affSColin Finck // NtUserWindowFromPoint are.
161c2c66affSColin Finck return NtUserWindowFromPoint(Point.x, Point.y);
162c2c66affSColin Finck }
163c2c66affSColin Finck
164c2c66affSColin Finck /*
165c2c66affSColin Finck * @implemented
166c2c66affSColin Finck */
167c2c66affSColin Finck int WINAPI
MapWindowPoints(HWND hWndFrom,HWND hWndTo,LPPOINT lpPoints,UINT cPoints)168c2c66affSColin Finck MapWindowPoints(HWND hWndFrom, HWND hWndTo, LPPOINT lpPoints, UINT cPoints)
169c2c66affSColin Finck {
170c2c66affSColin Finck PWND FromWnd = NULL, ToWnd = NULL;
171c2c66affSColin Finck BOOL mirror_from, mirror_to;
172c2c66affSColin Finck POINT Delta;
173c2c66affSColin Finck UINT i;
174c2c66affSColin Finck int Change = 1;
175c2c66affSColin Finck
176c2c66affSColin Finck if (hWndFrom)
177c2c66affSColin Finck {
178c2c66affSColin Finck FromWnd = ValidateHwnd(hWndFrom);
179c2c66affSColin Finck if (!FromWnd)
180c2c66affSColin Finck return 0;
181c2c66affSColin Finck }
182c2c66affSColin Finck if (hWndTo)
183c2c66affSColin Finck {
184c2c66affSColin Finck ToWnd = ValidateHwnd(hWndTo);
185c2c66affSColin Finck if (!ToWnd)
186c2c66affSColin Finck return 0;
187c2c66affSColin Finck }
188c2c66affSColin Finck
189c2c66affSColin Finck /* Note: Desktop Top and Left is always 0! */
190c2c66affSColin Finck Delta.x = Delta.y = 0;
191c2c66affSColin Finck mirror_from = mirror_to = FALSE;
192c2c66affSColin Finck
193c2c66affSColin Finck if (FromWnd && hWndFrom != GetDesktopWindow()) // FromWnd->fnid != FNID_DESKTOP)
194c2c66affSColin Finck {
195c2c66affSColin Finck if (FromWnd->ExStyle & WS_EX_LAYOUTRTL)
196c2c66affSColin Finck {
197c2c66affSColin Finck mirror_from = TRUE;
198c2c66affSColin Finck Change = -Change;
199c2c66affSColin Finck Delta.x = -FromWnd->rcClient.right;
200c2c66affSColin Finck }
201c2c66affSColin Finck else
202c2c66affSColin Finck Delta.x = FromWnd->rcClient.left;
203c2c66affSColin Finck Delta.y = FromWnd->rcClient.top;
204c2c66affSColin Finck }
205c2c66affSColin Finck
206c2c66affSColin Finck if (ToWnd && hWndTo != GetDesktopWindow()) // ToWnd->fnid != FNID_DESKTOP)
207c2c66affSColin Finck {
208c2c66affSColin Finck if (ToWnd->ExStyle & WS_EX_LAYOUTRTL)
209c2c66affSColin Finck {
210c2c66affSColin Finck mirror_to = TRUE;
211c2c66affSColin Finck Change = -Change;
212c2c66affSColin Finck Delta.x += Change * ToWnd->rcClient.right;
213c2c66affSColin Finck }
214c2c66affSColin Finck else
215c2c66affSColin Finck Delta.x -= Change * ToWnd->rcClient.left;
216c2c66affSColin Finck Delta.y -= ToWnd->rcClient.top;
217c2c66affSColin Finck }
218c2c66affSColin Finck
219c2c66affSColin Finck for (i = 0; i != cPoints; i++)
220c2c66affSColin Finck {
221c2c66affSColin Finck lpPoints[i].x += Delta.x;
222c2c66affSColin Finck lpPoints[i].x *= Change;
223c2c66affSColin Finck lpPoints[i].y += Delta.y;
224c2c66affSColin Finck }
225c2c66affSColin Finck
226c2c66affSColin Finck if ((mirror_from || mirror_to) && cPoints == 2) /* special case for rectangle */
227c2c66affSColin Finck {
228c2c66affSColin Finck int tmp = min(lpPoints[0].x, lpPoints[1].x);
229c2c66affSColin Finck lpPoints[1].x = max(lpPoints[0].x, lpPoints[1].x);
230c2c66affSColin Finck lpPoints[0].x = tmp;
231c2c66affSColin Finck }
232c2c66affSColin Finck
233c2c66affSColin Finck return MAKELONG(LOWORD(Delta.x), LOWORD(Delta.y));
234c2c66affSColin Finck }
235c2c66affSColin Finck
236c2c66affSColin Finck /*
237c2c66affSColin Finck * @implemented
238c2c66affSColin Finck */
239c2c66affSColin Finck BOOL WINAPI
ScreenToClient(HWND hWnd,LPPOINT lpPoint)240c2c66affSColin Finck ScreenToClient(HWND hWnd, LPPOINT lpPoint)
241c2c66affSColin Finck {
242c2c66affSColin Finck PWND Wnd;
243c2c66affSColin Finck /* Note: Desktop Top and Left is always 0! */
244c2c66affSColin Finck Wnd = ValidateHwnd(hWnd);
245c2c66affSColin Finck if (!Wnd)
246c2c66affSColin Finck return FALSE;
247c2c66affSColin Finck
248c2c66affSColin Finck if (hWnd != GetDesktopWindow()) // Wnd->fnid != FNID_DESKTOP )
249c2c66affSColin Finck {
250c2c66affSColin Finck if (Wnd->ExStyle & WS_EX_LAYOUTRTL)
251c2c66affSColin Finck lpPoint->x = Wnd->rcClient.right - lpPoint->x;
252c2c66affSColin Finck else
253c2c66affSColin Finck lpPoint->x -= Wnd->rcClient.left;
254c2c66affSColin Finck lpPoint->y -= Wnd->rcClient.top;
255c2c66affSColin Finck }
256c2c66affSColin Finck return TRUE;
257c2c66affSColin Finck }
258c2c66affSColin Finck
259c2c66affSColin Finck /*
260c2c66affSColin Finck * @implemented
261c2c66affSColin Finck */
262c2c66affSColin Finck BOOL WINAPI
ClientToScreen(HWND hWnd,LPPOINT lpPoint)263c2c66affSColin Finck ClientToScreen(HWND hWnd, LPPOINT lpPoint)
264c2c66affSColin Finck {
265c2c66affSColin Finck PWND Wnd;
266c2c66affSColin Finck /* Note: Desktop Top and Left is always 0! */
267c2c66affSColin Finck Wnd = ValidateHwnd(hWnd);
268c2c66affSColin Finck if (!Wnd)
269c2c66affSColin Finck return FALSE;
270c2c66affSColin Finck
271c2c66affSColin Finck if ( hWnd != GetDesktopWindow()) // Wnd->fnid != FNID_DESKTOP )
272c2c66affSColin Finck {
273c2c66affSColin Finck if (Wnd->ExStyle & WS_EX_LAYOUTRTL)
274c2c66affSColin Finck lpPoint->x = Wnd->rcClient.right - lpPoint->x;
275c2c66affSColin Finck else
276c2c66affSColin Finck lpPoint->x += Wnd->rcClient.left;
277c2c66affSColin Finck lpPoint->y += Wnd->rcClient.top;
278c2c66affSColin Finck }
279c2c66affSColin Finck return TRUE;
280c2c66affSColin Finck }
281