]> Pileus Git - ~andy/gtk/blobdiff - gdk/gdkcc.c
[ Merges from gtk-1-2 ]
[~andy/gtk] / gdk / gdkcc.c
index df7c0a78331674dab2bcfd4caeadff83833a85ea..d1d1e754f713a984286d1ffea70a9d2eb0c235fd 100644 (file)
  *  cwikla@wri.com
  */
 
+/*
+ * Modified by the GTK+ Team and others 1997-1999.  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 <X11/Xlib.h>
 #include <stdlib.h>
@@ -485,10 +491,11 @@ init_palette (GdkColorContext *cc)
   
   if (cc->color_hash)
     {
-      /* XXX: quick-and-dirty way to remove everything */
-      
+      g_hash_table_foreach (cc->color_hash,
+                           free_hash_entry,
+                           NULL);
       g_hash_table_destroy (cc->color_hash);
-      cc->color_hash = g_hash_table_new (hash_color, compare_colors);
+      cc->color_hash = NULL;
     }
   
   cc->palette = NULL;
@@ -612,11 +619,6 @@ gdk_color_context_new (GdkVisual   *visual,
            g_message ("gdk_color_context_new: screen depth is %i, no. of colors is %i\n",
                       cc->visual->depth, cc->num_colors));
   
-  /* check if we need to initialize a hash table */
-  
-  if ((cc->mode == GDK_CC_MODE_STD_CMAP) || (cc->mode == GDK_CC_MODE_UNDEFINED))
-    cc->color_hash = g_hash_table_new (hash_color, compare_colors);
-  
   return (GdkColorContext *) cc;
 }
 
@@ -671,17 +673,9 @@ gdk_color_context_free (GdkColorContext *cc)
     gdk_colormap_unref (cc->colormap);
   
   /* free any palette that has been associated with this GdkColorContext */
-  
+
   init_palette (cc);
   
-  if (cc->color_hash)
-    {
-      g_hash_table_foreach (cc->color_hash,
-                           free_hash_entry,
-                           NULL);
-      g_hash_table_destroy (cc->color_hash);
-    }
-  
   g_free (cc);
 }
 
@@ -774,13 +768,14 @@ gdk_color_context_get_pixel (GdkColorContext *cc,
     default:
     {
       GdkColor color;
-      GdkColor *result;
+      GdkColor *result = NULL;
       
       color.red   = red;
       color.green = green;
       color.blue  = blue;
-      
-      result = g_hash_table_lookup (cc->color_hash, &color);
+
+      if (cc->color_hash)
+       result = g_hash_table_lookup (cc->color_hash, &color);
       
       if (!result)
        {
@@ -825,6 +820,9 @@ gdk_color_context_get_pixel (GdkColorContext *cc,
              
              cnew = g_new (GdkColor, 1);
              *cnew = color;
+             
+             if (!cc->color_hash)
+               cc->color_hash = g_hash_table_new (hash_color, compare_colors);
              g_hash_table_insert (cc->color_hash, cnew, cnew);
              
              cc->clut[cc->num_allocated] = color.pixel;
@@ -1483,20 +1481,7 @@ gdk_color_context_add_palette (GdkColorContext *cc,
   /* restore previous mode if we aren't adding a new palette */
   
   if (num_palette == 0)
-    {
-      /* GDK_CC_MODE_STD_CMAP uses a hash table, so we'd better initialize one */
-      
-      /* XXX: here, the hash table is already initialized */
-      
-      return 0;
-    }
-  
-  /* Initialize a hash table for this palette (we need one for allocating
-   * the pixels in the palette using the current settings)
-   */
-  
-  if (cc->color_hash == NULL)
-    cc->color_hash = g_hash_table_new (hash_color, compare_colors);
+    return 0;
   
   /* copy incoming palette */
   
@@ -1543,6 +1528,9 @@ gdk_color_context_add_palette (GdkColorContext *cc,
   
   if (cc->color_hash)
     {
+      g_hash_table_foreach (cc->color_hash,
+                           free_hash_entry,
+                           NULL);
       g_hash_table_destroy (cc->color_hash);
       cc->color_hash = NULL;
     }