2 * Routines for packet display windows
4 * $Id: display.c,v 1.9 1999/07/13 02:52:48 gram 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.
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
47 #ifdef HAVE_SYS_SOCKET_H
48 #include <sys/socket.h>
55 #ifdef HAVE_SYS_IOCTL_H
56 #include <sys/ioctl.h>
66 #ifdef NEED_SNPRINTF_H
72 # include "snprintf.h"
75 #ifdef HAVE_SYS_SOCKIO_H
76 # include <sys/sockio.h>
79 #include "timestamp.h"
84 extern capture_file cf;
85 extern GtkWidget *packet_list;
87 /* Display callback data keys */
88 #define E_DISPLAY_TIME_ABS_KEY "display_time_abs"
89 #define E_DISPLAY_TIME_REL_KEY "display_time_rel"
90 #define E_DISPLAY_TIME_DELTA_KEY "display_time_delta"
92 static void display_opt_ok_cb(GtkWidget *, gpointer);
93 static void display_opt_apply_cb(GtkWidget *, gpointer);
94 static void display_opt_close_cb(GtkWidget *, gpointer);
97 * Keep track of whether the "Display Options" window is active, so that,
98 * if it is, selecting "Display/Options" doesn't pop up another such
101 static int display_opt_window_active;
102 static ts_type prev_timestamp_type;
105 display_opt_cb(GtkWidget *w, gpointer d) {
106 GtkWidget *display_opt_w, *button, *main_vb, *bbox, *ok_bt, *apply_bt, *cancel_bt;
108 /* If there's already a "Display Options" window active, don't pop
111 XXX - this should arguably give the input focus to the active
112 "Display Options" window, if possible. */
113 if (display_opt_window_active)
116 /* Save the current timestamp type, so that "Cancel" can put it back
117 if we've changed it with "Apply". */
118 prev_timestamp_type = timestamp_type;
120 display_opt_w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
121 gtk_window_set_title(GTK_WINDOW(display_opt_w), "Ethereal: Display Options");
123 /* Container for each row of widgets */
124 main_vb = gtk_vbox_new(FALSE, 3);
125 gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
126 gtk_container_add(GTK_CONTAINER(display_opt_w), main_vb);
127 gtk_widget_show(main_vb);
129 button = gtk_radio_button_new_with_label(NULL, "Time of day");
130 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button),
131 (timestamp_type == ABSOLUTE));
132 gtk_object_set_data(GTK_OBJECT(display_opt_w), E_DISPLAY_TIME_ABS_KEY,
134 gtk_box_pack_start(GTK_BOX(main_vb), button, TRUE, TRUE, 0);
135 gtk_widget_show(button);
137 button = gtk_radio_button_new_with_label(
138 gtk_radio_button_group(GTK_RADIO_BUTTON(button)),
139 "Seconds since beginning of capture");
140 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button),
141 (timestamp_type == RELATIVE));
142 gtk_object_set_data(GTK_OBJECT(display_opt_w), E_DISPLAY_TIME_REL_KEY,
144 gtk_box_pack_start(GTK_BOX(main_vb), button, TRUE, TRUE, 0);
145 gtk_widget_show(button);
147 button = gtk_radio_button_new_with_label(
148 gtk_radio_button_group(GTK_RADIO_BUTTON(button)),
149 "Seconds since previous frame");
150 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button),
151 (timestamp_type == DELTA));
152 gtk_object_set_data(GTK_OBJECT(display_opt_w), E_DISPLAY_TIME_DELTA_KEY,
154 gtk_box_pack_start(GTK_BOX(main_vb), button, TRUE, TRUE, 0);
155 gtk_widget_show(button);
157 /* Button row: OK, Apply, and Cancel buttons */
158 bbox = gtk_hbutton_box_new();
159 gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
160 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5);
161 gtk_container_add(GTK_CONTAINER(main_vb), bbox);
162 gtk_widget_show(bbox);
164 ok_bt = gtk_button_new_with_label ("OK");
165 gtk_signal_connect(GTK_OBJECT(ok_bt), "clicked",
166 GTK_SIGNAL_FUNC(display_opt_ok_cb), GTK_OBJECT(display_opt_w));
167 GTK_WIDGET_SET_FLAGS(ok_bt, GTK_CAN_DEFAULT);
168 gtk_box_pack_start (GTK_BOX (bbox), ok_bt, TRUE, TRUE, 0);
169 gtk_widget_grab_default(ok_bt);
170 gtk_widget_show(ok_bt);
172 apply_bt = gtk_button_new_with_label ("Apply");
173 gtk_signal_connect(GTK_OBJECT(apply_bt), "clicked",
174 GTK_SIGNAL_FUNC(display_opt_apply_cb), GTK_OBJECT(display_opt_w));
175 GTK_WIDGET_SET_FLAGS(apply_bt, GTK_CAN_DEFAULT);
176 gtk_box_pack_start (GTK_BOX (bbox), apply_bt, TRUE, TRUE, 0);
177 gtk_widget_show(apply_bt);
179 cancel_bt = gtk_button_new_with_label ("Cancel");
180 gtk_signal_connect(GTK_OBJECT(cancel_bt), "clicked",
181 GTK_SIGNAL_FUNC(display_opt_close_cb), GTK_OBJECT(display_opt_w));
182 GTK_WIDGET_SET_FLAGS(cancel_bt, GTK_CAN_DEFAULT);
183 gtk_box_pack_start (GTK_BOX (bbox), cancel_bt, TRUE, TRUE, 0);
184 gtk_widget_show(cancel_bt);
186 display_opt_window_active = TRUE;
187 gtk_widget_show(display_opt_w);
191 display_opt_ok_cb(GtkWidget *ok_bt, gpointer parent_w) {
194 button = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(parent_w),
195 E_DISPLAY_TIME_ABS_KEY);
196 if (GTK_TOGGLE_BUTTON (button)->active)
197 timestamp_type = ABSOLUTE;
199 button = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(parent_w),
200 E_DISPLAY_TIME_REL_KEY);
201 if (GTK_TOGGLE_BUTTON (button)->active)
202 timestamp_type = RELATIVE;
204 button = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(parent_w),
205 E_DISPLAY_TIME_DELTA_KEY);
206 if (GTK_TOGGLE_BUTTON (button)->active)
207 timestamp_type = DELTA;
209 gtk_widget_destroy(GTK_WIDGET(parent_w));
210 display_opt_window_active = FALSE;
212 change_time_formats(&cf);
216 display_opt_apply_cb(GtkWidget *ok_bt, gpointer parent_w) {
219 button = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(parent_w),
220 E_DISPLAY_TIME_ABS_KEY);
221 if (GTK_TOGGLE_BUTTON (button)->active)
222 timestamp_type = ABSOLUTE;
224 button = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(parent_w),
225 E_DISPLAY_TIME_REL_KEY);
226 if (GTK_TOGGLE_BUTTON (button)->active)
227 timestamp_type = RELATIVE;
229 button = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(parent_w),
230 E_DISPLAY_TIME_DELTA_KEY);
231 if (GTK_TOGGLE_BUTTON (button)->active)
232 timestamp_type = DELTA;
234 change_time_formats(&cf);
238 display_opt_close_cb(GtkWidget *close_bt, gpointer parent_w) {
240 if (timestamp_type != prev_timestamp_type) {
241 timestamp_type = prev_timestamp_type;
242 change_time_formats(&cf);
245 gtk_grab_remove(GTK_WIDGET(parent_w));
246 gtk_widget_destroy(GTK_WIDGET(parent_w));
247 display_opt_window_active = FALSE;