Re: gtk_type_init() with no X connection [was: Re: horrible things]
- From: jacob berkman <jacob ximian com>
- To: Owen Taylor <otaylor redhat com>
- Cc: gtk-devel-list gnome org
- Subject: Re: gtk_type_init() with no X connection [was: Re: horrible things]
- Date: 28 Oct 2001 11:00:33 -0500
On Sun, 2001-10-28 at 09:32, Owen Taylor wrote:
>
> jacob berkman <jacob ximian com> writes:
>
> > On Wed, 2001-10-24 at 21:15, Owen Taylor wrote:
> > >
> > > > > jacob berkman <jacob ximian com> writes:
> > > > >
> > > > > > this patch allows the gtk docs to build w/o an X connection.
> > >
> > > Looks like its definitely heading in the right direction.
>
> Returning NULL here is not a good at all since it will just
> segfault programs. Why don't you:
>
> - Remove the cmap and visual fields from GtkPreviewInfo
> - Add a quick entry to Changes-2.0.txt mentioning that
> - Make gtk_preview_get_cmap/visual return
> gdk_rgb_get_colormap(), gdk_rgb_get_visual().
> - Deprecate gtk_preview_get_cmap/visual.
because i didn't know that removing the fields from GtkPreviewInfo was
allowed :) fixed in new patch
> This doesn't work, does it? gtk_color_selection_set_change_palette_hook()
> could be (and probably will be) called before the first colorsell
> is realized.
correct - i didn't understand the code enough. fixed in new patch.
jacob
--
"Beat mixing is 10000 times more fun than even video games."
-- bt
Index: gtk/gtkpreview.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkpreview.c,v
retrieving revision 1.36
diff -u -r1.36 gtkpreview.c
--- gtk/gtkpreview.c 2001/07/18 23:39:23 1.36
+++ gtk/gtkpreview.c 2001/10/28 15:57:40
@@ -117,16 +117,11 @@
widget_class->size_allocate = gtk_preview_size_allocate;
widget_class->expose_event = gtk_preview_expose;
- klass->info.visual = NULL;
- klass->info.cmap = NULL;
-
klass->info.lookup = NULL;
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 +308,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;
@@ -422,19 +416,13 @@
GdkVisual*
gtk_preview_get_visual (void)
{
- if (!preview_class)
- preview_class = gtk_type_class (gtk_preview_get_type ());
-
- return preview_class->info.visual;
+ return gdk_rgb_get_visual ();
}
GdkColormap*
gtk_preview_get_cmap (void)
{
- if (!preview_class)
- preview_class = gtk_type_class (gtk_preview_get_type ());
-
- return preview_class->info.cmap;
+ return gdk_rgb_get_colormap ();
}
GtkPreviewInfo*
@@ -491,10 +479,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.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
- attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+ attributes_mask = GDK_WA_X | GDK_WA_Y;
widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
gdk_window_set_user_data (widget->window, widget);
Index: gtk/gtkpreview.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkpreview.h,v
retrieving revision 1.12
diff -u -r1.12 gtkpreview.h
--- gtk/gtkpreview.h 2001/02/03 01:09:40 1.12
+++ gtk/gtkpreview.h 2001/10/28 15:57:40
@@ -70,9 +70,6 @@
struct _GtkPreviewInfo
{
- GdkVisual *visual;
- GdkColormap *cmap;
-
guchar *lookup;
gdouble gamma;
@@ -125,8 +122,10 @@
void gtk_preview_set_reserved (gint nreserved);
void gtk_preview_set_dither (GtkPreview *preview,
GdkRgbDither dither);
+#ifndef GTK_DISABLE_DEPRECATED
GdkVisual* gtk_preview_get_visual (void);
GdkColormap* gtk_preview_get_cmap (void);
+#endif
GtkPreviewInfo* gtk_preview_get_info (void);
/* This function reinitializes the preview colormap and visual from
Index: gtk/gtkcolorsel.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkcolorsel.c,v
retrieving revision 1.78
diff -u -r1.78 gtkcolorsel.c
--- gtk/gtkcolorsel.c 2001/10/11 20:37:51 1.78
+++ gtk/gtkcolorsel.c 2001/10/28 15:57:41
@@ -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,
@@ -162,13 +163,15 @@
GdkColor *color);
static void gtk_color_selection_unset_palette_color (GtkColorSelection *colorsel,
gint index);
+static void default_change_palette_func (const GdkColor *colors,
+ gint n_colors);
static gpointer parent_class = NULL;
static guint color_selection_signals[LAST_SIGNAL] = { 0 };
static gchar* default_colors = "black:white:gray50:red:purple:blue:light blue:green:yellow:orange:lavender:brown:goldenrod4:dodger blue:pink:light green:gray10:gray30:gray75:gray90";
-static GtkColorSelectionChangePaletteFunc change_palette_hook = NULL;
+static GtkColorSelectionChangePaletteFunc change_palette_hook = default_change_palette_func;
static GdkColor current_colors[GTK_CUSTOM_PALETTE_WIDTH * GTK_CUSTOM_PALETTE_HEIGHT];
@@ -1648,10 +1651,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 +1665,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 +1709,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 +1866,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 +1923,43 @@
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;
+ static gboolean initialized = FALSE;
+
+ if (!initialized)
+ {
+ g_object_get (gtk_settings_get_default (),
+ "gtk-color-palette", &palette,
+ NULL);
+
+ fill_palette_from_string (palette);
+ g_free (palette);
+
+ g_signal_connect (gtk_settings_get_default (),
+ "notify::gtk-color-palette",
+ G_CALLBACK (palette_change_notify_class),
+ NULL);
+
+ initialized = TRUE;
+ }
+
+ /* Set default colors */
+
+ update_palette (colorsel);
+ priv->settings_connection =
+ g_signal_connect (gtk_settings_get_default (),
+ "notify::gtk-color-palette",
+ G_CALLBACK (palette_change_notify_instance),
+ colorsel);
+
+ if (GTK_WIDGET_CLASS (parent_class)->realize)
+ GTK_WIDGET_CLASS (parent_class)->realize (widget);
+}
/**
* gtk_color_selection_new:
Index: docs/Changes-2.0.txt
===================================================================
RCS file: /cvs/gnome/gtk+/docs/Changes-2.0.txt,v
retrieving revision 1.35
diff -u -r1.35 Changes-2.0.txt
--- docs/Changes-2.0.txt 2001/10/22 14:14:33 1.35
+++ docs/Changes-2.0.txt 2001/10/28 15:57:41
@@ -502,3 +502,9 @@
If you aren't using GDK and GTK+ functions from multiple threads,
there is no reason to call gdk_threads_init().
+
+* The GtkPreviewInfo struct has had its visual and colormap fields
+ removed. Also, gtk_preview_get_cmap() and gtk_preview_get_visual()
+ are deprecated, as GdkRgb works on any colormap and visual. You no
+ longer need to gtk_widget_push_cmap (gtk_preview_get_cmap ()) in
+ your code.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]