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>
34 #include "../globals.h"
35 #include "../simple_dialog.h"
36 #include "../ui_util.h"
38 #include "gtk/goto_dlg.h"
39 #include "gtk/dlg_utils.h"
40 #include "gtk/gui_utils.h"
41 #include "gtk/help_dlg.h"
44 /* Capture callback data keys */
45 #define E_GOTO_FNUMBER_KEY "goto_fnumber_te"
48 goto_frame_ok_cb(GtkWidget *ok_bt, gpointer parent_w);
51 goto_frame_cb(GtkWidget *w _U_, gpointer d _U_)
53 GtkWidget *goto_frame_w, *main_vb, *fnumber_hb, *fnumber_lb, *fnumber_te,
54 *bbox, *ok_bt, *cancel_bt, *help_bt;
56 goto_frame_w = dlg_window_new("Wireshark: Go To Packet");
58 /* Container for each row of widgets */
59 main_vb = gtk_vbox_new(FALSE, 3);
60 gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
61 gtk_container_add(GTK_CONTAINER(goto_frame_w), main_vb);
62 gtk_widget_show(main_vb);
64 /* Frame number row */
65 fnumber_hb = gtk_hbox_new(FALSE, 3);
66 gtk_container_add(GTK_CONTAINER(main_vb), fnumber_hb);
67 gtk_widget_show(fnumber_hb);
69 fnumber_lb = gtk_label_new("Packet number:");
70 gtk_box_pack_start(GTK_BOX(fnumber_hb), fnumber_lb, FALSE, FALSE, 0);
71 gtk_widget_show(fnumber_lb);
73 fnumber_te = gtk_entry_new();
74 gtk_box_pack_start(GTK_BOX(fnumber_hb), fnumber_te, FALSE, FALSE, 0);
75 gtk_widget_show(fnumber_te);
77 /* Button row: OK and cancel buttons */
78 bbox = dlg_button_row_new(GTK_STOCK_JUMP_TO, GTK_STOCK_CANCEL, GTK_STOCK_HELP, NULL);
79 gtk_container_add(GTK_CONTAINER(main_vb), bbox);
80 gtk_widget_show(bbox);
82 ok_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_JUMP_TO);
83 g_signal_connect(ok_bt, "clicked", G_CALLBACK(goto_frame_ok_cb), goto_frame_w);
85 cancel_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CANCEL);
86 window_set_cancel_button(goto_frame_w, cancel_bt, window_cancel_button_cb);
88 help_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);
89 g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb), (gpointer)HELP_GOTO_DIALOG);
91 gtk_widget_grab_default(ok_bt);
93 /* Catch the "activate" signal on the frame number text entry, so that
94 if the user types Return there, we act as if the "OK" button
95 had been selected, as happens if Return is typed if some widget
96 that *doesn't* handle the Return key has the input focus. */
97 dlg_set_activate(fnumber_te, ok_bt);
99 /* Give the initial focus to the "Packet number" entry box. */
100 gtk_widget_grab_focus(fnumber_te);
102 /* Attach pointers to needed widgets to the capture prefs window/object */
103 g_object_set_data(G_OBJECT(goto_frame_w), E_GOTO_FNUMBER_KEY, fnumber_te);
105 g_signal_connect(goto_frame_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
107 gtk_widget_show(goto_frame_w);
108 window_present(goto_frame_w);
112 goto_frame_ok_cb(GtkWidget *ok_bt _U_, gpointer parent_w)
114 GtkWidget *fnumber_te;
115 const gchar *fnumber_text;
119 fnumber_te = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w), E_GOTO_FNUMBER_KEY);
121 fnumber_text = gtk_entry_get_text(GTK_ENTRY(fnumber_te));
122 fnumber = strtoul(fnumber_text, &p, 10);
123 if (p == fnumber_text || *p != '\0') {
125 XXX - what about negative numbers (which "strtoul()" allows)?
126 Can we hack up signal handlers for the widget to make it
127 reject attempts to type in characters other than digits? */
128 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
129 "The packet number you entered isn't a valid number.");
133 if (cf_goto_frame(&cfile, fnumber)) {
134 /* We succeeded in going to that frame; we're done. */
135 window_destroy(GTK_WIDGET(parent_w));
140 * Go to frame specified by currently selected protocol tree item.
143 goto_framenum_cb(GtkWidget *w _U_, gpointer data _U_)
145 cf_goto_framenum(&cfile);
149 goto_top_frame_cb(GtkWidget *w _U_, gpointer d _U_)
151 cf_goto_top_frame(&cfile);
155 goto_bottom_frame_cb(GtkWidget *w _U_, gpointer d _U_)
157 cf_goto_bottom_frame(&cfile);
161 goto_next_frame_cb(GtkWidget *w _U_, gpointer d _U_)
163 #ifdef NEW_PACKET_LIST
164 new_packet_list_next();
171 goto_previous_frame_cb(GtkWidget *w _U_, gpointer d _U_)
173 #ifdef NEW_PACKET_LIST
174 new_packet_list_prev();