Re: horrible things



On Wed, 2001-10-03 at 15:48, Owen Taylor wrote:
> 
> jacob berkman <jacob ximian com> writes:
> 
> > this patch allows the gtk docs to build w/o an X connection.
> 
> I'm not taking this patch. We'll need clean solutions of this
> sort of or GTK+-2.2, so I wouldn't object to clean patches,
> but I'm not going to put in bad hacks. You _can_ run Xvfb,
> after all.

here's a nicer version.  the colorsel fix is from the multihead branch,
and the preview fix is my own concoction.

it seems as GtkPreviewClass->info is pretty useless at this point, as
GdkRgb says about _get_colormap(), so i don't know if you'd rather have
this done in a better way.

i ran HEAD gimp and tried some of the filters which use GtkPreview, and
they didn't complain about anything.


thanks,
jacob
-- 
Index: gtkcolorsel.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkcolorsel.c,v
retrieving revision 1.78
diff -u -r1.78 gtkcolorsel.c
--- gtkcolorsel.c	2001/10/11 20:37:51	1.78
+++ gtkcolorsel.c	2001/10/22 21:59:53
@@ -143,6 +143,7 @@
 static void gtk_color_selection_class_init	(GtkColorSelectionClass	 *klass);
 static void gtk_color_selection_destroy		(GtkObject		 *object);
 static void gtk_color_selection_finalize        (GObject		 *object);
+static void gtk_color_selection_realize         (GtkWidget               *widget);
 static void update_color			(GtkColorSelection	 *colorsel);
 static void gtk_color_selection_set_property    (GObject                 *object,
 					         guint                    prop_id,
@@ -1648,10 +1649,11 @@
 {
   GtkObjectClass *object_class;
   GObjectClass *gobject_class;
-  gchar *palette;
+  GtkWidgetClass *widget_class;
   
   object_class = GTK_OBJECT_CLASS (klass);
   gobject_class = G_OBJECT_CLASS (klass);
+  widget_class = GTK_WIDGET_CLASS (klass);
   
   parent_class = gtk_type_class (GTK_TYPE_VBOX);
   
@@ -1661,6 +1663,8 @@
   gobject_class->set_property = gtk_color_selection_set_property;
   gobject_class->get_property = gtk_color_selection_get_property;
   
+  widget_class->realize = gtk_color_selection_realize;
+
   g_object_class_install_property (gobject_class,
                                    PROP_HAS_OPACITY_CONTROL,
                                    g_param_spec_boolean ("has_opacity_control",
@@ -1703,21 +1707,6 @@
                                                       _("Palette to use in the color selector"),
                                                       default_colors,
                                                       G_PARAM_READWRITE));
-
-  g_object_get (G_OBJECT (gtk_settings_get_default ()),
-                "gtk-color-palette",
-                &palette,
-                NULL);
-  
-  fill_palette_from_string (palette);
-  g_free (palette);
-
-  change_palette_hook = default_change_palette_func;
-  
-  g_signal_connect_data (G_OBJECT (gtk_settings_get_default ()),
-                         "notify::gtk-color-palette",
-                         G_CALLBACK (palette_change_notify_class),
-                         NULL, NULL, 0);
 }
 
 /* widget functions */
@@ -1875,16 +1864,6 @@
   
   gtk_widget_show_all (top_hbox);
 
-  /* Set default colors */
-
-  update_palette (colorsel);
-
-  priv->settings_connection = 
-    g_signal_connect_data (G_OBJECT (gtk_settings_get_default ()),
-                           "notify::gtk-color-palette",
-                           G_CALLBACK (palette_change_notify_instance),
-                           colorsel, NULL, 0);
-  
   /* hide unused stuff */
   
   if (priv->has_opacity == FALSE)
@@ -1942,6 +1921,40 @@
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
+static void
+gtk_color_selection_realize (GtkWidget *widget)
+{
+  GtkColorSelection *colorsel = GTK_COLOR_SELECTION (widget);
+  ColorSelectionPrivate *priv = colorsel->private_data;
+  gchar *palette;
+
+  g_object_get (G_OBJECT (gtk_settings_get_default ()),
+                "gtk-color-palette",
+                &palette,
+                NULL);
+  
+  fill_palette_from_string (palette);
+  g_free (palette);
+
+  change_palette_hook = default_change_palette_func;
+  
+  g_signal_connect_data (G_OBJECT (gtk_settings_get_default ()),
+                         "notify::gtk-color-palette",
+                         G_CALLBACK (palette_change_notify_class),
+                         NULL, NULL, 0);
+  
+  /* Set default colors */
+
+  update_palette (colorsel);
+  priv->settings_connection =
+    g_signal_connect_data (G_OBJECT (gtk_settings_get_default ()),
+			   "notify::gtk-color-palette",
+			   G_CALLBACK (palette_change_notify_instance),
+			   colorsel, NULL, 0);
+
+  if (GTK_WIDGET_CLASS (parent_class)->realize)
+    GTK_WIDGET_CLASS (parent_class)->realize (widget);
+}
 
 /**
  * gtk_color_selection_new:
Index: gtkpreview.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkpreview.c,v
retrieving revision 1.36
diff -u -r1.36 gtkpreview.c
--- gtkpreview.c	2001/07/18 23:39:23	1.36
+++ gtkpreview.c	2001/10/22 21:59:53
@@ -125,8 +125,6 @@
   klass->info.gamma = 1.0;
 
   gdk_rgb_init ();
-  klass->info.cmap = gdk_rgb_get_cmap ();
-  klass->info.visual = gdk_rgb_get_visual ();
 
   g_object_class_install_property (gobject_class,
                                    PROP_EXPAND,
@@ -313,7 +311,6 @@
 
   g_return_if_fail (GTK_IS_PREVIEW (preview));
   g_return_if_fail (data != NULL);
-  g_return_if_fail (preview_class->info.visual != NULL);
   
   bpp = (preview->type == GTK_PREVIEW_COLOR ? 3 : 1);
   rowstride = (preview->buffer_width * bpp + 3) & -4;
@@ -425,6 +422,9 @@
   if (!preview_class)
     preview_class = gtk_type_class (gtk_preview_get_type ());
 
+  if (!preview_class->info.visual)
+    preview_class->info.visual = gdk_rgb_get_visual ();
+
   return preview_class->info.visual;
 }
 
@@ -434,6 +434,9 @@
   if (!preview_class)
     preview_class = gtk_type_class (gtk_preview_get_type ());
 
+  if (!preview_class->info.cmap)
+    preview_class->info.cmap = gdk_rgb_get_cmap ();
+
   return preview_class->info.cmap;
 }
 
@@ -443,6 +446,12 @@
   if (!preview_class)
     preview_class = gtk_type_class (gtk_preview_get_type ());
 
+  if (!preview_class->info.visual)
+    preview_class->info.visual = gdk_rgb_get_visual ();
+
+  if (!preview_class->info.cmap)
+    preview_class->info.cmap = gdk_rgb_get_cmap ();
+
   return &preview_class->info;
 }
 
@@ -491,8 +500,8 @@
   attributes.y = widget->allocation.y + (widget->allocation.height - attributes.height) / 2;;
 
   attributes.wclass = GDK_INPUT_OUTPUT;
-  attributes.visual = preview_class->info.visual;
-  attributes.colormap = preview_class->info.cmap;
+  attributes.visual = gdk_rgb_get_visual ();
+  attributes.colormap = gdk_rgb_get_colormap ();
   attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
   attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]