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"
41 #include "../globals.h"
43 #include "gtk/gui_stat_util.h"
46 /* insert a string into a GTK_TABLE at column x and row y*/
49 typedef struct _gtk_table {
50 GtkWidget *widget; /**< the table widget */
51 int height; /**< the height */
52 int width; /**< the width */
56 add_table_entry(gtk_table *tab, const char *str, int x, int y)
62 gtk_table_resize(GTK_TABLE(tab->widget), tab->height, tab->width);
66 gtk_table_resize(GTK_TABLE(tab->widget), tab->height, tab->width);
69 tmp=gtk_label_new(str);
70 gtk_table_attach_defaults(GTK_TABLE(tab->widget), tmp, x, x+1, y, y+1);
71 gtk_label_set_justify(GTK_LABEL(tmp), GTK_JUSTIFY_LEFT);
76 /* init a main window for stats, set title and display used filter in window */
79 init_main_stat_window(GtkWidget *window, GtkWidget *mainbox, const char *title, const char *filter)
81 GtkWidget *main_label;
82 GtkWidget *filter_label;
86 gtk_window_set_title(GTK_WINDOW(window), title);
88 gtk_container_add(GTK_CONTAINER(window), mainbox);
89 gtk_container_set_border_width(GTK_CONTAINER(mainbox), 10);
90 gtk_widget_show(mainbox);
92 main_label=gtk_label_new(title);
93 gtk_box_pack_start(GTK_BOX(mainbox), main_label, FALSE, FALSE, 0);
94 gtk_widget_show(main_label);
96 filter_string = g_strdup_printf("Filter: %s", filter ? filter : "");
97 filter_label=gtk_label_new(filter_string);
98 g_free(filter_string);
99 gtk_label_set_line_wrap(GTK_LABEL(filter_label), TRUE);
100 gtk_box_pack_start(GTK_BOX(mainbox), filter_label, FALSE, FALSE, 0);
101 gtk_widget_show(filter_label);
105 /* create a table, using a scrollable gtkclist */
108 create_stat_table(GtkWidget *scrolled_window, GtkWidget *vbox, int columns, const stat_column *headers)
113 GtkTreeViewColumn *column;
114 GtkTreeSelection *sel;
115 GtkCellRenderer *renderer;
122 types = g_malloc(columns *sizeof(GType));
123 for (i = 0; i < columns; i++)
124 types[i] = headers[i].type;
126 store = gtk_list_store_newv (columns, types);
130 tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
131 table = GTK_TREE_VIEW(tree);
132 g_object_unref (G_OBJECT (store));
134 for (i = 0; i < columns; i++) {
135 renderer = gtk_cell_renderer_text_new ();
136 if (headers[i].align == RIGHT) {
138 g_object_set(G_OBJECT(renderer), "xalign", 1.0, NULL);
140 g_object_set(renderer, "ypad", 0, NULL);
141 column = gtk_tree_view_column_new_with_attributes (headers[i].title, renderer, "text",
143 gtk_tree_view_column_set_resizable(column, TRUE);
144 gtk_tree_view_append_column (table, column);
146 gtk_container_add(GTK_CONTAINER(scrolled_window), GTK_WIDGET (table));
147 gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0);
149 /* configure clist */
150 gtk_tree_view_set_rules_hint(table, FALSE);
151 gtk_tree_view_set_headers_clickable(table, FALSE);
153 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(table));
154 gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);
156 gtk_widget_show(scrolled_window);