From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Joakim =?UTF-8?Q?H=C3=A5rsman?= Newsgroups: gmane.emacs.bugs Subject: bug#10299: Emacs doesn't handle Unicode characters in keyboard layout on MS Windows Date: Mon, 23 Jan 2012 20:15:15 +0100 Message-ID: References: <8739clgapc.fsf@gnu.org> <83zket20xw.fsf@gnu.org> <83vcph0w9t.fsf@gnu.org> <83obv821wv.fsf@gnu.org> <831us31atj.fsf@gnu.org> <83pqflzr1d.fsf@gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1327346185 10317 80.91.229.12 (23 Jan 2012 19:16:25 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 23 Jan 2012 19:16:25 +0000 (UTC) Cc: 10299@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Jan 23 20:16:21 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RpPNI-0002R3-Nf for geb-bug-gnu-emacs@m.gmane.org; Mon, 23 Jan 2012 20:16:16 +0100 Original-Received: from localhost ([::1]:54134 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RpPNI-0003Xo-1E for geb-bug-gnu-emacs@m.gmane.org; Mon, 23 Jan 2012 14:16:16 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:40929) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RpPN1-0003De-43 for bug-gnu-emacs@gnu.org; Mon, 23 Jan 2012 14:16:14 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RpPMt-0001uI-Mr for bug-gnu-emacs@gnu.org; Mon, 23 Jan 2012 14:15:54 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:35636) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RpPMt-0001u6-KT for bug-gnu-emacs@gnu.org; Mon, 23 Jan 2012 14:15:51 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1RpPN4-0006eh-1S for bug-gnu-emacs@gnu.org; Mon, 23 Jan 2012 14:16:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Joakim =?UTF-8?Q?H=C3=A5rsman?= Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 23 Jan 2012 19:16:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 10299 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 10299-submit@debbugs.gnu.org id=B10299.132734614125557 (code B ref 10299); Mon, 23 Jan 2012 19:16:01 +0000 Original-Received: (at 10299) by debbugs.gnu.org; 23 Jan 2012 19:15:41 +0000 Original-Received: from localhost ([127.0.0.1]:41023 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1RpPMi-0006e9-CH for submit@debbugs.gnu.org; Mon, 23 Jan 2012 14:15:41 -0500 Original-Received: from mail-bk0-f44.google.com ([209.85.214.44]:57045) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1RpPMf-0006cM-Ni for 10299@debbugs.gnu.org; Mon, 23 Jan 2012 14:15:39 -0500 Original-Received: by bkbzt4 with SMTP id zt4so809540bkb.3 for <10299@debbugs.gnu.org>; Mon, 23 Jan 2012 11:15:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=7TREjgiqpaf+48W/ToFURz6jJOMX+hKgOC9u5JyqKaw=; b=dxS3mMSzC1bvM+BJ7/gh1y2w3ten10YzYbUR0vjtUpqKXAF7a8Icnj6Z0UQ9xDSKfR NThuR4sYZVx3j/41Vbd1VhU3F8hAr4jhoIP59q6zCadPEm95XLA+/WnONeghOsG0VXs3 DGE9RjCuZF0s855z0TB+CID4YnFV561GZxNdQ= Original-Received: by 10.205.128.140 with SMTP id he12mr3854118bkc.76.1327346115674; Mon, 23 Jan 2012 11:15:15 -0800 (PST) Original-Received: by 10.205.128.17 with HTTP; Mon, 23 Jan 2012 11:15:15 -0800 (PST) In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:55938 Archived-At: 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: =3D=3D=3D 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 =3D CS_HREDRAW | CS_VREDRAW; \ + wc.lpfnWndProc =3D (WNDPROC) w32_wnd_proc; \ + wc.cbClsExtra =3D 0; \ + wc.cbWndExtra =3D WND_EXTRA_BYTES; \ + wc.hInstance =3D hinst; \ + wc.hIcon =3D LoadIcon (hinst, EMACS_CLASS); \ + wc.hCursor =3D w32_load_cursor (IDC_ARROW); \ + wc.hbrBackground =3D NULL; \ + wc.lpszMenuName =3D NULL; \ + + + #endif /* EMACS_W32_H */ =3D=3D=3D 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 =3D=3D 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 =3D ENCODE_SYSTEM (name); - + name =3D 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 =3D 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 =3D CS_HREDRAW | CS_VREDRAW; - wc.lpfnWndProc =3D (WNDPROC) w32_wnd_proc; - wc.cbClsExtra =3D 0; - wc.cbWndExtra =3D WND_EXTRA_BYTES; - wc.hInstance =3D hinst; - wc.hIcon =3D LoadIcon (hinst, EMACS_CLASS); - wc.hCursor =3D w32_load_cursor (IDC_ARROW); - wc.hbrBackground =3D NULL; /* GetStockObject (WHITE_BRUSH); */ - wc.lpszMenuName =3D NULL; - wc.lpszClassName =3D EMACS_CLASS; - - return (RegisterClass (&wc)); + + if (os_subtype =3D=3D OS_NT) + { + WNDCLASSW uwc; + INIT_WINDOW_CLASS(uwc); + uwc.lpszClassName =3D L"Emacs"; + + return (RegisterClassW (&uwc)); + } + else + { + WNDCLASS wc; + INIT_WINDOW_CLASS(wc); + wc.lpszClassName =3D EMACS_CLASS; + + return (RegisterClass (&wc)); + } } static HWND @@ -2248,8 +2265,16 @@ msh_mousewheel =3D RegisterWindowMessage (MSH_MOUSEWHEEL); - while (GetMessage (&msg, NULL, 0, 0)) + while (1) { + if (os_subtype =3D=3D OS_NT) + result =3D GetMessageW (&msg, NULL, 0, 0); + else + result =3D GetMessage (&msg, NULL, 0, 0); + + if (!result) + break; + if (msg.hwnd =3D=3D 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 =3D wParam & 0x0000FFFF; + unsigned short hi =3D (wParam & 0xFFFF0000) >> 8; + wParam =3D hi | lo; + + W32Msg wmsg; + wmsg.dwModifiers =3D 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 wrote: > Note: I know very little about w32. > >> - =A0 =A0 =A0SetWindowText (FRAME_W32_WINDOW (f), SDATA (name)); >> + =A0 =A0 =A0if (os_subtype =3D=3D OS_NT) >> + =A0 =A0 =A0 =A0SetWindowTextW (FRAME_W32_WINDOW (f), SDATA (name)); >> + =A0 =A0 =A0else >> + =A0 =A0 =A0 =A0SetWindowText (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 @@ >> =A0static BOOL >> =A0w32_init_class (HINSTANCE hinst) >> =A0{ >> - =A0WNDCLASS wc; >> - >> - =A0wc.style =3D CS_HREDRAW | CS_VREDRAW; >> - =A0wc.lpfnWndProc =3D (WNDPROC) w32_wnd_proc; >> - =A0wc.cbClsExtra =3D 0; >> - =A0wc.cbWndExtra =3D WND_EXTRA_BYTES; >> - =A0wc.hInstance =3D hinst; >> - =A0wc.hIcon =3D LoadIcon (hinst, EMACS_CLASS); >> - =A0wc.hCursor =3D w32_load_cursor (IDC_ARROW); >> - =A0wc.hbrBackground =3D NULL; /* GetStockObject (WHITE_BRUSH); =A0*/ >> - =A0wc.lpszMenuName =3D NULL; >> - =A0wc.lpszClassName =3D EMACS_CLASS; >> - >> - =A0return (RegisterClass (&wc)); >> + =A0WNDCLASSW uwc; >> + =A0WNDCLASS =A0wc; >> + >> + =A0if (os_subtype =3D=3D OS_NT) >> + =A0 =A0{ >> + =A0 =A0 =A0uwc.style =3D CS_HREDRAW | CS_VREDRAW; >> + =A0 =A0 =A0uwc.lpfnWndProc =3D (WNDPROC) w32_wnd_proc; >> + =A0 =A0 =A0uwc.cbClsExtra =3D 0; >> + =A0 =A0 =A0uwc.cbWndExtra =3D WND_EXTRA_BYTES; >> + =A0 =A0 =A0uwc.hInstance =3D hinst; >> + =A0 =A0 =A0uwc.hIcon =3D LoadIcon (hinst, EMACS_CLASS); >> + =A0 =A0 =A0uwc.hCursor =3D w32_load_cursor (IDC_ARROW); >> + =A0 =A0 =A0uwc.hbrBackground =3D NULL; /* GetStockObject (WHITE_BRUSH)= ; =A0*/ >> + =A0 =A0 =A0uwc.lpszMenuName =3D NULL; >> + =A0 =A0 =A0uwc.lpszClassName =3D L"Emacs"; >> + >> + =A0 =A0 =A0return (RegisterClassW (&uwc)); >> + =A0 =A0} >> + =A0else >> + =A0 =A0{ >> + =A0 =A0 =A0wc.style =3D CS_HREDRAW | CS_VREDRAW; >> + =A0 =A0 =A0wc.lpfnWndProc =3D (WNDPROC) w32_wnd_proc; >> + =A0 =A0 =A0wc.cbClsExtra =3D 0; >> + =A0 =A0 =A0wc.cbWndExtra =3D WND_EXTRA_BYTES; >> + =A0 =A0 =A0wc.hInstance =3D hinst; >> + =A0 =A0 =A0wc.hIcon =3D LoadIcon (hinst, EMACS_CLASS); >> + =A0 =A0 =A0wc.hCursor =3D w32_load_cursor (IDC_ARROW); >> + =A0 =A0 =A0wc.hbrBackground =3D NULL; /* GetStockObject (WHITE_BRUSH);= =A0*/ >> + =A0 =A0 =A0wc.lpszMenuName =3D NULL; >> + =A0 =A0 =A0wc.lpszClassName =3D EMACS_CLASS; >> + >> + =A0 =A0 =A0return (RegisterClass (&wc)); >> + =A0 =A0} >> =A0} > > The two var declarations (WNDCLASSW uwc and WNDCLASS wc) should be moved > within their respective branch. =A0And it'd be better if we could share > some code between the two branches, e.g. using a macro. > > > =A0 =A0 =A0 =A0Stefan