Commit aee674c9 authored by Eric Pouech's avatar Eric Pouech Committed by Alexandre Julliard

kernel32: Properly manage UTF-8 (and any wcs) input strings.

parent ff057db6
......@@ -1101,8 +1101,9 @@ static enum read_console_input_return bare_console_fetch_input(HANDLE handle, in
{
enum read_console_input_return ret;
char input[8];
WCHAR inputw[8];
int i;
size_t idx = 0;
size_t idx = 0, idxw;
unsigned numEvent;
INPUT_RECORD ir[8];
DWORD written;
......@@ -1157,12 +1158,21 @@ static enum read_console_input_return bare_console_fetch_input(HANDLE handle, in
break;
case -1:
/* we haven't found the string into key-db, push full input string into server */
for (i = 0; i < idx; i++)
idxw = MultiByteToWideChar(CP_UNIXCP, 0, input, idx, inputw, sizeof(inputw) / sizeof(inputw[0]));
/* we cannot translate yet... likely we need more chars (wait max 1/2s for next char) */
if (idxw == 0)
{
timeout = 500;
next_char = TRUE;
break;
}
for (i = 0; i < idxw; i++)
{
numEvent = TERM_FillSimpleChar(input[i], ir);
numEvent = TERM_FillSimpleChar(inputw[i], ir);
WriteConsoleInputW(handle, ir, numEvent, &written);
}
ret = idx == 0 ? rci_timeout : rci_gotone;
ret = rci_gotone;
break;
default:
/* we got a transformation from key-db... push this into server */
......
......@@ -36,7 +36,7 @@ extern WCHAR* CONSOLE_Readline(HANDLE, BOOL);
/* term.c */
extern BOOL TERM_Init(void);
extern BOOL TERM_Exit(void);
extern unsigned TERM_FillSimpleChar(unsigned real_inchar, INPUT_RECORD* ir);
extern unsigned TERM_FillSimpleChar(WCHAR real_inchar, INPUT_RECORD* ir);
extern int TERM_FillInputRecord(const char* in, size_t len, INPUT_RECORD* ir);
#endif /* __WINE_CONSOLE_PRIVATE_H */
......@@ -87,11 +87,10 @@ static inline void init_complex_char(INPUT_RECORD* ir, BOOL down, WORD vk, WORD
* TERM_FillSimpleChar
*
*/
unsigned TERM_FillSimpleChar(unsigned real_inchar, INPUT_RECORD* ir)
unsigned TERM_FillSimpleChar(WCHAR real_inchar, INPUT_RECORD* ir)
{
unsigned vk;
unsigned inchar;
char ch;
WCHAR inchar;
unsigned numEvent = 0;
DWORD cks = 0;
......@@ -110,8 +109,7 @@ unsigned TERM_FillSimpleChar(unsigned real_inchar, INPUT_RECORD* ir)
inchar = real_inchar;
break;
}
if ((inchar & ~0xFF) != 0) FIXME("What a char (%u)\n", inchar);
vk = vkkeyscan_table[inchar];
vk = (inchar < 256) ? vkkeyscan_table[inchar] : 0;
if (vk & 0x0100)
init_complex_char(&ir[numEvent++], 1, 0x2a, 0x10, SHIFT_PRESSED);
if ((vk & 0x0200) || (unsigned char)real_inchar <= 26)
......@@ -132,8 +130,7 @@ unsigned TERM_FillSimpleChar(unsigned real_inchar, INPUT_RECORD* ir)
ir[numEvent].Event.KeyEvent.wVirtualKeyCode = vk;
ir[numEvent].Event.KeyEvent.wVirtualScanCode = mapvkey_0[vk & 0x00ff]; /* VirtualKeyCodes to ScanCode */
ch = inchar;
MultiByteToWideChar(CP_UNIXCP, 0, &ch, 1, &ir[numEvent].Event.KeyEvent.uChar.UnicodeChar, 1);
ir[numEvent].Event.KeyEvent.uChar.UnicodeChar = inchar;
ir[numEvent + 1] = ir[numEvent];
ir[numEvent + 1].Event.KeyEvent.bKeyDown = 0;
......
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