diff options
author | Guy Harris <guy@alum.mit.edu> | 2000-05-08 04:23:46 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2000-05-08 04:23:46 +0000 |
commit | e160ffa08cbb059edfa1049fd37fbc6093b50678 (patch) | |
tree | 75620276b0502829264d921f583857c733fbcb46 /gtk/dlg_utils.c | |
parent | e7013460968edce77ad2e67e8f6af6f6e502f196 (diff) | |
download | wireshark-e160ffa08cbb059edfa1049fd37fbc6093b50678.tar.gz wireshark-e160ffa08cbb059edfa1049fd37fbc6093b50678.tar.bz2 wireshark-e160ffa08cbb059edfa1049fd37fbc6093b50678.zip |
Add functions to create buttons whose labels specify mnemonics, i.e.
that contain an "_" preceding a letter, indicating that the letter is to
be underlined in the label, and that if the key for that letter is
pressed (either with Alt or without it) in the dialog box to which the
button belongs, and the widget with the input focus doesn't do anything
with that button, the button is sent the "clicked" signal.
Attach mnemonics to the buttons in the "Display->Options" dialog box.
svn path=/trunk/; revision=1915
Diffstat (limited to 'gtk/dlg_utils.c')
-rw-r--r-- | gtk/dlg_utils.c | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/gtk/dlg_utils.c b/gtk/dlg_utils.c index ac5f50af10..63d1ee2155 100644 --- a/gtk/dlg_utils.c +++ b/gtk/dlg_utils.c @@ -1,7 +1,7 @@ /* dlg_utils.c * Utilities to use when constructing dialogs * - * $Id: dlg_utils.c,v 1.1 2000/05/02 08:04:28 guy Exp $ + * $Id: dlg_utils.c,v 1.2 2000/05/08 04:23:46 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -89,3 +89,63 @@ dlg_key_press (GtkWidget *widget, GdkEventKey *event, gpointer cancel_button) return FALSE; } + +/* Sigh. GTK+ appears not to acknowledge that it should be possible + to attach mnemonics to anything other than menu items; perhaps + it's easy to dig up the label widget for a button, but, right now, + it appears to be easier just to cut-and-paste + "gtk_radio_button_new_with_label()". */ +GtkWidget * +dlg_radio_button_new_with_label_with_mnemonic(GSList *group, + const gchar *label, GtkAccelGroup *accel_group) +{ + GtkWidget *radio_button; + GtkWidget *label_widget; + guint accel_key; + + radio_button = gtk_radio_button_new (group); + label_widget = gtk_label_new (label); + gtk_misc_set_alignment (GTK_MISC (label_widget), 0.0, 0.5); + + gtk_container_add (GTK_CONTAINER (radio_button), label_widget); + gtk_widget_show (label_widget); + + accel_key = gtk_label_parse_uline (GTK_LABEL (label_widget), label); + if (accel_key != GDK_VoidSymbol) { + /* Yes, we have a mnemonic. */ + gtk_widget_add_accelerator (radio_button, "clicked", accel_group, + accel_key, 0, GTK_ACCEL_LOCKED); + gtk_widget_add_accelerator (radio_button, "clicked", accel_group, + accel_key, GDK_MOD1_MASK, GTK_ACCEL_LOCKED); + } + + return radio_button; +} + +/* The same applies to check buttons. */ +GtkWidget * +dlg_check_button_new_with_label_with_mnemonic(const gchar *label, + GtkAccelGroup *accel_group) +{ + GtkWidget *check_button; + GtkWidget *label_widget; + guint accel_key; + + check_button = gtk_check_button_new (); + label_widget = gtk_label_new (label); + gtk_misc_set_alignment (GTK_MISC (label_widget), 0.0, 0.5); + + gtk_container_add (GTK_CONTAINER (check_button), label_widget); + gtk_widget_show (label_widget); + + accel_key = gtk_label_parse_uline (GTK_LABEL (label_widget), label); + if (accel_key != GDK_VoidSymbol) { + /* Yes, we have a mnemonic. */ + gtk_widget_add_accelerator (check_button, "clicked", accel_group, + accel_key, 0, GTK_ACCEL_LOCKED); + gtk_widget_add_accelerator (check_button, "clicked", accel_group, + accel_key, GDK_MOD1_MASK, GTK_ACCEL_LOCKED); + } + + return check_button; +} |