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 #include "gtkimcontextime.h"
30 #include "imm-extra.h"
32 #include "gdk/win32/gdkwin32.h"
33 #include "gdk/gdkkeysyms.h"
34 #include "gtk/gtkwidget.h"
36 #include <pango/pango.h>
41 # include <pango/pangowin32.h>
46 # include <pango/pangowin32.h>
49 /* #define BUFSIZE 4096 */
51 #define FREE_PREEDIT_BUFFER(ctx) \
53 g_free((ctx)->priv->comp_str); \
54 g_free((ctx)->priv->read_str); \
55 (ctx)->priv->comp_str = NULL; \
56 (ctx)->priv->read_str = NULL; \
57 (ctx)->priv->comp_str_len = 0; \
58 (ctx)->priv->read_str_len = 0; \
62 struct _GtkIMContextIMEPrivate
64 /* save IME context when the client window is focused out */
65 DWORD conversion_mode;
75 /* GObject class methods */
76 static void gtk_im_context_ime_class_init (GtkIMContextIMEClass *class);
77 static void gtk_im_context_ime_init (GtkIMContextIME *context_ime);
78 static void gtk_im_context_ime_dispose (GObject *obj);
79 static void gtk_im_context_ime_finalize (GObject *obj);
81 static void gtk_im_context_ime_set_property (GObject *object,
85 static void gtk_im_context_ime_get_property (GObject *object,
90 /* GtkIMContext's virtual functions */
91 static void gtk_im_context_ime_set_client_window (GtkIMContext *context,
92 GdkWindow *client_window);
93 static gboolean gtk_im_context_ime_filter_keypress (GtkIMContext *context,
95 static void gtk_im_context_ime_reset (GtkIMContext *context);
96 static void gtk_im_context_ime_get_preedit_string (GtkIMContext *context,
98 PangoAttrList **attrs,
100 static void gtk_im_context_ime_focus_in (GtkIMContext *context);
101 static void gtk_im_context_ime_focus_out (GtkIMContext *context);
102 static void gtk_im_context_ime_set_cursor_location (GtkIMContext *context,
104 static void gtk_im_context_ime_set_use_preedit (GtkIMContext *context,
105 gboolean use_preedit);
107 /* GtkIMContextIME's private functions */
108 static void gtk_im_context_ime_set_preedit_font (GtkIMContext *context);
110 static GdkFilterReturn
111 gtk_im_context_ime_message_filter (GdkXEvent *xevent,
114 static void get_window_position (GdkWindow *win,
117 static void cb_client_widget_hierarchy_changed (GtkWidget *widget,
119 GtkIMContextIME *context_ime);
121 GType gtk_type_im_context_ime = 0;
122 static GObjectClass *parent_class;
126 gtk_im_context_ime_register_type (GTypeModule *type_module)
128 static const GTypeInfo im_context_ime_info = {
129 sizeof (GtkIMContextIMEClass),
130 (GBaseInitFunc) NULL,
131 (GBaseFinalizeFunc) NULL,
132 (GClassInitFunc) gtk_im_context_ime_class_init,
133 NULL, /* class_finalize */
134 NULL, /* class_data */
135 sizeof (GtkIMContextIME),
137 (GInstanceInitFunc) gtk_im_context_ime_init,
140 gtk_type_im_context_ime =
141 g_type_module_register_type (type_module,
143 "GtkIMContextIME", &im_context_ime_info, 0);
147 gtk_im_context_ime_class_init (GtkIMContextIMEClass *class)
149 GtkIMContextClass *im_context_class = GTK_IM_CONTEXT_CLASS (class);
150 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
152 parent_class = g_type_class_peek_parent (class);
154 gobject_class->finalize = gtk_im_context_ime_finalize;
155 gobject_class->dispose = gtk_im_context_ime_dispose;
156 gobject_class->set_property = gtk_im_context_ime_set_property;
157 gobject_class->get_property = gtk_im_context_ime_get_property;
159 im_context_class->set_client_window = gtk_im_context_ime_set_client_window;
160 im_context_class->filter_keypress = gtk_im_context_ime_filter_keypress;
161 im_context_class->reset = gtk_im_context_ime_reset;
162 im_context_class->get_preedit_string = gtk_im_context_ime_get_preedit_string;
163 im_context_class->focus_in = gtk_im_context_ime_focus_in;
164 im_context_class->focus_out = gtk_im_context_ime_focus_out;
165 im_context_class->set_cursor_location = gtk_im_context_ime_set_cursor_location;
166 im_context_class->set_use_preedit = gtk_im_context_ime_set_use_preedit;
171 gtk_im_context_ime_init (GtkIMContextIME *context_ime)
173 context_ime->client_window = NULL;
174 context_ime->toplevel = NULL;
175 context_ime->use_preedit = TRUE;
176 context_ime->preediting = FALSE;
177 context_ime->opened = FALSE;
178 context_ime->focus = FALSE;
179 context_ime->cursor_location.x = 0;
180 context_ime->cursor_location.y = 0;
181 context_ime->cursor_location.width = 0;
182 context_ime->cursor_location.height = 0;
184 context_ime->priv = g_malloc0 (sizeof (GtkIMContextIMEPrivate));
185 context_ime->priv->conversion_mode = 0;
186 context_ime->priv->sentence_mode = 0;
187 context_ime->priv->comp_str = NULL;
188 context_ime->priv->comp_str_len = 0;
189 context_ime->priv->read_str = NULL;
190 context_ime->priv->read_str_len = 0;
195 gtk_im_context_ime_dispose (GObject *obj)
197 GtkIMContext *context = GTK_IM_CONTEXT (obj);
198 GtkIMContextIME *context_ime = GTK_IM_CONTEXT_IME (obj);
200 if (context_ime->client_window)
201 gtk_im_context_ime_set_client_window (context, NULL);
203 FREE_PREEDIT_BUFFER (context_ime);
205 if (G_OBJECT_CLASS (parent_class)->dispose)
206 G_OBJECT_CLASS (parent_class)->dispose (obj);
211 gtk_im_context_ime_finalize (GObject *obj)
213 /* GtkIMContext *context = GTK_IM_CONTEXT (obj); */
214 GtkIMContextIME *context_ime = GTK_IM_CONTEXT_IME (obj);
216 g_free (context_ime->priv);
217 context_ime->priv = NULL;
219 if (G_OBJECT_CLASS (parent_class)->finalize)
220 G_OBJECT_CLASS (parent_class)->finalize (obj);
225 gtk_im_context_ime_set_property (GObject *object,
230 GtkIMContextIME *context_ime = GTK_IM_CONTEXT_IME (object);
232 g_return_if_fail (GTK_IS_IM_CONTEXT_IME (context_ime));
243 gtk_im_context_ime_get_property (GObject *object,
248 GtkIMContextIME *context_ime = GTK_IM_CONTEXT_IME (object);
250 g_return_if_fail (GTK_IS_IM_CONTEXT_IME (context_ime));
261 gtk_im_context_ime_new (void)
263 return g_object_new (GTK_TYPE_IM_CONTEXT_IME, NULL);
268 gtk_im_context_ime_set_client_window (GtkIMContext *context,
269 GdkWindow *client_window)
271 GtkIMContextIME *context_ime;
273 g_return_if_fail (GTK_IS_IM_CONTEXT_IME (context));
274 context_ime = GTK_IM_CONTEXT_IME (context);
281 hwnd = GDK_WINDOW_HWND (client_window);
282 himc = ImmGetContext (hwnd);
285 context_ime->opened = ImmGetOpenStatus (himc);
286 ImmGetConversionStatus (himc,
287 &context_ime->priv->conversion_mode,
288 &context_ime->priv->sentence_mode);
289 ImmReleaseContext (hwnd, himc);
292 else if (context_ime->focus)
294 gtk_im_context_ime_focus_out (context);
297 context_ime->client_window = client_window;
302 gtk_im_context_ime_filter_keypress (GtkIMContext *context,
305 GtkIMContextIME *context_ime;
306 gboolean retval = FALSE;
309 g_return_val_if_fail (GTK_IS_IM_CONTEXT_IME (context), FALSE);
310 g_return_val_if_fail (event, FALSE);
312 if (event->type == GDK_KEY_RELEASE)
315 if (event->state & GDK_CONTROL_MASK)
318 context_ime = GTK_IM_CONTEXT_IME (context);
320 if (!context_ime->focus)
323 if (!GDK_IS_WINDOW (context_ime->client_window))
326 c = gdk_keyval_to_unicode (event->keyval);
330 int len = g_unichar_to_utf8 (c, utf8);
333 g_signal_emit_by_name (context_ime, "commit", utf8);
342 gtk_im_context_ime_reset (GtkIMContext *context)
344 GtkIMContextIME *context_ime = GTK_IM_CONTEXT_IME (context);
348 hwnd = GDK_WINDOW_HWND (context_ime->client_window);
349 himc = ImmGetContext (hwnd);
353 if (context_ime->preediting && ImmGetOpenStatus (himc))
354 ImmNotifyIME (himc, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
356 context_ime->preediting = FALSE;
357 g_signal_emit_by_name (context, "preedit_changed");
359 ImmReleaseContext (hwnd, himc);
364 get_utf8_preedit_string (GtkIMContextIME *context_ime, gint *pos_ret)
366 gchar *utf8str = NULL;
374 hwnd = GDK_WINDOW_HWND (context_ime->client_window);
375 himc = ImmGetContext (hwnd);
377 return g_strdup ("");
379 if (context_ime->preediting)
383 len = ImmGetCompositionStringW (himc, GCS_COMPSTR, NULL, 0);
386 GError *error = NULL;
387 gpointer buf = g_alloca (len);
389 ImmGetCompositionStringW (himc, GCS_COMPSTR, buf, len);
391 utf8str = g_utf16_to_utf8 (buf, len, NULL, NULL, &error);
394 g_warning ("%s", error->message);
395 g_error_free (error);
400 pos = ImmGetCompositionStringW (himc, GCS_CURSORPOS, NULL, 0);
401 if (pos < 0 || len < pos)
403 g_warning ("ImmGetCompositionString: "
404 "Invalid cursor position!");
413 utf8str = g_strdup ("");
420 ImmReleaseContext (hwnd, himc);
426 static PangoAttrList *
427 get_pango_attr_list (GtkIMContextIME *context_ime, const gchar *utf8str)
429 PangoAttrList *attrs = pango_attr_list_new ();
433 hwnd = GDK_WINDOW_HWND (context_ime->client_window);
434 himc = ImmGetContext (hwnd);
438 if (context_ime->preediting)
440 const gchar *schr = utf8str, *echr;
442 guint16 f_red, f_green, f_blue, b_red, b_green, b_blue;
443 glong len, spos = 0, epos, sidx = 0, eidx;
444 PangoAttribute *attr;
447 * get attributes list of IME.
449 len = ImmGetCompositionStringW (himc, GCS_COMPATTR, NULL, 0);
450 buf = g_alloca (len);
451 ImmGetCompositionStringW (himc, GCS_COMPATTR, buf, len);
454 * schr and echr are pointer in utf8str.
456 for (echr = g_utf8_next_char (utf8str); *schr != '\0';
457 echr = g_utf8_next_char (echr))
460 * spos and epos are buf(attributes list of IME) position by
462 * Using the wide-char API, this value is same with UTF-8 offset.
464 epos = g_utf8_pointer_to_offset (utf8str, echr);
467 * sidx and eidx are positions in utf8str by bytes.
469 eidx = echr - utf8str;
472 * convert attributes list to PangoAttriute.
474 if (*echr == '\0' || buf[spos] != buf[epos])
478 case ATTR_TARGET_CONVERTED:
479 attr = pango_attr_underline_new (PANGO_UNDERLINE_DOUBLE);
480 attr->start_index = sidx;
481 attr->end_index = eidx;
482 pango_attr_list_change (attrs, attr);
483 f_red = f_green = f_blue = 0;
484 b_red = b_green = b_blue = 0xffff;
486 case ATTR_TARGET_NOTCONVERTED:
487 f_red = f_green = f_blue = 0xffff;
488 b_red = b_green = b_blue = 0;
490 case ATTR_INPUT_ERROR:
491 f_red = f_green = f_blue = 0;
492 b_red = b_green = b_blue = 0x7fff;
494 default: /* ATTR_INPUT,ATTR_CONVERTED,ATTR_FIXEDCONVERTED */
495 attr = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE);
496 attr->start_index = sidx;
497 attr->end_index = eidx;
498 pango_attr_list_change (attrs, attr);
499 f_red = f_green = f_blue = 0;
500 b_red = b_green = b_blue = 0xffff;
502 attr = pango_attr_foreground_new (f_red, f_green, f_blue);
503 attr->start_index = sidx;
504 attr->end_index = eidx;
505 pango_attr_list_change (attrs, attr);
506 attr = pango_attr_background_new (b_red, b_green, b_blue);
507 attr->start_index = sidx;
508 attr->end_index = eidx;
509 pango_attr_list_change (attrs, attr);
518 ImmReleaseContext (hwnd, himc);
525 gtk_im_context_ime_get_preedit_string (GtkIMContext *context,
527 PangoAttrList **attrs,
530 gchar *utf8str = NULL;
532 GtkIMContextIME *context_ime;
534 context_ime = GTK_IM_CONTEXT_IME (context);
536 utf8str = get_utf8_preedit_string (context_ime, &pos);
539 *attrs = get_pango_attr_list (context_ime, utf8str);
557 gtk_im_context_ime_focus_in (GtkIMContext *context)
559 GtkIMContextIME *context_ime = GTK_IM_CONTEXT_IME (context);
561 GtkWidget *widget = NULL;
565 if (!GDK_IS_WINDOW (context_ime->client_window))
568 /* swtich current context */
569 context_ime->focus = TRUE;
571 hwnd = GDK_WINDOW_HWND (context_ime->client_window);
572 himc = ImmGetContext (hwnd);
576 toplevel = gdk_window_get_toplevel (context_ime->client_window);
577 if (GDK_IS_WINDOW (toplevel))
579 gdk_window_add_filter (toplevel,
580 gtk_im_context_ime_message_filter, context_ime);
581 top_hwnd = GDK_WINDOW_HWND (toplevel);
583 context_ime->toplevel = toplevel;
587 g_warning ("gtk_im_context_ime_focus_in(): "
588 "cannot find toplevel window.");
592 /* trace reparenting (probably no need) */
593 gdk_window_get_user_data (context_ime->client_window, (gpointer) & widget);
594 if (GTK_IS_WIDGET (widget))
596 g_signal_connect (widget, "hierarchy-changed",
597 G_CALLBACK (cb_client_widget_hierarchy_changed),
605 /* restore preedit context */
606 ImmSetConversionStatus (himc,
607 context_ime->priv->conversion_mode,
608 context_ime->priv->sentence_mode);
610 if (context_ime->opened)
612 if (!ImmGetOpenStatus (himc))
613 ImmSetOpenStatus (himc, TRUE);
614 if (context_ime->preediting)
616 ImmSetCompositionStringW (himc,
618 context_ime->priv->comp_str,
619 context_ime->priv->comp_str_len, NULL, 0);
620 FREE_PREEDIT_BUFFER (context_ime);
625 ImmReleaseContext (hwnd, himc);
630 gtk_im_context_ime_focus_out (GtkIMContext *context)
632 GtkIMContextIME *context_ime = GTK_IM_CONTEXT_IME (context);
634 GtkWidget *widget = NULL;
638 if (!GDK_IS_WINDOW (context_ime->client_window))
641 /* swtich current context */
642 context_ime->focus = FALSE;
644 hwnd = GDK_WINDOW_HWND (context_ime->client_window);
645 himc = ImmGetContext (hwnd);
649 /* save preedit context */
650 ImmGetConversionStatus (himc,
651 &context_ime->priv->conversion_mode,
652 &context_ime->priv->sentence_mode);
654 if (ImmGetOpenStatus (himc))
656 gboolean preediting = context_ime->preediting;
660 FREE_PREEDIT_BUFFER (context_ime);
662 context_ime->priv->comp_str_len
663 = ImmGetCompositionStringW (himc, GCS_COMPSTR, NULL, 0);
664 context_ime->priv->comp_str
665 = g_malloc (context_ime->priv->comp_str_len);
666 ImmGetCompositionStringW (himc, GCS_COMPSTR,
667 context_ime->priv->comp_str,
668 context_ime->priv->comp_str_len);
670 context_ime->priv->read_str_len
671 = ImmGetCompositionStringW (himc, GCS_COMPREADSTR, NULL, 0);
672 context_ime->priv->read_str
673 = g_malloc (context_ime->priv->read_str_len);
674 ImmGetCompositionStringW (himc, GCS_COMPREADSTR,
675 context_ime->priv->read_str,
676 context_ime->priv->read_str_len);
679 ImmSetOpenStatus (himc, FALSE);
681 context_ime->opened = TRUE;
682 context_ime->preediting = preediting;
686 context_ime->opened = FALSE;
687 context_ime->preediting = FALSE;
690 /* remove signal handler */
691 gdk_window_get_user_data (context_ime->client_window, (gpointer) & widget);
692 if (GTK_IS_WIDGET (widget))
694 g_signal_handlers_disconnect_by_func
696 G_CALLBACK (cb_client_widget_hierarchy_changed), context_ime);
699 /* remove event fileter */
700 toplevel = gdk_window_get_toplevel (context_ime->client_window);
701 if (GDK_IS_WINDOW (toplevel))
703 gdk_window_remove_filter (toplevel,
704 gtk_im_context_ime_message_filter,
706 top_hwnd = GDK_WINDOW_HWND (toplevel);
708 context_ime->toplevel = NULL;
712 g_warning ("gtk_im_context_ime_focus_out(): "
713 "cannot find toplevel window.");
717 ImmReleaseContext (hwnd, himc);
722 gtk_im_context_ime_set_cursor_location (GtkIMContext *context,
726 GtkIMContextIME *context_ime;
731 g_return_if_fail (GTK_IS_IM_CONTEXT_IME (context));
733 context_ime = GTK_IM_CONTEXT_IME (context);
735 context_ime->cursor_location = *area;
737 if (!context_ime->client_window)
740 hwnd = GDK_WINDOW_HWND (context_ime->client_window);
741 himc = ImmGetContext (hwnd);
745 get_window_position (context_ime->client_window, &wx, &wy);
746 cf.dwStyle = CFS_POINT;
747 cf.ptCurrentPos.x = wx + context_ime->cursor_location.x;
748 cf.ptCurrentPos.y = wy + context_ime->cursor_location.y;
749 ImmSetCompositionWindow (himc, &cf);
751 ImmReleaseContext (hwnd, himc);
756 gtk_im_context_ime_set_use_preedit (GtkIMContext *context,
757 gboolean use_preedit)
759 GtkIMContextIME *context_ime;
761 g_return_if_fail (GTK_IS_IM_CONTEXT_IME (context));
762 context_ime = GTK_IM_CONTEXT_IME (context);
764 context_ime->use_preedit = use_preedit;
765 if (context_ime->preediting)
770 hwnd = GDK_WINDOW_HWND (context_ime->client_window);
771 himc = ImmGetContext (hwnd);
775 /* FIXME: What to do? */
777 ImmReleaseContext (hwnd, himc);
783 gtk_im_context_ime_set_preedit_font (GtkIMContext *context)
785 GtkIMContextIME *context_ime;
786 GtkWidget *widget = NULL;
789 HKL ime = GetKeyboardLayout (0);
792 PangoContext *pango_context;
796 g_return_if_fail (GTK_IS_IM_CONTEXT_IME (context));
798 context_ime = GTK_IM_CONTEXT_IME (context);
799 if (!context_ime->client_window)
802 gdk_window_get_user_data (context_ime->client_window, (gpointer) &widget);
803 if (!GTK_IS_WIDGET (widget))
806 hwnd = GDK_WINDOW_HWND (context_ime->client_window);
807 himc = ImmGetContext (hwnd);
812 pango_context = gtk_widget_get_pango_context (widget);
816 /* Try to make sure we use a font that actually can show the
817 * language in question.
820 switch (PRIMARYLANGID (LOWORD (ime)))
827 switch (SUBLANGID (LOWORD (ime)))
829 case SUBLANG_CHINESE_TRADITIONAL:
830 lang = "zh_TW"; break;
831 case SUBLANG_CHINESE_SIMPLIFIED:
832 lang = "zh_CN"; break;
833 case SUBLANG_CHINESE_HONGKONG:
834 lang = "zh_HK"; break;
835 case SUBLANG_CHINESE_SINGAPORE:
836 lang = "zh_SG"; break;
837 case SUBLANG_CHINESE_MACAU:
838 lang = "zh_MO"; break;
849 /* We know what language it is. Look for a character, any
850 * character, that language needs.
852 PangoLanguage *pango_lang = pango_language_from_string (lang);
853 PangoFontset *fontset =
854 pango_context_load_fontset (pango_context,
855 widget->style->font_desc,
858 g_utf8_to_ucs4 (pango_language_get_sample_string (pango_lang),
859 -1, NULL, NULL, NULL);
860 wc = 0x4E00; /* In all CJK languages? */
865 for (i = 0; sample[i]; i++)
866 if (g_unichar_iswide (sample[i]))
873 font = pango_fontset_get_font (fontset, wc);
874 g_object_unref (fontset);
877 font = pango_context_load_font (pango_context, widget->style->font_desc);
882 logfont = pango_win32_font_logfont (font);
884 ImmSetCompositionFont (himc, logfont);
886 g_object_unref (font);
890 ImmReleaseContext (hwnd, himc);
894 static GdkFilterReturn
895 gtk_im_context_ime_message_filter (GdkXEvent *xevent,
899 GtkIMContext *context;
900 GtkIMContextIME *context_ime;
903 MSG *msg = (MSG *) xevent;
904 GdkFilterReturn retval = GDK_FILTER_CONTINUE;
906 g_return_val_if_fail (GTK_IS_IM_CONTEXT_IME (data), retval);
908 context = GTK_IM_CONTEXT (data);
909 context_ime = GTK_IM_CONTEXT_IME (data);
910 if (!context_ime->focus)
913 hwnd = GDK_WINDOW_HWND (context_ime->client_window);
914 himc = ImmGetContext (hwnd);
918 switch (msg->message)
920 case WM_IME_COMPOSITION:
925 get_window_position (context_ime->client_window, &wx, &wy);
933 GDK_WINDOW_HWND (gdk_window_get_toplevel
934 (context_ime->client_window));
935 GetWindowRect (hwnd_top, &rc);
938 ClientToScreen (hwnd_top, &pt);
943 cf.dwStyle = CFS_CANDIDATEPOS;
944 cf.ptCurrentPos.x = wx + context_ime->cursor_location.x;
945 cf.ptCurrentPos.y = wy + context_ime->cursor_location.y
946 + context_ime->cursor_location.height;
947 ImmSetCandidateWindow (himc, &cf);
949 if ((msg->lParam & GCS_COMPSTR))
950 g_signal_emit_by_name (context, "preedit_changed");
952 if (msg->lParam & GCS_RESULTSTR)
955 gchar *utf8str = NULL;
956 GError *error = NULL;
958 len = ImmGetCompositionStringW (himc, GCS_RESULTSTR, NULL, 0);
962 gpointer buf = g_alloca (len);
963 ImmGetCompositionStringW (himc, GCS_RESULTSTR, buf, len);
965 utf8str = g_utf16_to_utf8 (buf, len, NULL, NULL, &error);
968 g_warning ("%s", error->message);
969 g_error_free (error);
975 g_signal_emit_by_name (context, "commit", utf8str);
981 if (context_ime->use_preedit)
986 case WM_IME_STARTCOMPOSITION:
987 context_ime->preediting = TRUE;
988 gtk_im_context_ime_set_cursor_location (context, NULL);
989 g_signal_emit_by_name (context, "preedit_start");
990 if (context_ime->use_preedit)
994 case WM_IME_ENDCOMPOSITION:
995 context_ime->preediting = FALSE;
996 g_signal_emit_by_name (context, "preedit_changed");
997 g_signal_emit_by_name (context, "preedit_end");
998 if (context_ime->use_preedit)
1003 switch (msg->wParam)
1005 case IMN_SETOPENSTATUS:
1006 context_ime->opened = ImmGetOpenStatus (himc);
1007 gtk_im_context_ime_set_preedit_font (context);
1018 ImmReleaseContext (hwnd, himc);
1024 * x and y must be initialized to 0.
1027 get_window_position (GdkWindow *win, gint *x, gint *y)
1029 GdkWindow *parent, *toplevel;
1032 g_return_if_fail (GDK_IS_WINDOW (win));
1033 g_return_if_fail (x && y);
1035 gdk_window_get_position (win, &wx, &wy);
1038 parent = gdk_window_get_parent (win);
1039 toplevel = gdk_window_get_toplevel (win);
1041 if (parent && parent != toplevel)
1042 get_window_position (parent, x, y);
1047 * probably, this handler isn't needed.
1050 cb_client_widget_hierarchy_changed (GtkWidget *widget,
1052 GtkIMContextIME *context_ime)
1054 GdkWindow *new_toplevel;
1056 g_return_if_fail (GTK_IS_WIDGET (widget));
1057 g_return_if_fail (GTK_IS_IM_CONTEXT_IME (context_ime));
1059 if (!context_ime->client_window)
1061 if (!context_ime->focus)
1064 new_toplevel = gdk_window_get_toplevel (context_ime->client_window);
1065 if (context_ime->toplevel == new_toplevel)
1068 /* remove filter from old toplevel */
1069 if (GDK_IS_WINDOW (context_ime->toplevel))
1071 gdk_window_remove_filter (context_ime->toplevel,
1072 gtk_im_context_ime_message_filter,
1079 /* add filter to new toplevel */
1080 if (GDK_IS_WINDOW (new_toplevel))
1082 gdk_window_add_filter (new_toplevel,
1083 gtk_im_context_ime_message_filter, context_ime);
1089 context_ime->toplevel = new_toplevel;