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