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#include "gdkinternals.h"
29
30/* Key handling not part of the keymap */
31
32#include "keyname-table.h"
33
34#include <glib/gprintf.h>
35#include <stdlib.h>
36#include <string.h>
37
38#define GDK_NUM_KEYS G_N_ELEMENTS (gdk_keys_by_keyval)
39
40static int
41gdk_keys_keyval_compare (const void *pkey, const void *pbase)
42{
43 return (*(int *) pkey) - ((gdk_key *) pbase)->keyval;
44}
45
46static gchar*
47_gdk_keyval_name (guint keyval)
48{
49 static gchar buf[100];
50 gdk_key *found;
51
52 /* Check for directly encoded 24-bit UCS characters: */
53 if ((keyval & 0xff000000) == 0x01000000)
54 {
55 g_sprintf (buf, "U+%.04X", (keyval & 0x00ffffff));
56 return buf;
57 }
58
59 found = bsearch (&keyval, gdk_keys_by_keyval,
60 GDK_NUM_KEYS, sizeof (gdk_key),
61 gdk_keys_keyval_compare);
62
63 if (found != NULL)
64 {
65 while ((found > gdk_keys_by_keyval) &&
66 ((found - 1)->keyval == keyval))
67 found--;
68
69 return (gchar *) (keynames + found->offset);
70 }
71 else if (keyval != 0)
72 {
73 g_sprintf (buf, "%#x", keyval);
74 return buf;
75 }
76
77 return NULL;
78}
79
80static int
81gdk_keys_name_compare (const void *pkey, const void *pbase)
82{
83 return strcmp ((const char *) pkey,
84 (const char *) (keynames + ((const gdk_key *) pbase)->offset));
85}
86
87static guint
88_gdk_keyval_from_name (const gchar *keyval_name)
89{
90 gdk_key *found;
91
92 g_return_val_if_fail (keyval_name != NULL, 0);
93
94 if (strncmp (keyval_name,"XF86", 4) == 0)
95 keyval_name += 4;
96
97 found = bsearch (keyval_name, gdk_keys_by_name,
98 GDK_NUM_KEYS, sizeof (gdk_key),
99 gdk_keys_name_compare);
100 if (found != NULL)
101 return found->keyval;
102 else
103 return GDK_KEY_VoidSymbol;
104}
105