BUG in propagating states
- From: "Damon Chaplin" <DAChaplin email msn com>
- To: "GTK List" <gtk-list redhat com>
- Subject: BUG in propagating states
- Date: Thu, 26 Mar 1998 15:54:46 -0000
Hi,
BUG: gtk_widget_propagate_state() doesn't save/restore states properly.
I've included a patch which seems to fix it, though the function seems
too complicated really. If there are any more problems I think it should
be split into something like gtk_widget_propagate_sensitive(),
gtk_widget_propagate_insensitive() and gtk_widget_propagate_state() for the
rest.
Damon
P.S. Has anything been done about the problem of redrawing labels,
where the background wasn't cleared? I've also had similar problems
with other widgets, if anyone is interested.
--------------------------
Example code: (leave the togglebutton active and set it insensitive and then
sensitive again - it is not redrawn properly)
#include <gtk/gtk.h>
void
set_sensitive(GtkWidget *widget, gpointer data)
{
gtk_widget_set_sensitive(GTK_WIDGET(data), TRUE);
}
void
set_insensitive(GtkWidget *widget, gpointer data)
{
gtk_widget_set_sensitive(GTK_WIDGET(data), FALSE);
}
int
main(int argc, char *argv[])
{
GtkWidget *win, *vbox, *togglebutton, *button, *hbox;
gtk_init(&argc, &argv);
win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_usize(win, 160, 220);
vbox = gtk_vbox_new (FALSE, 10);
gtk_container_add (GTK_CONTAINER (win), vbox);
gtk_widget_show (vbox);
hbox = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
gtk_widget_show (hbox);
togglebutton = gtk_toggle_button_new_with_label("Toggle Button");
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(togglebutton), TRUE);
gtk_box_pack_start (GTK_BOX (hbox), togglebutton, TRUE, TRUE, 0);
gtk_widget_show (togglebutton);
button = gtk_button_new_with_label("Set Insensitive");
gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
gtk_widget_show (button);
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC(set_insensitive), hbox);
button = gtk_button_new_with_label("Set Sensitive");
gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
gtk_widget_show (button);
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC(set_sensitive), hbox);
gtk_widget_show(win);
gtk_main();
return 0;
}
-------------------------------------------------
Patch: (though this was complicated so I'm not entirely certain it won't
cause other problems.)
--- gtkwidget.c~ Wed Mar 18 06:06:09 1998
+++ gtkwidget.c Thu Mar 26 15:19:31 1998
@@ -3755,7 +3755,14 @@
GTK_WIDGET_SET_FLAGS (widget, GTK_PARENT_SENSITIVE);
if (GTK_WIDGET_IS_SENSITIVE (widget))
- GTK_WIDGET_STATE (widget) = data->state;
+ {
+ /* If we're making an insensitive widget sensitive again, restore
+ the saved state, else set whatever state was wanted */
+ if (old_state == GTK_STATE_INSENSITIVE)
+ GTK_WIDGET_STATE (widget) = GTK_WIDGET_SAVED_STATE (widget);
+ else
+ GTK_WIDGET_STATE (widget) = data->state;
+ }
else
{
GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
@@ -3767,6 +3774,13 @@
{
GTK_WIDGET_UNSET_FLAGS (widget, GTK_PARENT_SENSITIVE);
GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
+
+ /* If we're now making the widget insensitive, save the current state
*/
+ if (old_state != GTK_STATE_INSENSITIVE)
+ GTK_WIDGET_SAVED_STATE (widget) = old_state;
+
+ /* If we're setting a state other than insensitive, then save the
state
+ so it will be used once the widget is made sensitive again */
if (data->state != GTK_STATE_INSENSITIVE)
GTK_WIDGET_SAVED_STATE (widget) = data->state;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]