]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkgc.c
Remove a leftover debugging envvar.
[~andy/gtk] / gtk / gtkgc.c
index 20dcc903310c5015e041281a696469a29e264304..09c5a62123b219804c05f1cf8712637b96b34ba4 100644 (file)
@@ -2,21 +2,31 @@
  * 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;
@@ -44,16 +54,15 @@ static gpointer  gtk_gc_new              (gpointer       key);
 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;
 
@@ -89,9 +98,33 @@ gtk_gc_release (GdkGC *gc)
   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;
 
@@ -101,10 +134,7 @@ gtk_gc_init ()
                          (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*
@@ -135,20 +165,25 @@ gtk_gc_new (gpointer key)
   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;
 }
@@ -156,7 +191,7 @@ gtk_gc_new (gpointer key)
 static void
 gtk_gc_destroy (gpointer value)
 {
-  gdk_gc_destroy ((GdkGC*) value);
+  g_object_unref (value);
 }
 
 static guint
@@ -250,9 +285,9 @@ gtk_gc_value_hash (gpointer value)
   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;
@@ -368,16 +403,18 @@ gtk_gc_key_compare (gpointer a,
   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"