diff options
author | Guy Harris <guy@alum.mit.edu> | 2000-11-21 23:54:10 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2000-11-21 23:54:10 +0000 |
commit | fcd119d834023122b8c1f37586acb2510743086f (patch) | |
tree | ac14477f29c8c86817ad58caf63b37cb7c5895b4 | |
parent | f8d8ac9df63e9566582aca55fd658252475bf5b2 (diff) |
Add a "color.h" file that declares a nominally-toolkit-independent
"color_t" structure to store color values (although currently it has all
the same fields that a GdkColor has; its currently advantage is that you
don't have to include any GTK/GDK stuff to declare it).
Add routines in the "gtk" directory to convert between "color_t" and
GdkColor values.
Define, in "prefs.h", all colors as "color_t" values rather than
GdkColor values. "prefs.h" now no longer needs to include <gtk/gtk.h>,
so don't include it.
svn path=/trunk/; revision=2692
-rw-r--r-- | Makefile.am | 3 | ||||
-rw-r--r-- | color.h | 45 | ||||
-rw-r--r-- | file.c | 21 | ||||
-rw-r--r-- | gtk/Makefile.am | 4 | ||||
-rw-r--r-- | gtk/Makefile.nmake | 3 | ||||
-rw-r--r-- | gtk/color_utils.c | 53 | ||||
-rw-r--r-- | gtk/color_utils.h | 33 | ||||
-rw-r--r-- | gtk/follow_dlg.c | 19 | ||||
-rw-r--r-- | gtk/gui_prefs.c | 16 | ||||
-rw-r--r-- | gtk/main.c | 19 | ||||
-rw-r--r-- | gtk/print_dlg.c | 4 | ||||
-rw-r--r-- | gtk/stream_prefs.c | 30 | ||||
-rw-r--r-- | prefs.h | 16 |
13 files changed, 207 insertions, 59 deletions
diff --git a/Makefile.am b/Makefile.am index 01b824a725..c6383e4a42 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,7 +1,7 @@ # Makefile.am # Automake file for Ethereal # -# $Id: Makefile.am,v 1.250 2000/11/19 04:14:26 guy Exp $ +# $Id: Makefile.am,v 1.251 2000/11/21 23:54:07 guy Exp $ # # Ethereal - Network traffic analyzer # By Gerald Combs <gerald@zing.org> @@ -274,6 +274,7 @@ ETHEREAL_COMMON_SOURCES = \ asn1.h \ column.c \ column.h \ + color.h \ etypes.h \ follow.c \ follow.h \ diff --git a/color.h b/color.h new file mode 100644 index 0000000000..56e012669d --- /dev/null +++ b/color.h @@ -0,0 +1,45 @@ +/* color.h + * Definitions for "toolkit-independent" colors + * + * $Id: color.h,v 1.1 2000/11/21 23:54:08 guy Exp $ + * + * Ethereal - Network traffic analyzer + * By Gerald Combs <gerald@zing.org> + * Copyright 1998 Gerald Combs + * + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __COLOR_H__ +#define __COLOR_H__ + +/* + * Data structure holding RGB value for a color. + * + * XXX - yes, I know, there's a "pixel" value in there as well; for + * now, it's intended to look just like a GdkColor but not to require + * that any GTK+ header files be included in order to use it. + * The way we handle colors needs to be cleaned up somewhat, in order + * to keep toolkit-specific stuff separate from toolkit-independent stuff. + */ +typedef struct { + guint32 pixel; + guint16 red; + guint16 green; + guint16 blue; +} color_t; + +#endif @@ -1,7 +1,7 @@ /* file.c * File I/O routines * - * $Id: file.c,v 1.226 2000/11/19 08:53:53 guy Exp $ + * $Id: file.c,v 1.227 2000/11/21 23:54:08 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -72,6 +72,8 @@ #include <epan.h> #include "gtk/main.h" +#include "color.h" +#include "gtk/color_utils.h" #include "column.h" #include "packet.h" #include "print.h" @@ -606,6 +608,7 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf, gint i, row; proto_tree *protocol_tree = NULL; epan_dissect_t *edt; + GdkColor fg, bg; /* We don't yet have a color filter to apply. */ args.colorf = NULL; @@ -734,17 +737,17 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf, gtk_clist_set_row_data(GTK_CLIST(packet_list), row, fdata); if (fdata->flags.marked) { - gtk_clist_set_background(GTK_CLIST(packet_list), row, &prefs.gui_marked_bg); - gtk_clist_set_foreground(GTK_CLIST(packet_list), row, &prefs.gui_marked_fg); + color_t_to_gdkcolor(&bg, &prefs.gui_marked_bg); + color_t_to_gdkcolor(&fg, &prefs.gui_marked_fg); } else if (filter_list != NULL && (args.colorf != NULL)) { - gtk_clist_set_background(GTK_CLIST(packet_list), row, - &args.colorf->bg_color); - gtk_clist_set_foreground(GTK_CLIST(packet_list), row, - &args.colorf->fg_color); + bg = args.colorf->bg_color; + fg = args.colorf->fg_color; } else { - gtk_clist_set_background(GTK_CLIST(packet_list), row, &WHITE); - gtk_clist_set_foreground(GTK_CLIST(packet_list), row, &BLACK); + bg = WHITE; + fg = BLACK; } + gtk_clist_set_background(GTK_CLIST(packet_list), row, &bg); + gtk_clist_set_foreground(GTK_CLIST(packet_list), row, &fg); } else { /* This frame didn't pass the display filter, so it's not being added to the clist, and thus has no row. */ diff --git a/gtk/Makefile.am b/gtk/Makefile.am index 9a2b245828..f60afbaec4 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -1,7 +1,7 @@ # Makefile.am # Automake file for the GTK interface routines for Ethereal # -# $Id: Makefile.am,v 1.30 2000/08/13 14:03:49 deniel Exp $ +# $Id: Makefile.am,v 1.31 2000/11/21 23:54:09 guy Exp $ # # Ethereal - Network traffic analyzer # By Gerald Combs <gerald@zing.org> @@ -35,6 +35,8 @@ libui_a_SOURCES = \ color_dlg.h \ colors.c \ colors.h \ + color_utils.c \ + color_utils.h \ column_prefs.c \ column_prefs.h \ display_opts.c \ diff --git a/gtk/Makefile.nmake b/gtk/Makefile.nmake index 939b8589b6..fe9c2397a9 100644 --- a/gtk/Makefile.nmake +++ b/gtk/Makefile.nmake @@ -15,8 +15,9 @@ CFLAGS=/MT /DHAVE_CONFIG_H /I.. /I../epan /I../wiretap \ # some functions that have disappeared in gtk+-1.3. I might # get around to #ifdef'ing them out in our gtkclist.c. OBJECTS=capture_dlg.obj \ - colors.obj \ color_dlg.obj \ + colors.obj \ + color_utils.obj \ column_prefs.obj \ display_opts.obj \ dlg_utils.obj \ diff --git a/gtk/color_utils.c b/gtk/color_utils.c new file mode 100644 index 0000000000..055a9356aa --- /dev/null +++ b/gtk/color_utils.c @@ -0,0 +1,53 @@ +/* color_utils.c + * Utilities for converting between "toolkit-independent" and GDK + * notions of color + * + * $Id: color_utils.c,v 1.1 2000/11/21 23:54:09 guy Exp $ + * + * Ethereal - Network traffic analyzer + * By Gerald Combs <gerald@zing.org> + * Copyright 1998 Gerald Combs + * + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <glib.h> + +#include <gtk/gtk.h> + +#include "prefs.h" /* to declare "color_t" */ + +void +color_t_to_gdkcolor(GdkColor *target, color_t *source) +{ + target->pixel = source->pixel; + target->red = source->red; + target->green = source->green; + target->blue = source->blue; +} + +void +gdkcolor_to_color_t(color_t *target, GdkColor *source) +{ + target->pixel = source->pixel; + target->red = source->red; + target->green = source->green; + target->blue = source->blue; +} diff --git a/gtk/color_utils.h b/gtk/color_utils.h new file mode 100644 index 0000000000..e25fbc5549 --- /dev/null +++ b/gtk/color_utils.h @@ -0,0 +1,33 @@ +/* color_utils.h + * Declarations of utilities for converting between "toolkit-independent" + * and GDK notions of color + * + * $Id: color_utils.h,v 1.1 2000/11/21 23:54:09 guy Exp $ + * + * Ethereal - Network traffic analyzer + * By Gerald Combs <gerald@zing.org> + * Copyright 1998 Gerald Combs + * + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __COLOR_UTILS_H__ +#define __COLOR_UTILS_H__ + +void color_t_to_gdkcolor(GdkColor *, color_t *); +void gdkcolor_to_color_t(color_t *, GdkColor *); + +#endif diff --git a/gtk/follow_dlg.c b/gtk/follow_dlg.c index 6518a05021..de55db53f5 100644 --- a/gtk/follow_dlg.c +++ b/gtk/follow_dlg.c @@ -1,6 +1,6 @@ /* follow_dlg.c * - * $Id: follow_dlg.c,v 1.10 2000/09/12 06:28:02 guy Exp $ + * $Id: follow_dlg.c,v 1.11 2000/11/21 23:54:09 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -54,6 +54,8 @@ # include "snprintf.h" #endif +#include "color.h" +#include "color_utils.h" #include "file.h" #include "follow_dlg.h" #include "follow.h" @@ -635,13 +637,16 @@ follow_add_to_gtk_text(char *buffer, int nchars, gboolean is_server, void *arg) { GtkWidget *text = arg; + GdkColor fg, bg; - if (is_server) - gtk_text_insert(GTK_TEXT(text), m_r_font, &prefs.st_server_fg, - &prefs.st_server_bg, buffer, nchars); - else - gtk_text_insert(GTK_TEXT(text), m_r_font, &prefs.st_client_fg, - &prefs.st_client_bg, buffer, nchars); + if (is_server) { + color_t_to_gdkcolor(&fg, &prefs.st_server_fg); + color_t_to_gdkcolor(&bg, &prefs.st_server_bg); + } else { + color_t_to_gdkcolor(&fg, &prefs.st_client_fg); + color_t_to_gdkcolor(&bg, &prefs.st_client_bg); + } + gtk_text_insert(GTK_TEXT(text), m_r_font, &fg, &bg, buffer, nchars); } static void diff --git a/gtk/gui_prefs.c b/gtk/gui_prefs.c index 2a8edf1c15..be8dba6ba4 100644 --- a/gtk/gui_prefs.c +++ b/gtk/gui_prefs.c @@ -1,7 +1,7 @@ /* gui_prefs.c * Dialog box for GUI preferences * - * $Id: gui_prefs.c,v 1.23 2000/11/18 21:41:38 guy Exp $ + * $Id: gui_prefs.c,v 1.24 2000/11/21 23:54:09 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -30,6 +30,8 @@ #include <errno.h> #include <gtk/gtk.h> +#include "color.h" +#include "color_utils.h" #include "globals.h" #include "gui_prefs.h" #include "gtkglobals.h" @@ -559,8 +561,8 @@ color_browse_cb(GtkWidget *w, gpointer data) return; } - color_info[MFG_IDX].color = prefs.gui_marked_fg; - color_info[MBG_IDX].color = prefs.gui_marked_bg; + color_t_to_gdkcolor(&color_info[MFG_IDX].color, &prefs.gui_marked_fg); + color_t_to_gdkcolor(&color_info[MBG_IDX].color, &prefs.gui_marked_bg); curcolor = &color_info[MFG_IDX].color; scolor[CS_RED] = (gdouble) (curcolor->red) / 65535.0; scolor[CS_GREEN] = (gdouble) (curcolor->green) / 65535.0; @@ -713,8 +715,8 @@ static void color_cancel_cb(GtkWidget *w, gpointer data) { /* Revert the colors to the current preference settings. */ - color_info[MFG_IDX].color = prefs.gui_marked_fg; - color_info[MBG_IDX].color = prefs.gui_marked_bg; + color_t_to_gdkcolor(&color_info[MFG_IDX].color, &prefs.gui_marked_fg); + color_t_to_gdkcolor(&color_info[MBG_IDX].color, &prefs.gui_marked_bg); gtk_widget_hide(GTK_WIDGET(data)); gtk_widget_destroy(GTK_WIDGET(data)); } @@ -745,6 +747,6 @@ color_destroy_cb(GtkWidget *w, gpointer data) static void fetch_colors(void) { - prefs.gui_marked_fg = color_info[MFG_IDX].color; - prefs.gui_marked_bg = color_info[MBG_IDX].color; + gdkcolor_to_color_t(&prefs.gui_marked_fg, &color_info[MFG_IDX].color); + gdkcolor_to_color_t(&prefs.gui_marked_bg, &color_info[MBG_IDX].color); } diff --git a/gtk/main.c b/gtk/main.c index e14afd5904..c11008c4de 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -1,6 +1,6 @@ /* main.c * - * $Id: main.c,v 1.164 2000/11/19 08:54:37 guy Exp $ + * $Id: main.c,v 1.165 2000/11/21 23:54:09 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -105,6 +105,8 @@ #include "file.h" #include "menu.h" #include "../menu.h" +#include "color.h" +#include "color_utils.h" #include "filter_prefs.h" #include "prefs_dlg.h" #include "column.h" @@ -463,12 +465,19 @@ packet_list_click_column_cb(GtkCList *clist, gint column, gpointer data) /* mark packets */ static void set_frame_mark(gboolean set, frame_data *frame, gint row) { + GdkColor fg, bg; + if (frame == NULL || row == -1) return; frame->flags.marked = set; - gtk_clist_set_background(GTK_CLIST(packet_list), row, - (set) ? &prefs.gui_marked_bg : &WHITE); - gtk_clist_set_foreground(GTK_CLIST(packet_list), row, - (set) ? &prefs.gui_marked_fg : &BLACK); + if (set) { + color_t_to_gdkcolor(&fg, &prefs.gui_marked_fg); + color_t_to_gdkcolor(&bg, &prefs.gui_marked_bg); + } else { + fg = BLACK; + bg = WHITE; + } + gtk_clist_set_background(GTK_CLIST(packet_list), row, &bg); + gtk_clist_set_foreground(GTK_CLIST(packet_list), row, &fg); } static void diff --git a/gtk/print_dlg.c b/gtk/print_dlg.c index 6c3b05107e..5ef506cf67 100644 --- a/gtk/print_dlg.c +++ b/gtk/print_dlg.c @@ -1,7 +1,7 @@ /* print_dlg.c * Dialog boxes for printing * - * $Id: print_dlg.c,v 1.21 2000/08/23 06:56:20 guy Exp $ + * $Id: print_dlg.c,v 1.22 2000/11/21 23:54:10 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -29,6 +29,8 @@ #include <errno.h> +#include <gtk/gtk.h> + #include "globals.h" #include "keys.h" #include "print.h" diff --git a/gtk/stream_prefs.c b/gtk/stream_prefs.c index 544bcded72..6ada92b862 100644 --- a/gtk/stream_prefs.c +++ b/gtk/stream_prefs.c @@ -1,7 +1,7 @@ /* stream_prefs.c * Dialog boxes for preferences for the stream window * - * $Id: stream_prefs.c,v 1.6 2000/10/20 04:26:40 gram Exp $ + * $Id: stream_prefs.c,v 1.7 2000/11/21 23:54:10 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -30,6 +30,8 @@ #include <errno.h> #include <gtk/gtk.h> +#include "color.h" +#include "color_utils.h" #include "globals.h" #include "stream_prefs.h" #include "keys.h" @@ -39,7 +41,6 @@ static void update_text_color(GtkWidget *, gpointer); static void update_current_color(GtkWidget *, gpointer); -static void copy_color_vals(GdkColor *, GdkColor *); static GdkColor tcolors[4], *curcolor = NULL; @@ -67,10 +68,10 @@ stream_prefs_show() int mcount = sizeof(mt) / sizeof (gchar *); gdouble scolor[4]; - copy_color_vals(&tcolors[CFG_IDX], &prefs.st_client_fg); - copy_color_vals(&tcolors[CBG_IDX], &prefs.st_client_bg); - copy_color_vals(&tcolors[SFG_IDX], &prefs.st_server_fg); - copy_color_vals(&tcolors[SBG_IDX], &prefs.st_server_bg); + color_t_to_gdkcolor(&tcolors[CFG_IDX], &prefs.st_client_fg); + color_t_to_gdkcolor(&tcolors[CBG_IDX], &prefs.st_client_bg); + color_t_to_gdkcolor(&tcolors[SFG_IDX], &prefs.st_server_fg); + color_t_to_gdkcolor(&tcolors[SBG_IDX], &prefs.st_server_bg); curcolor = &tcolors[CFG_IDX]; @@ -174,22 +175,13 @@ update_current_color(GtkWidget *w, gpointer data) gtk_color_selection_set_color(colorsel, &scolor[CS_RED]); } -static void -copy_color_vals(GdkColor *target, GdkColor *source) -{ - target->pixel = source->pixel; - target->red = source->red; - target->green = source->green; - target->blue = source->blue; -} - void stream_prefs_fetch(GtkWidget *w) { - copy_color_vals(&prefs.st_client_fg, &tcolors[CFG_IDX]); - copy_color_vals(&prefs.st_client_bg, &tcolors[CBG_IDX]); - copy_color_vals(&prefs.st_server_fg, &tcolors[SFG_IDX]); - copy_color_vals(&prefs.st_server_bg, &tcolors[SBG_IDX]); + gdkcolor_to_color_t(&prefs.st_client_fg, &tcolors[CFG_IDX]); + gdkcolor_to_color_t(&prefs.st_client_bg, &tcolors[CBG_IDX]); + gdkcolor_to_color_t(&prefs.st_server_fg, &tcolors[SFG_IDX]); + gdkcolor_to_color_t(&prefs.st_server_bg, &tcolors[SBG_IDX]); } /* XXX - "gui_prefs_apply()" handles this, as the "Follow TCP Stream" @@ -1,7 +1,7 @@ /* prefs.h * Definitions for preference handling routines * - * $Id: prefs.h,v 1.25 2000/11/18 21:41:36 guy Exp $ + * $Id: prefs.h,v 1.26 2000/11/21 23:54:08 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -26,13 +26,13 @@ #ifndef __PREFS_H__ #define __PREFS_H__ +#include <glib.h> + +#include "color.h" + #define PR_DEST_CMD 0 #define PR_DEST_FILE 1 -#ifndef __GTK_H__ -#include <gtk/gtk.h> -#endif - typedef struct _e_prefs { gint pr_format; gint pr_dest; @@ -40,7 +40,7 @@ typedef struct _e_prefs { gchar *pr_cmd; GList *col_list; gint num_cols; - GdkColor st_client_fg, st_client_bg, st_server_fg, st_server_bg; + color_t st_client_fg, st_client_bg, st_server_fg, st_server_bg; gboolean gui_scrollbar_on_right; gboolean gui_plist_sel_browse; gboolean gui_ptree_sel_browse; @@ -48,8 +48,8 @@ typedef struct _e_prefs { gint gui_ptree_expander_style; gboolean gui_hex_dump_highlight_style; gchar *gui_font_name; - GdkColor gui_marked_fg; - GdkColor gui_marked_bg; + color_t gui_marked_fg; + color_t gui_marked_bg; } e_prefs; extern e_prefs prefs; |