diff --git a/gtk/gtkcolorsel.c b/gtk/gtkcolorsel.c index 79618e74d8..a7240a66ee 100644 --- a/gtk/gtkcolorsel.c +++ b/gtk/gtkcolorsel.c @@ -1615,6 +1615,12 @@ gtk_color_selection_dialog_init (GtkColorSelectionDialog *colorseldiag) { GtkWidget *action_area, *frame; + gtk_widget_set_visual (GTK_WIDGET (colorseldiag), gdk_rgb_get_visual ()); + gtk_widget_set_colormap (GTK_WIDGET (colorseldiag), gdk_rgb_get_cmap ()); + + gtk_widget_push_visual (gdk_rgb_get_visual ()); + gtk_widget_push_colormap (gdk_rgb_get_cmap ()); + colorseldiag->main_vbox = gtk_vbox_new (FALSE, 10); gtk_container_set_border_width (GTK_CONTAINER (colorseldiag), 10); gtk_container_add (GTK_CONTAINER (colorseldiag), colorseldiag->main_vbox); @@ -1650,6 +1656,9 @@ gtk_color_selection_dialog_init (GtkColorSelectionDialog *colorseldiag) GTK_WIDGET_SET_FLAGS (colorseldiag->help_button, GTK_CAN_DEFAULT); gtk_box_pack_start (GTK_BOX (action_area), colorseldiag->help_button, TRUE, TRUE, 0); gtk_widget_show (colorseldiag->help_button); + + gtk_widget_pop_colormap (); + gtk_widget_pop_visual (); } GtkWidget * @@ -1657,14 +1666,8 @@ gtk_color_selection_dialog_new (const gchar *title) { GtkColorSelectionDialog *colorseldiag; - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - colorseldiag = gtk_type_new (gtk_color_selection_dialog_get_type ()); gtk_window_set_title (GTK_WINDOW (colorseldiag), title); - gtk_widget_pop_colormap (); - gtk_widget_pop_visual (); - return GTK_WIDGET (colorseldiag); } diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index 6bda63275f..b00272d14f 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -1015,19 +1015,11 @@ gtk_widget_init (GtkWidget *widget) colormap = gtk_widget_peek_colormap (); visual = gtk_widget_peek_visual (); - /* XXX - should we ref the colormap and visual, too? */ - if (colormap != gtk_widget_get_default_colormap ()) - { - /* gdk_colormap_ref (colormap); */ - gtk_object_set_data (GTK_OBJECT (widget), colormap_key, colormap); - } + gtk_widget_set_colormap (widget, colormap); if (visual != gtk_widget_get_default_visual ()) - { - /* gdk_visual_ref (visual); */ - gtk_object_set_data (GTK_OBJECT (widget), visual_key, visual); - } + gtk_widget_set_visual (widget, visual); } /***************************************** @@ -3912,6 +3904,59 @@ gtk_widget_get_visual (GtkWidget *widget) return gtk_widget_get_default_visual (); } +/***************************************** + * gtk_widget_set_colormap: + * Set the colormap for the widget to the given + * value. Widget must not have been previously + * realized. This probably should only be used + * from an init() function. + * arguments: + * widget: + * colormap: + * results: + *****************************************/ + +void +gtk_widget_set_colormap (GtkWidget *widget, GdkColormap *colormap) +{ + g_return_if_fail (widget != NULL); + g_return_if_fail (GTK_IS_WIDGET (widget)); + g_return_if_fail (!GTK_WIDGET_REALIZED (widget)); + g_return_if_fail (colormap != NULL); + + /* FIXME: reference count the colormap. + */ + + gtk_object_set_data (GTK_OBJECT (widget), + colormap_key, + colormap); +} + +/***************************************** + * gtk_widget_set_visual: + * Set the colormap for the widget to the given + * value. Widget must not have been previously + * realized. This probably should only be used + * from an init() function. + * arguments: + * widget: + * visual: + * results: + *****************************************/ + +void +gtk_widget_set_visual (GtkWidget *widget, GdkVisual *visual) +{ + g_return_if_fail (widget != NULL); + g_return_if_fail (GTK_IS_WIDGET (widget)); + g_return_if_fail (!GTK_WIDGET_REALIZED (widget)); + g_return_if_fail (visual != NULL); + + gtk_object_set_data (GTK_OBJECT (widget), + visual_key, + visual); +} + /***************************************** * gtk_widget_get_events: *