1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2000 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
25 #include "gtkimcontextxim.h"
27 #include "gtk/gtkintl.h"
29 typedef struct _StatusWindow StatusWindow;
30 typedef struct _GtkXIMInfo GtkXIMInfo;
32 struct _GtkIMContextXIM
41 GdkWindow *client_window;
42 GtkWidget *client_widget;
44 /* The status window for this input context; we claim the
45 * status window when we are focused and have created an XIC
47 StatusWindow *status_window;
51 gunichar *preedit_chars;
52 XIMFeedback *feedbacks;
56 XIMCallback preedit_start_callback;
57 XIMCallback preedit_done_callback;
58 XIMCallback preedit_draw_callback;
59 XIMCallback preedit_caret_callback;
61 XIMCallback status_start_callback;
62 XIMCallback status_done_callback;
63 XIMCallback status_draw_callback;
65 XIMCallback string_conversion_callback;
69 guint filter_key_release : 1;
70 guint use_preedit : 1;
72 guint in_toplevel : 1;
81 XIMStyle preedit_style_setting;
82 XIMStyle status_style_setting;
84 GtkSettings *settings;
87 gulong display_closed_cb;
88 XIMStyles *xim_styles;
91 guint reconnecting :1;
92 guint supports_string_conversion;
95 /* A context status window; these are kept in the status_windows list. */
100 /* Toplevel window to which the status window corresponds */
103 /* Currently focused GtkIMContextXIM for the toplevel, if any */
104 GtkIMContextXIM *context;
107 static void gtk_im_context_xim_class_init (GtkIMContextXIMClass *class);
108 static void gtk_im_context_xim_init (GtkIMContextXIM *im_context_xim);
109 static void gtk_im_context_xim_finalize (GObject *obj);
110 static void gtk_im_context_xim_set_client_window (GtkIMContext *context,
111 GdkWindow *client_window);
112 static gboolean gtk_im_context_xim_filter_keypress (GtkIMContext *context,
114 static void gtk_im_context_xim_reset (GtkIMContext *context);
115 static void gtk_im_context_xim_focus_in (GtkIMContext *context);
116 static void gtk_im_context_xim_focus_out (GtkIMContext *context);
117 static void gtk_im_context_xim_set_cursor_location (GtkIMContext *context,
119 static void gtk_im_context_xim_set_use_preedit (GtkIMContext *context,
120 gboolean use_preedit);
121 static void gtk_im_context_xim_get_preedit_string (GtkIMContext *context,
123 PangoAttrList **attrs,
126 static void reinitialize_ic (GtkIMContextXIM *context_xim);
127 static void set_ic_client_window (GtkIMContextXIM *context_xim,
128 GdkWindow *client_window);
130 static void setup_styles (GtkXIMInfo *info);
132 static void update_client_widget (GtkIMContextXIM *context_xim);
133 static void update_status_window (GtkIMContextXIM *context_xim);
135 static StatusWindow *status_window_get (GtkWidget *toplevel);
136 static void status_window_free (StatusWindow *status_window);
137 static void status_window_set_text (StatusWindow *status_window,
140 static void xim_destroy_callback (XIM xim,
141 XPointer client_data,
144 static XIC gtk_im_context_xim_get_ic (GtkIMContextXIM *context_xim);
145 static void xim_info_display_closed (GdkDisplay *display,
149 static GObjectClass *parent_class;
151 GType gtk_type_im_context_xim = 0;
153 static GSList *open_ims = NULL;
155 /* List of status windows for different toplevels */
156 static GSList *status_windows = NULL;
159 gtk_im_context_xim_register_type (GTypeModule *type_module)
161 const GTypeInfo im_context_xim_info =
163 sizeof (GtkIMContextXIMClass),
164 (GBaseInitFunc) NULL,
165 (GBaseFinalizeFunc) NULL,
166 (GClassInitFunc) gtk_im_context_xim_class_init,
167 NULL, /* class_finalize */
168 NULL, /* class_data */
169 sizeof (GtkIMContextXIM),
171 (GInstanceInitFunc) gtk_im_context_xim_init,
174 gtk_type_im_context_xim =
175 g_type_module_register_type (type_module,
178 &im_context_xim_info, 0);
181 #define PREEDIT_MASK (XIMPreeditCallbacks | XIMPreeditPosition | \
182 XIMPreeditArea | XIMPreeditNothing | XIMPreeditNone)
183 #define STATUS_MASK (XIMStatusCallbacks | XIMStatusArea | \
184 XIMStatusNothing | XIMStatusNone)
185 #define ALLOWED_MASK (XIMPreeditCallbacks | XIMPreeditNothing | XIMPreeditNone | \
186 XIMStatusCallbacks | XIMStatusNothing | XIMStatusNone)
189 choose_better_style (XIMStyle style1, XIMStyle style2)
193 if (style1 == 0) return style2;
194 if (style2 == 0) return style1;
195 if ((style1 & (PREEDIT_MASK | STATUS_MASK))
196 == (style2 & (PREEDIT_MASK | STATUS_MASK)))
199 s1 = style1 & PREEDIT_MASK;
200 s2 = style2 & PREEDIT_MASK;
203 if (u & XIMPreeditCallbacks)
204 return (s1 == XIMPreeditCallbacks) ? style1 : style2;
205 else if (u & XIMPreeditPosition)
206 return (s1 == XIMPreeditPosition) ? style1 :style2;
207 else if (u & XIMPreeditArea)
208 return (s1 == XIMPreeditArea) ? style1 : style2;
209 else if (u & XIMPreeditNothing)
210 return (s1 == XIMPreeditNothing) ? style1 : style2;
211 else if (u & XIMPreeditNone)
212 return (s1 == XIMPreeditNone) ? style1 : style2;
214 s1 = style1 & STATUS_MASK;
215 s2 = style2 & STATUS_MASK;
217 if (u & XIMStatusCallbacks)
218 return (s1 == XIMStatusCallbacks) ? style1 : style2;
219 else if (u & XIMStatusArea)
220 return (s1 == XIMStatusArea) ? style1 : style2;
221 else if (u & XIMStatusNothing)
222 return (s1 == XIMStatusNothing) ? style1 : style2;
223 else if (u & XIMStatusNone)
224 return (s1 == XIMStatusNone) ? style1 : style2;
226 return 0; /* Get rid of stupid warning */
230 reinitialize_all_ics (GtkXIMInfo *info)
234 for (tmp_list = info->ics; tmp_list; tmp_list = tmp_list->next)
235 reinitialize_ic (tmp_list->data);
239 status_style_change (GtkXIMInfo *info)
241 GtkIMStatusStyle status_style;
243 g_object_get (info->settings,
244 "gtk-im-status-style", &status_style,
246 if (status_style == GTK_IM_STATUS_CALLBACK)
247 info->status_style_setting = XIMStatusCallbacks;
248 else if (status_style == GTK_IM_STATUS_NOTHING)
249 info->status_style_setting = XIMStatusNothing;
250 else if (status_style == GTK_IM_STATUS_NONE)
251 info->status_style_setting = XIMStatusNone;
257 reinitialize_all_ics (info);
261 preedit_style_change (GtkXIMInfo *info)
263 GtkIMPreeditStyle preedit_style;
264 g_object_get (info->settings,
265 "gtk-im-preedit-style", &preedit_style,
267 if (preedit_style == GTK_IM_PREEDIT_CALLBACK)
268 info->preedit_style_setting = XIMPreeditCallbacks;
269 else if (preedit_style == GTK_IM_PREEDIT_NOTHING)
270 info->preedit_style_setting = XIMPreeditNothing;
271 else if (preedit_style == GTK_IM_PREEDIT_NONE)
272 info->preedit_style_setting = XIMPreeditNone;
278 reinitialize_all_ics (info);
282 setup_styles (GtkXIMInfo *info)
285 unsigned long settings_preference;
286 XIMStyles *xim_styles = info->xim_styles;
288 settings_preference = info->status_style_setting|info->preedit_style_setting;
292 for (i = 0; i < xim_styles->count_styles; i++)
293 if ((xim_styles->supported_styles[i] & ALLOWED_MASK) == xim_styles->supported_styles[i])
295 if (settings_preference == xim_styles->supported_styles[i])
297 info->style = settings_preference;
300 info->style = choose_better_style (info->style,
301 xim_styles->supported_styles[i]);
304 if (info->style == 0)
305 info->style = XIMPreeditNothing | XIMStatusNothing;
309 setup_im (GtkXIMInfo *info)
311 XIMValuesList *ic_values = NULL;
312 XIMCallback im_destroy_callback;
315 if (info->im == NULL)
318 im_destroy_callback.client_data = (XPointer)info;
319 im_destroy_callback.callback = (XIMProc)xim_destroy_callback;
320 XSetIMValues (info->im,
321 XNDestroyCallback, &im_destroy_callback,
324 XGetIMValues (info->im,
325 XNQueryInputStyle, &info->xim_styles,
326 XNQueryICValuesList, &ic_values,
329 info->settings = gtk_settings_get_for_screen (info->screen);
331 if (!g_object_class_find_property (G_OBJECT_GET_CLASS (info->settings),
332 "gtk-im-preedit-style"))
333 gtk_settings_install_property (g_param_spec_enum ("gtk-im-preedit-style",
334 P_("IM Preedit style"),
335 P_("How to draw the input method preedit string"),
336 GTK_TYPE_IM_PREEDIT_STYLE,
337 GTK_IM_PREEDIT_CALLBACK,
340 if (!g_object_class_find_property (G_OBJECT_GET_CLASS (info->settings),
341 "gtk-im-status-style"))
342 gtk_settings_install_property (g_param_spec_enum ("gtk-im-status-style",
343 P_("IM Status style"),
344 P_("How to draw the input method statusbar"),
345 GTK_TYPE_IM_STATUS_STYLE,
346 GTK_IM_STATUS_CALLBACK,
349 info->status_set = g_signal_connect_swapped (info->settings,
350 "notify::gtk-im-status-style",
351 G_CALLBACK (status_style_change),
353 info->preedit_set = g_signal_connect_swapped (info->settings,
354 "notify::gtk-im-preedit-style",
355 G_CALLBACK (preedit_style_change),
358 info->supports_string_conversion = FALSE;
363 for (i = 0; i < ic_values->count_values; i++)
364 if (strcmp (ic_values->supported_values[i],
365 XNStringConversionCallback) == 0)
367 info->supports_string_conversion = TRUE;
372 for (i = 0; i < ic_values->count_values; i++)
373 g_print ("%s\n", ic_values->supported_values[i]);
374 for (i = 0; i < xim_styles->count_styles; i++)
375 g_print ("%#x\n", xim_styles->supported_styles[i]);
381 status_style_change (info);
382 preedit_style_change (info);
384 display = gdk_screen_get_display (info->screen);
385 info->display_closed_cb = g_signal_connect (display, "closed",
386 G_CALLBACK (xim_info_display_closed), info);
390 xim_info_display_closed (GdkDisplay *display,
394 GSList *ics, *tmp_list;
396 open_ims = g_slist_remove (open_ims, info);
401 for (tmp_list = ics; tmp_list; tmp_list = tmp_list->next)
402 set_ic_client_window (tmp_list->data, NULL);
406 if (info->status_set)
407 g_signal_handler_disconnect (info->settings, info->status_set);
408 if (info->preedit_set)
409 g_signal_handler_disconnect (info->settings, info->preedit_set);
410 if (info->display_closed_cb)
411 g_signal_handler_disconnect (display, info->display_closed_cb);
413 if (info->xim_styles)
414 XFree (info->xim_styles);
415 g_free (info->locale);
424 xim_instantiate_callback (Display *display, XPointer client_data,
427 GtkXIMInfo *info = (GtkXIMInfo*)client_data;
430 im = XOpenIM (display, NULL, NULL, NULL);
438 XUnregisterIMInstantiateCallback (display, NULL, NULL, NULL,
439 xim_instantiate_callback,
441 info->reconnecting = FALSE;
444 /* initialize info->im */
446 xim_info_try_im (GtkXIMInfo *info)
448 GdkScreen *screen = info->screen;
449 GdkDisplay *display = gdk_screen_get_display (screen);
451 g_assert (info->im == NULL);
452 if (info->reconnecting)
455 if (XSupportsLocale ())
457 if (!XSetLocaleModifiers (""))
458 g_warning ("Unable to set locale modifiers with XSetLocaleModifiers()");
459 info->im = XOpenIM (GDK_DISPLAY_XDISPLAY (display), NULL, NULL, NULL);
462 XRegisterIMInstantiateCallback (GDK_DISPLAY_XDISPLAY(display),
464 xim_instantiate_callback,
466 info->reconnecting = TRUE;
474 xim_destroy_callback (XIM xim,
475 XPointer client_data,
478 GtkXIMInfo *info = (GtkXIMInfo*)client_data;
482 g_signal_handler_disconnect (info->settings, info->status_set);
483 info->status_set = 0;
484 g_signal_handler_disconnect (info->settings, info->preedit_set);
485 info->preedit_set = 0;
487 reinitialize_all_ics (info);
488 xim_info_try_im (info);
493 get_im (GdkWindow *client_window,
498 GdkScreen *screen = gdk_drawable_get_screen (client_window);
504 GtkXIMInfo *tmp_info = tmp_list->data;
505 if (tmp_info->screen == screen &&
506 strcmp (tmp_info->locale, locale) == 0)
518 tmp_list = tmp_list->next;
523 info = g_new (GtkXIMInfo, 1);
524 open_ims = g_slist_prepend (open_ims, info);
526 info->screen = screen;
527 info->locale = g_strdup (locale);
528 info->xim_styles = NULL;
529 info->preedit_style_setting = 0;
530 info->status_style_setting = 0;
531 info->settings = NULL;
532 info->preedit_set = 0;
533 info->status_set = 0;
534 info->display_closed_cb = 0;
536 info->reconnecting = FALSE;
540 xim_info_try_im (info);
545 gtk_im_context_xim_class_init (GtkIMContextXIMClass *class)
547 GtkIMContextClass *im_context_class = GTK_IM_CONTEXT_CLASS (class);
548 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
550 parent_class = g_type_class_peek_parent (class);
552 im_context_class->set_client_window = gtk_im_context_xim_set_client_window;
553 im_context_class->filter_keypress = gtk_im_context_xim_filter_keypress;
554 im_context_class->reset = gtk_im_context_xim_reset;
555 im_context_class->get_preedit_string = gtk_im_context_xim_get_preedit_string;
556 im_context_class->focus_in = gtk_im_context_xim_focus_in;
557 im_context_class->focus_out = gtk_im_context_xim_focus_out;
558 im_context_class->set_cursor_location = gtk_im_context_xim_set_cursor_location;
559 im_context_class->set_use_preedit = gtk_im_context_xim_set_use_preedit;
560 gobject_class->finalize = gtk_im_context_xim_finalize;
564 gtk_im_context_xim_init (GtkIMContextXIM *im_context_xim)
566 im_context_xim->use_preedit = TRUE;
567 im_context_xim->filter_key_release = FALSE;
568 im_context_xim->finalizing = FALSE;
569 im_context_xim->has_focus = FALSE;
570 im_context_xim->in_toplevel = FALSE;
574 gtk_im_context_xim_finalize (GObject *obj)
576 GtkIMContextXIM *context_xim = GTK_IM_CONTEXT_XIM (obj);
578 context_xim->finalizing = TRUE;
580 if (context_xim->im_info && !context_xim->im_info->ics->next)
582 if (context_xim->im_info->reconnecting)
586 display = gdk_screen_get_display (context_xim->im_info->screen);
587 XUnregisterIMInstantiateCallback (GDK_DISPLAY_XDISPLAY (display),
589 xim_instantiate_callback,
590 (XPointer)context_xim->im_info);
592 else if (context_xim->im_info->im)
594 XIMCallback im_destroy_callback;
596 im_destroy_callback.client_data = NULL;
597 im_destroy_callback.callback = NULL;
598 XSetIMValues (context_xim->im_info->im,
599 XNDestroyCallback, &im_destroy_callback,
604 set_ic_client_window (context_xim, NULL);
606 g_free (context_xim->locale);
607 g_free (context_xim->mb_charset);
609 G_OBJECT_CLASS (parent_class)->finalize (obj);
613 reinitialize_ic (GtkIMContextXIM *context_xim)
617 XDestroyIC (context_xim->ic);
618 context_xim->ic = NULL;
619 update_status_window (context_xim);
621 if (context_xim->preedit_length)
623 context_xim->preedit_length = 0;
624 if (!context_xim->finalizing)
625 g_signal_emit_by_name (context_xim, "preedit-changed");
629 reset filter_key_release flag, otherwise keystrokes will be doubled
630 until reconnecting to XIM.
632 context_xim->filter_key_release = FALSE;
636 set_ic_client_window (GtkIMContextXIM *context_xim,
637 GdkWindow *client_window)
639 reinitialize_ic (context_xim);
640 if (context_xim->client_window)
642 context_xim->im_info->ics = g_slist_remove (context_xim->im_info->ics, context_xim);
643 context_xim->im_info = NULL;
646 context_xim->client_window = client_window;
648 if (context_xim->client_window)
650 context_xim->im_info = get_im (context_xim->client_window, context_xim->locale);
651 context_xim->im_info->ics = g_slist_prepend (context_xim->im_info->ics, context_xim);
654 update_client_widget (context_xim);
658 gtk_im_context_xim_set_client_window (GtkIMContext *context,
659 GdkWindow *client_window)
661 GtkIMContextXIM *context_xim = GTK_IM_CONTEXT_XIM (context);
663 set_ic_client_window (context_xim, client_window);
667 gtk_im_context_xim_new (void)
669 GtkIMContextXIM *result;
670 const gchar *charset;
672 result = g_object_new (GTK_TYPE_IM_CONTEXT_XIM, NULL);
674 result->locale = g_strdup (setlocale (LC_CTYPE, NULL));
676 g_get_charset (&charset);
677 result->mb_charset = g_strdup (charset);
679 return GTK_IM_CONTEXT (result);
683 mb_to_utf8 (GtkIMContextXIM *context_xim,
686 GError *error = NULL;
689 if (strcmp (context_xim->mb_charset, "UTF-8") == 0)
690 result = g_strdup (str);
693 result = g_convert (str, -1,
694 "UTF-8", context_xim->mb_charset,
698 g_warning ("Error converting text from IM to UTF-8: %s\n", error->message);
699 g_error_free (error);
707 gtk_im_context_xim_filter_keypress (GtkIMContext *context,
710 GtkIMContextXIM *context_xim = GTK_IM_CONTEXT_XIM (context);
711 XIC ic = gtk_im_context_xim_get_ic (context_xim);
712 gchar static_buffer[256];
713 gchar *buffer = static_buffer;
714 gint buffer_size = sizeof(static_buffer) - 1;
718 gboolean result = FALSE;
719 GdkWindow *root_window = gdk_screen_get_root_window (gdk_drawable_get_screen (event->window));
721 XKeyPressedEvent xevent;
723 if (event->type == GDK_KEY_RELEASE && !context_xim->filter_key_release)
726 xevent.type = (event->type == GDK_KEY_PRESS) ? KeyPress : KeyRelease;
727 xevent.serial = 0; /* hope it doesn't matter */
728 xevent.send_event = event->send_event;
729 xevent.display = GDK_DRAWABLE_XDISPLAY (event->window);
730 xevent.window = GDK_DRAWABLE_XID (event->window);
731 xevent.root = GDK_DRAWABLE_XID (root_window);
732 xevent.subwindow = xevent.window;
733 xevent.time = event->time;
734 xevent.x = xevent.x_root = 0;
735 xevent.y = xevent.y_root = 0;
736 xevent.state = event->state;
737 xevent.keycode = event->hardware_keycode;
738 xevent.same_screen = True;
740 if (XFilterEvent ((XEvent *)&xevent, GDK_DRAWABLE_XID (context_xim->client_window)))
744 (gtk_accelerator_get_default_mod_mask () & ~(GDK_SHIFT_MASK | GDK_CONTROL_MASK)))
749 num_bytes = XmbLookupString (ic, &xevent, buffer, buffer_size, &keysym, &status);
752 num_bytes = XLookupString (&xevent, buffer, buffer_size, &keysym, NULL);
753 status = XLookupBoth;
756 if (status == XBufferOverflow)
758 buffer_size = num_bytes;
759 if (buffer != static_buffer)
761 buffer = g_malloc (num_bytes + 1);
765 /* I don't know how we should properly handle XLookupKeysym or XLookupBoth
766 * here ... do input methods actually change the keysym? we can't really
767 * feed it back to accelerator processing at this point...
769 if (status == XLookupChars || status == XLookupBoth)
773 buffer[num_bytes] = '\0';
775 result_utf8 = mb_to_utf8 (context_xim, buffer);
778 if ((guchar)result_utf8[0] >= 0x20 &&
779 result_utf8[0] != 0x7f) /* Some IM have a nasty habit of converting
780 * control characters into strings
783 g_signal_emit_by_name (context, "commit", result_utf8);
787 g_free (result_utf8);
791 if (buffer != static_buffer)
798 gtk_im_context_xim_focus_in (GtkIMContext *context)
800 GtkIMContextXIM *context_xim = GTK_IM_CONTEXT_XIM (context);
802 if (!context_xim->has_focus)
804 XIC ic = gtk_im_context_xim_get_ic (context_xim);
806 context_xim->has_focus = TRUE;
807 update_status_window (context_xim);
817 gtk_im_context_xim_focus_out (GtkIMContext *context)
819 GtkIMContextXIM *context_xim = GTK_IM_CONTEXT_XIM (context);
821 if (context_xim->has_focus)
823 XIC ic = gtk_im_context_xim_get_ic (context_xim);
825 context_xim->has_focus = FALSE;
826 update_status_window (context_xim);
836 gtk_im_context_xim_set_cursor_location (GtkIMContext *context,
839 GtkIMContextXIM *context_xim = GTK_IM_CONTEXT_XIM (context);
840 XIC ic = gtk_im_context_xim_get_ic (context_xim);
842 XVaNestedList preedit_attr;
849 spot.y = area->y + area->height;
851 preedit_attr = XVaCreateNestedList (0,
852 XNSpotLocation, &spot,
855 XNPreeditAttributes, preedit_attr,
863 gtk_im_context_xim_set_use_preedit (GtkIMContext *context,
864 gboolean use_preedit)
866 GtkIMContextXIM *context_xim = GTK_IM_CONTEXT_XIM (context);
868 use_preedit = use_preedit != FALSE;
870 if (context_xim->use_preedit != use_preedit)
872 context_xim->use_preedit = use_preedit;
873 reinitialize_ic (context_xim);
880 gtk_im_context_xim_reset (GtkIMContext *context)
882 GtkIMContextXIM *context_xim = GTK_IM_CONTEXT_XIM (context);
883 XIC ic = gtk_im_context_xim_get_ic (context_xim);
886 /* restore conversion state after resetting ic later */
887 XIMPreeditState preedit_state = XIMPreeditUnKnown;
888 XVaNestedList preedit_attr;
889 gboolean have_preedit_state = FALSE;
895 if (context_xim->preedit_length == 0)
898 preedit_attr = XVaCreateNestedList(0,
899 XNPreeditState, &preedit_state,
901 if (!XGetICValues(ic,
902 XNPreeditAttributes, preedit_attr,
904 have_preedit_state = TRUE;
908 result = XmbResetIC (ic);
910 preedit_attr = XVaCreateNestedList(0,
911 XNPreeditState, preedit_state,
913 if (have_preedit_state)
915 XNPreeditAttributes, preedit_attr,
922 char *result_utf8 = mb_to_utf8 (context_xim, result);
925 g_signal_emit_by_name (context, "commit", result_utf8);
926 g_free (result_utf8);
930 if (context_xim->preedit_length)
932 context_xim->preedit_length = 0;
933 g_signal_emit_by_name (context, "preedit-changed");
939 /* Mask of feedback bits that we render
941 #define FEEDBACK_MASK (XIMReverse | XIMUnderline)
944 add_feedback_attr (PangoAttrList *attrs,
946 XIMFeedback feedback,
950 PangoAttribute *attr;
952 gint start_index = g_utf8_offset_to_pointer (str, start_pos) - str;
953 gint end_index = g_utf8_offset_to_pointer (str, end_pos) - str;
955 if (feedback & XIMUnderline)
957 attr = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE);
958 attr->start_index = start_index;
959 attr->end_index = end_index;
961 pango_attr_list_change (attrs, attr);
964 if (feedback & XIMReverse)
966 attr = pango_attr_foreground_new (0xffff, 0xffff, 0xffff);
967 attr->start_index = start_index;
968 attr->end_index = end_index;
970 pango_attr_list_change (attrs, attr);
972 attr = pango_attr_background_new (0, 0, 0);
973 attr->start_index = start_index;
974 attr->end_index = end_index;
976 pango_attr_list_change (attrs, attr);
979 if (feedback & ~FEEDBACK_MASK)
980 g_warning ("Unrendered feedback style: %#lx", feedback & ~FEEDBACK_MASK);
984 gtk_im_context_xim_get_preedit_string (GtkIMContext *context,
986 PangoAttrList **attrs,
989 GtkIMContextXIM *context_xim = GTK_IM_CONTEXT_XIM (context);
990 gchar *utf8 = g_ucs4_to_utf8 (context_xim->preedit_chars, context_xim->preedit_length, NULL, NULL, NULL);
995 XIMFeedback last_feedback = 0;
998 *attrs = pango_attr_list_new ();
1000 for (i = 0; i < context_xim->preedit_length; i++)
1002 XIMFeedback new_feedback = context_xim->feedbacks[i] & FEEDBACK_MASK;
1003 if (new_feedback != last_feedback)
1006 add_feedback_attr (*attrs, utf8, last_feedback, start, i);
1008 last_feedback = new_feedback;
1014 add_feedback_attr (*attrs, utf8, last_feedback, start, i);
1023 *cursor_pos = context_xim->preedit_cursor;
1027 preedit_start_callback (XIC xic,
1028 XPointer client_data,
1031 GtkIMContext *context = GTK_IM_CONTEXT (client_data);
1032 GtkIMContextXIM *context_xim = GTK_IM_CONTEXT_XIM (context);
1034 if (!context_xim->finalizing)
1035 g_signal_emit_by_name (context, "preedit-start");
1037 return -1; /* No length limit */
1041 preedit_done_callback (XIC xic,
1042 XPointer client_data,
1045 GtkIMContext *context = GTK_IM_CONTEXT (client_data);
1046 GtkIMContextXIM *context_xim = GTK_IM_CONTEXT_XIM (context);
1048 if (context_xim->preedit_length)
1050 context_xim->preedit_length = 0;
1051 if (!context_xim->finalizing)
1052 g_signal_emit_by_name (context_xim, "preedit-changed");
1055 if (!context_xim->finalizing)
1056 g_signal_emit_by_name (context, "preedit-end");
1060 xim_text_to_utf8 (GtkIMContextXIM *context, XIMText *xim_text, gchar **text)
1062 gint text_length = 0;
1063 GError *error = NULL;
1064 gchar *result = NULL;
1066 if (xim_text && xim_text->string.multi_byte)
1068 if (xim_text->encoding_is_wchar)
1070 g_warning ("Wide character return from Xlib not currently supported");
1075 if (strcmp (context->mb_charset, "UTF-8") == 0)
1076 result = g_strdup (xim_text->string.multi_byte);
1078 result = g_convert (xim_text->string.multi_byte,
1081 context->mb_charset,
1082 NULL, NULL, &error);
1086 text_length = g_utf8_strlen (result, -1);
1088 if (text_length != xim_text->length)
1090 g_warning ("Size mismatch when converting text from input method: supplied length = %d\n, result length = %d", xim_text->length, text_length);
1095 g_warning ("Error converting text from IM to UCS-4: %s", error->message);
1096 g_error_free (error);
1113 preedit_draw_callback (XIC xic,
1114 XPointer client_data,
1115 XIMPreeditDrawCallbackStruct *call_data)
1117 GtkIMContextXIM *context = GTK_IM_CONTEXT_XIM (client_data);
1119 XIMText *new_xim_text = call_data->text;
1120 gint new_text_length;
1121 gunichar *new_text = NULL;
1127 gint chg_first = CLAMP (call_data->chg_first, 0, context->preedit_length);
1128 gint chg_length = CLAMP (call_data->chg_length, 0, context->preedit_length - chg_first);
1130 context->preedit_cursor = call_data->caret;
1132 if (chg_first != call_data->chg_first || chg_length != call_data->chg_length)
1133 g_warning ("Invalid change to preedit string, first=%d length=%d (orig length == %d)",
1134 call_data->chg_first, call_data->chg_length, context->preedit_length);
1136 new_text_length = xim_text_to_utf8 (context, new_xim_text, &tmp);
1139 new_text = g_utf8_to_ucs4_fast (tmp, -1, NULL);
1143 diff = new_text_length - chg_length;
1144 new_length = context->preedit_length + diff;
1146 if (new_length > context->preedit_size)
1148 context->preedit_size = new_length;
1149 context->preedit_chars = g_renew (gunichar, context->preedit_chars, new_length);
1150 context->feedbacks = g_renew (XIMFeedback, context->feedbacks, new_length);
1155 for (i = chg_first + chg_length ; i < context->preedit_length; i++)
1157 context->preedit_chars[i + diff] = context->preedit_chars[i];
1158 context->feedbacks[i + diff] = context->feedbacks[i];
1163 for (i = context->preedit_length - 1; i >= chg_first + chg_length ; i--)
1165 context->preedit_chars[i + diff] = context->preedit_chars[i];
1166 context->feedbacks[i + diff] = context->feedbacks[i];
1170 for (i = 0; i < new_text_length; i++)
1172 context->preedit_chars[chg_first + i] = new_text[i];
1173 context->feedbacks[chg_first + i] = new_xim_text->feedback[i];
1176 context->preedit_length += diff;
1180 if (!context->finalizing)
1181 g_signal_emit_by_name (context, "preedit-changed");
1186 preedit_caret_callback (XIC xic,
1187 XPointer client_data,
1188 XIMPreeditCaretCallbackStruct *call_data)
1190 GtkIMContextXIM *context = GTK_IM_CONTEXT_XIM (client_data);
1192 if (call_data->direction == XIMAbsolutePosition)
1194 context->preedit_cursor = call_data->position;
1195 if (!context->finalizing)
1196 g_signal_emit_by_name (context, "preedit-changed");
1200 g_warning ("Caret movement command: %d %d %d not supported",
1201 call_data->position, call_data->direction, call_data->style);
1206 status_start_callback (XIC xic,
1207 XPointer client_data,
1214 status_done_callback (XIC xic,
1215 XPointer client_data,
1222 status_draw_callback (XIC xic,
1223 XPointer client_data,
1224 XIMStatusDrawCallbackStruct *call_data)
1226 GtkIMContextXIM *context = GTK_IM_CONTEXT_XIM (client_data);
1228 if (call_data->type == XIMTextType)
1231 xim_text_to_utf8 (context, call_data->data.text, &text);
1233 if (context->status_window)
1234 status_window_set_text (context->status_window, text ? text : "");
1238 g_print ("Status drawn with bitmap - id = %#lx\n", call_data->data.bitmap);
1243 string_conversion_callback (XIC xic, XPointer client_data, XPointer call_data)
1245 GtkIMContextXIM *context_xim;
1246 XIMStringConversionCallbackStruct *conv_data;
1250 context_xim = (GtkIMContextXIM *)client_data;
1251 conv_data = (XIMStringConversionCallbackStruct *)call_data;
1253 if (gtk_im_context_get_surrounding ((GtkIMContext *)context_xim,
1254 &surrounding, &cursor_index))
1258 gint subst_offset = 0, subst_nchars = 0;
1260 gchar *p = surrounding + cursor_index, *q;
1261 gshort position = (gshort)conv_data->position;
1265 for (i = position; i > 0 && *p; --i)
1266 p = g_utf8_next_char (p);
1270 /* According to X11R6.4 Xlib - C Library Reference Manual
1271 * section 13.5.7.3 String Conversion Callback,
1272 * XIMStringConversionPosition is starting position _relative_
1273 * to current client's cursor position. So it should be able
1274 * to be negative, or referring to a position before the cursor
1275 * would be impossible. But current X protocol defines this as
1276 * unsigned short. So, compiler may warn about the value range
1277 * here. We hope the X protocol is fixed soon.
1279 else if (position < 0)
1281 for (i = position; i < 0 && p > surrounding; ++i)
1282 p = g_utf8_prev_char (p);
1287 switch (conv_data->direction)
1289 case XIMForwardChar:
1290 for (i = conv_data->factor, q = p; i > 0 && *q; --i)
1291 q = g_utf8_next_char (q);
1294 text = g_locale_from_utf8 (p, q - p, NULL, &text_len, NULL);
1295 subst_offset = position;
1296 subst_nchars = conv_data->factor;
1299 case XIMBackwardChar:
1300 for (i = conv_data->factor, q = p; i > 0 && q > surrounding; --i)
1301 q = g_utf8_prev_char (q);
1304 text = g_locale_from_utf8 (q, p - q, NULL, &text_len, NULL);
1305 subst_offset = position - conv_data->factor;
1306 subst_nchars = conv_data->factor;
1309 case XIMForwardWord:
1310 case XIMBackwardWord:
1314 case XIMPreviousLine:
1317 case XIMAbsolutePosition:
1322 /* block out any failure happenning to "text", including conversion */
1325 conv_data->text = (XIMStringConversionText *)
1326 malloc (sizeof (XIMStringConversionText));
1327 if (conv_data->text)
1329 conv_data->text->length = text_len;
1330 conv_data->text->feedback = NULL;
1331 conv_data->text->encoding_is_wchar = False;
1332 conv_data->text->string.mbs = (char *)malloc (text_len);
1333 if (conv_data->text->string.mbs)
1334 memcpy (conv_data->text->string.mbs, text, text_len);
1337 free (conv_data->text);
1338 conv_data->text = NULL;
1344 if (conv_data->operation == XIMStringConversionSubstitution
1345 && subst_nchars > 0)
1347 gtk_im_context_delete_surrounding ((GtkIMContext *)context_xim,
1348 subst_offset, subst_nchars);
1351 g_free (surrounding);
1356 static XVaNestedList
1357 set_preedit_callback (GtkIMContextXIM *context_xim)
1359 context_xim->preedit_start_callback.client_data = (XPointer)context_xim;
1360 context_xim->preedit_start_callback.callback = (XIMProc)preedit_start_callback;
1361 context_xim->preedit_done_callback.client_data = (XPointer)context_xim;
1362 context_xim->preedit_done_callback.callback = (XIMProc)preedit_done_callback;
1363 context_xim->preedit_draw_callback.client_data = (XPointer)context_xim;
1364 context_xim->preedit_draw_callback.callback = (XIMProc)preedit_draw_callback;
1365 context_xim->preedit_caret_callback.client_data = (XPointer)context_xim;
1366 context_xim->preedit_caret_callback.callback = (XIMProc)preedit_caret_callback;
1367 return XVaCreateNestedList (0,
1368 XNPreeditStartCallback, &context_xim->preedit_start_callback,
1369 XNPreeditDoneCallback, &context_xim->preedit_done_callback,
1370 XNPreeditDrawCallback, &context_xim->preedit_draw_callback,
1371 XNPreeditCaretCallback, &context_xim->preedit_caret_callback,
1375 static XVaNestedList
1376 set_status_callback (GtkIMContextXIM *context_xim)
1378 context_xim->status_start_callback.client_data = (XPointer)context_xim;
1379 context_xim->status_start_callback.callback = (XIMProc)status_start_callback;
1380 context_xim->status_done_callback.client_data = (XPointer)context_xim;
1381 context_xim->status_done_callback.callback = (XIMProc)status_done_callback;
1382 context_xim->status_draw_callback.client_data = (XPointer)context_xim;
1383 context_xim->status_draw_callback.callback = (XIMProc)status_draw_callback;
1385 return XVaCreateNestedList (0,
1386 XNStatusStartCallback, &context_xim->status_start_callback,
1387 XNStatusDoneCallback, &context_xim->status_done_callback,
1388 XNStatusDrawCallback, &context_xim->status_draw_callback,
1394 set_string_conversion_callback (GtkIMContextXIM *context_xim, XIC xic)
1396 if (!context_xim->im_info->supports_string_conversion)
1399 context_xim->string_conversion_callback.client_data = (XPointer)context_xim;
1400 context_xim->string_conversion_callback.callback = (XIMProc)string_conversion_callback;
1403 XNStringConversionCallback,
1404 (XPointer)&context_xim->string_conversion_callback,
1409 gtk_im_context_xim_get_ic (GtkIMContextXIM *context_xim)
1411 if (context_xim->im_info == NULL || context_xim->im_info->im == NULL)
1414 if (!context_xim->ic)
1416 const char *name1 = NULL;
1417 XVaNestedList list1 = NULL;
1418 const char *name2 = NULL;
1419 XVaNestedList list2 = NULL;
1420 XIMStyle im_style = 0;
1423 if (context_xim->use_preedit &&
1424 (context_xim->im_info->style & PREEDIT_MASK) == XIMPreeditCallbacks)
1426 im_style |= XIMPreeditCallbacks;
1427 name1 = XNPreeditAttributes;
1428 list1 = set_preedit_callback (context_xim);
1430 else if ((context_xim->im_info->style & PREEDIT_MASK) == XIMPreeditNone)
1431 im_style |= XIMPreeditNone;
1433 im_style |= XIMPreeditNothing;
1435 if ((context_xim->im_info->style & STATUS_MASK) == XIMStatusCallbacks)
1437 im_style |= XIMStatusCallbacks;
1440 name1 = XNStatusAttributes;
1441 list1 = set_status_callback (context_xim);
1445 name2 = XNStatusAttributes;
1446 list2 = set_status_callback (context_xim);
1449 else if ((context_xim->im_info->style & STATUS_MASK) == XIMStatusNone)
1450 im_style |= XIMStatusNone;
1452 im_style |= XIMStatusNothing;
1454 xic = XCreateIC (context_xim->im_info->im,
1455 XNInputStyle, im_style,
1456 XNClientWindow, GDK_DRAWABLE_XID (context_xim->client_window),
1467 /* Don't filter key released events with XFilterEvents unless
1468 * input methods ask for. This is a workaround for Solaris input
1469 * method bug in C and European locales. It doubles each key
1470 * stroke if both key pressed and released events are filtered.
1473 gulong mask = 0xaaaaaaaa;
1475 XNFilterEvents, &mask,
1477 context_xim->filter_key_release = (mask & KeyReleaseMask) != 0;
1478 set_string_conversion_callback (context_xim, xic);
1481 context_xim->ic = xic;
1483 update_status_window (context_xim);
1485 if (xic && context_xim->has_focus)
1488 return context_xim->ic;
1491 /*****************************************************************
1492 * Status Window handling
1494 * A status window is a small window attached to the toplevel
1495 * that is used to display information to the user about the
1496 * current input operation.
1498 * We claim the toplevel's status window for an input context if:
1500 * A) The input context has a toplevel
1501 * B) The input context has the focus
1502 * C) The input context has an XIC associated with it
1504 * Tracking A) and C) is pretty reliable since we
1505 * compute A) and create the XIC for C) ourselves.
1506 * For B) we basically have to depend on our callers
1507 * calling ::focus-in and ::focus-out at the right time.
1509 * The toplevel is computed by walking up the GdkWindow
1510 * hierarchy from context->client_window until we find a
1511 * window that is owned by some widget, and then calling
1512 * gtk_widget_get_toplevel() on that widget. This should
1513 * handle both cases where we might have GdkWindows without widgets,
1514 * and cases where GtkWidgets have strange window hierarchies
1515 * (like a torn off GtkHandleBox.)
1517 * The status window is visible if and only if there is text
1518 * for it; whenever a new GtkIMContextXIM claims the status
1519 * window, we blank out any existing text. We actually only
1520 * create a GtkWindow for the status window the first time
1521 * it is shown; this is an important optimization when we are
1522 * using XIM with something like a simple compose-key input
1523 * method that never needs a status window.
1524 *****************************************************************/
1526 /* Called when we no longer need a status window
1529 disclaim_status_window (GtkIMContextXIM *context_xim)
1531 if (context_xim->status_window)
1533 g_assert (context_xim->status_window->context == context_xim);
1535 status_window_set_text (context_xim->status_window, "");
1537 context_xim->status_window->context = NULL;
1538 context_xim->status_window = NULL;
1542 /* Called when we need a status window
1545 claim_status_window (GtkIMContextXIM *context_xim)
1547 if (!context_xim->status_window && context_xim->client_widget)
1549 GtkWidget *toplevel = gtk_widget_get_toplevel (context_xim->client_widget);
1550 if (toplevel && gtk_widget_is_toplevel (toplevel))
1552 StatusWindow *status_window = status_window_get (toplevel);
1554 if (status_window->context)
1555 disclaim_status_window (status_window->context);
1557 status_window->context = context_xim;
1558 context_xim->status_window = status_window;
1563 /* Basic call made whenever something changed that might cause
1564 * us to need, or not to need a status window.
1567 update_status_window (GtkIMContextXIM *context_xim)
1569 if (context_xim->ic && context_xim->in_toplevel && context_xim->has_focus)
1570 claim_status_window (context_xim);
1572 disclaim_status_window (context_xim);
1575 /* Updates the in_toplevel flag for @context_xim
1578 update_in_toplevel (GtkIMContextXIM *context_xim)
1580 if (context_xim->client_widget)
1582 GtkWidget *toplevel = gtk_widget_get_toplevel (context_xim->client_widget);
1584 context_xim->in_toplevel = (toplevel && gtk_widget_is_toplevel (toplevel));
1587 context_xim->in_toplevel = FALSE;
1589 /* Some paranoia, in case we don't get a focus out */
1590 if (!context_xim->in_toplevel)
1591 context_xim->has_focus = FALSE;
1593 update_status_window (context_xim);
1596 /* Callback when @widget's toplevel changes. It will always
1597 * change from NULL to a window, or a window to NULL;
1598 * we use that intermediate NULL state to make sure
1599 * that we disclaim the toplevel status window for the old
1603 on_client_widget_hierarchy_changed (GtkWidget *widget,
1604 GtkWidget *old_toplevel,
1605 GtkIMContextXIM *context_xim)
1607 update_in_toplevel (context_xim);
1610 /* Finds the GtkWidget that owns the window, or if none, the
1611 * widget owning the nearest parent that has a widget.
1614 widget_for_window (GdkWindow *window)
1619 gdk_window_get_user_data (window, &user_data);
1623 window = gdk_window_get_parent (window);
1629 /* Called when context_xim->client_window changes; takes care of
1630 * removing and/or setting up our watches for the toplevel
1633 update_client_widget (GtkIMContextXIM *context_xim)
1635 GtkWidget *new_client_widget = widget_for_window (context_xim->client_window);
1637 if (new_client_widget != context_xim->client_widget)
1639 if (context_xim->client_widget)
1641 g_signal_handlers_disconnect_by_func (context_xim->client_widget,
1642 G_CALLBACK (on_client_widget_hierarchy_changed),
1645 context_xim->client_widget = new_client_widget;
1646 if (context_xim->client_widget)
1648 g_signal_connect (context_xim->client_widget, "hierarchy-changed",
1649 G_CALLBACK (on_client_widget_hierarchy_changed),
1653 update_in_toplevel (context_xim);
1657 /* Called when the toplevel is destroyed; frees the status window
1660 on_status_toplevel_destroy (GtkWidget *toplevel,
1661 StatusWindow *status_window)
1663 status_window_free (status_window);
1666 /* Called when the screen for the toplevel changes; updates the
1667 * screen for the status window to match.
1670 on_status_toplevel_notify_screen (GtkWindow *toplevel,
1672 StatusWindow *status_window)
1674 if (status_window->window)
1675 gtk_window_set_screen (GTK_WINDOW (status_window->window),
1676 gtk_widget_get_screen (GTK_WIDGET (toplevel)));
1679 /* Called when the toplevel window is moved; updates the position of
1680 * the status window to follow it.
1683 on_status_toplevel_configure (GtkWidget *toplevel,
1684 GdkEventConfigure *event,
1685 StatusWindow *status_window)
1688 GtkRequisition requisition;
1692 if (status_window->window)
1694 height = gdk_screen_get_height (gtk_widget_get_screen (toplevel));
1696 gdk_window_get_frame_extents (toplevel->window, &rect);
1697 gtk_widget_size_request (status_window->window, &requisition);
1699 if (rect.y + rect.height + requisition.height < height)
1700 y = rect.y + rect.height;
1702 y = height - requisition.height;
1704 gtk_window_move (GTK_WINDOW (status_window->window), rect.x, y);
1710 /* Frees a status window and removes its link from the status_windows list
1713 status_window_free (StatusWindow *status_window)
1715 status_windows = g_slist_remove (status_windows, status_window);
1717 if (status_window->context)
1718 status_window->context->status_window = NULL;
1720 g_signal_handlers_disconnect_by_func (status_window->toplevel,
1721 G_CALLBACK (on_status_toplevel_destroy),
1723 g_signal_handlers_disconnect_by_func (status_window->toplevel,
1724 G_CALLBACK (on_status_toplevel_notify_screen),
1726 g_signal_handlers_disconnect_by_func (status_window->toplevel,
1727 G_CALLBACK (on_status_toplevel_configure),
1730 if (status_window->window)
1731 gtk_widget_destroy (status_window->window);
1733 g_object_set_data (G_OBJECT (status_window->toplevel), "gtk-im-xim-status-window", NULL);
1735 g_free (status_window);
1738 /* Finds the status window object for a toplevel, creating it if necessary.
1740 static StatusWindow *
1741 status_window_get (GtkWidget *toplevel)
1743 StatusWindow *status_window;
1745 status_window = g_object_get_data (G_OBJECT (toplevel), "gtk-im-xim-status-window");
1747 return status_window;
1749 status_window = g_new0 (StatusWindow, 1);
1750 status_window->toplevel = toplevel;
1752 status_windows = g_slist_prepend (status_windows, status_window);
1754 g_signal_connect (toplevel, "destroy",
1755 G_CALLBACK (on_status_toplevel_destroy),
1757 g_signal_connect (toplevel, "configure-event",
1758 G_CALLBACK (on_status_toplevel_configure),
1760 g_signal_connect (toplevel, "notify::screen",
1761 G_CALLBACK (on_status_toplevel_notify_screen),
1764 g_object_set_data (G_OBJECT (toplevel), "gtk-im-xim-status-window", status_window);
1766 return status_window;
1769 /* Draw the background (normally white) and border for the status window
1772 on_status_window_expose_event (GtkWidget *widget,
1773 GdkEventExpose *event)
1775 gdk_draw_rectangle (widget->window,
1776 widget->style->base_gc [GTK_STATE_NORMAL],
1779 widget->allocation.width, widget->allocation.height);
1780 gdk_draw_rectangle (widget->window,
1781 widget->style->text_gc [GTK_STATE_NORMAL],
1784 widget->allocation.width - 1, widget->allocation.height - 1);
1789 /* We watch the ::style-set signal for our label widget
1790 * and use that to change it's foreground color to match
1791 * the 'text' color of the toplevel window. The text/base
1792 * pair of colors might be reversed from the fg/bg pair
1793 * that are normally used for labels.
1796 on_status_window_style_set (GtkWidget *toplevel,
1797 GtkStyle *previous_style,
1802 for (i = 0; i < 5; i++)
1803 gtk_widget_modify_fg (label, i, &toplevel->style->text[i]);
1806 /* Creates the widgets for the status window; called when we
1807 * first need to show text for the status window.
1810 status_window_make_window (StatusWindow *status_window)
1813 GtkWidget *status_label;
1815 status_window->window = gtk_window_new (GTK_WINDOW_POPUP);
1816 window = status_window->window;
1818 gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
1819 gtk_widget_set_app_paintable (window, TRUE);
1821 status_label = gtk_label_new ("");
1822 gtk_misc_set_padding (GTK_MISC (status_label), 1, 1);
1823 gtk_widget_show (status_label);
1825 g_signal_connect (window, "style-set",
1826 G_CALLBACK (on_status_window_style_set), status_label);
1827 gtk_container_add (GTK_CONTAINER (window), status_label);
1829 g_signal_connect (window, "expose-event",
1830 G_CALLBACK (on_status_window_expose_event), NULL);
1832 gtk_window_set_screen (GTK_WINDOW (status_window->window),
1833 gtk_widget_get_screen (status_window->toplevel));
1835 on_status_toplevel_configure (status_window->toplevel, NULL, status_window);
1838 /* Updates the text in the status window, hiding or
1839 * showing the window as necessary.
1842 status_window_set_text (StatusWindow *status_window,
1849 if (!status_window->window)
1850 status_window_make_window (status_window);
1852 label = GTK_BIN (status_window->window)->child;
1853 gtk_label_set_text (GTK_LABEL (label), text);
1855 gtk_widget_show (status_window->window);
1859 if (status_window->window)
1860 gtk_widget_hide (status_window->window);
1865 * gtk_im_context_xim_shutdown:
1867 * Destroys all the status windows that are kept by the XIM contexts. This
1868 * function should only be called by the XIM module exit routine.
1871 gtk_im_context_xim_shutdown (void)
1873 while (status_windows)
1874 status_window_free (status_windows->data);
1878 GtkXIMInfo *info = open_ims->data;
1879 GdkDisplay *display = gdk_screen_get_display (info->screen);
1881 xim_info_display_closed (display, FALSE, info);
1882 open_ims = g_slist_remove_link (open_ims, open_ims);