diff options
author | Matthias Clasen <mclasen@redhat.com> | 2020-09-01 22:15:33 +0000 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2020-09-01 22:15:33 +0000 |
commit | 062822ab0626dd1198e7e095069b0ca81709c4f1 (patch) | |
tree | 32f42985195214ae822f4afe71b3564d8fbde3cb | |
parent | fc333ead793cf7517200e41b4ac9b79e9bc433cc (diff) | |
parent | 746bdd3d4778629b161d45f869659d2c77e839f1 (diff) | |
download | gtk+-062822ab0626dd1198e7e095069b0ca81709c4f1.tar.gz |
Merge branch 'checkbutton-fixes' into 'master'
Checkbutton fixes
See merge request GNOME/gtk!2518
-rw-r--r-- | gtk/gtkactionhelper.c | 9 | ||||
-rw-r--r-- | gtk/gtkactionhelperprivate.h | 13 | ||||
-rw-r--r-- | gtk/gtkcheckbutton.c | 44 | ||||
-rw-r--r-- | gtk/gtktogglebutton.c | 6 |
4 files changed, 57 insertions, 15 deletions
diff --git a/gtk/gtkactionhelper.c b/gtk/gtkactionhelper.c index ccc2153c33..36eaa7bf24 100644 --- a/gtk/gtkactionhelper.c +++ b/gtk/gtkactionhelper.c @@ -598,3 +598,12 @@ gtk_action_helper_activate (GtkActionHelper *helper) helper->action_name, helper->target); } + +GtkButtonRole +gtk_action_helper_get_role (GtkActionHelper *helper) +{ + g_return_val_if_fail (GTK_IS_ACTION_HELPER (helper), GTK_BUTTON_ROLE_NORMAL); + + return helper->role; +} + diff --git a/gtk/gtkactionhelperprivate.h b/gtk/gtkactionhelperprivate.h index f68ef104f9..57d70f9d55 100644 --- a/gtk/gtkactionhelperprivate.h +++ b/gtk/gtkactionhelperprivate.h @@ -22,6 +22,7 @@ #include <gtk/gtkapplication.h> #include <gtk/gtkactionable.h> +#include <gtk/gtkmodelbuttonprivate.h> #define GTK_TYPE_ACTION_HELPER (gtk_action_helper_get_type ()) #define GTK_ACTION_HELPER(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \ @@ -31,29 +32,23 @@ typedef struct _GtkActionHelper GtkActionHelper; -G_GNUC_INTERNAL GType gtk_action_helper_get_type (void); -G_GNUC_INTERNAL GtkActionHelper * gtk_action_helper_new (GtkActionable *widget); -G_GNUC_INTERNAL void gtk_action_helper_set_action_name (GtkActionHelper *helper, const char *action_name); -G_GNUC_INTERNAL void gtk_action_helper_set_action_target_value (GtkActionHelper *helper, GVariant *action_target); -G_GNUC_INTERNAL const char * gtk_action_helper_get_action_name (GtkActionHelper *helper); -G_GNUC_INTERNAL GVariant * gtk_action_helper_get_action_target_value (GtkActionHelper *helper); -G_GNUC_INTERNAL gboolean gtk_action_helper_get_enabled (GtkActionHelper *helper); -G_GNUC_INTERNAL gboolean gtk_action_helper_get_active (GtkActionHelper *helper); -G_GNUC_INTERNAL void gtk_action_helper_activate (GtkActionHelper *helper); +GtkButtonRole gtk_action_helper_get_role (GtkActionHelper *helper); + + #endif /* __GTK_ACTION_HELPER_H__ */ diff --git a/gtk/gtkcheckbutton.c b/gtk/gtkcheckbutton.c index 13aa7fb6cd..cd23ab3a05 100644 --- a/gtk/gtkcheckbutton.c +++ b/gtk/gtkcheckbutton.c @@ -37,6 +37,7 @@ #include "gtkprivate.h" #include "gtkstylecontextprivate.h" #include "gtkwidgetprivate.h" +#include "gtkmodelbuttonprivate.h" /** * SECTION:gtkcheckbutton @@ -111,6 +112,8 @@ gtk_check_button_dispose (GObject *object) { GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (GTK_CHECK_BUTTON (object)); + g_clear_object (&priv->action_helper); + g_clear_pointer (&priv->indicator_widget, gtk_widget_unparent); g_clear_pointer (&priv->label_widget, gtk_widget_unparent); @@ -120,14 +123,39 @@ gtk_check_button_dispose (GObject *object) } static void +button_role_changed (GtkCheckButton *self) +{ + GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (self); + + if (gtk_action_helper_get_role (priv->action_helper) == GTK_BUTTON_ROLE_RADIO) + gtk_css_node_set_name (gtk_widget_get_css_node (priv->indicator_widget), + g_quark_from_static_string("radio")); + else + gtk_css_node_set_name (gtk_widget_get_css_node (priv->indicator_widget), + g_quark_from_static_string("check")); +} + +static void +ensure_action_helper (GtkCheckButton *self) +{ + GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (self); + + if (priv->action_helper) + return; + + priv->action_helper = gtk_action_helper_new (GTK_ACTIONABLE (self)); + g_signal_connect_swapped (priv->action_helper, "notify::role", + G_CALLBACK (button_role_changed), self); +} + +static void gtk_check_button_set_action_name (GtkActionable *actionable, const char *action_name) { GtkCheckButton *self = GTK_CHECK_BUTTON (actionable); GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (self); - if (!priv->action_helper) - priv->action_helper = gtk_action_helper_new (actionable); + ensure_action_helper (self); gtk_action_helper_set_action_name (priv->action_helper, action_name); } @@ -139,8 +167,7 @@ gtk_check_button_set_action_target_value (GtkActionable *actionable, GtkCheckButton *self = GTK_CHECK_BUTTON (actionable); GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (self); - if (!priv->action_helper) - priv->action_helper = gtk_action_helper_new (actionable); + ensure_action_helper (self); gtk_action_helper_set_action_target_value (priv->action_helper, action_target); } @@ -775,7 +802,13 @@ gtk_check_button_set_label (GtkCheckButton *self, * Setting the group of a check button also changes the css name of the * indicator widget's CSS node to 'radio'. * - * The behavior of a checkbutton in a group is also commonly known as a 'radio button'. + * The behavior of a checkbutton in a group is also commonly known as + * a 'radio button'. + * + * Note that the same effect can be achieved via the #GtkActionable + * api, by using the same action with parameter type and state type 's' + * for all buttons in the group, and giving each button its own target + * value. */ void gtk_check_button_set_group (GtkCheckButton *self, @@ -801,7 +834,6 @@ gtk_check_button_set_group (GtkCheckButton *self, priv->group_next = NULL; priv->group_prev = NULL; - g_object_notify_by_pspec (G_OBJECT (self), props[PROP_GROUP]); if (priv->indicator_widget) gtk_css_node_set_name (gtk_widget_get_css_node (priv->indicator_widget), diff --git a/gtk/gtktogglebutton.c b/gtk/gtktogglebutton.c index edce7e0368..45019471b7 100644 --- a/gtk/gtktogglebutton.c +++ b/gtk/gtktogglebutton.c @@ -446,6 +446,12 @@ gtk_toggle_button_toggled (GtkToggleButton *toggle_button) * * Adds @self to the group of @group. In a group of multiple toggle buttons, * only one button can be active at a time. + * + * Note that the same effect can be achieved via the #GtkActionable + * api, by using the same action with parameter type and state type 's' + * for all buttons in the group, and giving each button its own target + * value. + */ void gtk_toggle_button_set_group (GtkToggleButton *self, |