]> Pileus Git - ~andy/gtk/blob - gdk/gdkkeys.c
Convert all gdk_keymap methods to vtable calls
[~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 "gdkinternals.h"
30 #include "gdkkeys.h"
31
32 #include "gdkdisplay.h"
33
34
35 /**
36  * SECTION:keys
37  * @Short_description: Functions for manipulating keyboard codes
38  * @Title: Key Values
39  *
40  * Key values are the codes which are sent whenever a key is pressed or released.
41  * They appear in the #GdkEventKey.keyval field of the
42  * #GdkEventKey structure, which is passed to signal handlers for the
43  * #GtkWidget::key-press-event and #GtkWidget::key-release-event signals.
44  * The complete list of key values can be found in the
45  * <filename>&lt;gdk/gdkkeysyms.h&gt;</filename> header file.
46  *
47  * Key values are regularly updated from the upstream X.org X11 implementation,
48  * so new values are added regularly. They will be prefixed with GDK_KEY_ rather
49  * than XF86XK_ or XK_ (for older symbols).
50  *
51  * Key values can be converted into a string representation using
52  * gdk_keyval_name(). The reverse function, converting a string to a key value,
53  * is provided by gdk_keyval_from_name().
54  *
55  * The case of key values can be determined using gdk_keyval_is_upper() and
56  * gdk_keyval_is_lower(). Key values can be converted to upper or lower case
57  * using gdk_keyval_to_upper() and gdk_keyval_to_lower().
58  *
59  * When it makes sense, key values can be converted to and from
60  * Unicode characters with gdk_keyval_to_unicode() and gdk_unicode_to_keyval().
61  *
62  * <para id="key-group-explanation">
63  * One #GdkKeymap object exists for each user display. gdk_keymap_get_default()
64  * returns the #GdkKeymap for the default display; to obtain keymaps for other
65  * displays, use gdk_keymap_get_for_display(). A keymap
66  * is a mapping from #GdkKeymapKey to key values. You can think of a #GdkKeymapKey
67  * as a representation of a symbol printed on a physical keyboard key. That is, it
68  * contains three pieces of information. First, it contains the hardware keycode;
69  * this is an identifying number for a physical key. Second, it contains the
70  * <firstterm>level</firstterm> of the key. The level indicates which symbol on the
71  * key will be used, in a vertical direction. So on a standard US keyboard, the key
72  * with the number "1" on it also has the exclamation point ("!") character on
73  * it. The level indicates whether to use the "1" or the "!" symbol.  The letter
74  * keys are considered to have a lowercase letter at level 0, and an uppercase
75  * letter at level 1, though only the uppercase letter is printed.  Third, the
76  * #GdkKeymapKey contains a group; groups are not used on standard US keyboards,
77  * but are used in many other countries. On a keyboard with groups, there can be 3
78  * or 4 symbols printed on a single key. The group indicates movement in a
79  * horizontal direction. Usually groups are used for two different languages.  In
80  * group 0, a key might have two English characters, and in group 1 it might have
81  * two Hebrew characters. The Hebrew characters will be printed on the key next to
82  * the English characters.
83  * </para>
84  *
85  * In order to use a keymap to interpret a key event, it's necessary to first
86  * convert the keyboard state into an effective group and level. This is done via a
87  * set of rules that varies widely according to type of keyboard and user
88  * configuration. The function gdk_keymap_translate_keyboard_state() accepts a
89  * keyboard state -- consisting of hardware keycode pressed, active modifiers, and
90  * active group -- applies the appropriate rules, and returns the group/level to be
91  * used to index the keymap, along with the modifiers which did not affect the
92  * group and level. i.e. it returns "unconsumed modifiers." The keyboard group may
93  * differ from the effective group used for keymap lookups because some keys don't
94  * have multiple groups - e.g. the Enter key is always in group 0 regardless of
95  * keyboard state.
96  *
97  * Note that gdk_keymap_translate_keyboard_state() also returns the keyval, i.e. it
98  * goes ahead and performs the keymap lookup in addition to telling you which
99  * effective group/level values were used for the lookup. #GdkEventKey already
100  * contains this keyval, however, so you don't normally need to call
101  * gdk_keymap_translate_keyboard_state() just to get the keyval.
102  */
103
104
105 enum {
106   DIRECTION_CHANGED,
107   KEYS_CHANGED,
108   STATE_CHANGED,
109   LAST_SIGNAL
110 };
111
112 static guint signals[LAST_SIGNAL] = { 0 };
113
114 G_DEFINE_TYPE (GdkKeymap, gdk_keymap, G_TYPE_OBJECT)
115
116 static void
117 gdk_keymap_class_init (GdkKeymapClass *klass)
118 {
119   GObjectClass *object_class = G_OBJECT_CLASS (klass);
120
121   /**
122    * GdkKeymap::direction-changed:
123    * @keymap: the object on which the signal is emitted
124    * 
125    * The ::direction-changed signal gets emitted when the direction of
126    * the keymap changes. 
127    *
128    * Since: 2.0
129    */
130   signals[DIRECTION_CHANGED] =
131     g_signal_new ("direction-changed",
132                   G_OBJECT_CLASS_TYPE (object_class),
133                   G_SIGNAL_RUN_LAST,
134                   G_STRUCT_OFFSET (GdkKeymapClass, direction_changed),
135                   NULL, NULL,
136                   g_cclosure_marshal_VOID__VOID,
137                   G_TYPE_NONE,
138                   0);
139   /**
140    * GdkKeymap::keys-changed:
141    * @keymap: the object on which the signal is emitted
142    *
143    * The ::keys-changed signal is emitted when the mapping represented by
144    * @keymap changes.
145    *
146    * Since: 2.2
147    */
148   signals[KEYS_CHANGED] =
149     g_signal_new ("keys-changed",
150                   G_OBJECT_CLASS_TYPE (object_class),
151                   G_SIGNAL_RUN_LAST,
152                   G_STRUCT_OFFSET (GdkKeymapClass, keys_changed),
153                   NULL, NULL,
154                   g_cclosure_marshal_VOID__VOID,
155                   G_TYPE_NONE,
156                   0);
157
158   /**
159    * GdkKeymap::state-changed:
160    * @keymap: the object on which the signal is emitted
161    *
162    * The ::state-changed signal is emitted when the state of the
163    * keyboard changes, e.g when Caps Lock is turned on or off.
164    * See gdk_keymap_get_caps_lock_state().
165    *
166    * Since: 2.16
167    */
168   signals[STATE_CHANGED] =
169     g_signal_new ("state_changed",
170                   G_OBJECT_CLASS_TYPE (object_class),
171                   G_SIGNAL_RUN_LAST,
172                   G_STRUCT_OFFSET (GdkKeymapClass, state_changed),
173                   NULL, NULL,
174                   g_cclosure_marshal_VOID__VOID,
175                   G_TYPE_NONE, 
176                   0);
177 }
178
179 static void
180 gdk_keymap_init (GdkKeymap *keymap)
181 {
182 }
183
184 /* Other key-handling stuff
185  */
186
187 #ifndef HAVE_XCONVERTCASE
188 #include "gdkkeysyms.h"
189
190 /* compatibility function from X11R6.3, since XConvertCase is not
191  * supplied by X11R5.
192  */
193 /**
194  * gdk_keyval_convert_case:
195  * @symbol: a keyval
196  * @lower: (out): return location for lowercase version of @symbol
197  * @upper: (out): return location for uppercase version of @symbol
198  *
199  * Obtains the upper- and lower-case versions of the keyval @symbol.
200  * Examples of keyvals are #GDK_KEY_a, #GDK_KEY_Enter, #GDK_KEY_F1, etc.
201  *
202  **/
203 void
204 gdk_keyval_convert_case (guint symbol,
205                          guint *lower,
206                          guint *upper)
207 {
208   guint xlower = symbol;
209   guint xupper = symbol;
210
211   /* Check for directly encoded 24-bit UCS characters: */
212   if ((symbol & 0xff000000) == 0x01000000)
213     {
214       if (lower)
215         *lower = gdk_unicode_to_keyval (g_unichar_tolower (symbol & 0x00ffffff));
216       if (upper)
217         *upper = gdk_unicode_to_keyval (g_unichar_toupper (symbol & 0x00ffffff));
218       return;
219     }
220
221   switch (symbol >> 8)
222     {
223     case 0: /* Latin 1 */
224       if ((symbol >= GDK_KEY_A) && (symbol <= GDK_KEY_Z))
225         xlower += (GDK_KEY_a - GDK_KEY_A);
226       else if ((symbol >= GDK_KEY_a) && (symbol <= GDK_KEY_z))
227         xupper -= (GDK_KEY_a - GDK_KEY_A);
228       else if ((symbol >= GDK_KEY_Agrave) && (symbol <= GDK_KEY_Odiaeresis))
229         xlower += (GDK_KEY_agrave - GDK_KEY_Agrave);
230       else if ((symbol >= GDK_KEY_agrave) && (symbol <= GDK_KEY_odiaeresis))
231         xupper -= (GDK_KEY_agrave - GDK_KEY_Agrave);
232       else if ((symbol >= GDK_KEY_Ooblique) && (symbol <= GDK_KEY_Thorn))
233         xlower += (GDK_KEY_oslash - GDK_KEY_Ooblique);
234       else if ((symbol >= GDK_KEY_oslash) && (symbol <= GDK_KEY_thorn))
235         xupper -= (GDK_KEY_oslash - GDK_KEY_Ooblique);
236       break;
237       
238     case 1: /* Latin 2 */
239       /* Assume the KeySym is a legal value (ignore discontinuities) */
240       if (symbol == GDK_KEY_Aogonek)
241         xlower = GDK_KEY_aogonek;
242       else if (symbol >= GDK_KEY_Lstroke && symbol <= GDK_KEY_Sacute)
243         xlower += (GDK_KEY_lstroke - GDK_KEY_Lstroke);
244       else if (symbol >= GDK_KEY_Scaron && symbol <= GDK_KEY_Zacute)
245         xlower += (GDK_KEY_scaron - GDK_KEY_Scaron);
246       else if (symbol >= GDK_KEY_Zcaron && symbol <= GDK_KEY_Zabovedot)
247         xlower += (GDK_KEY_zcaron - GDK_KEY_Zcaron);
248       else if (symbol == GDK_KEY_aogonek)
249         xupper = GDK_KEY_Aogonek;
250       else if (symbol >= GDK_KEY_lstroke && symbol <= GDK_KEY_sacute)
251         xupper -= (GDK_KEY_lstroke - GDK_KEY_Lstroke);
252       else if (symbol >= GDK_KEY_scaron && symbol <= GDK_KEY_zacute)
253         xupper -= (GDK_KEY_scaron - GDK_KEY_Scaron);
254       else if (symbol >= GDK_KEY_zcaron && symbol <= GDK_KEY_zabovedot)
255         xupper -= (GDK_KEY_zcaron - GDK_KEY_Zcaron);
256       else if (symbol >= GDK_KEY_Racute && symbol <= GDK_KEY_Tcedilla)
257         xlower += (GDK_KEY_racute - GDK_KEY_Racute);
258       else if (symbol >= GDK_KEY_racute && symbol <= GDK_KEY_tcedilla)
259         xupper -= (GDK_KEY_racute - GDK_KEY_Racute);
260       break;
261       
262     case 2: /* Latin 3 */
263       /* Assume the KeySym is a legal value (ignore discontinuities) */
264       if (symbol >= GDK_KEY_Hstroke && symbol <= GDK_KEY_Hcircumflex)
265         xlower += (GDK_KEY_hstroke - GDK_KEY_Hstroke);
266       else if (symbol >= GDK_KEY_Gbreve && symbol <= GDK_KEY_Jcircumflex)
267         xlower += (GDK_KEY_gbreve - GDK_KEY_Gbreve);
268       else if (symbol >= GDK_KEY_hstroke && symbol <= GDK_KEY_hcircumflex)
269         xupper -= (GDK_KEY_hstroke - GDK_KEY_Hstroke);
270       else if (symbol >= GDK_KEY_gbreve && symbol <= GDK_KEY_jcircumflex)
271         xupper -= (GDK_KEY_gbreve - GDK_KEY_Gbreve);
272       else if (symbol >= GDK_KEY_Cabovedot && symbol <= GDK_KEY_Scircumflex)
273         xlower += (GDK_KEY_cabovedot - GDK_KEY_Cabovedot);
274       else if (symbol >= GDK_KEY_cabovedot && symbol <= GDK_KEY_scircumflex)
275         xupper -= (GDK_KEY_cabovedot - GDK_KEY_Cabovedot);
276       break;
277       
278     case 3: /* Latin 4 */
279       /* Assume the KeySym is a legal value (ignore discontinuities) */
280       if (symbol >= GDK_KEY_Rcedilla && symbol <= GDK_KEY_Tslash)
281         xlower += (GDK_KEY_rcedilla - GDK_KEY_Rcedilla);
282       else if (symbol >= GDK_KEY_rcedilla && symbol <= GDK_KEY_tslash)
283         xupper -= (GDK_KEY_rcedilla - GDK_KEY_Rcedilla);
284       else if (symbol == GDK_KEY_ENG)
285         xlower = GDK_KEY_eng;
286       else if (symbol == GDK_KEY_eng)
287         xupper = GDK_KEY_ENG;
288       else if (symbol >= GDK_KEY_Amacron && symbol <= GDK_KEY_Umacron)
289         xlower += (GDK_KEY_amacron - GDK_KEY_Amacron);
290       else if (symbol >= GDK_KEY_amacron && symbol <= GDK_KEY_umacron)
291         xupper -= (GDK_KEY_amacron - GDK_KEY_Amacron);
292       break;
293       
294     case 6: /* Cyrillic */
295       /* Assume the KeySym is a legal value (ignore discontinuities) */
296       if (symbol >= GDK_KEY_Serbian_DJE && symbol <= GDK_KEY_Serbian_DZE)
297         xlower -= (GDK_KEY_Serbian_DJE - GDK_KEY_Serbian_dje);
298       else if (symbol >= GDK_KEY_Serbian_dje && symbol <= GDK_KEY_Serbian_dze)
299         xupper += (GDK_KEY_Serbian_DJE - GDK_KEY_Serbian_dje);
300       else if (symbol >= GDK_KEY_Cyrillic_YU && symbol <= GDK_KEY_Cyrillic_HARDSIGN)
301         xlower -= (GDK_KEY_Cyrillic_YU - GDK_KEY_Cyrillic_yu);
302       else if (symbol >= GDK_KEY_Cyrillic_yu && symbol <= GDK_KEY_Cyrillic_hardsign)
303         xupper += (GDK_KEY_Cyrillic_YU - GDK_KEY_Cyrillic_yu);
304       break;
305       
306     case 7: /* Greek */
307       /* Assume the KeySym is a legal value (ignore discontinuities) */
308       if (symbol >= GDK_KEY_Greek_ALPHAaccent && symbol <= GDK_KEY_Greek_OMEGAaccent)
309         xlower += (GDK_KEY_Greek_alphaaccent - GDK_KEY_Greek_ALPHAaccent);
310       else if (symbol >= GDK_KEY_Greek_alphaaccent && symbol <= GDK_KEY_Greek_omegaaccent &&
311                symbol != GDK_KEY_Greek_iotaaccentdieresis &&
312                symbol != GDK_KEY_Greek_upsilonaccentdieresis)
313         xupper -= (GDK_KEY_Greek_alphaaccent - GDK_KEY_Greek_ALPHAaccent);
314       else if (symbol >= GDK_KEY_Greek_ALPHA && symbol <= GDK_KEY_Greek_OMEGA)
315         xlower += (GDK_KEY_Greek_alpha - GDK_KEY_Greek_ALPHA);
316       else if (symbol >= GDK_KEY_Greek_alpha && symbol <= GDK_KEY_Greek_omega &&
317                symbol != GDK_KEY_Greek_finalsmallsigma)
318         xupper -= (GDK_KEY_Greek_alpha - GDK_KEY_Greek_ALPHA);
319       break;
320     }
321
322   if (lower)
323     *lower = xlower;
324   if (upper)
325     *upper = xupper;
326 }
327 #endif
328
329 /**
330  * gdk_keyval_to_upper:
331  * @keyval: a key value.
332  *
333  * Converts a key value to upper case, if applicable.
334  *
335  * Returns: the upper case form of @keyval, or @keyval itself if it is already
336  *   in upper case or it is not subject to case conversion.
337  */
338 guint
339 gdk_keyval_to_upper (guint keyval)
340 {
341   guint result;
342   
343   gdk_keyval_convert_case (keyval, NULL, &result);
344
345   return result;
346 }
347
348 /**
349  * gdk_keyval_to_lower:
350  * @keyval: a key value.
351  *
352  * Converts a key value to lower case, if applicable.
353  *
354  * Returns: the lower case form of @keyval, or @keyval itself if it is already
355  *  in lower case or it is not subject to case conversion.
356  */
357 guint
358 gdk_keyval_to_lower (guint keyval)
359 {
360   guint result;
361   
362   gdk_keyval_convert_case (keyval, &result, NULL);
363
364   return result;
365 }
366
367 /**
368  * gdk_keyval_is_upper:
369  * @keyval: a key value.
370  *
371  * Returns %TRUE if the given key value is in upper case.
372  *
373  * Returns: %TRUE if @keyval is in upper case, or if @keyval is not subject to
374  *  case conversion.
375  */
376 gboolean
377 gdk_keyval_is_upper (guint keyval)
378 {
379   if (keyval)
380     {
381       guint upper_val = 0;
382       
383       gdk_keyval_convert_case (keyval, NULL, &upper_val);
384       return upper_val == keyval;
385     }
386   return FALSE;
387 }
388
389 /**
390  * gdk_keyval_is_lower:
391  * @keyval: a key value.
392  *
393  * Returns %TRUE if the given key value is in lower case.
394  *
395  * Returns: %TRUE if @keyval is in lower case, or if @keyval is not
396  *   subject to case conversion.
397  */
398 gboolean
399 gdk_keyval_is_lower (guint keyval)
400 {
401   if (keyval)
402     {
403       guint lower_val = 0;
404       
405       gdk_keyval_convert_case (keyval, &lower_val, NULL);
406       return lower_val == keyval;
407     }
408   return FALSE;
409 }
410
411 /** 
412  * gdk_keymap_get_default:
413  *
414  * Returns the #GdkKeymap attached to the default display.
415  *
416  * Returns: (transfer none): the #GdkKeymap attached to the default display.
417  */
418 GdkKeymap*
419 gdk_keymap_get_default (void)
420 {
421   return gdk_keymap_get_for_display (gdk_display_get_default ());
422 }
423
424 /**
425  * gdk_keymap_get_direction:
426  * @keymap: a #GdkKeymap or %NULL to use the default keymap
427  *
428  * Returns the direction of effective layout of the keymap.
429  *
430  * Returns: %PANGO_DIRECTION_LTR or %PANGO_DIRECTION_RTL
431  *   if it can determine the direction. %PANGO_DIRECTION_NEUTRAL
432  *   otherwise.
433  **/
434 PangoDirection
435 gdk_keymap_get_direction (GdkKeymap *keymap)
436 {
437   return GDK_KEYMAP_GET_CLASS(keymap)->get_direction (keymap);
438 }
439
440 /**
441  * gdk_keymap_have_bidi_layouts:
442  * @keymap: a #GdkKeymap or %NULL to use the default keymap
443  *
444  * Determines if keyboard layouts for both right-to-left and left-to-right
445  * languages are in use.
446  *
447  * Returns: %TRUE if there are layouts in both directions, %FALSE otherwise
448  *
449  * Since: 2.12
450  **/
451 gboolean
452 gdk_keymap_have_bidi_layouts (GdkKeymap *keymap)
453 {
454   return GDK_KEYMAP_GET_CLASS(keymap)->have_bidi_layouts (keymap);
455 }
456
457 /**
458  * gdk_keymap_get_caps_lock_state:
459  * @keymap: a #GdkKeymap
460  *
461  * Returns whether the Caps Lock modifer is locked.
462  *
463  * Returns: %TRUE if Caps Lock is on
464  *
465  * Since: 2.16
466  */
467 gboolean
468 gdk_keymap_get_caps_lock_state (GdkKeymap *keymap)
469 {
470   return GDK_KEYMAP_GET_CLASS(keymap)->get_caps_lock_state (keymap);
471 }
472
473 /**
474  * gdk_keymap_get_num_lock_state:
475  * @keymap: a #GdkKeymap
476  *
477  * Returns whether the Num Lock modifer is locked.
478  *
479  * Returns: %TRUE if Num Lock is on
480  *
481  * Since: 3.0
482  */
483 gboolean
484 gdk_keymap_get_num_lock_state (GdkKeymap *keymap)
485 {
486   return GDK_KEYMAP_GET_CLASS(keymap)->get_num_lock_state (keymap);
487 }
488
489 /**
490  * gdk_keymap_get_entries_for_keyval:
491  * @keymap: (allow-none): a #GdkKeymap, or %NULL to use the default keymap
492  * @keyval: a keyval, such as %GDK_a, %GDK_Up, %GDK_Return, etc.
493  * @keys: (out): return location for an array of #GdkKeymapKey
494  * @n_keys: (out): return location for number of elements in returned array
495  *
496  * Obtains a list of keycode/group/level combinations that will
497  * generate @keyval. Groups and levels are two kinds of keyboard mode;
498  * in general, the level determines whether the top or bottom symbol
499  * on a key is used, and the group determines whether the left or
500  * right symbol is used. On US keyboards, the shift key changes the
501  * keyboard level, and there are no groups. A group switch key might
502  * convert a keyboard between Hebrew to English modes, for example.
503  * #GdkEventKey contains a %group field that indicates the active
504  * keyboard group. The level is computed from the modifier mask.
505  * The returned array should be freed
506  * with g_free().
507  *
508  * Return value: %TRUE if keys were found and returned
509  **/
510 gboolean
511 gdk_keymap_get_entries_for_keyval (GdkKeymap     *keymap,
512                                    guint          keyval,
513                                    GdkKeymapKey **keys,
514                                    gint          *n_keys)
515 {
516   return GDK_KEYMAP_GET_CLASS(keymap)->get_entries_for_keyval (keymap, keyval, keys, n_keys);
517 }
518
519 /**
520  * gdk_keymap_get_entries_for_keycode:
521  * @keymap: (allow-none): a #GdkKeymap or %NULL to use the default keymap
522  * @hardware_keycode: a keycode
523  * @keys: (out): return location for array of #GdkKeymapKey, or %NULL
524  * @keyvals: (out): return location for array of keyvals, or %NULL
525  * @n_entries: length of @keys and @keyvals
526  *
527  * Returns the keyvals bound to @hardware_keycode.
528  * The Nth #GdkKeymapKey in @keys is bound to the Nth
529  * keyval in @keyvals. Free the returned arrays with g_free().
530  * When a keycode is pressed by the user, the keyval from
531  * this list of entries is selected by considering the effective
532  * keyboard group and level. See gdk_keymap_translate_keyboard_state().
533  *
534  * Returns: %TRUE if there were any entries
535  **/
536 gboolean
537 gdk_keymap_get_entries_for_keycode (GdkKeymap     *keymap,
538                                     guint          hardware_keycode,
539                                     GdkKeymapKey **keys,
540                                     guint        **keyvals,
541                                     gint          *n_entries)
542 {
543   return GDK_KEYMAP_GET_CLASS(keymap)->get_entries_for_keycode (keymap, hardware_keycode, keys, keyvals, n_entries);
544 }
545
546 /**
547  * gdk_keymap_lookup_key:
548  * @keymap: a #GdkKeymap or %NULL to use the default keymap
549  * @key: a #GdkKeymapKey with keycode, group, and level initialized
550  *
551  * Looks up the keyval mapped to a keycode/group/level triplet.
552  * If no keyval is bound to @key, returns 0. For normal user input,
553  * you want to use gdk_keymap_translate_keyboard_state() instead of
554  * this function, since the effective group/level may not be
555  * the same as the current keyboard state.
556  *
557  * Return value: a keyval, or 0 if none was mapped to the given @key
558  **/
559 guint
560 gdk_keymap_lookup_key (GdkKeymap          *keymap,
561                        const GdkKeymapKey *key)
562 {
563   return GDK_KEYMAP_GET_CLASS(keymap)->lookup_key (keymap, key);
564 }
565
566 /**
567  * gdk_keymap_translate_keyboard_state:
568  * @keymap: (allow-none): a #GdkKeymap, or %NULL to use the default
569  * @hardware_keycode: a keycode
570  * @state: a modifier state
571  * @group: active keyboard group
572  * @keyval: (out) (allow-none): return location for keyval, or %NULL
573  * @effective_group: (out) (allow-none): return location for effective group, or %NULL
574  * @level: (out) (allow-none):  return location for level, or %NULL
575  * @consumed_modifiers: (out) (allow-none):  return location for modifiers that were used to
576  *     determine the group or level, or %NULL
577  *
578  * Translates the contents of a #GdkEventKey into a keyval, effective
579  * group, and level. Modifiers that affected the translation and
580  * are thus unavailable for application use are returned in
581  * @consumed_modifiers.  See <xref linkend="key-group-explanation"/> for an explanation of
582  * groups and levels.  The @effective_group is the group that was
583  * actually used for the translation; some keys such as Enter are not
584  * affected by the active keyboard group. The @level is derived from
585  * @state. For convenience, #GdkEventKey already contains the translated
586  * keyval, so this function isn't as useful as you might think.
587  *
588  * <note><para>
589  * @consumed_modifiers gives modifiers that should be masked out
590  * from @state when comparing this key press to a hot key. For
591  * instance, on a US keyboard, the <literal>plus</literal>
592  * symbol is shifted, so when comparing a key press to a
593  * <literal>&lt;Control&gt;plus</literal> accelerator &lt;Shift&gt; should
594  * be masked out.
595  * </para>
596  * <informalexample><programlisting>
597  * &sol;* We want to ignore irrelevant modifiers like ScrollLock *&sol;
598  * &num;define ALL_ACCELS_MASK (GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK)
599  * gdk_keymap_translate_keyboard_state (keymap, event->hardware_keycode,
600  *                                      event->state, event->group,
601  *                                      &amp;keyval, NULL, NULL, &amp;consumed);
602  * if (keyval == GDK_PLUS &&
603  *     (event->state &amp; ~consumed &amp; ALL_ACCELS_MASK) == GDK_CONTROL_MASK)
604  *   &sol;* Control was pressed *&sol;
605  * </programlisting></informalexample>
606  * <para>
607  * An older interpretation @consumed_modifiers was that it contained
608  * all modifiers that might affect the translation of the key;
609  * this allowed accelerators to be stored with irrelevant consumed
610  * modifiers, by doing:</para>
611  * <informalexample><programlisting>
612  * &sol;* XXX Don't do this XXX *&sol;
613  * if (keyval == accel_keyval &&
614  *     (event->state &amp; ~consumed &amp; ALL_ACCELS_MASK) == (accel_mods &amp; ~consumed))
615  *   &sol;* Accelerator was pressed *&sol;
616  * </programlisting></informalexample>
617  * <para>
618  * However, this did not work if multi-modifier combinations were
619  * used in the keymap, since, for instance, <literal>&lt;Control&gt;</literal>
620  * would be masked out even if only <literal>&lt;Control&gt;&lt;Alt&gt;</literal>
621  * was used in the keymap. To support this usage as well as well as
622  * possible, all <emphasis>single modifier</emphasis> combinations
623  * that could affect the key for any combination of modifiers will
624  * be returned in @consumed_modifiers; multi-modifier combinations
625  * are returned only when actually found in @state. When you store
626  * accelerators, you should always store them with consumed modifiers
627  * removed. Store <literal>&lt;Control&gt;plus</literal>,
628  * not <literal>&lt;Control&gt;&lt;Shift&gt;plus</literal>,
629  * </para></note>
630  *
631  * Return value: %TRUE if there was a keyval bound to the keycode/state/group
632  **/
633 gboolean
634 gdk_keymap_translate_keyboard_state (GdkKeymap       *keymap,
635                                      guint            hardware_keycode,
636                                      GdkModifierType  state,
637                                      gint             group,
638                                      guint           *keyval,
639                                      gint            *effective_group,
640                                      gint            *level,
641                                      GdkModifierType *consumed_modifiers)
642 {
643   return GDK_KEYMAP_GET_CLASS(keymap)->translate_keyboard_state (keymap,
644                                                                   hardware_keycode,
645                                                                   state,
646                                                                   group,
647                                                                   keyval,
648                                                                   effective_group,
649                                                                   level,
650                                                                   consumed_modifiers);
651 }
652
653 /**
654  * gdk_keymap_add_virtual_modifiers:
655  * @keymap: a #GdkKeymap
656  * @state: pointer to the modifier mask to change
657  *
658  * Adds virtual modifiers (i.e. Super, Hyper and Meta) which correspond
659  * to the real modifiers (i.e Mod2, Mod3, ...) in @modifiers.
660  * are set in @state to their non-virtual counterparts (i.e. Mod2,
661  * Mod3,...) and set the corresponding bits in @state.
662  *
663  * GDK already does this before delivering key events, but for
664  * compatibility reasons, it only sets the first virtual modifier
665  * it finds, whereas this function sets all matching virtual modifiers.
666  *
667  * This function is useful when matching key events against
668  * accelerators.
669  *
670  * Since: 2.20
671  */
672 void
673 gdk_keymap_add_virtual_modifiers (GdkKeymap       *keymap,
674                                   GdkModifierType *state)
675 {
676   GDK_KEYMAP_GET_CLASS(keymap)->add_virtual_modifiers (keymap, state);
677 }
678
679 /**
680  * gdk_keymap_map_virtual_modifiers:
681  * @keymap: a #GdkKeymap
682  * @state: pointer to the modifier state to map
683  *
684  * Maps the virtual modifiers (i.e. Super, Hyper and Meta) which
685  * are set in @state to their non-virtual counterparts (i.e. Mod2,
686  * Mod3,...) and set the corresponding bits in @state.
687  *
688  * This function is useful when matching key events against
689  * accelerators.
690  *
691  * Returns: %TRUE if no virtual modifiers were mapped to the
692  *     same non-virtual modifier. Note that %FALSE is also returned
693  *     if a virtual modifier is mapped to a non-virtual modifier that
694  *     was already set in @state.
695  *
696  * Since: 2.20
697  */
698 gboolean
699 gdk_keymap_map_virtual_modifiers (GdkKeymap       *keymap,
700                                   GdkModifierType *state)
701 {
702   return GDK_KEYMAP_GET_CLASS(keymap)->map_virtual_modifiers (keymap, state);
703 }