]> Pileus Git - ~andy/gtk/blob - gtk/gtkimmulticontext.c
Updated Norwegian bokmål translation.
[~andy/gtk] / gtk / gtkimmulticontext.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 2000 Red Hat, Inc.
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #include "config.h"
21
22 #include <string.h>
23 #include <locale.h>
24
25 #include "gtkimmulticontext.h"
26 #include "gtkimmodule.h"
27 #include "gtkmain.h"
28 #include "gtkradiomenuitem.h"
29 #include "gtkintl.h"
30 #include "gtkprivate.h" /* To get redefinition of GTK_LOCALE_DIR on Win32 */
31 #include "gtkalias.h"
32
33 struct _GtkIMMulticontextPrivate
34 {
35   GdkWindow *client_window;
36   GdkRectangle cursor_location;
37   gchar *context_id;
38
39   guint use_preedit : 1;
40   guint have_cursor_location : 1;
41   guint focus_in : 1;
42 };
43
44 static void     gtk_im_multicontext_finalize           (GObject                 *object);
45
46 static void     gtk_im_multicontext_set_slave          (GtkIMMulticontext       *multicontext,
47                                                         GtkIMContext            *slave,
48                                                         gboolean                 finalizing);
49
50 static void     gtk_im_multicontext_set_client_window  (GtkIMContext            *context,
51                                                         GdkWindow               *window);
52 static void     gtk_im_multicontext_get_preedit_string (GtkIMContext            *context,
53                                                         gchar                  **str,
54                                                         PangoAttrList          **attrs,
55                                                         gint                   *cursor_pos);
56 static gboolean gtk_im_multicontext_filter_keypress    (GtkIMContext            *context,
57                                                         GdkEventKey             *event);
58 static void     gtk_im_multicontext_focus_in           (GtkIMContext            *context);
59 static void     gtk_im_multicontext_focus_out          (GtkIMContext            *context);
60 static void     gtk_im_multicontext_reset              (GtkIMContext            *context);
61 static void     gtk_im_multicontext_set_cursor_location (GtkIMContext            *context,
62                                                         GdkRectangle            *area);
63 static void     gtk_im_multicontext_set_use_preedit    (GtkIMContext            *context,
64                                                         gboolean                 use_preedit);
65 static gboolean gtk_im_multicontext_get_surrounding    (GtkIMContext            *context,
66                                                         gchar                  **text,
67                                                         gint                    *cursor_index);
68 static void     gtk_im_multicontext_set_surrounding    (GtkIMContext            *context,
69                                                         const char              *text,
70                                                         gint                     len,
71                                                         gint                     cursor_index);
72
73 static void     gtk_im_multicontext_preedit_start_cb        (GtkIMContext      *slave,
74                                                              GtkIMMulticontext *multicontext);
75 static void     gtk_im_multicontext_preedit_end_cb          (GtkIMContext      *slave,
76                                                              GtkIMMulticontext *multicontext);
77 static void     gtk_im_multicontext_preedit_changed_cb      (GtkIMContext      *slave,
78                                                              GtkIMMulticontext *multicontext);
79 static void     gtk_im_multicontext_commit_cb               (GtkIMContext      *slave,
80                                                              const gchar       *str,
81                                                              GtkIMMulticontext *multicontext);
82 static gboolean gtk_im_multicontext_retrieve_surrounding_cb (GtkIMContext      *slave,
83                                                              GtkIMMulticontext *multicontext);
84 static gboolean gtk_im_multicontext_delete_surrounding_cb   (GtkIMContext      *slave,
85                                                              gint               offset,
86                                                              gint               n_chars,
87                                                              GtkIMMulticontext *multicontext);
88
89 static const gchar *global_context_id = NULL;
90
91 G_DEFINE_TYPE (GtkIMMulticontext, gtk_im_multicontext, GTK_TYPE_IM_CONTEXT)
92
93 static void
94 gtk_im_multicontext_class_init (GtkIMMulticontextClass *class)
95 {
96   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
97   GtkIMContextClass *im_context_class = GTK_IM_CONTEXT_CLASS (class);
98   
99   im_context_class->set_client_window = gtk_im_multicontext_set_client_window;
100   im_context_class->get_preedit_string = gtk_im_multicontext_get_preedit_string;
101   im_context_class->filter_keypress = gtk_im_multicontext_filter_keypress;
102   im_context_class->focus_in = gtk_im_multicontext_focus_in;
103   im_context_class->focus_out = gtk_im_multicontext_focus_out;
104   im_context_class->reset = gtk_im_multicontext_reset;
105   im_context_class->set_cursor_location = gtk_im_multicontext_set_cursor_location;
106   im_context_class->set_use_preedit = gtk_im_multicontext_set_use_preedit;
107   im_context_class->set_surrounding = gtk_im_multicontext_set_surrounding;
108   im_context_class->get_surrounding = gtk_im_multicontext_get_surrounding;
109
110   gobject_class->finalize = gtk_im_multicontext_finalize;
111
112   g_type_class_add_private (gobject_class, sizeof (GtkIMMulticontextPrivate));   
113 }
114
115 static void
116 gtk_im_multicontext_init (GtkIMMulticontext *multicontext)
117 {
118   multicontext->slave = NULL;
119   
120   multicontext->priv = G_TYPE_INSTANCE_GET_PRIVATE (multicontext, GTK_TYPE_IM_MULTICONTEXT, GtkIMMulticontextPrivate);
121   multicontext->priv->use_preedit = TRUE;
122   multicontext->priv->have_cursor_location = FALSE;
123   multicontext->priv->focus_in = FALSE;
124 }
125
126 /**
127  * gtk_im_multicontext_new:
128  *
129  * Creates a new #GtkIMMulticontext.
130  *
131  * Returns: a new #GtkIMMulticontext.
132  **/
133 GtkIMContext *
134 gtk_im_multicontext_new (void)
135 {
136   return g_object_new (GTK_TYPE_IM_MULTICONTEXT, NULL);
137 }
138
139 static void
140 gtk_im_multicontext_finalize (GObject *object)
141 {
142   GtkIMMulticontext *multicontext = GTK_IM_MULTICONTEXT (object);
143   
144   gtk_im_multicontext_set_slave (multicontext, NULL, TRUE);
145   g_free (multicontext->context_id);
146   g_free (multicontext->priv->context_id);
147
148   G_OBJECT_CLASS (gtk_im_multicontext_parent_class)->finalize (object);
149 }
150
151 static void
152 gtk_im_multicontext_set_slave (GtkIMMulticontext *multicontext,
153                                GtkIMContext      *slave,
154                                gboolean           finalizing)
155 {
156   GtkIMMulticontextPrivate *priv = multicontext->priv;
157   gboolean need_preedit_changed = FALSE;
158   
159   if (multicontext->slave)
160     {
161       if (!finalizing)
162         gtk_im_context_reset (multicontext->slave);
163       
164       g_signal_handlers_disconnect_by_func (multicontext->slave,
165                                             gtk_im_multicontext_preedit_start_cb,
166                                             multicontext);
167       g_signal_handlers_disconnect_by_func (multicontext->slave,
168                                             gtk_im_multicontext_preedit_end_cb,
169                                             multicontext);
170       g_signal_handlers_disconnect_by_func (multicontext->slave,
171                                             gtk_im_multicontext_preedit_changed_cb,
172                                             multicontext);
173       g_signal_handlers_disconnect_by_func (multicontext->slave,
174                                             gtk_im_multicontext_commit_cb,
175                                             multicontext);
176
177       g_object_unref (multicontext->slave);
178       multicontext->slave = NULL;
179
180       if (!finalizing)
181         need_preedit_changed = TRUE;
182     }
183   
184   multicontext->slave = slave;
185
186   if (multicontext->slave)
187     {
188       g_object_ref (multicontext->slave);
189
190       g_signal_connect (multicontext->slave, "preedit-start",
191                         G_CALLBACK (gtk_im_multicontext_preedit_start_cb),
192                         multicontext);
193       g_signal_connect (multicontext->slave, "preedit-end",
194                         G_CALLBACK (gtk_im_multicontext_preedit_end_cb),
195                         multicontext);
196       g_signal_connect (multicontext->slave, "preedit-changed",
197                         G_CALLBACK (gtk_im_multicontext_preedit_changed_cb),
198                         multicontext);
199       g_signal_connect (multicontext->slave, "commit",
200                         G_CALLBACK (gtk_im_multicontext_commit_cb),
201                         multicontext);
202       g_signal_connect (multicontext->slave, "retrieve-surrounding",
203                         G_CALLBACK (gtk_im_multicontext_retrieve_surrounding_cb),
204                         multicontext);
205       g_signal_connect (multicontext->slave, "delete-surrounding",
206                         G_CALLBACK (gtk_im_multicontext_delete_surrounding_cb),
207                         multicontext);
208       
209       if (!priv->use_preedit)   /* Default is TRUE */
210         gtk_im_context_set_use_preedit (slave, FALSE);
211       if (priv->client_window)
212         gtk_im_context_set_client_window (slave, priv->client_window);
213       if (priv->have_cursor_location)
214         gtk_im_context_set_cursor_location (slave, &priv->cursor_location);
215       if (priv->focus_in)
216         gtk_im_context_focus_in (slave);
217     }
218
219   if (need_preedit_changed)
220     g_signal_emit_by_name (multicontext, "preedit-changed");
221 }
222
223 static GtkIMContext *
224 gtk_im_multicontext_get_slave (GtkIMMulticontext *multicontext)
225 {
226   if (!multicontext->slave)
227     {
228       GtkIMContext *slave;
229       
230       g_free (multicontext->context_id);
231        
232       if (multicontext->priv->context_id)
233         multicontext->context_id = g_strdup (multicontext->priv->context_id);
234       else 
235         {
236           if (!global_context_id)
237             global_context_id = _gtk_im_module_get_default_context_id (multicontext->priv->client_window);
238           multicontext->context_id = g_strdup (global_context_id);
239         }
240       slave = _gtk_im_module_create (multicontext->context_id);
241       gtk_im_multicontext_set_slave (multicontext, slave, FALSE);
242       g_object_unref (slave);
243     }
244
245   return multicontext->slave;
246 }
247
248 static void
249 im_module_setting_changed (GtkSettings *settings, 
250                            gpointer     data)
251 {
252   global_context_id = NULL;
253 }
254
255
256 static void
257 gtk_im_multicontext_set_client_window (GtkIMContext *context,
258                                        GdkWindow    *window)
259 {
260   GtkIMMulticontext *multicontext = GTK_IM_MULTICONTEXT (context);
261   GdkScreen *screen; 
262   GtkSettings *settings;
263   gboolean connected;
264
265   multicontext->priv->client_window = window;
266
267   gtk_im_multicontext_set_slave (multicontext, NULL, FALSE);
268
269   if (window == NULL) 
270     return;
271    
272   screen = gdk_drawable_get_screen (GDK_DRAWABLE (window));
273   if (screen)
274     settings = gtk_settings_get_for_screen (screen);
275   else
276     settings = gtk_settings_get_default ();
277
278   connected = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (settings),
279                                                   "gtk-im-module-connected"));
280   if (!connected) 
281     {
282       g_signal_connect (settings, "notify::gtk-im-module",
283                         G_CALLBACK (im_module_setting_changed), NULL);
284       g_object_set_data (G_OBJECT (settings), "gtk-im-module-connected",
285                          GINT_TO_POINTER (TRUE));
286
287       global_context_id = NULL;  
288     }
289 }
290
291 static void
292 gtk_im_multicontext_get_preedit_string (GtkIMContext   *context,
293                                         gchar         **str,
294                                         PangoAttrList **attrs,
295                                         gint           *cursor_pos)
296 {
297   GtkIMMulticontext *multicontext = GTK_IM_MULTICONTEXT (context);
298   GtkIMContext *slave = gtk_im_multicontext_get_slave (multicontext);
299
300   if (slave)
301     gtk_im_context_get_preedit_string (slave, str, attrs, cursor_pos);
302   else
303     {
304       if (str)
305         *str = g_strdup ("");
306       if (attrs)
307         *attrs = pango_attr_list_new ();
308     }
309 }
310
311 static gboolean
312 gtk_im_multicontext_filter_keypress (GtkIMContext *context,
313                                      GdkEventKey  *event)
314 {
315   GtkIMMulticontext *multicontext = GTK_IM_MULTICONTEXT (context);
316   GtkIMContext *slave = gtk_im_multicontext_get_slave (multicontext);
317
318   if (slave)
319     return gtk_im_context_filter_keypress (slave, event);
320   else
321     return FALSE;
322 }
323
324 static void
325 gtk_im_multicontext_focus_in (GtkIMContext   *context)
326 {
327   GtkIMMulticontext *multicontext = GTK_IM_MULTICONTEXT (context);
328   GtkIMContext *slave;
329
330   /* If the global context type is different from the context we were
331    * using before, get rid of the old slave and create a new one
332    * for the new global context type.
333    */
334   if (multicontext->context_id == NULL || 
335       (multicontext->priv->context_id != NULL &&
336        strcmp (multicontext->priv->context_id, multicontext->context_id) != 0) ||
337       (multicontext->priv->context_id == NULL &&
338        (global_context_id == NULL ||
339         strcmp (global_context_id, multicontext->context_id) != 0)))
340     gtk_im_multicontext_set_slave (multicontext, NULL, FALSE);
341
342   slave = gtk_im_multicontext_get_slave (multicontext);
343   
344   multicontext->priv->focus_in = TRUE;
345   
346   if (slave)
347     gtk_im_context_focus_in (slave);
348 }
349
350 static void
351 gtk_im_multicontext_focus_out (GtkIMContext   *context)
352 {
353   GtkIMMulticontext *multicontext = GTK_IM_MULTICONTEXT (context);
354   GtkIMContext *slave = gtk_im_multicontext_get_slave (multicontext);
355
356   multicontext->priv->focus_in = FALSE;
357   
358   if (slave)
359     gtk_im_context_focus_out (slave);
360 }
361
362 static void
363 gtk_im_multicontext_reset (GtkIMContext   *context)
364 {
365   GtkIMMulticontext *multicontext = GTK_IM_MULTICONTEXT (context);
366   GtkIMContext *slave = gtk_im_multicontext_get_slave (multicontext);
367
368   if (slave)
369     gtk_im_context_reset (slave);
370 }
371
372 static void
373 gtk_im_multicontext_set_cursor_location (GtkIMContext   *context,
374                                          GdkRectangle   *area)
375 {
376   GtkIMMulticontext *multicontext = GTK_IM_MULTICONTEXT (context);
377   GtkIMContext *slave = gtk_im_multicontext_get_slave (multicontext);
378
379   multicontext->priv->have_cursor_location = TRUE;
380   multicontext->priv->cursor_location = *area;
381
382   if (slave)
383     gtk_im_context_set_cursor_location (slave, area);
384 }
385
386 static void
387 gtk_im_multicontext_set_use_preedit (GtkIMContext   *context,
388                                      gboolean       use_preedit)
389 {
390   GtkIMMulticontext *multicontext = GTK_IM_MULTICONTEXT (context);
391   GtkIMContext *slave = gtk_im_multicontext_get_slave (multicontext);
392
393   use_preedit = use_preedit != FALSE;
394
395   multicontext->priv->use_preedit = use_preedit;
396
397   if (slave)
398     gtk_im_context_set_use_preedit (slave, use_preedit);
399 }
400
401 static gboolean
402 gtk_im_multicontext_get_surrounding (GtkIMContext  *context,
403                                      gchar        **text,
404                                      gint          *cursor_index)
405 {
406   GtkIMMulticontext *multicontext = GTK_IM_MULTICONTEXT (context);
407   GtkIMContext *slave = gtk_im_multicontext_get_slave (multicontext);
408
409   if (slave)
410     return gtk_im_context_get_surrounding (slave, text, cursor_index);
411   else
412     {
413       if (text)
414         *text = NULL;
415       if (cursor_index)
416         *cursor_index = 0;
417
418       return FALSE;
419     }
420 }
421
422 static void
423 gtk_im_multicontext_set_surrounding (GtkIMContext *context,
424                                      const char   *text,
425                                      gint          len,
426                                      gint          cursor_index)
427 {
428   GtkIMMulticontext *multicontext = GTK_IM_MULTICONTEXT (context);
429   GtkIMContext *slave = gtk_im_multicontext_get_slave (multicontext);
430
431   if (slave)
432     gtk_im_context_set_surrounding (slave, text, len, cursor_index);
433 }
434
435 static void
436 gtk_im_multicontext_preedit_start_cb   (GtkIMContext      *slave,
437                                         GtkIMMulticontext *multicontext)
438 {
439   g_signal_emit_by_name (multicontext, "preedit-start");
440 }
441
442 static void
443 gtk_im_multicontext_preedit_end_cb (GtkIMContext      *slave,
444                                     GtkIMMulticontext *multicontext)
445 {
446   g_signal_emit_by_name (multicontext, "preedit-end");
447 }
448
449 static void
450 gtk_im_multicontext_preedit_changed_cb (GtkIMContext      *slave,
451                                         GtkIMMulticontext *multicontext)
452 {
453   g_signal_emit_by_name (multicontext, "preedit-changed");
454 }
455
456 static void
457 gtk_im_multicontext_commit_cb (GtkIMContext      *slave,
458                                const gchar       *str,
459                                GtkIMMulticontext *multicontext)
460 {
461   g_signal_emit_by_name (multicontext, "commit", str);;
462 }
463
464 static gboolean
465 gtk_im_multicontext_retrieve_surrounding_cb (GtkIMContext      *slave,
466                                              GtkIMMulticontext *multicontext)
467 {
468   gboolean result;
469   
470   g_signal_emit_by_name (multicontext, "retrieve-surrounding", &result);
471
472   return result;
473 }
474
475 static gboolean
476 gtk_im_multicontext_delete_surrounding_cb (GtkIMContext      *slave,
477                                            gint               offset,
478                                            gint               n_chars,
479                                            GtkIMMulticontext *multicontext)
480 {
481   gboolean result;
482   
483   g_signal_emit_by_name (multicontext, "delete-surrounding",
484                          offset, n_chars, &result);
485
486   return result;
487 }
488
489 static void
490 activate_cb (GtkWidget         *menuitem,
491              GtkIMMulticontext *context)
492 {
493   if (GTK_CHECK_MENU_ITEM (menuitem)->active)
494     {
495       const gchar *id = g_object_get_data (G_OBJECT (menuitem), "gtk-context-id");
496
497       gtk_im_multicontext_set_context_id (context, id);
498     }
499 }
500
501 static int
502 pathnamecmp (const char *a,
503              const char *b)
504 {
505 #ifndef G_OS_WIN32
506   return strcmp (a, b);
507 #else
508   /* Ignore case insensitivity, probably not that relevant here. Just
509    * make sure slash and backslash compare equal.
510    */
511   while (*a && *b)
512     if ((G_IS_DIR_SEPARATOR (*a) && G_IS_DIR_SEPARATOR (*b)) ||
513         *a == *b)
514       a++, b++;
515     else
516       return (*a - *b);
517   return (*a - *b);
518 #endif
519 }
520
521 /**
522  * gtk_im_multicontext_append_menuitems:
523  * @context: a #GtkIMMulticontext
524  * @menushell: a #GtkMenuShell
525  * 
526  * Add menuitems for various available input methods to a menu;
527  * the menuitems, when selected, will switch the input method
528  * for the context and the global default input method.
529  **/
530 void
531 gtk_im_multicontext_append_menuitems (GtkIMMulticontext *context,
532                                       GtkMenuShell      *menushell)
533 {
534   const GtkIMContextInfo **contexts;
535   guint n_contexts, i;
536   GSList *group = NULL;
537   GtkWidget *menuitem, *system_menuitem;
538   const char *system_context_id; 
539   
540   system_context_id = _gtk_im_module_get_default_context_id (context->priv->client_window);
541   system_menuitem = menuitem = gtk_radio_menu_item_new_with_label (group, C_("input method menu", "System"));
542   if (!context->priv->context_id)
543     gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem), TRUE);
544   group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menuitem));
545   g_object_set_data (G_OBJECT (menuitem), I_("gtk-context-id"), NULL);
546   g_signal_connect (menuitem, "activate", G_CALLBACK (activate_cb), context);
547
548   gtk_widget_show (menuitem);
549   gtk_menu_shell_append (menushell, menuitem);
550
551   menuitem = gtk_separator_menu_item_new ();
552   gtk_widget_show (menuitem);
553   gtk_menu_shell_append (menushell, menuitem);
554
555   _gtk_im_module_list (&contexts, &n_contexts);
556
557   for (i = 0; i < n_contexts; i++)
558     {
559       const gchar *translated_name;
560 #ifdef ENABLE_NLS
561       if (contexts[i]->domain && contexts[i]->domain[0])
562         {
563           if (strcmp (contexts[i]->domain, GETTEXT_PACKAGE) == 0)
564             {
565               /* Same translation domain as GTK+ */
566               if (!(contexts[i]->domain_dirname && contexts[i]->domain_dirname[0]) ||
567                   pathnamecmp (contexts[i]->domain_dirname, GTK_LOCALEDIR) == 0)
568                 {
569                   /* Empty or NULL, domain directory, or same as
570                    * GTK+. Input method may have a name in the GTK+
571                    * message catalog.
572                    */
573                   translated_name = _(contexts[i]->context_name);
574                 }
575               else
576                 {
577                   /* Separate domain directory but the same
578                    * translation domain as GTK+. We can't call
579                    * bindtextdomain() as that would make GTK+ forget
580                    * its own messages.
581                    */
582                   g_warning ("Input method %s should not use GTK's translation domain %s",
583                              contexts[i]->context_id, GETTEXT_PACKAGE);
584                   /* Try translating the name in GTK+'s domain */
585                   translated_name = _(contexts[i]->context_name);
586                 }
587             }
588           else if (contexts[i]->domain_dirname && contexts[i]->domain_dirname[0])
589             /* Input method has own translation domain and message catalog */
590             {
591               bindtextdomain (contexts[i]->domain,
592                               contexts[i]->domain_dirname);
593 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
594               bind_textdomain_codeset (contexts[i]->domain, "UTF-8");
595 #endif
596               translated_name = g_dgettext (contexts[i]->domain, contexts[i]->context_name);
597             }
598           else
599             {
600               /* Different translation domain, but no domain directory */
601               translated_name = contexts[i]->context_name;
602             }
603         }
604       else
605         /* Empty or NULL domain. We assume that input method does not
606          * want a translated name in this case.
607          */
608         translated_name = contexts[i]->context_name;
609 #else
610       translated_name = contexts[i]->context_name;
611 #endif
612       menuitem = gtk_radio_menu_item_new_with_label (group,
613                                                      translated_name);
614       
615       if ((context->priv->context_id &&
616            strcmp (contexts[i]->context_id, context->priv->context_id) == 0))
617         gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem), TRUE);
618
619       if (strcmp (contexts[i]->context_id, system_context_id) == 0)
620         {
621           GtkWidget *label;
622           char *text;
623
624           label = gtk_bin_get_child (GTK_BIN (system_menuitem));
625           text = g_strdup_printf (C_("input method menu", "System (%s)"), translated_name);
626           gtk_label_set_text (GTK_LABEL (label), text);
627           g_free (text);
628         }     
629  
630       group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menuitem));
631       
632       g_object_set_data (G_OBJECT (menuitem), I_("gtk-context-id"),
633                          (char *)contexts[i]->context_id);
634       g_signal_connect (menuitem, "activate",
635                         G_CALLBACK (activate_cb), context);
636
637       gtk_widget_show (menuitem);
638       gtk_menu_shell_append (menushell, menuitem);
639     }
640
641   g_free (contexts);
642 }
643
644 /**
645  * gtk_im_multicontext_get_context_id:
646  * @context: a #GtkIMMulticontext
647  *
648  * Gets the id of the currently active slave of the @context.
649  *
650  * Returns: the id of the currently active slave
651  *
652  * Since: 2.16
653  */
654 const char *
655 gtk_im_multicontext_get_context_id (GtkIMMulticontext *context)
656 {
657   return context->context_id;
658 }
659
660 /**
661  * gtk_im_multicontext_set_context_id:
662  * @context: a #GtkIMMulticontext
663  * @context_id: the id to use 
664  *
665  * Sets the context id for @context.
666  *
667  * This causes the currently active slave of @context to be
668  * replaced by the slave corresponding to the new context id.
669  *
670  * Since: 2.16
671  */
672 void
673 gtk_im_multicontext_set_context_id (GtkIMMulticontext *context,
674                                     const char        *context_id)
675 {
676   gtk_im_context_reset (GTK_IM_CONTEXT (context));
677   g_free (context->priv->context_id);
678   context->priv->context_id = g_strdup (context_id);
679   gtk_im_multicontext_set_slave (context, NULL, FALSE);
680 }
681
682
683 #define __GTK_IM_MULTICONTEXT_C__
684 #include "gtkaliasdef.c"