More warining fixes: char -> const char
[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$
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 #if 0
46 /* Statistic table */
47 typedef struct _gtk_table {
48         GtkWidget *widget;  /**< the table widget */
49         int height;         /**< the height */
50         int width;          /**< the width */
51 }gtk_table;
52
53 void
54 add_table_entry(gtk_table *tab, const char *str, int x, int y)
55 {
56         GtkWidget *tmp;
57
58         if(y>=tab->height){
59                 tab->height=y+1;
60                 gtk_table_resize(GTK_TABLE(tab->widget), tab->height, tab->width);
61         }
62         if(x>=tab->width){
63                 tab->width=x+1;
64                 gtk_table_resize(GTK_TABLE(tab->widget), tab->height, tab->width);
65         }
66
67         tmp=gtk_label_new(str);
68         gtk_table_attach_defaults(GTK_TABLE(tab->widget), tmp, x, x+1, y, y+1);
69         gtk_label_set_justify(GTK_LABEL(tmp), GTK_JUSTIFY_LEFT);
70         gtk_widget_show(tmp);
71 }
72 #endif
73
74 /* init a main windowfor stats, set title and display used filter in window */
75
76 void
77 init_main_stat_window(GtkWidget *window, GtkWidget *mainbox, char *title, char *filter)
78 {
79         GtkWidget *main_label;
80         GtkWidget *filter_label;
81         char filter_string[256];
82
83
84         gtk_window_set_title(GTK_WINDOW(window), title);
85
86         gtk_container_add(GTK_CONTAINER(window), mainbox);
87         gtk_container_set_border_width(GTK_CONTAINER(mainbox), 10);
88         gtk_widget_show(mainbox);
89
90         main_label=gtk_label_new(title);
91         gtk_box_pack_start(GTK_BOX(mainbox), main_label, FALSE, FALSE, 0);
92         gtk_widget_show(main_label);
93
94         g_snprintf(filter_string,255,"Filter:%s",filter?filter:"");
95         filter_label=gtk_label_new(filter_string);
96         gtk_box_pack_start(GTK_BOX(mainbox), filter_label, FALSE, FALSE, 0);
97         gtk_widget_show(filter_label);
98
99 }
100
101 /* create a table, using a scrollable gtkclist */
102
103 GtkCList *
104 create_stat_table(GtkWidget *scrolled_window, GtkWidget *vbox, int columns, char *titles[])
105 {
106         GtkCList *table;
107         int i;
108
109         /* create table */
110         table = GTK_CLIST(gtk_clist_new_with_titles(columns, titles));
111
112         gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0);
113
114         /* configure clist */
115         gtk_clist_column_titles_passive(table);
116         gtk_clist_column_titles_show(table);
117         for (i = 0; i < columns; i++)
118             gtk_clist_set_column_auto_resize(table, i, TRUE);
119         gtk_clist_set_selection_mode(table, GTK_SELECTION_SINGLE);
120
121         /* Put clist into a scrolled window */
122         gtk_container_add(GTK_CONTAINER(scrolled_window),
123                           GTK_WIDGET(table));
124         gtk_widget_show(GTK_WIDGET(table));
125         gtk_widget_show(scrolled_window);
126
127         return table;
128 }
129