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/.
29 #include "gdkdisplay.h"
40 static guint signals[LAST_SIGNAL] = { 0 };
42 G_DEFINE_TYPE (GdkKeymap, gdk_keymap, G_TYPE_OBJECT)
45 gdk_keymap_class_init (GdkKeymapClass *klass)
47 GObjectClass *object_class = G_OBJECT_CLASS (klass);
50 * GdkKeymap::direction-changed:
51 * @keymap: the object on which the signal is emitted
53 * The ::direction-changed signal gets emitted when the direction of
58 signals[DIRECTION_CHANGED] =
59 g_signal_new ("direction-changed",
60 G_OBJECT_CLASS_TYPE (object_class),
62 G_STRUCT_OFFSET (GdkKeymapClass, direction_changed),
64 g_cclosure_marshal_VOID__VOID,
68 * GdkKeymap::keys-changed:
69 * @keymap: the object on which the signal is emitted
71 * The ::keys-changed signal is emitted when the mapping represented by
76 signals[KEYS_CHANGED] =
77 g_signal_new ("keys-changed",
78 G_OBJECT_CLASS_TYPE (object_class),
80 G_STRUCT_OFFSET (GdkKeymapClass, keys_changed),
82 g_cclosure_marshal_VOID__VOID,
87 * GdkKeymap::state-changed:
88 * @keymap: the object on which the signal is emitted
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().
96 signals[STATE_CHANGED] =
97 g_signal_new ("state_changed",
98 G_OBJECT_CLASS_TYPE (object_class),
100 G_STRUCT_OFFSET (GdkKeymapClass, state_changed),
102 g_cclosure_marshal_VOID__VOID,
108 gdk_keymap_init (GdkKeymap *keymap)
112 /* Other key-handling stuff
115 #ifndef HAVE_XCONVERTCASE
116 #include "gdkkeysyms.h"
118 /* compatibility function from X11R6.3, since XConvertCase is not
122 * gdk_keyval_convert_case:
124 * @lower: (out): return location for lowercase version of @symbol
125 * @upper: (out): return location for uppercase version of @symbol
127 * Obtains the upper- and lower-case versions of the keyval @symbol.
128 * Examples of keyvals are #GDK_a, #GDK_Enter, #GDK_F1, etc.
132 gdk_keyval_convert_case (guint symbol,
136 guint xlower = symbol;
137 guint xupper = symbol;
139 /* Check for directly encoded 24-bit UCS characters: */
140 if ((symbol & 0xff000000) == 0x01000000)
143 *lower = gdk_unicode_to_keyval (g_unichar_tolower (symbol & 0x00ffffff));
145 *upper = gdk_unicode_to_keyval (g_unichar_toupper (symbol & 0x00ffffff));
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);
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);
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);
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)
214 else if (symbol == 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);
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);
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);
258 gdk_keyval_to_upper (guint keyval)
262 gdk_keyval_convert_case (keyval, NULL, &result);
268 gdk_keyval_to_lower (guint keyval)
272 gdk_keyval_convert_case (keyval, &result, NULL);
278 gdk_keyval_is_upper (guint keyval)
284 gdk_keyval_convert_case (keyval, NULL, &upper_val);
285 return upper_val == keyval;
291 gdk_keyval_is_lower (guint keyval)
297 gdk_keyval_convert_case (keyval, &lower_val, NULL);
298 return lower_val == keyval;
304 * gdk_keymap_get_default:
305 * @returns: the #GdkKeymap attached to the default display.
307 * Returns the #GdkKeymap attached to the default display.
310 gdk_keymap_get_default (void)
312 return gdk_keymap_get_for_display (gdk_display_get_default ());