[gtk/checkbutton-fixes: 3/3] checkbutton: Support GtkActionable properly




commit 47519a1855c0645c6f4f46f79a2f250fcdeb5fee
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 | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
---
diff --git a/gtk/gtkcheckbutton.c b/gtk/gtkcheckbutton.c
index 8da36398d2..ce3b758ec4 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,22 @@ 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);
+  int role;
+
+  g_object_get (priv->action_helper, "role", &role, NULL);
+
+  if (role == 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
 gtk_check_button_set_action_name (GtkActionable *actionable,
                                   const char    *action_name)
@@ -132,6 +149,8 @@ gtk_check_button_set_action_name (GtkActionable *actionable,
     priv->action_helper = gtk_action_helper_new (actionable);
 
   gtk_action_helper_set_action_name (priv->action_helper, action_name);
+  g_signal_connect_swapped (priv->action_helper, "notify::role",
+                            G_CALLBACK (button_role_changed), self);
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]