From 8f52632ca9925c376bacf60444739a3635f776d7 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Tue, 16 Nov 2021 12:33:53 +0100 Subject: [PATCH] win32u: Move NtUserVkKeyScanEx implementation from user32. Signed-off-by: Jacek Caban Signed-off-by: Huw Davies Signed-off-by: Alexandre Julliard --- dlls/user32/driver.c | 7 +--- dlls/user32/input.c | 69 ++---------------------------------- dlls/user32/user32.spec | 2 +- dlls/win32u/driver.c | 6 ++++ dlls/win32u/gdiobj.c | 1 + dlls/win32u/input.c | 66 ++++++++++++++++++++++++++++++++++ dlls/win32u/win32u.spec | 2 +- dlls/win32u/win32u_private.h | 1 + dlls/win32u/wrappers.c | 5 +++ 9 files changed, 84 insertions(+), 75 deletions(-) diff --git a/dlls/user32/driver.c b/dlls/user32/driver.c index 0b386b0af21..f50b8d73ae5 100644 --- a/dlls/user32/driver.c +++ b/dlls/user32/driver.c @@ -274,11 +274,6 @@ static void CDECL loaderdrv_UnregisterHotKey( HWND hwnd, UINT modifiers, UINT vk load_driver()->pUnregisterHotKey( hwnd, modifiers, vk ); } -static SHORT CDECL loaderdrv_VkKeyScanEx( WCHAR ch, HKL layout ) -{ - return load_driver()->pVkKeyScanEx( ch, layout ); -} - static void CDECL loaderdrv_SetCursor( HCURSOR cursor ) { load_driver()->pSetCursor( cursor ); @@ -374,7 +369,7 @@ static struct user_driver_funcs lazy_load_driver = loaderdrv_RegisterHotKey, loaderdrv_ToUnicodeEx, loaderdrv_UnregisterHotKey, - loaderdrv_VkKeyScanEx, + NULL, /* cursor/icon functions */ nulldrv_DestroyCursorIcon, loaderdrv_SetCursor, diff --git a/dlls/user32/input.c b/dlls/user32/input.c index fc6b6fa5822..7a38a974808 100644 --- a/dlls/user32/input.c +++ b/dlls/user32/input.c @@ -625,7 +625,7 @@ SHORT WINAPI VkKeyScanA(CHAR cChar) */ SHORT WINAPI VkKeyScanW(WCHAR cChar) { - return VkKeyScanExW(cChar, GetKeyboardLayout(0)); + return NtUserVkKeyScanEx( cChar, GetKeyboardLayout(0) ); } /********************************************************************** @@ -638,72 +638,7 @@ WORD WINAPI VkKeyScanExA(CHAR cChar, HKL dwhkl) if (IsDBCSLeadByte(cChar)) return -1; MultiByteToWideChar(CP_ACP, 0, &cChar, 1, &wChar, 1); - return VkKeyScanExW(wChar, dwhkl); -} - -/****************************************************************************** - * VkKeyScanExW (USER32.@) - */ -WORD WINAPI VkKeyScanExW( WCHAR chr, HKL layout ) -{ - WORD shift = 0x100, ctrl = 0x200; - SHORT ret; - - TRACE_(keyboard)( "chr %s, layout %p\n", debugstr_wn(&chr, 1), layout ); - - if ((ret = USER_Driver->pVkKeyScanEx( chr, layout )) != -256) return ret; - - /* FIXME: English keyboard layout specific */ - - if (chr == VK_CANCEL || chr == VK_BACK || chr == VK_TAB || chr == VK_RETURN || - chr == VK_ESCAPE || chr == VK_SPACE) ret = chr; - else if (chr >= '0' && chr <= '9') ret = chr; - else if (chr == ')') ret = shift + '0'; - else if (chr == '!') ret = shift + '1'; - else if (chr == '@') ret = shift + '2'; - else if (chr == '#') ret = shift + '3'; - else if (chr == '$') ret = shift + '4'; - else if (chr == '%') ret = shift + '5'; - else if (chr == '^') ret = shift + '6'; - else if (chr == '&') ret = shift + '7'; - else if (chr == '*') ret = shift + '8'; - else if (chr == '(') ret = shift + '9'; - else if (chr >= 'a' && chr <= 'z') ret = chr - 'a' + 'A'; - else if (chr >= 'A' && chr <= 'Z') ret = shift + chr; - else if (chr == ';') ret = VK_OEM_1; - else if (chr == '=') ret = VK_OEM_PLUS; - else if (chr == ',') ret = VK_OEM_COMMA; - else if (chr == '-') ret = VK_OEM_MINUS; - else if (chr == '.') ret = VK_OEM_PERIOD; - else if (chr == '/') ret = VK_OEM_2; - else if (chr == '`') ret = VK_OEM_3; - else if (chr == '[') ret = VK_OEM_4; - else if (chr == '\\') ret = VK_OEM_5; - else if (chr == ']') ret = VK_OEM_6; - else if (chr == '\'') ret = VK_OEM_7; - else if (chr == ':') ret = shift + VK_OEM_1; - else if (chr == '+') ret = shift + VK_OEM_PLUS; - else if (chr == '<') ret = shift + VK_OEM_COMMA; - else if (chr == '_') ret = shift + VK_OEM_MINUS; - else if (chr == '>') ret = shift + VK_OEM_PERIOD; - else if (chr == '?') ret = shift + VK_OEM_2; - else if (chr == '~') ret = shift + VK_OEM_3; - else if (chr == '{') ret = shift + VK_OEM_4; - else if (chr == '|') ret = shift + VK_OEM_5; - else if (chr == '}') ret = shift + VK_OEM_6; - else if (chr == '\"') ret = shift + VK_OEM_7; - else if (chr == 0x7f) ret = ctrl + VK_BACK; - else if (chr == '\n') ret = ctrl + VK_RETURN; - else if (chr == 0xf000) ret = ctrl + '2'; - else if (chr == 0x0000) ret = ctrl + shift + '2'; - else if (chr >= 0x0001 && chr <= 0x001a) ret = ctrl + 'A' + chr - 1; - else if (chr >= 0x001c && chr <= 0x001d) ret = ctrl + VK_OEM_3 + chr; - else if (chr == 0x001e) ret = ctrl + shift + '6'; - else if (chr == 0x001f) ret = ctrl + shift + VK_OEM_MINUS; - else ret = -1; - - TRACE_(keyboard)( "ret %04x\n", ret ); - return ret; + return NtUserVkKeyScanEx( wChar, dwhkl ); } /********************************************************************** diff --git a/dlls/user32/user32.spec b/dlls/user32/user32.spec index e48f30b46ca..31c33d0ba5c 100644 --- a/dlls/user32/user32.spec +++ b/dlls/user32/user32.spec @@ -805,7 +805,7 @@ @ stdcall ValidateRgn(long long) @ stdcall VkKeyScanA(long) @ stdcall VkKeyScanExA(long long) -@ stdcall VkKeyScanExW(long long) +@ stdcall VkKeyScanExW(long long) NtUserVkKeyScanEx @ stdcall VkKeyScanW(long) @ stub WCSToMBEx @ stdcall WINNLSEnableIME(long long) diff --git a/dlls/win32u/driver.c b/dlls/win32u/driver.c index 15e7d3701f7..f2d64a0a41b 100644 --- a/dlls/win32u/driver.c +++ b/dlls/win32u/driver.c @@ -1003,6 +1003,11 @@ static const struct user_driver_funcs *load_driver(void) return user_driver; } +static SHORT CDECL loaderdrv_VkKeyScanEx( WCHAR ch, HKL layout ) +{ + return load_driver()->pVkKeyScanEx( ch, layout ); +} + static void CDECL loaderdrv_UpdateClipboard(void) { load_driver()->pUpdateClipboard(); @@ -1010,6 +1015,7 @@ static void CDECL loaderdrv_UpdateClipboard(void) static const struct user_driver_funcs lazy_load_driver = { + .pVkKeyScanEx = loaderdrv_VkKeyScanEx, .pUpdateClipboard = loaderdrv_UpdateClipboard, }; diff --git a/dlls/win32u/gdiobj.c b/dlls/win32u/gdiobj.c index a03e1365737..2dcb60980c4 100644 --- a/dlls/win32u/gdiobj.c +++ b/dlls/win32u/gdiobj.c @@ -1171,6 +1171,7 @@ static struct unix_funcs unix_funcs = NtUserGetPriorityClipboardFormat, NtUserGetUpdatedClipboardFormats, NtUserIsClipboardFormatAvailable, + NtUserVkKeyScanEx, GDIRealizePalette, GDISelectPalette, diff --git a/dlls/win32u/input.c b/dlls/win32u/input.c index feab4693fad..ae104371f5c 100644 --- a/dlls/win32u/input.c +++ b/dlls/win32u/input.c @@ -31,6 +31,7 @@ #include "wine/debug.h" WINE_DEFAULT_DEBUG_CHANNEL(win); +WINE_DECLARE_DEBUG_CHANNEL(keyboard); /********************************************************************** @@ -109,3 +110,68 @@ BOOL WINAPI NtUserSetKeyboardState( BYTE *state ) SERVER_END_REQ; return ret; } + +/****************************************************************************** + * NtUserVkKeyScanEx (win32u.@) + */ +WORD WINAPI NtUserVkKeyScanEx( WCHAR chr, HKL layout ) +{ + WORD shift = 0x100, ctrl = 0x200; + SHORT ret; + + TRACE_(keyboard)( "chr %s, layout %p\n", debugstr_wn(&chr, 1), layout ); + + if ((ret = user_driver->pVkKeyScanEx( chr, layout )) != -256) return ret; + + /* FIXME: English keyboard layout specific */ + + if (chr == VK_CANCEL || chr == VK_BACK || chr == VK_TAB || chr == VK_RETURN || + chr == VK_ESCAPE || chr == VK_SPACE) ret = chr; + else if (chr >= '0' && chr <= '9') ret = chr; + else if (chr == ')') ret = shift + '0'; + else if (chr == '!') ret = shift + '1'; + else if (chr == '@') ret = shift + '2'; + else if (chr == '#') ret = shift + '3'; + else if (chr == '$') ret = shift + '4'; + else if (chr == '%') ret = shift + '5'; + else if (chr == '^') ret = shift + '6'; + else if (chr == '&') ret = shift + '7'; + else if (chr == '*') ret = shift + '8'; + else if (chr == '(') ret = shift + '9'; + else if (chr >= 'a' && chr <= 'z') ret = chr - 'a' + 'A'; + else if (chr >= 'A' && chr <= 'Z') ret = shift + chr; + else if (chr == ';') ret = VK_OEM_1; + else if (chr == '=') ret = VK_OEM_PLUS; + else if (chr == ',') ret = VK_OEM_COMMA; + else if (chr == '-') ret = VK_OEM_MINUS; + else if (chr == '.') ret = VK_OEM_PERIOD; + else if (chr == '/') ret = VK_OEM_2; + else if (chr == '`') ret = VK_OEM_3; + else if (chr == '[') ret = VK_OEM_4; + else if (chr == '\\') ret = VK_OEM_5; + else if (chr == ']') ret = VK_OEM_6; + else if (chr == '\'') ret = VK_OEM_7; + else if (chr == ':') ret = shift + VK_OEM_1; + else if (chr == '+') ret = shift + VK_OEM_PLUS; + else if (chr == '<') ret = shift + VK_OEM_COMMA; + else if (chr == '_') ret = shift + VK_OEM_MINUS; + else if (chr == '>') ret = shift + VK_OEM_PERIOD; + else if (chr == '?') ret = shift + VK_OEM_2; + else if (chr == '~') ret = shift + VK_OEM_3; + else if (chr == '{') ret = shift + VK_OEM_4; + else if (chr == '|') ret = shift + VK_OEM_5; + else if (chr == '}') ret = shift + VK_OEM_6; + else if (chr == '\"') ret = shift + VK_OEM_7; + else if (chr == 0x7f) ret = ctrl + VK_BACK; + else if (chr == '\n') ret = ctrl + VK_RETURN; + else if (chr == 0xf000) ret = ctrl + '2'; + else if (chr == 0x0000) ret = ctrl + shift + '2'; + else if (chr >= 0x0001 && chr <= 0x001a) ret = ctrl + 'A' + chr - 1; + else if (chr >= 0x001c && chr <= 0x001d) ret = ctrl + VK_OEM_3 + chr; + else if (chr == 0x001e) ret = ctrl + shift + '6'; + else if (chr == 0x001f) ret = ctrl + shift + VK_OEM_MINUS; + else ret = -1; + + TRACE_(keyboard)( "ret %04x\n", ret ); + return ret; +} diff --git a/dlls/win32u/win32u.spec b/dlls/win32u/win32u.spec index df48dfe9586..35d42c073c9 100644 --- a/dlls/win32u/win32u.spec +++ b/dlls/win32u/win32u.spec @@ -1302,7 +1302,7 @@ @ stub NtUserUserHandleGrantAccess @ stub NtUserValidateRect @ stub NtUserValidateTimerCallback -@ stub NtUserVkKeyScanEx +@ stdcall NtUserVkKeyScanEx(long long) @ stub NtUserWOWCleanup @ stub NtUserWaitAvailableMessageEx @ stub NtUserWaitForInputIdle diff --git a/dlls/win32u/win32u_private.h b/dlls/win32u/win32u_private.h index 92f7c83576e..d9a06e64c9c 100644 --- a/dlls/win32u/win32u_private.h +++ b/dlls/win32u/win32u_private.h @@ -198,6 +198,7 @@ struct unix_funcs INT (WINAPI *pNtUserGetPriorityClipboardFormat)( UINT *list, INT count ); BOOL (WINAPI *pNtUserGetUpdatedClipboardFormats)( UINT *formats, UINT size, UINT *out_size ); BOOL (WINAPI *pNtUserIsClipboardFormatAvailable)( UINT format ); + WORD (WINAPI *pNtUserVkKeyScanEx)( WCHAR chr, HKL layout ); /* Wine-specific functions */ UINT (WINAPI *pGDIRealizePalette)( HDC hdc ); diff --git a/dlls/win32u/wrappers.c b/dlls/win32u/wrappers.c index dd3186ed2da..4aa83eb8ceb 100644 --- a/dlls/win32u/wrappers.c +++ b/dlls/win32u/wrappers.c @@ -616,6 +616,11 @@ BOOL WINAPI NtUserIsClipboardFormatAvailable( UINT format ) return unix_funcs->pNtUserIsClipboardFormatAvailable( format ); } +WORD WINAPI NtUserVkKeyScanEx( WCHAR chr, HKL layout ) +{ + return unix_funcs->pNtUserVkKeyScanEx( chr, layout ); +} + UINT WINAPI GDIRealizePalette( HDC hdc ) { return unix_funcs->pGDIRealizePalette( hdc );