2 * Toolkit-dependent implementations of routines to handle colors.
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
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.
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.
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.
34 #include "../simple_dialog.h"
36 #include "ui/gtk/color_utils.h"
37 #include "ui/gtk/gtkglobals.h"
39 static GdkColormap* sys_cmap;
40 static GdkColormap* our_cmap = NULL;
42 GdkColor WHITE = { 0, 65535, 65535, 65535 };
43 /*GdkColor LTGREY = { 0, 57343, 57343, 57343 };*/
44 GdkColor BLACK = { 0, 0, 0, 0 };
47 * Initialize a color with R, G, and B values, including any toolkit-dependent
48 * work that needs to be done.
49 * Returns TRUE if it succeeds, FALSE if it fails.
52 initialize_color(color_t *color, guint16 red, guint16 green, guint16 blue)
58 gdk_color.green = green;
59 gdk_color.blue = blue;
61 if (!get_color(&gdk_color))
64 gdkcolor_to_color_t(color, &gdk_color);
68 /* Initialize the colors */
73 gboolean got_white, got_black;
75 sys_cmap = gdk_colormap_get_system();
77 /* Allocate "constant" colors. */
78 got_white = get_color(&WHITE);
79 got_black = get_color(&BLACK);
83 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
84 "Could not allocate colors black or white.");
86 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
87 "Could not allocate color white.");
90 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
91 "Could not allocate color black.");
97 /* allocate a color from the color map */
99 get_color(GdkColor *new_color)
104 if (!gdk_colormap_alloc_color (sys_cmap, new_color, FALSE,
106 pv = gdk_visual_get_best();
107 if (!(our_cmap = gdk_colormap_new(pv, TRUE))) {
108 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
109 "Could not create new colormap");
114 return (gdk_colormap_alloc_color(our_cmap, new_color, FALSE, TRUE));
118 color_t_to_gdkcolor(GdkColor *target, const color_t *source)
120 target->pixel = source->pixel;
121 target->red = source->red;
122 target->green = source->green;
123 target->blue = source->blue;
125 #if GTK_CHECK_VERSION(3,0,0)
127 color_t_to_gdkRGBAcolor(GdkRGBA *target, const color_t *source)
130 target->red = source->red / 65535.0;
131 target->green = source->green / 65535.0;
132 target->blue = source->blue / 65535.0;
136 gdkcolor_to_color_t(color_t *target, const GdkColor *source)
138 target->pixel = source->pixel;
139 target->red = source->red;
140 target->green = source->green;
141 target->blue = source->blue;
143 #if GTK_CHECK_VERSION(3,0,0)
145 gdkRGBAcolor_to_color_t(color_t *target, const GdkRGBA *source)
148 target->red = source->red*65535;
149 target->green = source->green*65535;
150 target->blue = source->blue*65535;