4 * $Id: util.c,v 1.3 1998/09/27 22:12:46 gerald Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@zing.org>
8 * Copyright 1998 Gerald Combs
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.
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.
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.
38 #include "image/icon-excl.xpm"
40 const gchar *bm_key = "button mask";
42 /* Simple dialog function - Displays a dialog box with the supplied message
46 * type : One of ESD_TYPE_*. Currently ignored.
47 * btn_mask : The address of a gint. The value passed in determines if
48 * the 'Cancel' button is displayed. The button pressed by the
49 * user is passed back.
50 * message : The text displayed in the dialog.
53 * - Switch to variable args
56 simple_dialog(gint type, gint *btn_mask, gchar *message) {
57 GtkWidget *win, *main_vb, *top_hb, *type_pm, *msg_label,
58 *bbox, *ok_btn, *cancel_btn;
65 win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
66 gtk_container_border_width(GTK_CONTAINER(win), 7);
67 gtk_window_set_title(GTK_WINDOW(win), "Ethereal: Warning");
68 gtk_object_set_data(GTK_OBJECT(win), bm_key, btn_mask);
70 /* Container for our rows */
71 main_vb = gtk_vbox_new(FALSE, 5);
72 gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
73 gtk_container_add(GTK_CONTAINER(win), main_vb);
74 gtk_widget_show(main_vb);
76 /* Top row: Icon and message text */
77 top_hb = gtk_hbox_new(FALSE, 5);
78 gtk_container_add(GTK_CONTAINER(main_vb), top_hb);
79 gtk_widget_show(top_hb);
81 style = gtk_widget_get_style(win);
82 cmap = gdk_colormap_get_system();
83 pixmap = gdk_pixmap_colormap_create_from_xpm_d(NULL, cmap, &mask,
84 &style->bg[GTK_STATE_NORMAL], icon_excl_xpm);
85 type_pm = gtk_pixmap_new(pixmap, mask);
86 gtk_container_add(GTK_CONTAINER(top_hb), type_pm);
87 gtk_widget_show(type_pm);
89 msg_label = gtk_label_new(message);
90 gtk_label_set_justify(GTK_LABEL(msg_label), GTK_JUSTIFY_FILL);
91 gtk_container_add(GTK_CONTAINER(top_hb), msg_label);
92 gtk_widget_show(msg_label);
95 bbox = gtk_hbutton_box_new();
96 gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
97 gtk_container_add(GTK_CONTAINER(main_vb), bbox);
98 gtk_widget_show(bbox);
100 ok_btn = gtk_button_new_with_label ("OK");
101 gtk_signal_connect_object(GTK_OBJECT(ok_btn), "clicked",
102 GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT (win));
103 gtk_container_add(GTK_CONTAINER(bbox), ok_btn);
104 GTK_WIDGET_SET_FLAGS(ok_btn, GTK_CAN_DEFAULT);
105 gtk_widget_grab_default(ok_btn);
106 gtk_widget_show(ok_btn);
108 if (btn_mask && *btn_mask == ESD_BTN_CANCEL) {
109 cancel_btn = gtk_button_new_with_label("Cancel");
110 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
111 GTK_SIGNAL_FUNC(simple_dialog_cancel_cb), (gpointer) win);
112 gtk_container_add(GTK_CONTAINER(bbox), cancel_btn);
113 gtk_widget_show(cancel_btn);
117 *btn_mask = ESD_BTN_OK;
119 gtk_widget_show(win);
123 simple_dialog_cancel_cb(GtkWidget *w, gpointer win) {
124 gint *btn_mask = (gint *) gtk_object_get_data(win, bm_key);
127 *btn_mask = ESD_BTN_CANCEL;
128 gtk_widget_destroy(GTK_WIDGET(win));