2 * gui functions used by stats
3 * Copyright 2003 Lars Roland
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 #include "ui/simple_dialog.h"
33 #include "ui/gtk/gui_stat_util.h"
35 /* init a main window for stats, set title and display used filter in window */
38 init_main_stat_window(GtkWidget *window, GtkWidget *mainbox, const char *title, const char *filter)
40 GtkWidget *main_label;
41 GtkWidget *filter_label;
44 gtk_window_set_title(GTK_WINDOW(window), title);
46 gtk_container_add(GTK_CONTAINER(window), mainbox);
47 gtk_container_set_border_width(GTK_CONTAINER(mainbox), 10);
48 gtk_widget_show(mainbox);
50 main_label = gtk_label_new(title);
51 gtk_box_pack_start(GTK_BOX(mainbox), main_label, FALSE, FALSE, 0);
52 gtk_widget_show(main_label);
54 filter_string = g_strdup_printf("Filter: %s", filter ? filter : "");
55 filter_label = gtk_label_new(filter_string);
56 g_free(filter_string);
57 gtk_label_set_line_wrap(GTK_LABEL(filter_label), TRUE);
58 gtk_box_pack_start(GTK_BOX(mainbox), filter_label, FALSE, FALSE, 0);
59 gtk_widget_show(filter_label);
62 /* create a table, using a scrollable GtkTreeView */
65 create_stat_table(GtkWidget *scrolled_window, GtkWidget *vbox, int columns, const stat_column *headers)
70 GtkTreeViewColumn *column;
71 GtkTreeSelection *sel;
72 GtkCellRenderer *renderer;
79 types = g_malloc(columns *sizeof(GType));
80 for (i = 0; i < columns; i++)
81 types[i] = headers[i].type;
83 store = gtk_list_store_newv (columns, types);
87 tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
88 table = GTK_TREE_VIEW(tree);
89 g_object_unref (G_OBJECT (store));
91 for (i = 0; i < columns; i++) {
92 renderer = gtk_cell_renderer_text_new ();
93 if (headers[i].align == RIGHT) {
95 g_object_set(G_OBJECT(renderer), "xalign", 1.0, NULL);
97 g_object_set(renderer, "ypad", 0, NULL);
98 column = gtk_tree_view_column_new_with_attributes (headers[i].title, renderer, "text",
100 gtk_tree_view_column_set_resizable(column, TRUE);
101 gtk_tree_view_append_column (table, column);
103 gtk_container_add(GTK_CONTAINER(scrolled_window), GTK_WIDGET (table));
104 gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0);
106 /* configure TreeView */
107 gtk_tree_view_set_rules_hint(table, FALSE);
108 gtk_tree_view_set_headers_clickable(table, FALSE);
110 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(table));
111 gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);
113 gtk_widget_show(scrolled_window);