]> Pileus Git - ~andy/gtk/blob - gdk/gdkkeys.c
Make PLT-reduction work with gcc4, and don't include everything in
[~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 #include "gdkalias.h"
32
33 enum {
34   DIRECTION_CHANGED,
35   KEYS_CHANGED,
36   LAST_SIGNAL
37 };
38
39 static void gdk_keymap_class_init (GdkKeymapClass *klass);
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) NULL,
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_class_init (GdkKeymapClass *klass)
73 {
74   GObjectClass *object_class = G_OBJECT_CLASS (klass);
75
76   /**
77    * GdkKeymap::direction-changed:
78    * @keymap: the object on which the signal is emitted
79    * 
80    * The ::direction_changed signal gets emitted when the direction of
81    * the keymap changes. 
82    *
83    * Since: 2.0
84    */
85   signals[DIRECTION_CHANGED] =
86     g_signal_new ("direction_changed",
87                   G_OBJECT_CLASS_TYPE (object_class),
88                   G_SIGNAL_RUN_LAST,
89                   G_STRUCT_OFFSET (GdkKeymapClass, direction_changed),
90                   NULL, NULL,
91                   g_cclosure_marshal_VOID__VOID,
92                   G_TYPE_NONE,
93                   0);
94   /**
95    * GdkKeymap::keys-changed:
96    * @keymap: the object on which the signal is emitted
97    *
98    * The ::keys_changed signal is emitted when the mapping represented by
99    * @keymap changes.
100    *
101    * Since: 2.2
102    */
103   signals[KEYS_CHANGED] =
104     g_signal_new ("keys_changed",
105                   G_OBJECT_CLASS_TYPE (object_class),
106                   G_SIGNAL_RUN_LAST,
107                   G_STRUCT_OFFSET (GdkKeymapClass, keys_changed),
108                   NULL, NULL,
109                   g_cclosure_marshal_VOID__VOID,
110                   G_TYPE_NONE,
111                   0);
112 }
113
114 /* Other key-handling stuff
115  */
116
117 #ifndef HAVE_XCONVERTCASE
118 #include "gdkkeysyms.h"
119
120 /* compatibility function from X11R6.3, since XConvertCase is not
121  * supplied by X11R5.
122  */
123 /**
124  * gdk_keyval_convert_case:
125  * @symbol: a keyval
126  * @lower: return location for lowercase version of @symbol
127  * @upper: return location for uppercase version of @symbol
128  *
129  * Obtains the upper- and lower-case versions of the keyval @symbol.
130  * Examples of keyvals are #GDK_a, #GDK_Enter, #GDK_F1, etc.
131  * 
132  **/
133 void
134 gdk_keyval_convert_case (guint symbol,
135                          guint *lower,
136                          guint *upper)
137 {
138   guint xlower = symbol;
139   guint xupper = symbol;
140
141   /* Check for directly encoded 24-bit UCS characters: */
142   if ((symbol & 0xff000000) == 0x01000000)
143     {
144       if (lower)
145         *lower = gdk_unicode_to_keyval (g_unichar_tolower (symbol & 0x00ffffff));
146       if (upper)
147         *upper = gdk_unicode_to_keyval (g_unichar_toupper (symbol & 0x00ffffff));
148       return;
149     }
150
151   switch (symbol >> 8)
152     {
153     case 0: /* Latin 1 */
154       if ((symbol >= GDK_A) && (symbol <= GDK_Z))
155         xlower += (GDK_a - GDK_A);
156       else if ((symbol >= GDK_a) && (symbol <= GDK_z))
157         xupper -= (GDK_a - GDK_A);
158       else if ((symbol >= GDK_Agrave) && (symbol <= GDK_Odiaeresis))
159         xlower += (GDK_agrave - GDK_Agrave);
160       else if ((symbol >= GDK_agrave) && (symbol <= GDK_odiaeresis))
161         xupper -= (GDK_agrave - GDK_Agrave);
162       else if ((symbol >= GDK_Ooblique) && (symbol <= GDK_Thorn))
163         xlower += (GDK_oslash - GDK_Ooblique);
164       else if ((symbol >= GDK_oslash) && (symbol <= GDK_thorn))
165         xupper -= (GDK_oslash - GDK_Ooblique);
166       break;
167       
168     case 1: /* Latin 2 */
169       /* Assume the KeySym is a legal value (ignore discontinuities) */
170       if (symbol == GDK_Aogonek)
171         xlower = GDK_aogonek;
172       else if (symbol >= GDK_Lstroke && symbol <= GDK_Sacute)
173         xlower += (GDK_lstroke - GDK_Lstroke);
174       else if (symbol >= GDK_Scaron && symbol <= GDK_Zacute)
175         xlower += (GDK_scaron - GDK_Scaron);
176       else if (symbol >= GDK_Zcaron && symbol <= GDK_Zabovedot)
177         xlower += (GDK_zcaron - GDK_Zcaron);
178       else if (symbol == GDK_aogonek)
179         xupper = GDK_Aogonek;
180       else if (symbol >= GDK_lstroke && symbol <= GDK_sacute)
181         xupper -= (GDK_lstroke - GDK_Lstroke);
182       else if (symbol >= GDK_scaron && symbol <= GDK_zacute)
183         xupper -= (GDK_scaron - GDK_Scaron);
184       else if (symbol >= GDK_zcaron && symbol <= GDK_zabovedot)
185         xupper -= (GDK_zcaron - GDK_Zcaron);
186       else if (symbol >= GDK_Racute && symbol <= GDK_Tcedilla)
187         xlower += (GDK_racute - GDK_Racute);
188       else if (symbol >= GDK_racute && symbol <= GDK_tcedilla)
189         xupper -= (GDK_racute - GDK_Racute);
190       break;
191       
192     case 2: /* Latin 3 */
193       /* Assume the KeySym is a legal value (ignore discontinuities) */
194       if (symbol >= GDK_Hstroke && symbol <= GDK_Hcircumflex)
195         xlower += (GDK_hstroke - GDK_Hstroke);
196       else if (symbol >= GDK_Gbreve && symbol <= GDK_Jcircumflex)
197         xlower += (GDK_gbreve - GDK_Gbreve);
198       else if (symbol >= GDK_hstroke && symbol <= GDK_hcircumflex)
199         xupper -= (GDK_hstroke - GDK_Hstroke);
200       else if (symbol >= GDK_gbreve && symbol <= GDK_jcircumflex)
201         xupper -= (GDK_gbreve - GDK_Gbreve);
202       else if (symbol >= GDK_Cabovedot && symbol <= GDK_Scircumflex)
203         xlower += (GDK_cabovedot - GDK_Cabovedot);
204       else if (symbol >= GDK_cabovedot && symbol <= GDK_scircumflex)
205         xupper -= (GDK_cabovedot - GDK_Cabovedot);
206       break;
207       
208     case 3: /* Latin 4 */
209       /* Assume the KeySym is a legal value (ignore discontinuities) */
210       if (symbol >= GDK_Rcedilla && symbol <= GDK_Tslash)
211         xlower += (GDK_rcedilla - GDK_Rcedilla);
212       else if (symbol >= GDK_rcedilla && symbol <= GDK_tslash)
213         xupper -= (GDK_rcedilla - GDK_Rcedilla);
214       else if (symbol == GDK_ENG)
215         xlower = GDK_eng;
216       else if (symbol == GDK_eng)
217         xupper = GDK_ENG;
218       else if (symbol >= GDK_Amacron && symbol <= GDK_Umacron)
219         xlower += (GDK_amacron - GDK_Amacron);
220       else if (symbol >= GDK_amacron && symbol <= GDK_umacron)
221         xupper -= (GDK_amacron - GDK_Amacron);
222       break;
223       
224     case 6: /* Cyrillic */
225       /* Assume the KeySym is a legal value (ignore discontinuities) */
226       if (symbol >= GDK_Serbian_DJE && symbol <= GDK_Serbian_DZE)
227         xlower -= (GDK_Serbian_DJE - GDK_Serbian_dje);
228       else if (symbol >= GDK_Serbian_dje && symbol <= GDK_Serbian_dze)
229         xupper += (GDK_Serbian_DJE - GDK_Serbian_dje);
230       else if (symbol >= GDK_Cyrillic_YU && symbol <= GDK_Cyrillic_HARDSIGN)
231         xlower -= (GDK_Cyrillic_YU - GDK_Cyrillic_yu);
232       else if (symbol >= GDK_Cyrillic_yu && symbol <= GDK_Cyrillic_hardsign)
233         xupper += (GDK_Cyrillic_YU - GDK_Cyrillic_yu);
234       break;
235       
236     case 7: /* Greek */
237       /* Assume the KeySym is a legal value (ignore discontinuities) */
238       if (symbol >= GDK_Greek_ALPHAaccent && symbol <= GDK_Greek_OMEGAaccent)
239         xlower += (GDK_Greek_alphaaccent - GDK_Greek_ALPHAaccent);
240       else if (symbol >= GDK_Greek_alphaaccent && symbol <= GDK_Greek_omegaaccent &&
241                symbol != GDK_Greek_iotaaccentdieresis &&
242                symbol != GDK_Greek_upsilonaccentdieresis)
243         xupper -= (GDK_Greek_alphaaccent - GDK_Greek_ALPHAaccent);
244       else if (symbol >= GDK_Greek_ALPHA && symbol <= GDK_Greek_OMEGA)
245         xlower += (GDK_Greek_alpha - GDK_Greek_ALPHA);
246       else if (symbol >= GDK_Greek_alpha && symbol <= GDK_Greek_omega &&
247                symbol != GDK_Greek_finalsmallsigma)
248         xupper -= (GDK_Greek_alpha - GDK_Greek_ALPHA);
249       break;
250     }
251
252   if (lower)
253     *lower = xlower;
254   if (upper)
255     *upper = xupper;
256 }
257 #endif
258
259 guint
260 gdk_keyval_to_upper (guint keyval)
261 {
262   guint result;
263   
264   gdk_keyval_convert_case (keyval, NULL, &result);
265
266   return result;
267 }
268
269 guint
270 gdk_keyval_to_lower (guint keyval)
271 {
272   guint result;
273   
274   gdk_keyval_convert_case (keyval, &result, NULL);
275
276   return result;
277 }
278
279 gboolean
280 gdk_keyval_is_upper (guint keyval)
281 {
282   if (keyval)
283     {
284       guint upper_val = 0;
285       
286       gdk_keyval_convert_case (keyval, NULL, &upper_val);
287       return upper_val == keyval;
288     }
289   return FALSE;
290 }
291
292 gboolean
293 gdk_keyval_is_lower (guint keyval)
294 {
295   if (keyval)
296     {
297       guint lower_val = 0;
298       
299       gdk_keyval_convert_case (keyval, &lower_val, NULL);
300       return lower_val == keyval;
301     }
302   return FALSE;
303 }
304
305 /** 
306  * gdk_keymap_get_default:
307  * @returns: the #GdkKeymap attached to the default display.
308  *
309  * Returns the #GdkKeymap attached to the default display.
310  **/
311 GdkKeymap*
312 gdk_keymap_get_default (void)
313 {
314   return gdk_keymap_get_for_display (gdk_display_get_default ());
315 }
316
317 #define __GDK_KEYS_C__
318 #include "gdkaliasdef.c"