Minor bug in gtk_widget_reparent




Summary:

Buttons (and possibly other widgets) stays prelighted 
after beeing reparented from the clicked-callback.


Affected versions:

GTK 1.2.8 and possibly earlier versions to.


How to reproduce:

Create a button with a clicked-handler that creates a new toplevel 
window and reparent the button to this window.
When the button is clicked, it's reparented as expected, but 
stays in prelight state until the mouse is moved over it again. 

I guess this is becaus no leave_notify_event will be sent
when the button is moved.


A demonstration is attached to the mail.


	- Jens
/*
 * This program demonstrates a gtk bug that leaves a
 * button in prelight state after beeing reparented
 * in the clicked-callback
 *
 * Written by jensus@linux.nu
 *
 * To compile: cc `gtk-config --cflags --libs` reparent-bug.c -o reparent-bug
 */

#include <gtk/gtk.h>

static void reparent_cb(GtkWidget* widget, gpointer data);


int main(int argc, char** argv)
{
	GtkWidget* window;
	GtkWidget* button;

	gtk_init(&argc, &argv);

	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_container_set_border_width(GTK_CONTAINER(window), 20);

	button = gtk_button_new_with_label("Reparent");
	gtk_container_add(GTK_CONTAINER(window), button);
	gtk_signal_connect (GTK_OBJECT (button), "clicked",
			    GTK_SIGNAL_FUNC (reparent_cb), NULL);

	gtk_widget_show_all(window);

	gtk_main();

        return 0;
}

static void reparent_cb(GtkWidget* widget, gpointer data)
{
	GtkWidget* window;
	GtkWidget* vbox;
	GtkWidget* label;

	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_container_set_border_width(GTK_CONTAINER(window), 20);

	vbox = gtk_vbox_new(FALSE, 10);
	gtk_container_add(GTK_CONTAINER(window), vbox);

        label = gtk_label_new("Please note that\nthe button is prelighted!");
	gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0);

	gtk_widget_ref(widget);
	gtk_widget_reparent(widget, vbox);
	gtk_widget_unref(widget);

	gtk_widget_show_all(window);

}


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