widget: Get rid of parent_sensitive flag

Instead rely on state_flags & GTK_STATE_FLAG_INSENSITIVE to tell us if a
widget is sensitive.
This has the huge benefit that the way the widget is actually rendered
corresponds to the return value of gtk_widget_is_sensitive().

As a side effect, we do not ever allow unsetting the
GTK_STATE_FLAG_INSENSITIVE for a widget the is set to not be sensitive
(via gtk_widget_set_sensitive()). This way we stop propagation of making
stuff sensitive at insensitive widgets.

https://bugzilla.gnome.org/show_bug.cgi?id=642918
This commit is contained in:
Benjamin Otte 2011-03-30 16:15:21 +02:00
parent b2f872112a
commit 1e43965350

View File

@ -321,7 +321,6 @@ struct _GtkWidgetPrivate
guint mapped : 1;
guint visible : 1;
guint sensitive : 1;
guint parent_sensitive : 1;
guint can_focus : 1;
guint has_focus : 1;
guint can_default : 1;
@ -524,7 +523,6 @@ struct _GtkStateData
{
guint flags : 6;
guint operation : 2;
guint parent_sensitive : 1;
guint use_forall : 1;
};
@ -3514,7 +3512,6 @@ gtk_widget_init (GtkWidget *widget)
priv->parent = NULL;
priv->sensitive = TRUE;
priv->parent_sensitive = TRUE;
priv->composite_child = composite_child_stack != 0;
priv->double_buffered = TRUE;
priv->redraw_on_alloc = TRUE;
@ -6997,11 +6994,6 @@ _gtk_widget_update_state_flags (GtkWidget *widget,
data.operation = operation;
data.use_forall = FALSE;
if (priv->parent)
data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
else
data.parent_sensitive = TRUE;
gtk_widget_propagate_state (widget, &data);
gtk_widget_queue_resize (widget);
@ -7088,9 +7080,6 @@ gtk_widget_get_state_flags (GtkWidget *widget)
flags = widget->priv->state_flags;
if (!gtk_widget_is_sensitive (widget))
flags |= GTK_STATE_FLAG_INSENSITIVE;
if (gtk_widget_has_focus (widget))
flags |= GTK_STATE_FLAG_FOCUSED;
@ -7600,11 +7589,6 @@ gtk_widget_set_sensitive (GtkWidget *widget,
data.use_forall = TRUE;
if (priv->parent)
data.parent_sensitive = gtk_widget_is_sensitive (priv->parent);
else
data.parent_sensitive = TRUE;
gtk_widget_propagate_state (widget, &data);
gtk_widget_queue_resize (widget);
@ -7650,7 +7634,7 @@ gtk_widget_is_sensitive (GtkWidget *widget)
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
return widget->priv->sensitive && widget->priv->parent_sensitive;
return !(widget->priv->state_flags & GTK_STATE_FLAG_INSENSITIVE);
}
static void
@ -7720,7 +7704,6 @@ gtk_widget_set_parent (GtkWidget *widget,
data.flags |= priv->state_flags;
data.operation = STATE_CHANGE_REPLACE;
data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
gtk_widget_propagate_state (widget, &data);
@ -11178,11 +11161,6 @@ gtk_widget_propagate_state (GtkWidget *widget,
old_state = gtk_widget_get_state (widget);
if (!priv->parent_sensitive)
old_flags |= GTK_STATE_FLAG_INSENSITIVE;
priv->parent_sensitive = data->parent_sensitive;
switch (data->operation)
{
case STATE_CHANGE_REPLACE:
@ -11196,6 +11174,10 @@ gtk_widget_propagate_state (GtkWidget *widget,
break;
}
/* make insensitivity unoverridable */
if (!priv->sensitive)
priv->state_flags |= GTK_STATE_FLAG_INSENSITIVE;
if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
{
GtkWidget *window;
@ -11206,7 +11188,7 @@ gtk_widget_propagate_state (GtkWidget *widget,
gtk_window_set_focus (GTK_WINDOW (window), NULL);
}
new_flags = gtk_widget_get_state_flags (widget);
new_flags = priv->state_flags;
if (old_flags != new_flags)
{
@ -11258,8 +11240,6 @@ gtk_widget_propagate_state (GtkWidget *widget,
{
GtkStateData child_data = *data;
child_data.parent_sensitive = gtk_widget_is_sensitive (widget);
/* Do not propagate focused state further */
child_data.flags &= ~GTK_STATE_FLAG_FOCUSED;