togglebutton: Move :inconsistent to GtkCheckButton

This commit is contained in:
Timm Bäder 2017-01-28 08:11:14 +01:00
parent 66d584ce6e
commit 2aea8dfee9
7 changed files with 78 additions and 100 deletions

View File

@ -567,6 +567,8 @@ gtk_check_button_new_with_label
gtk_check_button_new_with_mnemonic
gtk_check_button_get_draw_indicator
gtk_check_button_set_draw_indicator
gtk_check_button_get_inconsistent
gtk_check_button_set_inconsistent
<SUBSECTION Standard>
GTK_CHECK_BUTTON
GTK_IS_CHECK_BUTTON
@ -3193,8 +3195,6 @@ gtk_toggle_button_new_with_mnemonic
gtk_toggle_button_toggled
gtk_toggle_button_get_active
gtk_toggle_button_set_active
gtk_toggle_button_get_inconsistent
gtk_toggle_button_set_inconsistent
<SUBSECTION Standard>
GTK_TOGGLE_BUTTON

View File

@ -56,22 +56,15 @@ gtk_toggle_button_accessible_notify_gtk (GObject *obj,
GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (obj);
AtkObject *atk_obj;
gboolean sensitive;
gboolean inconsistent;
atk_obj = gtk_widget_get_accessible (GTK_WIDGET (toggle_button));
sensitive = gtk_widget_get_sensitive (GTK_WIDGET (toggle_button));
inconsistent = gtk_toggle_button_get_inconsistent (toggle_button);
if (strcmp (pspec->name, "inconsistent") == 0)
{
atk_object_notify_state_change (atk_obj, ATK_STATE_INDETERMINATE, inconsistent);
atk_object_notify_state_change (atk_obj, ATK_STATE_ENABLED, (sensitive && !inconsistent));
}
else if (strcmp (pspec->name, "sensitive") == 0)
if (strcmp (pspec->name, "sensitive") == 0)
{
/* Need to override gailwidget behavior of notifying for ENABLED */
atk_object_notify_state_change (atk_obj, ATK_STATE_SENSITIVE, sensitive);
atk_object_notify_state_change (atk_obj, ATK_STATE_ENABLED, (sensitive && !inconsistent));
atk_object_notify_state_change (atk_obj, ATK_STATE_ENABLED, sensitive);
}
else
GTK_WIDGET_ACCESSIBLE_CLASS (gtk_toggle_button_accessible_parent_class)->notify_gtk (obj, pspec);
@ -94,12 +87,6 @@ gtk_toggle_button_accessible_ref_state_set (AtkObject *accessible)
if (gtk_toggle_button_get_active (toggle_button))
atk_state_set_add_state (state_set, ATK_STATE_CHECKED);
if (gtk_toggle_button_get_inconsistent (toggle_button))
{
atk_state_set_remove_state (state_set, ATK_STATE_ENABLED);
atk_state_set_add_state (state_set, ATK_STATE_INDETERMINATE);
}
return state_set;
}

View File

@ -88,11 +88,13 @@ typedef struct {
GtkCssGadget *indicator_gadget;
guint draw_indicator : 1;
guint inconsistent : 1;
} GtkCheckButtonPrivate;
enum {
PROP_0,
PROP_DRAW_INDICATOR,
PROP_INCONSISTENT,
NUM_PROPERTIES
};
@ -222,6 +224,10 @@ gtk_check_button_set_property (GObject *object,
g_value_get_boolean (value));
break;
case PROP_INCONSISTENT:
gtk_check_button_set_inconsistent (GTK_CHECK_BUTTON (object),
g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -239,6 +245,9 @@ gtk_check_button_get_property (GObject *object,
case PROP_DRAW_INDICATOR:
g_value_set_boolean (value, gtk_check_button_get_draw_indicator (GTK_CHECK_BUTTON (object)));
break;
case PROP_INCONSISTENT:
g_value_set_boolean (value, gtk_check_button_get_inconsistent (GTK_CHECK_BUTTON (object)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -272,6 +281,13 @@ gtk_check_button_class_init (GtkCheckButtonClass *class)
TRUE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
props[PROP_INCONSISTENT] =
g_param_spec_boolean ("inconsistent",
P_("Inconsistent"),
P_("If the check button is in an “in between” state"),
FALSE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
g_object_class_install_properties (object_class, NUM_PROPERTIES, props);
gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_CHECK_BOX);
@ -501,3 +517,54 @@ gtk_check_button_get_draw_indicator (GtkCheckButton *check_button)
return priv->draw_indicator;
}
/**
* gtk_check_button_set_inconsistent:
* @check_button: a #GtkCheckButton
* @inconsistent: %TRUE if state is inconsistent
*
* If the user has selected a range of elements (such as some text or
* spreadsheet cells) that are affected by a check button, and the
* current values in that range are inconsistent, you may want to
* display the toggle in an "in between" state. Normally you would
* turn off the inconsistent state again if the user checks the
* check button. This has to be done manually,
* gtk_check_button_set_inconsistent only affects visual appearance,
* not the semantics of the button.
*/
void
gtk_check_button_set_inconsistent (GtkCheckButton *check_button,
gboolean inconsistent)
{
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (check_button);
g_return_if_fail (GTK_IS_CHECK_BUTTON (check_button));
inconsistent = !!inconsistent;
if (inconsistent != priv->inconsistent)
{
if (inconsistent)
gtk_widget_set_state_flags (GTK_WIDGET (check_button), GTK_STATE_FLAG_INCONSISTENT, FALSE);
else
gtk_widget_unset_state_flags (GTK_WIDGET (check_button), GTK_STATE_FLAG_INCONSISTENT);
g_object_notify_by_pspec (G_OBJECT (check_button), props[PROP_INCONSISTENT]);
}
}
/**
* gtk_check_button_get_inconsistent:
* @check_button: a #GtkCheckButton
*
* Returns: %TRUE if @check_button is currently in an 'in between' state,
* %FALSE otherwise.
*/
gboolean
gtk_check_button_get_inconsistent (GtkCheckButton *check_button)
{
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (check_button);
g_return_val_if_fail (GTK_IS_CHECK_BUTTON (check_button), FALSE);
return priv->inconsistent;
}

View File

@ -76,6 +76,11 @@ void gtk_check_button_set_draw_indicator (GtkCheckButton *check_button,
gboolean draw_indicator);
GDK_AVAILABLE_IN_3_90
gboolean gtk_check_button_get_draw_indicator (GtkCheckButton *check_button);
GDK_AVAILABLE_IN_3_90
void gtk_check_button_set_inconsistent (GtkCheckButton *check_button,
gboolean inconsistent);
GDK_AVAILABLE_IN_3_90
gboolean gtk_check_button_get_inconsistent (GtkCheckButton *check_button);
G_END_DECLS

View File

@ -98,7 +98,6 @@
struct _GtkToggleButtonPrivate
{
guint active : 1;
guint inconsistent : 1;
};
enum {
@ -109,7 +108,6 @@ enum {
enum {
PROP_0,
PROP_ACTIVE,
PROP_INCONSISTENT,
NUM_PROPERTIES
};
@ -160,13 +158,6 @@ gtk_toggle_button_class_init (GtkToggleButtonClass *class)
FALSE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
toggle_button_props[PROP_INCONSISTENT] =
g_param_spec_boolean ("inconsistent",
P_("Inconsistent"),
P_("If the toggle button is in an “in between” state"),
FALSE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
g_object_class_install_properties (gobject_class, NUM_PROPERTIES, toggle_button_props);
/**
@ -264,9 +255,6 @@ gtk_toggle_button_set_property (GObject *object,
case PROP_ACTIVE:
gtk_toggle_button_set_active (tb, g_value_get_boolean (value));
break;
case PROP_INCONSISTENT:
gtk_toggle_button_set_inconsistent (tb, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -287,9 +275,6 @@ gtk_toggle_button_get_property (GObject *object,
case PROP_ACTIVE:
g_value_set_boolean (value, priv->active);
break;
case PROP_INCONSISTENT:
g_value_set_boolean (value, priv->inconsistent);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -371,62 +356,6 @@ gtk_toggle_button_toggled (GtkToggleButton *toggle_button)
g_signal_emit (toggle_button, toggle_button_signals[TOGGLED], 0);
}
/**
* gtk_toggle_button_set_inconsistent:
* @toggle_button: a #GtkToggleButton
* @setting: %TRUE if state is inconsistent
*
* If the user has selected a range of elements (such as some text or
* spreadsheet cells) that are affected by a toggle button, and the
* current values in that range are inconsistent, you may want to
* display the toggle in an in between state. This function turns on
* in between display. Normally you would turn off the inconsistent
* state again if the user toggles the toggle button. This has to be
* done manually, gtk_toggle_button_set_inconsistent() only affects
* visual appearance, it doesnt affect the semantics of the button.
*
**/
void
gtk_toggle_button_set_inconsistent (GtkToggleButton *toggle_button,
gboolean setting)
{
GtkToggleButtonPrivate *priv;
g_return_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button));
priv = toggle_button->priv;
setting = setting != FALSE;
if (setting != priv->inconsistent)
{
priv->inconsistent = setting;
if (setting)
gtk_widget_set_state_flags (GTK_WIDGET (toggle_button), GTK_STATE_FLAG_INCONSISTENT, FALSE);
else
gtk_widget_unset_state_flags (GTK_WIDGET (toggle_button), GTK_STATE_FLAG_INCONSISTENT);
g_object_notify_by_pspec (G_OBJECT (toggle_button), toggle_button_props[PROP_INCONSISTENT]);
}
}
/**
* gtk_toggle_button_get_inconsistent:
* @toggle_button: a #GtkToggleButton
*
* Gets the value set by gtk_toggle_button_set_inconsistent().
*
* Returns: %TRUE if the button is displayed as inconsistent, %FALSE otherwise
**/
gboolean
gtk_toggle_button_get_inconsistent (GtkToggleButton *toggle_button)
{
g_return_val_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button), FALSE);
return toggle_button->priv->inconsistent;
}
static gboolean
gtk_toggle_button_mnemonic_activate (GtkWidget *widget,
gboolean group_cycling)

View File

@ -84,12 +84,6 @@ GDK_AVAILABLE_IN_ALL
gboolean gtk_toggle_button_get_active (GtkToggleButton *toggle_button);
GDK_AVAILABLE_IN_ALL
void gtk_toggle_button_toggled (GtkToggleButton *toggle_button);
GDK_AVAILABLE_IN_ALL
void gtk_toggle_button_set_inconsistent (GtkToggleButton *toggle_button,
gboolean setting);
GDK_AVAILABLE_IN_ALL
gboolean gtk_toggle_button_get_inconsistent (GtkToggleButton *toggle_button);
G_END_DECLS

View File

@ -421,10 +421,6 @@ create_toggle_buttons (GtkWidget *widget)
button = gtk_toggle_button_new_with_label ("button3");
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE);
button = gtk_toggle_button_new_with_label ("inconsistent");
gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (button), TRUE);
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE);
separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE);
@ -546,7 +542,7 @@ create_check_buttons (GtkWidget *widget)
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE);
button = gtk_check_button_new_with_label ("inconsistent");
gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (button), TRUE);
gtk_check_button_set_inconsistent (GTK_CHECK_BUTTON (button), TRUE);
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE);
separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
@ -616,7 +612,7 @@ create_radio_buttons (GtkWidget *widget)
button = gtk_radio_button_new_with_label (
gtk_radio_button_get_group (GTK_RADIO_BUTTON (button)),
"inconsistent");
gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (button), TRUE);
gtk_check_button_set_inconsistent (GTK_CHECK_BUTTON (button), TRUE);
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE);
separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);