Change to color filters :
[obnox/wireshark/wip.git] / gtk2 / packet_list.c
1 /* packet_list.c
2  * packet list related functions   2002 Olivier Abad
3  *
4  * $Id: packet_list.c,v 1.2 2002/09/23 19:09:52 oabad Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <gtk/gtk.h>
30
31 #include "gtkglobals.h"
32 #include "epan/epan.h"
33 #include "color.h"
34 #include "../ui_util.h"
35 #include "color_utils.h"
36 #include "column.h"
37 #include "epan/column_info.h"
38
39 void
40 packet_list_clear(void)
41 {
42     gtk_clist_clear(GTK_CLIST(packet_list));
43 }
44
45 void
46 packet_list_freeze(void)
47 {
48     gtk_clist_freeze(GTK_CLIST(packet_list));
49 }
50
51 void
52 packet_list_thaw(void)
53 {
54     gtk_clist_thaw(GTK_CLIST(packet_list));
55 }
56
57 void
58 packet_list_select_row(gint row)
59 {
60     gtk_signal_emit_by_name(GTK_OBJECT(packet_list), "select_row", row);
61 }
62
63 void
64 packet_list_set_column_auto_resize(gint column, gboolean auto_resize)
65 {
66     gtk_clist_set_column_auto_resize(GTK_CLIST(packet_list), column,
67                                      auto_resize);
68 }
69
70 void
71 packet_list_set_column_resizeable(gint column, gboolean resizeable)
72 {
73     gtk_clist_set_column_resizeable(GTK_CLIST(packet_list), column, resizeable);
74 }
75
76 void
77 packet_list_set_column_width(gint column, gint width)
78 {
79     gtk_clist_set_column_width(GTK_CLIST(packet_list), column, width);
80 }
81
82 void
83 packet_list_moveto_end(void)
84 {
85     gtk_clist_moveto(GTK_CLIST(packet_list),
86                      GTK_CLIST(packet_list)->rows - 1, -1, 1.0, 1.0);
87 }
88
89 gint
90 packet_list_append(gchar *text[], gpointer data)
91 {
92     gint row;
93
94     row = gtk_clist_append(GTK_CLIST(packet_list), text);
95     gtk_clist_set_row_data(GTK_CLIST(packet_list), row, data);
96     return row;
97 }
98
99 void
100 packet_list_set_colors(gint row, color_t *fg, color_t *bg)
101 {
102     GdkColor gdkfg, gdkbg;
103
104     if (fg)
105     {
106         color_t_to_gdkcolor(&gdkfg, fg);
107         gtk_clist_set_foreground(GTK_CLIST(packet_list), row, &gdkfg);
108     }
109     if (bg)
110     {
111         color_t_to_gdkcolor(&gdkbg, bg);
112         gtk_clist_set_background(GTK_CLIST(packet_list), row, &gdkbg);
113     }
114 }
115
116 gint
117 packet_list_find_row_from_data(gpointer data)
118 {
119     return gtk_clist_find_row_from_data(GTK_CLIST(packet_list), data);
120 }
121
122 void
123 packet_list_set_text(gint row, gint column, const gchar *text)
124 {
125     gtk_clist_set_text(GTK_CLIST(packet_list), row, column, text);
126 }
127
128 /* Set the column widths of those columns that show the time in
129  * "command-line-specified" format. */
130 void
131 packet_list_set_cls_time_width(gint column)
132 {
133     GtkStyle *pl_style;
134     gint      width;
135
136     pl_style = gtk_widget_get_style(packet_list);
137     width = gdk_string_width(gdk_font_from_description(pl_style->font_desc),
138                              get_column_longest_string(COL_CLS_TIME));
139     packet_list_set_column_width(column, width);
140 }
141
142 gpointer
143 packet_list_get_row_data(gint row)
144 {
145     return gtk_clist_get_row_data(GTK_CLIST(packet_list), row);
146 }
147
148 /* Set the selected row and the focus row of the packet list to the specified
149  * row, and make it visible if it's not currently visible. */
150 void
151 packet_list_set_selected_row(gint row)
152 {
153     if (gtk_clist_row_is_visible(GTK_CLIST(packet_list), row) !=
154         GTK_VISIBILITY_FULL)
155         gtk_clist_moveto(GTK_CLIST(packet_list), row, -1, 0.0, 0.0);
156
157     /* XXX - why is there no "gtk_clist_set_focus_row()", so that we
158      * can make the row for the frame we found the focus row?
159      *
160      * See http://www.gnome.org/mailing-lists/archives/gtk-list/2000-January/0038.shtml
161      */
162     GTK_CLIST(packet_list)->focus_row = row;
163
164     gtk_clist_select_row(GTK_CLIST(packet_list), row, -1);
165 }