]> Pileus Git - ~andy/gtk/blob - gdk/gdkkeys.c
after allocating the treedatalist, zero it to make sure the values are
[~andy/gtk] / gdk / gdkkeys.c
1 /* GDK - The GIMP Drawing Kit
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 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.
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  * Lesser General Public License for more details.
13  *
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.
18  */
19
20 /*
21  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
22  * file for a list of people on the GTK+ Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
25  */
26
27 #include "gdkkeys.h"
28 #include <config.h>
29
30 enum {
31   DIRECTION_CHANGED,
32   LAST_SIGNAL
33 };
34
35 static void gdk_keymap_init       (GdkKeymap      *keymap);
36 static void gdk_keymap_class_init (GdkKeymapClass *klass);
37
38 static gpointer parent_class = NULL;
39
40 static guint signals[LAST_SIGNAL] = { 0 };
41
42 GType
43 gdk_keymap_get_type (void)
44 {
45   static GType object_type = 0;
46
47   if (!object_type)
48     {
49       static const GTypeInfo object_info =
50       {
51         sizeof (GdkKeymapClass),
52         (GBaseInitFunc) NULL,
53         (GBaseFinalizeFunc) NULL,
54         (GClassInitFunc) gdk_keymap_class_init,
55         NULL,           /* class_finalize */
56         NULL,           /* class_data */
57         sizeof (GdkKeymap),
58         0,              /* n_preallocs */
59         (GInstanceInitFunc) gdk_keymap_init,
60       };
61       
62       object_type = g_type_register_static (G_TYPE_OBJECT,
63                                             "GdkKeymap",
64                                             &object_info, 0);
65     }
66   
67   return object_type;
68 }
69
70 static void
71 gdk_keymap_init (GdkKeymap *keymap)
72 {
73
74 }
75
76 static void
77 gdk_keymap_class_init (GdkKeymapClass *klass)
78 {
79   GObjectClass *object_class = G_OBJECT_CLASS (klass);
80
81   parent_class = g_type_class_peek_parent (klass);
82
83   signals[DIRECTION_CHANGED] =
84     g_signal_new ("direction_changed",
85                   G_OBJECT_CLASS_TYPE (object_class),
86                   G_SIGNAL_RUN_LAST,
87                   G_STRUCT_OFFSET (GdkKeymapClass, direction_changed),
88                   NULL, NULL,
89                   g_cclosure_marshal_VOID__VOID,
90                   G_TYPE_NONE,
91                   0);
92 }
93
94 /* Other key-handling stuff
95  */
96
97 #ifndef HAVE_XCONVERTCASE
98 /* compatibility function from X11R6.3, since XConvertCase is not
99  * supplied by X11R5.
100  */
101 /**
102  * gdk_keyval_convert_case:
103  * @symbol: a keyval
104  * @lower: return location for lowercase version of @symbol
105  * @upper: return location for uppercase version of @symbol
106  *
107  * Obtains the upper- and lower-case versions of the keyval @symbol.
108  * Examples of keyvals are #GDK_a, #GDK_Enter, #GDK_F1, etc.
109  * 
110  **/
111 void
112 gdk_keyval_convert_case (guint symbol,
113                          guint *lower,
114                          guint *upper)
115 {
116   guint xlower = symbol;
117   guint xupper = symbol;
118
119   switch (symbol >> 8)
120     {
121 #if     defined (GDK_A) && defined (GDK_Ooblique)
122     case 0: /* Latin 1 */
123       if ((symbol >= GDK_A) && (symbol <= GDK_Z))
124         xlower += (GDK_a - GDK_A);
125       else if ((symbol >= GDK_a) && (symbol <= GDK_z))
126         xupper -= (GDK_a - GDK_A);
127       else if ((symbol >= GDK_Agrave) && (symbol <= GDK_Odiaeresis))
128         xlower += (GDK_agrave - GDK_Agrave);
129       else if ((symbol >= GDK_agrave) && (symbol <= GDK_odiaeresis))
130         xupper -= (GDK_agrave - GDK_Agrave);
131       else if ((symbol >= GDK_Ooblique) && (symbol <= GDK_Thorn))
132         xlower += (GDK_oslash - GDK_Ooblique);
133       else if ((symbol >= GDK_oslash) && (symbol <= GDK_thorn))
134         xupper -= (GDK_oslash - GDK_Ooblique);
135       break;
136 #endif  /* LATIN1 */
137       
138 #if     defined (GDK_Aogonek) && defined (GDK_tcedilla)
139     case 1: /* Latin 2 */
140       /* Assume the KeySym is a legal value (ignore discontinuities) */
141       if (symbol == GDK_Aogonek)
142         xlower = GDK_aogonek;
143       else if (symbol >= GDK_Lstroke && symbol <= GDK_Sacute)
144         xlower += (GDK_lstroke - GDK_Lstroke);
145       else if (symbol >= GDK_Scaron && symbol <= GDK_Zacute)
146         xlower += (GDK_scaron - GDK_Scaron);
147       else if (symbol >= GDK_Zcaron && symbol <= GDK_Zabovedot)
148         xlower += (GDK_zcaron - GDK_Zcaron);
149       else if (symbol == GDK_aogonek)
150         xupper = GDK_Aogonek;
151       else if (symbol >= GDK_lstroke && symbol <= GDK_sacute)
152         xupper -= (GDK_lstroke - GDK_Lstroke);
153       else if (symbol >= GDK_scaron && symbol <= GDK_zacute)
154         xupper -= (GDK_scaron - GDK_Scaron);
155       else if (symbol >= GDK_zcaron && symbol <= GDK_zabovedot)
156         xupper -= (GDK_zcaron - GDK_Zcaron);
157       else if (symbol >= GDK_Racute && symbol <= GDK_Tcedilla)
158         xlower += (GDK_racute - GDK_Racute);
159       else if (symbol >= GDK_racute && symbol <= GDK_tcedilla)
160         xupper -= (GDK_racute - GDK_Racute);
161       break;
162 #endif  /* LATIN2 */
163       
164 #if     defined (GDK_Hstroke) && defined (GDK_Cabovedot)
165     case 2: /* Latin 3 */
166       /* Assume the KeySym is a legal value (ignore discontinuities) */
167       if (symbol >= GDK_Hstroke && symbol <= GDK_Hcircumflex)
168         xlower += (GDK_hstroke - GDK_Hstroke);
169       else if (symbol >= GDK_Gbreve && symbol <= GDK_Jcircumflex)
170         xlower += (GDK_gbreve - GDK_Gbreve);
171       else if (symbol >= GDK_hstroke && symbol <= GDK_hcircumflex)
172         xupper -= (GDK_hstroke - GDK_Hstroke);
173       else if (symbol >= GDK_gbreve && symbol <= GDK_jcircumflex)
174         xupper -= (GDK_gbreve - GDK_Gbreve);
175       else if (symbol >= GDK_Cabovedot && symbol <= GDK_Scircumflex)
176         xlower += (GDK_cabovedot - GDK_Cabovedot);
177       else if (symbol >= GDK_cabovedot && symbol <= GDK_scircumflex)
178         xupper -= (GDK_cabovedot - GDK_Cabovedot);
179       break;
180 #endif  /* LATIN3 */
181       
182 #if     defined (GDK_Rcedilla) && defined (GDK_Amacron)
183     case 3: /* Latin 4 */
184       /* Assume the KeySym is a legal value (ignore discontinuities) */
185       if (symbol >= GDK_Rcedilla && symbol <= GDK_Tslash)
186         xlower += (GDK_rcedilla - GDK_Rcedilla);
187       else if (symbol >= GDK_rcedilla && symbol <= GDK_tslash)
188         xupper -= (GDK_rcedilla - GDK_Rcedilla);
189       else if (symbol == GDK_ENG)
190         xlower = GDK_eng;
191       else if (symbol == GDK_eng)
192         xupper = GDK_ENG;
193       else if (symbol >= GDK_Amacron && symbol <= GDK_Umacron)
194         xlower += (GDK_amacron - GDK_Amacron);
195       else if (symbol >= GDK_amacron && symbol <= GDK_umacron)
196         xupper -= (GDK_amacron - GDK_Amacron);
197       break;
198 #endif  /* LATIN4 */
199       
200 #if     defined (GDK_Serbian_DJE) && defined (GDK_Cyrillic_yu)
201     case 6: /* Cyrillic */
202       /* Assume the KeySym is a legal value (ignore discontinuities) */
203       if (symbol >= GDK_Serbian_DJE && symbol <= GDK_Serbian_DZE)
204         xlower -= (GDK_Serbian_DJE - GDK_Serbian_dje);
205       else if (symbol >= GDK_Serbian_dje && symbol <= GDK_Serbian_dze)
206         xupper += (GDK_Serbian_DJE - GDK_Serbian_dje);
207       else if (symbol >= GDK_Cyrillic_YU && symbol <= GDK_Cyrillic_HARDSIGN)
208         xlower -= (GDK_Cyrillic_YU - GDK_Cyrillic_yu);
209       else if (symbol >= GDK_Cyrillic_yu && symbol <= GDK_Cyrillic_hardsign)
210         xupper += (GDK_Cyrillic_YU - GDK_Cyrillic_yu);
211       break;
212 #endif  /* CYRILLIC */
213       
214 #if     defined (GDK_Greek_ALPHAaccent) && defined (GDK_Greek_finalsmallsigma)
215     case 7: /* Greek */
216       /* Assume the KeySym is a legal value (ignore discontinuities) */
217       if (symbol >= GDK_Greek_ALPHAaccent && symbol <= GDK_Greek_OMEGAaccent)
218         xlower += (GDK_Greek_alphaaccent - GDK_Greek_ALPHAaccent);
219       else if (symbol >= GDK_Greek_alphaaccent && symbol <= GDK_Greek_omegaaccent &&
220                symbol != GDK_Greek_iotaaccentdieresis &&
221                symbol != GDK_Greek_upsilonaccentdieresis)
222         xupper -= (GDK_Greek_alphaaccent - GDK_Greek_ALPHAaccent);
223       else if (symbol >= GDK_Greek_ALPHA && symbol <= GDK_Greek_OMEGA)
224         xlower += (GDK_Greek_alpha - GDK_Greek_ALPHA);
225       else if (symbol >= GDK_Greek_alpha && symbol <= GDK_Greek_omega &&
226                symbol != GDK_Greek_finalsmallsigma)
227         xupper -= (GDK_Greek_alpha - GDK_Greek_ALPHA);
228       break;
229 #endif  /* GREEK */
230     }
231
232   if (lower)
233     *lower = xlower;
234   if (upper)
235     *upper = xupper;
236 }
237 #endif
238
239 guint
240 gdk_keyval_to_upper (guint keyval)
241 {
242   guint result;
243   
244   gdk_keyval_convert_case (keyval, NULL, &result);
245
246   return result;
247 }
248
249 guint
250 gdk_keyval_to_lower (guint keyval)
251 {
252   guint result;
253   
254   gdk_keyval_convert_case (keyval, &result, NULL);
255
256   return result;
257 }
258
259 gboolean
260 gdk_keyval_is_upper (guint keyval)
261 {
262   if (keyval)
263     {
264       guint upper_val = 0;
265       
266       gdk_keyval_convert_case (keyval, NULL, &upper_val);
267       return upper_val == keyval;
268     }
269   return FALSE;
270 }
271
272 gboolean
273 gdk_keyval_is_lower (guint keyval)
274 {
275   if (keyval)
276     {
277       guint lower_val = 0;
278       
279       gdk_keyval_convert_case (keyval, &lower_val, NULL);
280       return lower_val == keyval;
281     }
282   return FALSE;
283 }