2 * Routines for "go to frame" window
4 * $Id: goto_dlg.c,v 1.12 2001/01/04 04:54:14 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.
45 #include "prefs_dlg.h"
46 #include "simple_dialog.h"
47 #include "dlg_utils.h"
49 /* Capture callback data keys */
50 #define E_GOTO_FNUMBER_KEY "goto_fnumber_te"
53 goto_frame_ok_cb(GtkWidget *ok_bt, gpointer parent_w);
56 goto_frame_close_cb(GtkWidget *close_bt, gpointer parent_w);
59 goto_frame_cb(GtkWidget *w, gpointer d)
61 GtkWidget *goto_frame_w, *main_vb, *fnumber_hb, *fnumber_lb, *fnumber_te,
62 *bbox, *ok_bt, *cancel_bt;
64 goto_frame_w = dlg_window_new("Ethereal: Go To Frame");
66 /* Container for each row of widgets */
67 main_vb = gtk_vbox_new(FALSE, 3);
68 gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
69 gtk_container_add(GTK_CONTAINER(goto_frame_w), main_vb);
70 gtk_widget_show(main_vb);
72 /* Frame number row */
73 fnumber_hb = gtk_hbox_new(FALSE, 3);
74 gtk_container_add(GTK_CONTAINER(main_vb), fnumber_hb);
75 gtk_widget_show(fnumber_hb);
77 fnumber_lb = gtk_label_new("Frame number:");
78 gtk_box_pack_start(GTK_BOX(fnumber_hb), fnumber_lb, FALSE, FALSE, 0);
79 gtk_widget_show(fnumber_lb);
81 fnumber_te = gtk_entry_new();
82 gtk_box_pack_start(GTK_BOX(fnumber_hb), fnumber_te, FALSE, FALSE, 0);
83 gtk_widget_show(fnumber_te);
85 /* Button row: OK and cancel buttons */
86 bbox = gtk_hbutton_box_new();
87 gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
88 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5);
89 gtk_container_add(GTK_CONTAINER(main_vb), bbox);
90 gtk_widget_show(bbox);
92 ok_bt = gtk_button_new_with_label ("OK");
93 gtk_signal_connect(GTK_OBJECT(ok_bt), "clicked",
94 GTK_SIGNAL_FUNC(goto_frame_ok_cb), GTK_OBJECT(goto_frame_w));
95 GTK_WIDGET_SET_FLAGS(ok_bt, GTK_CAN_DEFAULT);
96 gtk_box_pack_start (GTK_BOX (bbox), ok_bt, TRUE, TRUE, 0);
97 gtk_widget_grab_default(ok_bt);
98 gtk_widget_show(ok_bt);
100 cancel_bt = gtk_button_new_with_label ("Cancel");
101 gtk_signal_connect(GTK_OBJECT(cancel_bt), "clicked",
102 GTK_SIGNAL_FUNC(goto_frame_close_cb), GTK_OBJECT(goto_frame_w));
103 GTK_WIDGET_SET_FLAGS(cancel_bt, GTK_CAN_DEFAULT);
104 gtk_box_pack_start (GTK_BOX (bbox), cancel_bt, TRUE, TRUE, 0);
105 gtk_widget_show(cancel_bt);
107 /* Attach pointers to needed widgets to the capture prefs window/object */
108 gtk_object_set_data(GTK_OBJECT(goto_frame_w), E_GOTO_FNUMBER_KEY, fnumber_te);
110 /* Catch the "activate" signal on the frame number text entry, so that
111 if the user types Return there, we act as if the "OK" button
112 had been selected, as happens if Return is typed if some widget
113 that *doesn't* handle the Return key has the input focus. */
114 dlg_set_activate(fnumber_te, ok_bt);
116 /* Catch the "key_press_event" signal in the window, so that we can catch
117 the ESC key being pressed and act as if the "Cancel" button had
119 dlg_set_cancel(goto_frame_w, cancel_bt);
121 /* Give the initial focus to the "Frame number" entry box. */
122 gtk_widget_grab_focus(fnumber_te);
124 gtk_widget_show(goto_frame_w);
128 goto_frame_ok_cb(GtkWidget *ok_bt, gpointer parent_w)
130 GtkWidget *fnumber_te;
135 fnumber_te = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(parent_w), E_GOTO_FNUMBER_KEY);
137 fnumber_text = gtk_entry_get_text(GTK_ENTRY(fnumber_te));
138 fnumber = strtoul(fnumber_text, &p, 10);
139 if (p == fnumber_text || *p != '\0') {
141 XXX - what about negative numbers (which "strtoul()" allows)?
142 Can we hack up signal handlers for the widget to make it
143 reject attempts to type in characters other than digits? */
144 simple_dialog(ESD_TYPE_CRIT, NULL,
145 "The frame number you entered isn't a valid number.");
149 switch (goto_frame(&cfile, fnumber)) {
152 simple_dialog(ESD_TYPE_CRIT, NULL, "There is no frame with that frame number.");
155 case FRAME_NOT_DISPLAYED:
156 /* XXX - add it to the display filter? */
157 simple_dialog(ESD_TYPE_CRIT, NULL, "The frame with that frame number is not currently being displayed.");
161 gtk_widget_destroy(GTK_WIDGET(parent_w));
167 goto_frame_close_cb(GtkWidget *close_bt, gpointer parent_w)
169 gtk_grab_remove(GTK_WIDGET(parent_w));
170 gtk_widget_destroy(GTK_WIDGET(parent_w));