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