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
This commit is contained in:
Guy Harris 2000-11-21 23:54:10 +00:00
parent f8d8ac9df6
commit fcd119d834
13 changed files with 207 additions and 59 deletions

View File

@ -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 \

45
color.h Normal file
View File

@ -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

21
file.c
View File

@ -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. */

View File

@ -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 \

View File

@ -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 \

53
gtk/color_utils.c Normal file
View File

@ -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;
}

33
gtk/color_utils.h Normal file
View File

@ -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

View File

@ -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

View File

@ -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);
}

View File

@ -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

View File

@ -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"

View File

@ -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"

16
prefs.h
View File

@ -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;