Ethereal-dev: Re: [ethereal-dev] Right button menus
Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.
From: Guy Harris <gharris@xxxxxxxxxxxx>
Date: Wed, 29 Dec 1999 21:54:00 -0800
On Mon, Dec 20, 1999 at 11:41:24PM -0800, Jerry Talkington wrote: > * Guy Harris (gharris@xxxxxxxxxxxx) done spit this rhetoric: > > > All three have the problem that the cursor must be above a top-level tree > > > item to popup the window. I suppose that one could attach the menu to the > > > lower widgets also, but I didn't try it. Trying to attach the menu to the > > > tv_scrollw had some funky results... > > > > Popping up the menu also causes the top-level tree item you're above to > > close, if it's open. > > That's the default behavior, so it just carries through, in addition to > popping up the menu. I dunno how to make it not do that, I guess it's a > default action for that widget type... Your first patch, at least, applies to the new CTree-based code, with some hand tweaking; the right mouse button doesn't close the current tree item in a CTree, so that behavior is gone. I'm not sure which items you classified as "top-level tree items" in the first paragraph, but the right button appears to pop up the menu everywhere in the CTree-based code. I've attached "cvs diff -c" output for the result of applying the first patch + hand-tweaking to the current CVS tree (which is also the 0.8.0 tree).
Index: gtk/main.c
===================================================================
RCS file: /usr/local/cvsroot/ethereal/gtk/main.c,v
retrieving revision 1.77
diff -c -r1.77 main.c
*** main.c 1999/12/29 20:10:10 1.77
--- main.c 1999/12/30 05:57:19
***************
*** 1269,1274 ****
--- 1269,1276 ----
pl_style->font);
}
gtk_widget_set_usize(packet_list, -1, pl_size);
+ gtk_signal_connect_object(GTK_OBJECT(packet_list), "button_press_event",
+ GTK_SIGNAL_FUNC(popup_menu_handler), GTK_OBJECT(popup_menu_object));
gtk_widget_show(packet_list);
/* Tree view */
***************
*** 1288,1293 ****
--- 1290,1297 ----
GTK_SIGNAL_FUNC(tree_view_select_row_cb), NULL);
gtk_signal_connect(GTK_OBJECT(tree_view), "tree-unselect-row",
GTK_SIGNAL_FUNC(tree_view_unselect_row_cb), NULL);
+ gtk_signal_connect_object(GTK_OBJECT(tree_view), "button_press_event",
+ GTK_SIGNAL_FUNC(popup_menu_handler), GTK_OBJECT(popup_menu_object));
gtk_widget_show(tree_view);
item_style = gtk_style_new();
Index: gtk/menu.c
===================================================================
RCS file: /usr/local/cvsroot/ethereal/gtk/menu.c,v
retrieving revision 1.12
diff -c -r1.12 menu.c
*** menu.c 1999/12/10 07:04:30 1.12
--- menu.c 1999/12/30 05:57:20
***************
*** 74,79 ****
--- 74,80 ----
"<LastBranch>" -> create a right justified branch
*/
+ /* main menu */
static GtkItemFactoryEntry menu_items[] =
{
{"/_File", NULL, NULL, 0, "<Branch>" },
***************
*** 122,129 ****
--- 123,147 ----
/* calculate the number of menu_items */
static int nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]);
+ /* packet list popup */
+ static GtkItemFactoryEntry popup_menu_items[] =
+ {
+ {"/Match Selected", NULL, GTK_MENU_FUNC(match_selected_cb), 0, NULL},
+ {"/Follow TCP Stream", NULL, GTK_MENU_FUNC(follow_stream_cb), 0, NULL},
+ {"/Filters...", NULL, GTK_MENU_FUNC(filter_dialog_cb), 0, NULL},
+ {"/<separator>", NULL, NULL, 0, "<Separator>"},
+ {"/Colorize Display...", NULL, GTK_MENU_FUNC(color_display_cb), 0, NULL},
+ {"/Print...", NULL, GTK_MENU_FUNC(file_print_cmd_cb), 0, NULL},
+ {"/Print Packet", NULL, GTK_MENU_FUNC(file_print_packet_cmd_cb), 0, NULL},
+ {"/<separator>", NULL, NULL, 0, "<Separator>"},
+ {"/Collapse All", NULL, GTK_MENU_FUNC(collapse_all_cb), 0, NULL},
+ {"/Expand All", NULL, GTK_MENU_FUNC(expand_all_cb), 0, NULL}
+ };
+
+
static int initialize = TRUE;
static GtkItemFactory *factory = NULL;
+ static GtkItemFactory *popup_menu_factory;
void
get_main_menu(GtkWidget ** menubar, GtkAccelGroup ** table) {
***************
*** 147,153 ****
--- 165,174 ----
initialize = FALSE;
factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>", grp);
+ popup_menu_factory = gtk_item_factory_new(GTK_TYPE_MENU, "<main>", NULL);
gtk_item_factory_create_items_ac(factory, nmenu_items, menu_items, NULL,2);
+ gtk_item_factory_create_items_ac(popup_menu_factory, sizeof(popup_menu_items)/sizeof(popup_menu_items[0]), popup_menu_items, NULL,2);
+ popup_menu_object = popup_menu_factory->widget;
set_menu_sensitivity("/File/Close", FALSE);
set_menu_sensitivity("/File/Save", FALSE);
set_menu_sensitivity("/File/Save As...", FALSE);
***************
*** 173,189 ****
--- 194,237 ----
void
set_menu_sensitivity (gchar *path, gint val) {
GtkWidget *menu;
+ gchar *shortpath = rindex(path, '/');
if ((menu = gtk_item_factory_get_widget(factory, path)) != NULL)
gtk_widget_set_sensitive(menu, val);
+
+ if ((menu = gtk_item_factory_get_widget(popup_menu_factory, shortpath)) != NULL)
+ gtk_widget_set_sensitive(menu, val);
}
void
set_menu_object_data (gchar *path, gchar *key, gpointer data) {
GtkWidget *menu;
+ gchar *shortpath = rindex(path, '/');
if ((menu = gtk_item_factory_get_widget(factory, path)) != NULL)
gtk_object_set_data(GTK_OBJECT(menu), key, data);
+
+ if ((menu = gtk_item_factory_get_widget(popup_menu_factory, shortpath)) != NULL)
+ gtk_object_set_data(GTK_OBJECT(menu), key, data);
+
}
+ void
+ popup_menu_handler(GtkWidget *widget, GdkEvent *event)
+ {
+ GtkWidget *menu = NULL;
+ GdkEventButton *event_button = NULL;
+ if(widget == NULL || event == NULL) {
+ return;
+ }
+
+ menu = widget;
+ if(event->type == GDK_BUTTON_PRESS) {
+ event_button = (GdkEventButton *) event;
+
+ if(event_button->button == 3) {
+ gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, event_button->button, event_button->time);
+ }
+ }
+ }
Index: gtk/menu.h
===================================================================
RCS file: /usr/local/cvsroot/ethereal/gtk/menu.h,v
retrieving revision 1.1
diff -c -r1.1 menu.h
*** menu.h 1999/09/01 03:04:23 1.1
--- menu.h 1999/12/30 05:57:20
***************
*** 38,44 ****
--- 38,46 ----
void set_menu_sensitivity (gchar *, gint);
void set_menu_object_data (gchar *path, gchar *key, gpointer data);
void menus_create (GtkMenuEntry *, int);
+ void popup_menu_handler(GtkWidget *widget, GdkEvent *event);
+ GtkWidget *popup_menu_object;
#ifdef __cplusplus
}
- References:
- [ethereal-dev] Right button menus
- From: Jerry Talkington
- Re: [ethereal-dev] Right button menus
- From: Guy Harris
- Re: [ethereal-dev] Right button menus
- From: Jerry Talkington
- [ethereal-dev] Right button menus
- Prev by Date: [ethereal-dev] Changing from one packet_list view to three panes ...
- Next by Date: Re: [ethereal-dev] Right button menus
- Previous by thread: Re: [ethereal-dev] Right button menus
- Next by thread: Re: [ethereal-dev] Right button menus
- Index(es):





