]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkgc.c
Correctly select default printer when there is more than one (CUPS)
[~andy/gtk] / gtk / gtkgc.c
index 72f207b3757eac99a3e8c95955cc92bc64cc110b..15d863621fc7c1dac2b0d55bcb9f216661a0dd47 100644 (file)
@@ -2,21 +2,32 @@
  * 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 "gtkintl.h"
+#include "gtkalias.h"
 
 
 typedef struct _GtkGCKey       GtkGCKey;
@@ -44,19 +55,16 @@ 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;
-
+static GQuark quark_gtk_gc_drawable_ht = 0;
 
 GdkGC*
 gtk_gc_get (gint             depth,
@@ -89,22 +97,45 @@ 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_slice_free (GtkGCDrawable, drawable);
+}
+
+static GHashTable*
+gtk_gc_get_drawable_ht (GdkScreen *screen)
+{
+  GHashTable *ht = g_object_get_qdata (G_OBJECT (screen), quark_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_qdata_full (G_OBJECT (screen), 
+                              quark_gtk_gc_drawable_ht, ht, 
+                              (GDestroyNotify)g_hash_table_destroy);
+    }
+  
+  return ht;
+}
 
 static void
 gtk_gc_init (void)
 {
   initialize = FALSE;
 
+  quark_gtk_gc_drawable_ht = g_quark_from_static_string ("gtk-gc-drawable-ht");
+
   gc_cache = g_cache_new ((GCacheNewFunc) gtk_gc_new,
                          (GCacheDestroyFunc) gtk_gc_destroy,
                          (GCacheDupFunc) gtk_gc_key_dup,
                          (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*
@@ -112,11 +143,7 @@ gtk_gc_key_dup (GtkGCKey *key)
 {
   GtkGCKey *new_key;
 
-  if (!key_mem_chunk)
-    key_mem_chunk = g_mem_chunk_new ("key mem chunk", sizeof (GtkGCKey),
-                                    1024, G_ALLOC_AND_FREE);
-
-  new_key = g_chunk_new (GtkGCKey, key_mem_chunk);
+  new_key = g_slice_new (GtkGCKey);
 
   *new_key = *key;
 
@@ -126,7 +153,7 @@ gtk_gc_key_dup (GtkGCKey *key)
 static void
 gtk_gc_key_destroy (GtkGCKey *key)
 {
-  g_mem_chunk_free (key_mem_chunk, key);
+  g_slice_free (GtkGCKey, key);
 }
 
 static gpointer
@@ -135,20 +162,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 = g_slice_new (GtkGCDrawable);
       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 +188,7 @@ gtk_gc_new (gpointer key)
 static void
 gtk_gc_destroy (gpointer value)
 {
-  gdk_gc_destroy ((GdkGC*) value);
+  g_object_unref (value);
 }
 
 static guint
@@ -190,15 +222,15 @@ gtk_gc_key_hash (gpointer key)
     }
   if (keyval->mask & GDK_GC_TILE)
     {
-      hash_val += (glong) keyval->values.tile;
+      hash_val += (gintptr) keyval->values.tile;
     }
   if (keyval->mask & GDK_GC_STIPPLE)
     {
-      hash_val += (glong) keyval->values.stipple;
+      hash_val += (gintptr) keyval->values.stipple;
     }
   if (keyval->mask & GDK_GC_CLIP_MASK)
     {
-      hash_val += (glong) keyval->values.clip_mask;
+      hash_val += (gintptr) keyval->values.clip_mask;
     }
   if (keyval->mask & GDK_GC_SUBWINDOW)
     {
@@ -250,9 +282,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 +400,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"