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