diff options
author | Jason Rumney <jasonr@gnu.org> | 2008-01-30 09:34:49 +0000 |
---|---|---|
committer | Jason Rumney <jasonr@gnu.org> | 2008-01-30 09:34:49 +0000 |
commit | e36f510747e35f27729a7808cbdddac2d43c8066 (patch) | |
tree | 5fa9efd13541ab2182b82d83bcd16e40c43bd588 /src/w32term.c | |
parent | ab50ffed1de13d0738617a309d34aab0454b5c99 (diff) | |
download | emacs-e36f510747e35f27729a7808cbdddac2d43c8066.tar.gz |
(w32_read_socket) <WM_CHAR>: Decode non-Unicode
input in the default locale. Handle non-Unicode multibyte input.
Diffstat (limited to 'src/w32term.c')
-rw-r--r-- | src/w32term.c | 57 |
1 files changed, 51 insertions, 6 deletions
diff --git a/src/w32term.c b/src/w32term.c index e04e57cd52a..4766382f6a1 100644 --- a/src/w32term.c +++ b/src/w32term.c @@ -4787,19 +4787,64 @@ w32_read_socket (sd, expected, hold_quit) 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; |