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.
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,
40 static gboolean gtk_im_context_real_filter_keypress (GtkIMContext *context,
44 gtk_im_context_get_type (void)
46 static GtkType im_context_type = 0;
50 static const GtkTypeInfo im_context_info =
53 sizeof (GtkIMContext),
54 sizeof (GtkIMContextClass),
55 (GtkClassInitFunc) gtk_im_context_class_init,
56 (GtkObjectInitFunc) gtk_im_context_init,
57 /* reserved_1 */ NULL,
58 /* reserved_2 */ NULL,
59 (GtkClassInitFunc) NULL,
62 im_context_type = gtk_type_unique (GTK_TYPE_OBJECT, &im_context_info);
65 return im_context_type;
69 gtk_im_context_class_init (GtkIMContextClass *klass)
71 GtkObjectClass *object_class;
73 object_class = (GtkObjectClass*) klass;
75 klass->get_preedit_string = gtk_im_context_real_get_preedit_string;
76 klass->filter_keypress = gtk_im_context_real_filter_keypress;
78 im_context_signals[PREEDIT_START] =
79 gtk_signal_new ("preedit_start",
81 GTK_CLASS_TYPE (object_class),
82 GTK_SIGNAL_OFFSET (GtkIMContextClass, preedit_start),
83 gtk_marshal_VOID__VOID,
86 im_context_signals[PREEDIT_END] =
87 gtk_signal_new ("preedit_end",
89 GTK_CLASS_TYPE (object_class),
90 GTK_SIGNAL_OFFSET (GtkIMContextClass, preedit_end),
91 gtk_marshal_VOID__VOID,
94 im_context_signals[PREEDIT_CHANGED] =
95 gtk_signal_new ("preedit_changed",
97 GTK_CLASS_TYPE (object_class),
98 GTK_SIGNAL_OFFSET (GtkIMContextClass, preedit_changed),
99 gtk_marshal_VOID__VOID,
102 im_context_signals[COMMIT] =
103 gtk_signal_new ("commit",
105 GTK_CLASS_TYPE (object_class),
106 GTK_SIGNAL_OFFSET (GtkIMContextClass, commit),
107 gtk_marshal_VOID__STRING,
113 gtk_im_context_init (GtkIMContext *im_context)
118 gtk_im_context_real_get_preedit_string (GtkIMContext *context,
120 PangoAttrList **attrs,
124 *str = g_strdup ("");
126 *attrs = pango_attr_list_new ();
132 gtk_im_context_real_filter_keypress (GtkIMContext *context,
139 * gtk_im_context_set_client_window:
140 * @context: a #GtkIMContext
141 * @window: the client window. This may be %NULL to indicate
142 * that the previous client window no longer exists.
144 * Set the client window for the input context; this is the
145 * #GdkWindow in which the input appears. This window is
146 * used in order to correctly position status windows, and may
147 * also be used for purposes internal to the input method.
150 gtk_im_context_set_client_window (GtkIMContext *context,
153 GtkIMContextClass *klass;
155 g_return_if_fail (GTK_IS_IM_CONTEXT (context));
157 klass = GTK_IM_CONTEXT_GET_CLASS (context);
158 if (klass->set_client_window)
159 klass->set_client_window (context, window);
163 * gtk_im_context_get_preedit_string:
164 * @context: a #GtkIMContext
165 * @str: location to store the retrieved string. The
166 * string retrieved must be freed with g_free ().
167 * @attrs: location to store the retrieved attribute list.
168 * When you are done with this list, you must
169 * unreference it with pango_attr_list_unref().
170 * @cursor_pos: location to store position of cursor (in bytes)
171 * within the preedit string.
173 * Retrieve the current preedit string for the input context,
174 * and a list of attributes to apply to the string.
175 * This string should be displayed inserted at the insertion
179 gtk_im_context_get_preedit_string (GtkIMContext *context,
181 PangoAttrList **attrs,
184 GtkIMContextClass *klass;
186 g_return_if_fail (GTK_IS_IM_CONTEXT (context));
188 klass = GTK_IM_CONTEXT_GET_CLASS (context);
189 klass->get_preedit_string (context, str, attrs, cursor_pos);
190 g_return_if_fail (str == NULL || g_utf8_validate (*str, -1, NULL));
194 * gtk_im_context_filter_keypress:
195 * @context: a #GtkIMContext
196 * @event: the key event
198 * Allow an input method to internally handle a key press event.
199 * if this function returns %TRUE, then no further processing
200 * should be done for this keystroke.
202 * Return value: %TRUE if the input method handled the keystroke.
206 gtk_im_context_filter_keypress (GtkIMContext *context,
209 GtkIMContextClass *klass;
211 g_return_val_if_fail (GTK_IS_IM_CONTEXT (context), FALSE);
212 g_return_val_if_fail (key != NULL, FALSE);
214 klass = GTK_IM_CONTEXT_GET_CLASS (context);
215 return klass->filter_keypress (context, key);
219 * gtk_im_context_focus_in:
220 * @context: a #GtkIMContext
222 * Notify the input method that the widget to which this
223 * input context corresponds has lost gained. The input method
224 * may, for example, change the displayed feedback to reflect
228 gtk_im_context_focus_in (GtkIMContext *context)
230 GtkIMContextClass *klass;
232 g_return_if_fail (GTK_IS_IM_CONTEXT (context));
234 klass = GTK_IM_CONTEXT_GET_CLASS (context);
236 klass->focus_in (context);
240 * gtk_im_context_focus_out:
241 * @context: a #GtkIMContext
243 * Notify the input method that the widget to which this
244 * input context corresponds has lost focus. The input method
245 * may, for example, change the displayed feedback or reset the contexts
246 * state to reflect this change.
249 gtk_im_context_focus_out (GtkIMContext *context)
251 GtkIMContextClass *klass;
253 g_return_if_fail (GTK_IS_IM_CONTEXT (context));
255 klass = GTK_IM_CONTEXT_GET_CLASS (context);
256 if (klass->focus_out)
257 klass->focus_out (context);
261 * gtk_im_context_reset:
262 * @context: a #GtkIMContext
264 * Notify the input method that a change such as a change in cursor
265 * position has been made. This will typically cause the input
266 * method to clear the preedit state.
269 gtk_im_context_reset (GtkIMContext *context)
271 GtkIMContextClass *klass;
273 g_return_if_fail (GTK_IS_IM_CONTEXT (context));
275 klass = GTK_IM_CONTEXT_GET_CLASS (context);
277 klass->reset (context);
282 * gtk_im_context_set_cursor_location:
283 * @context: a #GtkIMContext
284 * @area: new location
286 * Notify the input method that a change in cursor
287 * position has been made.
290 gtk_im_context_set_cursor_location (GtkIMContext *context,
293 GtkIMContextClass *klass;
295 g_return_if_fail (GTK_IS_IM_CONTEXT (context));
297 klass = GTK_IM_CONTEXT_GET_CLASS (context);
298 if (klass->set_cursor_location)
299 klass->set_cursor_location (context, area);
303 * gtk_im_context_set_use_preedit:
304 * @context: a #GtkIMContext
305 * @use_preedit: whether the IM context should use the preedit string.
307 * Sets whether the IM context should use the preedit string
308 * to display feedback. If @use_preedit is FALSE (default
309 * is TRUE), then the IM context may use some other method to display
310 * feedback, such as displaying it in a child of the root window.
313 gtk_im_context_set_use_preedit (GtkIMContext *context,
314 gboolean use_preedit)
316 GtkIMContextClass *klass;
318 g_return_if_fail (GTK_IS_IM_CONTEXT (context));
320 klass = GTK_IM_CONTEXT_GET_CLASS (context);
321 if (klass->set_use_preedit)
322 klass->set_use_preedit (context, use_preedit);