]> git.samba.org - obnox/wireshark/wip.git/blob - gtk2/dlg_utils.c
Change to color filters :
[obnox/wireshark/wip.git] / gtk2 / dlg_utils.c
1 /* dlg_utils.c
2  * Utilities to use when constructing dialogs
3  *
4  * $Id: dlg_utils.c,v 1.2 2002/09/01 09:46:54 oabad Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@zing.org>
8  * Copyright 1998 Gerald Combs
9  *
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <gtk/gtk.h>
31 #include <gdk/gdkkeysyms.h>
32
33 #include "gtkglobals.h"
34 #include "ui_util.h"
35
36 static void
37 dlg_activate (GtkWidget *widget, gpointer ok_button);
38
39 static gint
40 dlg_key_press (GtkWidget *widget, GdkEventKey *event, gpointer cancel_button);
41
42 /* Create a dialog box window that belongs to Ethereal's main window. */
43 GtkWidget *
44 dlg_window_new(const gchar *title)
45 {
46   GtkWidget *win;
47
48   win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
49   gtk_window_set_transient_for(GTK_WINDOW(win), GTK_WINDOW(top_level));
50   gtk_window_set_title(GTK_WINDOW(win), title);
51   g_signal_connect(G_OBJECT(win), "realize",
52                    G_CALLBACK(window_icon_realize_cb), NULL);
53   return win;
54 }
55
56 /* Set the "activate" signal for a widget to call a routine to
57    activate the "OK" button for a dialog box.
58
59    XXX - there should be a way to specify that a GtkEntry widget
60    shouldn't itself handle the Return key, but should let it be
61    passed on to the parent, so that you don't have to do this
62    by hand for every GtkEntry widget in a dialog box, but, alas,
63    there isn't.  (Does this problem exist for other widgets?
64    I.e., are there any others that seize the Return key? */
65 void
66 dlg_set_activate(GtkWidget *widget, GtkWidget *ok_button)
67 {
68   g_signal_connect(G_OBJECT(widget), "activate",
69                    G_CALLBACK(dlg_activate), ok_button);
70 }
71
72 static void
73 dlg_activate (GtkWidget *widget _U_, gpointer ok_button)
74 {
75   gtk_widget_activate(GTK_WIDGET(ok_button));
76 }
77
78 /* Set the "key_press_event" signal for a top-level dialog window to
79    call a routine to activate the "Cancel" button for a dialog box if
80    the key being pressed is the <Esc> key.
81
82    XXX - there should be a GTK+ widget that'll do that for you, and
83    let you specify a "Cancel" button.  It should also not impose
84    a requirement that there be a separator in the dialog box, as
85    the GtkDialog widget does; the visual convention that there's
86    such a separator between the rest of the dialog boxes and buttons
87    such as "OK" and "Cancel" is, for better or worse, not universal
88    (not even in GTK+ - look at the GtkFileSelection dialog!). */
89 void
90 dlg_set_cancel(GtkWidget *widget, GtkWidget *cancel_button)
91 {
92   g_signal_connect(G_OBJECT(widget), "key_press_event",
93                    G_CALLBACK(dlg_key_press), cancel_button);
94 }
95
96 static gint
97 dlg_key_press (GtkWidget *widget, GdkEventKey *event, gpointer cancel_button)
98 {
99   g_return_val_if_fail (widget != NULL, FALSE);
100   g_return_val_if_fail (event != NULL, FALSE);
101
102   if (event->keyval == GDK_Escape) {
103     gtk_widget_activate(GTK_WIDGET(cancel_button));
104     return TRUE;
105   }
106
107   return FALSE;
108 }