3 * Copyright (C) 2003 Takuro Ashie
4 * Copyright (C) 2003-2004 Kazuki IWAMOTO
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
24 * Please see the following site for the detail of Windows IME API.
25 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/appendix/hh/appendix/imeimes2_35ph.asp
28 #ifdef GTK_DISABLE_DEPRECATED
29 #undef GTK_DISABLE_DEPRECATED
32 #include "gtkimcontextime.h"
34 #include "imm-extra.h"
36 #include "gdk/win32/gdkwin32.h"
37 #include "gdk/gdkkeysyms.h"
39 #include <pango/pango.h>
44 # include <pango/pangowin32.h>
49 # include <pango/pangowin32.h>
52 /* #define BUFSIZE 4096 */
54 #define FREE_PREEDIT_BUFFER(ctx) \
56 g_free((ctx)->priv->comp_str); \
57 g_free((ctx)->priv->read_str); \
58 (ctx)->priv->comp_str = NULL; \
59 (ctx)->priv->read_str = NULL; \
60 (ctx)->priv->comp_str_len = 0; \
61 (ctx)->priv->read_str_len = 0; \
65 struct _GtkIMContextIMEPrivate
67 /* save IME context when the client window is focused out */
68 DWORD conversion_mode;
78 /* GObject class methods */
79 static void gtk_im_context_ime_class_init (GtkIMContextIMEClass *class);
80 static void gtk_im_context_ime_init (GtkIMContextIME *context_ime);
81 static void gtk_im_context_ime_dispose (GObject *obj);
82 static void gtk_im_context_ime_finalize (GObject *obj);
84 static void gtk_im_context_ime_set_property (GObject *object,
88 static void gtk_im_context_ime_get_property (GObject *object,
93 /* GtkIMContext's virtual functions */
94 static void gtk_im_context_ime_set_client_window (GtkIMContext *context,
95 GdkWindow *client_window);
96 static gboolean gtk_im_context_ime_filter_keypress (GtkIMContext *context,
98 static void gtk_im_context_ime_reset (GtkIMContext *context);
99 static void gtk_im_context_ime_get_preedit_string (GtkIMContext *context,
101 PangoAttrList **attrs,
103 static void gtk_im_context_ime_focus_in (GtkIMContext *context);
104 static void gtk_im_context_ime_focus_out (GtkIMContext *context);
105 static void gtk_im_context_ime_set_cursor_location (GtkIMContext *context,
107 static void gtk_im_context_ime_set_use_preedit (GtkIMContext *context,
108 gboolean use_preedit);
110 /* GtkIMContextIME's private functions */
111 static void gtk_im_context_ime_set_preedit_font (GtkIMContext *context);
113 static GdkFilterReturn
114 gtk_im_context_ime_message_filter (GdkXEvent *xevent,
117 static void get_window_position (GdkWindow *win,
120 static void cb_client_widget_hierarchy_changed (GtkWidget *widget,
122 GtkIMContextIME *context_ime);
124 GType gtk_type_im_context_ime = 0;
125 static GObjectClass *parent_class;
129 gtk_im_context_ime_register_type (GTypeModule *type_module)
131 const GTypeInfo im_context_ime_info = {
132 sizeof (GtkIMContextIMEClass),
133 (GBaseInitFunc) NULL,
134 (GBaseFinalizeFunc) NULL,
135 (GClassInitFunc) gtk_im_context_ime_class_init,
136 NULL, /* class_finalize */
137 NULL, /* class_data */
138 sizeof (GtkIMContextIME),
140 (GInstanceInitFunc) gtk_im_context_ime_init,
143 gtk_type_im_context_ime =
144 g_type_module_register_type (type_module,
146 "GtkIMContextIME", &im_context_ime_info, 0);
150 gtk_im_context_ime_class_init (GtkIMContextIMEClass *class)
152 GtkIMContextClass *im_context_class = GTK_IM_CONTEXT_CLASS (class);
153 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
155 parent_class = g_type_class_peek_parent (class);
157 gobject_class->finalize = gtk_im_context_ime_finalize;
158 gobject_class->dispose = gtk_im_context_ime_dispose;
159 gobject_class->set_property = gtk_im_context_ime_set_property;
160 gobject_class->get_property = gtk_im_context_ime_get_property;
162 im_context_class->set_client_window = gtk_im_context_ime_set_client_window;
163 im_context_class->filter_keypress = gtk_im_context_ime_filter_keypress;
164 im_context_class->reset = gtk_im_context_ime_reset;
165 im_context_class->get_preedit_string = gtk_im_context_ime_get_preedit_string;
166 im_context_class->focus_in = gtk_im_context_ime_focus_in;
167 im_context_class->focus_out = gtk_im_context_ime_focus_out;
168 im_context_class->set_cursor_location = gtk_im_context_ime_set_cursor_location;
169 im_context_class->set_use_preedit = gtk_im_context_ime_set_use_preedit;
174 gtk_im_context_ime_init (GtkIMContextIME *context_ime)
176 context_ime->client_window = NULL;
177 context_ime->toplevel = NULL;
178 context_ime->use_preedit = TRUE;
179 context_ime->preediting = FALSE;
180 context_ime->opened = FALSE;
181 context_ime->focus = FALSE;
182 context_ime->cursor_location.x = 0;
183 context_ime->cursor_location.y = 0;
184 context_ime->cursor_location.width = 0;
185 context_ime->cursor_location.height = 0;
187 context_ime->priv = g_malloc0 (sizeof (GtkIMContextIMEPrivate));
188 context_ime->priv->conversion_mode = 0;
189 context_ime->priv->sentence_mode = 0;
190 context_ime->priv->comp_str = NULL;
191 context_ime->priv->comp_str_len = 0;
192 context_ime->priv->read_str = NULL;
193 context_ime->priv->read_str_len = 0;
198 gtk_im_context_ime_dispose (GObject *obj)
200 GtkIMContext *context = GTK_IM_CONTEXT (obj);
201 GtkIMContextIME *context_ime = GTK_IM_CONTEXT_IME (obj);
203 if (context_ime->client_window)
204 gtk_im_context_ime_set_client_window (context, NULL);
206 FREE_PREEDIT_BUFFER (context_ime);
208 if (G_OBJECT_CLASS (parent_class)->dispose)
209 G_OBJECT_CLASS (parent_class)->dispose (obj);
214 gtk_im_context_ime_finalize (GObject *obj)
216 /* GtkIMContext *context = GTK_IM_CONTEXT (obj); */
217 GtkIMContextIME *context_ime = GTK_IM_CONTEXT_IME (obj);
219 g_free (context_ime->priv);
220 context_ime->priv = NULL;
222 if (G_OBJECT_CLASS (parent_class)->finalize)
223 G_OBJECT_CLASS (parent_class)->finalize (obj);
228 gtk_im_context_ime_set_property (GObject *object,
233 GtkIMContextIME *context_ime = GTK_IM_CONTEXT_IME (object);
235 g_return_if_fail (GTK_IS_IM_CONTEXT_IME (context_ime));
246 gtk_im_context_ime_get_property (GObject *object,
251 GtkIMContextIME *context_ime = GTK_IM_CONTEXT_IME (object);
253 g_return_if_fail (GTK_IS_IM_CONTEXT_IME (context_ime));
264 gtk_im_context_ime_new (void)
266 return g_object_new (GTK_TYPE_IM_CONTEXT_IME, NULL);
271 gtk_im_context_ime_set_client_window (GtkIMContext *context,
272 GdkWindow *client_window)
274 GtkIMContextIME *context_ime;
276 g_return_if_fail (GTK_IS_IM_CONTEXT_IME (context));
277 context_ime = GTK_IM_CONTEXT_IME (context);
284 hwnd = GDK_WINDOW_HWND (client_window);
285 himc = ImmGetContext (hwnd);
288 context_ime->opened = ImmGetOpenStatus (himc);
289 ImmGetConversionStatus (himc,
290 &context_ime->priv->conversion_mode,
291 &context_ime->priv->sentence_mode);
292 ImmReleaseContext (hwnd, himc);
295 else if (context_ime->focus)
297 gtk_im_context_ime_focus_out (context);
300 context_ime->client_window = client_window;
305 gtk_im_context_ime_filter_keypress (GtkIMContext *context,
308 GtkIMContextIME *context_ime;
309 gboolean retval = FALSE;
312 g_return_val_if_fail (GTK_IS_IM_CONTEXT_IME (context), FALSE);
313 g_return_val_if_fail (event, FALSE);
315 if (event->type == GDK_KEY_RELEASE)
318 if (event->state & GDK_CONTROL_MASK)
321 context_ime = GTK_IM_CONTEXT_IME (context);
323 if (!context_ime->focus)
326 if (!GDK_IS_WINDOW (context_ime->client_window))
329 c = gdk_keyval_to_unicode (event->keyval);
333 int len = g_unichar_to_utf8 (c, utf8);
336 g_signal_emit_by_name (context_ime, "commit", utf8);
345 gtk_im_context_ime_reset (GtkIMContext *context)
347 GtkIMContextIME *context_ime = GTK_IM_CONTEXT_IME (context);
351 hwnd = GDK_WINDOW_HWND (context_ime->client_window);
352 himc = ImmGetContext (hwnd);
356 if (context_ime->preediting && ImmGetOpenStatus (himc))
357 ImmNotifyIME (himc, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
359 context_ime->preediting = FALSE;
360 g_signal_emit_by_name (context, "preedit-changed");
362 ImmReleaseContext (hwnd, himc);
367 get_utf8_preedit_string (GtkIMContextIME *context_ime, gint *pos_ret)
369 gchar *utf8str = NULL;
377 hwnd = GDK_WINDOW_HWND (context_ime->client_window);
378 himc = ImmGetContext (hwnd);
380 return g_strdup ("");
382 if (context_ime->preediting)
386 len = ImmGetCompositionStringW (himc, GCS_COMPSTR, NULL, 0);
389 GError *error = NULL;
390 gpointer buf = g_alloca (len);
392 ImmGetCompositionStringW (himc, GCS_COMPSTR, buf, len);
394 utf8str = g_utf16_to_utf8 (buf, len, NULL, NULL, &error);
397 g_warning ("%s", error->message);
398 g_error_free (error);
403 pos = ImmGetCompositionStringW (himc, GCS_CURSORPOS, NULL, 0);
404 if (pos < 0 || len < pos)
406 g_warning ("ImmGetCompositionString: "
407 "Invalid cursor position!");
416 utf8str = g_strdup ("");
423 ImmReleaseContext (hwnd, himc);
429 static PangoAttrList *
430 get_pango_attr_list (GtkIMContextIME *context_ime, const gchar *utf8str)
432 PangoAttrList *attrs = pango_attr_list_new ();
436 hwnd = GDK_WINDOW_HWND (context_ime->client_window);
437 himc = ImmGetContext (hwnd);
441 if (context_ime->preediting)
443 const gchar *schr = utf8str, *echr;
445 guint16 f_red, f_green, f_blue, b_red, b_green, b_blue;
446 glong len, spos = 0, epos, sidx = 0, eidx;
447 PangoAttribute *attr;
450 * get attributes list of IME.
452 len = ImmGetCompositionStringW (himc, GCS_COMPATTR, NULL, 0);
453 buf = g_alloca (len);
454 ImmGetCompositionStringW (himc, GCS_COMPATTR, buf, len);
457 * schr and echr are pointer in utf8str.
459 for (echr = g_utf8_next_char (utf8str); *schr != '\0';
460 echr = g_utf8_next_char (echr))
463 * spos and epos are buf(attributes list of IME) position by
465 * Using the wide-char API, this value is same with UTF-8 offset.
467 epos = g_utf8_pointer_to_offset (utf8str, echr);
470 * sidx and eidx are positions in utf8str by bytes.
472 eidx = echr - utf8str;
475 * convert attributes list to PangoAttriute.
477 if (*echr == '\0' || buf[spos] != buf[epos])
481 case ATTR_TARGET_CONVERTED:
482 attr = pango_attr_underline_new (PANGO_UNDERLINE_DOUBLE);
483 attr->start_index = sidx;
484 attr->end_index = eidx;
485 pango_attr_list_change (attrs, attr);
486 f_red = f_green = f_blue = 0;
487 b_red = b_green = b_blue = 0xffff;
489 case ATTR_TARGET_NOTCONVERTED:
490 f_red = f_green = f_blue = 0xffff;
491 b_red = b_green = b_blue = 0;
493 case ATTR_INPUT_ERROR:
494 f_red = f_green = f_blue = 0;
495 b_red = b_green = b_blue = 0x7fff;
497 default: /* ATTR_INPUT,ATTR_CONVERTED,ATTR_FIXEDCONVERTED */
498 attr = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE);
499 attr->start_index = sidx;
500 attr->end_index = eidx;
501 pango_attr_list_change (attrs, attr);
502 f_red = f_green = f_blue = 0;
503 b_red = b_green = b_blue = 0xffff;
505 attr = pango_attr_foreground_new (f_red, f_green, f_blue);
506 attr->start_index = sidx;
507 attr->end_index = eidx;
508 pango_attr_list_change (attrs, attr);
509 attr = pango_attr_background_new (b_red, b_green, b_blue);
510 attr->start_index = sidx;
511 attr->end_index = eidx;
512 pango_attr_list_change (attrs, attr);
521 ImmReleaseContext (hwnd, himc);
528 gtk_im_context_ime_get_preedit_string (GtkIMContext *context,
530 PangoAttrList **attrs,
533 gchar *utf8str = NULL;
535 GtkIMContextIME *context_ime;
537 context_ime = GTK_IM_CONTEXT_IME (context);
539 utf8str = get_utf8_preedit_string (context_ime, &pos);
542 *attrs = get_pango_attr_list (context_ime, utf8str);
560 gtk_im_context_ime_focus_in (GtkIMContext *context)
562 GtkIMContextIME *context_ime = GTK_IM_CONTEXT_IME (context);
564 GtkWidget *widget = NULL;
568 if (!GDK_IS_WINDOW (context_ime->client_window))
571 /* swtich current context */
572 context_ime->focus = TRUE;
574 hwnd = GDK_WINDOW_HWND (context_ime->client_window);
575 himc = ImmGetContext (hwnd);
579 toplevel = gdk_window_get_toplevel (context_ime->client_window);
580 if (GDK_IS_WINDOW (toplevel))
582 gdk_window_add_filter (toplevel,
583 gtk_im_context_ime_message_filter, context_ime);
584 top_hwnd = GDK_WINDOW_HWND (toplevel);
586 context_ime->toplevel = toplevel;
590 g_warning ("gtk_im_context_ime_focus_in(): "
591 "cannot find toplevel window.");
595 /* trace reparenting (probably no need) */
596 gdk_window_get_user_data (context_ime->client_window, (gpointer) & widget);
597 if (GTK_IS_WIDGET (widget))
599 g_signal_connect (widget, "hierarchy-changed",
600 G_CALLBACK (cb_client_widget_hierarchy_changed),
608 /* restore preedit context */
609 ImmSetConversionStatus (himc,
610 context_ime->priv->conversion_mode,
611 context_ime->priv->sentence_mode);
613 if (context_ime->opened)
615 if (!ImmGetOpenStatus (himc))
616 ImmSetOpenStatus (himc, TRUE);
617 if (context_ime->preediting)
619 ImmSetCompositionStringW (himc,
621 context_ime->priv->comp_str,
622 context_ime->priv->comp_str_len, NULL, 0);
623 FREE_PREEDIT_BUFFER (context_ime);
628 ImmReleaseContext (hwnd, himc);
633 gtk_im_context_ime_focus_out (GtkIMContext *context)
635 GtkIMContextIME *context_ime = GTK_IM_CONTEXT_IME (context);
637 GtkWidget *widget = NULL;
641 if (!GDK_IS_WINDOW (context_ime->client_window))
644 /* swtich current context */
645 context_ime->focus = FALSE;
647 hwnd = GDK_WINDOW_HWND (context_ime->client_window);
648 himc = ImmGetContext (hwnd);
652 /* save preedit context */
653 ImmGetConversionStatus (himc,
654 &context_ime->priv->conversion_mode,
655 &context_ime->priv->sentence_mode);
657 if (ImmGetOpenStatus (himc))
659 gboolean preediting = context_ime->preediting;
663 FREE_PREEDIT_BUFFER (context_ime);
665 context_ime->priv->comp_str_len
666 = ImmGetCompositionStringW (himc, GCS_COMPSTR, NULL, 0);
667 context_ime->priv->comp_str
668 = g_malloc (context_ime->priv->comp_str_len);
669 ImmGetCompositionStringW (himc, GCS_COMPSTR,
670 context_ime->priv->comp_str,
671 context_ime->priv->comp_str_len);
673 context_ime->priv->read_str_len
674 = ImmGetCompositionStringW (himc, GCS_COMPREADSTR, NULL, 0);
675 context_ime->priv->read_str
676 = g_malloc (context_ime->priv->read_str_len);
677 ImmGetCompositionStringW (himc, GCS_COMPREADSTR,
678 context_ime->priv->read_str,
679 context_ime->priv->read_str_len);
682 ImmSetOpenStatus (himc, FALSE);
684 context_ime->opened = TRUE;
685 context_ime->preediting = preediting;
689 context_ime->opened = FALSE;
690 context_ime->preediting = FALSE;
693 /* remove signal handler */
694 gdk_window_get_user_data (context_ime->client_window, (gpointer) & widget);
695 if (GTK_IS_WIDGET (widget))
697 g_signal_handlers_disconnect_by_func
699 G_CALLBACK (cb_client_widget_hierarchy_changed), context_ime);
702 /* remove event fileter */
703 toplevel = gdk_window_get_toplevel (context_ime->client_window);
704 if (GDK_IS_WINDOW (toplevel))
706 gdk_window_remove_filter (toplevel,
707 gtk_im_context_ime_message_filter,
709 top_hwnd = GDK_WINDOW_HWND (toplevel);
711 context_ime->toplevel = NULL;
715 g_warning ("gtk_im_context_ime_focus_out(): "
716 "cannot find toplevel window.");
720 ImmReleaseContext (hwnd, himc);
725 gtk_im_context_ime_set_cursor_location (GtkIMContext *context,
729 GtkIMContextIME *context_ime;
734 g_return_if_fail (GTK_IS_IM_CONTEXT_IME (context));
736 context_ime = GTK_IM_CONTEXT_IME (context);
738 context_ime->cursor_location = *area;
740 if (!context_ime->client_window)
743 hwnd = GDK_WINDOW_HWND (context_ime->client_window);
744 himc = ImmGetContext (hwnd);
748 get_window_position (context_ime->client_window, &wx, &wy);
749 cf.dwStyle = CFS_POINT;
750 cf.ptCurrentPos.x = wx + context_ime->cursor_location.x;
751 cf.ptCurrentPos.y = wy + context_ime->cursor_location.y;
752 ImmSetCompositionWindow (himc, &cf);
754 ImmReleaseContext (hwnd, himc);
759 gtk_im_context_ime_set_use_preedit (GtkIMContext *context,
760 gboolean use_preedit)
762 GtkIMContextIME *context_ime;
764 g_return_if_fail (GTK_IS_IM_CONTEXT_IME (context));
765 context_ime = GTK_IM_CONTEXT_IME (context);
767 context_ime->use_preedit = use_preedit;
768 if (context_ime->preediting)
773 hwnd = GDK_WINDOW_HWND (context_ime->client_window);
774 himc = ImmGetContext (hwnd);
778 /* FIXME: What to do? */
780 ImmReleaseContext (hwnd, himc);
786 gtk_im_context_ime_set_preedit_font (GtkIMContext *context)
788 GtkIMContextIME *context_ime;
789 GtkWidget *widget = NULL;
792 HKL ime = GetKeyboardLayout (0);
795 PangoContext *pango_context;
799 g_return_if_fail (GTK_IS_IM_CONTEXT_IME (context));
801 context_ime = GTK_IM_CONTEXT_IME (context);
802 if (!context_ime->client_window)
805 gdk_window_get_user_data (context_ime->client_window, (gpointer) &widget);
806 if (!GTK_IS_WIDGET (widget))
809 hwnd = GDK_WINDOW_HWND (context_ime->client_window);
810 himc = ImmGetContext (hwnd);
815 pango_context = gtk_widget_get_pango_context (widget);
819 /* Try to make sure we use a font that actually can show the
820 * language in question.
823 switch (PRIMARYLANGID (LOWORD (ime)))
830 switch (SUBLANGID (LOWORD (ime)))
832 case SUBLANG_CHINESE_TRADITIONAL:
833 lang = "zh_TW"; break;
834 case SUBLANG_CHINESE_SIMPLIFIED:
835 lang = "zh_CN"; break;
836 case SUBLANG_CHINESE_HONGKONG:
837 lang = "zh_HK"; break;
838 case SUBLANG_CHINESE_SINGAPORE:
839 lang = "zh_SG"; break;
840 case SUBLANG_CHINESE_MACAU:
841 lang = "zh_MO"; break;
852 /* We know what language it is. Look for a character, any
853 * character, that language needs.
855 PangoLanguage *pango_lang = pango_language_from_string (lang);
856 PangoFontset *fontset =
857 pango_context_load_fontset (pango_context,
858 gtk_widget_get_style (widget)->font_desc,
861 g_utf8_to_ucs4 (pango_language_get_sample_string (pango_lang),
862 -1, NULL, NULL, NULL);
863 wc = 0x4E00; /* In all CJK languages? */
868 for (i = 0; sample[i]; i++)
869 if (g_unichar_iswide (sample[i]))
876 font = pango_fontset_get_font (fontset, wc);
877 g_object_unref (fontset);
880 font = pango_context_load_font (pango_context, gtk_widget_get_style (widget)->font_desc);
885 logfont = pango_win32_font_logfont (font);
887 ImmSetCompositionFont (himc, logfont);
889 g_object_unref (font);
893 ImmReleaseContext (hwnd, himc);
897 static GdkFilterReturn
898 gtk_im_context_ime_message_filter (GdkXEvent *xevent,
902 GtkIMContext *context;
903 GtkIMContextIME *context_ime;
906 MSG *msg = (MSG *) xevent;
907 GdkFilterReturn retval = GDK_FILTER_CONTINUE;
909 g_return_val_if_fail (GTK_IS_IM_CONTEXT_IME (data), retval);
911 context = GTK_IM_CONTEXT (data);
912 context_ime = GTK_IM_CONTEXT_IME (data);
913 if (!context_ime->focus)
916 hwnd = GDK_WINDOW_HWND (context_ime->client_window);
917 himc = ImmGetContext (hwnd);
921 switch (msg->message)
923 case WM_IME_COMPOSITION:
928 get_window_position (context_ime->client_window, &wx, &wy);
936 GDK_WINDOW_HWND (gdk_window_get_toplevel
937 (context_ime->client_window));
938 GetWindowRect (hwnd_top, &rc);
941 ClientToScreen (hwnd_top, &pt);
946 cf.dwStyle = CFS_CANDIDATEPOS;
947 cf.ptCurrentPos.x = wx + context_ime->cursor_location.x;
948 cf.ptCurrentPos.y = wy + context_ime->cursor_location.y
949 + context_ime->cursor_location.height;
950 ImmSetCandidateWindow (himc, &cf);
952 if ((msg->lParam & GCS_COMPSTR))
953 g_signal_emit_by_name (context, "preedit-changed");
955 if (msg->lParam & GCS_RESULTSTR)
958 gchar *utf8str = NULL;
959 GError *error = NULL;
961 len = ImmGetCompositionStringW (himc, GCS_RESULTSTR, NULL, 0);
965 gpointer buf = g_alloca (len);
966 ImmGetCompositionStringW (himc, GCS_RESULTSTR, buf, len);
968 utf8str = g_utf16_to_utf8 (buf, len, NULL, NULL, &error);
971 g_warning ("%s", error->message);
972 g_error_free (error);
978 g_signal_emit_by_name (context, "commit", utf8str);
984 if (context_ime->use_preedit)
989 case WM_IME_STARTCOMPOSITION:
990 context_ime->preediting = TRUE;
991 gtk_im_context_ime_set_cursor_location (context, NULL);
992 g_signal_emit_by_name (context, "preedit-start");
993 if (context_ime->use_preedit)
997 case WM_IME_ENDCOMPOSITION:
998 context_ime->preediting = FALSE;
999 g_signal_emit_by_name (context, "preedit-changed");
1000 g_signal_emit_by_name (context, "preedit-end");
1001 if (context_ime->use_preedit)
1006 switch (msg->wParam)
1008 case IMN_SETOPENSTATUS:
1009 context_ime->opened = ImmGetOpenStatus (himc);
1010 gtk_im_context_ime_set_preedit_font (context);
1021 ImmReleaseContext (hwnd, himc);
1027 * x and y must be initialized to 0.
1030 get_window_position (GdkWindow *win, gint *x, gint *y)
1032 GdkWindow *parent, *toplevel;
1035 g_return_if_fail (GDK_IS_WINDOW (win));
1036 g_return_if_fail (x && y);
1038 gdk_window_get_position (win, &wx, &wy);
1041 parent = gdk_window_get_parent (win);
1042 toplevel = gdk_window_get_toplevel (win);
1044 if (parent && parent != toplevel)
1045 get_window_position (parent, x, y);
1050 * probably, this handler isn't needed.
1053 cb_client_widget_hierarchy_changed (GtkWidget *widget,
1055 GtkIMContextIME *context_ime)
1057 GdkWindow *new_toplevel;
1059 g_return_if_fail (GTK_IS_WIDGET (widget));
1060 g_return_if_fail (GTK_IS_IM_CONTEXT_IME (context_ime));
1062 if (!context_ime->client_window)
1064 if (!context_ime->focus)
1067 new_toplevel = gdk_window_get_toplevel (context_ime->client_window);
1068 if (context_ime->toplevel == new_toplevel)
1071 /* remove filter from old toplevel */
1072 if (GDK_IS_WINDOW (context_ime->toplevel))
1074 gdk_window_remove_filter (context_ime->toplevel,
1075 gtk_im_context_ime_message_filter,
1082 /* add filter to new toplevel */
1083 if (GDK_IS_WINDOW (new_toplevel))
1085 gdk_window_add_filter (new_toplevel,
1086 gtk_im_context_ime_message_filter, context_ime);
1092 context_ime->toplevel = new_toplevel;