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