Commit 8932c867 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

win32u: Move NtUserToUnicodeEx implementation from user32.

parent 354be0a1
......@@ -253,12 +253,6 @@ static BOOL CDECL loaderdrv_RegisterHotKey( HWND hwnd, UINT modifiers, UINT vk )
return load_driver()->pRegisterHotKey( hwnd, modifiers, vk );
}
static INT CDECL loaderdrv_ToUnicodeEx( UINT virt, UINT scan, const BYTE *state, LPWSTR str,
int size, UINT flags, HKL layout )
{
return load_driver()->pToUnicodeEx( virt, scan, state, str, size, flags, layout );
}
static void CDECL loaderdrv_UnregisterHotKey( HWND hwnd, UINT modifiers, UINT vk )
{
load_driver()->pUnregisterHotKey( hwnd, modifiers, vk );
......@@ -357,7 +351,7 @@ static struct user_driver_funcs lazy_load_driver =
loaderdrv_GetKeyboardLayoutList,
NULL,
loaderdrv_RegisterHotKey,
loaderdrv_ToUnicodeEx,
NULL,
loaderdrv_UnregisterHotKey,
NULL,
/* cursor/icon functions */
......
......@@ -841,102 +841,9 @@ INT WINAPI GetKeyNameTextA(LONG lParam, LPSTR lpBuffer, INT nSize)
/****************************************************************************
* ToUnicode (USER32.@)
*/
INT WINAPI ToUnicode(UINT virtKey, UINT scanCode, const BYTE *lpKeyState,
LPWSTR lpwStr, int size, UINT flags)
INT WINAPI ToUnicode( UINT virt, UINT scan, const BYTE *state, LPWSTR str, int size, UINT flags )
{
return ToUnicodeEx( virtKey, scanCode, lpKeyState, lpwStr, size, flags,
NtUserGetKeyboardLayout(0) );
}
/****************************************************************************
* ToUnicodeEx (USER32.@)
*/
INT WINAPI ToUnicodeEx( UINT virt, UINT scan, const BYTE *state,
WCHAR *str, int size, UINT flags, HKL layout )
{
BOOL shift, ctrl, alt, numlock;
WCHAR buffer[2];
INT len;
TRACE_(keyboard)( "virt %u, scan %u, state %p, str %p, size %d, flags %x, layout %p.\n",
virt, scan, state, str, size, flags, layout );
if (!state) return 0;
if ((len = USER_Driver->pToUnicodeEx( virt, scan, state, str, size, flags, layout )) >= -1) return len;
alt = state[VK_MENU] & 0x80;
shift = state[VK_SHIFT] & 0x80;
ctrl = state[VK_CONTROL] & 0x80;
numlock = state[VK_NUMLOCK] & 0x01;
/* FIXME: English keyboard layout specific */
if (scan & 0x8000) buffer[0] = 0; /* key up */
else if (virt == VK_ESCAPE) buffer[0] = VK_ESCAPE;
else if (!ctrl)
{
switch (virt)
{
case VK_BACK: buffer[0] = '\b'; break;
case VK_OEM_1: buffer[0] = shift ? ':' : ';'; break;
case VK_OEM_2: buffer[0] = shift ? '?' : '/'; break;
case VK_OEM_3: buffer[0] = shift ? '~' : '`'; break;
case VK_OEM_4: buffer[0] = shift ? '{' : '['; break;
case VK_OEM_5: buffer[0] = shift ? '|' : '\\'; break;
case VK_OEM_6: buffer[0] = shift ? '}' : ']'; break;
case VK_OEM_7: buffer[0] = shift ? '"' : '\''; break;
case VK_OEM_COMMA: buffer[0] = shift ? '<' : ','; break;
case VK_OEM_MINUS: buffer[0] = shift ? '_' : '-'; break;
case VK_OEM_PERIOD: buffer[0] = shift ? '>' : '.'; break;
case VK_OEM_PLUS: buffer[0] = shift ? '+' : '='; break;
case VK_RETURN: buffer[0] = '\r'; break;
case VK_SPACE: buffer[0] = ' '; break;
case VK_TAB: buffer[0] = '\t'; break;
case VK_MULTIPLY: buffer[0] = '*'; break;
case VK_ADD: buffer[0] = '+'; break;
case VK_SUBTRACT: buffer[0] = '-'; break;
case VK_DIVIDE: buffer[0] = '/'; break;
default:
if (virt >= '0' && virt <= '9')
buffer[0] = shift ? ")!@#$%^&*("[virt - '0'] : virt;
else if (virt >= 'A' && virt <= 'Z')
buffer[0] = shift || (state[VK_CAPITAL] & 0x01) ? virt : virt + 'a' - 'A';
else if (virt >= VK_NUMPAD0 && virt <= VK_NUMPAD9 && numlock && !shift)
buffer[0] = '0' + virt - VK_NUMPAD0;
else if (virt == VK_DECIMAL && numlock && !shift)
buffer[0] = '.';
else
buffer[0] = 0;
break;
}
}
else if (!alt) /* Control codes */
{
switch (virt)
{
case VK_OEM_4: buffer[0] = 0x1b; break;
case VK_OEM_5: buffer[0] = 0x1c; break;
case VK_OEM_6: buffer[0] = 0x1d; break;
case '6': buffer[0] = shift ? 0x1e : 0; break;
case VK_OEM_MINUS: buffer[0] = shift ? 0x1f : 0; break;
case VK_BACK: buffer[0] = 0x7f; break;
case VK_RETURN: buffer[0] = shift ? 0 : '\n'; break;
case '2': buffer[0] = shift ? 0xffff : 0xf000; break;
case VK_SPACE: buffer[0] = ' '; break;
default:
if (virt >= 'A' && virt <= 'Z') buffer[0] = virt - 'A' + 1;
else buffer[0] = 0;
break;
}
}
else buffer[0] = 0;
buffer[1] = 0;
len = wcslen( buffer );
if (buffer[0] == 0xffff) buffer[0] = 0;
lstrcpynW( str, buffer, size );
TRACE_(keyboard)( "ret %d, str %s.\n", len, debugstr_w(str) );
return len;
return NtUserToUnicodeEx( virt, scan, state, str, size, flags, NtUserGetKeyboardLayout(0) );
}
/****************************************************************************
......@@ -958,7 +865,7 @@ INT WINAPI ToAsciiEx( UINT virtKey, UINT scanCode, const BYTE *lpKeyState,
WCHAR uni_chars[2];
INT ret, n_ret;
ret = ToUnicodeEx(virtKey, scanCode, lpKeyState, uni_chars, 2, flags, dwhkl);
ret = NtUserToUnicodeEx( virtKey, scanCode, lpKeyState, uni_chars, 2, flags, dwhkl );
if (ret < 0) n_ret = 1; /* FIXME: make ToUnicode return 2 for dead chars */
else n_ret = ret;
WideCharToMultiByte(CP_ACP, 0, uni_chars, n_ret, (LPSTR)lpChar, 2, NULL, NULL);
......
......@@ -760,7 +760,7 @@
@ stdcall ToAscii(long long ptr ptr long)
@ stdcall ToAsciiEx(long long ptr ptr long long)
@ stdcall ToUnicode(long long ptr ptr long long)
@ stdcall ToUnicodeEx(long long ptr ptr long long long)
@ stdcall ToUnicodeEx(long long ptr ptr long long long) NtUserToUnicodeEx
@ stdcall TrackMouseEvent(ptr)
@ stdcall TrackPopupMenu(long long long long long long ptr)
@ stdcall TrackPopupMenuEx(long long long long long ptr)
......
......@@ -1013,6 +1013,12 @@ static UINT CDECL loaderdrv_MapVirtualKeyEx( UINT code, UINT type, HKL layout )
return load_driver()->pMapVirtualKeyEx( code, type, layout );
}
static INT CDECL loaderdrv_ToUnicodeEx( UINT virt, UINT scan, const BYTE *state, LPWSTR str,
int size, UINT flags, HKL layout )
{
return load_driver()->pToUnicodeEx( virt, scan, state, str, size, flags, layout );
}
static SHORT CDECL loaderdrv_VkKeyScanEx( WCHAR ch, HKL layout )
{
return load_driver()->pVkKeyScanEx( ch, layout );
......@@ -1027,6 +1033,7 @@ static const struct user_driver_funcs lazy_load_driver =
{
.pGetKeyNameText = loaderdrv_GetKeyNameText,
.pMapVirtualKeyEx = loaderdrv_MapVirtualKeyEx,
.pToUnicodeEx = loaderdrv_ToUnicodeEx,
.pVkKeyScanEx = loaderdrv_VkKeyScanEx,
.pUpdateClipboard = loaderdrv_UpdateClipboard,
};
......
......@@ -1173,6 +1173,7 @@ static struct unix_funcs unix_funcs =
NtUserGetUpdatedClipboardFormats,
NtUserIsClipboardFormatAvailable,
NtUserMapVirtualKeyEx,
NtUserToUnicodeEx,
NtUserVkKeyScanEx,
GDIRealizePalette,
......
......@@ -478,3 +478,95 @@ INT WINAPI NtUserGetKeyNameText( LONG lparam, WCHAR *buffer, INT size )
TRACE_(keyboard)( "ret %d, str %s.\n", len, debugstr_w(buffer) );
return len;
}
/****************************************************************************
* NtUserToUnicodeEx (win32u.@)
*/
INT WINAPI NtUserToUnicodeEx( UINT virt, UINT scan, const BYTE *state,
WCHAR *str, int size, UINT flags, HKL layout )
{
BOOL shift, ctrl, alt, numlock;
WCHAR buffer[2];
INT len;
TRACE_(keyboard)( "virt %u, scan %u, state %p, str %p, size %d, flags %x, layout %p.\n",
virt, scan, state, str, size, flags, layout );
if (!state) return 0;
if ((len = user_driver->pToUnicodeEx( virt, scan, state, str, size, flags, layout )) >= -1)
return len;
alt = state[VK_MENU] & 0x80;
shift = state[VK_SHIFT] & 0x80;
ctrl = state[VK_CONTROL] & 0x80;
numlock = state[VK_NUMLOCK] & 0x01;
/* FIXME: English keyboard layout specific */
if (scan & 0x8000) buffer[0] = 0; /* key up */
else if (virt == VK_ESCAPE) buffer[0] = VK_ESCAPE;
else if (!ctrl)
{
switch (virt)
{
case VK_BACK: buffer[0] = '\b'; break;
case VK_OEM_1: buffer[0] = shift ? ':' : ';'; break;
case VK_OEM_2: buffer[0] = shift ? '?' : '/'; break;
case VK_OEM_3: buffer[0] = shift ? '~' : '`'; break;
case VK_OEM_4: buffer[0] = shift ? '{' : '['; break;
case VK_OEM_5: buffer[0] = shift ? '|' : '\\'; break;
case VK_OEM_6: buffer[0] = shift ? '}' : ']'; break;
case VK_OEM_7: buffer[0] = shift ? '"' : '\''; break;
case VK_OEM_COMMA: buffer[0] = shift ? '<' : ','; break;
case VK_OEM_MINUS: buffer[0] = shift ? '_' : '-'; break;
case VK_OEM_PERIOD: buffer[0] = shift ? '>' : '.'; break;
case VK_OEM_PLUS: buffer[0] = shift ? '+' : '='; break;
case VK_RETURN: buffer[0] = '\r'; break;
case VK_SPACE: buffer[0] = ' '; break;
case VK_TAB: buffer[0] = '\t'; break;
case VK_MULTIPLY: buffer[0] = '*'; break;
case VK_ADD: buffer[0] = '+'; break;
case VK_SUBTRACT: buffer[0] = '-'; break;
case VK_DIVIDE: buffer[0] = '/'; break;
default:
if (virt >= '0' && virt <= '9')
buffer[0] = shift ? ")!@#$%^&*("[virt - '0'] : virt;
else if (virt >= 'A' && virt <= 'Z')
buffer[0] = shift || (state[VK_CAPITAL] & 0x01) ? virt : virt + 'a' - 'A';
else if (virt >= VK_NUMPAD0 && virt <= VK_NUMPAD9 && numlock && !shift)
buffer[0] = '0' + virt - VK_NUMPAD0;
else if (virt == VK_DECIMAL && numlock && !shift)
buffer[0] = '.';
else
buffer[0] = 0;
break;
}
}
else if (!alt) /* Control codes */
{
switch (virt)
{
case VK_OEM_4: buffer[0] = 0x1b; break;
case VK_OEM_5: buffer[0] = 0x1c; break;
case VK_OEM_6: buffer[0] = 0x1d; break;
case '6': buffer[0] = shift ? 0x1e : 0; break;
case VK_OEM_MINUS: buffer[0] = shift ? 0x1f : 0; break;
case VK_BACK: buffer[0] = 0x7f; break;
case VK_RETURN: buffer[0] = shift ? 0 : '\n'; break;
case '2': buffer[0] = shift ? 0xffff : 0xf000; break;
case VK_SPACE: buffer[0] = ' '; break;
default:
if (virt >= 'A' && virt <= 'Z') buffer[0] = virt - 'A' + 1;
else buffer[0] = 0;
break;
}
}
else buffer[0] = 0;
buffer[1] = 0;
len = lstrlenW( buffer );
if (buffer[0] == 0xffff) buffer[0] = 0;
lstrcpynW( str, buffer, size );
TRACE_(keyboard)( "ret %d, str %s.\n", len, debugstr_w(str) );
return len;
}
......@@ -1276,7 +1276,7 @@
@ stub NtUserTestForInteractiveUser
@ stub NtUserThunkedMenuInfo
@ stub NtUserThunkedMenuItemInfo
@ stub NtUserToUnicodeEx
@ stdcall NtUserToUnicodeEx(long long ptr ptr long long long)
@ stub NtUserTrackMouseEvent
@ stub NtUserTrackPopupMenuEx
@ stub NtUserTransformPoint
......
......@@ -200,6 +200,8 @@ struct unix_funcs
BOOL (WINAPI *pNtUserGetUpdatedClipboardFormats)( UINT *formats, UINT size, UINT *out_size );
BOOL (WINAPI *pNtUserIsClipboardFormatAvailable)( UINT format );
UINT (WINAPI *pNtUserMapVirtualKeyEx)( UINT code, UINT type, HKL layout );
INT (WINAPI *pNtUserToUnicodeEx)( UINT virt, UINT scan, const BYTE *state,
WCHAR *str, int size, UINT flags, HKL layout );
WORD (WINAPI *pNtUserVkKeyScanEx)( WCHAR chr, HKL layout );
/* Wine-specific functions */
......
......@@ -626,6 +626,12 @@ UINT WINAPI NtUserMapVirtualKeyEx( UINT code, UINT type, HKL layout )
return unix_funcs->pNtUserMapVirtualKeyEx( code, type, layout );
}
INT WINAPI NtUserToUnicodeEx( UINT virt, UINT scan, const BYTE *state,
WCHAR *str, int size, UINT flags, HKL layout )
{
return unix_funcs->pNtUserToUnicodeEx( virt, scan, state, str, size, flags, layout );
}
WORD WINAPI NtUserVkKeyScanEx( WCHAR chr, HKL layout )
{
return unix_funcs->pNtUserVkKeyScanEx( chr, layout );
......
......@@ -53,6 +53,7 @@ struct user_thread_info
C_ASSERT( sizeof(struct user_thread_info) <= sizeof(((TEB *)0)->Win32ClientInfo) );
HKL WINAPI NtUserActivateKeyboardLayout( HKL layout, UINT flags );
BOOL WINAPI NtUserAddClipboardFormatListener( HWND hwnd );
BOOL WINAPI NtUserAttachThreadInput( DWORD from, DWORD to, BOOL attach );
BOOL WINAPI NtUserCloseDesktop( HDESK handle );
......@@ -70,8 +71,11 @@ HWND WINAPI NtUserGetClipboardViewer(void);
INT WINAPI NtUserGetKeyNameText( LONG lparam, WCHAR *buffer, INT size );
SHORT WINAPI NtUserGetKeyState( INT vkey );
HKL WINAPI NtUserGetKeyboardLayout( DWORD thread_id );
UINT WINAPI NtUserGetKeyboardLayoutList( INT size, HKL *layouts );
BOOL WINAPI NtUserGetKeyboardState( BYTE *state );
BOOL WINAPI NtUserGetLayeredWindowAttributes( HWND hwnd, COLORREF *key, BYTE *alpha, DWORD *flags );
int WINAPI NtUserGetMouseMovePointsEx( UINT size, MOUSEMOVEPOINT *ptin, MOUSEMOVEPOINT *ptout,
int count, DWORD resolution );
BOOL WINAPI NtUserGetObjectInformation( HANDLE handle, INT index, void *info,
DWORD len, DWORD *needed );
HWND WINAPI NtUserGetOpenClipboardWindow(void);
......@@ -92,6 +96,10 @@ BOOL WINAPI NtUserSetKeyboardState( BYTE *state );
BOOL WINAPI NtUserSetProcessWindowStation( HWINSTA handle );
BOOL WINAPI NtUserSetProp( HWND hwnd, const WCHAR *str, HANDLE handle );
BOOL WINAPI NtUserSetThreadDesktop( HDESK handle );
INT WINAPI NtUserShowCursor( BOOL show );
INT WINAPI NtUserToUnicodeEx( UINT virt, UINT scan, const BYTE *state,
WCHAR *str, int size, UINT flags, HKL layout );
BOOL WINAPI NtUserUnregisterHotKey( HWND hwnd, INT id );
WORD WINAPI NtUserVkKeyScanEx( WCHAR chr, HKL layout );
#endif /* _NTUSER_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment