Path from Joerg Mayer, I'm committing it as I think the right thing to do is to have...
[obnox/wireshark/wip.git] / gtk / proto_hier_stats_dlg.c
index 513a9890f8c18db9ee0bd2deb677277ef214caf7..515f3f8febd9b0a9919906bb42c8d364bda17813 100644 (file)
@@ -26,6 +26,7 @@
 # include "config.h"
 #endif
 
+#include <stdio.h>
 #include <string.h>
 
 #include <gtk/gtk.h>
@@ -39,6 +40,7 @@
 #include "gtk/filter_utils.h"
 #include "gtk/gtkglobals.h"
 #include "gtk/help_dlg.h"
+#include "gtk/utf8_entities.h"
 
 
 enum {
@@ -92,57 +94,8 @@ proto_hier_select_filter_cb(GtkWidget *widget _U_, gpointer callback_data _U_, g
     g_free (str);
 }
 
-#define PROTO_HIER_STATS_USE_GUIMANAGER 1
-#ifndef PROTO_HIER_STATS_USE_GUIMANAGER
-static GtkItemFactoryEntry proto_hier_list_menu_items[] =
-{
-    /* Match */
-    {"/Apply as Filter", NULL, NULL, 0, "<Branch>", NULL,},
-    {"/Apply as Filter/Selected", NULL,
-     GTK_MENU_FUNC(proto_hier_select_filter_cb), CALLBACK_MATCH(ACTYPE_SELECTED, 0), NULL, NULL,},
-    {"/Apply as Filter/Not Selected", NULL,
-     GTK_MENU_FUNC(proto_hier_select_filter_cb), CALLBACK_MATCH(ACTYPE_NOT_SELECTED, 0), NULL, NULL,},
-    {"/Apply as Filter/... and Selected", NULL,
-     GTK_MENU_FUNC(proto_hier_select_filter_cb), CALLBACK_MATCH(ACTYPE_AND_SELECTED, 0), NULL, NULL,},
-    {"/Apply as Filter/... or Selected", NULL,
-     GTK_MENU_FUNC(proto_hier_select_filter_cb), CALLBACK_MATCH(ACTYPE_OR_SELECTED, 0), NULL, NULL,},
-    {"/Apply as Filter/... and not Selected", NULL,
-     GTK_MENU_FUNC(proto_hier_select_filter_cb), CALLBACK_MATCH(ACTYPE_AND_NOT_SELECTED, 0), NULL, NULL,},
-    {"/Apply as Filter/... or not Selected", NULL,
-     GTK_MENU_FUNC(proto_hier_select_filter_cb), CALLBACK_MATCH(ACTYPE_OR_NOT_SELECTED, 0), NULL, NULL,},
-
-    /* Prepare */
-    {"/Prepare a Filter", NULL, NULL, 0, "<Branch>", NULL,},
-    {"/Prepare a Filter/Selected", NULL,
-     GTK_MENU_FUNC(proto_hier_select_filter_cb), CALLBACK_PREPARE(ACTYPE_SELECTED, 0), NULL, NULL,},
-    {"/Prepare a Filter/Not Selected", NULL,
-     GTK_MENU_FUNC(proto_hier_select_filter_cb), CALLBACK_PREPARE(ACTYPE_NOT_SELECTED, 0), NULL, NULL,},
-    {"/Prepare a Filter/... and Selected", NULL,
-     GTK_MENU_FUNC(proto_hier_select_filter_cb), CALLBACK_PREPARE(ACTYPE_AND_SELECTED, 0), NULL, NULL,},
-    {"/Prepare a Filter/... or Selected", NULL,
-     GTK_MENU_FUNC(proto_hier_select_filter_cb), CALLBACK_PREPARE(ACTYPE_OR_SELECTED, 0), NULL, NULL,},
-    {"/Prepare a Filter/... and not Selected", NULL,
-     GTK_MENU_FUNC(proto_hier_select_filter_cb), CALLBACK_PREPARE(ACTYPE_AND_NOT_SELECTED, 0), NULL, NULL,},
-    {"/Prepare a Filter/... or not Selected", NULL,
-     GTK_MENU_FUNC(proto_hier_select_filter_cb), CALLBACK_PREPARE(ACTYPE_OR_NOT_SELECTED, 0), NULL, NULL,},
-
-    /* Find Frame */
-    {"/Find Frame", NULL, NULL, 0, "<Branch>", NULL,},
-    {"/Find Frame/Find Frame", NULL,
-     GTK_MENU_FUNC(proto_hier_select_filter_cb), CALLBACK_FIND_FRAME(ACTYPE_SELECTED, 0), NULL, NULL,},
-    /* Find Next */
-    {"/Find Frame/Find Next", NULL,
-     GTK_MENU_FUNC(proto_hier_select_filter_cb), CALLBACK_FIND_NEXT(ACTYPE_SELECTED, 0), NULL, NULL,},
-    /* Find Previous */
-    {"/Find Frame/Find Previous", NULL,
-     GTK_MENU_FUNC(proto_hier_select_filter_cb), CALLBACK_FIND_PREVIOUS(ACTYPE_SELECTED, 0), NULL, NULL,},
-    /* Colorize Protocol */
-    {"/Colorize Protocol", NULL,
-     GTK_MENU_FUNC(proto_hier_select_filter_cb), CALLBACK_COLORIZE(ACTYPE_SELECTED, 0), NULL, NULL,}
 
-};
-#else /* PROTO_HIER_STATS_USE_GUIMANAGER */
-/* Prepare to change GtkItemFactory to GtkUIManager */
+/* Action callbacks */
 static void
 apply_as_selected_cb(GtkWidget *widget, gpointer user_data)
 {
@@ -247,19 +200,19 @@ static const char *ui_desc_proto_hier_stats_filter_popup =
 "  <popup name='ProtoHierStatsFilterPopup'>\n"
 "    <menu action='/Apply as Filter'>\n"
 "      <menuitem action='/Apply as Filter/Selected'/>\n"
-"      <menuitem action='/Apply as Filter/... not Selected'/>\n"
-"      <menuitem action='/Apply as Filter/... and Selected'/>\n"
-"      <menuitem action='/Apply as Filter/... or Selected'/>\n"
-"      <menuitem action='/Apply as Filter/... and not Selected'/>\n"
-"      <menuitem action='/Apply as Filter/... or not Selected'/>\n"
+"      <menuitem action='/Apply as Filter/Not Selected'/>\n"
+"      <menuitem action='/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " and Selected'/>\n"
+"      <menuitem action='/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " or Selected'/>\n"
+"      <menuitem action='/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " and not Selected'/>\n"
+"      <menuitem action='/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " or not Selected'/>\n"
 "    </menu>\n"
 "    <menu action='/Prepare a Filter'>\n"
 "      <menuitem action='/Prepare a Filter/Selected'/>\n"
-"      <menuitem action='/Prepare a Filter/... not Selected'/>\n"
-"      <menuitem action='/Prepare a Filter/... and Selected'/>\n"
-"      <menuitem action='/Prepare a Filter/... or Selected'/>\n"
-"      <menuitem action='/Prepare a Filter/... and not Selected'/>\n"
-"      <menuitem action='/Prepare a Filter/... or not Selected'/>\n"
+"      <menuitem action='/Prepare a Filter/Not Selected'/>\n"
+"      <menuitem action='/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " and Selected'/>\n"
+"      <menuitem action='/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " or Selected'/>\n"
+"      <menuitem action='/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " and not Selected'/>\n"
+"      <menuitem action='/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " or not Selected'/>\n"
 "    </menu>\n"
 "    <menu action='/Find Frame'>\n"
 "      <menu action='/Find Frame/Find Frame'>\n"
@@ -311,17 +264,17 @@ static const GtkActionEntry proto_hier_stats_popup_entries[] = {
   { "/Find Frame/Find Previous",                               NULL, "Find Previous",                                  NULL, NULL,                                                             NULL },
   { "/Colorize Procedure",                                             NULL, "Colorize Procedure",                             NULL, NULL,                                                             NULL },
   { "/Apply as Filter/Selected",                               NULL, "Selected",                                               NULL, "Selected",                                               G_CALLBACK(apply_as_selected_cb) },
-  { "/Apply as Filter/... not Selected",               NULL, "... not Selected",                               NULL, "... not Selected",                               G_CALLBACK(apply_as_not_selected_cb) },
-  { "/Apply as Filter/... and Selected",               NULL, "... and Selected",                               NULL, "... and Selected",                               G_CALLBACK(apply_as_and_selected_cb) },
-  { "/Apply as Filter/... or Selected",                        NULL, "... or Selected",                                NULL, "... or Selected",                                G_CALLBACK(apply_as_or_selected_cb) },
-  { "/Apply as Filter/... and not Selected",   NULL, "... and not Selected",                   NULL, "... and not Selected",                   G_CALLBACK(apply_as_and_not_selected_cb) },
-  { "/Apply as Filter/... or not Selected",            NULL, "... or not Selected",                    NULL, "... or not Selected",                    G_CALLBACK(apply_as_or_not_selected_cb) },
+  { "/Apply as Filter/Not Selected",           NULL, "Not Selected",                           NULL, "Not Selected",                           G_CALLBACK(apply_as_not_selected_cb) },
+  { "/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " and Selected",              NULL, UTF8_HORIZONTAL_ELLIPSIS " and Selected",                         NULL, UTF8_HORIZONTAL_ELLIPSIS " and Selected",                         G_CALLBACK(apply_as_and_selected_cb) },
+  { "/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " or Selected",                       NULL, UTF8_HORIZONTAL_ELLIPSIS " or Selected",                          NULL, UTF8_HORIZONTAL_ELLIPSIS " or Selected",                          G_CALLBACK(apply_as_or_selected_cb) },
+  { "/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " and not Selected",  NULL, UTF8_HORIZONTAL_ELLIPSIS " and not Selected",                     NULL, UTF8_HORIZONTAL_ELLIPSIS " and not Selected",                     G_CALLBACK(apply_as_and_not_selected_cb) },
+  { "/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " or not Selected",           NULL, UTF8_HORIZONTAL_ELLIPSIS " or not Selected",                      NULL, UTF8_HORIZONTAL_ELLIPSIS " or not Selected",                      G_CALLBACK(apply_as_or_not_selected_cb) },
   { "/Prepare a Filter/Selected",                              NULL, "Selected",                                               NULL, "selcted",                                                G_CALLBACK(prep_as_selected_cb) },
-  { "/Prepare a Filter/... not Selected",              NULL, "... not Selected",                               NULL, "... not Selected",                               G_CALLBACK(prep_as_not_selected_cb) },
-  { "/Prepare a Filter/... and Selected",              NULL, "... and Selected",                               NULL, "... and Selected",                               G_CALLBACK(prep_as_and_selected_cb) },
-  { "/Prepare a Filter/... or Selected",               NULL, "... or Selected",                                NULL, "... or Selected",                                G_CALLBACK(prep_as_or_selected_cb) },
-  { "/Prepare a Filter/... and not Selected",  NULL, "... and not Selected",                   NULL, "... and not Selected",                   G_CALLBACK(prep_as_and_not_selected_cb) },
-  { "/Prepare a Filter/... or not Selected",   NULL, "... or not Selected",                    NULL, "... or not Selected",                    G_CALLBACK(prep_as_or_not_selected_cb) },
+  { "/Prepare a Filter/Not Selected",          NULL, "Not Selected",                           NULL, "Not Selected",                           G_CALLBACK(prep_as_not_selected_cb) },
+  { "/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " and Selected",             NULL, UTF8_HORIZONTAL_ELLIPSIS " and Selected",                         NULL, UTF8_HORIZONTAL_ELLIPSIS " and Selected",                         G_CALLBACK(prep_as_and_selected_cb) },
+  { "/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " or Selected",              NULL, UTF8_HORIZONTAL_ELLIPSIS " or Selected",                          NULL, UTF8_HORIZONTAL_ELLIPSIS " or Selected",                          G_CALLBACK(prep_as_or_selected_cb) },
+  { "/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " and not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " and not Selected",                     NULL, UTF8_HORIZONTAL_ELLIPSIS " and not Selected",                     G_CALLBACK(prep_as_and_not_selected_cb) },
+  { "/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " or not Selected",  NULL, UTF8_HORIZONTAL_ELLIPSIS " or not Selected",                      NULL, UTF8_HORIZONTAL_ELLIPSIS " or not Selected",                      G_CALLBACK(prep_as_or_not_selected_cb) },
   { "/Find Frame/Selected",                                            NULL, "Selected",                                               NULL, "Selected",                                               G_CALLBACK(find_selected_cb) },
   { "/Find Frame/Not Selected",                                        NULL, "Not Selected",                                   NULL, "Not Selected",                                   G_CALLBACK(find_not_selected_cb) },
   { "/Find Previous/Selected",                                 NULL, "Selected",                                               NULL, "Selected",                                               G_CALLBACK(find_prev_selected_cb) },
@@ -330,7 +283,6 @@ static const GtkActionEntry proto_hier_stats_popup_entries[] = {
   { "/Find Next/Not Selected",                                 NULL, "Not Selected",                                   NULL, "Not Selected",                                   G_CALLBACK(find_next_not_selected_cb) },
   { "/Colorize Procedure/Colorize Protocol",   NULL, "Colorize Protocol",                              NULL, "Colorize Protocol",                              G_CALLBACK(color_selected_cb) },
 };
-#endif /* PROTO_HIER_STATS_USE_GUIMANAGER */
 
 static void
 fill_in_tree_node(GNode *node, gpointer data)
@@ -435,25 +387,17 @@ proto_hier_show_popup_menu_cb(GtkWidget *widget _U_, GdkEvent *event, GtkWidget
 static void
 proto_hier_create_popup_menu(void)
 {
-#ifndef PROTO_HIER_STATS_USE_GUIMANAGER
-    GtkItemFactory *item_factory;
-       GtkWidget *popup_menu_object;
 
-    item_factory = gtk_item_factory_new(GTK_TYPE_MENU, "<main>", NULL);
-    gtk_item_factory_create_items_ac(item_factory, sizeof(proto_hier_list_menu_items)/sizeof(proto_hier_list_menu_items[0]), proto_hier_list_menu_items, NULL, 2);
-    popup_menu_object = gtk_item_factory_get_widget (item_factory, "<main>");
-    g_signal_connect(tree, "button_press_event", G_CALLBACK(proto_hier_show_popup_menu_cb), popup_menu_object);
-#else
        GtkUIManager *ui_manager;
        GtkActionGroup *action_group;
        GError *error = NULL;
        GtkWidget *popup_menu_object;
 
        action_group = gtk_action_group_new ("ProtoHierStatsTFilterPopupActionGroup");
-       gtk_action_group_add_actions (action_group,                                                             /* the action group */
-                                                               proto_hier_stats_popup_entries,                         /* an array of action descriptions */
-                                                               G_N_ELEMENTS(proto_hier_stats_popup_entries),/* the number of entries */
-                                                               NULL);                                                                          /* data to pass to the action callbacks */
+       gtk_action_group_add_actions (action_group,                                                                     /* the action group */
+                                                               (gpointer)proto_hier_stats_popup_entries,               /* an array of action descriptions */
+                                                               G_N_ELEMENTS(proto_hier_stats_popup_entries),   /* the number of entries */
+                                                               NULL);                                                                                  /* data to pass to the action callbacks */
 
        ui_manager = gtk_ui_manager_new ();
        gtk_ui_manager_insert_action_group (ui_manager,
@@ -469,7 +413,7 @@ proto_hier_create_popup_menu(void)
     }
        popup_menu_object = gtk_ui_manager_get_widget(ui_manager, "/ProtoHierStatsFilterPopup");
        g_signal_connect(tree, "button_press_event", G_CALLBACK(proto_hier_show_popup_menu_cb), popup_menu_object);
-#endif /* PROTO_HIER_STATS_USE_GUIMANAGER */
+
 }
 
 #define MAX_DLG_HEIGHT 450
@@ -485,13 +429,13 @@ create_tree(GtkWidget *container, ph_stats_t *ps)
 
     /* Scrolled Window */
     sw = scrolled_window_new(NULL, NULL);
-    gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), 
+    gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
                                         GTK_SHADOW_IN);
     gtk_container_add(GTK_CONTAINER(container), sw);
 
     store = gtk_tree_store_new(NUM_STAT_COLUMNS, G_TYPE_STRING, G_TYPE_STRING,
                                G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
-                               G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, 
+                               G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
                                G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_FLOAT,
                                G_TYPE_FLOAT);
     tree = tree_view_new(GTK_TREE_MODEL(store));
@@ -505,21 +449,12 @@ create_tree(GtkWidget *container, ph_stats_t *ps)
                                                       NULL);
     gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
     gtk_tree_view_append_column(tree_view, column);
-#if GTK_CHECK_VERSION(2,6,0)
     renderer = gtk_cell_renderer_progress_new();
     column = gtk_tree_view_column_new_with_attributes("% Packets", renderer,
                                                       "text", PRCT_PKTS_COLUMN,
                                                       "value", PRCT_PKTS_VALUE_COLUMN,
                                                       NULL);
     gtk_tree_view_column_set_expand(column, TRUE);
-#else
-    gtk_tree_view_column_set_expand(column, TRUE);
-    renderer = gtk_cell_renderer_text_new();
-    column = gtk_tree_view_column_new_with_attributes("% Packets", renderer,
-                                                      "text", PRCT_PKTS_COLUMN,
-                                                      NULL);
-    g_object_set(G_OBJECT(renderer), "xalign", 1.0, NULL);
-#endif
     gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
     gtk_tree_view_append_column(tree_view, column);
     renderer = gtk_cell_renderer_text_new();
@@ -529,20 +464,12 @@ create_tree(GtkWidget *container, ph_stats_t *ps)
     g_object_set(G_OBJECT(renderer), "xalign", 1.0, NULL);
     gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
     gtk_tree_view_append_column(tree_view, column);
-#if GTK_CHECK_VERSION(2,6,0)
     renderer = gtk_cell_renderer_progress_new();
     column = gtk_tree_view_column_new_with_attributes("% Bytes", renderer,
                                                       "text", PRCT_BYTES_COLUMN,
                                                       "value", PRCT_BYTES_VALUE_COLUMN,
                                                       NULL);
     gtk_tree_view_column_set_expand(column, TRUE);
-#else
-    renderer = gtk_cell_renderer_text_new();
-    column = gtk_tree_view_column_new_with_attributes("% Bytes", renderer,
-                                                      "text", PRCT_BYTES_COLUMN,
-                                                      NULL);
-    g_object_set(G_OBJECT(renderer), "xalign", 1.0, NULL);
-#endif
     gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
     gtk_tree_view_append_column(tree_view, column);
     renderer = gtk_cell_renderer_text_new();
@@ -659,4 +586,3 @@ proto_hier_stats_cb(GtkWidget *w _U_, gpointer d _U_)
  * ex: set shiftwidth=4 tabstop=8 expandtab
  * :indentSize=4:tabSize=8:noTabs=true:
  */
-