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/.
30 #include "gdkinternals.h"
34 * @cmap: a #GdkColormap
36 * Deprecated function; use g_object_ref() instead.
38 * Return value: the colormap
41 gdk_colormap_ref (GdkColormap *cmap)
43 return (GdkColormap *) g_object_ref (G_OBJECT (cmap));
48 * @cmap: a #GdkColormap
50 * Deprecated function; use g_object_ref() instead.
53 gdk_colormap_unref (GdkColormap *cmap)
55 g_object_unref (G_OBJECT (cmap));
59 gdk_colormap_get_visual (GdkColormap *colormap)
61 g_return_val_if_fail (GDK_IS_COLORMAP (colormap), NULL);
63 return colormap->visual;
67 gdk_colors_store (GdkColormap *colormap,
73 for (i = 0; i < ncolors; i++)
75 colormap->colors[i].pixel = colors[i].pixel;
76 colormap->colors[i].red = colors[i].red;
77 colormap->colors[i].green = colors[i].green;
78 colormap->colors[i].blue = colors[i].blue;
81 gdk_colormap_change (colormap, ncolors);
85 *--------------------------------------------------------------
88 * Copy a color structure into new storage.
91 * "color" is the color struct to copy.
94 * A new color structure. Free it with gdk_color_free.
96 *--------------------------------------------------------------
99 static GMemChunk *color_chunk;
102 gdk_color_copy (const GdkColor *color)
106 g_return_val_if_fail (color != NULL, NULL);
108 if (color_chunk == NULL)
109 color_chunk = g_mem_chunk_new ("colors",
114 new_color = g_chunk_new (GdkColor, color_chunk);
120 *--------------------------------------------------------------
123 * Free a color structure obtained from gdk_color_copy. Do not use
124 * with other color structures.
127 * "color" is the color struct to free.
129 *-------------------------------------------------------------- */
132 gdk_color_free (GdkColor *color)
134 g_assert (color_chunk != NULL);
135 g_return_if_fail (color != NULL);
137 g_mem_chunk_free (color_chunk, color);
141 gdk_color_white (GdkColormap *colormap,
146 g_return_val_if_fail (colormap != NULL, FALSE);
151 color->green = 65535;
154 return_val = gdk_color_alloc (colormap, color);
163 gdk_color_black (GdkColormap *colormap,
168 g_return_val_if_fail (colormap != NULL, FALSE);
176 return_val = gdk_color_alloc (colormap, color);
184 /********************
186 ********************/
189 gdk_colormap_alloc_color (GdkColormap *colormap,
196 gdk_colormap_alloc_colors (colormap, color, 1, writeable, best_match,
203 gdk_color_alloc (GdkColormap *colormap,
208 gdk_colormap_alloc_colors (colormap, color, 1, FALSE, TRUE, &success);
214 gdk_color_hash (const GdkColor *colora)
216 return ((colora->red) +
217 (colora->green << 11) +
218 (colora->blue << 22) +
219 (colora->blue >> 6));
223 gdk_color_equal (const GdkColor *colora,
224 const GdkColor *colorb)
226 g_return_val_if_fail (colora != NULL, FALSE);
227 g_return_val_if_fail (colorb != NULL, FALSE);
229 return ((colora->red == colorb->red) &&
230 (colora->green == colorb->green) &&
231 (colora->blue == colorb->blue));
235 gdk_color_get_type (void)
237 static GType our_type = 0;
240 our_type = g_boxed_type_register_static ("GdkColor",
241 (GBoxedCopyFunc)gdk_color_copy,
242 (GBoxedFreeFunc)gdk_color_free);
247 gdk_color_parse (const gchar *spec,
250 PangoColor pango_color;
252 if (pango_color_parse (&pango_color, spec))
254 color->red = pango_color.red;
255 color->green = pango_color.green;
256 color->blue = pango_color.blue;