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