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 (context != NULL);
156 g_return_if_fail (GTK_IS_IM_CONTEXT (context));
158 klass = GTK_IM_CONTEXT_GET_CLASS (context);
159 if (klass->set_client_window)
160 klass->set_client_window (context, window);
164 * gtk_im_context_get_preedit_string:
165 * @context: a #GtkIMContext
166 * @str: location to store the retrieved string. The
167 * string retrieved must be freed with g_free ().
168 * @attrs: location to store the retrieved attribute list.
169 * When you are done with this list, you must
170 * unreference it with pango_attr_list_unref().
171 * @cursor_pos: location to store position of cursor (in bytes)
172 * within the preedit string.
174 * Retrieve the current preedit string for the input context,
175 * and a list of attributes to apply to the string.
176 * This string should be displayed inserted at the insertion
180 gtk_im_context_get_preedit_string (GtkIMContext *context,
182 PangoAttrList **attrs,
185 GtkIMContextClass *klass;
187 g_return_if_fail (context != NULL);
188 g_return_if_fail (GTK_IS_IM_CONTEXT (context));
190 klass = GTK_IM_CONTEXT_GET_CLASS (context);
191 klass->get_preedit_string (context, str, attrs, cursor_pos);
192 g_return_if_fail (str == NULL || g_utf8_validate (*str, -1, NULL));
196 * gtk_im_context_filter_keypress:
197 * @context: a #GtkIMContext
198 * @event: the key event
200 * Allow an input method to internally handle a key press event.
201 * if this function returns %TRUE, then no further processing
202 * should be done for this keystroke.
204 * Return value: %TRUE if the input method handled the keystroke.
208 gtk_im_context_filter_keypress (GtkIMContext *context,
211 GtkIMContextClass *klass;
213 g_return_val_if_fail (context != NULL, FALSE);
214 g_return_val_if_fail (GTK_IS_IM_CONTEXT (context), FALSE);
215 g_return_val_if_fail (key != NULL, FALSE);
217 klass = GTK_IM_CONTEXT_GET_CLASS (context);
218 return klass->filter_keypress (context, key);
222 * gtk_im_context_focus_in:
223 * @context: a #GtkIMContext
225 * Notify the input method that the widget to which this
226 * input context corresponds has lost gained. The input method
227 * may, for example, change the displayed feedback to reflect
231 gtk_im_context_focus_in (GtkIMContext *context)
233 GtkIMContextClass *klass;
235 g_return_if_fail (context != NULL);
236 g_return_if_fail (GTK_IS_IM_CONTEXT (context));
238 klass = GTK_IM_CONTEXT_GET_CLASS (context);
240 klass->focus_in (context);
244 * gtk_im_context_focus_out:
245 * @context: a #GtkIMContext
247 * Notify the input method that the widget to which this
248 * input context corresponds has lost focus. The input method
249 * may, for example, change the displayed feedback or reset the contexts
250 * state to reflect this change.
253 gtk_im_context_focus_out (GtkIMContext *context)
255 GtkIMContextClass *klass;
257 g_return_if_fail (context != NULL);
258 g_return_if_fail (GTK_IS_IM_CONTEXT (context));
260 klass = GTK_IM_CONTEXT_GET_CLASS (context);
261 if (klass->focus_out)
262 klass->focus_out (context);
266 * gtk_im_context_reset:
267 * @context: a #GtkIMContext
269 * Notify the input method that a change such as a change in cursor
270 * position has been made. This will typically cause the input
271 * method to clear the preedit state.
274 gtk_im_context_reset (GtkIMContext *context)
276 GtkIMContextClass *klass;
278 g_return_if_fail (context != NULL);
279 g_return_if_fail (GTK_IS_IM_CONTEXT (context));
281 klass = GTK_IM_CONTEXT_GET_CLASS (context);
283 klass->reset (context);
288 * gtk_im_context_set_cursor_location:
289 * @context: a #GtkIMContext
290 * @area: new location
292 * Notify the input method that a change in cursor
293 * position has been made.
296 gtk_im_context_set_cursor_location (GtkIMContext *context,
299 GtkIMContextClass *klass;
301 g_return_if_fail (context != NULL);
302 g_return_if_fail (GTK_IS_IM_CONTEXT (context));
304 klass = GTK_IM_CONTEXT_GET_CLASS (context);
305 if (klass->set_cursor_location)
306 klass->set_cursor_location (context, area);