From e624656c20124d1482a77b4cb50b0223cb4a073b Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sun, 29 Aug 2010 13:06:35 +0200 Subject: [PATCH] API: Remove GdkColormap --- docs/reference/gdk/gdk3-sections.txt | 22 +- gdk/Makefile.am | 1 - gdk/gdk.symbols | 12 - gdk/gdkcolor.c | 65 +- gdk/gdkcolor.h | 61 +- gdk/gdktypes.h | 1 - gdk/quartz/Makefile.am | 1 - gdk/quartz/gdkcolor-quartz.c | 113 --- gdk/win32/Makefile.am | 1 - gdk/win32/gdkcolor-win32.c | 1121 ------------------------ gdk/win32/gdkprivate-win32.h | 3 - gdk/win32/makefile.msc | 1 - gdk/x11/Makefile.am | 1 - gdk/x11/gdkcolor-x11.c | 1168 -------------------------- gdk/x11/gdkscreen-x11.c | 2 - gdk/x11/gdkscreen-x11.h | 1 - gdk/x11/gdkx.h | 7 - gtk/tests/defaultvalue.c | 2 - 18 files changed, 9 insertions(+), 2574 deletions(-) delete mode 100644 gdk/quartz/gdkcolor-quartz.c delete mode 100644 gdk/win32/gdkcolor-win32.c delete mode 100644 gdk/x11/gdkcolor-x11.c diff --git a/docs/reference/gdk/gdk3-sections.txt b/docs/reference/gdk/gdk3-sections.txt index 632b2fbd58..0b57d32250 100644 --- a/docs/reference/gdk/gdk3-sections.txt +++ b/docs/reference/gdk/gdk3-sections.txt @@ -244,16 +244,9 @@ gdk_pixbuf_get_from_surface
-Colormaps and Colors +Colors colors GdkColor -GdkColormap -gdk_colormap_new -gdk_colormap_alloc_colors -gdk_colormap_alloc_color -gdk_colormap_free_colors -gdk_colormap_get_visual -gdk_colormap_get_screen gdk_color_copy gdk_color_free gdk_color_parse @@ -262,18 +255,8 @@ gdk_color_hash gdk_color_to_string -GDK_COLORMAP -GDK_COLORMAP_GET_CLASS -GDK_TYPE_COLORMAP -GDK_IS_COLORMAP -GDK_COLORMAP_CLASS -GDK_IS_COLORMAP_CLASS GDK_TYPE_COLOR - -GdkColormapClass -gdk_colormap_get_type -gdk_color_get_type
@@ -1000,9 +983,6 @@ gdk_x11_screen_lookup_visual gdk_x11_window_set_user_time gdk_x11_window_move_to_current_desktop gdk_x11_display_get_user_time -gdk_x11_colormap_foreign_new -gdk_x11_colormap_get_xcolormap -gdk_x11_colormap_get_xdisplay gdk_x11_cursor_get_xcursor gdk_x11_cursor_get_xdisplay gdk_x11_display_broadcast_startup_message diff --git a/gdk/Makefile.am b/gdk/Makefile.am index 175084b52b..9c972f19f8 100644 --- a/gdk/Makefile.am +++ b/gdk/Makefile.am @@ -187,7 +187,6 @@ x11_introspection_files = \ x11/checksettings.c \ x11/gdkapplaunchcontext-x11.c \ x11/gdkasync.c \ - x11/gdkcolor-x11.c \ x11/gdkcursor-x11.c \ x11/gdkdevice-core.c \ x11/gdkdevicemanager-core.c \ diff --git a/gdk/gdk.symbols b/gdk/gdk.symbols index 8a2a1d9c31..a5ec76ed13 100644 --- a/gdk/gdk.symbols +++ b/gdk/gdk.symbols @@ -304,23 +304,11 @@ gdk_color_equal gdk_color_free gdk_color_get_type G_GNUC_CONST gdk_color_hash -gdk_colormap_alloc_color -gdk_colormap_get_visual gdk_color_parse gdk_color_to_string #endif #endif -#if IN_HEADER(__GDK_COLOR_H__) -#if IN_FILE(__GDK_COLOR_X11_C__) -gdk_colormap_new -gdk_colormap_get_type G_GNUC_CONST -gdk_colormap_alloc_colors -gdk_colormap_free_colors -gdk_colormap_get_screen -#endif -#endif - #if IN_HEADER(__GDK_CURSOR_H__) #if IN_FILE(__GDK_CURSOR_C__) gdk_cursor_get_type G_GNUC_CONST diff --git a/gdk/gdkcolor.c b/gdk/gdkcolor.c index ce5c89cab7..84416005df 100644 --- a/gdk/gdkcolor.c +++ b/gdk/gdkcolor.c @@ -32,22 +32,6 @@ #include "gdkinternals.h" -/** - * gdk_colormap_get_visual: - * @colormap: a #GdkColormap. - * - * Returns the visual for which a given colormap was created. - * - * Return value: the visual of the colormap. - **/ -GdkVisual * -gdk_colormap_get_visual (GdkColormap *colormap) -{ - g_return_val_if_fail (GDK_IS_COLORMAP (colormap), NULL); - - return colormap->visual; -} - /** * gdk_color_copy: * @color: a #GdkColor. @@ -84,39 +68,6 @@ gdk_color_free (GdkColor *color) g_slice_free (GdkColor, color); } -/******************** - * Color allocation * - ********************/ - -/** - * gdk_colormap_alloc_color: - * @colormap: a #GdkColormap. - * @color: the color to allocate. On return the - * pixel field will be - * filled in if allocation succeeds. - * @writeable: this parameter has no effect, and it's here for mere - * compatibility. - * @best_match: If %TRUE, GDK will attempt to do matching against - * existing colors if the color cannot be allocated as requested. - * - * Allocates a single color from a colormap. - * - * Return value: %TRUE if the allocation succeeded. - **/ -gboolean -gdk_colormap_alloc_color (GdkColormap *colormap, - GdkColor *color, - gboolean writeable, - gboolean best_match) -{ - gboolean success; - - gdk_colormap_alloc_colors (colormap, color, 1, writeable, best_match, - &success); - - return success; -} - /** * gdk_color_hash: * @colora: a #GdkColor. @@ -168,15 +119,13 @@ G_DEFINE_BOXED_TYPE (GdkColor, gdk_color, * Parses a textual specification of a color and fill in the * red, green, * and blue fields of a #GdkColor - * structure. The color is not allocated, you - * must call gdk_colormap_alloc_color() yourself. The string can - * either one of a large set of standard names. (Taken from the X11 - * rgb.txt file), or it can be a hex value in the - * form '#rgb' '#rrggbb' '#rrrgggbbb' or - * '#rrrrggggbbbb' where 'r', 'g' and 'b' are hex digits of the - * red, green, and blue components of the color, respectively. (White - * in the four forms is '#fff' '#ffffff' '#fffffffff' and - * '#ffffffffffff') + * structure. The string can either one of a large set of standard + * names. (Taken from the X11 rgb.txt file), or + * it can be a hex value in the form '#rgb' '#rrggbb' + * '#rrrgggbbb' or '#rrrrggggbbbb' where 'r', 'g' and 'b' are + * hex digits of the red, green, and blue components of the color, + * respectively. (White in the four forms is '#fff' '#ffffff' + * '#fffffffff' and '#ffffffffffff') * * Return value: %TRUE if the parsing succeeded. **/ diff --git a/gdk/gdkcolor.h b/gdk/gdkcolor.h index d531cbe6b0..97da01bf06 100644 --- a/gdk/gdkcolor.h +++ b/gdk/gdkcolor.h @@ -38,10 +38,7 @@ G_BEGIN_DECLS /* The color type. * A color consists of red, green and blue values in the - * range 0-65535 and a pixel value. The pixel value is highly - * dependent on the depth and colormap which this color will - * be used to draw into. Therefore, sharing colors between - * colormaps is a bad idea. + * range 0-65535 and a pixel value. The pixel value is unused. */ struct _GdkColor { @@ -51,64 +48,8 @@ struct _GdkColor guint16 blue; }; -/* The colormap type. - */ - -typedef struct _GdkColormapClass GdkColormapClass; - -#define GDK_TYPE_COLORMAP (gdk_colormap_get_type ()) -#define GDK_COLORMAP(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_COLORMAP, GdkColormap)) -#define GDK_COLORMAP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_COLORMAP, GdkColormapClass)) -#define GDK_IS_COLORMAP(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_COLORMAP)) -#define GDK_IS_COLORMAP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_COLORMAP)) -#define GDK_COLORMAP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_COLORMAP, GdkColormapClass)) - #define GDK_TYPE_COLOR (gdk_color_get_type ()) -struct _GdkColormap -{ - /*< private >*/ - GObject parent_instance; - - /*< public >*/ - gint GSEAL (size); - GdkColor *GSEAL (colors); - - /*< private >*/ - GdkVisual *GSEAL (visual); - - gpointer GSEAL (windowing_data); -}; - -struct _GdkColormapClass -{ - GObjectClass parent_class; - -}; - -GType gdk_colormap_get_type (void) G_GNUC_CONST; - -GdkColormap* gdk_colormap_new (GdkVisual *visual, - gboolean allocate); - -GdkScreen *gdk_colormap_get_screen (GdkColormap *cmap); - -gint gdk_colormap_alloc_colors (GdkColormap *colormap, - GdkColor *colors, - gint n_colors, - gboolean writeable, - gboolean best_match, - gboolean *success); -gboolean gdk_colormap_alloc_color (GdkColormap *colormap, - GdkColor *color, - gboolean writeable, - gboolean best_match); -void gdk_colormap_free_colors (GdkColormap *colormap, - const GdkColor *colors, - gint n_colors); - -GdkVisual *gdk_colormap_get_visual (GdkColormap *colormap); - GdkColor *gdk_color_copy (const GdkColor *color); void gdk_color_free (GdkColor *color); gboolean gdk_color_parse (const gchar *spec, diff --git a/gdk/gdktypes.h b/gdk/gdktypes.h index e36d01c751..42ebf59943 100644 --- a/gdk/gdktypes.h +++ b/gdk/gdktypes.h @@ -90,7 +90,6 @@ typedef guint32 GdkNativeWindow; /* Forward declarations of commonly used types */ typedef struct _GdkColor GdkColor; -typedef struct _GdkColormap GdkColormap; typedef struct _GdkCursor GdkCursor; typedef struct _GdkVisual GdkVisual; diff --git a/gdk/quartz/Makefile.am b/gdk/quartz/Makefile.am index 2bb63b9515..b0a967d1e8 100644 --- a/gdk/quartz/Makefile.am +++ b/gdk/quartz/Makefile.am @@ -22,7 +22,6 @@ libgdk_quartz_la_SOURCES = \ GdkQuartzWindow.c \ GdkQuartzWindow.h \ gdkapplaunchcontext-quartz.c \ - gdkcolor-quartz.c \ gdkcursor-quartz.c \ gdkdevice-core.c \ gdkdevicemanager-core.c \ diff --git a/gdk/quartz/gdkcolor-quartz.c b/gdk/quartz/gdkcolor-quartz.c deleted file mode 100644 index ec8335c3bb..0000000000 --- a/gdk/quartz/gdkcolor-quartz.c +++ /dev/null @@ -1,113 +0,0 @@ -/* gdkcolor-quartz.c - * - * Copyright (C) 2005 Imendio AB - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include "config.h" - -#include "gdkcolor.h" -#include "gdkprivate-quartz.h" - -GType -gdk_colormap_get_type (void) -{ - static GType object_type = 0; - - if (!object_type) - { - const GTypeInfo object_info = - { - sizeof (GdkColormapClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) NULL, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (GdkColormap), - 0, /* n_preallocs */ - (GInstanceInitFunc) NULL, - }; - - object_type = g_type_register_static (G_TYPE_OBJECT, - "GdkColormap", - &object_info, - 0); - } - - return object_type; -} - -GdkColormap * -gdk_colormap_new (GdkVisual *visual, - gint private_cmap) -{ - g_return_val_if_fail (visual != NULL, NULL); - - /* FIXME: Implement */ - return NULL; -} - -void -gdk_colormap_free_colors (GdkColormap *colormap, - const GdkColor *colors, - gint n_colors) -{ - /* This function shouldn't do anything since colors are never allocated. */ -} - -gint -gdk_colormap_alloc_colors (GdkColormap *colormap, - GdkColor *colors, - gint ncolors, - gboolean writeable, - gboolean best_match, - gboolean *success) -{ - int i; - int alpha; - - g_return_val_if_fail (GDK_IS_COLORMAP (colormap), ncolors); - g_return_val_if_fail (colors != NULL, ncolors); - g_return_val_if_fail (success != NULL, ncolors); - - if (gdk_colormap_get_visual (colormap)->depth == 32) - alpha = 0xff; - else - alpha = 0; - - for (i = 0; i < ncolors; i++) - { - colors[i].pixel = alpha << 24 | - ((colors[i].red >> 8) & 0xff) << 16 | - ((colors[i].green >> 8) & 0xff) << 8 | - ((colors[i].blue >> 8) & 0xff); - } - - *success = TRUE; - - return 0; -} - -GdkScreen* -gdk_colormap_get_screen (GdkColormap *cmap) -{ - g_return_val_if_fail (cmap != NULL, NULL); - - return gdk_screen_get_default (); -} - diff --git a/gdk/win32/Makefile.am b/gdk/win32/Makefile.am index a1cf0fd357..d851ccf056 100644 --- a/gdk/win32/Makefile.am +++ b/gdk/win32/Makefile.am @@ -27,7 +27,6 @@ EXTRA_DIST += \ libgdk_win32_la_SOURCES = \ xcursors.h \ gdkapplaunchcontext-win32.c \ - gdkcolor-win32.c \ gdkcursor-win32.c \ gdkdevicemanager-win32.c \ gdkdevicemanager-win32.h \ diff --git a/gdk/win32/gdkcolor-win32.c b/gdk/win32/gdkcolor-win32.c deleted file mode 100644 index dfb986c8d0..0000000000 --- a/gdk/win32/gdkcolor-win32.c +++ /dev/null @@ -1,1121 +0,0 @@ -/* GDK - The GIMP Drawing Kit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * Copyright (C) 1998-2002 Tor Lillqvist - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -/* - * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS - * file for a list of people on the GTK+ Team. See the ChangeLog - * files for a list of changes. These files are distributed with - * GTK+ at ftp://ftp.gtk.org/pub/gtk/. - */ - -#include "config.h" -#include -#include -#include - -#include "gdkcolor.h" -#include "gdkscreen.h" -#include "gdkinternals.h" -#include "gdkprivate-win32.h" - -static gint gdk_colormap_match_color (GdkColormap *cmap, - GdkColor *color, - const gchar *available); -static void gdk_colormap_init (GdkColormap *colormap); -static void gdk_colormap_class_init (GdkColormapClass *klass); -static void gdk_colormap_finalize (GObject *object); - -static gpointer parent_class = NULL; - -GType -gdk_colormap_get_type (void) -{ - static GType object_type = 0; - - if (!object_type) - { - const GTypeInfo object_info = - { - sizeof (GdkColormapClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) gdk_colormap_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (GdkColormap), - 0, /* n_preallocs */ - (GInstanceInitFunc) gdk_colormap_init, - }; - - object_type = g_type_register_static (G_TYPE_OBJECT, - "GdkColormap", - &object_info, 0); - } - - return object_type; -} - -static void -gdk_colormap_init (GdkColormap *colormap) -{ - GdkColormapPrivateWin32 *private; - - private = g_new (GdkColormapPrivateWin32, 1); - - colormap->windowing_data = private; - - private->hpal = NULL; - private->current_size = 0; - private->use = NULL; - private->hash = NULL; - private->info = NULL; - - colormap->size = 0; - colormap->colors = NULL; -} - -static void -gdk_colormap_class_init (GdkColormapClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - parent_class = g_type_class_peek_parent (klass); - - object_class->finalize = gdk_colormap_finalize; -} - -static void -gdk_colormap_finalize (GObject *object) -{ - GdkColormap *colormap = GDK_COLORMAP (object); - GdkColormapPrivateWin32 *private = GDK_WIN32_COLORMAP_DATA (colormap); - - GDI_CALL (DeleteObject, (private->hpal)); - - if (private->hash) - g_hash_table_destroy (private->hash); - - g_free (private->info); - g_free (colormap->colors); - g_free (private); - - G_OBJECT_CLASS (parent_class)->finalize (object); -} - -/* Mimics XAllocColorCells. Allocate read/write color cells. */ - -static gboolean -alloc_color_cells (GdkColormap *cmap, - gboolean contig, - unsigned long plane_masks_return[], - unsigned int nplanes, - unsigned long pixels_return[], - unsigned int npixels) -{ - GdkColormapPrivateWin32 *cmapp = GDK_WIN32_COLORMAP_DATA (cmap); - gint i, nfree, iret, start = 0; - - GDK_NOTE (COLORMAP, g_print ("alloc_color_cells: cmap=%p contig=%s npl=%d npix=%d", - cmapp, contig ? "TRUE" : "FALSE", - nplanes, npixels)); - - switch (cmap->visual->type) - { - case GDK_VISUAL_GRAYSCALE: - case GDK_VISUAL_PSEUDO_COLOR: - nfree = 0; - for (i = 0; i < cmap->size && nfree < npixels; i++) - if (cmapp->use[i] == GDK_WIN32_PE_AVAILABLE && - (!contig || - (nfree == 0 || cmapp->use[i-1] == GDK_WIN32_PE_AVAILABLE))) - { - if (nfree == 0) - start = i; - nfree++; - } - else if (contig) - nfree = 0; - - if (npixels > nfree) - { - GDK_NOTE (COLORMAP, g_print ("... nope (%d > %d)\n", - npixels, nfree)); - return FALSE; - } - else - GDK_NOTE (COLORMAP, g_print ("... ok\n")); - - iret = 0; - for (i = start; i < cmap->size && iret < npixels; i++) - if (cmapp->use[i] == GDK_WIN32_PE_AVAILABLE) - { - cmapp->use[i] = GDK_WIN32_PE_INUSE; - pixels_return[iret] = i; - iret++; - } - g_assert (iret == npixels); - break; - - default: - g_assert_not_reached (); - } - - return TRUE; -} - -/* The following functions are originally from Tk8.0, but heavily - modified. Here are tk's licensing terms. I hope these terms don't - conflict with the GNU Lesser General Public License? They - shouldn't, as they are looser that the GLPL, yes? */ - -/* -This software is copyrighted by the Regents of the University of -California, Sun Microsystems, Inc., and other parties. The following -terms apply to all files associated with the software unless explicitly -disclaimed in individual files. - -The authors hereby grant permission to use, copy, modify, distribute, -and license this software and its documentation for any purpose, provided -that existing copyright notices are retained in all copies and that this -notice is included verbatim in any distributions. No written agreement, -license, or royalty fee is required for any of the authorized uses. -Modifications to this software may be copyrighted by their authors -and need not follow the licensing terms described here, provided that -the new terms are clearly indicated on the first page of each file where -they apply. - -IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY -FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES -ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY -DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - -THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE -IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE -NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR -MODIFICATIONS. - -GOVERNMENT USE: If you are acquiring this software on behalf of the -U.S. government, the Government shall have only "Restricted Rights" -in the software and related documentation as defined in the Federal -Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you -are acquiring the software on behalf of the Department of Defense, the -software shall be classified as "Commercial Computer Software" and the -Government shall have only "Restricted Rights" as defined in Clause -252.227-7013 (c) (1) of DFARs. Notwithstanding the foregoing, the -authors grant the U.S. Government and others acting in its behalf -permission to use and distribute the software in accordance with the -terms specified in this license. -*/ - -/* Mimics XAllocColor. Allocate a read-only colormap entry. */ - -static int -alloc_color (GdkColormap *cmap, - PALETTEENTRY *color, - guint *pixelp) -{ - PALETTEENTRY entry, close_entry; - COLORREF new_pixel; - UINT index; - GdkColormapPrivateWin32 *cmapp = GDK_WIN32_COLORMAP_DATA (cmap); - gint i; - - entry = *color; - entry.peFlags = 0; - - new_pixel = RGB (entry.peRed, entry.peGreen, entry.peBlue); - - switch (cmap->visual->type) - { - case GDK_VISUAL_PSEUDO_COLOR: - /* Find the nearest existing palette entry. */ - index = GetNearestPaletteIndex (cmapp->hpal, new_pixel); - GetPaletteEntries (cmapp->hpal, index, 1, &close_entry); - - GDK_NOTE (COLORMAP, - g_print ("alloc_color: new_pixel=%06lx index=%d=%02x close=%06lx\n", - new_pixel, index, index, - RGB (close_entry.peRed, close_entry.peGreen, close_entry.peBlue))); - - if (new_pixel != RGB (close_entry.peRed, close_entry.peGreen, - close_entry.peBlue)) - { - /* Not a perfect match. */ - if (cmapp->use[index] == GDK_WIN32_PE_AVAILABLE) - { - /* It was a nonused entry anyway, so we can use it, and - * set it to the correct color. - */ - GDK_NOTE (COLORMAP, g_print ("... was free\n")); - GDI_CALL (SetPaletteEntries, (cmapp->hpal, index, 1, &entry)); - } - else - { - /* The close entry found is in use, so search for a - * available slot. - */ - gboolean done = FALSE; - for (i = 0; i < cmap->size; i++) - if (cmapp->use[i] == GDK_WIN32_PE_AVAILABLE) - { - /* An available slot, use it. */ - GDK_NOTE (COLORMAP, - g_print ("... use free slot %d%s\n", - i, (i >= cmapp->current_size) ? - ", will resize palette" : "")); - if (i >= cmapp->current_size) - { - if (!ResizePalette (cmapp->hpal, i + 1)) - { - WIN32_GDI_FAILED ("ResizePalette"); - break; - } - cmapp->current_size = i + 1; - } - if (!SetPaletteEntries (cmapp->hpal, i, 1, &entry)) - { - WIN32_GDI_FAILED ("SetPaletteEntries"); - i = cmap->size; - } - else - { - done = TRUE; - index = i; - } - break; - } - if (!done) - { - /* No free slots available, or failed to resize - * palette or set palette entry. - */ - GDK_NOTE (COLORMAP, g_print ("... failure\n")); - return FALSE; - } - } - } - else - { - /* We got a match, so use it. */ - } - - *pixelp = index; - cmapp->use[index] = GDK_WIN32_PE_INUSE; - GDK_NOTE (COLORMAP, g_print ("alloc_color: %p: " - "index=%3d=%02x for %02x %02x %02x: " - "%02x %02x %02x\n", - cmapp->hpal, index, index, - entry.peRed, entry.peGreen, entry.peBlue, - color->peRed, color->peGreen, color->peBlue)); - return TRUE; - - case GDK_VISUAL_STATIC_COLOR: - /* Find the nearest existing palette entry. */ - index = GetNearestPaletteIndex (cmapp->hpal, new_pixel); - GetPaletteEntries (cmapp->hpal, index, 1, &close_entry); - *color = close_entry; - *pixelp = index; - GDK_NOTE (COLORMAP, g_print ("alloc_color %p: " - "index=%3d=%02x for %02x %02x %02x: " - "%02x %02x %02x\n", - cmapp->hpal, index, index, - entry.peRed, entry.peGreen, entry.peBlue, - color->peRed, color->peGreen, color->peBlue)); - return TRUE; - - case GDK_VISUAL_TRUE_COLOR: - /* Determine what color will actually be used on non-colormap systems. */ - - *pixelp = GetNearestColor (_gdk_display_hdc, new_pixel); - color->peRed = GetRValue (*pixelp); - color->peGreen = GetGValue (*pixelp); - color->peBlue = GetBValue (*pixelp); - return TRUE; - - default: - g_assert_not_reached (); - return FALSE; - } -} - -/* Mimics XFreeColors. */ - -static void -free_colors (GdkColormap *cmap, - gulong *pixels, - gint npixels, - gulong planes) -{ - PALETTEENTRY pe; - GdkColormapPrivateWin32 *cmapp = GDK_WIN32_COLORMAP_DATA (cmap); - gint i; -#ifdef G_ENABLE_DEBUG - gint set_black_count = 0; -#endif - gboolean *cleared_entries; - - cleared_entries = g_new0 (gboolean, cmap->size); - - /* We don't have to do anything for non-palette devices. */ - - switch (cmap->visual->type) - { - case GDK_VISUAL_GRAYSCALE: - case GDK_VISUAL_PSEUDO_COLOR: - for (i = 0; i < npixels; i++) - { - if (pixels[i] >= cmap->size) - ; /* Nothing */ - else if (cmapp->use[pixels[i]] == GDK_WIN32_PE_STATIC) - ; /* Nothing either*/ - else - { - cmapp->use[pixels[i]] = GDK_WIN32_PE_AVAILABLE; - cleared_entries[pixels[i]] = TRUE; - } - } - for (i = cmapp->current_size - 1; i >= 0; i--) - if (cmapp->use[i] != GDK_WIN32_PE_AVAILABLE) - break; - if (i < cmapp->current_size - 1) - { - GDK_NOTE (COLORMAP, g_print ("free_colors: hpal=%p resize=%d\n", - cmapp->hpal, i + 1)); - if (!ResizePalette (cmapp->hpal, i + 1)) - WIN32_GDI_FAILED ("ResizePalette"); - else - cmapp->current_size = i + 1; - } - pe.peRed = pe.peGreen = pe.peBlue = pe.peFlags = 0; - for (i = 0; i < cmapp->current_size; i++) - { - if (cleared_entries[i]) - { - GDI_CALL (SetPaletteEntries, (cmapp->hpal, i, 1, &pe)); - GDK_NOTE (COLORMAP, set_black_count++); - } - } -#if 0 - GDK_NOTE (COLORMAP, _gdk_win32_print_hpalette (cmapp->hpal)); -#else - GDK_NOTE (COLORMAP, (set_black_count > 0 ? - g_print ("free_colors: %d (%d) set to black\n", - set_black_count, cmapp->current_size) - : (void) 0)); -#endif - g_free (cleared_entries); - - break; - - default: - g_assert_not_reached (); - } -} - -/* Mimics XCreateColormap. */ - -static void -create_colormap (GdkColormap *cmap, - gboolean writeable) -{ - struct { - LOGPALETTE pal; - PALETTEENTRY pe[256-1]; - } lp; - HPALETTE hpal; - GdkColormapPrivateWin32 *cmapp = GDK_WIN32_COLORMAP_DATA (cmap); - gint i; - - /* Allocate a starting palette with all the static colors. */ - hpal = GetStockObject (DEFAULT_PALETTE); - lp.pal.palVersion = 0x300; - lp.pal.palNumEntries = GetPaletteEntries (hpal, 0, 256, lp.pal.palPalEntry); - - if (cmap->visual->type == GDK_VISUAL_STATIC_COLOR && - cmap->visual->depth == 4) - { - /* Use only 16 colors */ - for (i = 8; i < 16; i++) - lp.pal.palPalEntry[i] = lp.pal.palPalEntry[i+4]; - lp.pal.palNumEntries = 16; - } - - for (i = 0; i < lp.pal.palNumEntries; i++) - lp.pal.palPalEntry[i].peFlags = 0; - GDK_NOTE (COLORMAP, (g_print ("Default palette %p: %d entries\n", - hpal, lp.pal.palNumEntries), - _gdk_win32_print_paletteentries (lp.pal.palPalEntry, - lp.pal.palNumEntries))); - DeleteObject (hpal); - - /* For writeable colormaps, allow all 256 entries to be set. They won't - * set all 256 system palette entries anyhow, of course, but we shouldn't - * let the app see that, I think. - */ - if (writeable) - cmapp->current_size = 0; - else - cmapp->current_size = lp.pal.palNumEntries; - - cmapp->private_val = writeable; - - if (!(cmapp->hpal = CreatePalette (&lp.pal))) - WIN32_GDI_FAILED ("CreatePalette"); - else - GDK_NOTE (COLORMAP, g_print ("Created palette %p\n", cmapp->hpal)); - - switch (cmap->visual->type) - { - case GDK_VISUAL_PSEUDO_COLOR: - cmapp->use = g_new (GdkWin32PalEntryState, cmap->size); - - /* Mark static colors in use. */ - for (i = 0; i < cmapp->current_size; i++) - { - cmapp->use[i] = GDK_WIN32_PE_STATIC; - cmapp->info[i].ref_count = G_MAXUINT/2; - } - /* Mark rest not in use */ - for (; i < cmap->size; i++) - cmapp->use[i] = GDK_WIN32_PE_AVAILABLE; - break; - - default: - break; - } -} - -static void -sync_colors (GdkColormap *colormap) -{ - PALETTEENTRY *pe; - GdkColormapPrivateWin32 *private = GDK_WIN32_COLORMAP_DATA (colormap); - gint nlookup; - gint i; - - pe = g_new (PALETTEENTRY, colormap->size); - nlookup = GetPaletteEntries (private->hpal, 0, colormap->size, pe); - - GDK_NOTE (COLORMAP, (g_print ("sync_colors: %p hpal=%p: %d entries\n", - private, private->hpal, nlookup), - _gdk_win32_print_paletteentries (pe, nlookup))); - - for (i = 0; i < nlookup; i++) - { - colormap->colors[i].pixel = i; - colormap->colors[i].red = (pe[i].peRed * 65535) / 255; - colormap->colors[i].green = (pe[i].peGreen * 65535) / 255; - colormap->colors[i].blue = (pe[i].peBlue * 65535) / 255; - } - - for ( ; i < colormap->size; i++) - { - colormap->colors[i].pixel = i; - colormap->colors[i].red = 0; - colormap->colors[i].green = 0; - colormap->colors[i].blue = 0; - } - - g_free (pe); -} - -GdkColormap* -gdk_colormap_new (GdkVisual *visual, - gboolean private_cmap) -{ - GdkColormap *colormap; - GdkColormapPrivateWin32 *private; - - g_return_val_if_fail (visual != NULL, NULL); - - colormap = g_object_new (gdk_colormap_get_type (), NULL); - private = GDK_WIN32_COLORMAP_DATA (colormap); - - colormap->visual = visual; - - colormap->size = visual->colormap_size; - - switch (visual->type) - { - case GDK_VISUAL_GRAYSCALE: - case GDK_VISUAL_PSEUDO_COLOR: - private->info = g_new0 (GdkColorInfo, colormap->size); - colormap->colors = g_new (GdkColor, colormap->size); - - private->hash = g_hash_table_new ((GHashFunc) gdk_color_hash, - (GEqualFunc) gdk_color_equal); - - create_colormap (colormap, private_cmap); - - if (private_cmap) - { - sync_colors (colormap); - } - break; - - case GDK_VISUAL_STATIC_GRAY: - case GDK_VISUAL_STATIC_COLOR: - create_colormap (colormap, FALSE); - colormap->colors = g_new (GdkColor, colormap->size); - sync_colors (colormap); - break; - - case GDK_VISUAL_TRUE_COLOR: - break; - - default: - g_assert_not_reached (); - } - - return colormap; -} - -static void -gdk_colors_free (GdkColormap *colormap, - gulong *in_pixels, - gint in_npixels, - gulong planes) -{ - GdkColormapPrivateWin32 *private; - gulong *pixels; - gint npixels = 0; - gint i; - - g_return_if_fail (GDK_IS_COLORMAP (colormap)); - g_return_if_fail (in_pixels != NULL); - - private = GDK_WIN32_COLORMAP_DATA (colormap); - - if ((colormap->visual->type != GDK_VISUAL_PSEUDO_COLOR) && - (colormap->visual->type != GDK_VISUAL_GRAYSCALE)) - return; - - pixels = g_new (gulong, in_npixels); - - for (i = 0; i < in_npixels; i++) - { - gulong pixel = in_pixels[i]; - - if (private->use[pixel] == GDK_WIN32_PE_STATIC) - continue; - - if (private->info[pixel].ref_count) - { - private->info[pixel].ref_count--; - - if (private->info[pixel].ref_count == 0) - { - pixels[npixels++] = pixel; - if (!(private->info[pixel].flags & GDK_COLOR_WRITEABLE)) - g_hash_table_remove (private->hash, &colormap->colors[pixel]); - private->info[pixel].flags = 0; - } - } - } - - if (npixels) - free_colors (colormap, pixels, npixels, planes); - - g_free (pixels); -} - -void -gdk_colormap_free_colors (GdkColormap *colormap, - const GdkColor *colors, - gint ncolors) -{ - gulong *pixels; - gint i; - - g_return_if_fail (GDK_IS_COLORMAP (colormap)); - g_return_if_fail (colors != NULL); - - if ((colormap->visual->type != GDK_VISUAL_PSEUDO_COLOR) && - (colormap->visual->type != GDK_VISUAL_GRAYSCALE)) - return; - - pixels = g_new (gulong, ncolors); - - for (i = 0; i < ncolors; i++) - pixels[i] = colors[i].pixel; - - gdk_colors_free (colormap, pixels, ncolors, 0); - - g_free (pixels); -} - -/******************** - * Color allocation * - ********************/ - -/* Try to allocate a single color using alloc_color. If it succeeds, - * cache the result in our colormap, and store in ret. - */ -static gboolean -gdk_colormap_alloc1 (GdkColormap *colormap, - GdkColor *color, - GdkColor *ret) -{ - GdkColormapPrivateWin32 *private; - PALETTEENTRY pe; - - private = GDK_WIN32_COLORMAP_DATA (colormap); - - pe.peRed = color->red >> 8; - pe.peGreen = color->green >> 8; - pe.peBlue = color->blue >> 8; - - if (alloc_color (colormap, &pe, &ret->pixel)) - { - ret->red = (pe.peRed * 65535) / 255; - ret->green = (pe.peGreen * 65535) / 255; - ret->blue = (pe.peBlue * 65535) / 255; - - if ((guint) ret->pixel < colormap->size) - { - if (private->info[ret->pixel].ref_count) /* got a duplicate */ - { - } - else - { - colormap->colors[ret->pixel] = *color; - colormap->colors[ret->pixel].pixel = ret->pixel; - private->info[ret->pixel].ref_count = 1; - - g_hash_table_insert (private->hash, - &colormap->colors[ret->pixel], - &colormap->colors[ret->pixel]); - } - } - return TRUE; - } - return FALSE; -} - -static gint -gdk_colormap_alloc_colors_writeable (GdkColormap *colormap, - GdkColor *colors, - gint ncolors, - gboolean writeable, - gboolean best_match, - gboolean *success) -{ - GdkColormapPrivateWin32 *private; - gulong *pixels; - gboolean status; - gint i, index; - - private = GDK_WIN32_COLORMAP_DATA (colormap); - - if (private->private_val) - { - index = 0; - for (i=0; isize) && - (private->info[index].ref_count != 0)) - index++; - - if (index < colormap->size) - { - colors[i].pixel = index; - success[i] = TRUE; - private->info[index].ref_count++; - private->info[i].flags |= GDK_COLOR_WRITEABLE; - } - else - break; - } - return i; - } - else - { - pixels = g_new (gulong, ncolors); - - /* Allocation of a writeable color cells */ - status = alloc_color_cells (colormap, FALSE, NULL, 0, pixels, ncolors); - if (status) - { - for (i = 0; i < ncolors; i++) - { - colors[i].pixel = pixels[i]; - private->info[pixels[i]].ref_count++; - private->info[pixels[i]].flags |= GDK_COLOR_WRITEABLE; - } - } - - g_free (pixels); - - return status ? ncolors : 0; - } -} - -static gint -gdk_colormap_alloc_colors_private (GdkColormap *colormap, - GdkColor *colors, - gint ncolors, - gboolean writeable, - gboolean best_match, - gboolean *success) -{ - GdkColormapPrivateWin32 *cmapp; - gint i, index; - PALETTEENTRY pe; - gint nremaining = 0; - - cmapp = GDK_WIN32_COLORMAP_DATA (colormap); - index = -1; - - /* First, store the colors we have room for */ - - index = 0; - for (i = 0; i < ncolors; i++) - { - if (!success[i]) - { - while ((index < colormap->size) && - (cmapp->info[index].ref_count != 0)) - index++; - - if (index < colormap->size) - { - if (index >= cmapp->current_size) - { - if (!ResizePalette (cmapp->hpal, index + 1)) - { - WIN32_GDI_FAILED ("ResizePalette"); - nremaining++; - } - else - cmapp->current_size = index + 1; - } - if (index < cmapp->current_size) - { - pe.peRed = colors[i].red >> 8; - pe.peBlue = colors[i].blue >> 8; - pe.peGreen = colors[i].green >> 8; - pe.peFlags = 0; - - if (!SetPaletteEntries (cmapp->hpal, index, 1, &pe)) - { - WIN32_GDI_FAILED ("SetPaletteEntries"); - nremaining++; - } - else - { - success[i] = TRUE; - - colors[i].pixel = index; - colormap->colors[index] = colors[i]; - cmapp->info[index].ref_count++; - } - } - } - else - nremaining++; - } - } - - if (nremaining > 0 && best_match) - { - /* Get best matches for remaining colors */ - - gchar *available = g_new (gchar, colormap->size); - for (i = 0; i < colormap->size; i++) - available[i] = TRUE; - - for (i=0; icolors[index]; - cmapp->info[index].ref_count++; - - success[i] = TRUE; - nremaining--; - } - } - } - g_free (available); - } - - return (ncolors - nremaining); -} - -static gint -gdk_colormap_alloc_colors_shared (GdkColormap *colormap, - GdkColor *colors, - gint ncolors, - gboolean writeable, - gboolean best_match, - gboolean *success) -{ - GdkColormapPrivateWin32 *private; - gint i, index; - gint nremaining = 0; - gint nfailed = 0; - - private = GDK_WIN32_COLORMAP_DATA (colormap); - index = -1; - - for (i = 0; i < ncolors; i++) - { - if (!success[i]) - { - if (gdk_colormap_alloc1 (colormap, &colors[i], &colors[i])) - success[i] = TRUE; - else - nremaining++; - } - } - - - if (nremaining > 0 && best_match) - { - gchar *available = g_new (gchar, colormap->size); - for (i = 0; i < colormap->size; i++) - available[i] = ((private->info[i].ref_count == 0) || - !(private->info[i].flags & GDK_COLOR_WRITEABLE)); - while (nremaining > 0) - { - for (i = 0; i < ncolors; i++) - { - if (!success[i]) - { - index = gdk_colormap_match_color (colormap, &colors[i], available); - if (index != -1) - { - if (private->info[index].ref_count) - { - private->info[index].ref_count++; - colors[i] = colormap->colors[index]; - success[i] = TRUE; - nremaining--; - } - else - { - if (gdk_colormap_alloc1 (colormap, - &colormap->colors[index], - &colors[i])) - { - success[i] = TRUE; - nremaining--; - break; - } - else - { - available[index] = FALSE; - } - } - } - else - { - nfailed++; - nremaining--; - success[i] = 2; /* flag as permanent failure */ - } - } - } - } - g_free (available); - } - - /* Change back the values we flagged as permanent failures */ - if (nfailed > 0) - { - for (i = 0; i < ncolors; i++) - if (success[i] == 2) - success[i] = FALSE; - nremaining = nfailed; - } - - return (ncolors - nremaining); -} - -static gint -gdk_colormap_alloc_colors_pseudocolor (GdkColormap *colormap, - GdkColor *colors, - gint ncolors, - gboolean writeable, - gboolean best_match, - gboolean *success) -{ - GdkColormapPrivateWin32 *private; - GdkColor *lookup_color; - gint i; - gint nremaining = 0; - - private = GDK_WIN32_COLORMAP_DATA (colormap); - - /* Check for an exact match among previously allocated colors */ - - for (i = 0; i < ncolors; i++) - { - if (!success[i]) - { - lookup_color = g_hash_table_lookup (private->hash, &colors[i]); - if (lookup_color) - { - private->info[lookup_color->pixel].ref_count++; - colors[i].pixel = lookup_color->pixel; - success[i] = TRUE; - } - else - nremaining++; - } - } - - /* If that failed, we try to allocate a new color, or approxmiate - * with what we can get if best_match is TRUE. - */ - if (nremaining > 0) - { - if (private->private_val) - return gdk_colormap_alloc_colors_private (colormap, colors, ncolors, writeable, best_match, success); - else - return gdk_colormap_alloc_colors_shared (colormap, colors, ncolors, writeable, best_match, success); - } - else - return 0; -} - -gint -gdk_colormap_alloc_colors (GdkColormap *colormap, - GdkColor *colors, - gint ncolors, - gboolean writeable, - gboolean best_match, - gboolean *success) -{ - GdkColormapPrivateWin32 *private; - GdkVisual *visual; - gint i; - gint nremaining = 0; - PALETTEENTRY pe; - - g_return_val_if_fail (GDK_IS_COLORMAP (colormap), FALSE); - g_return_val_if_fail (colors != NULL, FALSE); - g_return_val_if_fail (success != NULL, ncolors); - - private = GDK_WIN32_COLORMAP_DATA (colormap); - - for (i = 0; i < ncolors; i++) - success[i] = FALSE; - - switch (colormap->visual->type) - { - case GDK_VISUAL_PSEUDO_COLOR: - case GDK_VISUAL_GRAYSCALE: - if (writeable) - return gdk_colormap_alloc_colors_writeable (colormap, colors, ncolors, - writeable, best_match, success); - else - return gdk_colormap_alloc_colors_pseudocolor (colormap, colors, ncolors, - writeable, best_match, success); - break; - - case GDK_VISUAL_TRUE_COLOR: - visual = colormap->visual; - - for (i = 0; i < ncolors; i++) - { - colors[i].pixel = - (((colors[i].red >> (16 - visual->red_prec)) << visual->red_shift) + - ((colors[i].green >> (16 - visual->green_prec)) << visual->green_shift) + - ((colors[i].blue >> (16 - visual->blue_prec)) << visual->blue_shift)); - success[i] = TRUE; - } - break; - - case GDK_VISUAL_STATIC_GRAY: - case GDK_VISUAL_STATIC_COLOR: - for (i = 0; i < ncolors; i++) - { - pe.peRed = colors[i].red >> 8; - pe.peGreen = colors[i].green >> 8; - pe.peBlue = colors[i].blue >> 8; - if (alloc_color (colormap, &pe, &colors[i].pixel)) - success[i] = TRUE; - else - nremaining++; - } - break; - - case GDK_VISUAL_DIRECT_COLOR: - g_assert_not_reached (); - } - - return nremaining; -} - -static gint -gdk_colormap_match_color (GdkColormap *cmap, - GdkColor *color, - const gchar *available) -{ - GdkColor *colors; - guint sum, min; - gint rdiff, gdiff, bdiff; - gint i, index; - - g_return_val_if_fail (cmap != NULL, 0); - g_return_val_if_fail (color != NULL, 0); - - colors = cmap->colors; - min = 3 * (65536); - index = -1; - - for (i = 0; i < cmap->size; i++) - { - if ((!available) || (available && available[i])) - { - rdiff = (color->red - colors[i].red); - gdiff = (color->green - colors[i].green); - bdiff = (color->blue - colors[i].blue); - - sum = ABS (rdiff) + ABS (gdiff) + ABS (bdiff); - - if (sum < min) - { - index = i; - min = sum; - } - } - } - - return index; -} - -GdkScreen* -gdk_colormap_get_screen (GdkColormap *cmap) -{ - g_return_val_if_fail (GDK_IS_COLORMAP (cmap), NULL); - - return _gdk_screen; -} - diff --git a/gdk/win32/gdkprivate-win32.h b/gdk/win32/gdkprivate-win32.h index a14f192763..384167ee2b 100644 --- a/gdk/win32/gdkprivate-win32.h +++ b/gdk/win32/gdkprivate-win32.h @@ -179,9 +179,6 @@ void gdk_win32_handle_table_insert (HANDLE *handle, gpointer data); void gdk_win32_handle_table_remove (HANDLE handle); -COLORREF _gdk_win32_colormap_color (GdkColormap *colormap, - gulong pixel); - HRGN _gdk_win32_cairo_region_to_hrgn (const cairo_region_t *region, gint x_origin, gint y_origin); diff --git a/gdk/win32/makefile.msc b/gdk/win32/makefile.msc index c87eeed92c..3dac7c69c3 100644 --- a/gdk/win32/makefile.msc +++ b/gdk/win32/makefile.msc @@ -32,7 +32,6 @@ all: \ gdk_win32_OBJECTS = \ gdkapplaunchcontext-win32.obj \ - gdkcolor-win32.obj \ gdkcursor-win32.obj \ gdkdnd-win32.obj \ gdkdisplay-win32.obj \ diff --git a/gdk/x11/Makefile.am b/gdk/x11/Makefile.am index f0d45c2d9c..6344754597 100644 --- a/gdk/x11/Makefile.am +++ b/gdk/x11/Makefile.am @@ -21,7 +21,6 @@ libgdk_x11_la_SOURCES = \ gdkapplaunchcontext-x11.c \ gdkasync.c \ gdkasync.h \ - gdkcolor-x11.c \ gdkcursor-x11.c \ gdkdevice-core.h \ gdkdevice-core.c \ diff --git a/gdk/x11/gdkcolor-x11.c b/gdk/x11/gdkcolor-x11.c deleted file mode 100644 index 848dcc2a41..0000000000 --- a/gdk/x11/gdkcolor-x11.c +++ /dev/null @@ -1,1168 +0,0 @@ -/* GDK - The GIMP Drawing Kit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -/* - * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS - * file for a list of people on the GTK+ Team. See the ChangeLog - * files for a list of changes. These files are distributed with - * GTK+ at ftp://ftp.gtk.org/pub/gtk/. - */ - -#include "config.h" -#include - -#include "gdkcolor.h" -#include "gdkinternals.h" -#include "gdkx.h" -#include "gdkprivate-x11.h" -#include "gdkscreen-x11.h" - - -typedef struct _GdkColormapPrivateX11 GdkColormapPrivateX11; - -struct _GdkColormapPrivateX11 -{ - GdkScreen *screen; - Colormap xcolormap; - gint private_val; - - GHashTable *hash; - GdkColorInfo *info; - time_t last_sync_time; - - gboolean foreign; -}; - -#define GDK_COLORMAP_PRIVATE_DATA(cmap) ((GdkColormapPrivateX11 *) GDK_COLORMAP (cmap)->windowing_data) - -static gint gdk_colormap_match_color (GdkColormap *cmap, - GdkColor *color, - const gchar *available); -static void gdk_colormap_add (GdkColormap *cmap); -static void gdk_colormap_remove (GdkColormap *cmap); - -static GdkColormap *gdk_colormap_lookup (GdkScreen *screen, - Colormap xcolormap); - -static guint gdk_colormap_hash (Colormap *cmap); -static gboolean gdk_colormap_equal (Colormap *a, - Colormap *b); -static void gdk_colormap_sync (GdkColormap *colormap, - gboolean force); - -static void gdk_colormap_finalize (GObject *object); - -static void gdk_colormap_change (GdkColormap *colormap, - gint ncolors); - -G_DEFINE_TYPE (GdkColormap, gdk_colormap, G_TYPE_OBJECT) - -static void -gdk_colormap_init (GdkColormap *colormap) -{ - GdkColormapPrivateX11 *private; - - private = G_TYPE_INSTANCE_GET_PRIVATE (colormap, GDK_TYPE_COLORMAP, - GdkColormapPrivateX11); - - colormap->windowing_data = private; - - private->screen = NULL; - private->hash = NULL; - private->last_sync_time = 0; - private->info = NULL; - - colormap->size = 0; - colormap->colors = NULL; -} - -static void -gdk_colormap_class_init (GdkColormapClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->finalize = gdk_colormap_finalize; - - g_type_class_add_private (object_class, sizeof (GdkColormapPrivateX11)); -} - -static void -gdk_colormap_finalize (GObject *object) -{ - GdkColormap *colormap = GDK_COLORMAP (object); - GdkColormapPrivateX11 *private = GDK_COLORMAP_PRIVATE_DATA (colormap); - - gdk_colormap_remove (colormap); - - if (!private->screen->closed && !private->foreign) - XFreeColormap (GDK_SCREEN_XDISPLAY (private->screen), private->xcolormap); - - if (private->hash) - g_hash_table_destroy (private->hash); - - g_free (private->info); - g_free (colormap->colors); - - G_OBJECT_CLASS (gdk_colormap_parent_class)->finalize (object); -} - -/** - * gdk_colormap_new: - * @visual: a #GdkVisual. - * @allocate: if %TRUE, the newly created colormap will be - * a private colormap, and all colors in it will be - * allocated for the applications use. - * - * Creates a new colormap for the given visual. - * - * Return value: the new #GdkColormap. - **/ -GdkColormap* -gdk_colormap_new (GdkVisual *visual, - gboolean allocate) -{ - GdkColormap *colormap; - GdkColormapPrivateX11 *private; - Visual *xvisual; - Display *xdisplay; - Window xrootwin; - int size; - int i; - - /* FIXME when object properties settle down, there needs to be some - * kind of default construction (and construct-only arguments) - */ - - g_return_val_if_fail (GDK_IS_VISUAL (visual), NULL); - - colormap = g_object_new (GDK_TYPE_COLORMAP, NULL); - private = GDK_COLORMAP_PRIVATE_DATA (colormap); - - colormap->visual = visual; - private->screen = gdk_visual_get_screen (visual); - - xvisual = gdk_x11_visual_get_xvisual (visual); - xdisplay = GDK_SCREEN_XDISPLAY (private->screen); - xrootwin = GDK_SCREEN_XROOTWIN (private->screen); - - colormap->size = visual->colormap_size; - - switch (visual->type) - { - case GDK_VISUAL_GRAYSCALE: - case GDK_VISUAL_PSEUDO_COLOR: - private->info = g_new0 (GdkColorInfo, colormap->size); - colormap->colors = g_new (GdkColor, colormap->size); - - private->hash = g_hash_table_new ((GHashFunc) gdk_color_hash, - (GEqualFunc) gdk_color_equal); - - private->private_val = allocate; - private->xcolormap = XCreateColormap (xdisplay, xrootwin, - xvisual, (allocate) ? (AllocAll) : (AllocNone)); - - if (allocate) - { - GdkVisual *system_visual; - XColor *default_colors; - gint n_default_colors; - - system_visual = gdk_screen_get_system_visual (private->screen); - n_default_colors = MIN (system_visual->colormap_size, colormap->size); - - default_colors = g_new (XColor, colormap->size); - - for (i = 0; i < n_default_colors; i++) - default_colors[i].pixel = i; - - XQueryColors (xdisplay, - DefaultColormapOfScreen (GDK_SCREEN_X11 (private->screen)->xscreen), - default_colors, n_default_colors); - - for (i = 0; i < n_default_colors; i++) - { - colormap->colors[i].pixel = default_colors[i].pixel; - colormap->colors[i].red = default_colors[i].red; - colormap->colors[i].green = default_colors[i].green; - colormap->colors[i].blue = default_colors[i].blue; - } - - gdk_colormap_change (colormap, n_default_colors); - - g_free (default_colors); - } - break; - - case GDK_VISUAL_DIRECT_COLOR: - private->private_val = TRUE; - private->xcolormap = XCreateColormap (xdisplay, xrootwin, - xvisual, AllocAll); - colormap->colors = g_new (GdkColor, colormap->size); - - size = 1 << visual->red_prec; - for (i = 0; i < size; i++) - colormap->colors[i].red = i * 65535 / (size - 1); - - size = 1 << visual->green_prec; - for (i = 0; i < size; i++) - colormap->colors[i].green = i * 65535 / (size - 1); - - size = 1 << visual->blue_prec; - for (i = 0; i < size; i++) - colormap->colors[i].blue = i * 65535 / (size - 1); - - gdk_colormap_change (colormap, colormap->size); - break; - - case GDK_VISUAL_STATIC_GRAY: - case GDK_VISUAL_STATIC_COLOR: - private->private_val = FALSE; - private->xcolormap = XCreateColormap (xdisplay, xrootwin, - xvisual, AllocNone); - - colormap->colors = g_new (GdkColor, colormap->size); - gdk_colormap_sync (colormap, TRUE); - break; - - case GDK_VISUAL_TRUE_COLOR: - private->private_val = FALSE; - private->xcolormap = XCreateColormap (xdisplay, xrootwin, - xvisual, AllocNone); - break; - } - - gdk_colormap_add (colormap); - - return colormap; -} - -static void -gdk_colormap_sync_palette (GdkColormap *colormap) -{ - GdkColormapPrivateX11 *private = GDK_COLORMAP_PRIVATE_DATA (colormap); - XColor *xpalette; - gint nlookup; - gint i; - - nlookup = 0; - xpalette = g_new (XColor, colormap->size); - - for (i = 0; i < colormap->size; i++) - { - if (!private->info || private->info[i].ref_count == 0) - { - xpalette[nlookup].pixel = i; - xpalette[nlookup].red = 0; - xpalette[nlookup].green = 0; - xpalette[nlookup].blue = 0; - nlookup++; - } - } - - XQueryColors (GDK_SCREEN_XDISPLAY (private->screen), - private->xcolormap, xpalette, nlookup); - - for (i = 0; i < nlookup; i++) - { - gulong pixel = xpalette[i].pixel; - colormap->colors[pixel].pixel = pixel; - colormap->colors[pixel].red = xpalette[i].red; - colormap->colors[pixel].green = xpalette[i].green; - colormap->colors[pixel].blue = xpalette[i].blue; - } - - g_free (xpalette); -} - -static void -gdk_colormap_sync_direct_color (GdkColormap *colormap) -{ - GdkColormapPrivateX11 *private = GDK_COLORMAP_PRIVATE_DATA (colormap); - GdkVisual *visual = colormap->visual; - XColor *xpalette; - gint i; - - xpalette = g_new (XColor, colormap->size); - - for (i = 0; i < colormap->size; i++) - { - xpalette[i].pixel = - (((i << visual->red_shift) & visual->red_mask) | - ((i << visual->green_shift) & visual->green_mask) | - ((i << visual->blue_shift) & visual->blue_mask)); - } - - XQueryColors (GDK_SCREEN_XDISPLAY (private->screen), - private->xcolormap, xpalette, colormap->size); - - for (i = 0; i < colormap->size; i++) - { - colormap->colors[i].pixel = xpalette[i].pixel; - colormap->colors[i].red = xpalette[i].red; - colormap->colors[i].green = xpalette[i].green; - colormap->colors[i].blue = xpalette[i].blue; - } - - g_free (xpalette); -} - -#define MIN_SYNC_TIME 2 - -static void -gdk_colormap_sync (GdkColormap *colormap, - gboolean force) -{ - time_t current_time; - GdkColormapPrivateX11 *private = GDK_COLORMAP_PRIVATE_DATA (colormap); - - g_return_if_fail (GDK_IS_COLORMAP (colormap)); - - if (private->screen->closed) - return; - - current_time = time (NULL); - if (!force && ((current_time - private->last_sync_time) < MIN_SYNC_TIME)) - return; - - private->last_sync_time = current_time; - - if (colormap->visual->type == GDK_VISUAL_DIRECT_COLOR) - gdk_colormap_sync_direct_color (colormap); - else - gdk_colormap_sync_palette (colormap); -} - -/* - * gdk_colormap_change: - * @colormap: a #GdkColormap. - * @ncolors: the number of colors to change. - * - * Changes the value of the first @ncolors in a private colormap - * to match the values in the colors - * array in the colormap. This function is obsolete and - * should not be used. - */ -static void -gdk_colormap_change (GdkColormap *colormap, - gint ncolors) -{ - GdkColormapPrivateX11 *private; - GdkVisual *visual; - XColor *palette; - Display *xdisplay; - gint shift; - int max_colors; - int size; - int i; - - g_return_if_fail (GDK_IS_COLORMAP (colormap)); - - private = GDK_COLORMAP_PRIVATE_DATA (colormap); - - if (private->screen->closed) - return; - - xdisplay = GDK_SCREEN_XDISPLAY (private->screen); - palette = g_new (XColor, ncolors); - - switch (colormap->visual->type) - { - case GDK_VISUAL_GRAYSCALE: - case GDK_VISUAL_PSEUDO_COLOR: - for (i = 0; i < ncolors; i++) - { - palette[i].pixel = colormap->colors[i].pixel; - palette[i].red = colormap->colors[i].red; - palette[i].green = colormap->colors[i].green; - palette[i].blue = colormap->colors[i].blue; - palette[i].flags = DoRed | DoGreen | DoBlue; - } - - XStoreColors (xdisplay, private->xcolormap, palette, ncolors); - break; - - case GDK_VISUAL_DIRECT_COLOR: - visual = colormap->visual; - - shift = visual->red_shift; - max_colors = 1 << visual->red_prec; - size = (ncolors < max_colors) ? (ncolors) : (max_colors); - - for (i = 0; i < size; i++) - { - palette[i].pixel = i << shift; - palette[i].red = colormap->colors[i].red; - palette[i].flags = DoRed; - } - - XStoreColors (xdisplay, private->xcolormap, palette, size); - - shift = visual->green_shift; - max_colors = 1 << visual->green_prec; - size = (ncolors < max_colors) ? (ncolors) : (max_colors); - - for (i = 0; i < size; i++) - { - palette[i].pixel = i << shift; - palette[i].green = colormap->colors[i].green; - palette[i].flags = DoGreen; - } - - XStoreColors (xdisplay, private->xcolormap, palette, size); - - shift = visual->blue_shift; - max_colors = 1 << visual->blue_prec; - size = (ncolors < max_colors) ? (ncolors) : (max_colors); - - for (i = 0; i < size; i++) - { - palette[i].pixel = i << shift; - palette[i].blue = colormap->colors[i].blue; - palette[i].flags = DoBlue; - } - - XStoreColors (xdisplay, private->xcolormap, palette, size); - break; - - default: - break; - } - - g_free (palette); -} - -/** - * gdk_colormap_free_colors: - * @colormap: a #GdkColormap. - * @colors: the colors to free. - * @n_colors: the number of colors in @colors. - * - * Frees previously allocated colors. - **/ -void -gdk_colormap_free_colors (GdkColormap *colormap, - const GdkColor *colors, - gint n_colors) -{ - GdkColormapPrivateX11 *private; - gulong *pixels; - gint npixels = 0; - gint i; - - g_return_if_fail (GDK_IS_COLORMAP (colormap)); - g_return_if_fail (colors != NULL); - - private = GDK_COLORMAP_PRIVATE_DATA (colormap); - - if ((colormap->visual->type != GDK_VISUAL_PSEUDO_COLOR) && - (colormap->visual->type != GDK_VISUAL_GRAYSCALE)) - return; - - pixels = g_new (gulong, n_colors); - - for (i = 0; i < n_colors; i++) - { - gulong pixel = colors[i].pixel; - - if (private->info[pixel].ref_count) - { - private->info[pixel].ref_count--; - - if (private->info[pixel].ref_count == 0) - { - pixels[npixels++] = pixel; - if (!(private->info[pixel].flags & GDK_COLOR_WRITEABLE)) - g_hash_table_remove (private->hash, &colormap->colors[pixel]); - private->info[pixel].flags = 0; - } - } - } - - if (npixels && !private->private_val && !private->screen->closed) - XFreeColors (GDK_SCREEN_XDISPLAY (private->screen), private->xcolormap, - pixels, npixels, 0); - - g_free (pixels); -} - -/******************** - * Color allocation * - ********************/ - -/* Try to allocate a single color using XAllocColor. If it succeeds, - * cache the result in our colormap, and store in ret. - */ -static gboolean -gdk_colormap_alloc1 (GdkColormap *colormap, - const GdkColor *color, - GdkColor *ret) -{ - GdkColormapPrivateX11 *private; - XColor xcolor; - - private = GDK_COLORMAP_PRIVATE_DATA (colormap); - - xcolor.red = color->red; - xcolor.green = color->green; - xcolor.blue = color->blue; - xcolor.pixel = color->pixel; - xcolor.flags = DoRed | DoGreen | DoBlue; - - if (XAllocColor (GDK_SCREEN_XDISPLAY (private->screen), private->xcolormap, &xcolor)) - { - ret->pixel = xcolor.pixel; - ret->red = xcolor.red; - ret->green = xcolor.green; - ret->blue = xcolor.blue; - - if (ret->pixel < colormap->size) - { - if (private->info[ret->pixel].ref_count) /* got a duplicate */ - { - XFreeColors (GDK_SCREEN_XDISPLAY (private->screen), private->xcolormap, - &xcolor.pixel, 1, 0); - private->info[ret->pixel].ref_count++; - } - else - { - colormap->colors[ret->pixel] = *color; - colormap->colors[ret->pixel].pixel = ret->pixel; - private->info[ret->pixel].ref_count = 1; - - g_hash_table_insert (private->hash, - &colormap->colors[ret->pixel], - &colormap->colors[ret->pixel]); - } - } - return TRUE; - } - else - { - return FALSE; - } -} - -static gint -gdk_colormap_alloc_colors_writeable (GdkColormap *colormap, - GdkColor *colors, - gint ncolors, - gboolean writeable, - gboolean best_match, - gboolean *success) -{ - GdkColormapPrivateX11 *private; - gulong *pixels; - Status status; - gint i, index; - - private = GDK_COLORMAP_PRIVATE_DATA (colormap); - - if (private->private_val) - { - index = 0; - for (i = 0; i < ncolors; i++) - { - while ((index < colormap->size) && (private->info[index].ref_count != 0)) - index++; - - if (index < colormap->size) - { - colors[i].pixel = index; - success[i] = TRUE; - private->info[index].ref_count++; - private->info[i].flags |= GDK_COLOR_WRITEABLE; - } - else - break; - } - return ncolors - i; - } - else - { - pixels = g_new (gulong, ncolors); - /* Allocation of a writeable color cells */ - - status = XAllocColorCells (GDK_SCREEN_XDISPLAY (private->screen), private->xcolormap, - FALSE, NULL, 0, pixels, ncolors); - if (status) - { - for (i = 0; i < ncolors; i++) - { - colors[i].pixel = pixels[i]; - success[i] = TRUE; - private->info[pixels[i]].ref_count++; - private->info[pixels[i]].flags |= GDK_COLOR_WRITEABLE; - } - } - - g_free (pixels); - - return status ? 0 : ncolors; - } -} - -static gint -gdk_colormap_alloc_colors_private (GdkColormap *colormap, - GdkColor *colors, - gint ncolors, - gboolean writeable, - gboolean best_match, - gboolean *success) -{ - GdkColormapPrivateX11 *private; - gint i, index; - XColor *store = g_new (XColor, ncolors); - gint nstore = 0; - gint nremaining = 0; - - private = GDK_COLORMAP_PRIVATE_DATA (colormap); - - /* First, store the colors we have room for */ - - index = 0; - for (i = 0; i < ncolors; i++) - { - if (!success[i]) - { - while ((index < colormap->size) && (private->info[index].ref_count != 0)) - index++; - - if (index < colormap->size) - { - store[nstore].red = colors[i].red; - store[nstore].blue = colors[i].blue; - store[nstore].green = colors[i].green; - store[nstore].pixel = index; - store[nstore].flags = DoRed | DoGreen | DoBlue; - nstore++; - - success[i] = TRUE; - colors[i].pixel = index; - - colormap->colors[index] = colors[i]; - private->info[index].ref_count++; - - g_hash_table_insert (private->hash, - &colormap->colors[index], - &colormap->colors[index]); - } - else - nremaining++; - } - } - - XStoreColors (GDK_SCREEN_XDISPLAY (private->screen), private->xcolormap, - store, nstore); - g_free (store); - - if (nremaining > 0 && best_match) - { - /* Get best matches for remaining colors */ - - gchar *available = g_new (gchar, colormap->size); - for (i = 0; i < colormap->size; i++) - available[i] = !(private->info[i].flags & GDK_COLOR_WRITEABLE); - - for (i = 0; i < ncolors; i++) - { - if (!success[i]) - { - index = gdk_colormap_match_color (colormap, - &colors[i], - available); - if (index != -1) - { - colors[i] = colormap->colors[index]; - private->info[index].ref_count++; - - success[i] = TRUE; - nremaining--; - } - } - } - g_free (available); - } - - return nremaining; -} - -static gint -gdk_colormap_alloc_colors_shared (GdkColormap *colormap, - GdkColor *colors, - gint ncolors, - gboolean writeable, - gboolean best_match, - gboolean *success) -{ - GdkColormapPrivateX11 *private; - gint i, index; - gint nremaining = 0; - gint nfailed = 0; - - private = GDK_COLORMAP_PRIVATE_DATA (colormap); - - for (i = 0; i < ncolors; i++) - { - if (!success[i]) - { - if (gdk_colormap_alloc1 (colormap, &colors[i], &colors[i])) - success[i] = TRUE; - else - nremaining++; - } - } - - - if (nremaining > 0 && best_match) - { - gchar *available = g_new (gchar, colormap->size); - for (i = 0; i < colormap->size; i++) - available[i] = ((private->info[i].ref_count == 0) || - !(private->info[i].flags & GDK_COLOR_WRITEABLE)); - gdk_colormap_sync (colormap, FALSE); - - while (nremaining > 0) - { - for (i = 0; i < ncolors; i++) - { - if (!success[i]) - { - index = gdk_colormap_match_color (colormap, &colors[i], available); - if (index != -1) - { - if (private->info[index].ref_count) - { - private->info[index].ref_count++; - colors[i] = colormap->colors[index]; - success[i] = TRUE; - nremaining--; - } - else - { - if (gdk_colormap_alloc1 (colormap, - &colormap->colors[index], - &colors[i])) - { - success[i] = TRUE; - nremaining--; - break; - } - else - { - available[index] = FALSE; - } - } - } - else - { - nfailed++; - nremaining--; - success[i] = 2; /* flag as permanent failure */ - } - } - } - } - g_free (available); - } - - /* Change back the values we flagged as permanent failures */ - if (nfailed > 0) - { - for (i = 0; i < ncolors; i++) - if (success[i] == 2) - success[i] = FALSE; - nremaining = nfailed; - } - - return nremaining; -} - -static gint -gdk_colormap_alloc_colors_pseudocolor (GdkColormap *colormap, - GdkColor *colors, - gint ncolors, - gboolean writeable, - gboolean best_match, - gboolean *success) -{ - GdkColormapPrivateX11 *private; - GdkColor *lookup_color; - gint i; - gint nremaining = 0; - - private = GDK_COLORMAP_PRIVATE_DATA (colormap); - - /* Check for an exact match among previously allocated colors */ - - for (i = 0; i < ncolors; i++) - { - if (!success[i]) - { - lookup_color = g_hash_table_lookup (private->hash, &colors[i]); - if (lookup_color) - { - private->info[lookup_color->pixel].ref_count++; - colors[i].pixel = lookup_color->pixel; - success[i] = TRUE; - } - else - nremaining++; - } - } - - /* If that failed, we try to allocate a new color, or approxmiate - * with what we can get if best_match is TRUE. - */ - if (nremaining > 0) - { - if (private->private_val) - return gdk_colormap_alloc_colors_private (colormap, colors, ncolors, writeable, best_match, success); - else - return gdk_colormap_alloc_colors_shared (colormap, colors, ncolors, writeable, best_match, success); - } - else - return 0; -} - -/** - * gdk_colormap_alloc_colors: - * @colormap: a #GdkColormap. - * @colors: The color values to allocate. On return, the pixel - * values for allocated colors will be filled in. - * @n_colors: The number of colors in @colors. - * @writeable: this parameter has no effect, and it's here for mere - * compatibility. - * @best_match: If %TRUE, GDK will attempt to do matching against - * existing colors if the colors cannot be allocated as requested. - * @success: An array of length @ncolors. On return, this - * indicates whether the corresponding color in @colors was - * successfully allocated or not. - * - * Allocates colors from a colormap. - * - * Return value: The number of colors that were not successfully - * allocated. - **/ -gint -gdk_colormap_alloc_colors (GdkColormap *colormap, - GdkColor *colors, - gint n_colors, - gboolean writeable, - gboolean best_match, - gboolean *success) -{ - GdkColormapPrivateX11 *private; - GdkVisual *visual; - gint i; - gint nremaining = 0; - XColor xcolor; - - g_return_val_if_fail (GDK_IS_COLORMAP (colormap), n_colors); - g_return_val_if_fail (colors != NULL, n_colors); - g_return_val_if_fail (success != NULL, n_colors); - - private = GDK_COLORMAP_PRIVATE_DATA (colormap); - - if (private->screen->closed) - return n_colors; - - for (i = 0; i < n_colors; i++) - success[i] = FALSE; - - switch (colormap->visual->type) - { - case GDK_VISUAL_PSEUDO_COLOR: - case GDK_VISUAL_GRAYSCALE: - if (writeable) - return gdk_colormap_alloc_colors_writeable (colormap, colors, n_colors, - writeable, best_match, success); - else - return gdk_colormap_alloc_colors_pseudocolor (colormap, colors, n_colors, - writeable, best_match, success); - break; - - case GDK_VISUAL_DIRECT_COLOR: - case GDK_VISUAL_TRUE_COLOR: - visual = colormap->visual; - - for (i = 0; i < n_colors; i++) - { - /* If bits not used for color are used for something other than padding, - * it's likely alpha, so we set them to 1s. - */ - guint padding, unused; - - /* Shifting by >= width-of-type isn't defined in C */ - if (visual->depth >= 32) - padding = 0; - else - padding = ((~(guint32)0)) << visual->depth; - - unused = ~ (visual->red_mask | visual->green_mask | visual->blue_mask | padding); - - colors[i].pixel = (unused + - ((colors[i].red >> (16 - visual->red_prec)) << visual->red_shift) + - ((colors[i].green >> (16 - visual->green_prec)) << visual->green_shift) + - ((colors[i].blue >> (16 - visual->blue_prec)) << visual->blue_shift)); - success[i] = TRUE; - } - break; - case GDK_VISUAL_STATIC_GRAY: - case GDK_VISUAL_STATIC_COLOR: - for (i = 0; i < n_colors; i++) - { - xcolor.red = colors[i].red; - xcolor.green = colors[i].green; - xcolor.blue = colors[i].blue; - xcolor.pixel = colors[i].pixel; - xcolor.flags = DoRed | DoGreen | DoBlue; - - if (XAllocColor (GDK_SCREEN_XDISPLAY (private->screen), private->xcolormap, &xcolor)) - { - colors[i].pixel = xcolor.pixel; - success[i] = TRUE; - } - else - nremaining++; - } - break; - } - return nremaining; -} - -/** - * gdk_x11_colormap_foreign_new: - * @visual: a #GdkVisual - * @xcolormap: The XID of a colormap with visual @visual - * - * If xcolormap refers to a colormap previously known to GTK+, - * returns a new reference to the existing #GdkColormap object, - * otherwise creates a new GdkColormap object and returns that - * - * Return value: the #GdkColormap object for @xcolormap. - * Free with g_object_unref(). Note that for colormap created - * with gdk_x11_colormap_foreign_new(), unref'ing the last - * reference to the object will only free the #GdkColoramp - * object and not call XFreeColormap() - * - * Since: 2.2 - **/ -GdkColormap * -gdk_x11_colormap_foreign_new (GdkVisual *visual, - Colormap xcolormap) -{ - GdkColormap *colormap; - GdkScreen *screen; - GdkColormapPrivateX11 *private; - - g_return_val_if_fail (GDK_IS_VISUAL (visual), NULL); - g_return_val_if_fail (xcolormap != None, NULL); - - screen = gdk_visual_get_screen (visual); - - colormap = gdk_colormap_lookup (screen, xcolormap); - if (colormap) - return g_object_ref (colormap); - - colormap = g_object_new (GDK_TYPE_COLORMAP, NULL); - private = GDK_COLORMAP_PRIVATE_DATA (colormap); - - colormap->visual = visual; - - private->screen = screen; - private->xcolormap = xcolormap; - private->private_val = FALSE; - private->foreign = TRUE; - - colormap->size = visual->colormap_size; - - switch (colormap->visual->type) - { - case GDK_VISUAL_GRAYSCALE: - case GDK_VISUAL_PSEUDO_COLOR: - private->info = g_new0 (GdkColorInfo, colormap->size); - private->hash = g_hash_table_new ((GHashFunc) gdk_color_hash, - (GEqualFunc) gdk_color_equal); - /* Fall through */ - case GDK_VISUAL_STATIC_GRAY: - case GDK_VISUAL_STATIC_COLOR: - case GDK_VISUAL_DIRECT_COLOR: - colormap->colors = g_new (GdkColor, colormap->size); - gdk_colormap_sync (colormap, TRUE); - - case GDK_VISUAL_TRUE_COLOR: - break; - } - - gdk_colormap_add (colormap); - - return colormap; - -} - -static gint -gdk_colormap_match_color (GdkColormap *cmap, - GdkColor *color, - const gchar *available) -{ - GdkColor *colors; - guint sum, max; - gint rdiff, gdiff, bdiff; - gint i, index; - - colors = cmap->colors; - max = 3 * (65536); - index = -1; - - for (i = 0; i < cmap->size; i++) - { - if ((!available) || (available && available[i])) - { - rdiff = (color->red - colors[i].red); - gdiff = (color->green - colors[i].green); - bdiff = (color->blue - colors[i].blue); - - sum = ABS (rdiff) + ABS (gdiff) + ABS (bdiff); - - if (sum < max) - { - index = i; - max = sum; - } - } - } - - return index; -} - - -static GdkColormap* -gdk_colormap_lookup (GdkScreen *screen, - Colormap xcolormap) -{ - GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen); - - if (screen_x11->colormap_hash) - return g_hash_table_lookup (screen_x11->colormap_hash, &xcolormap); - else - return NULL; -} - -static void -gdk_colormap_add (GdkColormap *cmap) -{ - GdkScreenX11 *screen_x11; - GdkColormapPrivateX11 *private; - - private = GDK_COLORMAP_PRIVATE_DATA (cmap); - screen_x11 = GDK_SCREEN_X11 (private->screen); - - if (!screen_x11->colormap_hash) - screen_x11->colormap_hash = g_hash_table_new ((GHashFunc) gdk_colormap_hash, - (GEqualFunc) gdk_colormap_equal); - - g_hash_table_insert (screen_x11->colormap_hash, &private->xcolormap, cmap); -} - -static void -gdk_colormap_remove (GdkColormap *cmap) -{ - GdkScreenX11 *screen_x11; - GdkColormapPrivateX11 *private; - - private = GDK_COLORMAP_PRIVATE_DATA (cmap); - screen_x11 = GDK_SCREEN_X11 (private->screen); - - if (screen_x11->colormap_hash) - g_hash_table_remove (screen_x11->colormap_hash, &private->xcolormap); -} - -static guint -gdk_colormap_hash (Colormap *colormap) -{ - return *colormap; -} - -static gboolean -gdk_colormap_equal (Colormap *a, - Colormap *b) -{ - return (*a == *b); -} - -/** - * gdk_x11_colormap_get_xdisplay: - * @colormap: a #GdkColormap. - * - * Returns the display of a #GdkColormap. - * - * Return value: an Xlib Display*. - **/ -Display * -gdk_x11_colormap_get_xdisplay (GdkColormap *colormap) -{ - GdkColormapPrivateX11 *private; - - g_return_val_if_fail (GDK_IS_COLORMAP (colormap), NULL); - - private = GDK_COLORMAP_PRIVATE_DATA (colormap); - - return GDK_SCREEN_XDISPLAY (private->screen); -} - -/** - * gdk_x11_colormap_get_xcolormap: - * @colormap: a #GdkColormap. - * - * Returns the X colormap belonging to a #GdkColormap. - * - * Return value: an Xlib Colormap. - **/ -Colormap -gdk_x11_colormap_get_xcolormap (GdkColormap *colormap) -{ - GdkColormapPrivateX11 *private; - - g_return_val_if_fail (GDK_IS_COLORMAP (colormap), None); - - private = GDK_COLORMAP_PRIVATE_DATA (colormap); - - if (private->screen->closed) - return None; - else - return private->xcolormap; -} - -/** - * gdk_colormap_get_screen: - * @cmap: a #GdkColormap - * - * Gets the screen for which this colormap was created. - * - * Return value: the screen for which this colormap was created. - * - * Since: 2.2 - **/ -GdkScreen * -gdk_colormap_get_screen (GdkColormap *cmap) -{ - g_return_val_if_fail (GDK_IS_COLORMAP (cmap), NULL); - - return GDK_COLORMAP_PRIVATE_DATA (cmap)->screen; -} diff --git a/gdk/x11/gdkscreen-x11.c b/gdk/x11/gdkscreen-x11.c index 004011ab58..cacb144b93 100644 --- a/gdk/x11/gdkscreen-x11.c +++ b/gdk/x11/gdkscreen-x11.c @@ -295,8 +295,6 @@ gdk_screen_x11_finalize (GObject *object) g_free (screen_x11->window_manager_name); - g_hash_table_destroy (screen_x11->colormap_hash); - deinit_multihead (GDK_SCREEN (object)); G_OBJECT_CLASS (_gdk_screen_x11_parent_class)->finalize (object); diff --git a/gdk/x11/gdkscreen-x11.h b/gdk/x11/gdkscreen-x11.h index b0c6303903..07fec614a3 100644 --- a/gdk/x11/gdkscreen-x11.h +++ b/gdk/x11/gdkscreen-x11.h @@ -78,7 +78,6 @@ struct _GdkScreenX11 GdkVisualType available_types[6]; gint navailable_types; GHashTable *visual_hash; - GHashTable *colormap_hash; GdkVisual *rgba_visual; /* X settings */ diff --git a/gdk/x11/gdkx.h b/gdk/x11/gdkx.h index 99094a6335..a0cc7dd36a 100644 --- a/gdk/x11/gdkx.h +++ b/gdk/x11/gdkx.h @@ -37,8 +37,6 @@ G_BEGIN_DECLS Display *gdk_x11_drawable_get_xdisplay (GdkDrawable *drawable); XID gdk_x11_drawable_get_xid (GdkDrawable *drawable); GdkDrawable *gdk_x11_window_get_drawable_impl (GdkWindow *window); -Display *gdk_x11_colormap_get_xdisplay (GdkColormap *colormap); -Colormap gdk_x11_colormap_get_xcolormap (GdkColormap *colormap); Display *gdk_x11_cursor_get_xdisplay (GdkCursor *cursor); Cursor gdk_x11_cursor_get_xcursor (GdkCursor *cursor); Display *gdk_x11_display_get_xdisplay (GdkDisplay *display); @@ -57,8 +55,6 @@ Display *gdk_x11_get_default_xdisplay (void); gint gdk_x11_get_default_screen (void); #endif -#define GDK_COLORMAP_XDISPLAY(cmap) (gdk_x11_colormap_get_xdisplay (cmap)) -#define GDK_COLORMAP_XCOLORMAP(cmap) (gdk_x11_colormap_get_xcolormap (cmap)) #define GDK_CURSOR_XDISPLAY(cursor) (gdk_x11_cursor_get_xdisplay (cursor)) #define GDK_CURSOR_XCURSOR(cursor) (gdk_x11_cursor_get_xcursor (cursor)) @@ -105,9 +101,6 @@ GdkVisual* gdk_x11_screen_lookup_visual (GdkScreen *screen, GdkVisual* gdkx_visual_get (VisualID xvisualid); #endif -GdkColormap *gdk_x11_colormap_foreign_new (GdkVisual *visual, - Colormap xcolormap); - /* Return the Gdk* for a particular XID */ gpointer gdk_xid_table_lookup_for_display (GdkDisplay *display, XID xid); diff --git a/gtk/tests/defaultvalue.c b/gtk/tests/defaultvalue.c index 52848ebe6d..ace79ff109 100644 --- a/gtk/tests/defaultvalue.c +++ b/gtk/tests/defaultvalue.c @@ -84,8 +84,6 @@ test_type (gconstpointer data) if (g_type_is_a (type, GTK_TYPE_SETTINGS)) instance = g_object_ref (gtk_settings_get_default ()); - else if (g_type_is_a (type, GDK_TYPE_COLORMAP)) - instance = g_object_ref (gdk_colormap_new (gdk_visual_get_best (), TRUE)); else if (g_type_is_a (type, GDK_TYPE_WINDOW)) { GdkWindowAttr attributes;