From d30be705dfb9a14e6ac07df9e8b61f09ed96d95e Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Fri, 10 Aug 2012 09:54:37 +0300 Subject: [PATCH] Fix bug #10299 with Unicode characters sent on MS-Windows by MSKLC. src/w32fns.c (INIT_WINDOW_CLASS): New macro. (w32_init_class): Use it to initialize the Emacs class with either ANSI or Unicode API calls. (w32_msg_pump): Call GetMessageW and DispatchMessageW on NT and later. (w32_wnd_proc): If the character code sent by WM_CHAR or WM_SYSCHAR is above 255, post a WM_UNICHAR message, not the original message. Call DefWindowProcW on NT and later. --- src/ChangeLog | 14 ++++++++++++ src/w32fns.c | 61 +++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 58 insertions(+), 17 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index bd43b7ba05e..a537c07b769 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,17 @@ +2012-08-10 Joakim HÃ¥rsman (tiny patch) + Eli Zaretskii + + Fix bug #10299 with Unicode characters sent by customized + keyboards created by MSKLC. + * w32fns.c (INIT_WINDOW_CLASS): New macro. + (w32_init_class): Use it to initialize the Emacs class with either + ANSI or Unicode API calls. + (w32_msg_pump): Call GetMessageW and DispatchMessageW on NT and + later. + (w32_wnd_proc): If the character code sent by WM_CHAR or + WM_SYSCHAR is above 255, post a WM_UNICHAR message, not the + original message. Call DefWindowProcW on NT and later. + 2012-08-10 Glenn Morris * Makefile.in (config_h): Fix conf_post.h out-of-tree build location. diff --git a/src/w32fns.c b/src/w32fns.c index 3c40361ca86..62b4272f236 100644 --- a/src/w32fns.c +++ b/src/w32fns.c @@ -1780,23 +1780,37 @@ w32_load_cursor (LPCTSTR name) static LRESULT CALLBACK w32_wnd_proc (HWND, UINT, WPARAM, LPARAM); +#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; \ + 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; + 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)); + return RegisterClassA (&wc); + } } static HWND @@ -2246,7 +2260,7 @@ w32_msg_pump (deferred_msg * msg_buf) msh_mousewheel = RegisterWindowMessage (MSH_MOUSEWHEEL); - while (GetMessage (&msg, NULL, 0, 0)) + while ((os_subtype == OS_NT ? GetMessageW : GetMessageA) (&msg, NULL, 0, 0)) { if (msg.hwnd == NULL) { @@ -2341,7 +2355,10 @@ w32_msg_pump (deferred_msg * msg_buf) } else { - DispatchMessage (&msg); + if (os_subtype == OS_NT) + DispatchMessageW (&msg); + else + DispatchMessageA (&msg); } /* Exit nested loop when our deferred message has completed. */ @@ -2918,8 +2935,18 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) case WM_SYSCHAR: case WM_CHAR: - post_character_message (hwnd, msg, wParam, lParam, - w32_get_key_modifiers (wParam, lParam)); + if (wParam > 255 ) + { + 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: @@ -3801,7 +3828,7 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) } dflt: - return DefWindowProc (hwnd, msg, wParam, lParam); + return (os_subtype == OS_NT ? DefWindowProcW : DefWindowProcA) (hwnd, msg, wParam, lParam); } /* The most common default return code for handled messages is 0. */ -- 2.39.2