win32u: Move NtUserTranslateMessage 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 2022-04-15 14:52:36 +02:00 committed by Alexandre Julliard
parent 262831bc63
commit 6ea417b2d5
9 changed files with 72 additions and 46 deletions

View File

@ -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,<x>,%08lx) for <x> 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 );
}

View File

@ -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,

View File

@ -1209,6 +1209,7 @@ static struct unix_funcs unix_funcs =
NtUserSystemParametersInfo,
NtUserSystemParametersInfoForDpi,
NtUserToUnicodeEx,
NtUserTranslateMessage,
NtUserUnregisterClass,
NtUserUnregisterHotKey,
NtUserUpdateLayeredWindow,

View File

@ -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,<x>,%08lx) for <x> 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;
}

View File

@ -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 );

View File

@ -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)

View File

@ -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 );

View File

@ -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 )
{

View File

@ -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,