changeset 103500:d0e3ea40717c EMACS_23_1_BASE

(keyboard_codepage): New static variable. (w32_read_socket) [WM_INPUTLANGCHANGE]: Update it. (w32_read_socket) [WM_CHAR]: Use it to decode character input (bug#3237). (w32_initialize): Initialize it. (codepage_for_locale): New function.
author Jason Rumney <jasonr@gnu.org>
date Sun, 21 Jun 2009 03:34:19 +0000
parents 247269056555
children fe679d9c8eb9
files src/ChangeLog src/w32term.c
diffstat 2 files changed, 39 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Sun Jun 21 01:39:43 2009 +0000
+++ b/src/ChangeLog	Sun Jun 21 03:34:19 2009 +0000
@@ -1,3 +1,12 @@
+2009-06-21  Jason Rumney  <jasonr@gnu.org>
+
+	* w32term.c (keyboard_codepage): New static variable.
+	(w32_read_socket) [WM_INPUTLANGCHANGE]: Update it.
+	(w32_read_socket) [WM_CHAR]: Use it to decode character
+	input (bug#3237).
+	(w32_initialize): Initialize it.
+	(codepage_for_locale): New function.
+
 2009-06-20  Ken Raeburn  <raeburn@raeburn.org>
 
 	* process.c (status_message): Pass Faset index argument as a lisp
--- a/src/w32term.c	Sun Jun 21 01:39:43 2009 +0000
+++ b/src/w32term.c	Sun Jun 21 03:34:19 2009 +0000
@@ -180,7 +180,6 @@
 /* Mouse movement. */
 
 /* Where the mouse was last time we reported a mouse event.  */
-
 static RECT last_mouse_glyph;
 static FRAME_PTR last_mouse_glyph_frame;
 static Lisp_Object last_mouse_press_frame;
@@ -215,12 +214,10 @@
    along with the position query.  So, we just keep track of the time
    of the last movement we received, and return that in hopes that
    it's somewhat accurate.  */
-
 static Time last_mouse_movement_time;
 
 /* Incremented by w32_read_socket whenever it really tries to read
    events.  */
-
 #ifdef __STDC__
 static int volatile input_signal_count;
 #else
@@ -234,9 +231,11 @@
 #endif
 
 /* A mask of extra modifier bits to put into every keyboard char.  */
-
 extern EMACS_INT extra_keyboard_modifiers;
 
+/* Keyboard code page - may be changed by language-change events.  */
+static int keyboard_codepage;
+
 static void x_update_window_end P_ ((struct window *, int, int));
 static void w32_handle_tool_bar_click P_ ((struct frame *,
                                           struct input_event *));
@@ -2908,6 +2907,15 @@
   return value;
 }
 
+static int codepage_for_locale(LCID locale)
+{
+  char cp[20];
+
+  if (GetLocaleInfo (locale, LOCALE_IDEFAULTANSICODEPAGE, cp, 20) > 0)
+    return atoi (cp);
+  else
+    return CP_ACP;
+}
 
 
 /* Mouse clicks and mouse movement.  Rah.  */
@@ -4160,6 +4168,11 @@
 	  /* Generate a language change event.  */
 	  f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
 
+	  /* lParam contains the input lang ID.  Use it to update our
+	     record of the keyboard codepage.  */
+	  keyboard_codepage = codepage_for_locale ((LCID)(msg.msg.lParam
+							  & 0xffff));
+
 	  if (f)
 	    {
 	      inev.kind = LANGUAGE_CHANGE_EVENT;
@@ -4230,7 +4243,8 @@
                     {
                       dbcs[0] = dbcs_lead;
                       dbcs_lead = 0;
-                      if (!MultiByteToWideChar (CP_ACP, 0, dbcs, 2, &code, 1))
+                      if (!MultiByteToWideChar (keyboard_codepage, 0,
+						dbcs, 2, &code, 1))
                         {
                           /* Garbage */
                           DebPrint (("Invalid DBCS sequence: %d %d\n",
@@ -4239,7 +4253,8 @@
                           break;
                         }
                     }
-                  else if (IsDBCSLeadByteEx (CP_ACP, (BYTE) msg.msg.wParam))
+                  else if (IsDBCSLeadByteEx (keyboard_codepage,
+					     (BYTE) msg.msg.wParam))
                     {
                       dbcs_lead = (char) msg.msg.wParam;
                       inev.kind = NO_EVENT;
@@ -4247,8 +4262,8 @@
                     }
                   else
                     {
-                      if (!MultiByteToWideChar (CP_ACP, 0, &dbcs[1], 1,
-                                                &code, 1))
+                      if (!MultiByteToWideChar (keyboard_codepage, 0,
+						&dbcs[1], 1, &code, 1))
                         {
                           /* What to do with garbage? */
                           DebPrint (("Invalid character: %d\n", dbcs[1]));
@@ -6345,8 +6360,13 @@
      8 bit character input, standard quit char.  */
   Fset_input_mode (Qnil, Qnil, make_number (2), Qnil);
 
-  /* Create the window thread - it will terminate itself or when the app terminates */
-
+  {
+    HKL input_locale_id = GetKeyboardLayout (0);
+    keyboard_codepage = codepage_for_locale (input_locale_id & 0xffff);
+  }
+
+  /* Create the window thread - it will terminate itself when the app
+     terminates */
   init_crit ();
 
   dwMainThreadId = GetCurrentThreadId ();
@@ -6354,7 +6374,6 @@
 		   GetCurrentProcess (), &hMainThread, 0, TRUE, DUPLICATE_SAME_ACCESS);
 
   /* Wait for thread to start */
-
   {
     MSG msg;