[gtk+/buttons: 4/5] GtkButton: 'is-toggle' was a mistake
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/buttons: 4/5] GtkButton: 'is-toggle' was a mistake
- Date: Wed, 1 Dec 2010 07:52:27 +0000 (UTC)
commit 9a01b164e3b53586c70c505985a6bb0a4a6caa80
Author: Ryan Lortie <desrt desrt ca>
Date: Wed Dec 1 01:23:23 2010 -0500
GtkButton: 'is-toggle' was a mistake
Do it differently.
gtk/gtkbutton.c | 41 ++++-------------------------------------
gtk/gtkbuttonprivate.h | 1 -
gtk/gtkcheckbutton.c | 4 +---
gtk/gtkradiobutton.c | 4 +---
gtk/gtktogglebutton.c | 18 +++++++++++++++---
5 files changed, 21 insertions(+), 47 deletions(-)
---
diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c
index 9faabcf..13f9f18 100644
--- a/gtk/gtkbutton.c
+++ b/gtk/gtkbutton.c
@@ -90,7 +90,6 @@ enum {
PROP_XALIGN,
PROP_YALIGN,
PROP_IMAGE_POSITION,
- PROP_IS_TOGGLE,
PROP_ACTION,
PROP_INDICATOR_STYLE,
@@ -336,21 +335,6 @@ gtk_button_class_init (GtkButtonClass *klass)
GTK_PARAM_READWRITE));
/**
- * GtkButton:is-toggle:
- *
- * Determines if the default action added to the button has a boolean
- * state or not. This property is only used at construct time.
- *
- * Since: 3.0
- */
- g_object_class_install_property (gobject_class,
- PROP_IS_TOGGLE,
- g_param_spec_boolean ("is-toggle",
- P_("Is toggle"),
- P_("If the default action should be stateful"),
- FALSE, GTK_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
-
- /**
* GtkButton:action:
*
* The #GAction that the button activates.
@@ -665,7 +649,9 @@ gtk_button_release_action (GtkButton *button)
g_signal_handler_disconnect (button->priv->g_action,
button->priv->state_id);
- g_object_unref (button->priv->g_action);
+ if (button->priv->g_action)
+ g_object_unref (button->priv->g_action);
+
button->priv->state_id = 0;
}
@@ -704,13 +690,6 @@ gtk_button_setup_action (GtkButton *button)
g_variant_unref (state);
}
-static void
-action_activated (GAction *action,
- gpointer user_data)
-{
- g_action_set_state (action, g_variant_new_boolean (!g_variant_get_boolean (g_action_get_state (action))));
-}
-
static GObject*
gtk_button_constructor (GType type,
guint n_construct_properties,
@@ -731,16 +710,7 @@ gtk_button_constructor (GType type,
if (priv->g_action == NULL)
{
- if (priv->is_toggle)
- {
- priv->g_action = G_ACTION (g_simple_action_new_stateful ("anonymous", NULL,
- g_variant_new_boolean (FALSE)));
- g_signal_connect (priv->g_action, "activate",
- G_CALLBACK (action_activated), NULL);
- }
- else
- priv->g_action = G_ACTION (g_simple_action_new ("anonymous", NULL));
-
+ priv->g_action = G_ACTION (g_simple_action_new ("anonymous", NULL));
gtk_button_setup_action (button);
}
@@ -870,9 +840,6 @@ gtk_button_set_property (GObject *object,
case PROP_IMAGE_POSITION:
gtk_button_set_image_position (button, g_value_get_enum (value));
break;
- case PROP_IS_TOGGLE:
- priv->is_toggle = g_value_get_boolean (value);
- break;
case PROP_ACTION:
if (g_value_get_object (value) != NULL)
gtk_button_set_action (button, g_value_get_object (value));
diff --git a/gtk/gtkbuttonprivate.h b/gtk/gtkbuttonprivate.h
index edcdcf5..89627ea 100644
--- a/gtk/gtkbuttonprivate.h
+++ b/gtk/gtkbuttonprivate.h
@@ -54,7 +54,6 @@ struct _GtkButtonPrivate
guint use_action_appearance : 1;
guint use_stock : 1;
guint use_underline : 1;
- guint is_toggle : 1;
guint indicator_style : 2;
};
diff --git a/gtk/gtkcheckbutton.c b/gtk/gtkcheckbutton.c
index 3ee43cd..d5effcc 100644
--- a/gtk/gtkcheckbutton.c
+++ b/gtk/gtkcheckbutton.c
@@ -50,7 +50,7 @@ gtk_check_button_init (GtkCheckButton *button)
GtkWidget*
gtk_check_button_new (void)
{
- return g_object_new (GTK_TYPE_CHECK_BUTTON, "is-toggle", TRUE, NULL);
+ return g_object_new (GTK_TYPE_CHECK_BUTTON, NULL);
}
@@ -58,7 +58,6 @@ GtkWidget*
gtk_check_button_new_with_label (const gchar *label)
{
return g_object_new (GTK_TYPE_CHECK_BUTTON,
- "is-toggle", TRUE,
"label", label,
NULL);
}
@@ -77,7 +76,6 @@ GtkWidget*
gtk_check_button_new_with_mnemonic (const gchar *label)
{
return g_object_new (GTK_TYPE_CHECK_BUTTON,
- "is-toggle", TRUE,
"label", label,
"use-underline", TRUE,
NULL);
diff --git a/gtk/gtkradiobutton.c b/gtk/gtkradiobutton.c
index 95b89b2..6505553 100644
--- a/gtk/gtkradiobutton.c
+++ b/gtk/gtkradiobutton.c
@@ -413,7 +413,7 @@ gtk_radio_button_new (GSList *group)
{
GtkRadioButton *radio_button;
- radio_button = g_object_new (GTK_TYPE_RADIO_BUTTON, "is-toggle", TRUE, NULL);
+ radio_button = g_object_new (GTK_TYPE_RADIO_BUTTON, NULL);
if (group)
gtk_radio_button_set_group (radio_button, group);
@@ -438,7 +438,6 @@ gtk_radio_button_new_with_label (GSList *group,
GtkWidget *radio_button;
radio_button = g_object_new (GTK_TYPE_RADIO_BUTTON,
- "is-toggle", TRUE,
"label", label,
NULL);
@@ -469,7 +468,6 @@ gtk_radio_button_new_with_mnemonic (GSList *group,
GtkWidget *radio_button;
radio_button = g_object_new (GTK_TYPE_RADIO_BUTTON,
- "is-toggle", TRUE,
"label", label,
"use-underline", TRUE,
NULL);
diff --git a/gtk/gtktogglebutton.c b/gtk/gtktogglebutton.c
index 6caee85..2570d21 100644
--- a/gtk/gtktogglebutton.c
+++ b/gtk/gtktogglebutton.c
@@ -176,15 +176,29 @@ gtk_toggle_button_class_init (GtkToggleButtonClass *class)
}
static void
+invert (GAction *action,
+ gpointer user_data)
+{
+ g_action_set_state (action, g_variant_new_boolean (!g_variant_get_boolean (g_action_get_state (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);
+ gtk_button_set_action (GTK_BUTTON (toggle_button), G_ACTION (action));
+ g_object_unref (action);
+
GTK_BUTTON (toggle_button)->priv->depress_on_activate = TRUE;
}
@@ -238,14 +252,13 @@ gtk_toggle_button_sync_action_properties (GtkActivatable *activatable,
GtkWidget*
gtk_toggle_button_new (void)
{
- return g_object_new (GTK_TYPE_TOGGLE_BUTTON, "is-toggle", TRUE, NULL);
+ return g_object_new (GTK_TYPE_TOGGLE_BUTTON, NULL);
}
GtkWidget*
gtk_toggle_button_new_with_label (const gchar *label)
{
return g_object_new (GTK_TYPE_TOGGLE_BUTTON,
- "is-toggle", TRUE,
"label", label,
NULL);
}
@@ -264,7 +277,6 @@ GtkWidget*
gtk_toggle_button_new_with_mnemonic (const gchar *label)
{
return g_object_new (GTK_TYPE_TOGGLE_BUTTON,
- "is-toggle", TRUE,
"label", label,
"use-underline", TRUE,
NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]