1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 2000 Red Hat, Inc.
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.
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.
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.
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/.
30 #include "gdkdisplay.h"
39 static void gdk_keymap_class_init (GdkKeymapClass *klass);
41 static guint signals[LAST_SIGNAL] = { 0 };
44 gdk_keymap_get_type (void)
46 static GType object_type = 0;
50 static const GTypeInfo object_info =
52 sizeof (GdkKeymapClass),
54 (GBaseFinalizeFunc) NULL,
55 (GClassInitFunc) gdk_keymap_class_init,
56 NULL, /* class_finalize */
57 NULL, /* class_data */
60 (GInstanceInitFunc) NULL,
63 object_type = g_type_register_static (G_TYPE_OBJECT,
72 gdk_keymap_class_init (GdkKeymapClass *klass)
74 GObjectClass *object_class = G_OBJECT_CLASS (klass);
77 * GdkKeymap::direction-changed:
78 * @keymap: the object on which the signal is emitted
80 * The ::direction_changed signal gets emitted when the direction of
85 signals[DIRECTION_CHANGED] =
86 g_signal_new ("direction_changed",
87 G_OBJECT_CLASS_TYPE (object_class),
89 G_STRUCT_OFFSET (GdkKeymapClass, direction_changed),
91 g_cclosure_marshal_VOID__VOID,
95 * GdkKeymap::keys-changed:
96 * @keymap: the object on which the signal is emitted
98 * The ::keys_changed signal is emitted when the mapping represented by
103 signals[KEYS_CHANGED] =
104 g_signal_new ("keys_changed",
105 G_OBJECT_CLASS_TYPE (object_class),
107 G_STRUCT_OFFSET (GdkKeymapClass, keys_changed),
109 g_cclosure_marshal_VOID__VOID,
114 /* Other key-handling stuff
117 #ifndef HAVE_XCONVERTCASE
118 #include "gdkkeysyms.h"
120 /* compatibility function from X11R6.3, since XConvertCase is not
124 * gdk_keyval_convert_case:
126 * @lower: return location for lowercase version of @symbol
127 * @upper: return location for uppercase version of @symbol
129 * Obtains the upper- and lower-case versions of the keyval @symbol.
130 * Examples of keyvals are #GDK_a, #GDK_Enter, #GDK_F1, etc.
134 gdk_keyval_convert_case (guint symbol,
138 guint xlower = symbol;
139 guint xupper = symbol;
141 /* Check for directly encoded 24-bit UCS characters: */
142 if ((symbol & 0xff000000) == 0x01000000)
145 *lower = gdk_unicode_to_keyval (g_unichar_tolower (symbol & 0x00ffffff));
147 *upper = gdk_unicode_to_keyval (g_unichar_toupper (symbol & 0x00ffffff));
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);
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);
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);
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)
216 else if (symbol == 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);
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);
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);
260 gdk_keyval_to_upper (guint keyval)
264 gdk_keyval_convert_case (keyval, NULL, &result);
270 gdk_keyval_to_lower (guint keyval)
274 gdk_keyval_convert_case (keyval, &result, NULL);
280 gdk_keyval_is_upper (guint keyval)
286 gdk_keyval_convert_case (keyval, NULL, &upper_val);
287 return upper_val == keyval;
293 gdk_keyval_is_lower (guint keyval)
299 gdk_keyval_convert_case (keyval, &lower_val, NULL);
300 return lower_val == keyval;
306 * gdk_keymap_get_default:
307 * @returns: the #GdkKeymap attached to the default display.
309 * Returns the #GdkKeymap attached to the default display.
312 gdk_keymap_get_default (void)
314 return gdk_keymap_get_for_display (gdk_display_get_default ());