1999-08-24 16:27:23 +00:00
|
|
|
/* colors.c
|
2003-01-08 01:59:42 +00:00
|
|
|
* Routines for colors
|
1999-08-24 16:27:23 +00:00
|
|
|
*
|
2003-01-08 01:59:42 +00:00
|
|
|
* $Id: colors.c,v 1.27 2003/01/08 01:59:42 guy Exp $
|
1999-08-24 16:27:23 +00:00
|
|
|
*
|
|
|
|
* Ethereal - Network traffic analyzer
|
2001-10-21 21:48:00 +00:00
|
|
|
* By Gerald Combs <gerald@ethereal.com>
|
1999-08-24 16:27:23 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
1999-08-24 16:27:23 +00:00
|
|
|
* 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.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
1999-08-24 16:27:23 +00:00
|
|
|
* 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.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
1999-08-24 16:27:23 +00:00
|
|
|
* 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 <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "colors.h"
|
2000-01-03 06:59:25 +00:00
|
|
|
#include "simple_dialog.h"
|
2002-11-03 17:38:45 +00:00
|
|
|
#include "gtkglobals.h"
|
1999-08-24 16:27:23 +00:00
|
|
|
|
Make a whole pile of routines private to "colors.c" static, and remove
their declarations from "colors.h". Do the same with some variables -
and remove the ones that aren't used any more.
Make some name changes suggested in the comments in "colors.c".
Make "color_delete_cb()" take, as the user-supplied argument,
"cf->colors", just as "color_new_cb()" does, and make it use its
argument to find the color filter, just as "color_new_cb()" does, rather
than using "cf.colors".
When there are no colors in the list, make the "Edit" button
insensitive; make it sensitive if there are any colors in the list, so
that we don't crash if you press "Edit" when there are no colors in the
list.
Make "remember_selected_row()" take, as the user-supplied argument,
"cf->colors", rather than "cf" - it needs only the color filter, not the
entire "capture_file" structure.
When using "gtk_clist_select_row()" to forcibly select a row, pass -1 as
the column number, to indicate that we don't care which column is
selected.
Fix some typos in function names.
svn path=/trunk/; revision=1161
1999-11-30 04:23:06 +00:00
|
|
|
static GdkColormap* sys_cmap;
|
|
|
|
static GdkColormap* our_cmap = NULL;
|
1999-08-24 16:27:23 +00:00
|
|
|
|
1999-10-05 04:34:00 +00:00
|
|
|
GdkColor WHITE = { 0, 65535, 65535, 65535 };
|
|
|
|
GdkColor BLACK = { 0, 0, 0, 0 };
|
1999-08-24 16:27:23 +00:00
|
|
|
|
2003-01-08 01:59:42 +00:00
|
|
|
/* Initialize the colors */
|
2002-05-27 22:00:37 +00:00
|
|
|
void
|
2003-01-08 01:59:42 +00:00
|
|
|
colors_init(void)
|
1999-08-24 16:27:23 +00:00
|
|
|
{
|
2002-01-08 21:35:17 +00:00
|
|
|
gboolean got_white, got_black;
|
|
|
|
|
|
|
|
sys_cmap = gdk_colormap_get_system();
|
|
|
|
|
|
|
|
/* Allocate "constant" colors. */
|
|
|
|
got_white = get_color(&WHITE);
|
|
|
|
got_black = get_color(&BLACK);
|
|
|
|
|
|
|
|
/* Got milk? */
|
|
|
|
if (!got_white) {
|
|
|
|
if (!got_black)
|
|
|
|
simple_dialog(ESD_TYPE_WARN, NULL,
|
|
|
|
"Could not allocate colors black or white.");
|
|
|
|
else
|
|
|
|
simple_dialog(ESD_TYPE_WARN, NULL,
|
|
|
|
"Could not allocate color white.");
|
|
|
|
} else {
|
|
|
|
if (!got_black)
|
|
|
|
simple_dialog(ESD_TYPE_WARN, NULL,
|
|
|
|
"Could not allocate color black.");
|
|
|
|
}
|
1999-08-24 16:27:23 +00:00
|
|
|
}
|
|
|
|
|
2001-12-02 00:16:02 +00:00
|
|
|
/* allocate a color from the color map */
|
2000-02-12 08:31:49 +00:00
|
|
|
gboolean
|
2003-01-08 01:59:42 +00:00
|
|
|
get_color(GdkColor *new_color)
|
Make a whole pile of routines private to "colors.c" static, and remove
their declarations from "colors.h". Do the same with some variables -
and remove the ones that aren't used any more.
Make some name changes suggested in the comments in "colors.c".
Make "color_delete_cb()" take, as the user-supplied argument,
"cf->colors", just as "color_new_cb()" does, and make it use its
argument to find the color filter, just as "color_new_cb()" does, rather
than using "cf.colors".
When there are no colors in the list, make the "Edit" button
insensitive; make it sensitive if there are any colors in the list, so
that we don't crash if you press "Edit" when there are no colors in the
list.
Make "remember_selected_row()" take, as the user-supplied argument,
"cf->colors", rather than "cf" - it needs only the color filter, not the
entire "capture_file" structure.
When using "gtk_clist_select_row()" to forcibly select a row, pass -1 as
the column number, to indicate that we don't care which column is
selected.
Fix some typos in function names.
svn path=/trunk/; revision=1161
1999-11-30 04:23:06 +00:00
|
|
|
{
|
2003-01-08 01:59:42 +00:00
|
|
|
GdkVisual *pv;
|
|
|
|
|
|
|
|
if (!our_cmap) {
|
|
|
|
if (!gdk_colormap_alloc_color (sys_cmap, new_color, FALSE,
|
|
|
|
TRUE)) {
|
|
|
|
pv = gdk_visual_get_best();
|
|
|
|
if (!(our_cmap = gdk_colormap_new(pv, TRUE))) {
|
|
|
|
simple_dialog(ESD_TYPE_WARN, NULL,
|
|
|
|
"Could not create new colormap");
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
return (gdk_colormap_alloc_color(our_cmap, new_color, FALSE, TRUE));
|
1999-10-07 22:50:45 +00:00
|
|
|
}
|