aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Rumney2007-11-17 03:01:50 +0000
committerJason Rumney2007-11-17 03:01:50 +0000
commit820eff5a8fdc592b5765791534227fc70ffee30e (patch)
tree8c59d7a6a18ef41a33294d162f27fb05c53c641b
parenta60b033380f657f2af669cc08d12f7ace82fdd67 (diff)
downloademacs-820eff5a8fdc592b5765791534227fc70ffee30e.tar.gz
emacs-820eff5a8fdc592b5765791534227fc70ffee30e.zip
Include imm.h.
(get_composition_string_fn, get_ime_context_fn): New optional system functions. (globals_of_w32fns): Load them from imm32.dll. (ignore_ime_char): New flag. (w32_wnd_proc): Handle WM_UNICHAR, WM_IME_CHAR and WM_IME_ENDCOMPOSITION.
-rw-r--r--src/w32fns.c77
1 files changed, 75 insertions, 2 deletions
diff --git a/src/w32fns.c b/src/w32fns.c
index 808376bf580..03179c6952e 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -58,6 +58,7 @@ Boston, MA 02110-1301, USA. */
58#include <objbase.h> 58#include <objbase.h>
59 59
60#include <dlgs.h> 60#include <dlgs.h>
61#include <imm.h>
61#define FILE_NAME_TEXT_FIELD edt1 62#define FILE_NAME_TEXT_FIELD edt1
62 63
63#ifdef USE_FONT_BACKEND 64#ifdef USE_FONT_BACKEND
@@ -269,11 +270,20 @@ static HWND track_mouse_window;
269 270
270typedef BOOL (WINAPI * TrackMouseEvent_Proc) 271typedef BOOL (WINAPI * TrackMouseEvent_Proc)
271 (IN OUT LPTRACKMOUSEEVENT lpEventTrack); 272 (IN OUT LPTRACKMOUSEEVENT lpEventTrack);
273typedef LONG (WINAPI * ImmGetCompositionString_Proc)
274 (IN HIMC context, IN DWORD index, OUT LPVOID buffer, IN DWORD bufLen);
275typedef HIMC (WINAPI * ImmGetContext_Proc) (IN HWND window);
272 276
273TrackMouseEvent_Proc track_mouse_event_fn = NULL; 277TrackMouseEvent_Proc track_mouse_event_fn = NULL;
274ClipboardSequence_Proc clipboard_sequence_fn = NULL; 278ClipboardSequence_Proc clipboard_sequence_fn = NULL;
279ImmGetCompositionString_Proc get_composition_string_fn = NULL;
280ImmGetContext_Proc get_ime_context_fn = NULL;
281
275extern AppendMenuW_Proc unicode_append_menu; 282extern AppendMenuW_Proc unicode_append_menu;
276 283
284/* Flag to selectively ignore WM_IME_CHAR messages. */
285static int ignore_ime_char = 0;
286
277/* W95 mousewheel handler */ 287/* W95 mousewheel handler */
278unsigned int msh_mousewheel = 0; 288unsigned int msh_mousewheel = 0;
279 289
@@ -3162,7 +3172,6 @@ w32_wnd_proc (hwnd, msg, wParam, lParam)
3162 if (windows_translate) 3172 if (windows_translate)
3163 { 3173 {
3164 MSG windows_msg = { hwnd, msg, wParam, lParam, 0, {0,0} }; 3174 MSG windows_msg = { hwnd, msg, wParam, lParam, 0, {0,0} };
3165
3166 windows_msg.time = GetMessageTime (); 3175 windows_msg.time = GetMessageTime ();
3167 TranslateMessage (&windows_msg); 3176 TranslateMessage (&windows_msg);
3168 goto dflt; 3177 goto dflt;
@@ -3176,6 +3185,64 @@ w32_wnd_proc (hwnd, msg, wParam, lParam)
3176 w32_get_key_modifiers (wParam, lParam)); 3185 w32_get_key_modifiers (wParam, lParam));
3177 break; 3186 break;
3178 3187
3188 case WM_UNICHAR:
3189 /* WM_UNICHAR looks promising from the docs, but the exact
3190 circumstances in which TranslateMessage sends it is one of those
3191 Microsoft secret API things that EU and US courts are supposed
3192 to have put a stop to already. Spy++ shows it being sent to Notepad
3193 and other MS apps, but never to Emacs.
3194
3195 Some third party IMEs send it in accordance with the official
3196 documentation though, so handle it here.
3197
3198 UNICODE_NOCHAR is used to test for support for this message.
3199 TRUE indicates that the message is supported. */
3200 if (wParam == UNICODE_NOCHAR)
3201 return TRUE;
3202
3203 {
3204 W32Msg wmsg;
3205 wmsg.dwModifiers = w32_get_key_modifiers (wParam, lParam);
3206 signal_user_input ();
3207 my_post_msg (&wmsg, hwnd, msg, wParam, lParam);
3208 }
3209 break;
3210
3211 case WM_IME_CHAR:
3212 /* If we can't get the IME result as unicode, use default processing,
3213 which will at least allow characters decodable in the system locale
3214 get through. */
3215 if (!get_composition_string_fn)
3216 goto dflt;
3217
3218 else if (!ignore_ime_char)
3219 {
3220 wchar_t * buffer;
3221 int size, i;
3222 W32Msg wmsg;
3223 HIMC context = get_ime_context_fn (hwnd);
3224 wmsg.dwModifiers = w32_get_key_modifiers (wParam, lParam);
3225 /* Get buffer size. */
3226 size = get_composition_string_fn (context, GCS_RESULTSTR, buffer, 0);
3227 buffer = alloca(size);
3228 size = get_composition_string_fn (context, GCS_RESULTSTR,
3229 buffer, size);
3230 signal_user_input ();
3231 for (i = 0; i < size / sizeof (wchar_t); i++)
3232 {
3233 my_post_msg (&wmsg, hwnd, WM_UNICHAR, (WPARAM) buffer[i],
3234 lParam);
3235 }
3236 /* We output the whole string above, so ignore following ones
3237 until we are notified of the end of composition. */
3238 ignore_ime_char = 1;
3239 }
3240 break;
3241
3242 case WM_IME_ENDCOMPOSITION:
3243 ignore_ime_char = 0;
3244 goto dflt;
3245
3179 /* Simulate middle mouse button events when left and right buttons 3246 /* Simulate middle mouse button events when left and right buttons
3180 are used together, but only if user has two button mouse. */ 3247 are used together, but only if user has two button mouse. */
3181 case WM_LBUTTONDOWN: 3248 case WM_LBUTTONDOWN:
@@ -9227,7 +9294,13 @@ void globals_of_w32fns ()
9227 /* ditto for GetClipboardSequenceNumber. */ 9294 /* ditto for GetClipboardSequenceNumber. */
9228 clipboard_sequence_fn = (ClipboardSequence_Proc) 9295 clipboard_sequence_fn = (ClipboardSequence_Proc)
9229 GetProcAddress (user32_lib, "GetClipboardSequenceNumber"); 9296 GetProcAddress (user32_lib, "GetClipboardSequenceNumber");
9230 9297 {
9298 HMODULE imm32_lib = GetModuleHandle ("imm32.dll");
9299 get_composition_string_fn = (ImmGetCompositionString_Proc)
9300 GetProcAddress (imm32_lib, "ImmGetCompositionStringW");
9301 get_ime_context_fn = (ImmGetContext_Proc)
9302 GetProcAddress (imm32_lib, "ImmGetContext");
9303 }
9231 DEFVAR_INT ("w32-ansi-code-page", 9304 DEFVAR_INT ("w32-ansi-code-page",
9232 &w32_ansi_code_page, 9305 &w32_ansi_code_page,
9233 doc: /* The ANSI code page used by the system. */); 9306 doc: /* The ANSI code page used by the system. */);