1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
29 #include "gdkscreen.h"
31 #include "gdkinternals.h"
35 * @cmap: a #GdkColormap
37 * Deprecated function; use g_object_ref() instead.
39 * Return value: the colormap
42 gdk_colormap_ref (GdkColormap *cmap)
44 return (GdkColormap *) g_object_ref (cmap);
49 * @cmap: a #GdkColormap
51 * Deprecated function; use g_object_ref() instead.
54 gdk_colormap_unref (GdkColormap *cmap)
56 g_object_unref (cmap);
60 gdk_colormap_get_visual (GdkColormap *colormap)
62 g_return_val_if_fail (GDK_IS_COLORMAP (colormap), NULL);
64 return colormap->visual;
68 gdk_colors_store (GdkColormap *colormap,
74 for (i = 0; i < ncolors; i++)
76 colormap->colors[i].pixel = colors[i].pixel;
77 colormap->colors[i].red = colors[i].red;
78 colormap->colors[i].green = colors[i].green;
79 colormap->colors[i].blue = colors[i].blue;
82 gdk_colormap_change (colormap, ncolors);
86 *--------------------------------------------------------------
89 * Copy a color structure into new storage.
92 * "color" is the color struct to copy.
95 * A new color structure. Free it with gdk_color_free.
97 *--------------------------------------------------------------
100 static GMemChunk *color_chunk;
103 gdk_color_copy (const GdkColor *color)
107 g_return_val_if_fail (color != NULL, NULL);
109 if (color_chunk == NULL)
110 color_chunk = g_mem_chunk_new ("colors",
115 new_color = g_chunk_new (GdkColor, color_chunk);
121 *--------------------------------------------------------------
124 * Free a color structure obtained from gdk_color_copy. Do not use
125 * with other color structures.
128 * "color" is the color struct to free.
130 *-------------------------------------------------------------- */
133 gdk_color_free (GdkColor *color)
135 g_assert (color_chunk != NULL);
136 g_return_if_fail (color != NULL);
138 g_mem_chunk_free (color_chunk, color);
142 gdk_color_white (GdkColormap *colormap,
147 g_return_val_if_fail (colormap != NULL, FALSE);
152 color->green = 65535;
155 return_val = gdk_color_alloc (colormap, color);
164 gdk_color_black (GdkColormap *colormap,
169 g_return_val_if_fail (colormap != NULL, FALSE);
177 return_val = gdk_color_alloc (colormap, color);
185 /********************
187 ********************/
190 gdk_colormap_alloc_color (GdkColormap *colormap,
197 gdk_colormap_alloc_colors (colormap, color, 1, writeable, best_match,
204 gdk_color_alloc (GdkColormap *colormap,
209 gdk_colormap_alloc_colors (colormap, color, 1, FALSE, TRUE, &success);
215 gdk_color_hash (const GdkColor *colora)
217 return ((colora->red) +
218 (colora->green << 11) +
219 (colora->blue << 22) +
220 (colora->blue >> 6));
224 gdk_color_equal (const GdkColor *colora,
225 const GdkColor *colorb)
227 g_return_val_if_fail (colora != NULL, FALSE);
228 g_return_val_if_fail (colorb != NULL, FALSE);
230 return ((colora->red == colorb->red) &&
231 (colora->green == colorb->green) &&
232 (colora->blue == colorb->blue));
236 gdk_color_get_type (void)
238 static GType our_type = 0;
241 our_type = g_boxed_type_register_static ("GdkColor",
242 (GBoxedCopyFunc)gdk_color_copy,
243 (GBoxedFreeFunc)gdk_color_free);
248 gdk_color_parse (const gchar *spec,
251 PangoColor pango_color;
253 if (pango_color_parse (&pango_color, spec))
255 color->red = pango_color.red;
256 color->green = pango_color.green;
257 color->blue = pango_color.blue;
266 * gdk_colormap_get_system:
268 * Gets the system's default colormap for the default screen. (See
269 * gdk_colormap_get_system_for_screen ())
271 * Return value: the default colormap.
274 gdk_colormap_get_system (void)
276 return gdk_screen_get_system_colormap (gdk_screen_get_default ());