From Martin Regner: fix dissection of non-standard parameters.
[obnox/wireshark/wip.git] / gtk / gtk_stat_util.c
1 /* gtk_stat_util.c
2  * gui functions used by stats
3  * Copyright 2003 Lars Roland
4  *
5  * $Id: gtk_stat_util.c,v 1.3 2003/08/21 17:48:04 guy Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
9  * Copyright 1998 Gerald Combs
10  *
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.
15  *
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.
20  *
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.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <stdio.h>
31
32 #ifdef HAVE_SYS_TYPES_H
33 # include <sys/types.h>
34 #endif
35
36 #include <gtk/gtk.h>
37 #include <string.h>
38 #include "gtk_stat_util.h"
39 #include "compat_macros.h"
40 #include "../simple_dialog.h"
41 #include "../file.h"
42 #include "../globals.h"
43
44 /* insert a string into a GTK_TABLE at column x and row y*/
45
46 void
47 add_table_entry(gtk_table *tab, char *str, int x, int y)
48 {
49         GtkWidget *tmp;
50
51         if(y>=tab->height){
52                 tab->height=y+1;
53                 gtk_table_resize(GTK_TABLE(tab->widget), tab->height, tab->width);
54         }
55         if(x>=tab->width){
56                 tab->width=x+1;
57                 gtk_table_resize(GTK_TABLE(tab->widget), tab->height, tab->width);
58         }
59
60         tmp=gtk_label_new(str);
61         gtk_table_attach_defaults(GTK_TABLE(tab->widget), tmp, x, x+1, y, y+1);
62         gtk_label_set_justify(GTK_LABEL(tmp), GTK_JUSTIFY_LEFT);
63         gtk_widget_show(tmp);
64 }
65
66 /* init a main windowfor stats, set title and display used filter in window */
67
68 void
69 init_main_stat_window(GtkWidget *window, GtkWidget *mainbox, char *title, char *filter)
70 {
71         GtkWidget *main_label;
72         GtkWidget *filter_label;
73         char filter_string[256];
74
75
76         gtk_window_set_title(GTK_WINDOW(window), title);
77
78         gtk_container_add(GTK_CONTAINER(window), mainbox);
79         gtk_container_set_border_width(GTK_CONTAINER(mainbox), 10);
80         gtk_widget_show(mainbox);
81
82         main_label=gtk_label_new(title);
83         gtk_box_pack_start(GTK_BOX(mainbox), main_label, FALSE, FALSE, 0);
84         gtk_widget_show(main_label);
85
86         snprintf(filter_string,255,"Filter:%s",filter?filter:"");
87         filter_label=gtk_label_new(filter_string);
88         gtk_box_pack_start(GTK_BOX(mainbox), filter_label, FALSE, FALSE, 0);
89         gtk_widget_show(filter_label);
90
91 }
92
93 /* create a table, using a scrollable gtkclist */
94
95 GtkCList *
96 create_stat_table(GtkWidget *scrolled_window, GtkWidget *vbox, int columns, char *titles[])
97 {
98         GtkCList *table;
99         int i;
100
101         /* create table */
102         table = GTK_CLIST(gtk_clist_new_with_titles(columns, titles));
103
104         /* configure scrolling window*/
105         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
106                                        GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
107         gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0);
108
109         /* configure clist */
110         gtk_clist_column_titles_passive(table);
111         gtk_clist_column_titles_show(table);
112         for (i = 0; i < columns; i++)
113             gtk_clist_set_column_auto_resize(table, i, TRUE);
114         gtk_clist_set_selection_mode(table, GTK_SELECTION_SINGLE);
115
116         /* Put clist into a scrolled window */
117         gtk_container_add(GTK_CONTAINER(scrolled_window),
118                           GTK_WIDGET(table));
119         gtk_widget_show(GTK_WIDGET(table));
120         gtk_widget_show(scrolled_window);
121
122         return table;
123 }
124