From 2a76c1a5a02a0881bfeb2d479c78e5d4cd69a972 Mon Sep 17 00:00:00 2001 From: James Tabor Date: Sat, 10 Oct 2009 04:40:36 +0000 Subject: [PATCH] - [Win32k] Implement AttachThreadInput, not yet connected to the thread message queue, update related. - See http://www.codeproject.com/KB/cpp/onscreenkeyboard.aspx for test program. svn path=/trunk/; revision=43352 --- reactos/include/reactos/win32k/ntuser.h | 8 ++- .../subsystems/win32/win32k/include/input.h | 10 +++ .../subsystems/win32/win32k/include/tags.h | 1 + .../subsystems/win32/win32k/include/win32.h | 8 +++ .../subsystems/win32/win32k/ntuser/input.c | 71 ++++++++++++++----- .../subsystems/win32/win32k/ntuser/ntstubs.c | 31 +++++++- 6 files changed, 107 insertions(+), 22 deletions(-) diff --git a/reactos/include/reactos/win32k/ntuser.h b/reactos/include/reactos/win32k/ntuser.h index 1f4081d918b..934528df955 100644 --- a/reactos/include/reactos/win32k/ntuser.h +++ b/reactos/include/reactos/win32k/ntuser.h @@ -124,7 +124,13 @@ typedef struct _CALLBACKWND PVOID pvWnd; } CALLBACKWND, *PCALLBACKWND; -#define CI_CURTHPRHOOK 0x00000010 +#define CI_TRANSACTION 0x00000001 +#define CI_QUEUEMSG 0x00000002 +#define CI_WOW 0x00000004 +#define CI_INITTHREAD 0x00000008 +#define CI_CURTHPRHOOK 0x00000010 +#define CI_CLASSESREGISTERED 0x00000020 +#define CI_IMMACTIVATE 0x00000040 typedef struct _CLIENTINFO { diff --git a/reactos/subsystems/win32/win32k/include/input.h b/reactos/subsystems/win32/win32k/include/input.h index 1a97b3afd50..86deb303e87 100644 --- a/reactos/subsystems/win32/win32k/include/input.h +++ b/reactos/subsystems/win32/win32k/include/input.h @@ -15,6 +15,15 @@ typedef struct _KBL DWORD klid; // Low word - language id. High word - device id. } KBL, *PKBL; +typedef struct _ATTACHINFO +{ + struct _ATTACHINFO* paiNext; + PTHREADINFO pti1; + PTHREADINFO pti2; +} ATTACHINFO, *PATTACHINFO; + +extern PATTACHINFO gpai; + #define KBL_UNLOAD 1 #define KBL_PRELOAD 2 #define KBL_RESET 4 @@ -33,6 +42,7 @@ BOOL FASTCALL IntKeyboardInput(KEYBDINPUT *ki); BOOL UserInitDefaultKeyboardLayout(); PKBL UserHklToKbl(HKL hKl); +BOOL FASTCALL UserAttachThreadInput(PTHREADINFO,PTHREADINFO,BOOL); #define ThreadHasInputAccess(W32Thread) \ (TRUE) diff --git a/reactos/subsystems/win32/win32k/include/tags.h b/reactos/subsystems/win32/win32k/include/tags.h index 7f802e22d1a..0688639ca1e 100644 --- a/reactos/subsystems/win32/win32k/include/tags.h +++ b/reactos/subsystems/win32/win32k/include/tags.h @@ -26,6 +26,7 @@ #define TAG_CALLBACK 'KCBC' /* callback memory */ #define TAG_WINSTA 'ATSW' /* window station */ #define TAG_PDCE 'cdsU' /* dce */ +#define TAG_ATTACHINFO 'iasU' /* Attach Info Input */ #define TAG_INPUT 'yssU' /* Input */ /* gdi objects from the handle table */ diff --git a/reactos/subsystems/win32/win32k/include/win32.h b/reactos/subsystems/win32/win32k/include/win32.h index cb9fbf824d1..1cd75082fa8 100644 --- a/reactos/subsystems/win32/win32k/include/win32.h +++ b/reactos/subsystems/win32/win32k/include/win32.h @@ -105,10 +105,18 @@ typedef struct _THREADINFO PDESKTOPINFO pDeskInfo; PCLIENTINFO pClientInfo; FLONG TIF_flags; + PUNICODE_STRING pstrAppName; LONG timeLast; + ULONG_PTR idLast; + INT exitCode; HANDLE hDesktop; UINT cPaintsReady; /* Count of paints pending. */ UINT cTimersReady; /* Count of timers pending. */ + DWORD dwExpWinVer; + DWORD dwCompatFlags; + DWORD dwCompatFlags2; + struct _USER_MESSAGE_QUEUE* pqAttach; + PTHREADINFO ptiSibling; ULONG fsHooks; PHOOK sphkCurrent; LIST_ENTRY PtiLink; diff --git a/reactos/subsystems/win32/win32k/ntuser/input.c b/reactos/subsystems/win32/win32k/ntuser/input.c index dbbcc82c9a6..8a65c45b846 100644 --- a/reactos/subsystems/win32/win32k/ntuser/input.c +++ b/reactos/subsystems/win32/win32k/ntuser/input.c @@ -1,23 +1,4 @@ /* - * ReactOS W32 Subsystem - * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -/* $Id$ - * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel * PURPOSE: Window classes @@ -42,6 +23,7 @@ extern NTSTATUS Win32kInitWin32Thread(PETHREAD Thread); PTHREADINFO ptiRawInput; PKTIMER MasterTimer; +PATTACHINFO gpai = NULL; static HANDLE MouseDeviceHandle; static HANDLE MouseThreadHandle; @@ -1324,6 +1306,57 @@ IntKeyboardInput(KEYBDINPUT *ki) return FALSE; } +BOOL FASTCALL +UserAttachThreadInput( PTHREADINFO pti, PTHREADINFO ptiTo, BOOL fAttach) +{ + PATTACHINFO pai; + + /* Can not be the same thread.*/ + if (pti == ptiTo) return FALSE; + + /* Do not attach if IMM is in activate mode or between different desktops. */ + if ( pti->pClientInfo->CI_flags & CI_IMMACTIVATE || + ptiTo->pClientInfo->CI_flags & CI_IMMACTIVATE || + pti->Desktop != ptiTo->Desktop ) + return FALSE; + + /* If Attach set, allocate and link. */ + if ( fAttach ) + { + pai = ExAllocatePoolWithTag(PagedPool, sizeof(ATTACHINFO), TAG_ATTACHINFO); + if ( !pai ) return FALSE; + + pai->paiNext = gpai; + pai->pti1 = pti; + pai->pti2 = ptiTo; + gpai = pai; + } + else /* If clear, unlink and free it. */ + { + PATTACHINFO paiprev = NULL; + + if ( !gpai ) return FALSE; + + pai = gpai; + + /* Search list and free if found or return false. */ + do + { + if ( pai->pti2 == ptiTo && pai->pti1 == pti ) break; + paiprev = pai; + pai = pai->paiNext; + } while (pai); + + if ( !pai ) return FALSE; + + if (paiprev) paiprev->paiNext = pai->paiNext; + + ExFreePoolWithTag(pai, TAG_ATTACHINFO); + } + + return TRUE; +} + UINT APIENTRY NtUserSendInput( diff --git a/reactos/subsystems/win32/win32k/ntuser/ntstubs.c b/reactos/subsystems/win32/win32k/ntuser/ntstubs.c index 7fad1fb9081..d014a00cfd7 100644 --- a/reactos/subsystems/win32/win32k/ntuser/ntstubs.c +++ b/reactos/subsystems/win32/win32k/ntuser/ntstubs.c @@ -31,9 +31,36 @@ NtUserAttachThreadInput( IN DWORD idAttachTo, IN BOOL fAttach) { - UNIMPLEMENTED + NTSTATUS Status; + PETHREAD Thread, ThreadTo; + PTHREADINFO pti, ptiTo; + BOOL Ret = FALSE; - return 0; + UserEnterExclusive(); + Status = PsLookupThreadByThreadId((HANDLE)idAttach, &Thread); + if (!NT_SUCCESS(Status)) + { + SetLastWin32Error(ERROR_INVALID_PARAMETER); + goto Exit; + } + Status = PsLookupThreadByThreadId((HANDLE)idAttachTo, &ThreadTo); + if (!NT_SUCCESS(Status)) + { + SetLastWin32Error(ERROR_INVALID_PARAMETER); + ObDereferenceObject(Thread); + goto Exit; + } + + pti = PsGetThreadWin32Thread(Thread); + ptiTo = PsGetThreadWin32Thread(ThreadTo); + ObDereferenceObject(Thread); + ObDereferenceObject(ThreadTo); + + Ret = UserAttachThreadInput( pti, ptiTo, fAttach); + +Exit: + UserLeave(); + return Ret; } //