1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * e-colors.c - General color allocation utilities
4 * Copyright 2000, 2001, Ximian, Inc.
7 * Miguel de Icaza (miguel@kernel.org)
9 * Modified for gLabels by:
10 * Jim Evins <evins@snaught.com>
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public
14 * License, version 2, as published by the Free Software Foundation.
16 * This library is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 /* We keep our own color context, as the color allocation might take
28 * place before things are realized.
32 #include <gtk/gtkwidget.h>
35 GdkColor e_white, e_dark_gray, e_black;
38 e_color_alloc (gushort red, gushort green, gushort blue)
45 return gdk_rgb_xpixel_from_rgb (
46 ((red & 0xff) << 16) | ((green & 0xff) << 8) |
51 e_color_alloc_gdk (GtkWidget *widget, GdkColor *c)
58 map = gtk_widget_get_colormap (widget);
59 else /* FIXME: multi depth broken ? */
60 map = gtk_widget_get_default_colormap ();
62 gdk_rgb_find_color (map, c);
66 e_color_alloc_name (GtkWidget *widget, const char *name, GdkColor *c)
72 gdk_color_parse (name, c);
75 map = gtk_widget_get_colormap (widget);
76 else /* FIXME: multi depth broken ? */
77 map = gtk_widget_get_default_colormap ();
79 gdk_rgb_find_color (map, c);
85 static gboolean e_color_inited = FALSE;
87 /* It's surprisingly easy to end up calling this twice. Survive. */
91 e_color_inited = TRUE;
93 /* Allocate the default colors */
95 e_white.green = 65535;
97 e_color_alloc_gdk (NULL, &e_white);
102 e_color_alloc_gdk (NULL, &e_black);
104 e_color_alloc_name (NULL, "gray20", &e_dark_gray);