1/* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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, see <http://www.gnu.org/licenses/>.
16 */
17
18/*
19 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GTK+ Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
23 */
24
25#include "config.h"
26
27#include "gdkkeysyms.h"
28
29/* Key handling not part of the keymap */
30
31#include "keyname-table.h"
32
33#include <glib/gprintf.h>
34#include <stdlib.h>
35#include <string.h>
36
37#define GDK_NUM_KEYS G_N_ELEMENTS (gdk_keys_by_keyval)
38
39static int
40gdk_keys_keyval_compare (const void *pkey, const void *pbase)
41{
42 return (*(int *) pkey) - ((gdk_key *) pbase)->keyval;
43}
44
45static char *
46_gdk_keyval_name (guint keyval)
47{
48 static char buf[100];
49 gdk_key *found;
50
51 /* Check for directly encoded 24-bit UCS characters: */
52 if ((keyval & 0xff000000) == 0x01000000)
53 {
54 g_sprintf (string: buf, format: "U+%.04X", (keyval & 0x00ffffff));
55 return buf;
56 }
57
58 found = bsearch (key: &keyval, base: gdk_keys_by_keyval,
59 GDK_NUM_KEYS, size: sizeof (gdk_key),
60 compar: gdk_keys_keyval_compare);
61
62 if (found != NULL)
63 {
64 while ((found > gdk_keys_by_keyval) &&
65 ((found - 1)->keyval == keyval))
66 found--;
67
68 return (char *) (keynames + found->offset);
69 }
70 else if (keyval != 0)
71 {
72 g_sprintf (string: buf, format: "%#x", keyval);
73 return buf;
74 }
75
76 return NULL;
77}
78
79static int
80gdk_keys_name_compare (const void *pkey, const void *pbase)
81{
82 return strcmp (s1: (const char *) pkey,
83 s2: (const char *) (keynames + ((const gdk_key *) pbase)->offset));
84}
85
86static guint
87_gdk_keyval_from_name (const char *keyval_name)
88{
89 gdk_key *found;
90
91 g_return_val_if_fail (keyval_name != NULL, 0);
92
93 if (strncmp (s1: keyval_name,s2: "XF86", n: 4) == 0)
94 keyval_name += 4;
95
96 found = bsearch (key: keyval_name, base: gdk_keys_by_name,
97 GDK_NUM_KEYS, size: sizeof (gdk_key),
98 compar: gdk_keys_name_compare);
99 if (found != NULL)
100 return found->keyval;
101 else
102 return GDK_KEY_VoidSymbol;
103}
104

source code of gtk/gdk/gdkkeynames.c