2 * ReactOS Win32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
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.
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.
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.
30 PUSER_MESSAGE_QUEUE ForegroundQueue
= IntGetFocusMessageQueue();
31 return ForegroundQueue
!= NULL
? ForegroundQueue
->CaptureWindow
: 0;
37 PUSER_MESSAGE_QUEUE ForegroundQueue
= IntGetFocusMessageQueue();
38 return ForegroundQueue
!= NULL
? ForegroundQueue
->FocusWindow
: 0;
42 IntGetThreadFocusWindow()
44 PUSER_MESSAGE_QUEUE ThreadQueue
;
45 ThreadQueue
= (PUSER_MESSAGE_QUEUE
)PsGetWin32Thread()->MessageQueue
;
46 return ThreadQueue
!= NULL
? ThreadQueue
->FocusWindow
: 0;
50 co_IntSendDeactivateMessages(HWND hWndPrev
, HWND hWnd
)
54 co_IntPostOrSendMessage(hWndPrev
, WM_NCACTIVATE
, FALSE
, 0);
55 co_IntPostOrSendMessage(hWndPrev
, WM_ACTIVATE
,
56 MAKEWPARAM(WA_INACTIVE
, UserGetWindowLong(hWndPrev
, GWL_STYLE
, FALSE
) & WS_MINIMIZE
),
62 co_IntSendActivateMessages(HWND hWndPrev
, HWND hWnd
, BOOL MouseActivate
)
64 USER_REFERENCE_ENTRY Ref
;
65 PWINDOW_OBJECT Window
;
67 if ((Window
= UserGetWindowObject(hWnd
)))
70 UserRefObjectCo(Window
, &Ref
);
72 /* Send palette messages */
73 if (co_IntPostOrSendMessage(hWnd
, WM_QUERYNEWPALETTE
, 0, 0))
75 co_IntPostOrSendMessage(HWND_BROADCAST
, WM_PALETTEISCHANGING
,
79 if (UserGetWindow(hWnd
, GW_HWNDPREV
) != NULL
)
80 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0,
81 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOSENDCHANGING
);
83 if (!IntGetOwner(Window
) && !IntGetParent(Window
))
85 co_IntShellHookNotify(HSHELL_WINDOWACTIVATED
, (LPARAM
) hWnd
);
88 UserDerefObjectCo(Window
);
90 /* FIXME: IntIsWindow */
92 co_IntPostOrSendMessage(hWnd
, WM_NCACTIVATE
, (WPARAM
)(hWnd
== UserGetForegroundWindow()), 0);
93 /* FIXME: WA_CLICKACTIVE */
94 co_IntPostOrSendMessage(hWnd
, WM_ACTIVATE
,
95 MAKEWPARAM(MouseActivate
? WA_CLICKACTIVE
: WA_ACTIVE
,
96 UserGetWindowLong(hWnd
, GWL_STYLE
, FALSE
) & WS_MINIMIZE
),
102 co_IntSendKillFocusMessages(HWND hWndPrev
, HWND hWnd
)
106 co_IntPostOrSendMessage(hWndPrev
, WM_KILLFOCUS
, (WPARAM
)hWnd
, 0);
111 co_IntSendSetFocusMessages(HWND hWndPrev
, HWND hWnd
)
115 co_IntPostOrSendMessage(hWnd
, WM_SETFOCUS
, (WPARAM
)hWndPrev
, 0);
120 IntFindChildWindowToOwner(PWINDOW_OBJECT Root
, PWINDOW_OBJECT Owner
)
123 PWINDOW_OBJECT Child
, OwnerWnd
;
125 for(Child
= Root
->FirstChild
; Child
; Child
= Child
->NextSibling
)
127 OwnerWnd
= UserGetWindowObject(Child
->hOwner
);
131 if(OwnerWnd
== Owner
)
142 co_IntSetForegroundAndFocusWindow(PWINDOW_OBJECT Window
, PWINDOW_OBJECT FocusWindow
, BOOL MouseActivate
)
144 HWND hWnd
= Window
->hSelf
;
145 HWND hWndPrev
= NULL
;
146 HWND hWndFocus
= FocusWindow
->hSelf
;
147 HWND hWndFocusPrev
= NULL
;
148 PUSER_MESSAGE_QUEUE PrevForegroundQueue
;
150 ASSERT_REFS_CO(Window
);
152 DPRINT("IntSetForegroundAndFocusWindow(%x, %x, %s)\n", hWnd
, hWndFocus
, MouseActivate
? "TRUE" : "FALSE");
153 DPRINT("(%wZ)\n", &Window
->WindowName
);
155 if ((Window
->Style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
157 DPRINT("Failed - Child\n");
161 if (0 == (Window
->Style
& WS_VISIBLE
))
163 DPRINT("Failed - Invisible\n");
167 PrevForegroundQueue
= IntGetFocusMessageQueue();
168 if (PrevForegroundQueue
!= 0)
170 hWndPrev
= PrevForegroundQueue
->ActiveWindow
;
173 if (hWndPrev
== hWnd
)
175 DPRINT("Failed - Same\n");
179 hWndFocusPrev
= (PrevForegroundQueue
== FocusWindow
->MessageQueue
180 ? FocusWindow
->MessageQueue
->FocusWindow
: NULL
);
182 /* FIXME: Call hooks. */
184 co_IntSendDeactivateMessages(hWndPrev
, hWnd
);
185 co_IntSendKillFocusMessages(hWndFocusPrev
, hWndFocus
);
187 IntSetFocusMessageQueue(Window
->MessageQueue
);
188 if (Window
->MessageQueue
)
190 Window
->MessageQueue
->ActiveWindow
= hWnd
;
193 if (FocusWindow
->MessageQueue
)
195 FocusWindow
->MessageQueue
->FocusWindow
= hWndFocus
;
198 if (PrevForegroundQueue
!= Window
->MessageQueue
)
200 /* FIXME: Send WM_ACTIVATEAPP to all thread windows. */
203 co_IntSendSetFocusMessages(hWndFocusPrev
, hWndFocus
);
204 co_IntSendActivateMessages(hWndPrev
, hWnd
, MouseActivate
);
210 co_IntSetForegroundWindow(PWINDOW_OBJECT Window
)//FIXME: can Window be NULL??
212 /*if (Window)*/ ASSERT_REFS_CO(Window
);
214 return co_IntSetForegroundAndFocusWindow(Window
, Window
, FALSE
);
218 co_IntMouseActivateWindow(PWINDOW_OBJECT Window
)
221 PWINDOW_OBJECT TopWindow
;
222 USER_REFERENCE_ENTRY Ref
;
224 ASSERT_REFS_CO(Window
);
226 if(Window
->Style
& WS_DISABLED
)
229 PWINDOW_OBJECT TopWnd
;
230 PWINDOW_OBJECT DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
233 Top
= IntFindChildWindowToOwner(DesktopWindow
, Window
);
234 if((TopWnd
= UserGetWindowObject(Top
)))
236 UserRefObjectCo(TopWnd
, &Ref
);
237 Ret
= co_IntMouseActivateWindow(TopWnd
);
238 UserDerefObjectCo(TopWnd
);
247 TopWindow
= UserGetAncestor(Window
, GA_ROOT
);
248 if (!TopWindow
) return FALSE
;
250 /* TMN: Check return valud from this function? */
251 UserRefObjectCo(TopWindow
, &Ref
);
253 co_IntSetForegroundAndFocusWindow(TopWindow
, Window
, TRUE
);
255 UserDerefObjectCo(TopWindow
);
261 co_IntSetActiveWindow(PWINDOW_OBJECT Window OPTIONAL
)
263 PUSER_MESSAGE_QUEUE ThreadQueue
;
268 ASSERT_REFS_CO(Window
);
270 ThreadQueue
= (PUSER_MESSAGE_QUEUE
)PsGetWin32Thread()->MessageQueue
;
271 ASSERT(ThreadQueue
!= 0);
275 if (!(Window
->Style
& WS_VISIBLE
) ||
276 (Window
->Style
& (WS_POPUP
| WS_CHILD
)) == WS_CHILD
)
278 return ThreadQueue
? 0 : ThreadQueue
->ActiveWindow
;
280 hWnd
= Window
->hSelf
;
283 hWndPrev
= ThreadQueue
->ActiveWindow
;
284 if (hWndPrev
== hWnd
)
289 /* FIXME: Call hooks. */
291 ThreadQueue
->ActiveWindow
= hWnd
;
293 co_IntSendDeactivateMessages(hWndPrev
, hWnd
);
294 co_IntSendActivateMessages(hWndPrev
, hWnd
, FALSE
);
297 /* return IntIsWindow(hWndPrev) ? hWndPrev : 0;*/
303 co_IntSetFocusWindow(PWINDOW_OBJECT Window
)
306 PUSER_MESSAGE_QUEUE ThreadQueue
;
308 ASSERT_REFS_CO(Window
);
310 ThreadQueue
= (PUSER_MESSAGE_QUEUE
)PsGetWin32Thread()->MessageQueue
;
311 ASSERT(ThreadQueue
!= 0);
313 hWndPrev
= ThreadQueue
->FocusWindow
;
314 if (hWndPrev
== Window
->hSelf
)
319 ThreadQueue
->FocusWindow
= Window
->hSelf
;
321 co_IntSendKillFocusMessages(hWndPrev
, Window
->hSelf
);
322 co_IntSendSetFocusMessages(hWndPrev
, Window
->hSelf
);
332 UserGetForegroundWindow(VOID
)
334 PUSER_MESSAGE_QUEUE ForegroundQueue
;
336 ForegroundQueue
= IntGetFocusMessageQueue();
337 return( ForegroundQueue
!= NULL
? ForegroundQueue
->ActiveWindow
: 0);
345 NtUserGetForegroundWindow(VOID
)
347 DECLARE_RETURN(HWND
);
349 DPRINT("Enter NtUserGetForegroundWindow\n");
350 UserEnterExclusive();
352 RETURN( UserGetForegroundWindow());
355 DPRINT("Leave NtUserGetForegroundWindow, ret=%i\n",_ret_
);
361 HWND FASTCALL
UserGetActiveWindow()
363 PUSER_MESSAGE_QUEUE ThreadQueue
;
364 ThreadQueue
= (PUSER_MESSAGE_QUEUE
)PsGetWin32Thread()->MessageQueue
;
365 return( ThreadQueue
? ThreadQueue
->ActiveWindow
: 0);
373 NtUserGetActiveWindow(VOID
)
375 DECLARE_RETURN(HWND
);
377 DPRINT("Enter NtUserGetActiveWindow\n");
380 RETURN( UserGetActiveWindow());
383 DPRINT("Leave NtUserGetActiveWindow, ret=%i\n",_ret_
);
389 NtUserSetActiveWindow(HWND hWnd
)
391 USER_REFERENCE_ENTRY Ref
;
392 DECLARE_RETURN(HWND
);
394 DPRINT("Enter NtUserSetActiveWindow(%x)\n", hWnd
);
395 UserEnterExclusive();
399 PWINDOW_OBJECT Window
;
400 PUSER_MESSAGE_QUEUE ThreadQueue
;
403 if (!(Window
= UserGetWindowObject(hWnd
)))
408 DPRINT("(%wZ)\n", &Window
->WindowName
);
410 ThreadQueue
= (PUSER_MESSAGE_QUEUE
)PsGetWin32Thread()->MessageQueue
;
412 if (Window
->MessageQueue
!= ThreadQueue
)
414 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
418 UserRefObjectCo(Window
, &Ref
);
419 hWndPrev
= co_IntSetActiveWindow(Window
);
420 UserDerefObjectCo(Window
);
426 RETURN( co_IntSetActiveWindow(0));
430 DPRINT("Leave NtUserSetActiveWindow, ret=%i\n",_ret_
);
439 NtUserGetCapture(VOID
)
441 DECLARE_RETURN(HWND
);
443 DPRINT("Enter NtUserGetCapture\n");
446 PUSER_MESSAGE_QUEUE ThreadQueue
;
447 ThreadQueue
= (PUSER_MESSAGE_QUEUE
)PsGetWin32Thread()->MessageQueue
;
448 RETURN( ThreadQueue
? ThreadQueue
->CaptureWindow
: 0);
451 DPRINT("Leave NtUserGetCapture, ret=%i\n",_ret_
);
460 NtUserSetCapture(HWND hWnd
)
462 PUSER_MESSAGE_QUEUE ThreadQueue
;
463 PWINDOW_OBJECT Window
;
465 DECLARE_RETURN(HWND
);
467 DPRINT("Enter NtUserSetCapture(%x)\n", hWnd
);
468 UserEnterExclusive();
470 ThreadQueue
= (PUSER_MESSAGE_QUEUE
)PsGetWin32Thread()->MessageQueue
;
472 if((Window
= UserGetWindowObject(hWnd
)))
474 if(Window
->MessageQueue
!= ThreadQueue
)
480 hWndPrev
= MsqSetStateWindow(ThreadQueue
, MSQ_STATE_CAPTURE
, hWnd
);
482 /* also remove other windows if not capturing anymore */
485 MsqSetStateWindow(ThreadQueue
, MSQ_STATE_MENUOWNER
, NULL
);
486 MsqSetStateWindow(ThreadQueue
, MSQ_STATE_MOVESIZE
, NULL
);
489 co_IntPostOrSendMessage(hWndPrev
, WM_CAPTURECHANGED
, 0, (LPARAM
)hWnd
);
490 ThreadQueue
->CaptureWindow
= hWnd
;
495 DPRINT("Leave NtUserSetCapture, ret=%i\n",_ret_
);
502 HWND FASTCALL
co_UserSetFocus(PWINDOW_OBJECT Window OPTIONAL
)
506 PUSER_MESSAGE_QUEUE ThreadQueue
;
508 PWINDOW_OBJECT TopWnd
;
509 USER_REFERENCE_ENTRY Ref
;
511 ASSERT_REFS_CO(Window
);
513 ThreadQueue
= (PUSER_MESSAGE_QUEUE
)PsGetWin32Thread()->MessageQueue
;
515 if (Window
->Style
& (WS_MINIMIZE
| WS_DISABLED
))
517 return( (ThreadQueue
? ThreadQueue
->FocusWindow
: 0));
520 if (Window
->MessageQueue
!= ThreadQueue
)
522 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
526 TopWnd
= UserGetAncestor(Window
, GA_ROOT
);
527 if (TopWnd
&& TopWnd
->hSelf
!= UserGetActiveWindow())
529 // PWINDOW_OBJECT WndTops = UserGetWindowObject(hWndTop);
530 UserRefObjectCo(TopWnd
, &Ref
);
531 co_IntSetActiveWindow(TopWnd
);
532 UserDerefObjectCo(TopWnd
);
535 hWndPrev
= co_IntSetFocusWindow(Window
);
541 return( co_IntSetFocusWindow(NULL
));
551 NtUserSetFocus(HWND hWnd
)
553 PWINDOW_OBJECT Window
;
554 USER_REFERENCE_ENTRY Ref
;
555 DECLARE_RETURN(HWND
);
558 DPRINT("Enter NtUserSetFocus(%x)\n", hWnd
);
559 UserEnterExclusive();
561 if (!(Window
= UserGetWindowObject(hWnd
)))
566 UserRefObjectCo(Window
, &Ref
);
567 ret
= co_UserSetFocus(Window
);
568 UserDerefObjectCo(Window
);
573 DPRINT("Leave NtUserSetFocus, ret=%i\n",_ret_
);