changeset 91369:4c4c06eecf22

(w32_read_socket) <WM_CHAR>: Decode non-Unicode input in the default locale. Handle non-Unicode multibyte input.
author Jason Rumney <jasonr@gnu.org>
date Wed, 30 Jan 2008 09:34:49 +0000
parents 928f0831d88b
children 079bf43d2bd9
files src/w32term.c
diffstat 1 files changed, 51 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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;