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 Library 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 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library 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.
20 #include "gtkimcontext.h"
21 #include "gtksignal.h"
31 static guint im_context_signals[LAST_SIGNAL] = { 0 };
33 static void gtk_im_context_class_init (GtkIMContextClass *class);
34 static void gtk_im_context_init (GtkIMContext *im_context);
36 static void gtk_im_context_real_get_preedit_string (GtkIMContext *context,
38 PangoAttrList **attrs);
39 static gboolean gtk_im_context_real_filter_keypress (GtkIMContext *context,
43 gtk_im_context_get_type (void)
45 static GtkType im_context_type = 0;
49 static const GtkTypeInfo im_context_info =
52 sizeof (GtkIMContext),
53 sizeof (GtkIMContextClass),
54 (GtkClassInitFunc) gtk_im_context_class_init,
55 (GtkObjectInitFunc) gtk_im_context_init,
56 /* reserved_1 */ NULL,
57 /* reserved_2 */ NULL,
58 (GtkClassInitFunc) NULL,
61 im_context_type = gtk_type_unique (GTK_TYPE_OBJECT, &im_context_info);
64 return im_context_type;
68 gtk_im_context_class_init (GtkIMContextClass *klass)
70 GtkObjectClass *object_class;
72 object_class = (GtkObjectClass*) klass;
74 im_context_signals[PREEDIT_START] =
75 gtk_signal_new ("preedit_start",
77 GTK_CLASS_TYPE (object_class),
78 GTK_SIGNAL_OFFSET (GtkIMContextClass, preedit_start),
79 gtk_marshal_NONE__NONE,
82 im_context_signals[PREEDIT_END] =
83 gtk_signal_new ("preedit_end",
85 GTK_CLASS_TYPE (object_class),
86 GTK_SIGNAL_OFFSET (GtkIMContextClass, preedit_end),
87 gtk_marshal_NONE__NONE,
90 im_context_signals[PREEDIT_CHANGED] =
91 gtk_signal_new ("preedit_changed",
93 GTK_CLASS_TYPE (object_class),
94 GTK_SIGNAL_OFFSET (GtkIMContextClass, preedit_changed),
95 gtk_marshal_NONE__NONE,
98 im_context_signals[COMMIT] =
99 gtk_signal_new ("commit",
101 GTK_CLASS_TYPE (object_class),
102 GTK_SIGNAL_OFFSET (GtkIMContextClass, commit),
103 gtk_marshal_NONE__STRING,
107 klass->get_preedit_string = gtk_im_context_real_get_preedit_string;
108 klass->filter_keypress = gtk_im_context_real_filter_keypress;
110 gtk_object_class_add_signals (object_class, im_context_signals, LAST_SIGNAL);
114 gtk_im_context_init (GtkIMContext *im_context)
119 gtk_im_context_real_get_preedit_string (GtkIMContext *context,
121 PangoAttrList **attrs)
124 *str = g_strdup ("");
126 *attrs = pango_attr_list_new ();
130 gtk_im_context_real_filter_keypress (GtkIMContext *context,
137 * gtk_im_context_set_client_window:
138 * @context: a #GtkIMContext
139 * @window: the client window. This may be %NULL to indicate
140 * that the previous client window no longer exists.
142 * Set the client window for the input context; this is the
143 * #GdkWindow in which the input appears. This window is
144 * used in order to correctly position status windows, and may
145 * also be used for purposes internal to the input method.
148 gtk_im_context_set_client_window (GtkIMContext *context,
151 GtkIMContextClass *klass;
153 g_return_if_fail (context != NULL);
154 g_return_if_fail (GTK_IS_IM_CONTEXT (context));
156 klass = GTK_IM_CONTEXT_GET_CLASS (context);
157 if (klass->set_client_window)
158 klass->set_client_window (context, window);
162 * gtk_im_context_get_preedit_string:
163 * @context: a #GtkIMContext
164 * @str: location to store the retrieved string. The
165 * string retrieved must be freed with g_free ().
166 * @attrs: location to store the retrieved attribute list.
167 * When you are done with this list, you must
168 * unreference it with pango_attr_list_unref().
170 * Retrieve the current preedit string for the input context,
171 * and a list of attributes to apply to the string.
172 * This string should be displayed inserted at the insertion
176 gtk_im_context_get_preedit_string (GtkIMContext *context,
178 PangoAttrList **attrs)
180 GtkIMContextClass *klass;
182 g_return_if_fail (context != NULL);
183 g_return_if_fail (GTK_IS_IM_CONTEXT (context));
185 klass = GTK_IM_CONTEXT_GET_CLASS (context);
186 klass->get_preedit_string (context, str, attrs);
190 * gtk_im_context_filter_keypress:
191 * @context: a #GtkIMContext
192 * @key: the key event
194 * Allow an input method to internally handle a key press event.
195 * if this function returns %TRUE, then no further processing
196 * should be done for this keystroke.
198 * Return value: %TRUE if the input method handled the keystroke.
202 gtk_im_context_filter_keypress (GtkIMContext *context,
205 GtkIMContextClass *klass;
207 g_return_val_if_fail (context != NULL, FALSE);
208 g_return_val_if_fail (GTK_IS_IM_CONTEXT (context), FALSE);
209 g_return_val_if_fail (key != NULL, FALSE);
211 klass = GTK_IM_CONTEXT_GET_CLASS (context);
212 return klass->filter_keypress (context, key);
216 * gtk_im_context_focus_in:
217 * @context: a #GtkIMContext
219 * Notify the input method that the widget to which this
220 * input context corresponds has lost gained. The input method
221 * may, for example, change the displayed feedback to reflect
225 gtk_im_context_focus_in (GtkIMContext *context)
227 GtkIMContextClass *klass;
229 g_return_if_fail (context != NULL);
230 g_return_if_fail (GTK_IS_IM_CONTEXT (context));
232 klass = GTK_IM_CONTEXT_GET_CLASS (context);
234 klass->focus_in (context);
238 * gtk_im_context_focus_in:
239 * @context: a #GtkIMContext
241 * Notify the input method that the widget to which this
242 * input context corresponds has lost focus. The input method
243 * may, for example, change the displayed feedback or reset the contexts
244 * state to reflect this change.
247 gtk_im_context_focus_out (GtkIMContext *context)
249 GtkIMContextClass *klass;
251 g_return_if_fail (context != NULL);
252 g_return_if_fail (GTK_IS_IM_CONTEXT (context));
254 klass = GTK_IM_CONTEXT_GET_CLASS (context);
255 if (klass->focus_out)
256 klass->focus_out (context);