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




commit b58ec8ac24f2c95b5ecd4927672bbd8e6b182a79
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 | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
---
diff --git a/gtk/gtkcheckbutton.c b/gtk/gtkcheckbutton.c
index 8da36398d2..6796187cb3 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,19 @@ 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
 gtk_check_button_set_action_name (GtkActionable *actionable,
                                   const char    *action_name)
@@ -132,6 +146,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]