4 * $Id: menu.c,v 1.93 2003/05/03 00:48:37 guy 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.
37 #include <epan/packet.h>
38 #include <epan/resolv.h>
40 #include "capture_dlg.h"
41 #include "color_dlg.h"
43 #include "filter_prefs.h"
46 #include "summary_dlg.h"
47 #include "display_opts.h"
48 #include "prefs_dlg.h"
49 #include "packet_win.h"
51 #include "follow_dlg.h"
52 #include "decode_as_dlg.h"
54 #include "proto_dlg.h"
55 #include "proto_hier_stats_dlg.h"
57 #include <epan/plugins.h>
58 #include "tcp_graph.h"
59 #include <epan/epan_dissect.h>
60 #include "compat_macros.h"
61 #include "gtkglobals.h"
64 GtkWidget *popup_menu_object;
66 #define GTK_MENU_FUNC(a) ((GtkItemFactoryCallback)(a))
68 static void menus_init(void);
69 static void set_menu_sensitivity (GtkItemFactory *, gchar *, gint);
71 /* This is the GtkItemFactoryEntry structure used to generate new menus.
72 Item 1: The menu path. The letter after the underscore indicates an
73 accelerator key once the menu is open.
74 Item 2: The accelerator key for the entry
75 Item 3: The callback function.
76 Item 4: The callback action. This changes the parameters with
77 which the function is called. The default is 0.
78 Item 5: The item type, used to define what kind of an item it is.
79 Here are the possible values:
83 "<Title>" -> create a title item
84 "<Item>" -> create a simple item
85 "<ImageItem>" -> create an item holding an image (gtk2)
86 "<StockItem>" -> create an item holding a stock image (gtk2)
87 "<CheckItem>" -> create a check item
88 "<ToggleItem>" -> create a toggle item
89 "<RadioItem>" -> create a radio item
90 <path> -> path of a radio item to link against
91 "<Separator>" -> create a separator
92 "<Tearoff>" -> create a tearoff separator (gtk2)
93 "<Branch>" -> create an item to hold sub items (optional)
94 "<LastBranch>" -> create a right justified branch
95 Item 6: extra data needed for ImageItem and StockItem (gtk2)
99 static GtkItemFactoryEntry menu_items[] =
101 ITEM_FACTORY_ENTRY("/_File", NULL, NULL, 0, "<Branch>", NULL),
102 ITEM_FACTORY_STOCK_ENTRY("/File/_Open...", "<control>O", file_open_cmd_cb,
104 ITEM_FACTORY_STOCK_ENTRY("/File/_Close", "<control>W", file_close_cmd_cb,
106 ITEM_FACTORY_STOCK_ENTRY("/File/_Save", "<control>S", file_save_cmd_cb,
108 ITEM_FACTORY_STOCK_ENTRY("/File/Save _As...", NULL, file_save_as_cmd_cb,
109 0, GTK_STOCK_SAVE_AS),
110 ITEM_FACTORY_STOCK_ENTRY("/File/_Reload", "<control>R", file_reload_cmd_cb,
111 0, GTK_STOCK_REFRESH),
112 ITEM_FACTORY_ENTRY("/File/<separator>", NULL, NULL, 0, "<Separator>", NULL),
113 ITEM_FACTORY_STOCK_ENTRY("/File/_Print...", NULL, file_print_cmd_cb,
115 ITEM_FACTORY_ENTRY("/File/<separator>", NULL, NULL, 0, "<Separator>", NULL),
116 ITEM_FACTORY_ENTRY("/File/Print Pac_ket", "<control>P",
117 file_print_packet_cmd_cb, 0, NULL, NULL),
118 ITEM_FACTORY_ENTRY("/File/<separator>", NULL, NULL, 0, "<Separator>", NULL),
119 ITEM_FACTORY_STOCK_ENTRY("/File/_Quit", "<control>Q", file_quit_cmd_cb,
121 ITEM_FACTORY_ENTRY("/_Edit", NULL, NULL, 0, "<Branch>", NULL),
123 /* Un-#if this when we actually implement Cut/Copy/Paste. */
124 ITEM_FACTORY_STOCK_ENTRY("/Edit/Cut", "<control>X", NULL,
126 ITEM_FACTORY_STOCK_ENTRY("/Edit/Copy", "<control>C", NULL,
128 ITEM_FACTORY_STOCK_ENTRY("/Edit/Paste", "<control>V", NULL,
130 ITEM_FACTORY_ENTRY("/Edit/<separator>", NULL, NULL, 0, "<Separator>"),
132 ITEM_FACTORY_STOCK_ENTRY("/Edit/_Find Frame...", "<control>F",
133 find_frame_cb, 0, GTK_STOCK_FIND),
134 ITEM_FACTORY_STOCK_ENTRY("/Edit/Find _Next", "<control>N", find_next_cb,
135 0, GTK_STOCK_GO_FORWARD),
136 ITEM_FACTORY_STOCK_ENTRY("/Edit/Find _Previous", "<control>B",
137 find_previous_cb, 0, GTK_STOCK_GO_BACK),
138 ITEM_FACTORY_STOCK_ENTRY("/Edit/_Go To Frame...", "<control>G",
139 goto_frame_cb, 0, GTK_STOCK_JUMP_TO),
140 ITEM_FACTORY_ENTRY("/Edit/<separator>", NULL, NULL, 0, "<Separator>", NULL),
141 ITEM_FACTORY_ENTRY("/Edit/_Mark Frame", "<control>M", mark_frame_cb,
143 ITEM_FACTORY_ENTRY("/Edit/Mark _All Frames", NULL, mark_all_frames_cb,
145 ITEM_FACTORY_ENTRY("/Edit/_Unmark All Frames", NULL, unmark_all_frames_cb,
147 ITEM_FACTORY_ENTRY("/Edit/<separator>", NULL, NULL, 0, "<Separator>", NULL),
148 ITEM_FACTORY_STOCK_ENTRY("/Edit/_Preferences...", NULL, prefs_cb,
149 0, GTK_STOCK_PREFERENCES),
151 ITEM_FACTORY_ENTRY("/Edit/_Capture Filters...", NULL, cfilter_dialog_cb,
153 #endif /* HAVE_LIBPCAP */
154 ITEM_FACTORY_ENTRY("/Edit/_Display Filters...", NULL, dfilter_dialog_cb,
156 ITEM_FACTORY_ENTRY("/Edit/P_rotocols...", NULL, proto_cb, 0, NULL, NULL),
158 ITEM_FACTORY_ENTRY("/_Capture", NULL, NULL, 0, "<Branch>", NULL),
159 ITEM_FACTORY_STOCK_ENTRY("/Capture/_Start...", "<control>K",
160 capture_prep_cb, 0, GTK_STOCK_EXECUTE),
162 * XXX - this doesn't yet work in Win32.
165 ITEM_FACTORY_STOCK_ENTRY("/Capture/S_top", "<control>E", capture_stop_cb,
168 #endif /* HAVE_LIBPCAP */
169 ITEM_FACTORY_ENTRY("/_Display", NULL, NULL, 0, "<Branch>", NULL),
170 ITEM_FACTORY_ENTRY("/Display/_Options...", NULL, display_opt_cb,
172 ITEM_FACTORY_ENTRY("/Display/_Match", NULL, NULL, 0, "<Branch>", NULL),
173 ITEM_FACTORY_ENTRY("/Display/Match/_Selected", NULL,
174 match_selected_cb_replace_ptree, 0, NULL, NULL),
175 ITEM_FACTORY_ENTRY("/Display/Match/_Not Selected", NULL,
176 match_selected_cb_not_ptree, 0, NULL, NULL),
177 ITEM_FACTORY_ENTRY("/Display/Match/_And Selected", NULL,
178 match_selected_cb_and_ptree, 0, NULL, NULL),
179 ITEM_FACTORY_ENTRY("/Display/Match/_Or Selected", NULL,
180 match_selected_cb_or_ptree, 0, NULL, NULL),
181 ITEM_FACTORY_ENTRY("/Display/Match/A_nd Not Selected", NULL,
182 match_selected_cb_and_ptree_not, 0, NULL, NULL),
183 ITEM_FACTORY_ENTRY("/Display/Match/O_r Not Selected", NULL,
184 match_selected_cb_or_ptree_not, 0, NULL, NULL),
185 ITEM_FACTORY_ENTRY("/Display/_Prepare", NULL, NULL, 0, "<Branch>", NULL),
186 ITEM_FACTORY_ENTRY("/Display/Prepare/_Selected", NULL,
187 prepare_selected_cb_replace_ptree, 0, NULL, NULL),
188 ITEM_FACTORY_ENTRY("/Display/Prepare/_Not Selected", NULL,
189 prepare_selected_cb_not_ptree, 0, NULL, NULL),
190 ITEM_FACTORY_ENTRY("/Display/Prepare/_And Selected", NULL,
191 prepare_selected_cb_and_ptree, 0, NULL, NULL),
192 ITEM_FACTORY_ENTRY("/Display/Prepare/_Or Selected", NULL,
193 prepare_selected_cb_or_ptree, 0, NULL, NULL),
194 ITEM_FACTORY_ENTRY("/Display/Prepare/A_nd Not Selected", NULL,
195 prepare_selected_cb_and_ptree_not, 0, NULL, NULL),
196 ITEM_FACTORY_ENTRY("/Display/Prepare/O_r Not Selected", NULL,
197 prepare_selected_cb_or_ptree_not, 0, NULL, NULL),
198 ITEM_FACTORY_ENTRY("/Display/_Colorize Display...", NULL, color_display_cb,
200 ITEM_FACTORY_ENTRY("/Display/Collapse _All", NULL, collapse_all_cb,
202 ITEM_FACTORY_ENTRY("/Display/_Expand All", NULL, expand_all_cb,
204 ITEM_FACTORY_ENTRY("/Display/_Show Packet In New Window", NULL,
205 new_window_cb, 0, NULL, NULL),
206 ITEM_FACTORY_ENTRY("/Display/User Specified Decodes...", NULL,
207 decode_show_cb, 0, NULL, NULL),
208 ITEM_FACTORY_ENTRY("/_Tools", NULL, NULL, 0, "<Branch>", NULL),
210 ITEM_FACTORY_ENTRY("/Tools/_Plugins...", NULL, tools_plugins_cmd_cb,
212 #endif /* HAVE_PLUGINS */
213 ITEM_FACTORY_ENTRY("/Tools/_Follow TCP Stream", NULL, follow_stream_cb,
215 ITEM_FACTORY_ENTRY("/Tools/_Decode As...", NULL, decode_as_cb,
217 ITEM_FACTORY_ENTRY("/Tools/_Go To Corresponding Frame", NULL, goto_framenum_cb,
219 /* {"/Tools/Graph", NULL, NULL, 0, NULL}, future use */
220 ITEM_FACTORY_ENTRY("/_Tools/TCP Stream Analysis", NULL, NULL,
221 0, "<Branch>", NULL),
222 ITEM_FACTORY_ENTRY("/_Tools/TCP Stream Analysis/Time-Sequence Graph (Stevens)",
223 NULL, tcp_graph_cb, 0, NULL, NULL),
224 ITEM_FACTORY_ENTRY("/_Tools/TCP Stream Analysis/Time-Sequence Graph (tcptrace)",
225 NULL, tcp_graph_cb, 1, NULL, NULL),
226 ITEM_FACTORY_ENTRY("/_Tools/TCP Stream Analysis/Throughput Graph", NULL,
227 tcp_graph_cb, 2, NULL, NULL),
228 ITEM_FACTORY_ENTRY("/_Tools/TCP Stream Analysis/RTT Graph", NULL,
229 tcp_graph_cb, 3, NULL, NULL),
230 ITEM_FACTORY_ENTRY("/Tools/_Summary", NULL, summary_open_cb, 0, NULL, NULL),
231 ITEM_FACTORY_ENTRY("/Tools/Protocol Hierarchy Statistics", NULL,
232 proto_hier_stats_cb, 0, NULL, NULL),
233 ITEM_FACTORY_ENTRY("/Tools/Statistics", NULL, NULL, 0, "<Branch>", NULL),
234 ITEM_FACTORY_ENTRY("/_Help", NULL, NULL, 0, "<LastBranch>", NULL),
235 ITEM_FACTORY_STOCK_ENTRY("/Help/_Help", NULL, help_cb, 0, GTK_STOCK_HELP),
236 ITEM_FACTORY_ENTRY("/Help/<separator>", NULL, NULL, 0, "<Separator>", NULL),
237 ITEM_FACTORY_ENTRY("/Help/_About Ethereal...", NULL, about_ethereal,
242 /* calculate the number of menu_items */
243 static int nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]);
245 /* packet list popup */
246 static GtkItemFactoryEntry packet_list_menu_items[] =
248 ITEM_FACTORY_ENTRY("/Follow TCP Stream", NULL, follow_stream_cb,
250 ITEM_FACTORY_ENTRY("/Decode As...", NULL, decode_as_cb, 0, NULL, NULL),
251 ITEM_FACTORY_ENTRY("/Display Filters...", NULL, dfilter_dialog_cb,
253 ITEM_FACTORY_ENTRY("/<separator>", NULL, NULL, 0, "<Separator>", NULL),
254 ITEM_FACTORY_ENTRY("/Mark Frame", NULL, mark_frame_cb, 0, NULL, NULL),
255 ITEM_FACTORY_ENTRY("/Match", NULL, NULL, 0, "<Branch>", NULL),
256 ITEM_FACTORY_ENTRY("/Match/_Selected", NULL,
257 match_selected_cb_replace_plist, 0, NULL, NULL),
258 ITEM_FACTORY_ENTRY("/Match/_Not Selected", NULL,
259 match_selected_cb_not_plist, 0, NULL, NULL),
260 ITEM_FACTORY_ENTRY("/Match/_And Selected", NULL,
261 match_selected_cb_and_plist, 0, NULL, NULL),
262 ITEM_FACTORY_ENTRY("/Match/_Or Selected", NULL, match_selected_cb_or_plist,
264 ITEM_FACTORY_ENTRY("/Match/A_nd Not Selected", NULL,
265 match_selected_cb_and_plist_not, 0, NULL, NULL),
266 ITEM_FACTORY_ENTRY("/Match/O_r Not Selected", NULL,
267 match_selected_cb_or_plist_not, 0, NULL, NULL),
268 ITEM_FACTORY_ENTRY("/Prepare", NULL, NULL, 0, "<Branch>", NULL),
269 ITEM_FACTORY_ENTRY("/Prepare/_Selected", NULL,
270 prepare_selected_cb_replace_plist, 0, NULL, NULL),
271 ITEM_FACTORY_ENTRY("/Prepare/_Not Selected", NULL,
272 prepare_selected_cb_not_plist, 0, NULL, NULL),
273 ITEM_FACTORY_ENTRY("/Prepare/_And Selected", NULL,
274 prepare_selected_cb_and_plist, 0, NULL, NULL),
275 ITEM_FACTORY_ENTRY("/Prepare/_Or Selected", NULL,
276 prepare_selected_cb_or_plist, 0, NULL, NULL),
277 ITEM_FACTORY_ENTRY("/Prepare/A_nd Not Selected", NULL,
278 prepare_selected_cb_and_plist_not, 0, NULL, NULL),
279 ITEM_FACTORY_ENTRY("/Prepare/O_r Not Selected", NULL,
280 prepare_selected_cb_or_plist_not, 0, NULL, NULL),
281 ITEM_FACTORY_ENTRY("/<separator>", NULL, NULL, 0, "<Separator>", NULL),
282 ITEM_FACTORY_ENTRY("/Colorize Display...", NULL, color_display_cb,
284 ITEM_FACTORY_ENTRY("/Print...", NULL, file_print_cmd_cb, 0, NULL, NULL),
285 ITEM_FACTORY_ENTRY("/Print Packet", NULL, file_print_packet_cmd_cb,
287 ITEM_FACTORY_ENTRY("/Show Packet In New Window", NULL, new_window_cb,
291 static GtkItemFactoryEntry tree_view_menu_items[] =
293 ITEM_FACTORY_ENTRY("/Follow TCP Stream", NULL, follow_stream_cb,
295 ITEM_FACTORY_ENTRY("/Decode As...", NULL, decode_as_cb, 0, NULL, NULL),
296 ITEM_FACTORY_ENTRY("/Display Filters...", NULL, dfilter_dialog_cb,
298 ITEM_FACTORY_ENTRY("/<separator>", NULL, NULL, 0, "<Separator>", NULL),
299 ITEM_FACTORY_ENTRY("/_Resolve Name", NULL, resolve_name_cb, 0, NULL, NULL),
300 ITEM_FACTORY_ENTRY("/_Go To Corresponding Frame", NULL, goto_framenum_cb, 0, NULL, NULL),
301 ITEM_FACTORY_ENTRY("/Protocol Properties...", NULL, properties_cb,
303 ITEM_FACTORY_ENTRY("/Match", NULL, NULL, 0, "<Branch>", NULL),
304 ITEM_FACTORY_ENTRY("/Match/_Selected", NULL,
305 match_selected_cb_replace_ptree, 0, NULL, NULL),
306 ITEM_FACTORY_ENTRY("/Match/_Not Selected", NULL,
307 match_selected_cb_not_ptree, 0, NULL, NULL),
308 ITEM_FACTORY_ENTRY("/Match/_And Selected", NULL,
309 match_selected_cb_and_ptree, 0, NULL, NULL),
310 ITEM_FACTORY_ENTRY("/Match/_Or Selected", NULL, match_selected_cb_or_ptree,
312 ITEM_FACTORY_ENTRY("/Match/A_nd Not Selected", NULL,
313 match_selected_cb_and_ptree_not, 0, NULL, NULL),
314 ITEM_FACTORY_ENTRY("/Match/O_r Not Selected", NULL,
315 match_selected_cb_or_ptree_not, 0, NULL, NULL),
316 ITEM_FACTORY_ENTRY("/Prepare", NULL, NULL, 0, "<Branch>", NULL),
317 ITEM_FACTORY_ENTRY("/Prepare/_Selected", NULL,
318 prepare_selected_cb_replace_ptree, 0, NULL, NULL),
319 ITEM_FACTORY_ENTRY("/Prepare/_Not Selected", NULL,
320 prepare_selected_cb_not_ptree, 0, NULL, NULL),
321 ITEM_FACTORY_ENTRY("/Prepare/_And Selected", NULL,
322 prepare_selected_cb_and_ptree, 0, NULL, NULL),
323 ITEM_FACTORY_ENTRY("/Prepare/_Or Selected", NULL,
324 prepare_selected_cb_or_ptree, 0, NULL, NULL),
325 ITEM_FACTORY_ENTRY("/Prepare/A_nd Not Selected", NULL,
326 prepare_selected_cb_and_ptree_not, 0, NULL, NULL),
327 ITEM_FACTORY_ENTRY("/Prepare/O_r Not Selected", NULL,
328 prepare_selected_cb_or_ptree_not, 0, NULL, NULL),
329 ITEM_FACTORY_ENTRY("/<separator>", NULL, NULL, 0, "<Separator>", NULL),
330 ITEM_FACTORY_ENTRY("/Collapse All", NULL, collapse_all_cb, 0, NULL, NULL),
331 ITEM_FACTORY_ENTRY("/Expand All", NULL, expand_all_cb, 0, NULL, NULL)
334 static GtkItemFactoryEntry hexdump_menu_items[] =
336 ITEM_FACTORY_ENTRY("/Follow TCP Stream", NULL, follow_stream_cb,
338 ITEM_FACTORY_ENTRY("/Decode As...", NULL, decode_as_cb, 0, NULL, NULL),
339 ITEM_FACTORY_ENTRY("/Display Filters...", NULL, dfilter_dialog_cb,
343 static int initialize = TRUE;
344 static GtkItemFactory *main_menu_factory = NULL;
345 static GtkItemFactory *packet_list_menu_factory = NULL;
346 static GtkItemFactory *tree_view_menu_factory = NULL;
347 static GtkItemFactory *hexdump_menu_factory = NULL;
349 static GSList *popup_menu_list = NULL;
351 static GtkAccelGroup *grp;
354 get_main_menu(GtkWidget ** menubar, GtkAccelGroup ** table) {
356 grp = gtk_accel_group_new();
359 popup_menu_object = gtk_menu_new();
364 *menubar = main_menu_factory->widget;
378 packet_list_menu_factory = gtk_item_factory_new(GTK_TYPE_MENU, "<main>", NULL);
379 gtk_item_factory_create_items_ac(packet_list_menu_factory, sizeof(packet_list_menu_items)/sizeof(packet_list_menu_items[0]), packet_list_menu_items, popup_menu_object, 2);
380 OBJECT_SET_DATA(popup_menu_object, PM_PACKET_LIST_KEY,
381 packet_list_menu_factory->widget);
382 popup_menu_list = g_slist_append((GSList *)popup_menu_list, packet_list_menu_factory);
384 tree_view_menu_factory = gtk_item_factory_new(GTK_TYPE_MENU, "<main>", NULL);
385 gtk_item_factory_create_items_ac(tree_view_menu_factory, sizeof(tree_view_menu_items)/sizeof(tree_view_menu_items[0]), tree_view_menu_items, popup_menu_object, 2);
386 OBJECT_SET_DATA(popup_menu_object, PM_TREE_VIEW_KEY,
387 tree_view_menu_factory->widget);
388 popup_menu_list = g_slist_append((GSList *)popup_menu_list, tree_view_menu_factory);
390 hexdump_menu_factory = gtk_item_factory_new(GTK_TYPE_MENU, "<main>", NULL);
391 gtk_item_factory_create_items_ac(hexdump_menu_factory, sizeof(hexdump_menu_items)/sizeof(hexdump_menu_items[0]), hexdump_menu_items, popup_menu_object, 2);
392 OBJECT_SET_DATA(popup_menu_object, PM_HEXDUMP_KEY,
393 hexdump_menu_factory->widget);
394 popup_menu_list = g_slist_append((GSList *)popup_menu_list, hexdump_menu_factory);
396 main_menu_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>", grp);
397 gtk_item_factory_create_items_ac(main_menu_factory, nmenu_items, menu_items, NULL,2);
398 set_menus_for_unsaved_capture_file(FALSE);
399 set_menus_for_capture_file(FALSE);
401 /* Un-#if this when we actually implement Cut/Copy/Paste.
402 Then make sure you enable them when they can be done. */
403 set_menu_sensitivity(main_menu_factory, "/Edit/Cut", FALSE);
404 set_menu_sensitivity(main_menu_factory, "/Edit/Copy", FALSE);
405 set_menu_sensitivity(main_menu_factory, "/Edit/Paste", FALSE);
408 set_menus_for_captured_packets(FALSE);
409 set_menus_for_selected_packet(FALSE);
410 set_menus_for_selected_tree_row(FALSE);
415 * Add a new menu item for a statistical tap.
416 * This must be called after we've created the main menu, so it can't
417 * be called from the routine that registers taps - we have to introduce
418 * another per-tap registration routine.
421 register_tap_menu_item(char *name, GtkItemFactoryCallback callback)
423 static const char statspath[] = "/Tools/Statistics/";
428 GtkItemFactoryEntry *entry;
431 * The menu path must be relative.
433 g_assert(*name != '/');
436 * Create any submenus required.
439 while ((p = strchr(p, '/')) != NULL) {
441 * OK, everything between "name" and "p" is
442 * a menu relative subtree into which the menu item
445 * Construct the absolute path name of that subtree.
447 menupathlen = sizeof statspath + (p - name);
448 menupath = g_malloc(menupathlen);
449 strcpy(menupath, statspath);
450 strncat(menupath, name, p - name);
453 * Does there exist an entry with that path in the main
456 w = gtk_item_factory_get_widget(main_menu_factory, menupath);
459 * No. Create such an item as a subtree.
461 entry = g_malloc0(sizeof (GtkItemFactoryEntry));
462 entry->path = menupath;
463 entry->item_type = "<Branch>";
464 gtk_item_factory_create_item(main_menu_factory, entry,
469 * Skip over the '/' we found.
475 * Construct the main menu path for the menu item.
477 * "sizeof statspath" includes the trailing '\0', so the sum
478 * of that and the length of "name" is enough to hold a string
479 * containing their concatenation.
481 menupathlen = sizeof statspath + strlen(name);
482 menupath = g_malloc(menupathlen);
483 strcpy(menupath, statspath);
484 strcat(menupath, name);
487 * Construct an item factory entry for the item, and add it to
490 entry = g_malloc0(sizeof (GtkItemFactoryEntry));
491 entry->path = menupath;
492 entry->callback = callback;
493 gtk_item_factory_create_item(main_menu_factory, entry, NULL, 2);
498 * Enable/disable menu sensitivity.
501 set_menu_sensitivity(GtkItemFactory *ifactory, gchar *path, gint val)
504 GtkWidget *menu_item;
506 if (ifactory == NULL) {
508 * Do it for all pop-up menus.
510 for (menu_list = popup_menu_list; menu_list != NULL;
511 menu_list = g_slist_next(menu_list))
512 set_menu_sensitivity(menu_list->data, path, val);
515 * Do it for that particular menu.
517 if ((menu_item = gtk_item_factory_get_widget(ifactory, path)) != NULL) {
518 if (GTK_IS_MENU(menu_item)) {
520 * "path" refers to a submenu; "gtk_item_factory_get_widget()"
521 * gets the menu, not the item that, when selected, pops up
524 * We have to change the latter item's sensitivity, so that
525 * it shows up normally if sensitive and grayed-out if
528 menu_item = gtk_menu_get_attach_widget(GTK_MENU(menu_item));
530 gtk_widget_set_sensitive(menu_item, val);
536 set_menu_object_data_meat(GtkItemFactory *ifactory, gchar *path, gchar *key, gpointer data)
538 GtkWidget *menu = NULL;
540 if ((menu = gtk_item_factory_get_widget(ifactory, path)) != NULL)
541 OBJECT_SET_DATA(menu, key, data);
545 set_menu_object_data (gchar *path, gchar *key, gpointer data) {
546 GSList *menu_list = popup_menu_list;
547 gchar *shortpath = strrchr(path, '/');
549 set_menu_object_data_meat(main_menu_factory, path, key, data);
550 while (menu_list != NULL) {
551 set_menu_object_data_meat(menu_list->data, shortpath, key, data);
552 menu_list = g_slist_next(menu_list);
557 popup_menu_handler(GtkWidget *widget, GdkEvent *event, gpointer data)
559 GtkWidget *menu = NULL;
560 GdkEventButton *event_button = NULL;
561 GtkCList *packet_list = NULL;
564 if(widget == NULL || event == NULL || data == NULL) {
569 * If we ever want to make the menu differ based on what row
570 * and/or column we're above, we'd use "gtk_clist_get_selection_info()"
571 * to find the row and column number for the coordinates; a CTree is,
572 * I guess, like a CList with one column(?) and the expander widget
575 /* Check if we are on packet_list object */
576 if (widget == OBJECT_GET_DATA(popup_menu_object, E_MPACKET_LIST_KEY)) {
577 packet_list=GTK_CLIST(widget);
578 if (gtk_clist_get_selection_info(GTK_CLIST(packet_list),
579 ((GdkEventButton *)event)->x,
580 ((GdkEventButton *)event)->y,&row,&column)) {
581 OBJECT_SET_DATA(popup_menu_object, E_MPACKET_LIST_ROW_KEY,
582 GINT_TO_POINTER(row));
583 OBJECT_SET_DATA(popup_menu_object, E_MPACKET_LIST_COL_KEY,
584 GINT_TO_POINTER(column));
587 menu = (GtkWidget *)data;
588 if(event->type == GDK_BUTTON_PRESS) {
589 event_button = (GdkEventButton *) event;
591 if(event_button->button == 3) {
592 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
593 event_button->button,
595 SIGNAL_EMIT_STOP_BY_NAME(widget, "button_press_event");
599 #if GTK_MAJOR_VERSION >= 2
600 if (widget == tree_view && event->type == GDK_2BUTTON_PRESS) {
603 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget),
604 ((GdkEventButton *)event)->x,
605 ((GdkEventButton *)event)->y,
606 &path, NULL, NULL, NULL))
608 if (gtk_tree_view_row_expanded(GTK_TREE_VIEW(widget), path))
609 gtk_tree_view_collapse_row(GTK_TREE_VIEW(widget), path);
611 gtk_tree_view_expand_row(GTK_TREE_VIEW(widget), path,
613 gtk_tree_path_free(path);
620 /* Enable or disable menu items based on whether you have a capture file
621 you've finished reading. */
623 set_menus_for_capture_file(gboolean have_capture_file)
625 set_menu_sensitivity(main_menu_factory, "/File/Open...", have_capture_file);
626 set_menu_sensitivity(main_menu_factory, "/File/Save As...",
628 set_menu_sensitivity(main_menu_factory, "/File/Close", have_capture_file);
629 set_menu_sensitivity(main_menu_factory, "/File/Reload", have_capture_file);
632 /* Enable or disable menu items based on whether you have an unsaved
633 capture file you've finished reading. */
635 set_menus_for_unsaved_capture_file(gboolean have_unsaved_capture_file)
637 set_menu_sensitivity(main_menu_factory, "/File/Save",
638 have_unsaved_capture_file);
641 /* Enable or disable menu items based on whether there's a capture in
644 set_menus_for_capture_in_progress(gboolean capture_in_progress)
646 set_menu_sensitivity(main_menu_factory, "/File/Open...",
647 !capture_in_progress);
648 set_menu_sensitivity(main_menu_factory, "/Capture/Start...",
649 !capture_in_progress);
651 * XXX - this doesn't yet work in Win32.
654 set_menu_sensitivity(main_menu_factory, "/Capture/Stop",
655 capture_in_progress);
659 /* Enable or disable menu items based on whether you have some captured
662 set_menus_for_captured_packets(gboolean have_captured_packets)
664 set_menu_sensitivity(main_menu_factory, "/File/Print...",
665 have_captured_packets);
666 set_menu_sensitivity(packet_list_menu_factory, "/Print...",
667 have_captured_packets);
668 set_menu_sensitivity(main_menu_factory, "/Edit/Find Frame...",
669 have_captured_packets);
670 set_menu_sensitivity(main_menu_factory, "/Edit/Find Next",
671 have_captured_packets);
672 set_menu_sensitivity(main_menu_factory, "/Edit/Find Previous",
673 have_captured_packets);
674 set_menu_sensitivity(main_menu_factory, "/Edit/Go To Frame...",
675 have_captured_packets);
676 set_menu_sensitivity(main_menu_factory, "/Display/Colorize Display...",
677 have_captured_packets);
678 set_menu_sensitivity(packet_list_menu_factory, "/Colorize Display...",
679 have_captured_packets);
680 set_menu_sensitivity(main_menu_factory, "/Tools/Summary",
681 have_captured_packets);
682 set_menu_sensitivity(main_menu_factory,
683 "/Tools/Protocol Hierarchy Statistics", have_captured_packets);
684 set_menu_sensitivity(packet_list_menu_factory, "/Match",
685 have_captured_packets);
686 set_menu_sensitivity(packet_list_menu_factory, "/Prepare",
687 have_captured_packets);
688 set_menu_sensitivity(main_menu_factory, "/Tools/Statistics",
689 have_captured_packets);
692 /* Enable or disable menu items based on whether a packet is selected. */
694 set_menus_for_selected_packet(gboolean have_selected_packet)
696 set_menu_sensitivity(main_menu_factory, "/File/Print Packet",
697 have_selected_packet);
698 set_menu_sensitivity(packet_list_menu_factory, "/Print Packet",
699 have_selected_packet);
700 set_menu_sensitivity(main_menu_factory, "/Edit/Mark Frame",
701 have_selected_packet);
702 set_menu_sensitivity(packet_list_menu_factory, "/Mark Frame",
703 have_selected_packet);
704 set_menu_sensitivity(main_menu_factory, "/Edit/Mark All Frames",
705 have_selected_packet);
706 set_menu_sensitivity(main_menu_factory, "/Edit/Unmark All Frames",
707 have_selected_packet);
708 set_menu_sensitivity(main_menu_factory, "/Display/Collapse All",
709 have_selected_packet);
710 set_menu_sensitivity(tree_view_menu_factory, "/Collapse All",
711 have_selected_packet);
712 set_menu_sensitivity(main_menu_factory, "/Display/Expand All",
713 have_selected_packet);
714 set_menu_sensitivity(tree_view_menu_factory, "/Expand All",
715 have_selected_packet);
716 set_menu_sensitivity(main_menu_factory, "/Display/Show Packet In New Window",
717 have_selected_packet);
718 set_menu_sensitivity(packet_list_menu_factory, "/Show Packet In New Window",
719 have_selected_packet);
720 set_menu_sensitivity(main_menu_factory, "/Tools/Follow TCP Stream",
721 have_selected_packet ? (cfile.edt->pi.ipproto == 6) : FALSE);
722 set_menu_sensitivity(NULL, "/Follow TCP Stream",
723 have_selected_packet ? (cfile.edt->pi.ipproto == 6) : FALSE);
724 set_menu_sensitivity(main_menu_factory, "/Tools/Decode As...",
725 have_selected_packet && decode_as_ok());
726 set_menu_sensitivity(NULL, "/Decode As...",
727 have_selected_packet && decode_as_ok());
728 set_menu_sensitivity(tree_view_menu_factory, "/Resolve Name",
729 have_selected_packet && g_resolv_flags == 0);
730 set_menu_sensitivity(main_menu_factory, "/Tools/TCP Stream Analysis",
731 have_selected_packet ? (cfile.edt->pi.ipproto == 6) : FALSE);
734 /* Enable or disable menu items based on whether a tree row is selected
735 and and on whether a "Match" can be done. */
737 set_menus_for_selected_tree_row(gboolean have_selected_tree)
739 gboolean properties = FALSE;
741 if (finfo_selected) {
742 header_field_info *hfinfo = finfo_selected->hfinfo;
743 if (hfinfo->parent == -1) {
744 properties = prefs_is_registered_protocol(hfinfo->abbrev);
746 properties = prefs_is_registered_protocol(proto_registrar_get_abbrev(hfinfo->parent));
748 if (hfinfo->type == FT_FRAMENUM) {
749 set_menu_sensitivity(main_menu_factory,
750 "/Tools/Go To Corresponding Frame", TRUE);
751 set_menu_sensitivity(tree_view_menu_factory,
752 "/Go To Corresponding Frame", TRUE);
754 set_menu_sensitivity(main_menu_factory,
755 "/Tools/Go To Corresponding Frame", FALSE);
756 set_menu_sensitivity(tree_view_menu_factory,
757 "/Go To Corresponding Frame", FALSE);
759 set_menu_sensitivity(main_menu_factory, "/Display/Match",
760 proto_can_match_selected(finfo_selected, cfile.edt));
761 set_menu_sensitivity(tree_view_menu_factory, "/Match",
762 proto_can_match_selected(finfo_selected, cfile.edt));
763 set_menu_sensitivity(main_menu_factory, "/Display/Prepare",
764 proto_can_match_selected(finfo_selected, cfile.edt));
765 set_menu_sensitivity(tree_view_menu_factory, "/Prepare",
766 proto_can_match_selected(finfo_selected, cfile.edt));
768 set_menu_sensitivity(main_menu_factory, "/Display/Match", FALSE);
769 set_menu_sensitivity(tree_view_menu_factory, "/Match", FALSE);
770 set_menu_sensitivity(main_menu_factory, "/Display/Prepare", FALSE);
771 set_menu_sensitivity(tree_view_menu_factory, "/Prepare", FALSE);
772 set_menu_sensitivity(main_menu_factory,
773 "/Tools/Go To Corresponding Frame", FALSE);
774 set_menu_sensitivity(tree_view_menu_factory,
775 "/Go To Corresponding Frame", FALSE);
778 set_menu_sensitivity(tree_view_menu_factory, "/Protocol Properties...",
779 have_selected_tree && properties);