GTK+ 1.2.10 style bug
- From: "Joe.C" <joe animeta com>
- To: gtk-devel-list gnome org
- Cc: Owen Taylor <otaylor redhat com>
- Subject: GTK+ 1.2.10 style bug
- Date: Thu, 06 Sep 2001 19:11:12 +0800
Hi,
I don't know if you are going to release 1.2.11,
but I think I'll report this bug anyway.
If we create a widget and change its style's
bg_pixmap and show it, after we remove the widget
from the container and add to another container, it
will crash. I've attached a small test program to
show the problem.
The problem is from 1.2.9, gtk_style_detach will
unreference the bg_pixmap. But when we re-attached
the style, the pixmap will be used again.
We can fix the problem by only unreference the
bg_pixmap when we destroy the style, or set the
bg_pixmap to NULL after we unreference it. I think
unreference when the style is destroyed is a better
idea. What's your opinion? I can create a patch if
you think it is OK.
Joe.C
==================================================
#include <gtk/gtk.h>
#include "marble.xpm"
GdkPixmap *pixmap, *bitmap;
GtkWidget *button;
GtkWidget *window, *fixed;
gboolean in_fixed = TRUE;
void ChangeBackground (GtkWidget *widget, GdkPixmap *pixmap)
{
GtkStyle *style;
style = gtk_widget_get_style (widget);
if (style->bg_pixmap[0] == pixmap)
return;
style = gtk_style_copy (style);
if (pixmap && pixmap != (GdkPixmap*)GDK_PARENT_RELATIVE)
gdk_pixmap_ref (pixmap);
if (style->bg_pixmap[0] && style->bg_pixmap[0] !=
(GdkPixmap*)GDK_PARENT_RELATIVE)
gdk_pixmap_unref (style->bg_pixmap[0]);
style->bg_pixmap[0] = pixmap;
gtk_widget_set_style (GTK_WIDGET(widget), style);
gtk_style_unref (style);
}
gboolean
on_button_press_event (GtkWidget *widget,
GdkEventButton *event,
gpointer data)
{
if (in_fixed) {
gtk_container_remove (GTK_CONTAINER(fixed), button);
in_fixed = FALSE;
} else {
gtk_widget_show (button);
gtk_fixed_put (GTK_FIXED (fixed), button, 10, 10);
in_fixed = TRUE;
}
}
int main (int argc, char *argv[])
{
gtk_init (&argc, &argv);
pixmap = gdk_pixmap_create_from_xpm_d (
NULL, &bitmap, NULL, granite07);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_policy (GTK_WINDOW (window), FALSE, FALSE, FALSE);
gtk_widget_set_name (window, "main window");
gtk_widget_set_usize (window, 200, 400);
gtk_widget_set_uposition (window, 450, 20);
fixed = gtk_fixed_new ();
gtk_widget_show (fixed);
gtk_container_add (GTK_CONTAINER (window), fixed);
button = gtk_event_box_new();
gtk_widget_ref (button);
gtk_object_set_data_full (GTK_OBJECT (fixed), "button", button,
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (button);
gtk_widget_set_usize (button, 100, 100);
gtk_fixed_put (GTK_FIXED (fixed), button, 10, 10);
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_FOCUS);
ChangeBackground (button, pixmap);
gtk_signal_connect (GTK_OBJECT (fixed), "button_press_event",
GTK_SIGNAL_FUNC (on_button_press_event), NULL);
gtk_widget_show (window);
gtk_main ();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]