From 9826d4e679fd899cc541d51c51a1e50114505eb7 Mon Sep 17 00:00:00 2001 From: Casper Hornstrup Date: Sat, 5 Jul 2003 16:04:01 +0000 Subject: [PATCH] 2003-07-05 Casper S. Hornstrup * include/win32k/ntuser.h (NtUserSetFocus): Correct prototype. * lib/user32/misc/stubs.c (SetFocus): Remove. * lib/user32/windows/defwnd.c (KEYDATA_ALT): New. (User32DefWindowProc): Handle WM_SYSKEYDOWN. * lib/user32/windows/input.c (SetFocus): New. * subsys/win32k/include/msgqueue.h (USER_MESSAGE_QUEUE): Document FocusWindow field. * subsys/win32k/include/window.h (W32kSetFocusWindow): Change return type to HWND. * subsys/win32k/include/winsta.h (W32kGetFocusMessageQueue): New. * subsys/win32k/ntuser/input.c (KeyboardThreadMain): Handle system keys. * subsys/win32k/ntuser/keyboard.c (NtUserSetFocus): New. * subsys/win32k/ntuser/msgqueue.c (MsqPostKeyboardMessage): Implement. * subsys/win32k/ntuser/stubs.c (NtUserSetFocus): Remove. * subsys/win32k/ntuser/window.c (W32kSetFocusWindow): Implement. (NtUserGetClientRect, W32kGetWindowProc, NtUserCreateWindowEx): Release window reference on error. (W32kDestroyWindow): Remove focus from window tree before destroying it if needed. * subsys/win32k/ntuser/winpos.c (WinPosChangeActiveWindow): Implement. (WinPosShowWindow): Activate window if needed. * subsys/win32k/ntuser/winsta.c (W32kGetFocusMessageQueue): New. svn path=/trunk/; revision=5000 --- reactos/ChangeLog | 27 ++++++- reactos/include/win32k/ntuser.h | 4 +- reactos/lib/user32/misc/stubs.c | 11 +-- reactos/lib/user32/windows/defwnd.c | 33 ++++++++- reactos/lib/user32/windows/input.c | 8 +- reactos/subsys/win32k/include/msgqueue.h | 2 +- reactos/subsys/win32k/include/window.h | 2 +- reactos/subsys/win32k/include/winsta.h | 3 + reactos/subsys/win32k/ntuser/input.c | 41 +++++++++-- reactos/subsys/win32k/ntuser/keyboard.c | 11 ++- reactos/subsys/win32k/ntuser/msgqueue.c | 37 ++++++---- reactos/subsys/win32k/ntuser/stubs.c | 12 +-- reactos/subsys/win32k/ntuser/window.c | 94 ++++++++++++++++++++---- reactos/subsys/win32k/ntuser/winpos.c | 29 +++++++- reactos/subsys/win32k/ntuser/winsta.c | 17 ++++- 15 files changed, 259 insertions(+), 72 deletions(-) diff --git a/reactos/ChangeLog b/reactos/ChangeLog index c612461338a..ccff7473701 100644 --- a/reactos/ChangeLog +++ b/reactos/ChangeLog @@ -1,6 +1,31 @@ +2003-07-05 Casper S. Hornstrup + + * include/win32k/ntuser.h (NtUserSetFocus): Correct prototype. + * lib/user32/misc/stubs.c (SetFocus): Remove. + * lib/user32/windows/defwnd.c (KEYDATA_ALT): New. + (User32DefWindowProc): Handle WM_SYSKEYDOWN. + * lib/user32/windows/input.c (SetFocus): New. + * subsys/win32k/include/msgqueue.h (USER_MESSAGE_QUEUE): Document + FocusWindow field. + * subsys/win32k/include/window.h (W32kSetFocusWindow): Change return type + to HWND. + * subsys/win32k/include/winsta.h (W32kGetFocusMessageQueue): New. + * subsys/win32k/ntuser/input.c (KeyboardThreadMain): Handle system keys. + * subsys/win32k/ntuser/keyboard.c (NtUserSetFocus): New. + * subsys/win32k/ntuser/msgqueue.c (MsqPostKeyboardMessage): Implement. + * subsys/win32k/ntuser/stubs.c (NtUserSetFocus): Remove. + * subsys/win32k/ntuser/window.c (W32kSetFocusWindow): Implement. + (NtUserGetClientRect, W32kGetWindowProc, NtUserCreateWindowEx): Release + window reference on error. + (W32kDestroyWindow): Remove focus from window tree before destroying it + if needed. + * subsys/win32k/ntuser/winpos.c (WinPosChangeActiveWindow): Implement. + (WinPosShowWindow): Activate window if needed. + * subsys/win32k/ntuser/winsta.c (W32kGetFocusMessageQueue): New. + 2003-06-27 Casper S. Hornstrup - * lib/user32/controls/button.c (ButtonWndProc_comm): Fix unsigned/signed + * lib/user32/controls/button.c (ButtonWndProc_common): Fix unsigned/signed warning. 2003-06-07 Casper S. Hornstrup diff --git a/reactos/include/win32k/ntuser.h b/reactos/include/win32k/ntuser.h index 0faad8a0d84..5b44e5e66f2 100644 --- a/reactos/include/win32k/ntuser.h +++ b/reactos/include/win32k/ntuser.h @@ -1270,10 +1270,10 @@ NtUserSetDbgTag( DWORD Unknown0, DWORD Unknown1); -DWORD +HWND STDCALL NtUserSetFocus( - DWORD Unknown0); + HWND hWnd); DWORD STDCALL diff --git a/reactos/lib/user32/misc/stubs.c b/reactos/lib/user32/misc/stubs.c index bb06a56523e..5bd7e5ba8d6 100644 --- a/reactos/lib/user32/misc/stubs.c +++ b/reactos/lib/user32/misc/stubs.c @@ -1,4 +1,4 @@ -/* $Id: stubs.c,v 1.23 2003/07/03 02:52:54 sedwards Exp $ +/* $Id: stubs.c,v 1.24 2003/07/05 16:04:01 chorns Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS user32.dll @@ -399,15 +399,6 @@ SetDoubleClickTime( return FALSE; } -HWND -STDCALL -SetFocus( - HWND hWnd) -{ - UNIMPLEMENTED; - return (HWND)0; -} - VOID STDCALL SetLastErrorEx( diff --git a/reactos/lib/user32/windows/defwnd.c b/reactos/lib/user32/windows/defwnd.c index 37c593366f5..f026ff69e94 100644 --- a/reactos/lib/user32/windows/defwnd.c +++ b/reactos/lib/user32/windows/defwnd.c @@ -1,4 +1,4 @@ -/* $Id: defwnd.c,v 1.52 2003/06/24 00:55:02 rcampbell Exp $ +/* $Id: defwnd.c,v 1.53 2003/07/05 16:04:01 chorns Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS user32.dll @@ -71,6 +71,9 @@ static COLORREF SysColours[] = static ATOM AtomInternalPos; +/* Bits in the dwKeyData */ +#define KEYDATA_ALT 0x2000 + /* FUNCTIONS *****************************************************************/ BOOL IsMaxBoxActive(HWND hWnd) @@ -1183,10 +1186,10 @@ User32DefWindowProc(HWND hWnd, case WM_ACTIVATE: { + /* Check if the window is minimized. */ if (LOWORD(lParam) != WA_INACTIVE && - GetWindowLong(hWnd, GWL_STYLE) & WS_MINIMIZE) + !(GetWindowLong(hWnd, GWL_STYLE) & WS_MINIMIZE)) { - /* Check if the window is minimized. */ SetFocus(hWnd); } break; @@ -1370,6 +1373,30 @@ User32DefWindowProc(HWND hWnd, } break; } + + case WM_SYSKEYDOWN: + if (HIWORD(lParam) & KEYDATA_ALT) + { + if (wParam == VK_F4) /* Try to close the window */ + { + //HWND hTopWnd = GetAncestor(hWnd, GA_ROOT); + HWND hTopWnd = hWnd; + if (!(GetClassLongW(hTopWnd, GCL_STYLE) & CS_NOCLOSE)) + { + if (bUnicode) + { + PostMessageW(hTopWnd, WM_CLOSE, 0, 0); + PostMessageW(hTopWnd, WM_SYSCOMMAND, SC_CLOSE, 0); + } + else + { + PostMessageA(hTopWnd, WM_CLOSE, 0, 0); + PostMessageA(hTopWnd, WM_SYSCOMMAND, SC_CLOSE, 0); + } + } + } + } + break; } return 0; } diff --git a/reactos/lib/user32/windows/input.c b/reactos/lib/user32/windows/input.c index d68e8980461..73e932005e4 100644 --- a/reactos/lib/user32/windows/input.c +++ b/reactos/lib/user32/windows/input.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: input.c,v 1.6 2003/05/12 19:30:00 jfilby Exp $ +/* $Id: input.c,v 1.7 2003/07/05 16:04:01 chorns Exp $ * * PROJECT: ReactOS user32.dll * FILE: lib/user32/windows/input.c @@ -209,6 +209,12 @@ OemKeyScan(WORD wOemChar) return 0; } +HWND STDCALL +SetFocus(HWND hWnd) +{ + return NtUserSetFocus(hWnd); +} + WINBOOL STDCALL SetKeyboardState(LPBYTE lpKeyState) { diff --git a/reactos/subsys/win32k/include/msgqueue.h b/reactos/subsys/win32k/include/msgqueue.h index 22d2f58674e..1f59059a380 100644 --- a/reactos/subsys/win32k/include/msgqueue.h +++ b/reactos/subsys/win32k/include/msgqueue.h @@ -52,7 +52,7 @@ typedef struct _USER_MESSAGE_QUEUE KEVENT NewMessages; /* FIXME: Unknown. */ ULONG QueueStatus; - /* Current window with focus for this queue. */ + /* Current window with focus (ie. receives keyboard input) for this queue. */ HWND FocusWindow; /* True if a window needs painting. */ BOOLEAN PaintPosted; diff --git a/reactos/subsys/win32k/include/window.h b/reactos/subsys/win32k/include/window.h index 16d8567e11a..d75adbf84e6 100644 --- a/reactos/subsys/win32k/include/window.h +++ b/reactos/subsys/win32k/include/window.h @@ -107,7 +107,7 @@ BOOL FASTCALL W32kIsWindowVisible (HWND Wnd); BOOL FASTCALL W32kIsChildWindow (HWND Parent, HWND Child); HWND FASTCALL W32kGetDesktopWindow (VOID); HWND FASTCALL W32kGetFocusWindow (VOID); -VOID FASTCALL W32kSetFocusWindow (HWND hWnd); +HWND FASTCALL W32kSetFocusWindow (HWND hWnd); #endif /* __WIN32K_WINDOW_H */ /* EOF */ diff --git a/reactos/subsys/win32k/include/winsta.h b/reactos/subsys/win32k/include/winsta.h index 7c257564632..7c71a12105d 100644 --- a/reactos/subsys/win32k/include/winsta.h +++ b/reactos/subsys/win32k/include/winsta.h @@ -5,6 +5,7 @@ #include #include #include +#include "msgqueue.h" #define PROCESS_WINDOW_STATION() \ ((HWINSTA)(IoGetCurrentProcess()->Win32WindowStation)) @@ -34,6 +35,8 @@ LRESULT CALLBACK W32kDesktopWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); PDESKTOP_OBJECT FASTCALL W32kGetActiveDesktop(VOID); +PUSER_MESSAGE_QUEUE FASTCALL +W32kGetFocusMessageQueue(VOID); VOID FASTCALL W32kInitializeDesktopGraphics(VOID); VOID FASTCALL diff --git a/reactos/subsys/win32k/ntuser/input.c b/reactos/subsys/win32k/ntuser/input.c index 57bf5d848f5..75918439953 100644 --- a/reactos/subsys/win32k/ntuser/input.c +++ b/reactos/subsys/win32k/ntuser/input.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: input.c,v 1.7 2003/05/22 00:47:04 gdalsnes Exp $ +/* $Id: input.c,v 1.8 2003/07/05 16:04:01 chorns Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -89,6 +89,7 @@ KeyboardThreadMain(PVOID StartContext) UserMode, TRUE, NULL); + /* * Receive and process keyboard input. */ @@ -96,6 +97,7 @@ KeyboardThreadMain(PVOID StartContext) { KEY_EVENT_RECORD KeyEvent; LPARAM lParam; + BOOLEAN SysKey; Status = NtReadFile (KeyboardDeviceHandle, NULL, @@ -116,23 +118,48 @@ KeyboardThreadMain(PVOID StartContext) return(Status); } + SysKey = KeyEvent.dwControlKeyState & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED); + /* * Post a keyboard message. */ if (KeyEvent.bKeyDown) { - /* FIXME: Bit 24 indicates if this is an extended key. */ lParam = KeyEvent.wRepeatCount | - ((KeyEvent.wVirtualScanCode << 16) & 0x00FF0000) | 0x40000000; - MsqPostKeyboardMessage(WM_KEYDOWN, KeyEvent.wVirtualKeyCode, + ((KeyEvent.wVirtualScanCode << 16) & 0x00FF0000) | 0x40000000; + + /* Bit 24 indicates if this is an extended key */ + if (KeyEvent.dwControlKeyState & ENHANCED_KEY) + { + lParam |= (1 << 24); + } + + if (SysKey) + { + lParam |= (1 << 29); /* Context mode. 1 if ALT if pressed while the key is pressed */ + } + + MsqPostKeyboardMessage(SysKey ? WM_SYSKEYDOWN : WM_KEYDOWN, KeyEvent.wVirtualKeyCode, lParam); } else { - /* FIXME: Bit 24 indicates if this is an extended key. */ lParam = KeyEvent.wRepeatCount | - ((KeyEvent.wVirtualScanCode << 16) & 0x00FF0000) | 0xC0000000; - MsqPostKeyboardMessage(WM_KEYUP, KeyEvent.wVirtualKeyCode, + ((KeyEvent.wVirtualScanCode << 16) & 0x00FF0000) | 0xC0000000; + + /* Bit 24 indicates if this is an extended key */ + if (KeyEvent.dwControlKeyState & ENHANCED_KEY) + { + lParam |= (1 << 24); + } + + if (SysKey) + { + lParam |= (1 << 29); /* Context mode. 1 if ALT if pressed while the key is pressed */ + } + + + MsqPostKeyboardMessage(SysKey ? WM_SYSKEYDOWN : WM_KEYDOWN, KeyEvent.wVirtualKeyCode, lParam); } } diff --git a/reactos/subsys/win32k/ntuser/keyboard.c b/reactos/subsys/win32k/ntuser/keyboard.c index fdf14de7330..4624dac39ce 100644 --- a/reactos/subsys/win32k/ntuser/keyboard.c +++ b/reactos/subsys/win32k/ntuser/keyboard.c @@ -16,12 +16,12 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: keyboard.c,v 1.3 2003/05/18 17:16:17 ea Exp $ +/* $Id: keyboard.c,v 1.4 2003/07/05 16:04:01 chorns Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel * PURPOSE: Messages - * FILE: subsys/win32k/ntuser/message.c + * FILE: subsys/win32k/ntuser/keyboard.c * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net) * REVISION HISTORY: * 06-06-2001 CSH Created @@ -239,4 +239,11 @@ NtUserTranslateMessage(LPMSG lpMsg, } return(FALSE); } + +HWND STDCALL +NtUserSetFocus(HWND hWnd) +{ + return W32kSetFocusWindow(hWnd); +} + /* EOF */ diff --git a/reactos/subsys/win32k/ntuser/msgqueue.c b/reactos/subsys/win32k/ntuser/msgqueue.c index 49408117284..36af474e8cc 100644 --- a/reactos/subsys/win32k/ntuser/msgqueue.c +++ b/reactos/subsys/win32k/ntuser/msgqueue.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: msgqueue.c,v 1.9 2003/05/21 22:58:42 gvg Exp $ +/* $Id: msgqueue.c,v 1.10 2003/07/05 16:04:01 chorns Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -351,24 +351,35 @@ MsqPeekHardwareMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd, VOID STDCALL MsqPostKeyboardMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) { -#if 0 - MSG Msg; + PUSER_MESSAGE_QUEUE FocusMessageQueue; PUSER_MESSAGE Message; + MSG Msg; - if (CurrentFocusMessageQueue == NULL) + DPRINT("MsqPostKeyboardMessage(uMsg 0x%x, wParam 0x%x, lParam 0x%x)\n", + uMsg, wParam, lParam); + + FocusMessageQueue = W32kGetFocusMessageQueue(); + if (FocusMessageQueue == NULL) { + DPRINT("No focus message queue\n"); return; } - Msg.hwnd = CurrentFocusMessageQueue->FocusWindow; - Msg.message = uMsg; - Msg.wParam = wParam; - Msg.lParam = lParam; - /* FIXME: Initialize time and point. */ - - Message = MsqCreateMessage(&Msg); - MsqPostMessage(CurrentFocusMessageQueue, Message, TRUE); -#endif + if (FocusMessageQueue->FocusWindow != (HWND)0) + { + Msg.hwnd = FocusMessageQueue->FocusWindow; + Msg.message = uMsg; + Msg.wParam = wParam; + Msg.lParam = lParam; + /* FIXME: Initialize time and point. */ + + Message = MsqCreateMessage(&Msg); + MsqPostMessage(FocusMessageQueue, Message); + } + else + { + DPRINT("Invalid focus window handle\n"); + } } VOID FASTCALL diff --git a/reactos/subsys/win32k/ntuser/stubs.c b/reactos/subsys/win32k/ntuser/stubs.c index d78fab1fbad..405281435cb 100644 --- a/reactos/subsys/win32k/ntuser/stubs.c +++ b/reactos/subsys/win32k/ntuser/stubs.c @@ -1,4 +1,4 @@ -/* $Id: stubs.c,v 1.12 2003/06/03 22:26:12 ekohl Exp $ +/* $Id: stubs.c,v 1.13 2003/07/05 16:04:01 chorns Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -1261,16 +1261,6 @@ NtUserSetDbgTag( return 0; } -DWORD -STDCALL -NtUserSetFocus( - DWORD Unknown0) -{ - UNIMPLEMENTED - - return 0; -} - DWORD STDCALL NtUserSetImeHotKey( diff --git a/reactos/subsys/win32k/ntuser/window.c b/reactos/subsys/win32k/ntuser/window.c index b91177e6d61..1cc921c3477 100644 --- a/reactos/subsys/win32k/ntuser/window.c +++ b/reactos/subsys/win32k/ntuser/window.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: window.c,v 1.58 2003/06/25 22:37:07 gvg Exp $ +/* $Id: window.c,v 1.59 2003/07/05 16:04:01 chorns Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -124,9 +124,65 @@ NtUserGetAncestor(HWND hWnd, UINT Flags) } } -VOID FASTCALL +HWND FASTCALL W32kSetFocusWindow(HWND hWnd) { + PUSER_MESSAGE_QUEUE OldMessageQueue; + PDESKTOP_OBJECT DesktopObject; + PWINDOW_OBJECT WindowObject; + HWND hWndOldFocus; + + DPRINT("W32kSetFocusWindow(hWnd 0x%x)\n", hWnd); + + if (hWnd != (HWND)0) + { + WindowObject = W32kGetWindowObject(hWnd); + if (!WindowObject) + { + DPRINT("Bad window handle 0x%x\n", hWnd); + SetLastWin32Error(ERROR_INVALID_HANDLE); + return (HWND)0; + } + } + else + { + WindowObject = NULL; + } + + DesktopObject = W32kGetActiveDesktop(); + if (!DesktopObject) + { + DPRINT("No active desktop\n"); + if (WindowObject != NULL) + { + W32kReleaseWindowObject(WindowObject); + } + SetLastWin32Error(ERROR_INVALID_HANDLE); + return (HWND)0; + } + + hWndOldFocus = (HWND)0; + OldMessageQueue = (PUSER_MESSAGE_QUEUE)DesktopObject->ActiveMessageQueue; + if (OldMessageQueue != NULL) + { + hWndOldFocus = OldMessageQueue->FocusWindow; + } + + if (WindowObject != NULL) + { + WindowObject->MessageQueue->FocusWindow = hWnd; + (PUSER_MESSAGE_QUEUE)DesktopObject->ActiveMessageQueue = + WindowObject->MessageQueue; + W32kReleaseWindowObject(WindowObject); + } + else + { + (PUSER_MESSAGE_QUEUE)DesktopObject->ActiveMessageQueue = NULL; + } + + DPRINT("hWndOldFocus = 0x%x\n", hWndOldFocus); + + return hWndOldFocus; } BOOL FASTCALL @@ -297,6 +353,7 @@ NtUserGetClientRect(HWND hWnd, LPRECT Rect) W32kGetClientRect(WindowObject, &SafeRect); if (! NT_SUCCESS(MmCopyToCaller(Rect, &SafeRect, sizeof(RECT)))) { + W32kReleaseWindowObject(WindowObject); return(FALSE); } @@ -348,7 +405,7 @@ W32kGetWindowProc(HWND Wnd) return NULL; WndProc = WindowObject->WndProc; - W32kReleaseWindowObject(Wnd); + W32kReleaseWindowObject(WindowObject); return(WndProc); } @@ -495,6 +552,7 @@ NtUserCreateWindowEx(DWORD dwExStyle, if (!NT_SUCCESS(Status)) { RtlFreeUnicodeString(&WindowName); + W32kReleaseWindowObject(ParentWindow); return((HWND)0); } @@ -509,6 +567,7 @@ NtUserCreateWindowEx(DWORD dwExStyle, { RtlFreeUnicodeString(&WindowName); ObmDereferenceObject(ClassObject); + W32kReleaseWindowObject(ParentWindow); DPRINT("Validation of window station handle (0x%X) failed\n", PROCESS_WINDOW_STATION()); return (HWND)0; @@ -524,6 +583,7 @@ NtUserCreateWindowEx(DWORD dwExStyle, ObDereferenceObject(WinStaObject); ObmDereferenceObject(ClassObject); RtlFreeUnicodeString(&WindowName); + W32kReleaseWindowObject(ParentWindow); SetLastNtError(STATUS_INSUFFICIENT_RESOURCES); return (HWND)0; } @@ -649,8 +709,9 @@ NtUserCreateWindowEx(DWORD dwExStyle, if (!Result) { /* FIXME: Cleanup. */ + W32kReleaseWindowObject(ParentWindow); DPRINT("NtUserCreateWindowEx(): NCCREATE message failed.\n"); - return(NULL); + return((HWND)0); } /* Calculate the non-client size. */ @@ -670,8 +731,9 @@ NtUserCreateWindowEx(DWORD dwExStyle, if (Result == (LRESULT)-1) { /* FIXME: Cleanup. */ + W32kReleaseWindowObject(ParentWindow); DPRINT("NtUserCreateWindowEx(): send CREATE message failed.\n"); - return(NULL); + return((HWND)0); } /* Send move and size messages. */ @@ -984,8 +1046,9 @@ static LRESULT W32kDestroyWindow(PWINDOW_OBJECT Window, BOOLEAN STDCALL NtUserDestroyWindow(HWND Wnd) { - BOOL isChild; PWINDOW_OBJECT Window; + BOOLEAN isChild; + HWND hWndFocus; Window = W32kGetWindowObject(Wnd); if (Window == NULL) @@ -996,6 +1059,7 @@ NtUserDestroyWindow(HWND Wnd) /* Check for desktop window (has NULL parent) */ if (NULL == Window->Parent) { + W32kReleaseWindowObject(Window); SetLastWin32Error(ERROR_ACCESS_DENIED); return FALSE; } @@ -1003,18 +1067,16 @@ NtUserDestroyWindow(HWND Wnd) /* Look whether the focus is within the tree of windows we will * be destroying. */ -#if 0 /* FIXME */ - h = GetFocus(); - if (h == Wnd || IsChild(Wnd, h)) + hWndFocus = W32kGetFocusWindow(); + if (hWndFocus == Wnd || W32kIsChildWindow(Wnd, hWndFocus)) { - HWND Parent = GetAncestor(Wnd, GA_PARENT); - if (Parent == GetDesktopWindow()) - { - Parent = NULL; - } - SetFocus(Parent); + HWND Parent = NtUserGetAncestor(Wnd, GA_PARENT); + if (Parent == W32kGetDesktopWindow()) + { + Parent = NULL; + } + W32kSetFocusWindow(Parent); } -#endif /* Call hooks */ #if 0 /* FIXME */ diff --git a/reactos/subsys/win32k/ntuser/winpos.c b/reactos/subsys/win32k/ntuser/winpos.c index 84c9827427d..36673a35fd5 100644 --- a/reactos/subsys/win32k/ntuser/winpos.c +++ b/reactos/subsys/win32k/ntuser/winpos.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: winpos.c,v 1.11 2003/05/18 22:09:08 gvg Exp $ +/* $Id: winpos.c,v 1.12 2003/07/05 16:04:01 chorns Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -346,9 +346,25 @@ WinPosGetMinMaxInfo(PWINDOW_OBJECT Window, POINT* MaxSize, POINT* MaxPos, } BOOL STATIC FASTCALL -WinPosChangeActiveWindow(HWND Wnd, BOOL MouseMsg) +WinPosChangeActiveWindow(HWND hWnd, BOOL MouseMsg) { - return FALSE; + PWINDOW_OBJECT WindowObject; + + WindowObject = W32kGetWindowObject(hWnd); + if (WindowObject == NULL) + { + return FALSE; + } + + NtUserSendMessage(hWnd, + WM_ACTIVATE, + MAKELONG(MouseMsg ? WA_CLICKACTIVE : WA_CLICKACTIVE, + (WindowObject->Style & WS_MINIMIZE) ? 1 : 0), + W32kGetDesktopWindow()); /* FIXME: Previous active window */ + + W32kReleaseWindowObject(WindowObject); + + return TRUE; } LONG STATIC STDCALL @@ -759,6 +775,13 @@ WinPosShowWindow(HWND Wnd, INT Cmd) MAKELONG(Window->ClientRect.left, Window->ClientRect.top)); } + + /* Activate the window if activation is not requested and the window is not minimized */ + if (!(Swp & (SWP_NOACTIVATE | SWP_HIDEWINDOW)) && !(Window->Style & WS_MINIMIZE)) + { + WinPosChangeActiveWindow(Wnd, FALSE); + } + ObmDereferenceObject(Window); return(WasVisible); } diff --git a/reactos/subsys/win32k/ntuser/winsta.c b/reactos/subsys/win32k/ntuser/winsta.c index 358101e46a4..69d9e56df2d 100644 --- a/reactos/subsys/win32k/ntuser/winsta.c +++ b/reactos/subsys/win32k/ntuser/winsta.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: winsta.c,v 1.16 2003/06/20 16:26:14 ekohl Exp $ +/* $Id: winsta.c,v 1.17 2003/07/05 16:04:01 chorns Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -74,6 +74,21 @@ W32kGetActiveDesktop(VOID) return(InputDesktop); } +PUSER_MESSAGE_QUEUE FASTCALL +W32kGetFocusMessageQueue(VOID) +{ + PDESKTOP_OBJECT pdo = W32kGetActiveDesktop(); + + if (!pdo) + { + DPRINT("No active desktop\n"); + return(NULL); + } + + return (PUSER_MESSAGE_QUEUE)pdo->ActiveMessageQueue; +} + + NTSTATUS FASTCALL InitWindowStationImpl(VOID) {