win32u: Move NtUserGetKeyboardLayout implementation from user32.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2021-11-16 12:35:43 +01:00 committed by Alexandre Julliard
parent 8d34353878
commit 563a233284
11 changed files with 106 additions and 63 deletions

View File

@ -625,7 +625,7 @@ SHORT WINAPI VkKeyScanA(CHAR cChar)
*/
SHORT WINAPI VkKeyScanW(WCHAR cChar)
{
return NtUserVkKeyScanEx( cChar, GetKeyboardLayout(0) );
return NtUserVkKeyScanEx( cChar, NtUserGetKeyboardLayout(0) );
}
/**********************************************************************
@ -668,7 +668,7 @@ DWORD WINAPI OemKeyScan( WORD oem )
INT WINAPI GetKeyboardType(INT nTypeFlag)
{
TRACE_(keyboard)("(%d)\n", nTypeFlag);
if (LOWORD(GetKeyboardLayout(0)) == MAKELANGID(LANG_JAPANESE, SUBLANG_JAPANESE_JAPAN))
if (LOWORD(NtUserGetKeyboardLayout(0)) == MAKELANGID(LANG_JAPANESE, SUBLANG_JAPANESE_JAPAN))
{
/* scan code for `_', the key left of r-shift, in Japanese 106 keyboard */
const UINT JP106_VSC_USCORE = 0x73;
@ -709,7 +709,7 @@ INT WINAPI GetKeyboardType(INT nTypeFlag)
*/
UINT WINAPI MapVirtualKeyA(UINT code, UINT maptype)
{
return MapVirtualKeyExA( code, maptype, GetKeyboardLayout(0) );
return MapVirtualKeyExA( code, maptype, NtUserGetKeyboardLayout(0) );
}
/******************************************************************************
@ -717,7 +717,7 @@ UINT WINAPI MapVirtualKeyA(UINT code, UINT maptype)
*/
UINT WINAPI MapVirtualKeyW(UINT code, UINT maptype)
{
return NtUserMapVirtualKeyEx( code, maptype, GetKeyboardLayout(0) );
return NtUserMapVirtualKeyEx( code, maptype, NtUserGetKeyboardLayout(0) );
}
/******************************************************************************
@ -840,25 +840,6 @@ UINT WINAPI GetKBCodePage(void)
return GetOEMCP();
}
/***********************************************************************
* GetKeyboardLayout (USER32.@)
*
* - device handle for keyboard layout defaulted to
* the language id. This is the way Windows default works.
* - the thread identifier is also ignored.
*/
HKL WINAPI GetKeyboardLayout(DWORD thread_id)
{
struct user_thread_info *thread = get_user_thread_info();
HKL layout = thread->kbd_layout;
if (thread_id && thread_id != GetCurrentThreadId())
FIXME( "couldn't return keyboard layout for thread %04x\n", thread_id );
if (!layout) return get_locale_kbd_layout();
return layout;
}
/****************************************************************************
* GetKeyboardLayoutNameA (USER32.@)
*/
@ -896,7 +877,7 @@ BOOL WINAPI GetKeyboardLayoutNameW( WCHAR *name )
return TRUE;
}
layout = GetKeyboardLayout( 0 );
layout = NtUserGetKeyboardLayout( 0 );
tmp = HandleToUlong( layout );
if (HIWORD( tmp ) == LOWORD( tmp )) tmp = LOWORD( tmp );
swprintf( name, KL_NAMELENGTH, L"%08X", tmp );
@ -1007,7 +988,8 @@ INT WINAPI GetKeyNameTextW( LONG lparam, LPWSTR buffer, INT size )
INT WINAPI ToUnicode(UINT virtKey, UINT scanCode, const BYTE *lpKeyState,
LPWSTR lpwStr, int size, UINT flags)
{
return ToUnicodeEx(virtKey, scanCode, lpKeyState, lpwStr, size, flags, GetKeyboardLayout(0));
return ToUnicodeEx( virtKey, scanCode, lpKeyState, lpwStr, size, flags,
NtUserGetKeyboardLayout(0) );
}
/****************************************************************************
@ -1107,7 +1089,8 @@ INT WINAPI ToUnicodeEx( UINT virt, UINT scan, const BYTE *state,
INT WINAPI ToAscii( UINT virtKey, UINT scanCode, const BYTE *lpKeyState,
LPWORD lpChar, UINT flags )
{
return ToAsciiEx(virtKey, scanCode, lpKeyState, lpChar, flags, GetKeyboardLayout(0));
return ToAsciiEx( virtKey, scanCode, lpKeyState, lpChar, flags,
NtUserGetKeyboardLayout(0) );
}
/****************************************************************************

View File

@ -586,7 +586,7 @@ DWORD get_input_codepage( void )
{
DWORD cp;
int ret;
HKL hkl = GetKeyboardLayout( 0 );
HKL hkl = NtUserGetKeyboardLayout( 0 );
ret = GetLocaleInfoW( LOWORD(hkl), LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
(WCHAR *)&cp, sizeof(cp) / sizeof(WCHAR) );
@ -2377,7 +2377,7 @@ static BOOL process_keyboard_message( MSG *msg, UINT hw_id, HWND hwnd_filter,
msg->pt = point_phys_to_win_dpi( msg->hwnd, msg->pt );
if ( remove && msg->message == WM_KEYDOWN )
if (ImmProcessKey(msg->hwnd, GetKeyboardLayout(0), msg->wParam, msg->lParam, 0) )
if (ImmProcessKey(msg->hwnd, NtUserGetKeyboardLayout(0), msg->wParam, msg->lParam, 0) )
msg->wParam = VK_PROCESSKEY;
return TRUE;

View File

@ -606,7 +606,7 @@ LRESULT WINAPI ImeWndProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
if (imm_get_ui_window && is_ime_ui_msg(msg))
{
if ((uiwnd = imm_get_ui_window(GetKeyboardLayout(0))))
if ((uiwnd = imm_get_ui_window( NtUserGetKeyboardLayout(0) )))
return SendMessageA(uiwnd, msg, wParam, lParam);
return FALSE;
}
@ -626,7 +626,7 @@ LRESULT WINAPI ImeWndProcW( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
if (imm_get_ui_window && is_ime_ui_msg(msg))
{
if ((uiwnd = imm_get_ui_window(GetKeyboardLayout(0))))
if ((uiwnd = imm_get_ui_window( NtUserGetKeyboardLayout(0) )))
return SendMessageW(uiwnd, msg, wParam, lParam);
return FALSE;
}

View File

@ -2065,7 +2065,7 @@ BOOL WINAPI SystemParametersInfoW( UINT uiAction, UINT uiParam,
WINE_SPI_FIXME(SPI_SETICONS); /* 88 WINVER >= 0x400 */
case SPI_GETDEFAULTINPUTLANG: /* 89 WINVER >= 0x400 */
ret = GetKeyboardLayout(0) != 0;
ret = NtUserGetKeyboardLayout(0) != 0;
break;
WINE_SPI_FIXME(SPI_SETDEFAULTINPUTLANG); /* 90 WINVER >= 0x400 */

View File

@ -317,7 +317,7 @@
@ stdcall GetKeyNameTextA(long ptr long)
@ stdcall GetKeyNameTextW(long ptr long)
@ stdcall -import GetKeyState(long) NtUserGetKeyState
@ stdcall GetKeyboardLayout(long)
@ stdcall GetKeyboardLayout(long) NtUserGetKeyboardLayout
@ stdcall GetKeyboardLayoutList(long ptr)
@ stdcall GetKeyboardLayoutNameA(ptr)
@ stdcall GetKeyboardLayoutNameW(ptr)

View File

@ -123,36 +123,6 @@ struct rawinput_thread_data
RAWINPUT buffer[1]; /* rawinput message data buffer */
};
/* this is the structure stored in TEB->Win32ClientInfo */
/* no attempt is made to keep the layout compatible with the Windows one */
struct user_thread_info
{
HANDLE server_queue; /* Handle to server-side queue */
DWORD wake_mask; /* Current queue wake mask */
DWORD changed_mask; /* Current queue changed mask */
WORD recursion_count; /* SendMessage recursion counter */
WORD message_count; /* Get/PeekMessage loop counter */
WORD hook_call_depth; /* Number of recursively called hook procs */
WORD hook_unicode; /* Is current hook unicode? */
HHOOK hook; /* Current hook */
UINT active_hooks; /* Bitmap of active hooks */
DPI_AWARENESS dpi_awareness; /* DPI awareness */
INPUT_MESSAGE_SOURCE msg_source; /* Message source for current message */
struct received_message_info *receive_info; /* Message being currently received */
struct wm_char_mapping_data *wmchar_data; /* Data for WM_CHAR mappings */
DWORD GetMessageTimeVal; /* Value for GetMessageTime */
DWORD GetMessagePosVal; /* Value for GetMessagePos */
ULONG_PTR GetMessageExtraInfoVal; /* Value for GetMessageExtraInfo */
struct user_key_state_info *key_state; /* Cache of global key state */
HKL kbd_layout; /* Current keyboard layout */
DWORD kbd_layout_id; /* Current keyboard layout ID */
HWND top_window; /* Desktop window */
HWND msg_window; /* HWND_MESSAGE parent window */
struct rawinput_thread_data *rawinput; /* RawInput thread local data / buffer */
};
C_ASSERT( sizeof(struct user_thread_info) <= sizeof(((TEB *)0)->Win32ClientInfo) );
extern INT global_key_state_counter DECLSPEC_HIDDEN;
extern BOOL (WINAPI *imm_register_window)(HWND) DECLSPEC_HIDDEN;
extern void (WINAPI *imm_unregister_window)(HWND) DECLSPEC_HIDDEN;

View File

@ -52,6 +52,60 @@ BOOL WINAPI NtUserAttachThreadInput( DWORD from, DWORD to, BOOL attach )
return ret;
}
/***********************************************************************
* get_locale_kbd_layout
*/
static HKL get_locale_kbd_layout(void)
{
LCID layout;
LANGID langid;
/* FIXME:
*
* layout = main_key_tab[kbd_layout].lcid;
*
* Winword uses return value of GetKeyboardLayout as a codepage
* to translate ANSI keyboard messages to unicode. But we have
* a problem with it: for instance Polish keyboard layout is
* identical to the US one, and therefore instead of the Polish
* locale id we return the US one.
*/
NtQueryDefaultLocale( TRUE, &layout );
/*
* Microsoft Office expects this value to be something specific
* for Japanese and Korean Windows with an IME the value is 0xe001
* We should probably check to see if an IME exists and if so then
* set this word properly.
*/
langid = PRIMARYLANGID( LANGIDFROMLCID( layout ) );
if (langid == LANG_CHINESE || langid == LANG_JAPANESE || langid == LANG_KOREAN)
layout = MAKELONG( layout, 0xe001 ); /* IME */
else
layout = MAKELONG( layout, layout );
return ULongToHandle( layout );
}
/***********************************************************************
* NtUserGetKeyboardLayout (win32u.@)
*
* Device handle for keyboard layout defaulted to
* the language id. This is the way Windows default works.
*/
HKL WINAPI NtUserGetKeyboardLayout( DWORD thread_id )
{
struct user_thread_info *thread = get_user_thread_info();
HKL layout = thread->kbd_layout;
if (thread_id && thread_id != GetCurrentThreadId())
FIXME( "couldn't return keyboard layout for thread %04x\n", thread_id );
if (!layout) return get_locale_kbd_layout();
return layout;
}
/**********************************************************************
* NtUserGetKeyState (win32u.@)
*

View File

@ -112,6 +112,7 @@ static void * const syscalls[] =
NtUserGetClipboardSequenceNumber,
NtUserGetClipboardViewer,
NtUserGetKeyState,
NtUserGetKeyboardLayout,
NtUserGetKeyboardState,
NtUserGetLayeredWindowAttributes,
NtUserGetObjectInformation,

View File

@ -946,7 +946,7 @@
@ stub NtUserGetInternalWindowPos
@ stub NtUserGetKeyNameText
@ stdcall -syscall NtUserGetKeyState(long)
@ stub NtUserGetKeyboardLayout
@ stdcall -syscall NtUserGetKeyboardLayout(long)
@ stub NtUserGetKeyboardLayoutList
@ stub NtUserGetKeyboardLayoutName
@ stdcall -syscall NtUserGetKeyboardState(ptr)

View File

@ -235,6 +235,11 @@ extern HKEY reg_open_key( HKEY root, const WCHAR *name, ULONG name_len ) DECLSPE
extern ULONG query_reg_ascii_value( HKEY hkey, const char *name,
KEY_VALUE_PARTIAL_INFORMATION *info, ULONG size ) DECLSPEC_HIDDEN;
static inline struct user_thread_info *get_user_thread_info(void)
{
return (struct user_thread_info *)NtCurrentTeb()->Win32ClientInfo;
}
extern const struct user_driver_funcs *user_driver DECLSPEC_HIDDEN;
static inline BOOL set_ntstatus( NTSTATUS status )

View File

@ -23,6 +23,36 @@
#include <wingdi.h>
#include <winternl.h>
/* this is the structure stored in TEB->Win32ClientInfo */
/* no attempt is made to keep the layout compatible with the Windows one */
struct user_thread_info
{
HANDLE server_queue; /* Handle to server-side queue */
DWORD wake_mask; /* Current queue wake mask */
DWORD changed_mask; /* Current queue changed mask */
WORD recursion_count; /* SendMessage recursion counter */
WORD message_count; /* Get/PeekMessage loop counter */
WORD hook_call_depth; /* Number of recursively called hook procs */
WORD hook_unicode; /* Is current hook unicode? */
HHOOK hook; /* Current hook */
UINT active_hooks; /* Bitmap of active hooks */
DPI_AWARENESS dpi_awareness; /* DPI awareness */
INPUT_MESSAGE_SOURCE msg_source; /* Message source for current message */
struct received_message_info *receive_info; /* Message being currently received */
struct wm_char_mapping_data *wmchar_data; /* Data for WM_CHAR mappings */
DWORD GetMessageTimeVal; /* Value for GetMessageTime */
DWORD GetMessagePosVal; /* Value for GetMessagePos */
ULONG_PTR GetMessageExtraInfoVal; /* Value for GetMessageExtraInfo */
struct user_key_state_info *key_state; /* Cache of global key state */
HKL kbd_layout; /* Current keyboard layout */
DWORD kbd_layout_id; /* Current keyboard layout ID */
HWND top_window; /* Desktop window */
HWND msg_window; /* HWND_MESSAGE parent window */
struct rawinput_thread_data *rawinput; /* RawInput thread local data / buffer */
};
C_ASSERT( sizeof(struct user_thread_info) <= sizeof(((TEB *)0)->Win32ClientInfo) );
BOOL WINAPI NtUserAddClipboardFormatListener( HWND hwnd );
BOOL WINAPI NtUserAttachThreadInput( DWORD from, DWORD to, BOOL attach );
BOOL WINAPI NtUserCloseDesktop( HDESK handle );