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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #ifdef HAVE_SYS_TYPES_H
33 # include <sys/types.h>
39 #include "../simple_dialog.h"
42 #include "gtk/gui_stat_util.h"
45 /* insert a string into a GTK_TABLE at column x and row y*/
48 typedef struct _gtk_table {
49 GtkWidget *widget; /**< the table widget */
50 int height; /**< the height */
51 int width; /**< the width */
55 add_table_entry(gtk_table *tab, const char *str, int x, int y)
61 gtk_table_resize(GTK_TABLE(tab->widget), tab->height, tab->width);
65 gtk_table_resize(GTK_TABLE(tab->widget), tab->height, tab->width);
68 tmp=gtk_label_new(str);
69 gtk_table_attach_defaults(GTK_TABLE(tab->widget), tmp, x, x+1, y, y+1);
70 gtk_label_set_justify(GTK_LABEL(tmp), GTK_JUSTIFY_LEFT);
75 /* init a main window for stats, set title and display used filter in window */
78 init_main_stat_window(GtkWidget *window, GtkWidget *mainbox, const char *title, const char *filter)
80 GtkWidget *main_label;
81 GtkWidget *filter_label;
85 gtk_window_set_title(GTK_WINDOW(window), title);
87 gtk_container_add(GTK_CONTAINER(window), mainbox);
88 gtk_container_set_border_width(GTK_CONTAINER(mainbox), 10);
89 gtk_widget_show(mainbox);
91 main_label=gtk_label_new(title);
92 gtk_box_pack_start(GTK_BOX(mainbox), main_label, FALSE, FALSE, 0);
93 gtk_widget_show(main_label);
95 filter_string = g_strdup_printf("Filter: %s", filter ? filter : "");
96 filter_label=gtk_label_new(filter_string);
97 g_free(filter_string);
98 gtk_label_set_line_wrap(GTK_LABEL(filter_label), TRUE);
99 gtk_box_pack_start(GTK_BOX(mainbox), filter_label, FALSE, FALSE, 0);
100 gtk_widget_show(filter_label);
104 /* create a table, using a scrollable GtkTreeView */
107 create_stat_table(GtkWidget *scrolled_window, GtkWidget *vbox, int columns, const stat_column *headers)
112 GtkTreeViewColumn *column;
113 GtkTreeSelection *sel;
114 GtkCellRenderer *renderer;
121 types = g_malloc(columns *sizeof(GType));
122 for (i = 0; i < columns; i++)
123 types[i] = headers[i].type;
125 store = gtk_list_store_newv (columns, types);
129 tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
130 table = GTK_TREE_VIEW(tree);
131 g_object_unref (G_OBJECT (store));
133 for (i = 0; i < columns; i++) {
134 renderer = gtk_cell_renderer_text_new ();
135 if (headers[i].align == RIGHT) {
137 g_object_set(G_OBJECT(renderer), "xalign", 1.0, NULL);
139 g_object_set(renderer, "ypad", 0, NULL);
140 column = gtk_tree_view_column_new_with_attributes (headers[i].title, renderer, "text",
142 gtk_tree_view_column_set_resizable(column, TRUE);
143 gtk_tree_view_append_column (table, column);
145 gtk_container_add(GTK_CONTAINER(scrolled_window), GTK_WIDGET (table));
146 gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0);
148 /* configure TreeView */
149 gtk_tree_view_set_rules_hint(table, FALSE);
150 gtk_tree_view_set_headers_clickable(table, FALSE);
152 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(table));
153 gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);
155 gtk_widget_show(scrolled_window);