2 * Routines for "go to packet" window
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
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"
39 #include "gui_utils.h"
42 /* Capture callback data keys */
43 #define E_GOTO_FNUMBER_KEY "goto_fnumber_te"
46 goto_frame_ok_cb(GtkWidget *ok_bt, gpointer parent_w);
49 goto_frame_cb(GtkWidget *w _U_, gpointer d _U_)
51 GtkWidget *goto_frame_w, *main_vb, *fnumber_hb, *fnumber_lb, *fnumber_te,
52 *bbox, *ok_bt, *cancel_bt, *help_bt;
54 goto_frame_w = dlg_window_new("Wireshark: Go To Packet");
56 /* Container for each row of widgets */
57 main_vb = gtk_vbox_new(FALSE, 3);
58 gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
59 gtk_container_add(GTK_CONTAINER(goto_frame_w), main_vb);
60 gtk_widget_show(main_vb);
62 /* Frame number row */
63 fnumber_hb = gtk_hbox_new(FALSE, 3);
64 gtk_container_add(GTK_CONTAINER(main_vb), fnumber_hb);
65 gtk_widget_show(fnumber_hb);
67 fnumber_lb = gtk_label_new("Packet number:");
68 gtk_box_pack_start(GTK_BOX(fnumber_hb), fnumber_lb, FALSE, FALSE, 0);
69 gtk_widget_show(fnumber_lb);
71 fnumber_te = gtk_entry_new();
72 gtk_box_pack_start(GTK_BOX(fnumber_hb), fnumber_te, FALSE, FALSE, 0);
73 gtk_widget_show(fnumber_te);
75 /* Button row: OK and cancel buttons */
76 if(topic_available(HELP_GOTO_DIALOG)) {
77 bbox = dlg_button_row_new(GTK_STOCK_JUMP_TO, GTK_STOCK_CANCEL, GTK_STOCK_HELP, NULL);
79 bbox = dlg_button_row_new(GTK_STOCK_JUMP_TO, GTK_STOCK_CANCEL, NULL);
81 gtk_container_add(GTK_CONTAINER(main_vb), bbox);
82 gtk_widget_show(bbox);
84 ok_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_JUMP_TO);
85 SIGNAL_CONNECT(ok_bt, "clicked", goto_frame_ok_cb, goto_frame_w);
87 cancel_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_CANCEL);
88 window_set_cancel_button(goto_frame_w, cancel_bt, window_cancel_button_cb);
90 if(topic_available(HELP_GOTO_DIALOG)) {
91 help_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_HELP);
92 SIGNAL_CONNECT(help_bt, "clicked", topic_cb, HELP_GOTO_DIALOG);
95 gtk_widget_grab_default(ok_bt);
97 /* Catch the "activate" signal on the frame number text entry, so that
98 if the user types Return there, we act as if the "OK" button
99 had been selected, as happens if Return is typed if some widget
100 that *doesn't* handle the Return key has the input focus. */
101 dlg_set_activate(fnumber_te, ok_bt);
103 /* Give the initial focus to the "Packet number" entry box. */
104 gtk_widget_grab_focus(fnumber_te);
106 /* Attach pointers to needed widgets to the capture prefs window/object */
107 OBJECT_SET_DATA(goto_frame_w, E_GOTO_FNUMBER_KEY, fnumber_te);
109 SIGNAL_CONNECT(goto_frame_w, "delete_event", window_delete_event_cb, NULL);
111 gtk_widget_show(goto_frame_w);
112 window_present(goto_frame_w);
116 goto_frame_ok_cb(GtkWidget *ok_bt _U_, gpointer parent_w)
118 GtkWidget *fnumber_te;
119 const gchar *fnumber_text;
123 fnumber_te = (GtkWidget *)OBJECT_GET_DATA(parent_w, E_GOTO_FNUMBER_KEY);
125 fnumber_text = gtk_entry_get_text(GTK_ENTRY(fnumber_te));
126 fnumber = strtoul(fnumber_text, &p, 10);
127 if (p == fnumber_text || *p != '\0') {
129 XXX - what about negative numbers (which "strtoul()" allows)?
130 Can we hack up signal handlers for the widget to make it
131 reject attempts to type in characters other than digits? */
132 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
133 "The packet number you entered isn't a valid number.");
137 if (cf_goto_frame(&cfile, fnumber)) {
138 /* We succeeded in going to that frame; we're done. */
139 window_destroy(GTK_WIDGET(parent_w));
144 * Go to frame specified by currently selected protocol tree item.
147 goto_framenum_cb(GtkWidget *w _U_, gpointer data _U_)
149 cf_goto_framenum(&cfile);
153 goto_top_frame_cb(GtkWidget *w _U_, gpointer d _U_)
155 cf_goto_top_frame(&cfile);
159 goto_bottom_frame_cb(GtkWidget *w _U_, gpointer d _U_)
161 cf_goto_bottom_frame(&cfile);