1 /* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
2 /* vim:set et sts=4: */
3 /* GDK - The GIMP Drawing Kit
4 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
24 * file for a list of people on the GTK+ Team. See the ChangeLog
25 * files for a list of changes. These files are distributed with
26 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
29 /* Key handling not part of the keymap */
31 #include <glib/gprintf.h>
34 #include "ibuskeysyms.h"
35 #include "keyname-table.h"
37 #define IBUS_NUM_KEYS G_N_ELEMENTS (gdk_keys_by_keyval)
40 gdk_keys_keyval_compare (const void *pkey, const void *pbase)
42 return (*(int *) pkey) - ((gdk_key *) pbase)->keyval;
46 ibus_keyval_name (guint keyval)
48 static gchar buf[100];
51 /* Check for directly encoded 24-bit UCS characters: */
52 if ((keyval & 0xff000000) == 0x01000000)
54 g_sprintf (buf, "U+%.04X", (keyval & 0x00ffffff));
58 found = bsearch (&keyval, gdk_keys_by_keyval,
59 IBUS_NUM_KEYS, sizeof (gdk_key),
60 gdk_keys_keyval_compare);
64 while ((found > gdk_keys_by_keyval) &&
65 ((found - 1)->keyval == keyval))
68 return (gchar *) (keynames + found->offset);
72 g_sprintf (buf, "%#x", keyval);
80 gdk_keys_name_compare (const void *pkey, const void *pbase)
82 return strcmp ((const char *) pkey,
83 (const char *) (keynames + ((const gdk_key *) pbase)->offset));
87 ibus_keyval_from_name (const gchar *keyval_name)
91 g_return_val_if_fail (keyval_name != NULL, 0);
93 found = bsearch (keyval_name, gdk_keys_by_name,
94 IBUS_NUM_KEYS, sizeof (gdk_key),
95 gdk_keys_name_compare);
99 return IBUS_KEY_VoidSymbol;
117 NULL, NULL, NULL, NULL, NULL, // 13 - 17
118 NULL, NULL, NULL, NULL, NULL, // 18 - 22
119 NULL, NULL, NULL, // 23 - 25
129 ibus_key_event_to_string (guint keyval,
134 const gchar *keyval_name;
136 g_return_val_if_fail (keyval != IBUS_KEY_VoidSymbol, NULL);
138 keyval_name = ibus_keyval_name (keyval);
139 g_return_val_if_fail (keyval_name != NULL, NULL);
141 str = g_string_new ("");
143 for (i = 0; i < 32; i++) {
146 if ((modifiers & mask) == 0)
148 if (modifier_name[i] == NULL)
151 g_string_append (str, modifier_name[i]);
152 g_string_append_c (str, '+');
155 g_string_append (str, keyval_name);
157 return g_string_free (str, FALSE);
161 ibus_key_event_from_string (const gchar *string,
165 g_return_val_if_fail (string != NULL, FALSE);
166 g_return_val_if_fail (keyval != NULL, FALSE);
167 g_return_val_if_fail (modifiers != NULL, FALSE);
169 gchar **tokens = NULL;
171 gboolean retval = FALSE;
173 tokens = g_strsplit (string, "+", 0);
174 g_return_val_if_fail (tokens != NULL, FALSE);
179 for (p = tokens; *(p + 1) != NULL; p++) {
181 for (i = 0; i < 32; i++) {
182 if (g_strcmp0 (modifier_name[i], *p) != 0)
184 *modifiers |= (1 << i);
192 *keyval = ibus_keyval_from_name (*p);
193 if (*keyval != IBUS_KEY_VoidSymbol)