# HG changeset patch # User Jason Rumney <jasonr@gnu.org> # Date 1201685689 0 # Node ID 4c4c06eecf220a6af61b8da3089a79a5692a5155 # Parent 928f0831d88b03a519878c5ca81a5ae3e8266e8a (w32_read_socket) <WM_CHAR>: Decode non-Unicode input in the default locale. Handle non-Unicode multibyte input. diff -r 928f0831d88b -r 4c4c06eecf22 src/w32term.c --- a/src/w32term.c Wed Jan 30 08:29:16 2008 +0000 +++ b/src/w32term.c Wed Jan 30 09:34:49 2008 +0000 @@ -4787,19 +4787,64 @@ if (temp_index == sizeof temp_buffer / sizeof (short)) temp_index = 0; temp_buffer[temp_index++] = msg.msg.wParam; + + inev.modifiers = msg.dwModifiers; + XSETFRAME (inev.frame_or_window, f); + inev.timestamp = msg.msg.time; + if (msg.msg.message == WM_UNICHAR) { - inev.kind = MULTIBYTE_CHAR_KEYSTROKE_EVENT; inev.code = msg.msg.wParam; } + else if (msg.msg.wParam < 256) + { + wchar_t code; + char dbcs[2]; + dbcs[0] = 0; + dbcs[1] = (char) msg.msg.wParam; + + if (dbcs_lead) + { + dbcs[0] = dbcs_lead; + dbcs_lead = 0; + if (!MultiByteToWideChar (CP_ACP, 0, dbcs, 2, &code, 1)) + { + /* Garbage */ + DebPrint (("Invalid DBCS sequence: %d %d\n", + dbcs[0], dbcs[1])); + inev.kind = NO_EVENT; + break; + } + } + else if (IsDBCSLeadByteEx (CP_ACP, (BYTE) msg.msg.wParam)) + { + dbcs_lead = (char) msg.msg.wParam; + inev.kind = NO_EVENT; + break; + } + else + { + if (!MultiByteToWideChar (CP_ACP, 0, &dbcs[1], 1, + &code, 1)) + { + /* What to do with garbage? */ + DebPrint (("Invalid character: %d\n", dbcs[1])); + inev.kind = NO_EVENT; + break; + } + } + inev.code = code; + } else { - inev.kind = ASCII_KEYSTROKE_EVENT; - inev.code = msg.msg.wParam; + /* Windows shouldn't generate WM_CHAR events above 0xFF + in non-Unicode message handlers. */ + DebPrint (("Non-byte WM_CHAR: %d\n", msg.msg.wParam)); + inev.kind = NO_EVENT; + break; } - inev.modifiers = msg.dwModifiers; - XSETFRAME (inev.frame_or_window, f); - inev.timestamp = msg.msg.time; + inev.kind = inev.code < 128 ? ASCII_KEYSTROKE_EVENT + : MULTIBYTE_CHAR_KEYSTROKE_EVENT; } break;