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