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