]> Pileus Git - ~andy/gtk/blob - gtk/gtkimcontext.c
Remove all references to offscreen flag which was no longer used.
[~andy/gtk] / gtk / gtkimcontext.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 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.
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  * Library General Public License for more details.
13  *
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.
18  */
19
20 #include "gtkimcontext.h"
21 #include "gtksignal.h"
22
23 enum {
24   PREEDIT_START,
25   PREEDIT_END,
26   PREEDIT_CHANGED,
27   COMMIT,
28   LAST_SIGNAL
29 };
30
31 static guint im_context_signals[LAST_SIGNAL] = { 0 };
32
33 static void gtk_im_context_class_init (GtkIMContextClass *class);
34 static void gtk_im_context_init (GtkIMContext *im_context);
35
36 static void     gtk_im_context_real_get_preedit_string (GtkIMContext       *context,
37                                                         gchar             **str,
38                                                         PangoAttrList     **attrs);
39 static gboolean gtk_im_context_real_filter_keypress    (GtkIMContext       *context,
40                                                         GdkEventKey        *event);
41
42 GtkType
43 gtk_im_context_get_type (void)
44 {
45   static GtkType im_context_type = 0;
46
47   if (!im_context_type)
48     {
49       static const GtkTypeInfo im_context_info =
50       {
51         "GtkIMContext",
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,
59       };
60
61       im_context_type = gtk_type_unique (GTK_TYPE_OBJECT, &im_context_info);
62     }
63
64   return im_context_type;
65 }
66
67 static void
68 gtk_im_context_class_init (GtkIMContextClass *klass)
69 {
70   GtkObjectClass *object_class;
71   
72   object_class = (GtkObjectClass*) klass;
73
74   im_context_signals[PREEDIT_START] =
75     gtk_signal_new ("preedit_start",
76                     GTK_RUN_LAST,
77                     GTK_CLASS_TYPE (object_class),
78                     GTK_SIGNAL_OFFSET (GtkIMContextClass, preedit_start),
79                     gtk_marshal_NONE__NONE,
80                     GTK_TYPE_NONE, 0);
81   
82   im_context_signals[PREEDIT_END] =
83     gtk_signal_new ("preedit_end",
84                     GTK_RUN_LAST,
85                     GTK_CLASS_TYPE (object_class),
86                     GTK_SIGNAL_OFFSET (GtkIMContextClass, preedit_end),
87                     gtk_marshal_NONE__NONE,
88                     GTK_TYPE_NONE, 0);
89   
90   im_context_signals[PREEDIT_CHANGED] =
91     gtk_signal_new ("preedit_changed",
92                     GTK_RUN_LAST,
93                     GTK_CLASS_TYPE (object_class),
94                     GTK_SIGNAL_OFFSET (GtkIMContextClass, preedit_changed),
95                     gtk_marshal_NONE__NONE,
96                     GTK_TYPE_NONE, 0);
97   
98   im_context_signals[COMMIT] =
99     gtk_signal_new ("commit",
100                     GTK_RUN_LAST,
101                     GTK_CLASS_TYPE (object_class),
102                     GTK_SIGNAL_OFFSET (GtkIMContextClass, commit),
103                     gtk_marshal_NONE__STRING,
104                     GTK_TYPE_NONE, 1,
105                     GTK_TYPE_STRING);
106
107   klass->get_preedit_string = gtk_im_context_real_get_preedit_string;
108   klass->filter_keypress = gtk_im_context_real_filter_keypress;
109   
110   gtk_object_class_add_signals (object_class, im_context_signals, LAST_SIGNAL);
111 }
112
113 static void
114 gtk_im_context_init (GtkIMContext *im_context)
115 {
116 }
117
118 static void
119 gtk_im_context_real_get_preedit_string (GtkIMContext       *context,
120                                         gchar             **str,
121                                         PangoAttrList     **attrs)
122 {
123   if (str)
124     *str = g_strdup ("");
125   if (attrs)
126     *attrs = pango_attr_list_new ();
127 }
128
129 static gboolean
130 gtk_im_context_real_filter_keypress (GtkIMContext       *context,
131                                      GdkEventKey        *event)
132 {
133   return FALSE;
134 }
135
136 /**
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.
141  * 
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.
146  **/
147 void
148 gtk_im_context_set_client_window (GtkIMContext *context,
149                                   GdkWindow    *window)
150 {
151   GtkIMContextClass *klass;
152   
153   g_return_if_fail (context != NULL);
154   g_return_if_fail (GTK_IS_IM_CONTEXT (context));
155
156   klass = GTK_IM_CONTEXT_GET_CLASS (context);
157   if (klass->set_client_window)
158     klass->set_client_window (context, window);
159 }
160
161 /**
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().
169  * 
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
173  * point.
174  **/
175 void
176 gtk_im_context_get_preedit_string (GtkIMContext   *context,
177                                    gchar         **str,
178                                    PangoAttrList **attrs)
179 {
180   GtkIMContextClass *klass;
181   
182   g_return_if_fail (context != NULL);
183   g_return_if_fail (GTK_IS_IM_CONTEXT (context));
184   
185   klass = GTK_IM_CONTEXT_GET_CLASS (context);
186   klass->get_preedit_string (context, str, attrs);
187 }
188
189 /**
190  * gtk_im_context_filter_keypress:
191  * @context: a #GtkIMContext
192  * @key: the key event
193  * 
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.
197  * 
198  * Return value: %TRUE if the input method handled the keystroke.
199  *
200  **/
201 gboolean
202 gtk_im_context_filter_keypress (GtkIMContext *context,
203                                 GdkEventKey  *key)
204 {
205   GtkIMContextClass *klass;
206   
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);
210
211   klass = GTK_IM_CONTEXT_GET_CLASS (context);
212   return klass->filter_keypress (context, key);
213 }
214
215 /**
216  * gtk_im_context_focus_in:
217  * @context: a #GtkIMContext
218  *
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
222  * this change.
223  **/
224 void
225 gtk_im_context_focus_in (GtkIMContext   *context)
226 {
227   GtkIMContextClass *klass;
228   
229   g_return_if_fail (context != NULL);
230   g_return_if_fail (GTK_IS_IM_CONTEXT (context));
231   
232   klass = GTK_IM_CONTEXT_GET_CLASS (context);
233   if (klass->focus_in)
234     klass->focus_in (context);
235 }
236
237 /**
238  * gtk_im_context_focus_in:
239  * @context: a #GtkIMContext
240  *
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.
245  **/
246 void
247 gtk_im_context_focus_out (GtkIMContext   *context)
248 {
249   GtkIMContextClass *klass;
250   
251   g_return_if_fail (context != NULL);
252   g_return_if_fail (GTK_IS_IM_CONTEXT (context));
253
254   klass = GTK_IM_CONTEXT_GET_CLASS (context);
255   if (klass->focus_out)
256     klass->focus_out (context);
257 }
258
259