diff options
author | Ryan Lortie <desrt@desrt.ca> | 2010-12-01 01:31:32 -0500 |
---|---|---|
committer | Ryan Lortie <desrt@desrt.ca> | 2010-12-01 02:14:52 -0500 |
commit | 8713d6bff6d6e306cb2e34d89ec5b579ffe43129 (patch) | |
tree | 8d3f2ecacc22638cb758dd7fe6005de06cf87ca5 | |
parent | 9a01b164e3b53586c70c505985a6bb0a4a6caa80 (diff) | |
download | gtk+-buttons.tar.gz |
GtkButton: move GtkToggleButton functionality upbuttons
Move 'active', 'inconsistent' and 'toggled' functionality from
GtkToggleButton into GtkButton. Nuke GtkToggleButtonPrivate. Remove
the special enter/leave/press/release handles for toggle as well as the
state update function and merge its logic into the GtkButton one.
-rw-r--r-- | gtk/gtkbutton.c | 196 | ||||
-rw-r--r-- | gtk/gtkbutton.h | 14 | ||||
-rw-r--r-- | gtk/gtkbuttonprivate.h | 2 | ||||
-rw-r--r-- | gtk/gtkradiobutton.c | 18 | ||||
-rw-r--r-- | gtk/gtktogglebutton.c | 196 | ||||
-rw-r--r-- | gtk/gtktogglebutton.h | 8 |
6 files changed, 199 insertions, 235 deletions
diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c index 13f9f18dbc..d590514579 100644 --- a/gtk/gtkbutton.c +++ b/gtk/gtkbutton.c @@ -76,6 +76,7 @@ enum { ENTER, LEAVE, ACTIVATE, + TOGGLED, LAST_SIGNAL }; @@ -92,6 +93,8 @@ enum { PROP_IMAGE_POSITION, PROP_ACTION, PROP_INDICATOR_STYLE, + PROP_ACTIVE, + PROP_INCONSISTENT, /* activatable properties */ PROP_ACTIVATABLE_RELATED_ACTION, @@ -357,6 +360,23 @@ gtk_button_class_init (GtkButtonClass *klass) GTK_INDICATOR_STYLE_PLAIN, GTK_PARAM_READWRITE)); + g_object_class_install_property (gobject_class, + PROP_ACTIVE, + g_param_spec_boolean ("active", + P_("Active"), + P_("If the toggle button should be pressed in"), + FALSE, + GTK_PARAM_READWRITE)); + + g_object_class_install_property (gobject_class, + 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_object_class_override_property (gobject_class, PROP_ACTIVATABLE_RELATED_ACTION, "related-action"); g_object_class_override_property (gobject_class, PROP_ACTIVATABLE_USE_ACTION_APPEARANCE, "use-action-appearance"); @@ -462,6 +482,15 @@ gtk_button_class_init (GtkButtonClass *klass) G_TYPE_NONE, 0); widget_class->activate_signal = button_signals[ACTIVATE]; + button_signals[TOGGLED] = + g_signal_new (I_("toggled"), + G_OBJECT_CLASS_TYPE (gobject_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (GtkButtonClass, toggled), + NULL, NULL, + _gtk_marshal_VOID__VOID, + G_TYPE_NONE, 0); + /** * GtkButton:default-border: * @@ -627,16 +656,20 @@ gtk_button_action_state_changed (GAction *action, { GtkButton *button = GTK_BUTTON (user_data); GVariant *state; + gboolean active; state = g_action_get_state (action); - if (!g_variant_equal (state, button->priv->state)) + active = g_variant_is_of_type (state, G_VARIANT_TYPE_BOOLEAN) && + g_variant_get_boolean (state); + + if (active != button->priv->active) { - g_variant_unref (button->priv->state); - button->priv->state = g_variant_ref (state); + button->priv->active = active; - GTK_BUTTON_GET_CLASS (button) - ->action_state_changed (button, state); + gtk_button_toggled (button); + gtk_button_update_state (button); + g_object_notify (G_OBJECT (button), "active"); } g_variant_unref (state); @@ -659,35 +692,32 @@ static void gtk_button_setup_action (GtkButton *button) { GVariant *state; + gboolean active; state = g_action_get_state (button->priv->g_action); if (state != NULL) - button->priv->state_id = - g_signal_connect (button->priv->g_action, "notify::state", - G_CALLBACK (gtk_button_action_state_changed), button); - - if (state != button->priv->state) { - if (state == NULL || - button->priv->state == NULL || - !g_variant_equal (state, button->priv->state)) - { - if (button->priv->state != NULL) - g_variant_unref (button->priv->state); + button->priv->state_id = + g_signal_connect (button->priv->g_action, "notify::state", + G_CALLBACK (gtk_button_action_state_changed), button); - button->priv->state = NULL; + active = g_variant_is_of_type (state, G_VARIANT_TYPE_BOOLEAN) && + g_variant_get_boolean (state); - if (state != NULL) - button->priv->state = g_variant_ref (state); - - GTK_BUTTON_GET_CLASS (button) - ->action_state_changed (button, state); - } + g_variant_unref (state); } + else + active = FALSE; + + if (active != button->priv->active) + { + button->priv->active = active; - if (state) - g_variant_unref (state); + gtk_button_toggled (button); + gtk_button_update_state (button); + g_object_notify (G_OBJECT (button), "active"); + } } static GObject* @@ -847,6 +877,12 @@ gtk_button_set_property (GObject *object, case PROP_INDICATOR_STYLE: gtk_button_set_indicator_style (button, g_value_get_enum (value)); break; + case PROP_ACTIVE: + gtk_button_set_active (button, g_value_get_boolean (value)); + break; + case PROP_INCONSISTENT: + gtk_button_set_inconsistent (button, g_value_get_boolean (value)); + break; case PROP_ACTIVATABLE_RELATED_ACTION: gtk_button_set_related_action (button, g_value_get_object (value)); break; @@ -903,6 +939,12 @@ gtk_button_get_property (GObject *object, case PROP_INDICATOR_STYLE: g_value_set_enum (value, priv->indicator_style); break; + case PROP_ACTIVE: + g_value_set_boolean (value, priv->active); + break; + case PROP_INCONSISTENT: + g_value_set_boolean (value, priv->inconsistent); + break; case PROP_ACTIVATABLE_RELATED_ACTION: g_value_set_object (value, priv->action); break; @@ -1946,6 +1988,7 @@ gtk_real_button_pressed (GtkButton *button) priv->button_down = TRUE; gtk_button_update_state (button); + gtk_widget_queue_draw (GTK_WIDGET (button)); } static void @@ -1964,6 +2007,7 @@ gtk_real_button_released (GtkButton *button) gtk_button_clicked (button); gtk_button_update_state (button); + gtk_widget_queue_draw (GTK_WIDGET (button)); } } @@ -2425,15 +2469,22 @@ static void gtk_button_update_state (GtkButton *button) { GtkButtonPrivate *priv = button->priv; + gboolean depressed, touchscreen; GtkStateType new_state; - gboolean depressed; + + g_object_get (gtk_widget_get_settings (GTK_WIDGET (button)), + "gtk-touchscreen-mode", &touchscreen, + NULL); if (priv->activate_timeout) depressed = priv->depress_on_activate; + else if (priv->in_button && priv->button_down) + depressed = TRUE; else - depressed = priv->in_button && priv->button_down; + depressed = button->priv->active; - if (priv->in_button && (!priv->button_down || !depressed)) + if (!touchscreen && button->priv->in_button && + (!button->priv->button_down || button->priv->indicator_style != GTK_INDICATOR_STYLE_PLAIN)) new_state = GTK_STATE_PRELIGHT; else new_state = depressed ? GTK_STATE_ACTIVE : GTK_STATE_NORMAL; @@ -2715,3 +2766,92 @@ gtk_button_get_indicator_style (GtkButton *button) return button->priv->indicator_style; } + +void +_gtk_button_set_active (GtkButton *button, + gboolean active) +{ + g_warning ("this is broken..."); + button->priv->active = active; +} + +void +gtk_button_set_active (GtkButton *button, + gboolean active) +{ + g_return_if_fail (GTK_IS_BUTTON (button)); + + active = active != FALSE; + + if (button->priv->active != active) + gtk_button_clicked (button); +} + +gboolean +gtk_button_get_active (GtkButton *button) +{ + g_return_val_if_fail (GTK_IS_BUTTON (button), FALSE); + + return button->priv->active; +} + +/** + * gtk_button_set_inconsistent: + * @button: a #GtkButton + * @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 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 doesn't affect the semantics of the button. + **/ + +void +gtk_button_set_inconsistent (GtkButton *button, + gboolean inconsistent) +{ + GtkButtonPrivate *priv; + + g_return_if_fail (GTK_IS_BUTTON (button)); + + priv = button->priv; + + inconsistent = inconsistent != FALSE; + + if (priv->inconsistent != inconsistent) + { + priv->inconsistent = inconsistent; + + gtk_button_update_state (GTK_BUTTON (button)); + gtk_widget_queue_draw (GTK_WIDGET (button)); + + g_object_notify (G_OBJECT (button), "inconsistent"); + } +} + +/** + * gtk_button_get_inconsistent: + * @button: a #GtkButton + * + * Gets the value set by gtk_button_set_inconsistent(). + * + * Return value: %TRUE if the button is displayed as inconsistent, + * %FALSE otherwise + **/ +gboolean +gtk_button_get_inconsistent (GtkButton *button) +{ + g_return_val_if_fail (GTK_IS_BUTTON (button), FALSE); + + return button->priv->inconsistent; +} + +void +gtk_button_toggled (GtkButton *button) +{ + g_signal_emit (button, button_signals[TOGGLED], 0); +} diff --git a/gtk/gtkbutton.h b/gtk/gtkbutton.h index 1e5b51481b..eda586ab75 100644 --- a/gtk/gtkbutton.h +++ b/gtk/gtkbutton.h @@ -68,13 +68,13 @@ struct _GtkButtonClass void (* enter) (GtkButton *button); void (* leave) (GtkButton *button); void (* activate) (GtkButton *button); + void (* toggled) (GtkButton *button); /* Padding for future expansion */ - void (* action_state_changed) (GtkButton *button, - GVariant *state); void (*_gtk_reserved1) (void); void (*_gtk_reserved2) (void); void (*_gtk_reserved3) (void); + void (*_gtk_reserved4) (void); }; @@ -125,6 +125,13 @@ GdkWindow* gtk_button_get_event_window (GtkButton *button); void gtk_button_set_action (GtkButton *button, GAction *action); GAction * gtk_button_get_action (GtkButton *button); +gboolean gtk_button_get_active (GtkButton *button); +void gtk_button_set_active (GtkButton *button, + gboolean active); +gboolean gtk_button_get_inconsistent (GtkButton *button); +void gtk_button_set_inconsistent (GtkButton *button, + gboolean active); + void gtk_button_set_indicator_style (GtkButton *button, GtkIndicatorStyle style); @@ -139,7 +146,8 @@ void _gtk_button_paint (GtkButton *button, GtkShadowType shadow_type, const gchar *main_detail, const gchar *default_detail); - +void _gtk_button_set_active (GtkButton *, gboolean); +void gtk_button_toggled (GtkButton *); G_END_DECLS diff --git a/gtk/gtkbuttonprivate.h b/gtk/gtkbuttonprivate.h index 89627eac5d..f82a34af73 100644 --- a/gtk/gtkbuttonprivate.h +++ b/gtk/gtkbuttonprivate.h @@ -42,6 +42,8 @@ struct _GtkButtonPrivate guint activate_timeout; guint32 grab_time; + guint active : 1; + guint inconsistent : 1; guint align_set : 1; guint button_down : 1; guint constructed : 1; diff --git a/gtk/gtkradiobutton.c b/gtk/gtkradiobutton.c index 65055533a9..08dd60b4f0 100644 --- a/gtk/gtkradiobutton.c +++ b/gtk/gtkradiobutton.c @@ -205,7 +205,7 @@ gtk_radio_button_init (GtkRadioButton *radio_button) gtk_widget_set_has_window (GTK_WIDGET (radio_button), FALSE); gtk_widget_set_receives_default (GTK_WIDGET (radio_button), FALSE); - _gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio_button), TRUE); + _gtk_button_set_active (GTK_BUTTON (radio_button), TRUE); gtk_button_set_indicator_style (GTK_BUTTON (radio_button), GTK_INDICATOR_STYLE_RADIO); @@ -788,7 +788,7 @@ gtk_radio_button_clicked (GtkButton *button) GtkRadioButton *radio_button = GTK_RADIO_BUTTON (button); GtkRadioButtonPrivate *priv = radio_button->priv; GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (button); - GtkToggleButton *tmp_button; + GtkButton *tmp_button; GtkStateType new_state; GSList *tmp_list; gint toggled; @@ -798,7 +798,7 @@ gtk_radio_button_clicked (GtkButton *button) g_object_ref (GTK_WIDGET (button)); - if (gtk_toggle_button_get_active (toggle_button)) + if (gtk_button_get_active (button)) { tmp_button = NULL; tmp_list = priv->group; @@ -808,8 +808,8 @@ gtk_radio_button_clicked (GtkButton *button) tmp_button = tmp_list->data; tmp_list = tmp_list->next; - if (tmp_button != toggle_button && - gtk_toggle_button_get_active (tmp_button)) + if (tmp_button != button && + gtk_button_get_active (tmp_button)) break; tmp_button = NULL; @@ -822,16 +822,14 @@ gtk_radio_button_clicked (GtkButton *button) else { toggled = TRUE; - _gtk_toggle_button_set_active (toggle_button, - !gtk_toggle_button_get_active (toggle_button)); + _gtk_button_set_active (button, !gtk_button_get_active (button)); new_state = (button->priv->in_button ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL); } } else { toggled = TRUE; - _gtk_toggle_button_set_active (toggle_button, - !gtk_toggle_button_get_active (toggle_button)); + _gtk_button_set_active (button, !gtk_button_get_active (button)); tmp_list = priv->group; while (tmp_list) @@ -839,7 +837,7 @@ gtk_radio_button_clicked (GtkButton *button) tmp_button = tmp_list->data; tmp_list = tmp_list->next; - if (gtk_toggle_button_get_active (tmp_button) && (tmp_button != toggle_button)) + if (gtk_button_get_active (tmp_button) && (tmp_button != button)) { gtk_button_clicked (GTK_BUTTON (tmp_button)); break; diff --git a/gtk/gtktogglebutton.c b/gtk/gtktogglebutton.c index 2570d2108c..b8e19305db 100644 --- a/gtk/gtktogglebutton.c +++ b/gtk/gtktogglebutton.c @@ -38,21 +38,8 @@ #include "gtkintl.h" -struct _GtkToggleButtonPrivate -{ - guint active : 1; - guint inconsistent : 1; -}; - -enum { - TOGGLED, - LAST_SIGNAL -}; - enum { PROP_0, - PROP_ACTIVE, - PROP_INCONSISTENT, PROP_DRAW_INDICATOR }; @@ -68,8 +55,6 @@ static gint gtk_toggle_button_draw (GtkWidget *widget, cairo_t *cr); static gboolean gtk_toggle_button_mnemonic_activate (GtkWidget *widget, gboolean group_cycling); -static void gtk_toggle_button_pressed (GtkButton *button); -static void gtk_toggle_button_released (GtkButton *button); static void gtk_toggle_button_set_property (GObject *object, guint prop_id, const GValue *value, @@ -78,10 +63,6 @@ static void gtk_toggle_button_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); -static void gtk_toggle_button_update_state (GtkButton *button); - -static void gtk_toggle_button_action_state_changed (GtkButton *button, - GVariant *state); static void gtk_toggle_button_activatable_interface_init (GtkActivatableIface *iface); static void gtk_toggle_button_update (GtkActivatable *activatable, @@ -91,7 +72,6 @@ static void gtk_toggle_button_sync_action_properties (GtkActivatable *acti GtkAction *action); static GtkActivatableIface *parent_activatable_iface; -static guint toggle_button_signals[LAST_SIGNAL] = { 0 }; G_DEFINE_TYPE_WITH_CODE (GtkToggleButton, gtk_toggle_button, GTK_TYPE_BUTTON, G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE, @@ -117,30 +97,6 @@ gtk_toggle_button_class_init (GtkToggleButtonClass *class) widget_class->draw = gtk_toggle_button_draw; widget_class->mnemonic_activate = gtk_toggle_button_mnemonic_activate; - button_class->pressed = gtk_toggle_button_pressed; - button_class->released = gtk_toggle_button_released; - button_class->action_state_changed = gtk_toggle_button_action_state_changed; - button_class->enter = gtk_toggle_button_update_state; - button_class->leave = gtk_toggle_button_update_state; - - class->toggled = NULL; - - g_object_class_install_property (gobject_class, - PROP_ACTIVE, - g_param_spec_boolean ("active", - P_("Active"), - P_("If the toggle button should be pressed in"), - FALSE, - GTK_PARAM_READWRITE)); - - g_object_class_install_property (gobject_class, - 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_object_class_install_property (gobject_class, PROP_DRAW_INDICATOR, g_param_spec_boolean ("draw-indicator", @@ -149,15 +105,6 @@ gtk_toggle_button_class_init (GtkToggleButtonClass *class) FALSE, GTK_PARAM_READWRITE|G_PARAM_DEPRECATED)); - toggle_button_signals[TOGGLED] = - g_signal_new (I_("toggled"), - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (GtkToggleButtonClass, toggled), - NULL, NULL, - _gtk_marshal_VOID__VOID, - G_TYPE_NONE, 0); - gtk_widget_class_install_style_property (widget_class, g_param_spec_int ("indicator-size", P_("Indicator Size"), @@ -171,8 +118,6 @@ gtk_toggle_button_class_init (GtkToggleButtonClass *class) P_("Spacing around check or radio indicator"), 0, G_MAXINT, 2, GTK_PARAM_READABLE)); - - g_type_class_add_private (class, sizeof (GtkToggleButtonPrivate)); } static void @@ -185,14 +130,8 @@ invert (GAction *action, static void gtk_toggle_button_init (GtkToggleButton *toggle_button) { - GtkToggleButtonPrivate *priv; GSimpleAction *action; - toggle_button->priv = G_TYPE_INSTANCE_GET_PRIVATE (toggle_button, - GTK_TYPE_TOGGLE_BUTTON, - GtkToggleButtonPrivate); - priv = toggle_button->priv; - action = g_simple_action_new_stateful ("anonymous", NULL, g_variant_new_boolean (FALSE)); g_signal_connect (action, "activate", G_CALLBACK (invert), NULL); @@ -294,12 +233,6 @@ gtk_toggle_button_set_property (GObject *object, switch (prop_id) { - 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; case PROP_DRAW_INDICATOR: gtk_button_set_indicator_style (GTK_BUTTON (tb), g_value_get_boolean (value) @@ -318,17 +251,8 @@ gtk_toggle_button_get_property (GObject *object, GValue *value, GParamSpec *pspec) { - GtkToggleButton *tb = GTK_TOGGLE_BUTTON (object); - GtkToggleButtonPrivate *priv = tb->priv; - switch (prop_id) { - case PROP_ACTIVE: - g_value_set_boolean (value, priv->active); - break; - case PROP_INCONSISTENT: - g_value_set_boolean (value, priv->inconsistent); - break; case PROP_DRAW_INDICATOR: g_value_set_boolean (value, gtk_button_get_indicator_style (GTK_BUTTON (object)) != GTK_INDICATOR_STYLE_PLAIN); break; @@ -390,24 +314,9 @@ void gtk_toggle_button_set_active (GtkToggleButton *button, gboolean is_active) { - GtkToggleButtonPrivate *priv; - g_return_if_fail (GTK_IS_TOGGLE_BUTTON (button)); - priv = button->priv; - - is_active = is_active != FALSE; - - if (priv->active != is_active) - gtk_button_clicked (GTK_BUTTON (button)); -} - -void -_gtk_toggle_button_set_active (GtkToggleButton *button, - gboolean is_active) -{ - g_warning ("this is broken..."); - button->priv->active = is_active; + gtk_button_set_active (GTK_BUTTON (button), is_active); } gboolean @@ -415,7 +324,7 @@ gtk_toggle_button_get_active (GtkToggleButton *button) { g_return_val_if_fail (GTK_IS_TOGGLE_BUTTON (button), FALSE); - return button->priv->active; + return gtk_button_get_active (GTK_BUTTON (button)); } @@ -424,7 +333,7 @@ gtk_toggle_button_toggled (GtkToggleButton *button) { g_return_if_fail (GTK_IS_TOGGLE_BUTTON (button)); - g_signal_emit (button, toggle_button_signals[TOGGLED], 0); + gtk_button_toggled (GTK_BUTTON (button)); } /** @@ -445,23 +354,9 @@ void gtk_toggle_button_set_inconsistent (GtkToggleButton *button, gboolean is_inconsistent) { - GtkToggleButtonPrivate *priv; - g_return_if_fail (GTK_IS_TOGGLE_BUTTON (button)); - priv = button->priv; - - is_inconsistent = is_inconsistent != FALSE; - - if (priv->inconsistent != is_inconsistent) - { - priv->inconsistent = is_inconsistent; - - gtk_toggle_button_update_state (GTK_BUTTON (button)); - gtk_widget_queue_draw (GTK_WIDGET (button)); - - g_object_notify (G_OBJECT (button), "inconsistent"); - } + gtk_button_set_inconsistent (GTK_BUTTON (button), is_inconsistent); } /** @@ -478,7 +373,7 @@ gtk_toggle_button_get_inconsistent (GtkToggleButton *button) { g_return_val_if_fail (GTK_IS_TOGGLE_BUTTON (button), FALSE); - return button->priv->inconsistent; + return gtk_button_get_inconsistent (GTK_BUTTON (button)); } static void @@ -631,7 +526,7 @@ gtk_toggle_button_size_allocate (GtkWidget *widget, } static void -gtk_toggle_button_draw_indicator (GtkToggleButton *button, +gtk_toggle_button_draw_indicator (GtkButton *button, cairo_t *cr) { GtkWidget *widget = GTK_WIDGET (button); @@ -666,9 +561,9 @@ gtk_toggle_button_draw_indicator (GtkToggleButton *button, if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) x = gtk_widget_get_allocated_width (widget) - (indicator_size + x); - if (gtk_toggle_button_get_inconsistent (button)) + if (gtk_button_get_inconsistent (button)) shadow_type = GTK_SHADOW_ETCHED_IN; - else if (gtk_toggle_button_get_active (button)) + else if (gtk_button_get_active (button)) shadow_type = GTK_SHADOW_IN; else shadow_type = GTK_SHADOW_OUT; @@ -707,8 +602,8 @@ static gint gtk_toggle_button_draw (GtkWidget *widget, cairo_t *cr) { - GtkToggleButton *button = GTK_TOGGLE_BUTTON (widget); - GtkToggleButtonPrivate *priv = button->priv; + GtkButton *button = GTK_BUTTON (widget); + GtkButtonPrivate *priv = button->priv; GtkStateType state; GtkShadowType shadow_type; GtkWidget *child; @@ -799,74 +694,3 @@ gtk_toggle_button_mnemonic_activate (GtkWidget *widget, return TRUE; } - -static void -gtk_toggle_button_pressed (GtkButton *button) -{ - button->priv->button_down = TRUE; - - gtk_toggle_button_update_state (button); - gtk_widget_queue_draw (GTK_WIDGET (button)); -} - -static void -gtk_toggle_button_released (GtkButton *button) -{ - if (button->priv->button_down) - { - button->priv->button_down = FALSE; - - if (button->priv->in_button) - gtk_button_clicked (button); - - gtk_toggle_button_update_state (button); - gtk_widget_queue_draw (GTK_WIDGET (button)); - } -} - -static void -gtk_toggle_button_action_state_changed (GtkButton *button, - GVariant *state) -{ - GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (button); - GtkToggleButtonPrivate *priv = toggle_button->priv; - - priv->active = state && - g_variant_is_of_type (state, G_VARIANT_TYPE_BOOLEAN) && - g_variant_get_boolean (state); - - gtk_toggle_button_toggled (toggle_button); - - gtk_toggle_button_update_state (button); - - g_object_notify (G_OBJECT (toggle_button), "active"); -} - -static void -gtk_toggle_button_update_state (GtkButton *button) -{ - GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (button); - GtkToggleButtonPrivate *priv = toggle_button->priv; - gboolean depressed, touchscreen; - GtkStateType new_state; - - g_object_get (gtk_widget_get_settings (GTK_WIDGET (button)), - "gtk-touchscreen-mode", &touchscreen, - NULL); - - if (priv->inconsistent) - depressed = FALSE; - else if (button->priv->in_button && button->priv->button_down) - depressed = TRUE; - else - depressed = priv->active; - - if (!touchscreen && button->priv->in_button && - (!button->priv->button_down || button->priv->indicator_style != GTK_INDICATOR_STYLE_PLAIN)) - new_state = GTK_STATE_PRELIGHT; - else - new_state = depressed ? GTK_STATE_ACTIVE : GTK_STATE_NORMAL; - - _gtk_button_set_depressed (button, depressed); - gtk_widget_set_state (GTK_WIDGET (toggle_button), new_state); -} diff --git a/gtk/gtktogglebutton.h b/gtk/gtktogglebutton.h index 0ff9280a2c..588966b9d1 100644 --- a/gtk/gtktogglebutton.h +++ b/gtk/gtktogglebutton.h @@ -45,23 +45,18 @@ G_BEGIN_DECLS #define GTK_TOGGLE_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_TOGGLE_BUTTON, GtkToggleButtonClass)) typedef struct _GtkToggleButton GtkToggleButton; -typedef struct _GtkToggleButtonPrivate GtkToggleButtonPrivate; typedef struct _GtkToggleButtonClass GtkToggleButtonClass; struct _GtkToggleButton { /*< private >*/ GtkButton button; - - GtkToggleButtonPrivate *priv; }; struct _GtkToggleButtonClass { GtkButtonClass parent_class; - void (* toggled) (GtkToggleButton *toggle_button); - /* Padding for future expansion */ void (*_gtk_reserved1) (void); void (*_gtk_reserved2) (void); @@ -88,9 +83,6 @@ void gtk_toggle_button_set_inconsistent (GtkToggleButton *button, gboolean gtk_toggle_button_get_inconsistent (GtkToggleButton *button); void gtk_toggle_button_toggled (GtkToggleButton *button); -void _gtk_toggle_button_set_active (GtkToggleButton *button, - gboolean is_active); - G_END_DECLS |