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)
8 * 06-06-2001 CSH Created
11 /* INCLUDES ******************************************************************/
15 #include <wine/debug.h>
16 WINE_DEFAULT_DEBUG_CHANNEL(user32
);
18 /* FUNCTIONS *****************************************************************/
20 /*******************************************************************
23 * Check if we can activate the specified window.
25 static BOOL
can_activate_window( HWND hwnd
)
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
);
37 /*******************************************************************
38 * WINPOS_ActivateOtherWindow
40 * Activates window other than pWnd.
44 WinPosActivateOtherWindow(HWND hwnd
)
48 if ((GetWindowLongPtrW( hwnd
, GWL_STYLE
) & WS_POPUP
) && (hwndTo
= GetWindow( hwnd
, GW_OWNER
)))
50 hwndTo
= GetAncestor( hwndTo
, GA_ROOT
);
51 if (can_activate_window( hwndTo
)) goto done
;
57 if (!(hwndTo
= GetWindow( hwndTo
, GW_HWNDNEXT
))) break;
58 if (can_activate_window( hwndTo
)) break;
62 fg
= GetForegroundWindow();
63 TRACE("win = %p fg = %p\n", hwndTo
, fg
);
64 if (!fg
|| (hwnd
== fg
))
66 if (SetForegroundWindow( hwndTo
)) return;
68 if (!SetActiveWindow( hwndTo
)) SetActiveWindow(0);
74 WinPosGetMinMaxInfo(HWND hWnd
, POINT
* MaxSize
, POINT
* MaxPos
,
75 POINT
* MinTrack
, POINT
* MaxTrack
)
79 if(NtUserGetMinMaxInfo(hWnd
, &MinMax
, TRUE
))
81 MinMax
.ptMaxTrackSize
.x
= max(MinMax
.ptMaxTrackSize
.x
,
82 MinMax
.ptMinTrackSize
.x
);
83 MinMax
.ptMaxTrackSize
.y
= max(MinMax
.ptMaxTrackSize
.y
,
84 MinMax
.ptMinTrackSize
.y
);
86 if (MaxSize
) *MaxSize
= MinMax
.ptMaxSize
;
87 if (MaxPos
) *MaxPos
= MinMax
.ptMaxPosition
;
88 if (MinTrack
) *MinTrack
= MinMax
.ptMinTrackSize
;
89 if (MaxTrack
) *MaxTrack
= MinMax
.ptMaxTrackSize
;
91 return 0; //FIXME: what does it return?
101 return (HWND
)NtUserGetThreadState(THREADSTATE_ACTIVEWINDOW
);
109 ArrangeIconicWindows(HWND hWnd
)
111 return NtUserCallHwndLock( hWnd
, HWNDLOCK_ROUTINE_ARRANGEICONICWINDOWS
);
118 WindowFromPoint(POINT Point
)
120 //TODO: Determine what the actual parameters to
121 // NtUserWindowFromPoint are.
122 return NtUserWindowFromPoint(Point
.x
, Point
.y
);
130 MapWindowPoints(HWND hWndFrom
, HWND hWndTo
, LPPOINT lpPoints
, UINT cPoints
)
132 PWND FromWnd
= NULL
, ToWnd
= NULL
;
133 BOOL mirror_from
, mirror_to
;
139 FromWnd
= ValidateHwnd(hWndFrom
);
145 ToWnd
= ValidateHwnd(hWndTo
);
150 /* Note: Desktop Top and Left is always 0! */
151 Delta
.x
= Delta
.y
= 0;
152 mirror_from
= mirror_to
= FALSE
;
154 if (FromWnd
&& FromWnd
->fnid
!= FNID_DESKTOP
)
156 if (FromWnd
->ExStyle
& WS_EX_LAYOUTRTL
)
159 Delta
.x
= FromWnd
->rcClient
.right
- FromWnd
->rcClient
.left
;
162 Delta
.x
= FromWnd
->rcClient
.left
;
163 Delta
.y
= FromWnd
->rcClient
.top
;
166 if (ToWnd
&& ToWnd
->fnid
!= FNID_DESKTOP
)
168 if (ToWnd
->ExStyle
& WS_EX_LAYOUTRTL
)
171 Delta
.x
-= ToWnd
->rcClient
.right
- ToWnd
->rcClient
.left
;
174 Delta
.x
-= ToWnd
->rcClient
.left
;
175 Delta
.y
-= ToWnd
->rcClient
.top
;
178 if (mirror_from
) Delta
.x
= -Delta
.x
;
180 for (i
= 0; i
!= cPoints
; i
++)
182 lpPoints
[i
].x
+= Delta
.x
;
183 lpPoints
[i
].y
+= Delta
.y
;
184 if (mirror_from
|| mirror_to
) lpPoints
[i
].x
= -lpPoints
[i
].x
;
187 if ((mirror_from
|| mirror_to
) && cPoints
== 2) /* special case for rectangle */
189 int tmp
= lpPoints
[0].x
;
190 lpPoints
[0].x
= lpPoints
[1].x
;
194 return MAKELONG(LOWORD(Delta
.x
), LOWORD(Delta
.y
));
202 ScreenToClient(HWND hWnd
, LPPOINT lpPoint
)
205 /* Note: Desktop Top and Left is always 0! */
206 Wnd
= ValidateHwnd(hWnd
);
210 if (Wnd
->fnid
!= FNID_DESKTOP
)
212 if (Wnd
->ExStyle
& WS_EX_LAYOUTRTL
)
213 lpPoint
->x
= Wnd
->rcClient
.right
- lpPoint
->x
;
215 lpPoint
->x
-= Wnd
->rcClient
.left
;
216 lpPoint
->y
-= Wnd
->rcClient
.top
;
226 ClientToScreen(HWND hWnd
, LPPOINT lpPoint
)
229 /* Note: Desktop Top and Left is always 0! */
230 Wnd
= ValidateHwnd(hWnd
);
234 if (Wnd
->fnid
!= FNID_DESKTOP
)
236 if (Wnd
->ExStyle
& WS_EX_LAYOUTRTL
)
237 lpPoint
->x
= Wnd
->rcClient
.right
- lpPoint
->x
;
239 lpPoint
->x
+= Wnd
->rcClient
.left
;
240 lpPoint
->y
+= Wnd
->rcClient
.top
;