add parameter dcerpc_info to PIDL_dissect_ipv?address()
[wireshark-wip.git] / ui / gtk / goto_dlg.c
blob9262d37dc6fb8a135653f8db8da83db9d60463f8
1 /* goto_dlg.c
2 * Routines for "go to packet" window
4 * $Id$
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "config.h"
28 #include <gtk/gtk.h>
30 #include <stdlib.h>
32 #include <epan/proto.h>
34 #include "../globals.h"
35 #include "ui/simple_dialog.h"
36 #include "ui/ui_util.h"
38 #include "ui/gtk/goto_dlg.h"
39 #include "ui/gtk/dlg_utils.h"
40 #include "ui/gtk/gui_utils.h"
41 #include "ui/gtk/help_dlg.h"
44 /* Capture callback data keys */
45 #define E_GOTO_FNUMBER_KEY "goto_fnumber_te"
47 static void
48 goto_frame_ok_cb(GtkWidget *ok_bt, gpointer parent_w);
50 void
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 = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 3, FALSE);
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 = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 3, FALSE);
66 gtk_box_pack_start(GTK_BOX (main_vb), fnumber_hb, TRUE, TRUE, 0);
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_box_pack_start(GTK_BOX (main_vb), bbox, TRUE, TRUE, 0);
81 gtk_widget_show(bbox);
83 ok_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_JUMP_TO);
84 g_signal_connect(ok_bt, "clicked", G_CALLBACK(goto_frame_ok_cb), goto_frame_w);
86 cancel_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CANCEL);
87 window_set_cancel_button(goto_frame_w, cancel_bt, window_cancel_button_cb);
89 help_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);
90 g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb), (gpointer)HELP_GOTO_DIALOG);
92 gtk_widget_grab_default(ok_bt);
94 /* Catch the "activate" signal on the frame number text entry, so that
95 if the user types Return there, we act as if the "OK" button
96 had been selected, as happens if Return is typed if some widget
97 that *doesn't* handle the Return key has the input focus. */
98 dlg_set_activate(fnumber_te, ok_bt);
100 /* Give the initial focus to the "Packet number" entry box. */
101 gtk_widget_grab_focus(fnumber_te);
103 /* Attach pointers to needed widgets to the capture prefs window/object */
104 g_object_set_data(G_OBJECT(goto_frame_w), E_GOTO_FNUMBER_KEY, fnumber_te);
106 g_signal_connect(goto_frame_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
108 gtk_widget_show(goto_frame_w);
109 window_present(goto_frame_w);
112 static void
113 goto_frame_ok_cb(GtkWidget *ok_bt _U_, gpointer parent_w)
115 GtkWidget *fnumber_te;
116 const gchar *fnumber_text;
117 guint fnumber;
118 char *p;
120 fnumber_te = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w), E_GOTO_FNUMBER_KEY);
122 fnumber_text = gtk_entry_get_text(GTK_ENTRY(fnumber_te));
123 fnumber = (guint) strtoul(fnumber_text, &p, 10);
124 if (p == fnumber_text || *p != '\0') {
125 /* Illegal number.
126 XXX - what about negative numbers (which "strtoul()" allows)?
127 Can we hack up signal handlers for the widget to make it
128 reject attempts to type in characters other than digits?
129 What about numbers > the maximum possible guint? */
130 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
131 "The packet number you entered isn't a valid number.");
132 return;
135 if (cf_goto_frame(&cfile, fnumber)) {
136 /* We succeeded in going to that frame; we're done. */
137 window_destroy(GTK_WIDGET(parent_w));
142 * Go to frame specified by currently selected protocol tree item.
144 void
145 goto_framenum_cb(GtkWidget *w _U_, gpointer data _U_)
147 cf_goto_framenum(&cfile);
150 void
151 goto_top_frame_cb(GtkWidget *w _U_, gpointer d _U_)
153 cf_goto_top_frame();
156 void
157 goto_bottom_frame_cb(GtkWidget *w _U_, gpointer d _U_)
159 cf_goto_bottom_frame();
162 void
163 goto_next_frame_cb(GtkWidget *w _U_, gpointer d _U_)
165 packet_list_next();
168 void
169 goto_previous_frame_cb(GtkWidget *w _U_, gpointer d _U_)
171 packet_list_prev();