changeset 104030:91b945d54645

* w32fns.c (w32_wnd_proc) [WM_IME_STARTCOMPOSITION]: Position IME window at cursor (Bug#2570). (w32_wnd_proc) [WM_IME_CHAR]: Release context when finished. (globals_of_w32fns): Dynamically load functions required above. * w32term.c (w32_draw_window_cursor): Send message to reposition any IME window.
author Jason Rumney <jasonr@gnu.org>
date Wed, 22 Jul 2009 16:03:39 +0000
parents 55ba5af4bf3a
children e5dc7eae1964
files src/ChangeLog src/w32fns.c src/w32term.c
diffstat 3 files changed, 58 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Wed Jul 22 03:07:18 2009 +0000
+++ b/src/ChangeLog	Wed Jul 22 16:03:39 2009 +0000
@@ -1,3 +1,13 @@
+2009-07-22  Jason Rumney  <jasonr@gnu.org>
+
+	* w32fns.c (w32_wnd_proc) [WM_IME_STARTCOMPOSITION]: Position
+	IME window at cursor (Bug#2570).
+	(w32_wnd_proc) [WM_IME_CHAR]: Release context when finished.
+	(globals_of_w32fns): Dynamically load functions required above.
+
+	* w32term.c (w32_draw_window_cursor): Send message to reposition
+	any IME window.
+
 2009-07-21  Chong Yidong  <cyd@stupidchicken.com>
 
 	* fileio.c: Revert 2009-07-16 changes.
--- a/src/w32fns.c	Wed Jul 22 03:07:18 2009 +0000
+++ b/src/w32fns.c	Wed Jul 22 16:03:39 2009 +0000
@@ -252,6 +252,9 @@
 typedef LONG (WINAPI * ImmGetCompositionString_Proc)
   (IN HIMC context, IN DWORD index, OUT LPVOID buffer, IN DWORD bufLen);
 typedef HIMC (WINAPI * ImmGetContext_Proc) (IN HWND window);
+typedef HWND (WINAPI * ImmReleaseContext_Proc) (IN HWND wnd, IN HIMC context);
+typedef HWND (WINAPI * ImmSetCompositionWindow_Proc) (IN HIMC context,
+						      IN COMPOSITIONFORM *form);
 typedef HMONITOR (WINAPI * MonitorFromPoint_Proc) (IN POINT pt, IN DWORD flags);
 typedef BOOL (WINAPI * GetMonitorInfo_Proc)
   (IN HMONITOR monitor, OUT struct MONITOR_INFO* info);
@@ -260,6 +263,8 @@
 ClipboardSequence_Proc clipboard_sequence_fn = NULL;
 ImmGetCompositionString_Proc get_composition_string_fn = NULL;
 ImmGetContext_Proc get_ime_context_fn = NULL;
+ImmReleaseContext_Proc release_ime_context_fn = NULL;
+ImmSetCompositionWindow_Proc set_ime_composition_window_fn = NULL;
 MonitorFromPoint_Proc monitor_from_point_fn = NULL;
 GetMonitorInfo_Proc get_monitor_info_fn = NULL;
 
@@ -3158,6 +3163,8 @@
           buffer = alloca(size);
           size = get_composition_string_fn (context, GCS_RESULTSTR,
                                             buffer, size);
+	  release_ime_context_fn (hwnd, context);
+
           signal_user_input ();
           for (i = 0; i < size / sizeof (wchar_t); i++)
             {
@@ -3173,6 +3180,40 @@
 
       break;
 
+    case WM_IME_STARTCOMPOSITION:
+      if (!set_ime_composition_window_fn)
+	goto dflt;
+      else
+	{
+	  COMPOSITIONFORM form;
+	  HIMC context;
+	  struct window *w;
+
+	  if (!context)
+	    break;
+
+	  f = x_window_to_frame (dpyinfo, hwnd);
+	  w = XWINDOW (FRAME_SELECTED_WINDOW (f));
+
+	  form.dwStyle = CFS_RECT;
+	  form.ptCurrentPos.x = w32_system_caret_x;
+	  form.ptCurrentPos.y = w32_system_caret_y;
+
+	  form.rcArea.left = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, 0);
+	  form.rcArea.top = (WINDOW_TOP_EDGE_Y (w)
+			     + WINDOW_HEADER_LINE_HEIGHT (w));
+	  form.rcArea.right = (WINDOW_BOX_RIGHT_EDGE_X (w)
+			       - WINDOW_RIGHT_MARGIN_WIDTH (w)
+			       - WINDOW_RIGHT_FRINGE_WIDTH (w));
+	  form.rcArea.bottom = (WINDOW_BOTTOM_EDGE_Y (w)
+				- WINDOW_MODE_LINE_HEIGHT (w));
+
+	  context = get_ime_context_fn (hwnd);
+	  set_ime_composition_window_fn (context, &form);
+	  release_ime_context_fn (hwnd, context);
+	}
+      break;
+
     case WM_IME_ENDCOMPOSITION:
       ignore_ime_char = 0;
       goto dflt;
@@ -7278,6 +7319,10 @@
       GetProcAddress (imm32_lib, "ImmGetCompositionStringW");
     get_ime_context_fn = (ImmGetContext_Proc)
       GetProcAddress (imm32_lib, "ImmGetContext");
+    release_ime_context_fn = (ImmReleaseContext_Proc)
+      GetProcAddress (imm32_lib, "ImmReleaseContext");
+    set_ime_composition_window_fn = (ImmSetCompositionWindow_Proc)
+      GetProcAddress (imm32_lib, "ImmSetCompositionWindow");
   }
   DEFVAR_INT ("w32-ansi-code-page",
 	      &w32_ansi_code_page,
--- a/src/w32term.c	Wed Jul 22 03:07:18 2009 +0000
+++ b/src/w32term.c	Wed Jul 22 16:03:39 2009 +0000
@@ -32,6 +32,7 @@
 #include <ctype.h>
 #include <errno.h>
 #include <sys/stat.h>
+#include <imm.h>
 
 #include "charset.h"
 #include "character.h"
@@ -5128,6 +5129,8 @@
 	    = (WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y)
 	       + glyph_row->ascent - w->phys_cursor_ascent);
 
+	  PostMessage (hwnd, WM_IME_STARTCOMPOSITION, 0, 0);
+
 	  /* If the size of the active cursor changed, destroy the old
 	     system caret.  */
 	  if (w32_system_caret_hwnd