diff options
author | Guy Harris <guy@alum.mit.edu> | 1999-06-19 03:14:32 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 1999-06-19 03:14:32 +0000 |
commit | becbefffcb9b460cc572a62b6ecf0920a5c47408 (patch) | |
tree | c5135b9685b259bb0a3c26730cf3c9a8533125d5 | |
parent | fe725bec8cb78d9fbcb1fb9133b1c3ad65e0e400 (diff) | |
download | wireshark-becbefffcb9b460cc572a62b6ecf0920a5c47408.tar.gz wireshark-becbefffcb9b460cc572a62b6ecf0920a5c47408.tar.bz2 wireshark-becbefffcb9b460cc572a62b6ecf0920a5c47408.zip |
Use "gtk_toggle_button_set_state()" rather than
"gtk_toggle_button_set_active()" to set the state of radio buttions;
"gtk_toggle_button_set_active()" doesn't exist in GTK+ 1.0[.x], and
"gtk_toggle_button_set_state()" is an alias for it in GTK+ 1.2[.x].
Compute the column widths in the summary display based on the longest
string in the column; recompute it whenever we update the columns.
svn path=/trunk/; revision=319
-rw-r--r-- | column.c | 64 | ||||
-rw-r--r-- | column.h | 3 | ||||
-rw-r--r-- | display.c | 24 | ||||
-rw-r--r-- | ethereal.c | 16 | ||||
-rw-r--r-- | file.c | 64 | ||||
-rw-r--r-- | packet.h | 4 |
6 files changed, 79 insertions, 96 deletions
@@ -1,7 +1,7 @@ /* column.c * Routines for handling column preferences * - * $Id: column.c,v 1.12 1999/06/19 01:47:43 guy Exp $ + * $Id: column.c,v 1.13 1999/06/19 03:14:30 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -166,68 +166,6 @@ get_column_format_matches(gboolean *fmt_list, gint format) { } } -/* Returns the longest possible width for a particular column type */ -/* XXX - this is somewhat fragile; we should probably generate */ -/* the summary lines for all the packets first, and compute the */ -/* maximum column width as the maximum string width of all the */ -/* values in that column. */ -gint -get_column_width(gint format, GdkFont *font) { - switch (format) { - case COL_NUMBER: - return (gdk_string_width(font, "0") * 7); - break; - case COL_CLS_TIME: - if (timestamp_type == ABSOLUTE) - return (gdk_string_width(font, "00:00:00.000000")); - else - return (gdk_string_width(font, "0000.000000")); - break; - case COL_ABS_TIME: - return (gdk_string_width(font, "00:00:00.000000")); - break; - case COL_REL_TIME: - case COL_DELTA_TIME: - return (gdk_string_width(font, "0000.000000")); - break; - case COL_DEF_SRC: - case COL_RES_SRC: - case COL_UNRES_SRC: - case COL_DEF_DL_SRC: - case COL_RES_DL_SRC: - case COL_UNRES_DL_SRC: - case COL_DEF_NET_SRC: - case COL_RES_NET_SRC: - case COL_UNRES_NET_SRC: - case COL_DEF_DST: - case COL_RES_DST: - case COL_UNRES_DST: - case COL_DEF_DL_DST: - case COL_RES_DL_DST: - case COL_UNRES_DL_DST: - case COL_DEF_NET_DST: - case COL_RES_NET_DST: - case COL_UNRES_NET_DST: - return (gdk_string_width(font, "00000000.000000000000")); /* IPX-style */ - break; - case COL_DEF_SRC_PORT: - case COL_RES_SRC_PORT: - case COL_UNRES_SRC_PORT: - case COL_DEF_DST_PORT: - case COL_RES_DST_PORT: - case COL_UNRES_DST_PORT: - return (gdk_string_width(font, "0") * 6); - break; - case COL_PROTOCOL: - return (gdk_string_width(font, "NBNS (UDP)")); - break; - default: /* COL_INFO */ - return (gdk_string_width(font, "Source port: kerberos-master " - "Destination port: kerberos-master")); - break; - } -} - #define TIME_DEF 0 #define TIME_REL 1 #define TIME_ABS 2 @@ -1,7 +1,7 @@ /* column.h * Definitions for column handling routines * - * $Id: column.h,v 1.1 1998/11/17 04:28:41 gerald Exp $ + * $Id: column.h,v 1.2 1999/06/19 03:14:31 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -35,7 +35,6 @@ gint get_column_format(gint); gchar *get_column_title(gint); gchar *col_format_to_pref_str(); void get_column_format_matches(gboolean *, gint); -gint get_column_width(gint format, GdkFont *font); GtkWidget *column_prefs_show(); void column_prefs_ok(GtkWidget *); void column_prefs_save(GtkWidget *); @@ -1,7 +1,7 @@ /* display.c * Routines for packet display windows * - * $Id: display.c,v 1.2 1999/06/19 01:47:43 guy Exp $ + * $Id: display.c,v 1.3 1999/06/19 03:14:29 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -60,7 +60,6 @@ #endif #include "timestamp.h" -#include "column.h" #include "packet.h" #include "file.h" #include "display.h" @@ -90,7 +89,7 @@ display_opt_cb(GtkWidget *w, gpointer d) { gtk_widget_show(main_vb); button = gtk_radio_button_new_with_label(NULL, "Time of day"); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), + gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), (timestamp_type == ABSOLUTE)); gtk_object_set_data(GTK_OBJECT(display_opt_w), E_DISPLAY_TIME_ABS_KEY, button); @@ -100,7 +99,7 @@ display_opt_cb(GtkWidget *w, gpointer d) { button = gtk_radio_button_new_with_label( gtk_radio_button_group(GTK_RADIO_BUTTON(button)), "Seconds since beginning of capture"); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), + gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), (timestamp_type == RELATIVE)); gtk_object_set_data(GTK_OBJECT(display_opt_w), E_DISPLAY_TIME_REL_KEY, button); @@ -110,7 +109,7 @@ display_opt_cb(GtkWidget *w, gpointer d) { button = gtk_radio_button_new_with_label( gtk_radio_button_group(GTK_RADIO_BUTTON(button)), "Seconds since previous frame"); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), + gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), (timestamp_type == DELTA)); gtk_object_set_data(GTK_OBJECT(display_opt_w), E_DISPLAY_TIME_DELTA_KEY, button); @@ -145,9 +144,6 @@ display_opt_cb(GtkWidget *w, gpointer d) { static void display_opt_ok_cb(GtkWidget *w, gpointer data) { GtkWidget *button; - GtkStyle *pl_style; - int i; - gint col_fmt; #ifdef GTK_HAVE_FEATURES_1_1_0 data = w; @@ -170,18 +166,6 @@ display_opt_ok_cb(GtkWidget *w, gpointer data) { gtk_widget_destroy(GTK_WIDGET(data)); - /* Recompute the column widths; we may have changed the format of the - time stamp column. */ - pl_style = gtk_widget_get_style(packet_list); - for (i = 0; i < cf.cinfo.num_cols; i++) { - col_fmt = get_column_format(i); - gtk_clist_set_column_width(GTK_CLIST(packet_list), i, - get_column_width(col_fmt, pl_style->font)); - if (col_fmt == COL_NUMBER) - gtk_clist_set_column_justification(GTK_CLIST(packet_list), i, - GTK_JUSTIFY_RIGHT); - } - redisplay_packets(&cf); } diff --git a/ethereal.c b/ethereal.c index 9e7ffc03c1..99b7630ff4 100644 --- a/ethereal.c +++ b/ethereal.c @@ -1,6 +1,6 @@ /* ethereal.c * - * $Id: ethereal.c,v 1.42 1999/06/19 01:14:49 guy Exp $ + * $Id: ethereal.c,v 1.43 1999/06/19 03:14:31 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -95,6 +95,7 @@ capture_file cf; GtkWidget *file_sel, *packet_list, *tree_view, *byte_view, *prog_bar, *info_bar; GdkFont *m_r_font, *m_b_font; +GtkStyle *pl_style; guint main_ctx, file_ctx; frame_data *fd; gint start_capture = 0; @@ -570,7 +571,6 @@ main(int argc, char *argv[]) GtkWidget *window, *main_vbox, *menubar, *u_pane, *l_pane, *bv_table, *bv_hscroll, *bv_vscroll, *stat_hbox, *tv_scrollw, *filter_bt, *filter_te; - GtkStyle *pl_style; #ifdef GTK_HAVE_FEATURES_1_1_0 GtkAccelGroup *accel; #else @@ -584,7 +584,6 @@ main(int argc, char *argv[]) gchar *rc_file, *cf_name = NULL; e_prefs *prefs; gint *col_fmt; - gchar **col_title; ethereal_path = argv[0]; @@ -616,8 +615,10 @@ main(int argc, char *argv[]) cf.snap = MAX_PACKET_SIZE; cf.count = 0; cf.cinfo.num_cols = prefs->num_cols; + cf.cinfo.col_title = (gchar **) g_malloc(sizeof(gchar *) * cf.cinfo.num_cols); cf.cinfo.fmt_matx = (gboolean **) g_malloc(sizeof(gboolean *) * cf.cinfo.num_cols); cf.cinfo.col_data = (gchar **) g_malloc(sizeof(gchar *) * cf.cinfo.num_cols); + cf.cinfo.col_width = (gint *) g_malloc(sizeof(gint) * cf.cinfo.num_cols); /* Assemble the compile-time options */ snprintf(comp_info_str, 256, @@ -728,15 +729,15 @@ main(int argc, char *argv[]) /* Build the column format array */ col_fmt = (gint *) g_malloc(sizeof(gint) * cf.cinfo.num_cols); - col_title = (gchar **) g_malloc(sizeof(gchar *) * cf.cinfo.num_cols); for (i = 0; i < cf.cinfo.num_cols; i++) { col_fmt[i] = get_column_format(i); - col_title[i] = g_strdup(get_column_title(i)); + cf.cinfo.col_title[i] = g_strdup(get_column_title(i)); cf.cinfo.fmt_matx[i] = (gboolean *) g_malloc0(sizeof(gboolean) * NUM_COL_FMTS); get_column_format_matches(cf.cinfo.fmt_matx[i], col_fmt[i]); cf.cinfo.col_data[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN); + cf.cinfo.col_width[i] = 0; } if (cf.snap < 1) @@ -798,7 +799,8 @@ main(int argc, char *argv[]) gtk_widget_show(l_pane); /* Packet list */ - packet_list = gtk_clist_new_with_titles(cf.cinfo.num_cols, col_title); + packet_list = gtk_clist_new_with_titles(cf.cinfo.num_cols, + cf.cinfo.col_title); gtk_clist_column_titles_passive(GTK_CLIST(packet_list)); #ifdef GTK_HAVE_FEATURES_1_1_4 packet_sw = gtk_scrolled_window_new(NULL, NULL); @@ -816,7 +818,7 @@ main(int argc, char *argv[]) GTK_SIGNAL_FUNC(packet_list_unselect_cb), NULL); for (i = 0; i < cf.cinfo.num_cols; i++) { gtk_clist_set_column_width(GTK_CLIST(packet_list), i, - get_column_width(get_column_format(i), pl_style->font)); + gdk_string_width(pl_style->font, cf.cinfo.col_title[i])); if (col_fmt[i] == COL_NUMBER) gtk_clist_set_column_justification(GTK_CLIST(packet_list), i, GTK_JUSTIFY_RIGHT); @@ -1,7 +1,7 @@ /* file.c * File I/O routines * - * $Id: file.c,v 1.29 1999/06/19 01:14:50 guy Exp $ + * $Id: file.c,v 1.30 1999/06/19 03:14:29 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -62,6 +62,7 @@ #endif #include "ethereal.h" +#include "column.h" #include "menu.h" #include "packet.h" #include "file.h" @@ -72,6 +73,7 @@ #define TAIL_TIMEOUT 2000 /* msec */ extern GtkWidget *packet_list, *prog_bar, *info_bar, *byte_view, *tree_view; +extern GtkStyle *pl_style; extern guint file_ctx; extern int sync_mode; extern int sync_pipe[]; @@ -89,6 +91,9 @@ static void pcap_dispatch_cb(u_char *, const struct pcap_pkthdr *, const u_char *); #endif +static void init_col_widths(capture_file *); +static void set_col_widths(capture_file *); + static gint tail_timeout_cb(gpointer); int @@ -273,6 +278,7 @@ load_cap_file(char *fname, capture_file *cf) { if ((err == 0) && (cf->cd_t != CD_UNKNOWN)) { #endif gtk_clist_freeze(GTK_CLIST(packet_list)); + init_col_widths(cf); #ifdef WITH_WIRETAP wtap_loop(cf->wth, 0, wtap_dispatch_cb, (u_char *) cf); wtap_close(cf->wth); @@ -283,6 +289,8 @@ load_cap_file(char *fname, capture_file *cf) { cf->pfh = NULL; #endif cf->fh = fopen(fname, "r"); + + set_col_widths(cf); gtk_clist_thaw(GTK_CLIST(packet_list)); } @@ -346,11 +354,14 @@ cap_file_input_cb (gpointer data, gint source, GdkInputCondition condition) { /* process data until end of file and stop capture (restore menu items) */ gtk_clist_freeze(GTK_CLIST(packet_list)); + init_col_widths(cf); #ifdef WITH_WIRETAP wtap_loop(cf->wth, 0, wtap_dispatch_cb, (u_char *) cf); #else pcap_loop(cf->pfh, 0, pcap_dispatch_cb, (u_char *) cf); #endif + + set_col_widths(cf); gtk_clist_thaw(GTK_CLIST(packet_list)); #ifdef WITH_WIRETAP @@ -380,11 +391,14 @@ cap_file_input_cb (gpointer data, gint source, GdkInputCondition condition) { } gtk_clist_freeze(GTK_CLIST(packet_list)); + init_col_widths(cf); #ifdef WITH_WIRETAP wtap_loop(cf->wth, 0, wtap_dispatch_cb, (u_char *) cf); #else pcap_loop(cf->pfh, 0, pcap_dispatch_cb, (u_char *) cf); #endif + + set_col_widths(cf); gtk_clist_thaw(GTK_CLIST(packet_list)); /* restore pipe handler */ @@ -409,11 +423,14 @@ tail_timeout_cb(gpointer data) { gtk_input_remove(cap_input_id); gtk_clist_freeze(GTK_CLIST(packet_list)); + init_col_widths(cf); #ifdef WITH_WIRETAP wtap_loop(cf->wth, 0, wtap_dispatch_cb, (u_char *) cf); #else pcap_loop(cf->pfh, 0, pcap_dispatch_cb, (u_char *) cf); #endif + + set_col_widths(cf); gtk_clist_thaw(GTK_CLIST(packet_list)); cap_input_id = gtk_input_add_full (sync_pipe[0], @@ -486,7 +503,7 @@ tail_cap_file(char *fname, capture_file *cf) { static void add_packet_to_packet_list(frame_data *fdata, capture_file *cf, const u_char *buf) { - gint i, row; + gint i, row, col_width; /* If we don't have the time stamp of the first packet, it's because this is the first packet. Save the time stamp of this packet as the time @@ -531,6 +548,11 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf, const u_char *buf if (check_col(fdata, COL_NUMBER)) col_add_fstr(fdata, COL_NUMBER, "%d", cf->count); dissect_packet(buf, fdata, NULL); + for (i = 0; i < fdata->cinfo->num_cols; i++) { + col_width = gdk_string_width(pl_style->font, fdata->cinfo->col_data[i]); + if (col_width > fdata->cinfo->col_width[i]) + fdata->cinfo->col_width[i] = col_width; + } row = gtk_clist_append(GTK_CLIST(packet_list), fdata->cinfo->col_data); fdata->cinfo = NULL; } @@ -594,6 +616,9 @@ redisplay_packets(capture_file *cf) /* Clear it out. */ gtk_clist_clear(GTK_CLIST(packet_list)); + /* Zero out the column widths. */ + init_col_widths(cf); + /* * Iterate through the list of packets, calling a routine * to run the filter on the packet, see if it matches, and @@ -606,10 +631,44 @@ redisplay_packets(capture_file *cf) cf->count = 0; g_list_foreach(cf->plist, redisplay_packets_cb, cf); + /* Set the column widths. */ + set_col_widths(cf); + /* Unfreeze the packet list. */ gtk_clist_thaw(GTK_CLIST(packet_list)); } +/* Initialize the maximum widths of the columns to the widths of their + titles. */ +static void +init_col_widths(capture_file *cf) +{ + int i; + + /* XXX - this should use the column *title* font, not the font for + the items in the list. + But how do you get that font? We set the font for the packet list + in "main()", but why does that affect only the list entries, not + the title? Is it because it's not supposed to affect the title, + or is it because we did a "gtk_clist_new_with_titles()" and + that put the titles in *before* we changed the font? */ + for (i = 0; i < cf->cinfo.num_cols; i++) + cf->cinfo.col_width[i] = gdk_string_width(pl_style->font, + cf->cinfo.col_title[i]); +} + +/* Set the widths of the columns to the maximum widths we found. */ +static void +set_col_widths(capture_file *cf) +{ + int i; + + for (i = 0; i < cf->cinfo.num_cols; i++) { + gtk_clist_set_column_width(GTK_CLIST(packet_list), i, + cf->cinfo.col_width[i]); + } +} + /* Tries to mv a file. If unsuccessful, tries to cp the file. * Returns 0 on failure to do either, 1 on success of either */ @@ -767,4 +826,3 @@ file_write_error_message(int err) } return errmsg; } - @@ -1,7 +1,7 @@ /* packet.h * Definitions for packet disassembly structures and routines * - * $Id: packet.h,v 1.60 1999/06/14 20:30:06 gram Exp $ + * $Id: packet.h,v 1.61 1999/06/19 03:14:32 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -74,8 +74,10 @@ typedef struct _column_info { gint num_cols; /* Number of columns */ + gchar **col_title;/* Column title */ gboolean **fmt_matx; /* Specifies which formats apply to a column */ gchar **col_data; /* Column data */ + gint *col_width; /* Column width */ } column_info; #define COL_MAX_LEN 256 |