From 6ea417b2d5a6c2d589578f1e9f958af64eb6f0fd Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Fri, 15 Apr 2022 14:52:36 +0200 Subject: [PATCH] win32u: Move NtUserTranslateMessage implementation from user32. Signed-off-by: Jacek Caban Signed-off-by: Huw Davies Signed-off-by: Alexandre Julliard --- dlls/user32/message.c | 46 +---------------------------- dlls/user32/user_main.c | 2 ++ dlls/win32u/gdiobj.c | 1 + dlls/win32u/message.c | 57 ++++++++++++++++++++++++++++++++++++ dlls/win32u/ntuser_private.h | 1 + dlls/win32u/win32u.spec | 2 +- dlls/win32u/win32u_private.h | 1 + dlls/win32u/wrappers.c | 6 ++++ include/ntuser.h | 2 ++ 9 files changed, 72 insertions(+), 46 deletions(-) diff --git a/dlls/user32/message.c b/dlls/user32/message.c index 51f183fdbc0..611f603fc1e 100644 --- a/dlls/user32/message.c +++ b/dlls/user32/message.c @@ -45,7 +45,6 @@ #include "wine/exception.h" WINE_DEFAULT_DEBUG_CHANNEL(msg); -WINE_DECLARE_DEBUG_CHANNEL(key); /* Message class descriptor */ @@ -848,50 +847,7 @@ BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG pmsg ) */ BOOL WINAPI TranslateMessage( const MSG *msg ) { - UINT message; - WCHAR wp[8]; - BYTE state[256]; - INT len; - - if (msg->message < WM_KEYFIRST || msg->message > WM_KEYLAST) return FALSE; - if (msg->message != WM_KEYDOWN && msg->message != WM_SYSKEYDOWN) return TRUE; - - TRACE_(key)("Translating key %s (%04lX), scancode %04x\n", - SPY_GetVKeyName(msg->wParam), msg->wParam, HIWORD(msg->lParam)); - - switch (msg->wParam) - { - case VK_PACKET: - message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR; - TRACE_(key)("PostMessageW(%p,%s,%04x,%08x)\n", - msg->hwnd, SPY_GetMsgName(message, msg->hwnd), HIWORD(msg->lParam), LOWORD(msg->lParam)); - PostMessageW( msg->hwnd, message, HIWORD(msg->lParam), LOWORD(msg->lParam)); - return TRUE; - - case VK_PROCESSKEY: - return ImmTranslateMessage(msg->hwnd, msg->message, msg->wParam, msg->lParam); - } - - NtUserGetKeyboardState( state ); - len = ToUnicode(msg->wParam, HIWORD(msg->lParam), state, wp, ARRAY_SIZE(wp), 0); - if (len == -1) - { - message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR; - TRACE_(key)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n", - msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam); - PostMessageW( msg->hwnd, message, wp[0], msg->lParam ); - } - else if (len > 0) - { - INT i; - - message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR; - TRACE_(key)("%d -> PostMessageW(%p,%s,,%08lx) for in %s\n", len, msg->hwnd, - SPY_GetMsgName(message, msg->hwnd), msg->lParam, debugstr_wn(wp, len)); - for (i = 0; i < len; i++) - PostMessageW( msg->hwnd, message, wp[i], msg->lParam ); - } - return TRUE; + return NtUserTranslateMessage( msg, 0 ); } diff --git a/dlls/user32/user_main.c b/dlls/user32/user_main.c index f99e773d6f4..c477d0325d3 100644 --- a/dlls/user32/user_main.c +++ b/dlls/user32/user_main.c @@ -26,6 +26,7 @@ #include "wingdi.h" #include "winuser.h" #include "imm.h" +#include "ddk/imm.h" #include "controls.h" #include "user_private.h" @@ -164,6 +165,7 @@ static const struct user_callbacks user_funcs = EndMenu, HideCaret, ImmProcessKey, + ImmTranslateMessage, SetSystemMenu, ShowCaret, free_menu_items, diff --git a/dlls/win32u/gdiobj.c b/dlls/win32u/gdiobj.c index d5538848a4f..b7b3d9d87b9 100644 --- a/dlls/win32u/gdiobj.c +++ b/dlls/win32u/gdiobj.c @@ -1209,6 +1209,7 @@ static struct unix_funcs unix_funcs = NtUserSystemParametersInfo, NtUserSystemParametersInfoForDpi, NtUserToUnicodeEx, + NtUserTranslateMessage, NtUserUnregisterClass, NtUserUnregisterHotKey, NtUserUpdateLayeredWindow, diff --git a/dlls/win32u/message.c b/dlls/win32u/message.c index 36bafccc9a4..644e91aed4f 100644 --- a/dlls/win32u/message.c +++ b/dlls/win32u/message.c @@ -36,6 +36,7 @@ #include "wine/debug.h" WINE_DEFAULT_DEBUG_CHANNEL(msg); +WINE_DECLARE_DEBUG_CHANNEL(key); WINE_DECLARE_DEBUG_CHANNEL(relay); #define MAX_WINPROC_RECURSION 64 @@ -2879,3 +2880,59 @@ LRESULT WINAPI NtUserMessageCall( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lpa } return 0; } + +/*********************************************************************** + * NtUserTranslateMessage (win32u.@) + */ +BOOL WINAPI NtUserTranslateMessage( const MSG *msg, UINT flags ) +{ + UINT message; + WCHAR wp[8]; + BYTE state[256]; + INT len; + + if (flags) FIXME( "unsupported flags %x\n", flags ); + + if (msg->message < WM_KEYFIRST || msg->message > WM_KEYLAST) return FALSE; + if (msg->message != WM_KEYDOWN && msg->message != WM_SYSKEYDOWN) return TRUE; + + TRACE_(key)( "Translating key %s (%04lX), scancode %04x\n", + debugstr_vkey_name( msg->wParam ), msg->wParam, HIWORD(msg->lParam) ); + + switch (msg->wParam) + { + case VK_PACKET: + message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR; + TRACE_(key)( "PostMessageW(%p,%s,%04x,%08x)\n", msg->hwnd, + debugstr_msg_name( message, msg->hwnd ), + HIWORD(msg->lParam), LOWORD(msg->lParam) ); + NtUserPostMessage( msg->hwnd, message, HIWORD(msg->lParam), LOWORD(msg->lParam) ); + return TRUE; + + case VK_PROCESSKEY: + return user_callbacks && user_callbacks->pImmTranslateMessage( msg->hwnd, msg->message, + msg->wParam, msg->lParam ); + } + + NtUserGetKeyboardState( state ); + len = NtUserToUnicodeEx( msg->wParam, HIWORD(msg->lParam), state, wp, ARRAY_SIZE(wp), 0, + NtUserGetKeyboardLayout(0) ); + if (len == -1) + { + message = msg->message == WM_KEYDOWN ? WM_DEADCHAR : WM_SYSDEADCHAR; + TRACE_(key)( "-1 -> PostMessageW(%p,%s,%04x,%08lx)\n", + msg->hwnd, debugstr_msg_name( message, msg->hwnd ), wp[0], msg->lParam ); + NtUserPostMessage( msg->hwnd, message, wp[0], msg->lParam ); + } + else if (len > 0) + { + INT i; + + message = msg->message == WM_KEYDOWN ? WM_CHAR : WM_SYSCHAR; + TRACE_(key)( "%d -> PostMessageW(%p,%s,,%08lx) for in %s\n", len, msg->hwnd, + debugstr_msg_name(message, msg->hwnd), msg->lParam, debugstr_wn(wp, len) ); + for (i = 0; i < len; i++) + NtUserPostMessage( msg->hwnd, message, wp[i], msg->lParam ); + } + return TRUE; +} diff --git a/dlls/win32u/ntuser_private.h b/dlls/win32u/ntuser_private.h index 5aee58fa1e3..57cf60681e2 100644 --- a/dlls/win32u/ntuser_private.h +++ b/dlls/win32u/ntuser_private.h @@ -38,6 +38,7 @@ struct user_callbacks BOOL (WINAPI *pEndMenu)(void); BOOL (WINAPI *pHideCaret)( HWND hwnd ); BOOL (WINAPI *pImmProcessKey)(HWND, HKL, UINT, LPARAM, DWORD); + BOOL (WINAPI *pImmTranslateMessage)(HWND, UINT, WPARAM, LPARAM); BOOL (WINAPI *pSetSystemMenu)( HWND hwnd, HMENU menu ); BOOL (WINAPI *pShowCaret)( HWND hwnd ); void (CDECL *free_menu_items)( void *ptr ); diff --git a/dlls/win32u/win32u.spec b/dlls/win32u/win32u.spec index cf419668789..ee9dc094ab6 100644 --- a/dlls/win32u/win32u.spec +++ b/dlls/win32u/win32u.spec @@ -1282,7 +1282,7 @@ @ stub NtUserTransformPoint @ stub NtUserTransformRect @ stub NtUserTranslateAccelerator -@ stub NtUserTranslateMessage +@ stdcall NtUserTranslateMessage(ptr long) @ stub NtUserUndelegateInput @ stdcall -syscall NtUserUnhookWinEvent(long) @ stdcall -syscall NtUserUnhookWindowsHookEx(long) diff --git a/dlls/win32u/win32u_private.h b/dlls/win32u/win32u_private.h index 69ddcc83c47..20d0e4ac5b1 100644 --- a/dlls/win32u/win32u_private.h +++ b/dlls/win32u/win32u_private.h @@ -283,6 +283,7 @@ struct unix_funcs UINT winini, UINT dpi ); INT (WINAPI *pNtUserToUnicodeEx)( UINT virt, UINT scan, const BYTE *state, WCHAR *str, int size, UINT flags, HKL layout ); + BOOL (WINAPI *pNtUserTranslateMessage)( const MSG *msg, UINT flags ); BOOL (WINAPI *pNtUserUnregisterClass)( UNICODE_STRING *name, HINSTANCE instance, struct client_menu_name *client_menu_name ); BOOL (WINAPI *pNtUserUnregisterHotKey)( HWND hwnd, INT id ); diff --git a/dlls/win32u/wrappers.c b/dlls/win32u/wrappers.c index b5c2b49ce79..77120efd0b3 100644 --- a/dlls/win32u/wrappers.c +++ b/dlls/win32u/wrappers.c @@ -1186,6 +1186,12 @@ INT WINAPI NtUserToUnicodeEx( UINT virt, UINT scan, const BYTE *state, return unix_funcs->pNtUserToUnicodeEx( virt, scan, state, str, size, flags, layout ); } +BOOL WINAPI NtUserTranslateMessage( const MSG *msg, UINT flags ) +{ + if (!unix_funcs) return 0; + return unix_funcs->pNtUserTranslateMessage( msg, flags ); +} + BOOL WINAPI NtUserUnregisterClass( UNICODE_STRING *name, HINSTANCE instance, struct client_menu_name *client_menu_name ) { diff --git a/include/ntuser.h b/include/ntuser.h index 5cf82043a2e..34b4462f7fe 100644 --- a/include/ntuser.h +++ b/include/ntuser.h @@ -559,6 +559,8 @@ BOOL WINAPI NtUserSystemParametersInfo( UINT action, UINT val, void *ptr, UIN BOOL WINAPI NtUserSystemParametersInfoForDpi( UINT action, UINT val, PVOID ptr, UINT winini, UINT dpi ); INT WINAPI NtUserToUnicodeEx( UINT virt, UINT scan, const BYTE *state, WCHAR *str, int size, UINT flags, HKL layout ); +INT WINAPI NtUserTranslateAccelerator( HWND hwnd, HACCEL accel, MSG *msg ); +BOOL WINAPI NtUserTranslateMessage( const MSG *msg, UINT flags ); BOOL WINAPI NtUserUnhookWinEvent( HWINEVENTHOOK hEventHook ); BOOL WINAPI NtUserUnhookWindowsHookEx( HHOOK handle ); BOOL WINAPI NtUserUnregisterClass( UNICODE_STRING *name, HINSTANCE instance,