unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Joakim Hårsman" <joakim.harsman@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 10299@debbugs.gnu.org
Subject: bug#10299: Emacs doesn't handle Unicode characters in keyboard layout on MS Windows
Date: Mon, 23 Jan 2012 20:15:15 +0100	[thread overview]
Message-ID: <CAFJF9wVcJ+gcOybJF4Cv-s_BUtpUKVZj-OK0qJeQohKZZtbJYA@mail.gmail.com> (raw)
In-Reply-To: <jwvfwff92b5.fsf-monnier+emacs@gnu.org>

I've amended the patch to take your comments into account.

Note that SetWindowText is already a macro that expands to
SetWindowTextA or SetWindowTextW depending on whether UNICODE is
defined. However, to retain compatibility with Windows 95, Emacs
doesn't define UNICODE and instead uses Unicode APIs directly where it
needs them. Still, the duplicated code was annoying, so I defined a
simple wrapper function which also gives a good place to document why
the code looks the way it does.

I also put the initialization of the window class structure into a
macro in w32.h, I wasn't entirely sure where to put it.

Here's the current version of the patch:


=== modified file 'src/w32.h'
--- src/w32.h   2011-10-28 09:54:02 +0000
+++ src/w32.h   2012-01-23 19:10:04 +0000
@@ -159,5 +159,18 @@
                                   const void* buf, size_t sz);
 #endif /* HAVE_GNUTLS */

+#define INIT_WINDOW_CLASS(wc)                   \
+    wc.style = CS_HREDRAW | CS_VREDRAW;         \
+    wc.lpfnWndProc = (WNDPROC) w32_wnd_proc;    \
+    wc.cbClsExtra = 0;                          \
+    wc.cbWndExtra = WND_EXTRA_BYTES;            \
+    wc.hInstance = hinst;                       \
+    wc.hIcon = LoadIcon (hinst, EMACS_CLASS);   \
+    wc.hCursor = w32_load_cursor (IDC_ARROW);   \
+    wc.hbrBackground = NULL;                    \
+    wc.lpszMenuName = NULL;                     \
+
+
+
 #endif /* EMACS_W32_H */


=== modified file 'src/w32fns.c'
--- src/w32fns.c        2011-12-04 08:02:42 +0000
+++ src/w32fns.c        2012-01-23 19:10:04 +0000
@@ -1641,6 +1641,20 @@

 }

+/* Set text of w32 frame with handle HWND to TEXT.
+
+   We explicitly switch between the Unicode and ANSI version of
+   SetWindowText because Emacs isn't compiled with UNICODE defined to
+   retain compatibility with Windows 95. */
+
+void
+w32_set_frame_text(HWND hwnd, LPCSTR text)
+{
+  if (os_subtype == OS_NT)
+    SetWindowTextW (hwnd, (LPCWSTR)text);
+  else
+    SetWindowTextA (hwnd, text);
+}

 /* Change the name of frame F to NAME.  If NAME is nil, set F's name to
        w32_id_name.
@@ -1697,10 +1711,10 @@
   if (FRAME_W32_WINDOW (f))
     {
       if (STRING_MULTIBYTE (name))
-       name = ENCODE_SYSTEM (name);
-
+        name = ENCODE_SYSTEM (name);
+
       BLOCK_INPUT;
-      SetWindowText (FRAME_W32_WINDOW (f), SDATA (name));
+      w32_set_frame_text(FRAME_W32_WINDOW (f), SDATA (name));
       UNBLOCK_INPUT;
     }
 }
@@ -1746,7 +1760,7 @@
        name = ENCODE_SYSTEM (name);

       BLOCK_INPUT;
-      SetWindowText (FRAME_W32_WINDOW (f), SDATA (name));
+      w32_set_frame_text(FRAME_W32_WINDOW (f), SDATA (name));
       UNBLOCK_INPUT;
     }
 }
@@ -1785,20 +1799,23 @@
 static BOOL
 w32_init_class (HINSTANCE hinst)
 {
-  WNDCLASS wc;
-
-  wc.style = CS_HREDRAW | CS_VREDRAW;
-  wc.lpfnWndProc = (WNDPROC) w32_wnd_proc;
-  wc.cbClsExtra = 0;
-  wc.cbWndExtra = WND_EXTRA_BYTES;
-  wc.hInstance = hinst;
-  wc.hIcon = LoadIcon (hinst, EMACS_CLASS);
-  wc.hCursor = w32_load_cursor (IDC_ARROW);
-  wc.hbrBackground = NULL; /* GetStockObject (WHITE_BRUSH);  */
-  wc.lpszMenuName = NULL;
-  wc.lpszClassName = EMACS_CLASS;
-
-  return (RegisterClass (&wc));
+
+  if (os_subtype == OS_NT)
+    {
+      WNDCLASSW  uwc;
+      INIT_WINDOW_CLASS(uwc);
+      uwc.lpszClassName = L"Emacs";
+
+      return (RegisterClassW (&uwc));
+    }
+  else
+    {
+      WNDCLASS  wc;
+      INIT_WINDOW_CLASS(wc);
+      wc.lpszClassName = EMACS_CLASS;
+
+      return (RegisterClass (&wc));
+    }
 }

 static HWND
@@ -2248,8 +2265,16 @@

   msh_mousewheel = RegisterWindowMessage (MSH_MOUSEWHEEL);

-  while (GetMessage (&msg, NULL, 0, 0))
+  while (1)
     {
+      if (os_subtype == OS_NT)
+        result = GetMessageW (&msg, NULL, 0, 0);
+      else
+        result = GetMessage (&msg, NULL, 0, 0);
+
+      if (!result)
+        break;
+
       if (msg.hwnd == NULL)
        {
          switch (msg.message)
@@ -2915,8 +2940,21 @@

     case WM_SYSCHAR:
     case WM_CHAR:
-      post_character_message (hwnd, msg, wParam, lParam,
-                             w32_get_key_modifiers (wParam, lParam));
+      if (wParam > 255 )
+        {
+          unsigned short lo = wParam & 0x0000FFFF;
+          unsigned short hi = (wParam & 0xFFFF0000) >> 8;
+          wParam  = hi | lo;
+
+          W32Msg wmsg;
+          wmsg.dwModifiers = w32_get_key_modifiers (wParam, lParam);
+          signal_user_input ();
+          my_post_msg (&wmsg, hwnd, WM_UNICHAR, wParam, lParam);
+
+        }
+      else
+        post_character_message (hwnd, msg, wParam, lParam,
+                                w32_get_key_modifiers (wParam, lParam));
       break;

     case WM_UNICHAR:



On 16 January 2012 15:03, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> Note: I know very little about w32.
>
>> -      SetWindowText (FRAME_W32_WINDOW (f), SDATA (name));
>> +      if (os_subtype == OS_NT)
>> +        SetWindowTextW (FRAME_W32_WINDOW (f), SDATA (name));
>> +      else
>> +        SetWindowText (FRAME_W32_WINDOW (f), SDATA (name));
>
> Can we move the test elsewhere by defining (or #defining) our own
> SetWindowText which uses either of the two?
>
>> @@ -1785,20 +1791,39 @@
>>  static BOOL
>>  w32_init_class (HINSTANCE hinst)
>>  {
>> -  WNDCLASS wc;
>> -
>> -  wc.style = CS_HREDRAW | CS_VREDRAW;
>> -  wc.lpfnWndProc = (WNDPROC) w32_wnd_proc;
>> -  wc.cbClsExtra = 0;
>> -  wc.cbWndExtra = WND_EXTRA_BYTES;
>> -  wc.hInstance = hinst;
>> -  wc.hIcon = LoadIcon (hinst, EMACS_CLASS);
>> -  wc.hCursor = w32_load_cursor (IDC_ARROW);
>> -  wc.hbrBackground = NULL; /* GetStockObject (WHITE_BRUSH);  */
>> -  wc.lpszMenuName = NULL;
>> -  wc.lpszClassName = EMACS_CLASS;
>> -
>> -  return (RegisterClass (&wc));
>> +  WNDCLASSW uwc;
>> +  WNDCLASS  wc;
>> +
>> +  if (os_subtype == OS_NT)
>> +    {
>> +      uwc.style = CS_HREDRAW | CS_VREDRAW;
>> +      uwc.lpfnWndProc = (WNDPROC) w32_wnd_proc;
>> +      uwc.cbClsExtra = 0;
>> +      uwc.cbWndExtra = WND_EXTRA_BYTES;
>> +      uwc.hInstance = hinst;
>> +      uwc.hIcon = LoadIcon (hinst, EMACS_CLASS);
>> +      uwc.hCursor = w32_load_cursor (IDC_ARROW);
>> +      uwc.hbrBackground = NULL; /* GetStockObject (WHITE_BRUSH);  */
>> +      uwc.lpszMenuName = NULL;
>> +      uwc.lpszClassName = L"Emacs";
>> +
>> +      return (RegisterClassW (&uwc));
>> +    }
>> +  else
>> +    {
>> +      wc.style = CS_HREDRAW | CS_VREDRAW;
>> +      wc.lpfnWndProc = (WNDPROC) w32_wnd_proc;
>> +      wc.cbClsExtra = 0;
>> +      wc.cbWndExtra = WND_EXTRA_BYTES;
>> +      wc.hInstance = hinst;
>> +      wc.hIcon = LoadIcon (hinst, EMACS_CLASS);
>> +      wc.hCursor = w32_load_cursor (IDC_ARROW);
>> +      wc.hbrBackground = NULL; /* GetStockObject (WHITE_BRUSH);  */
>> +      wc.lpszMenuName = NULL;
>> +      wc.lpszClassName = EMACS_CLASS;
>> +
>> +      return (RegisterClass (&wc));
>> +    }
>>  }
>
> The two var declarations (WNDCLASSW uwc and WNDCLASS wc) should be moved
> within their respective branch.  And it'd be better if we could share
> some code between the two branches, e.g. using a macro.
>
>
>        Stefan





  reply	other threads:[~2012-01-23 19:15 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-14 20:39 bug#10299: Emacs doesn't handle Unicode characters in keyboard layout on MS Windows Joakim Hårsman
2011-12-15  6:22 ` Eli Zaretskii
2011-12-15  6:51   ` Kenichi Handa
2011-12-15  7:53   ` Joakim Hårsman
2011-12-15 10:52     ` Eli Zaretskii
2011-12-15 11:11       ` Joakim Hårsman
2011-12-15 13:16         ` Eli Zaretskii
2011-12-15 14:40   ` Jason Rumney
2011-12-15 15:08     ` Lennart Borgman
2011-12-15 15:40     ` Joakim Hårsman
2011-12-15 17:34     ` Eli Zaretskii
2011-12-15 20:50       ` Joakim Hårsman
2011-12-15 21:47         ` Joakim Hårsman
2011-12-16  8:13           ` Eli Zaretskii
2011-12-16 11:01             ` Joakim Hårsman
2011-12-16 11:14               ` Dani Moncayo
2011-12-16 11:26                 ` Eli Zaretskii
2011-12-17 12:52                   ` Joakim Hårsman
2011-12-17 15:23                     ` Eli Zaretskii
     [not found]                       ` <CAFJF9wW7Cfmad+BmjQ4A-sVeLi+eRvOXSWfD=--=QJmr3Ver6w@mail.gmail.com>
2011-12-18 18:13                         ` Eli Zaretskii
2011-12-19 10:44                           ` Joakim Hårsman
2011-12-19 10:59                             ` Lennart Borgman
2011-12-19 11:04                               ` Joakim Hårsman
2011-12-19 11:17                                 ` Lennart Borgman
2011-12-19 11:50                                   ` Joakim Hårsman
2011-12-19 13:31                           ` Jason Rumney
2011-12-20 21:16                           ` Joakim Hårsman
2012-01-14 16:40                             ` Joakim Hårsman
2012-01-16 14:03                               ` Stefan Monnier
2012-01-23 19:15                                 ` Joakim Hårsman [this message]
2012-01-24  1:35                                   ` Stefan Monnier
2012-01-24  9:40                                     ` Andreas Schwab
2012-01-24 12:03                                       ` Juanma Barranquero
2012-01-24 20:42                                         ` Joakim Hårsman
2012-07-28 14:50                                           ` Eli Zaretskii
2012-08-06 20:20                                             ` Joakim Hårsman
2012-08-07  2:53                                               ` Eli Zaretskii
2012-08-07 19:47                                                 ` Joakim Hårsman
2012-08-08  2:48                                                   ` Eli Zaretskii
2012-08-08 18:54                                                     ` Joakim Hårsman
2012-08-10  6:56                                                       ` Eli Zaretskii
2012-08-07 12:15                                               ` Jason Rumney
2012-08-07 19:49                                                 ` Joakim Hårsman
2011-12-16 11:22               ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAFJF9wVcJ+gcOybJF4Cv-s_BUtpUKVZj-OK0qJeQohKZZtbJYA@mail.gmail.com \
    --to=joakim.harsman@gmail.com \
    --cc=10299@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).