[gtk/checkbutton-fixes: 2/5] checkbutton: Support GtkActionable properly
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/checkbutton-fixes: 2/5] checkbutton: Support GtkActionable properly
- Date: Tue, 1 Sep 2020 20:31:47 +0000 (UTC)
commit 5f8769e1a82dc0fd01c2af99c8d2d6d77fb23cb9
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Sep 1 15:25:26 2020 -0400
checkbutton: Support GtkActionable properly
Support grouping buttons via a radio action, as well
as via explicit gtk_check_button_set_group() calls.
gtk/gtkcheckbutton.c | 33 +++++++++++++++++++++++++++++----
1 file changed, 29 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtkcheckbutton.c b/gtk/gtkcheckbutton.c
index d7ba59c63e..a3d02f9ee5 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
@@ -121,6 +122,32 @@ gtk_check_button_dispose (GObject *object)
G_OBJECT_CLASS (gtk_check_button_parent_class)->dispose (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)
@@ -128,8 +155,7 @@ gtk_check_button_set_action_name (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_name (priv->action_helper, action_name);
}
@@ -141,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);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]