From 686d0f8d6429ac8b813e7e42f610acf6269788f0 Mon Sep 17 00:00:00 2001 From: PBS Date: Fri, 10 Nov 2023 18:34:56 +0900 Subject: [PATCH] spinbutton: Add activates-default property Add boilerplate for a new property, albeit one that does nothing yet. --- gtk/gtkspinbutton.c | 68 +++++++++++++++++++++++++++++++++++++++++++++ gtk/gtkspinbutton.h | 7 +++++ 2 files changed, 75 insertions(+) diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c index b9a2aab2ee..004904d036 100644 --- a/gtk/gtkspinbutton.c +++ b/gtk/gtkspinbutton.c @@ -218,6 +218,7 @@ struct _GtkSpinButton guint timer_calls : 3; guint wrap : 1; guint editing_canceled : 1; + guint activates_default : 1; }; struct _GtkSpinButtonClass @@ -238,6 +239,7 @@ struct _GtkSpinButtonClass enum { PROP_0, + PROP_ACTIVATES_DEFAULT, PROP_ADJUSTMENT, PROP_CLIMB_RATE, PROP_DIGITS, @@ -366,6 +368,20 @@ gtk_spin_button_class_init (GtkSpinButtonClass *class) class->output = NULL; class->change_value = gtk_spin_button_real_change_value; + /** + * GtkSpinButton:activates-default: (attributes org.gtk.Property.get=gtk_spin_button_get_activates_default org.gtk.Property.set=gtk_spin_button_set_activates_default) + * + * Whether to activate the default widget when the spin button is activated. + * + * See [signal@Gtk.SpinButton::activate] for what counts as activation. + * + * Since: 4.14 + */ + spinbutton_props[PROP_ACTIVATES_DEFAULT] = + g_param_spec_boolean ("activates-default", NULL, NULL, + FALSE, + GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY); + /** * GtkSpinButton:adjustment: (attributes org.gtk.Property.get=gtk_spin_button_get_adjustment org.gtk.Property.set=gtk_spin_button_set_adjustment) * @@ -729,6 +745,9 @@ gtk_spin_button_set_property (GObject *object, { GtkAdjustment *adjustment; + case PROP_ACTIVATES_DEFAULT: + gtk_spin_button_set_activates_default (spin_button, g_value_get_boolean (value)); + break; case PROP_ADJUSTMENT: adjustment = GTK_ADJUSTMENT (g_value_get_object (value)); gtk_spin_button_set_adjustment (spin_button, adjustment); @@ -794,6 +813,9 @@ gtk_spin_button_get_property (GObject *object, switch (prop_id) { + case PROP_ACTIVATES_DEFAULT: + g_value_set_boolean (value, spin_button->activates_default); + break; case PROP_ADJUSTMENT: g_value_set_object (value, spin_button->adjustment); break; @@ -1003,6 +1025,7 @@ gtk_spin_button_init (GtkSpinButton *spin_button) GtkEventController *controller; GtkGesture *gesture; + spin_button->activates_default = FALSE; spin_button->adjustment = NULL; spin_button->timer = 0; spin_button->climb_rate = 0.0; @@ -1852,6 +1875,51 @@ gtk_spin_button_new_with_range (double min, return GTK_WIDGET (spin); } +/** + * gtk_spin_button_set_activates_default: (attributes org.gtk.Method.set_property=activates-default) + * @spin_button: a `GtkSpinButton` + * @activates_default: %TRUE to activate window’s default widget on activation + * + * Sets whether activating the spin button will activate the default + * widget for the window containing the spin button. + * + * See [signal@Gtk.SpinButton::activate] for what counts as activation. + * + * Since: 4.14 + */ +void +gtk_spin_button_set_activates_default (GtkSpinButton *spin_button, + gboolean activates_default) +{ + g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button)); + + activates_default = !!activates_default; + + if (activates_default != spin_button->activates_default) + { + spin_button->activates_default = activates_default; + g_object_notify_by_pspec (G_OBJECT (spin_button), spinbutton_props[PROP_ACTIVATES_DEFAULT]); + } +} + +/** + * gtk_spin_button_get_activates_default: (attributes org.gtk.Method.get_property=activates-default) + * @spin_button: a `GtkSpinButton` + * + * Retrieves the value set by [method@Gtk.SpinButton.set_activates_default]. + * + * Returns: %TRUE if the spin button will activate the default widget + * + * Since: 4.14 + */ +gboolean +gtk_spin_button_get_activates_default (GtkSpinButton *spin_button) +{ + g_return_val_if_fail (GTK_IS_SPIN_BUTTON (spin_button), FALSE); + + return spin_button->activates_default; +} + /** * gtk_spin_button_set_adjustment: (attributes org.gtk.Method.set_property=adjustment) * @spin_button: a `GtkSpinButton` diff --git a/gtk/gtkspinbutton.h b/gtk/gtkspinbutton.h index d9ad80214d..412a4d25c2 100644 --- a/gtk/gtkspinbutton.h +++ b/gtk/gtkspinbutton.h @@ -116,6 +116,13 @@ GtkWidget* gtk_spin_button_new_with_range (double min, double max, double step); +GDK_AVAILABLE_IN_4_14 +void gtk_spin_button_set_activates_default (GtkSpinButton *spin_button, + gboolean activates_default); + +GDK_AVAILABLE_IN_4_14 +gboolean gtk_spin_button_get_activates_default (GtkSpinButton *spin_button); + GDK_AVAILABLE_IN_ALL void gtk_spin_button_set_adjustment (GtkSpinButton *spin_button, GtkAdjustment *adjustment);