156b46a28e7e09a511dbd6ff22144d20ed6509ee
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS user32.dll
4 * FILE: win32ss/user/user32/windows/winpos.c
5 * PURPOSE: Window management
6 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
8 * 06-06-2001 CSH Created
13 WINE_DEFAULT_DEBUG_CHANNEL(user32
);
15 void mirror_rect( const RECT
*window_rect
, RECT
*rect
)
17 int width
= window_rect
->right
- window_rect
->left
;
19 rect
->left
= width
- rect
->right
;
20 rect
->right
= width
- tmp
;
23 /* FUNCTIONS *****************************************************************/
25 #define EMPTYPOINT(pt) ((pt).x == -1 && (pt).y == -1)
28 WinPosGetMinMaxInfo(HWND hwnd
, POINT
* maxSize
, POINT
* maxPos
,
29 POINT
* minTrack
, POINT
* maxTrack
)
34 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
36 LONG exstyle
= GetWindowLongW( hwnd
, GWL_EXSTYLE
);
40 /* Compute default values */
42 GetWindowRect(hwnd
, &rc
);
43 MinMax
.ptReserved
.x
= rc
.left
;
44 MinMax
.ptReserved
.y
= rc
.top
;
46 if ((style
& WS_CAPTION
) == WS_CAPTION
)
47 adjustedStyle
= style
& ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
49 adjustedStyle
= style
;
51 GetClientRect(GetAncestor(hwnd
,GA_PARENT
), &rc
);
52 AdjustWindowRectEx(&rc
, adjustedStyle
, ((style
& WS_POPUP
) && GetMenu(hwnd
)), exstyle
);
57 MinMax
.ptMaxSize
.x
= rc
.right
- rc
.left
;
58 MinMax
.ptMaxSize
.y
= rc
.bottom
- rc
.top
;
59 if (style
& (WS_DLGFRAME
| WS_BORDER
))
61 MinMax
.ptMinTrackSize
.x
= GetSystemMetrics(SM_CXMINTRACK
);
62 MinMax
.ptMinTrackSize
.y
= GetSystemMetrics(SM_CYMINTRACK
);
66 MinMax
.ptMinTrackSize
.x
= 2 * xinc
;
67 MinMax
.ptMinTrackSize
.y
= 2 * yinc
;
69 MinMax
.ptMaxTrackSize
.x
= GetSystemMetrics(SM_CXMAXTRACK
);
70 MinMax
.ptMaxTrackSize
.y
= GetSystemMetrics(SM_CYMAXTRACK
);
71 MinMax
.ptMaxPosition
.x
= -xinc
;
72 MinMax
.ptMaxPosition
.y
= -yinc
;
74 if ((win
= ValidateHwnd( hwnd
)) )//&& win != WND_DESKTOP && win != WND_OTHER_PROCESS)
76 if (!EMPTYPOINT(win
->InternalPos
.MaxPos
)) MinMax
.ptMaxPosition
= win
->InternalPos
.MaxPos
;
79 SendMessageW( hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&MinMax
);
81 /* if the app didn't change the values, adapt them for the current monitor */
83 if ((monitor
= MonitorFromWindow( hwnd
, MONITOR_DEFAULTTOPRIMARY
)))
88 mon_info
.cbSize
= sizeof(mon_info
);
89 GetMonitorInfoW( monitor
, &mon_info
);
91 rc_work
= mon_info
.rcMonitor
;
93 if (style
& WS_MAXIMIZEBOX
)
95 if ((style
& WS_CAPTION
) == WS_CAPTION
|| !(style
& (WS_CHILD
| WS_POPUP
)))
96 rc_work
= mon_info
.rcWork
;
99 if (MinMax
.ptMaxSize
.x
== GetSystemMetrics(SM_CXSCREEN
) + 2 * xinc
&&
100 MinMax
.ptMaxSize
.y
== GetSystemMetrics(SM_CYSCREEN
) + 2 * yinc
)
102 MinMax
.ptMaxSize
.x
= (rc_work
.right
- rc_work
.left
) + 2 * xinc
;
103 MinMax
.ptMaxSize
.y
= (rc_work
.bottom
- rc_work
.top
) + 2 * yinc
;
105 if (MinMax
.ptMaxPosition
.x
== -xinc
&& MinMax
.ptMaxPosition
.y
== -yinc
)
107 MinMax
.ptMaxPosition
.x
= rc_work
.left
- xinc
;
108 MinMax
.ptMaxPosition
.y
= rc_work
.top
- yinc
;
112 /* Some sanity checks */
114 TRACE("%d %d / %d %d / %d %d / %d %d\n",
115 MinMax
.ptMaxSize
.x
, MinMax
.ptMaxSize
.y
,
116 MinMax
.ptMaxPosition
.x
, MinMax
.ptMaxPosition
.y
,
117 MinMax
.ptMaxTrackSize
.x
, MinMax
.ptMaxTrackSize
.y
,
118 MinMax
.ptMinTrackSize
.x
, MinMax
.ptMinTrackSize
.y
);
119 MinMax
.ptMaxTrackSize
.x
= max( MinMax
.ptMaxTrackSize
.x
,
120 MinMax
.ptMinTrackSize
.x
);
121 MinMax
.ptMaxTrackSize
.y
= max( MinMax
.ptMaxTrackSize
.y
,
122 MinMax
.ptMinTrackSize
.y
);
124 if (maxSize
) *maxSize
= MinMax
.ptMaxSize
;
125 if (maxPos
) *maxPos
= MinMax
.ptMaxPosition
;
126 if (minTrack
) *minTrack
= MinMax
.ptMinTrackSize
;
127 if (maxTrack
) *maxTrack
= MinMax
.ptMaxTrackSize
;
129 return 0; //FIXME: what does it return?
137 GetActiveWindow(VOID
)
139 return (HWND
)NtUserGetThreadState(THREADSTATE_ACTIVEWINDOW
);
147 ArrangeIconicWindows(HWND hWnd
)
149 return NtUserxArrangeIconicWindows( hWnd
);
156 WindowFromPoint(POINT Point
)
158 //TODO: Determine what the actual parameters to
159 // NtUserWindowFromPoint are.
160 return NtUserWindowFromPoint(Point
.x
, Point
.y
);
167 MapWindowPoints(HWND hWndFrom
, HWND hWndTo
, LPPOINT lpPoints
, UINT cPoints
)
169 PWND FromWnd
= NULL
, ToWnd
= NULL
;
170 BOOL mirror_from
, mirror_to
;
177 FromWnd
= ValidateHwnd(hWndFrom
);
183 ToWnd
= ValidateHwnd(hWndTo
);
188 /* Note: Desktop Top and Left is always 0! */
189 Delta
.x
= Delta
.y
= 0;
190 mirror_from
= mirror_to
= FALSE
;
192 if (FromWnd
&& hWndFrom
!= GetDesktopWindow()) // FromWnd->fnid != FNID_DESKTOP)
194 if (FromWnd
->ExStyle
& WS_EX_LAYOUTRTL
)
198 Delta
.x
= -FromWnd
->rcClient
.right
;
201 Delta
.x
= FromWnd
->rcClient
.left
;
202 Delta
.y
= FromWnd
->rcClient
.top
;
205 if (ToWnd
&& hWndTo
!= GetDesktopWindow()) // ToWnd->fnid != FNID_DESKTOP)
207 if (ToWnd
->ExStyle
& WS_EX_LAYOUTRTL
)
211 Delta
.x
+= Change
* ToWnd
->rcClient
.right
;
214 Delta
.x
-= Change
* ToWnd
->rcClient
.left
;
215 Delta
.y
-= ToWnd
->rcClient
.top
;
218 for (i
= 0; i
!= cPoints
; i
++)
220 lpPoints
[i
].x
+= Delta
.x
;
221 lpPoints
[i
].x
*= Change
;
222 lpPoints
[i
].y
+= Delta
.y
;
225 if ((mirror_from
|| mirror_to
) && cPoints
== 2) /* special case for rectangle */
227 int tmp
= min(lpPoints
[0].x
, lpPoints
[1].x
);
228 lpPoints
[1].x
= max(lpPoints
[0].x
, lpPoints
[1].x
);
232 return MAKELONG(LOWORD(Delta
.x
), LOWORD(Delta
.y
));
239 ScreenToClient(HWND hWnd
, LPPOINT lpPoint
)
242 /* Note: Desktop Top and Left is always 0! */
243 Wnd
= ValidateHwnd(hWnd
);
247 if (hWnd
!= GetDesktopWindow()) // Wnd->fnid != FNID_DESKTOP )
249 if (Wnd
->ExStyle
& WS_EX_LAYOUTRTL
)
250 lpPoint
->x
= Wnd
->rcClient
.right
- lpPoint
->x
;
252 lpPoint
->x
-= Wnd
->rcClient
.left
;
253 lpPoint
->y
-= Wnd
->rcClient
.top
;
262 ClientToScreen(HWND hWnd
, LPPOINT lpPoint
)
265 /* Note: Desktop Top and Left is always 0! */
266 Wnd
= ValidateHwnd(hWnd
);
270 if ( hWnd
!= GetDesktopWindow()) // Wnd->fnid != FNID_DESKTOP )
272 if (Wnd
->ExStyle
& WS_EX_LAYOUTRTL
)
273 lpPoint
->x
= Wnd
->rcClient
.right
- lpPoint
->x
;
275 lpPoint
->x
+= Wnd
->rcClient
.left
;
276 lpPoint
->y
+= Wnd
->rcClient
.top
;