move font related stuff to new file font_utils.c/.h
[obnox/wireshark/wip.git] / gtk / packet_list.c
1 /* packet_list.c
2  * packet list related functions   2002 Olivier Abad
3  *
4  * $Id: packet_list.c,v 1.21 2004/06/17 16:35:25 ulfl 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 #include <string.h>
31
32 #include "globals.h"
33 #include "gtkglobals.h"
34 #include "epan/epan.h"
35 #include "color.h"
36 #include "../ui_util.h"
37 #include "ui_util.h"
38 #include "main.h"
39 #include "menu.h"
40 #include "color_utils.h"
41 #include "column.h"
42 #include "epan/column_info.h"
43 #include "compat_macros.h"
44 #include "../prefs.h"
45 #include "file_dlg.h"
46 #include "packet_list.h"
47 #include "keys.h"
48 #include "font_utils.h"
49
50 #include <epan/timestamp.h>
51
52 #include "image/clist_ascend.xpm"
53 #include "image/clist_descend.xpm"
54
55 /*
56  * XXX - gross hack.
57  * This lets us use GtkCList in GTK+ 1.3[.x] and later, and EthCList on
58  * GTK+ 1.2[.x], at least until we either use GTK+ 2.x's native widgets
59  * or make EthCList work on 1.3[.x] and 2.x.
60  */
61 #if GTK_MAJOR_VERSION >= 2 || GTK_MINOR_VERSION >= 3
62 #define EthCList                                GtkCList
63 #define EthCListRow                             GtkCListRow
64 #define eth_clist_append                        gtk_clist_append
65 #define eth_clist_clear                         gtk_clist_clear
66 #define eth_clist_column_titles_show            gtk_clist_column_titles_show
67 #define eth_clist_find_row_from_data            gtk_clist_find_row_from_data
68 #define eth_clist_freeze                        gtk_clist_freeze
69 #define eth_clist_get_row_data                  gtk_clist_get_row_data
70 #define eth_clist_get_selection_info            gtk_clist_get_selection_info
71 #define eth_clist_moveto                        gtk_clist_moveto
72 #define eth_clist_new                           gtk_clist_new
73 #define eth_clist_row_is_visible                gtk_clist_row_is_visible
74 #define eth_clist_select_row                    gtk_clist_select_row
75 #define eth_clist_set_background                gtk_clist_set_background
76 #define eth_clist_set_column_auto_resize        gtk_clist_set_column_auto_resize
77 #define eth_clist_set_column_justification      gtk_clist_set_column_justification
78 #define eth_clist_set_column_resizeable         gtk_clist_set_column_resizeable
79 #define eth_clist_set_column_width              gtk_clist_set_column_width
80 #define eth_clist_set_column_widget             gtk_clist_set_column_widget
81 #define eth_clist_set_compare_func              gtk_clist_set_compare_func
82 #define eth_clist_set_foreground                gtk_clist_set_foreground
83 #define eth_clist_set_row_data                  gtk_clist_set_row_data
84 #define eth_clist_set_selection_mode            gtk_clist_set_selection_mode
85 #define eth_clist_set_sort_column               gtk_clist_set_sort_column
86 #define eth_clist_set_text                      gtk_clist_set_text
87 #define eth_clist_sort                          gtk_clist_sort
88 #define eth_clist_thaw                          gtk_clist_thaw
89 #define ETH_CLIST                               GTK_CLIST
90 #else
91 #include "ethclist.h"
92 #endif
93
94 typedef struct column_arrows {
95   GtkWidget *table;
96   GtkWidget *ascend_pm;
97   GtkWidget *descend_pm;
98 } column_arrows;
99
100 GtkWidget *packet_list;
101
102 /* EthClist compare routine, overrides default to allow numeric comparison */
103
104 #define COMPARE_FRAME_NUM()     ((fdata1->num < fdata2->num) ? -1 : \
105                                  (fdata1->num > fdata2->num) ? 1 : \
106                                  0)
107
108 #define COMPARE_NUM(f)  ((fdata1->f < fdata2->f) ? -1 : \
109                          (fdata1->f > fdata2->f) ? 1 : \
110                          COMPARE_FRAME_NUM())
111
112 /* Compare time stamps.
113    A packet whose time is a reference time is considered to have
114    a lower time stamp than any frame with a non-reference time;
115    if both packets' times are reference times, we compare the
116    times of the packets. */
117 #define COMPARE_TS(secs, usecs) \
118                 ((fdata1->flags.ref_time && !fdata2->flags.ref_time) ? -1 : \
119                  (!fdata1->flags.ref_time && fdata2->flags.ref_time) ? 1 : \
120                  (fdata1->secs < fdata2->secs) ? -1 : \
121                  (fdata1->secs > fdata2->secs) ? 1 : \
122                  (fdata1->usecs < fdata2->usecs) ? -1 :\
123                  (fdata1->usecs > fdata2->usecs) ? 1 : \
124                  COMPARE_FRAME_NUM())
125 static gint
126 packet_list_compare(EthCList *clist, gconstpointer  ptr1, gconstpointer  ptr2)
127 {
128   /* Get row data structures */
129   const EthCListRow *row1 = (const EthCListRow *)ptr1;
130   const EthCListRow *row2 = (const EthCListRow *)ptr2;
131
132   /* Get the frame data structures for the rows */
133   const frame_data *fdata1 = row1->data;
134   const frame_data *fdata2 = row2->data;
135
136   /* Get row text strings */
137   const char *text1 = GTK_CELL_TEXT (row1->cell[clist->sort_column])->text;
138   const char *text2 = GTK_CELL_TEXT (row2->cell[clist->sort_column])->text;
139
140   /* Attempt to convert to numbers */
141   double  num1;
142   double  num2;
143
144   int ret;
145
146   gint  col_fmt = cfile.cinfo.col_fmt[clist->sort_column];
147
148   switch (col_fmt) {
149
150   case COL_NUMBER:
151     return COMPARE_FRAME_NUM();
152
153   case COL_CLS_TIME:
154     switch (get_timestamp_setting()) {
155
156     case TS_ABSOLUTE:
157     case TS_ABSOLUTE_WITH_DATE:
158       return COMPARE_TS(abs_secs, abs_usecs);
159
160     case TS_RELATIVE:
161       return COMPARE_TS(rel_secs, rel_usecs);
162
163     case TS_DELTA:
164       return COMPARE_TS(del_secs, del_usecs);
165     }
166     return 0;
167
168   case COL_ABS_TIME:
169     return COMPARE_TS(abs_secs, abs_usecs);
170
171   case COL_REL_TIME:
172     return COMPARE_TS(rel_secs, rel_usecs);
173
174   case COL_DELTA_TIME:
175     return COMPARE_TS(del_secs, del_usecs);
176
177   case COL_PACKET_LENGTH:
178     return COMPARE_NUM(pkt_len);
179
180   case COL_CUMULATIVE_BYTES:
181     return COMPARE_NUM(cum_bytes);
182
183   default:
184     num1 = atof(text1);
185     num2 = atof(text2);
186     if ((col_fmt == COL_UNRES_SRC_PORT) || (col_fmt == COL_UNRES_DST_PORT) ||
187         ((num1 != 0) && (num2 != 0) && ((col_fmt == COL_DEF_SRC_PORT) || (col_fmt == COL_RES_SRC_PORT) ||
188                                       (col_fmt == COL_DEF_DST_PORT) || (col_fmt == COL_RES_DST_PORT)))) {
189
190       /* Compare numeric column */
191
192       if (num1 < num2)
193         return -1;
194       else if (num1 > num2)
195         return 1;
196       else
197         return COMPARE_FRAME_NUM();
198     }
199
200     else {
201
202       /* Compare text column */
203       if (!text2) {
204         if (text1)
205           return 1;
206         else
207           return COMPARE_FRAME_NUM();
208       }
209
210       if (!text1)
211         return -1;
212
213       ret = strcmp(text1, text2);
214       if (ret == 0)
215         return COMPARE_FRAME_NUM();
216       else
217         return ret;
218     }
219   }
220 }
221
222 /* What to do when a column is clicked */
223 static void
224 packet_list_click_column_cb(EthCList *clist, gint column, gpointer data)
225 {
226   column_arrows *col_arrows = (column_arrows *) data;
227   int i;
228
229   eth_clist_freeze(clist);
230
231   for (i = 0; i < cfile.cinfo.num_cols; i++) {
232     gtk_widget_hide(col_arrows[i].ascend_pm);
233     gtk_widget_hide(col_arrows[i].descend_pm);
234   }
235
236   if (column == clist->sort_column) {
237     if (clist->sort_type == GTK_SORT_ASCENDING) {
238       clist->sort_type = GTK_SORT_DESCENDING;
239       gtk_widget_show(col_arrows[column].descend_pm);
240     } else {
241       clist->sort_type = GTK_SORT_ASCENDING;
242       gtk_widget_show(col_arrows[column].ascend_pm);
243     }
244   }
245   else {
246     clist->sort_type = GTK_SORT_ASCENDING;
247     gtk_widget_show(col_arrows[column].ascend_pm);
248     eth_clist_set_sort_column(clist, column);
249   }
250   eth_clist_thaw(clist);
251
252   eth_clist_sort(clist);
253 }
254
255 /* What to do when a list item is selected/unselected */
256 static void
257 packet_list_select_cb(GtkWidget *w _U_, gint row, gint col _U_, gpointer evt _U_) {
258
259 /* Remove the hex display tabbed pages */
260   while( (gtk_notebook_get_nth_page( GTK_NOTEBOOK(byte_nb_ptr), 0)))
261     gtk_notebook_remove_page( GTK_NOTEBOOK(byte_nb_ptr), 0);
262
263   select_packet(&cfile, row);
264   gtk_widget_grab_focus(packet_list);
265 }
266
267 static void
268 packet_list_unselect_cb(GtkWidget *w _U_, gint row _U_, gint col _U_, gpointer evt _U_) {
269
270   unselect_packet(&cfile);
271 }
272
273 /* mark packets */
274 static void
275 set_frame_mark(gboolean set, frame_data *frame, gint row) {
276   GdkColor fg, bg;
277
278   if (row == -1)
279     return;
280   if (set) {
281     mark_frame(&cfile, frame);
282     color_t_to_gdkcolor(&fg, &prefs.gui_marked_fg);
283     color_t_to_gdkcolor(&bg, &prefs.gui_marked_bg);
284     eth_clist_set_foreground(ETH_CLIST(packet_list), row, &fg);
285     eth_clist_set_background(ETH_CLIST(packet_list), row, &bg);
286   } else {
287     color_filter_t *cfilter = frame->color_filter;
288
289     unmark_frame(&cfile, frame);
290     /* Restore the color from the matching color filter if any */
291     if (cfilter) { /* The packet matches a color filter */
292       color_t_to_gdkcolor(&fg, &cfilter->fg_color);
293       color_t_to_gdkcolor(&bg, &cfilter->bg_color);
294       eth_clist_set_foreground(ETH_CLIST(packet_list), row, &fg);
295       eth_clist_set_background(ETH_CLIST(packet_list), row, &bg);
296     } else { /* No color filter match */
297       eth_clist_set_foreground(ETH_CLIST(packet_list), row, NULL);
298       eth_clist_set_background(ETH_CLIST(packet_list), row, NULL);
299     }
300   }
301 }
302
303 /* call this after last set_frame_mark is done */
304 void mark_frames_ready(void) {
305   file_set_save_marked_sensitive();
306   packets_bar_update();
307 }
308
309 void mark_frame_cb(GtkWidget *w _U_, gpointer data _U_) {
310   if (cfile.current_frame) {
311     /* XXX hum, should better have a "cfile->current_row" here ... */
312     set_frame_mark(!cfile.current_frame->flags.marked,
313                    cfile.current_frame,
314                    eth_clist_find_row_from_data(ETH_CLIST(packet_list),
315                                                 cfile.current_frame));
316     mark_frames_ready();
317   }
318 }
319
320 static void mark_all_frames(gboolean set) {
321   frame_data *fdata;
322   
323   /* XXX: we might need a progressbar here */
324   cfile.marked_count = 0;       
325   for (fdata = cfile.plist; fdata != NULL; fdata = fdata->next) {
326     set_frame_mark(set,
327                    fdata,
328                    eth_clist_find_row_from_data(ETH_CLIST(packet_list), fdata));
329   }
330   mark_frames_ready();
331 }
332
333 void update_marked_frames(void) {
334   frame_data *fdata;
335
336   if (cfile.plist == NULL) return;
337
338   /* XXX: we might need a progressbar here */
339   for (fdata = cfile.plist; fdata != NULL; fdata = fdata->next) {
340     if (fdata->flags.marked)
341       set_frame_mark(TRUE,
342                      fdata,
343                      eth_clist_find_row_from_data(ETH_CLIST(packet_list),
344                                                   fdata));
345   }
346   mark_frames_ready();
347 }
348
349 void mark_all_frames_cb(GtkWidget *w _U_, gpointer data _U_) {
350   mark_all_frames(TRUE);
351 }
352
353 void unmark_all_frames_cb(GtkWidget *w _U_, gpointer data _U_) {
354   mark_all_frames(FALSE);
355 }
356
357 gboolean
358 packet_list_get_event_row_column(GtkWidget *w, GdkEventButton *event_button,
359                                  gint *row, gint *column)
360 {
361     return eth_clist_get_selection_info(ETH_CLIST(w), 
362                                  (gint) event_button->x, (gint) event_button->y, 
363                                   row, column);
364 }
365
366 #if GTK_MAJOR_VERSION < 2
367 static void
368 packet_list_button_pressed_cb(GtkWidget *w, GdkEvent *event, gpointer data _U_)
369 {
370     GdkEventButton *event_button = (GdkEventButton *)event;
371     gint row, column;
372
373     if (w == NULL || event == NULL)
374         return;
375
376     if (event->type == GDK_BUTTON_PRESS && event_button->button == 2 &&
377         event_button->window == ETH_CLIST(w)->clist_window &&
378         packet_list_get_event_row_column(w, event_button, &row, &column)) {
379         frame_data *fdata = (frame_data *) eth_clist_get_row_data(ETH_CLIST(w),
380                                                                   row);
381         set_frame_mark(!fdata->flags.marked, fdata, row);
382         mark_frames_ready();
383     }
384 }
385 #else
386 static gint
387 packet_list_button_pressed_cb(GtkWidget *w, GdkEvent *event, gpointer data _U_)
388 {
389     GdkEventButton *event_button = (GdkEventButton *)event;
390     gint row, column;
391
392     if (w == NULL || event == NULL)
393         return FALSE;
394
395     if (event->type == GDK_BUTTON_PRESS && event_button->button == 2 &&
396         event_button->window == ETH_CLIST(w)->clist_window &&
397         eth_clist_get_selection_info(ETH_CLIST(w), (gint) event_button->x,
398                                      (gint) event_button->y, &row, &column)) {
399         frame_data *fdata = (frame_data *)eth_clist_get_row_data(ETH_CLIST(w),
400                                                                  row);
401         set_frame_mark(!fdata->flags.marked, fdata, row);
402         mark_frames_ready();
403         return TRUE;
404     }
405     return FALSE;
406 }
407 #endif
408
409 /* Set the selection mode of the packet list window. */
410 void
411 set_plist_sel_browse(gboolean val)
412 {
413         GtkSelectionMode new_mode;
414         /* initialize with a mode we don't use, so that the mode == new_mode
415          * test will fail the first time */
416         static GtkSelectionMode mode = GTK_SELECTION_MULTIPLE;
417
418         /* Yeah, GTK uses "browse" in the case where we do not, but oh well. I
419          * think "browse" in Ethereal makes more sense than "SINGLE" in GTK+ */
420         new_mode = val ? GTK_SELECTION_SINGLE : GTK_SELECTION_BROWSE;
421
422         if (mode == new_mode) {
423                 /*
424                  * The mode isn't changing, so don't do anything.
425                  * In particular, don't gratuitiously unselect the
426                  * current packet.
427                  *
428                  * XXX - why do we have to unselect the current packet
429                  * ourselves?  The documentation for the GtkCList at
430                  *
431                  *      http://developer.gnome.org/doc/API/gtk/gtkclist.html
432                  *
433                  * says "Note that setting the widget's selection mode to
434                  * one of GTK_SELECTION_BROWSE or GTK_SELECTION_SINGLE will
435                  * cause all the items in the GtkCList to become deselected."
436                  */
437                 return;
438         }
439
440         if (cfile.finfo_selected)
441                 unselect_packet(&cfile);
442
443         mode = new_mode;
444         eth_clist_set_selection_mode(ETH_CLIST(packet_list), mode);
445 }
446
447 /* Set the font of the packet list window. */
448 void
449 set_plist_font(FONT_TYPE *font)
450 {
451         int i;
452         gint col_width;
453 #if GTK_MAJOR_VERSION < 2
454         GtkStyle *style;
455
456         style = gtk_style_new();
457         gdk_font_unref(style->font);
458         style->font = font;
459         gdk_font_ref(font);
460
461         gtk_widget_set_style(packet_list, style);
462 #else
463         PangoLayout *layout;
464
465         gtk_widget_modify_font(packet_list, font);
466 #endif
467
468         /* Compute default column sizes. */
469         for (i = 0; i < cfile.cinfo.num_cols; i++) {
470 #if GTK_MAJOR_VERSION < 2
471                 col_width = gdk_string_width(font,
472                         get_column_longest_string(get_column_format(i)));
473 #else
474                 layout = gtk_widget_create_pango_layout(packet_list,
475                     get_column_longest_string(get_column_format(i)));
476                 pango_layout_get_pixel_size(layout, &col_width, NULL);
477                 g_object_unref(G_OBJECT(layout));
478 #endif
479                 eth_clist_set_column_width(ETH_CLIST(packet_list), i,
480                         col_width);
481         }
482 }
483
484 GtkWidget *
485 packet_list_new(e_prefs *prefs)
486 {
487     GtkWidget *pkt_scrollw;
488     int            i;
489
490     /* Packet list */
491     pkt_scrollw = scrolled_window_new(NULL, NULL);
492 #if GTK_MAJOR_VERSION >= 2
493     /* the eth_clist will have it's own GTK_SHADOW_IN, so don't use a shadow 
494      * for both widgets */
495     gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(pkt_scrollw), 
496                                     GTK_SHADOW_NONE);
497 #endif
498
499     packet_list = eth_clist_new(cfile.cinfo.num_cols);
500     /* Column titles are filled in below */
501     gtk_container_add(GTK_CONTAINER(pkt_scrollw), packet_list);
502
503     set_plist_sel_browse(prefs->gui_plist_sel_browse);
504     set_plist_font(user_font_get_regular());
505     gtk_widget_set_name(packet_list, "packet list");
506     SIGNAL_CONNECT(packet_list, "select-row", packet_list_select_cb, NULL);
507     SIGNAL_CONNECT(packet_list, "unselect-row", packet_list_unselect_cb, NULL);
508     for (i = 0; i < cfile.cinfo.num_cols; i++) {
509         /* Columns do not automatically resize, but are resizeable by
510            the user. */
511         eth_clist_set_column_auto_resize(ETH_CLIST(packet_list), i, FALSE);
512         eth_clist_set_column_resizeable(ETH_CLIST(packet_list), i, TRUE);
513
514         /* Right-justify the packet number column. */
515         if (cfile.cinfo.col_fmt[i] == COL_NUMBER)
516             eth_clist_set_column_justification(ETH_CLIST(packet_list), i,
517                                                GTK_JUSTIFY_RIGHT);
518     }
519     SIGNAL_CONNECT(packet_list, "button_press_event", popup_menu_handler,
520                    OBJECT_GET_DATA(popup_menu_object, PM_PACKET_LIST_KEY));
521     SIGNAL_CONNECT(packet_list, "button_press_event",
522                    packet_list_button_pressed_cb, NULL);
523     eth_clist_set_compare_func(ETH_CLIST(packet_list), packet_list_compare);
524     gtk_widget_show(packet_list);
525
526     return pkt_scrollw;
527 }
528
529 void
530 packet_list_set_column_titles(void)
531 {
532     GtkStyle      *win_style;
533     GdkPixmap     *ascend_pm, *descend_pm;
534     GdkBitmap     *ascend_bm, *descend_bm;
535     column_arrows *col_arrows;
536     int            i;
537     GtkWidget     *column_lb;
538
539     win_style = gtk_widget_get_style(top_level);
540     ascend_pm = gdk_pixmap_create_from_xpm_d(top_level->window, &ascend_bm,
541                                              &win_style->bg[GTK_STATE_NORMAL],
542                                              (gchar **)clist_ascend_xpm);
543     descend_pm = gdk_pixmap_create_from_xpm_d(top_level->window, &descend_bm,
544                                               &win_style->bg[GTK_STATE_NORMAL],
545                                               (gchar **)clist_descend_xpm);
546
547     col_arrows = (column_arrows *) g_malloc(sizeof(column_arrows) *
548                                             cfile.cinfo.num_cols);
549     for (i = 0; i < cfile.cinfo.num_cols; i++) {
550         col_arrows[i].table = gtk_table_new(2, 2, FALSE);
551         gtk_table_set_col_spacings(GTK_TABLE(col_arrows[i].table), 5);
552         column_lb = gtk_label_new(cfile.cinfo.col_title[i]);
553         gtk_table_attach(GTK_TABLE(col_arrows[i].table), column_lb, 0, 1, 0, 2,
554                          GTK_SHRINK, GTK_SHRINK, 0, 0);
555         gtk_widget_show(column_lb);
556         col_arrows[i].ascend_pm = gtk_pixmap_new(ascend_pm, ascend_bm);
557         gtk_table_attach(GTK_TABLE(col_arrows[i].table),
558                          col_arrows[i].ascend_pm,
559                          1, 2, 1, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
560         if (i == 0) {
561             gtk_widget_show(col_arrows[i].ascend_pm);
562         }
563         col_arrows[i].descend_pm = gtk_pixmap_new(descend_pm, descend_bm);
564         gtk_table_attach(GTK_TABLE(col_arrows[i].table),
565                          col_arrows[i].descend_pm,
566                          1, 2, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
567         eth_clist_set_column_widget(ETH_CLIST(packet_list), i,
568                                     col_arrows[i].table);
569         gtk_widget_show(col_arrows[i].table);
570     }
571     eth_clist_column_titles_show(ETH_CLIST(packet_list));
572     SIGNAL_CONNECT(packet_list, "click-column", packet_list_click_column_cb,
573                    col_arrows);
574 }
575
576 void
577 packet_list_clear(void)
578 {
579     eth_clist_clear(ETH_CLIST(packet_list));
580 }
581
582 void
583 packet_list_freeze(void)
584 {
585     eth_clist_freeze(ETH_CLIST(packet_list));
586 }
587
588 void
589 packet_list_thaw(void)
590 {
591     eth_clist_thaw(ETH_CLIST(packet_list));
592     packets_bar_update();
593 }
594
595 void
596 packet_list_select_row(gint row)
597 {
598     SIGNAL_EMIT_BY_NAME(packet_list, "select_row", row);
599 }
600
601 void
602 packet_list_moveto_end(void)
603 {
604     eth_clist_moveto(ETH_CLIST(packet_list),
605                      ETH_CLIST(packet_list)->rows - 1, -1, 1.0, 1.0);
606 }
607
608 gint
609 packet_list_append(gchar *text[], gpointer data)
610 {
611     gint row;
612
613     row = eth_clist_append(ETH_CLIST(packet_list), text);
614     eth_clist_set_row_data(ETH_CLIST(packet_list), row, data);
615     return row;
616 }
617
618 void
619 packet_list_set_colors(gint row, color_t *fg, color_t *bg)
620 {
621     GdkColor gdkfg, gdkbg;
622
623     if (fg)
624     {
625         color_t_to_gdkcolor(&gdkfg, fg);
626         eth_clist_set_foreground(ETH_CLIST(packet_list), row, &gdkfg);
627     }
628     if (bg)
629     {
630         color_t_to_gdkcolor(&gdkbg, bg);
631         eth_clist_set_background(ETH_CLIST(packet_list), row, &gdkbg);
632     }
633 }
634
635 gint
636 packet_list_find_row_from_data(gpointer data)
637 {
638     return eth_clist_find_row_from_data(ETH_CLIST(packet_list), data);
639 }
640
641 void
642 packet_list_set_text(gint row, gint column, const gchar *text)
643 {
644     eth_clist_set_text(ETH_CLIST(packet_list), row, column, text);
645 }
646
647 /* Set the column widths of those columns that show the time in
648  * "command-line-specified" format. */
649 void
650 packet_list_set_cls_time_width(gint column)
651 {
652     gint      width;
653 #if GTK_MAJOR_VERSION < 2
654     GtkStyle *pl_style;
655
656     pl_style = gtk_widget_get_style(packet_list);
657     width = gdk_string_width(pl_style->font,
658                              get_column_longest_string(COL_CLS_TIME));
659 #else
660     PangoLayout  *layout;
661
662     layout = gtk_widget_create_pango_layout(packet_list,
663                  get_column_longest_string(COL_CLS_TIME));
664     pango_layout_get_pixel_size(layout, &width, NULL);
665     g_object_unref(G_OBJECT(layout));
666 #endif
667     eth_clist_set_column_width(ETH_CLIST(packet_list), column, width);
668 }
669
670 gpointer
671 packet_list_get_row_data(gint row)
672 {
673     return eth_clist_get_row_data(ETH_CLIST(packet_list), row);
674 }
675
676 /* Set the selected row and the focus row of the packet list to the specified
677  * row, and make it visible if it's not currently visible. */
678 void
679 packet_list_set_selected_row(gint row)
680 {
681     if (eth_clist_row_is_visible(ETH_CLIST(packet_list), row) !=
682         GTK_VISIBILITY_FULL)
683         eth_clist_moveto(ETH_CLIST(packet_list), row, -1, 0.0, 0.0);
684
685     /* XXX - why is there no "eth_clist_set_focus_row()", so that we
686      * can make the row for the frame we found the focus row?
687      *
688      * See http://www.gnome.org/mailing-lists/archives/gtk-list/2000-January/0038.shtml
689      */
690     ETH_CLIST(packet_list)->focus_row = row;
691
692     eth_clist_select_row(ETH_CLIST(packet_list), row, -1);
693 }
694
695 /* Return the column number that the clist is currently sorted by */
696 gint
697 packet_list_get_sort_column(void)
698 {
699     return ETH_CLIST(packet_list)->sort_column;
700 }