diff options
author | Owen Taylor <otaylor@redhat.com> | 2002-02-21 17:14:10 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 2002-02-21 17:14:10 +0000 |
commit | 708e1a95749ad61cb0167f729a77e951a30388cf (patch) | |
tree | 772eb9a2ff7cdfd6e94d79973a0a7645c9d41861 /tests | |
parent | 3b94ae4be5e2efaae91446c365077e8f5f4ee90d (diff) | |
download | gdk-pixbuf-708e1a95749ad61cb0167f729a77e951a30388cf.tar.gz |
Implement "fuzzy" key binding lookups; allow matches on key and level but
Wed Feb 20 14:26:47 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkkeyhash.[ch]: Implement "fuzzy" key binding lookups;
allow matches on key and level but not group. Also, implement
ignoring "consumed modifiers correctly."
* gtk/gtkaccelgroup.c gtk/gtkbindings.c: Convert to using
GtkKeyHash.
* gtk/gtkdebug.h gtk/gtkmain.c: Support GTK_DEBUG=keybindings
* gdk/x11/gdkevents-x11.c (gdk_event_translate): Fill in
the group for key release events as well as key press events.
* gdk/gdkkeys.h gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state):
Rename unused_modifiers to consumed_modifiers, make the docs and
non-Xkb implementation match the Xkb implementation.
* gdk/linux-fb/gdkkeyboard-fb.c gdk/win32/gdkkeys-win32.c: Propagate
doc and parameter name changes.
* gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state):
XkbTranslateKeyCode doesn't handle LockMask, we need to handle
it ourselves.
* gdk/x11/gdkkeys-x11.c (gdk_keymap_translate_keyboard_state): Force
<Shift>Tab to give GDK_ISO_Left_Tab, since we need consistency
to allow dealing with ISO_Left_Tab.
* gtk/gtkwindow.c gtk/gtktextview.c gtk/gtkscrolledwindow.c
gtk/gtkpaned.c gtk/gtkcombo.c gtk/gtknotebook.c:
Remove inappropriate uses of GDK_ISO_Left_Tab. (GDK_ISO_Left_Tab
or <Shift>Tab both are equivalent as a binding specifier.)
* gtk/gtkbutton.c (gtk_button_class_init): Make ::activate
GTK_RUN_ACTION, so you can bind an accelerator to it.
* gtk/gtklabel.c (gtk_label_set_uline_text_internal): Call
gdk_unicode_to_keyval on the mnemonic character.
* tests/testgtk.c: Add a test for the new fuzzy key binding matching.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/testgtk.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/testgtk.c b/tests/testgtk.c index 7bc2a4710..216548cf4 100644 --- a/tests/testgtk.c +++ b/tests/testgtk.c @@ -3433,6 +3433,83 @@ create_item_factory (void) gtk_widget_destroy (window); } +static GtkWidget * +accel_button_new (GtkAccelGroup *accel_group, + const gchar *text, + const gchar *accel) +{ + guint keyval; + GdkModifierType modifiers; + GtkWidget *button; + GtkWidget *label; + + gtk_accelerator_parse (accel, &keyval, &modifiers); + g_assert (keyval); + + button = gtk_button_new (); + gtk_widget_add_accelerator (button, "activate", accel_group, + keyval, modifiers, GTK_ACCEL_VISIBLE | GTK_ACCEL_LOCKED); + + label = gtk_accel_label_new (text); + gtk_accel_label_set_accel_widget (GTK_ACCEL_LABEL (label), button); + gtk_widget_show (label); + + gtk_container_add (GTK_CONTAINER (button), label); + + return button; +} + +static void +create_key_lookup (void) +{ + static GtkWidget *window = NULL; + + if (!window) + { + GtkAccelGroup *accel_group = gtk_accel_group_new (); + GtkWidget *button; + + window = gtk_dialog_new_with_buttons ("Key Lookup", NULL, 0, + GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, + NULL); + + /* We have to expand it so the accel labels will draw their labels + */ + gtk_window_set_default_size (GTK_WINDOW (window), 300, -1); + + gtk_window_add_accel_group (GTK_WINDOW (window), accel_group); + + button = gtk_button_new_with_mnemonic ("Button 1 (_a)"); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), button, FALSE, FALSE, 0); + button = gtk_button_new_with_mnemonic ("Button 2 (_A)"); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), button, FALSE, FALSE, 0); + button = gtk_button_new_with_mnemonic ("Button 3 (_ф)"); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), button, FALSE, FALSE, 0); + button = gtk_button_new_with_mnemonic ("Button 4 (_Ф)"); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), button, FALSE, FALSE, 0); + button = gtk_button_new_with_mnemonic ("Button 6 (_b)"); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), button, FALSE, FALSE, 0); + button = accel_button_new (accel_group, "Button 7", "<Alt><Shift>b"); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), button, FALSE, FALSE, 0); + button = accel_button_new (accel_group, "Button 8", "<Alt>d"); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), button, FALSE, FALSE, 0); + button = accel_button_new (accel_group, "Button 9", "<Alt>Cyrillic_ve"); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), button, FALSE, FALSE, 0); + button = gtk_button_new_with_mnemonic ("Button 10 (_1)"); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), button, FALSE, FALSE, 0); + button = gtk_button_new_with_mnemonic ("Button 11 (_!)"); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), button, FALSE, FALSE, 0); + + g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window); + g_signal_connect (window, "response", G_CALLBACK (gtk_object_destroy), NULL); + + gtk_widget_show_all (window); + } + else + gtk_widget_destroy (window); +} + + /* create_modal_window */ @@ -11350,6 +11427,7 @@ struct { { "image from drawable", create_get_image }, { "image", create_image }, { "item factory", create_item_factory }, + { "key lookup", create_key_lookup }, { "labels", create_labels }, { "layout", create_layout }, { "list", create_list }, |