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 if (!context_ime->client_window)
354 hwnd = GDK_WINDOW_HWND (context_ime->client_window);
355 himc = ImmGetContext (hwnd);
359 if (context_ime->preediting && ImmGetOpenStatus (himc))
360 ImmNotifyIME (himc, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
362 context_ime->preediting = FALSE;
363 g_signal_emit_by_name (context, "preedit-changed");
365 ImmReleaseContext (hwnd, himc);
370 get_utf8_preedit_string (GtkIMContextIME *context_ime, gint *pos_ret)
372 gchar *utf8str = NULL;
380 hwnd = GDK_WINDOW_HWND (context_ime->client_window);
381 himc = ImmGetContext (hwnd);
383 return g_strdup ("");
385 if (context_ime->preediting)
389 len = ImmGetCompositionStringW (himc, GCS_COMPSTR, NULL, 0);
392 GError *error = NULL;
393 gpointer buf = g_alloca (len);
395 ImmGetCompositionStringW (himc, GCS_COMPSTR, buf, len);
397 utf8str = g_utf16_to_utf8 (buf, len, NULL, NULL, &error);
400 g_warning ("%s", error->message);
401 g_error_free (error);
406 pos = ImmGetCompositionStringW (himc, GCS_CURSORPOS, NULL, 0);
407 if (pos < 0 || len < pos)
409 g_warning ("ImmGetCompositionString: "
410 "Invalid cursor position!");
419 utf8str = g_strdup ("");
426 ImmReleaseContext (hwnd, himc);
432 static PangoAttrList *
433 get_pango_attr_list (GtkIMContextIME *context_ime, const gchar *utf8str)
435 PangoAttrList *attrs = pango_attr_list_new ();
439 hwnd = GDK_WINDOW_HWND (context_ime->client_window);
440 himc = ImmGetContext (hwnd);
444 if (context_ime->preediting)
446 const gchar *schr = utf8str, *echr;
448 guint16 f_red, f_green, f_blue, b_red, b_green, b_blue;
449 glong len, spos = 0, epos, sidx = 0, eidx;
450 PangoAttribute *attr;
453 * get attributes list of IME.
455 len = ImmGetCompositionStringW (himc, GCS_COMPATTR, NULL, 0);
456 buf = g_alloca (len);
457 ImmGetCompositionStringW (himc, GCS_COMPATTR, buf, len);
460 * schr and echr are pointer in utf8str.
462 for (echr = g_utf8_next_char (utf8str); *schr != '\0';
463 echr = g_utf8_next_char (echr))
466 * spos and epos are buf(attributes list of IME) position by
468 * Using the wide-char API, this value is same with UTF-8 offset.
470 epos = g_utf8_pointer_to_offset (utf8str, echr);
473 * sidx and eidx are positions in utf8str by bytes.
475 eidx = echr - utf8str;
478 * convert attributes list to PangoAttriute.
480 if (*echr == '\0' || buf[spos] != buf[epos])
484 case ATTR_TARGET_CONVERTED:
485 attr = pango_attr_underline_new (PANGO_UNDERLINE_DOUBLE);
486 attr->start_index = sidx;
487 attr->end_index = eidx;
488 pango_attr_list_change (attrs, attr);
489 f_red = f_green = f_blue = 0;
490 b_red = b_green = b_blue = 0xffff;
492 case ATTR_TARGET_NOTCONVERTED:
493 f_red = f_green = f_blue = 0xffff;
494 b_red = b_green = b_blue = 0;
496 case ATTR_INPUT_ERROR:
497 f_red = f_green = f_blue = 0;
498 b_red = b_green = b_blue = 0x7fff;
500 default: /* ATTR_INPUT,ATTR_CONVERTED,ATTR_FIXEDCONVERTED */
501 attr = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE);
502 attr->start_index = sidx;
503 attr->end_index = eidx;
504 pango_attr_list_change (attrs, attr);
505 f_red = f_green = f_blue = 0;
506 b_red = b_green = b_blue = 0xffff;
508 attr = pango_attr_foreground_new (f_red, f_green, f_blue);
509 attr->start_index = sidx;
510 attr->end_index = eidx;
511 pango_attr_list_change (attrs, attr);
512 attr = pango_attr_background_new (b_red, b_green, b_blue);
513 attr->start_index = sidx;
514 attr->end_index = eidx;
515 pango_attr_list_change (attrs, attr);
524 ImmReleaseContext (hwnd, himc);
531 gtk_im_context_ime_get_preedit_string (GtkIMContext *context,
533 PangoAttrList **attrs,
536 gchar *utf8str = NULL;
538 GtkIMContextIME *context_ime;
540 context_ime = GTK_IM_CONTEXT_IME (context);
542 utf8str = get_utf8_preedit_string (context_ime, &pos);
545 *attrs = get_pango_attr_list (context_ime, utf8str);
563 gtk_im_context_ime_focus_in (GtkIMContext *context)
565 GtkIMContextIME *context_ime = GTK_IM_CONTEXT_IME (context);
567 GtkWidget *widget = NULL;
571 if (!GDK_IS_WINDOW (context_ime->client_window))
574 /* swtich current context */
575 context_ime->focus = TRUE;
577 hwnd = GDK_WINDOW_HWND (context_ime->client_window);
578 himc = ImmGetContext (hwnd);
582 toplevel = gdk_window_get_toplevel (context_ime->client_window);
583 if (GDK_IS_WINDOW (toplevel))
585 gdk_window_add_filter (toplevel,
586 gtk_im_context_ime_message_filter, context_ime);
587 top_hwnd = GDK_WINDOW_HWND (toplevel);
589 context_ime->toplevel = toplevel;
593 g_warning ("gtk_im_context_ime_focus_in(): "
594 "cannot find toplevel window.");
598 /* trace reparenting (probably no need) */
599 gdk_window_get_user_data (context_ime->client_window, (gpointer) & widget);
600 if (GTK_IS_WIDGET (widget))
602 g_signal_connect (widget, "hierarchy-changed",
603 G_CALLBACK (cb_client_widget_hierarchy_changed),
611 /* restore preedit context */
612 ImmSetConversionStatus (himc,
613 context_ime->priv->conversion_mode,
614 context_ime->priv->sentence_mode);
616 if (context_ime->opened)
618 if (!ImmGetOpenStatus (himc))
619 ImmSetOpenStatus (himc, TRUE);
620 if (context_ime->preediting)
622 ImmSetCompositionStringW (himc,
624 context_ime->priv->comp_str,
625 context_ime->priv->comp_str_len, NULL, 0);
626 FREE_PREEDIT_BUFFER (context_ime);
631 ImmReleaseContext (hwnd, himc);
636 gtk_im_context_ime_focus_out (GtkIMContext *context)
638 GtkIMContextIME *context_ime = GTK_IM_CONTEXT_IME (context);
640 GtkWidget *widget = NULL;
644 if (!GDK_IS_WINDOW (context_ime->client_window))
647 /* swtich current context */
648 context_ime->focus = FALSE;
650 hwnd = GDK_WINDOW_HWND (context_ime->client_window);
651 himc = ImmGetContext (hwnd);
655 /* save preedit context */
656 ImmGetConversionStatus (himc,
657 &context_ime->priv->conversion_mode,
658 &context_ime->priv->sentence_mode);
660 if (ImmGetOpenStatus (himc))
662 gboolean preediting = context_ime->preediting;
666 FREE_PREEDIT_BUFFER (context_ime);
668 context_ime->priv->comp_str_len
669 = ImmGetCompositionStringW (himc, GCS_COMPSTR, NULL, 0);
670 context_ime->priv->comp_str
671 = g_malloc (context_ime->priv->comp_str_len);
672 ImmGetCompositionStringW (himc, GCS_COMPSTR,
673 context_ime->priv->comp_str,
674 context_ime->priv->comp_str_len);
676 context_ime->priv->read_str_len
677 = ImmGetCompositionStringW (himc, GCS_COMPREADSTR, NULL, 0);
678 context_ime->priv->read_str
679 = g_malloc (context_ime->priv->read_str_len);
680 ImmGetCompositionStringW (himc, GCS_COMPREADSTR,
681 context_ime->priv->read_str,
682 context_ime->priv->read_str_len);
685 ImmSetOpenStatus (himc, FALSE);
687 context_ime->opened = TRUE;
688 context_ime->preediting = preediting;
692 context_ime->opened = FALSE;
693 context_ime->preediting = FALSE;
696 /* remove signal handler */
697 gdk_window_get_user_data (context_ime->client_window, (gpointer) & widget);
698 if (GTK_IS_WIDGET (widget))
700 g_signal_handlers_disconnect_by_func
702 G_CALLBACK (cb_client_widget_hierarchy_changed), context_ime);
705 /* remove event fileter */
706 toplevel = gdk_window_get_toplevel (context_ime->client_window);
707 if (GDK_IS_WINDOW (toplevel))
709 gdk_window_remove_filter (toplevel,
710 gtk_im_context_ime_message_filter,
712 top_hwnd = GDK_WINDOW_HWND (toplevel);
714 context_ime->toplevel = NULL;
718 g_warning ("gtk_im_context_ime_focus_out(): "
719 "cannot find toplevel window.");
723 ImmReleaseContext (hwnd, himc);
728 gtk_im_context_ime_set_cursor_location (GtkIMContext *context,
732 GtkIMContextIME *context_ime;
737 g_return_if_fail (GTK_IS_IM_CONTEXT_IME (context));
739 context_ime = GTK_IM_CONTEXT_IME (context);
741 context_ime->cursor_location = *area;
743 if (!context_ime->client_window)
746 hwnd = GDK_WINDOW_HWND (context_ime->client_window);
747 himc = ImmGetContext (hwnd);
751 get_window_position (context_ime->client_window, &wx, &wy);
752 cf.dwStyle = CFS_POINT;
753 cf.ptCurrentPos.x = wx + context_ime->cursor_location.x;
754 cf.ptCurrentPos.y = wy + context_ime->cursor_location.y;
755 ImmSetCompositionWindow (himc, &cf);
757 ImmReleaseContext (hwnd, himc);
762 gtk_im_context_ime_set_use_preedit (GtkIMContext *context,
763 gboolean use_preedit)
765 GtkIMContextIME *context_ime;
767 g_return_if_fail (GTK_IS_IM_CONTEXT_IME (context));
768 context_ime = GTK_IM_CONTEXT_IME (context);
770 context_ime->use_preedit = use_preedit;
771 if (context_ime->preediting)
776 hwnd = GDK_WINDOW_HWND (context_ime->client_window);
777 himc = ImmGetContext (hwnd);
781 /* FIXME: What to do? */
783 ImmReleaseContext (hwnd, himc);
789 gtk_im_context_ime_set_preedit_font (GtkIMContext *context)
791 GtkIMContextIME *context_ime;
792 GtkWidget *widget = NULL;
795 HKL ime = GetKeyboardLayout (0);
798 PangoContext *pango_context;
802 g_return_if_fail (GTK_IS_IM_CONTEXT_IME (context));
804 context_ime = GTK_IM_CONTEXT_IME (context);
805 if (!context_ime->client_window)
808 gdk_window_get_user_data (context_ime->client_window, (gpointer) &widget);
809 if (!GTK_IS_WIDGET (widget))
812 hwnd = GDK_WINDOW_HWND (context_ime->client_window);
813 himc = ImmGetContext (hwnd);
818 pango_context = gtk_widget_get_pango_context (widget);
822 /* Try to make sure we use a font that actually can show the
823 * language in question.
826 switch (PRIMARYLANGID (LOWORD (ime)))
833 switch (SUBLANGID (LOWORD (ime)))
835 case SUBLANG_CHINESE_TRADITIONAL:
836 lang = "zh_TW"; break;
837 case SUBLANG_CHINESE_SIMPLIFIED:
838 lang = "zh_CN"; break;
839 case SUBLANG_CHINESE_HONGKONG:
840 lang = "zh_HK"; break;
841 case SUBLANG_CHINESE_SINGAPORE:
842 lang = "zh_SG"; break;
843 case SUBLANG_CHINESE_MACAU:
844 lang = "zh_MO"; break;
855 /* We know what language it is. Look for a character, any
856 * character, that language needs.
858 PangoLanguage *pango_lang = pango_language_from_string (lang);
859 PangoFontset *fontset =
860 pango_context_load_fontset (pango_context,
861 gtk_widget_get_style (widget)->font_desc,
864 g_utf8_to_ucs4 (pango_language_get_sample_string (pango_lang),
865 -1, NULL, NULL, NULL);
866 wc = 0x4E00; /* In all CJK languages? */
871 for (i = 0; sample[i]; i++)
872 if (g_unichar_iswide (sample[i]))
879 font = pango_fontset_get_font (fontset, wc);
880 g_object_unref (fontset);
883 font = pango_context_load_font (pango_context, gtk_widget_get_style (widget)->font_desc);
888 logfont = pango_win32_font_logfont (font);
890 ImmSetCompositionFont (himc, logfont);
892 g_object_unref (font);
896 ImmReleaseContext (hwnd, himc);
900 static GdkFilterReturn
901 gtk_im_context_ime_message_filter (GdkXEvent *xevent,
905 GtkIMContext *context;
906 GtkIMContextIME *context_ime;
909 MSG *msg = (MSG *) xevent;
910 GdkFilterReturn retval = GDK_FILTER_CONTINUE;
912 g_return_val_if_fail (GTK_IS_IM_CONTEXT_IME (data), retval);
914 context = GTK_IM_CONTEXT (data);
915 context_ime = GTK_IM_CONTEXT_IME (data);
916 if (!context_ime->focus)
919 hwnd = GDK_WINDOW_HWND (context_ime->client_window);
920 himc = ImmGetContext (hwnd);
924 switch (msg->message)
926 case WM_IME_COMPOSITION:
931 get_window_position (context_ime->client_window, &wx, &wy);
939 GDK_WINDOW_HWND (gdk_window_get_toplevel
940 (context_ime->client_window));
941 GetWindowRect (hwnd_top, &rc);
944 ClientToScreen (hwnd_top, &pt);
949 cf.dwStyle = CFS_CANDIDATEPOS;
950 cf.ptCurrentPos.x = wx + context_ime->cursor_location.x;
951 cf.ptCurrentPos.y = wy + context_ime->cursor_location.y
952 + context_ime->cursor_location.height;
953 ImmSetCandidateWindow (himc, &cf);
955 if ((msg->lParam & GCS_COMPSTR))
956 g_signal_emit_by_name (context, "preedit-changed");
958 if (msg->lParam & GCS_RESULTSTR)
961 gchar *utf8str = NULL;
962 GError *error = NULL;
964 len = ImmGetCompositionStringW (himc, GCS_RESULTSTR, NULL, 0);
968 gpointer buf = g_alloca (len);
969 ImmGetCompositionStringW (himc, GCS_RESULTSTR, buf, len);
971 utf8str = g_utf16_to_utf8 (buf, len, NULL, NULL, &error);
974 g_warning ("%s", error->message);
975 g_error_free (error);
981 g_signal_emit_by_name (context, "commit", utf8str);
987 if (context_ime->use_preedit)
992 case WM_IME_STARTCOMPOSITION:
993 context_ime->preediting = TRUE;
994 gtk_im_context_ime_set_cursor_location (context, NULL);
995 g_signal_emit_by_name (context, "preedit-start");
996 if (context_ime->use_preedit)
1000 case WM_IME_ENDCOMPOSITION:
1001 context_ime->preediting = FALSE;
1002 g_signal_emit_by_name (context, "preedit-changed");
1003 g_signal_emit_by_name (context, "preedit-end");
1004 if (context_ime->use_preedit)
1009 switch (msg->wParam)
1011 case IMN_SETOPENSTATUS:
1012 context_ime->opened = ImmGetOpenStatus (himc);
1013 gtk_im_context_ime_set_preedit_font (context);
1024 ImmReleaseContext (hwnd, himc);
1030 * x and y must be initialized to 0.
1033 get_window_position (GdkWindow *win, gint *x, gint *y)
1035 GdkWindow *parent, *toplevel;
1038 g_return_if_fail (GDK_IS_WINDOW (win));
1039 g_return_if_fail (x && y);
1041 gdk_window_get_position (win, &wx, &wy);
1044 parent = gdk_window_get_parent (win);
1045 toplevel = gdk_window_get_toplevel (win);
1047 if (parent && parent != toplevel)
1048 get_window_position (parent, x, y);
1053 * probably, this handler isn't needed.
1056 cb_client_widget_hierarchy_changed (GtkWidget *widget,
1058 GtkIMContextIME *context_ime)
1060 GdkWindow *new_toplevel;
1062 g_return_if_fail (GTK_IS_WIDGET (widget));
1063 g_return_if_fail (GTK_IS_IM_CONTEXT_IME (context_ime));
1065 if (!context_ime->client_window)
1067 if (!context_ime->focus)
1070 new_toplevel = gdk_window_get_toplevel (context_ime->client_window);
1071 if (context_ime->toplevel == new_toplevel)
1074 /* remove filter from old toplevel */
1075 if (GDK_IS_WINDOW (context_ime->toplevel))
1077 gdk_window_remove_filter (context_ime->toplevel,
1078 gtk_im_context_ime_message_filter,
1085 /* add filter to new toplevel */
1086 if (GDK_IS_WINDOW (new_toplevel))
1088 gdk_window_add_filter (new_toplevel,
1089 gtk_im_context_ime_message_filter, context_ime);
1095 context_ime->toplevel = new_toplevel;