2 * Routines for "go to packet" window
4 * $Id: goto_dlg.c,v 1.23 2004/01/21 21:19:33 ulfl Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #include <epan/proto.h>
36 #include "simple_dialog.h"
37 #include "dlg_utils.h"
38 #include "compat_macros.h"
40 /* Capture callback data keys */
41 #define E_GOTO_FNUMBER_KEY "goto_fnumber_te"
44 goto_frame_ok_cb(GtkWidget *ok_bt, gpointer parent_w);
47 goto_frame_close_cb(GtkWidget *close_bt, gpointer parent_w);
50 goto_frame_cb(GtkWidget *w _U_, gpointer d _U_)
52 GtkWidget *goto_frame_w, *main_vb, *fnumber_hb, *fnumber_lb, *fnumber_te,
53 *bbox, *ok_bt, *cancel_bt;
55 goto_frame_w = dlg_window_new("Ethereal: Go To Packet");
57 /* Container for each row of widgets */
58 main_vb = gtk_vbox_new(FALSE, 3);
59 gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
60 gtk_container_add(GTK_CONTAINER(goto_frame_w), main_vb);
61 gtk_widget_show(main_vb);
63 /* Frame number row */
64 fnumber_hb = gtk_hbox_new(FALSE, 3);
65 gtk_container_add(GTK_CONTAINER(main_vb), fnumber_hb);
66 gtk_widget_show(fnumber_hb);
68 fnumber_lb = gtk_label_new("Packet number:");
69 gtk_box_pack_start(GTK_BOX(fnumber_hb), fnumber_lb, FALSE, FALSE, 0);
70 gtk_widget_show(fnumber_lb);
72 fnumber_te = gtk_entry_new();
73 gtk_box_pack_start(GTK_BOX(fnumber_hb), fnumber_te, FALSE, FALSE, 0);
74 gtk_widget_show(fnumber_te);
76 /* Button row: OK and cancel buttons */
77 bbox = dlg_button_row_new(GTK_STOCK_JUMP_TO, GTK_STOCK_CANCEL, NULL);
78 gtk_container_add(GTK_CONTAINER(main_vb), bbox);
79 gtk_widget_show(bbox);
81 ok_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_JUMP_TO);
82 SIGNAL_CONNECT(ok_bt, "clicked", goto_frame_ok_cb, goto_frame_w);
83 gtk_widget_grab_default(ok_bt);
85 cancel_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_CANCEL);
86 SIGNAL_CONNECT(cancel_bt, "clicked", goto_frame_close_cb, goto_frame_w);
88 /* Attach pointers to needed widgets to the capture prefs window/object */
89 OBJECT_SET_DATA(goto_frame_w, E_GOTO_FNUMBER_KEY, fnumber_te);
91 /* Catch the "activate" signal on the frame number text entry, so that
92 if the user types Return there, we act as if the "OK" button
93 had been selected, as happens if Return is typed if some widget
94 that *doesn't* handle the Return key has the input focus. */
95 dlg_set_activate(fnumber_te, ok_bt);
97 /* Catch the "key_press_event" signal in the window, so that we can catch
98 the ESC key being pressed and act as if the "Cancel" button had
100 dlg_set_cancel(goto_frame_w, cancel_bt);
102 /* Give the initial focus to the "Packet number" entry box. */
103 gtk_widget_grab_focus(fnumber_te);
105 gtk_widget_show(goto_frame_w);
109 goto_frame_ok_cb(GtkWidget *ok_bt _U_, gpointer parent_w)
111 GtkWidget *fnumber_te;
112 const gchar *fnumber_text;
116 fnumber_te = (GtkWidget *)OBJECT_GET_DATA(parent_w, E_GOTO_FNUMBER_KEY);
118 fnumber_text = gtk_entry_get_text(GTK_ENTRY(fnumber_te));
119 fnumber = strtoul(fnumber_text, &p, 10);
120 if (p == fnumber_text || *p != '\0') {
122 XXX - what about negative numbers (which "strtoul()" allows)?
123 Can we hack up signal handlers for the widget to make it
124 reject attempts to type in characters other than digits? */
125 simple_dialog(ESD_TYPE_CRIT, NULL,
126 "The packet number you entered isn't a valid number.");
130 if (goto_frame(&cfile, fnumber)) {
131 /* We succeeded in going to that frame; we're done. */
132 gtk_widget_destroy(GTK_WIDGET(parent_w));
137 goto_frame_close_cb(GtkWidget *close_bt _U_, gpointer parent_w)
139 gtk_grab_remove(GTK_WIDGET(parent_w));
140 gtk_widget_destroy(GTK_WIDGET(parent_w));