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 im_context_signals[PREEDIT_START] =
76 gtk_signal_new ("preedit_start",
78 GTK_CLASS_TYPE (object_class),
79 GTK_SIGNAL_OFFSET (GtkIMContextClass, preedit_start),
80 gtk_marshal_VOID__VOID,
83 im_context_signals[PREEDIT_END] =
84 gtk_signal_new ("preedit_end",
86 GTK_CLASS_TYPE (object_class),
87 GTK_SIGNAL_OFFSET (GtkIMContextClass, preedit_end),
88 gtk_marshal_VOID__VOID,
91 im_context_signals[PREEDIT_CHANGED] =
92 gtk_signal_new ("preedit_changed",
94 GTK_CLASS_TYPE (object_class),
95 GTK_SIGNAL_OFFSET (GtkIMContextClass, preedit_changed),
96 gtk_marshal_VOID__VOID,
99 im_context_signals[COMMIT] =
100 gtk_signal_new ("commit",
102 GTK_CLASS_TYPE (object_class),
103 GTK_SIGNAL_OFFSET (GtkIMContextClass, commit),
104 gtk_marshal_VOID__POINTER,
108 klass->get_preedit_string = gtk_im_context_real_get_preedit_string;
109 klass->filter_keypress = gtk_im_context_real_filter_keypress;
111 gtk_object_class_add_signals (object_class, im_context_signals, LAST_SIGNAL);
115 gtk_im_context_init (GtkIMContext *im_context)
120 gtk_im_context_real_get_preedit_string (GtkIMContext *context,
122 PangoAttrList **attrs,
126 *str = g_strdup ("");
128 *attrs = pango_attr_list_new ();
134 gtk_im_context_real_filter_keypress (GtkIMContext *context,
141 * gtk_im_context_set_client_window:
142 * @context: a #GtkIMContext
143 * @window: the client window. This may be %NULL to indicate
144 * that the previous client window no longer exists.
146 * Set the client window for the input context; this is the
147 * #GdkWindow in which the input appears. This window is
148 * used in order to correctly position status windows, and may
149 * also be used for purposes internal to the input method.
152 gtk_im_context_set_client_window (GtkIMContext *context,
155 GtkIMContextClass *klass;
157 g_return_if_fail (context != NULL);
158 g_return_if_fail (GTK_IS_IM_CONTEXT (context));
160 klass = GTK_IM_CONTEXT_GET_CLASS (context);
161 if (klass->set_client_window)
162 klass->set_client_window (context, window);
166 * gtk_im_context_get_preedit_string:
167 * @context: a #GtkIMContext
168 * @str: location to store the retrieved string. The
169 * string retrieved must be freed with g_free ().
170 * @attrs: location to store the retrieved attribute list.
171 * When you are done with this list, you must
172 * unreference it with pango_attr_list_unref().
173 * @cursor_pos: location to store position of cursor (in bytes)
174 * within the preedit string.
176 * Retrieve the current preedit string for the input context,
177 * and a list of attributes to apply to the string.
178 * This string should be displayed inserted at the insertion
182 gtk_im_context_get_preedit_string (GtkIMContext *context,
184 PangoAttrList **attrs,
187 GtkIMContextClass *klass;
189 g_return_if_fail (context != NULL);
190 g_return_if_fail (GTK_IS_IM_CONTEXT (context));
192 klass = GTK_IM_CONTEXT_GET_CLASS (context);
193 klass->get_preedit_string (context, str, attrs, cursor_pos);
194 g_return_if_fail (str == NULL || g_utf8_validate (*str, -1, NULL));
198 * gtk_im_context_filter_keypress:
199 * @context: a #GtkIMContext
200 * @event: the key event
202 * Allow an input method to internally handle a key press event.
203 * if this function returns %TRUE, then no further processing
204 * should be done for this keystroke.
206 * Return value: %TRUE if the input method handled the keystroke.
210 gtk_im_context_filter_keypress (GtkIMContext *context,
213 GtkIMContextClass *klass;
215 g_return_val_if_fail (context != NULL, FALSE);
216 g_return_val_if_fail (GTK_IS_IM_CONTEXT (context), FALSE);
217 g_return_val_if_fail (key != NULL, FALSE);
219 klass = GTK_IM_CONTEXT_GET_CLASS (context);
220 return klass->filter_keypress (context, key);
224 * gtk_im_context_focus_in:
225 * @context: a #GtkIMContext
227 * Notify the input method that the widget to which this
228 * input context corresponds has lost gained. The input method
229 * may, for example, change the displayed feedback to reflect
233 gtk_im_context_focus_in (GtkIMContext *context)
235 GtkIMContextClass *klass;
237 g_return_if_fail (context != NULL);
238 g_return_if_fail (GTK_IS_IM_CONTEXT (context));
240 klass = GTK_IM_CONTEXT_GET_CLASS (context);
242 klass->focus_in (context);
246 * gtk_im_context_focus_out:
247 * @context: a #GtkIMContext
249 * Notify the input method that the widget to which this
250 * input context corresponds has lost focus. The input method
251 * may, for example, change the displayed feedback or reset the contexts
252 * state to reflect this change.
255 gtk_im_context_focus_out (GtkIMContext *context)
257 GtkIMContextClass *klass;
259 g_return_if_fail (context != NULL);
260 g_return_if_fail (GTK_IS_IM_CONTEXT (context));
262 klass = GTK_IM_CONTEXT_GET_CLASS (context);
263 if (klass->focus_out)
264 klass->focus_out (context);
268 * gtk_im_context_reset:
269 * @context: a #GtkIMContext
271 * Notify the input method that a change such as a change in cursor
272 * position has been made. This will typically cause the input
273 * method to clear the preedit state.
276 gtk_im_context_reset (GtkIMContext *context)
278 GtkIMContextClass *klass;
280 g_return_if_fail (context != NULL);
281 g_return_if_fail (GTK_IS_IM_CONTEXT (context));
283 klass = GTK_IM_CONTEXT_GET_CLASS (context);
285 klass->reset (context);