* 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 Library General Public
+ * 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
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
*
- * You should have received a copy of the GNU Library General Public
+ * 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 "gtkgc.h"
+#include "gtkalias.h"
typedef struct _GtkGCKey GtkGCKey;
static void gtk_gc_destroy (gpointer value);
static guint gtk_gc_key_hash (gpointer key);
static guint gtk_gc_value_hash (gpointer value);
-static gint gtk_gc_key_compare (gpointer a,
+static gint gtk_gc_key_equal (gpointer a,
gpointer b);
static guint gtk_gc_drawable_hash (GtkGCDrawable *d);
-static gint gtk_gc_drawable_compare (GtkGCDrawable *a,
+static gint gtk_gc_drawable_equal (GtkGCDrawable *a,
GtkGCDrawable *b);
static gint initialize = TRUE;
static GCache *gc_cache = NULL;
-static GHashTable *gc_drawable_ht = NULL;
static GMemChunk *key_mem_chunk = NULL;
g_cache_remove (gc_cache, gc);
}
+static void
+free_gc_drawable (gpointer data)
+{
+ GtkGCDrawable *drawable = data;
+ g_object_unref (drawable->drawable);
+ g_free (drawable);
+}
+
+static GHashTable*
+gtk_gc_get_drawable_ht (GdkScreen *screen)
+{
+ GHashTable *ht = g_object_get_data (G_OBJECT (screen), "gtk-gc-drawable-ht");
+ if (!ht)
+ {
+ ht = g_hash_table_new_full ((GHashFunc) gtk_gc_drawable_hash,
+ (GEqualFunc) gtk_gc_drawable_equal,
+ NULL, free_gc_drawable);
+ g_object_set_data_full (G_OBJECT (screen),
+ "gtk-gc-drawable-ht", ht,
+ (GDestroyNotify)g_hash_table_destroy);
+ }
+
+ return ht;
+}
static void
-gtk_gc_init ()
+gtk_gc_init (void)
{
initialize = FALSE;
(GCacheDestroyFunc) gtk_gc_key_destroy,
(GHashFunc) gtk_gc_key_hash,
(GHashFunc) gtk_gc_value_hash,
- (GCompareFunc) gtk_gc_key_compare);
-
- gc_drawable_ht = g_hash_table_new ((GHashFunc) gtk_gc_drawable_hash,
- (GCompareFunc) gtk_gc_drawable_compare);
+ (GEqualFunc) gtk_gc_key_equal);
}
static GtkGCKey*
GtkGCKey *keyval;
GtkGCDrawable *drawable;
GdkGC *gc;
+ GHashTable *ht;
+ GdkScreen *screen;
keyval = key;
-
- drawable = g_hash_table_lookup (gc_drawable_ht, &keyval->depth);
+ screen = gdk_colormap_get_screen (keyval->colormap);
+
+ ht = gtk_gc_get_drawable_ht (screen);
+ drawable = g_hash_table_lookup (ht, &keyval->depth);
if (!drawable)
{
drawable = g_new (GtkGCDrawable, 1);
drawable->depth = keyval->depth;
- drawable->drawable = gdk_pixmap_new (NULL, 1, 1, drawable->depth);
-
- g_hash_table_insert (gc_drawable_ht, &drawable->depth, drawable);
+ drawable->drawable = gdk_pixmap_new (gdk_screen_get_root_window (screen),
+ 1, 1, drawable->depth);
+ g_hash_table_insert (ht, &drawable->depth, drawable);
}
gc = gdk_gc_new_with_values (drawable->drawable, &keyval->values, keyval->mask);
+ gdk_gc_set_colormap (gc, keyval->colormap);
return (gpointer) gc;
}
static void
gtk_gc_destroy (gpointer value)
{
- gdk_gc_destroy ((GdkGC*) value);
+ g_object_unref (value);
}
static guint
return (gulong) value;
}
-static gint
-gtk_gc_key_compare (gpointer a,
- gpointer b)
+static gboolean
+gtk_gc_key_equal (gpointer a,
+ gpointer b)
{
GtkGCKey *akey;
GtkGCKey *bkey;
return TRUE;
}
-
static guint
gtk_gc_drawable_hash (GtkGCDrawable *d)
{
return d->depth;
}
-static gint
-gtk_gc_drawable_compare (GtkGCDrawable *a,
- GtkGCDrawable *b)
+static gboolean
+gtk_gc_drawable_equal (GtkGCDrawable *a,
+ GtkGCDrawable *b)
{
return (a->depth == b->depth);
}
+
+#define __GTK_GC_C__
+#include "gtkaliasdef.c"