gtkscalebutton: add active property
authorIgnacio Casal Quinteiro <nacho.resa@gmail.com>
Sun, 12 Feb 2023 14:01:26 +0000 (14:01 +0000)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 12 Feb 2023 14:01:26 +0000 (14:01 +0000)
gtk/gtkscalebutton.c
gtk/gtkscalebutton.h

index 2918089bfd8b474b0ec392909613f4ae0cdbbc4c..0a011bdd464e2d7113c0f51e9ea5bd877a9f3d76 100644 (file)
@@ -95,7 +95,8 @@ enum
   PROP_VALUE,
   PROP_SIZE,
   PROP_ADJUSTMENT,
-  PROP_ICONS
+  PROP_ICONS,
+  PROP_ACTIVE
 };
 
 typedef struct
@@ -256,6 +257,17 @@ gtk_scale_button_class_init (GtkScaleButtonClass *klass)
                                                        G_TYPE_STRV,
                                                        GTK_PARAM_READWRITE));
 
+  /**
+   * GtkScaleButton:active: (attributes org.gtk.Property.get=gtk_scale_button_get_active)
+   *
+   * If the scale button should be pressed in.
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_ACTIVE,
+                                   g_param_spec_boolean ("active", NULL, NULL,
+                                                         FALSE,
+                                                         GTK_PARAM_READABLE));
+
   /**
    * GtkScaleButton::value-changed:
    * @button: the object which received the signal
@@ -394,6 +406,8 @@ gtk_scale_button_toggled (GtkScaleButton *button)
   GtkScaleButtonPrivate *priv = gtk_scale_button_get_instance_private (button);
   gboolean active;
 
+  g_object_notify (G_OBJECT (button), "active");
+
   active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->button));
 
   if (active)
@@ -515,6 +529,9 @@ gtk_scale_button_get_property (GObject     *object,
     case PROP_ICONS:
       g_value_set_boxed (value, priv->icon_list);
       break;
+    case PROP_ACTIVE:
+      g_value_set_boolean (value, gtk_scale_button_get_active (button));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -768,6 +785,29 @@ gtk_scale_button_get_popup (GtkScaleButton *button)
   return priv->dock;
 }
 
+/**
+ * gtk_scale_button_get_active: (attributes org.gtk.Method.get_property=active)
+ * @button: a `GtkScaleButton`
+ *
+ * Queries a `GtkScaleButton` and returns its current state.
+ *
+ * Returns %TRUE if the scale button is pressed in and %FALSE
+ * if it is raised.
+ *
+ * Returns: whether the button is pressed
+ *
+ * Since: 4.10
+ */
+gboolean
+gtk_scale_button_get_active (GtkScaleButton *button)
+{
+  GtkScaleButtonPrivate *priv = gtk_scale_button_get_instance_private (button);
+
+  g_return_val_if_fail (GTK_IS_SCALE_BUTTON (button), FALSE);
+
+  return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->button));
+}
+
 static void
 gtk_scale_button_set_orientation_private (GtkScaleButton *button,
                                           GtkOrientation  orientation)
index 717e9f6f2f0a9d100a9bf0dc0d60d23094b6162d..c2132a9c0402140f0b6704927e178d6758065f31 100644 (file)
@@ -96,6 +96,8 @@ GDK_AVAILABLE_IN_ALL
 GtkWidget *      gtk_scale_button_get_minus_button (GtkScaleButton  *button);
 GDK_AVAILABLE_IN_ALL
 GtkWidget *      gtk_scale_button_get_popup        (GtkScaleButton  *button);
+GDK_AVAILABLE_IN_4_10
+gboolean         gtk_scale_button_get_active       (GtkScaleButton  *button);
 
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkScaleButton, g_object_unref)