checkbutton: Add activate signal to work with gtk_widget_activate()

Fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/3525
Fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/3550
This commit is contained in:
Yetizone 2020-12-29 15:54:25 +02:00
parent cf623ce774
commit 601dfeeff9
2 changed files with 52 additions and 1 deletions

View File

@ -34,6 +34,7 @@
#include "gtkintl.h" #include "gtkintl.h"
#include "gtklabel.h" #include "gtklabel.h"
#include "gtkprivate.h" #include "gtkprivate.h"
#include "gtkshortcuttrigger.h"
#include "gtkstylecontextprivate.h" #include "gtkstylecontextprivate.h"
#include "gtkwidgetprivate.h" #include "gtkwidgetprivate.h"
#include "gtkmodelbuttonprivate.h" #include "gtkmodelbuttonprivate.h"
@ -94,6 +95,7 @@ enum {
enum { enum {
TOGGLED, TOGGLED,
ACTIVATE,
LAST_SIGNAL LAST_SIGNAL
}; };
@ -442,11 +444,26 @@ gtk_check_button_focus (GtkWidget *widget,
} }
} }
static void
gtk_check_button_real_activate (GtkCheckButton *check_button)
{
gtk_check_button_set_active (check_button,
!gtk_check_button_get_active (check_button));
}
static void static void
gtk_check_button_class_init (GtkCheckButtonClass *class) gtk_check_button_class_init (GtkCheckButtonClass *class)
{ {
const guint activate_keyvals[] = {
GDK_KEY_space,
GDK_KEY_KP_Space,
GDK_KEY_Return,
GDK_KEY_ISO_Enter,
GDK_KEY_KP_Enter
};
GObjectClass *object_class = G_OBJECT_CLASS (class); GObjectClass *object_class = G_OBJECT_CLASS (class);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
GtkShortcutAction *activate_action;
object_class->dispose = gtk_check_button_dispose; object_class->dispose = gtk_check_button_dispose;
object_class->set_property = gtk_check_button_set_property; object_class->set_property = gtk_check_button_set_property;
@ -454,6 +471,8 @@ gtk_check_button_class_init (GtkCheckButtonClass *class)
widget_class->focus = gtk_check_button_focus; widget_class->focus = gtk_check_button_focus;
class->activate = gtk_check_button_real_activate;
props[PROP_ACTIVE] = props[PROP_ACTIVE] =
g_param_spec_boolean ("active", g_param_spec_boolean ("active",
P_("Active"), P_("Active"),
@ -507,6 +526,37 @@ gtk_check_button_class_init (GtkCheckButtonClass *class)
NULL, NULL,
G_TYPE_NONE, 0); G_TYPE_NONE, 0);
/**
* GtkCheckButton::activate:
* @widget: the object which received the signal.
*
* The ::activate signal on GtkCheckButton is an action signal and
* emitting it causes the button to animate press then release.
* Applications should never connect to this signal, but use the
* #GtkCheckButton::toggled signal.
*/
signals[ACTIVATE] =
g_signal_new (I_ ("activate"),
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkCheckButtonClass, activate),
NULL, NULL,
NULL,
G_TYPE_NONE, 0);
gtk_widget_class_set_activate_signal (widget_class, signals[ACTIVATE]);
activate_action = gtk_signal_action_new ("activate");
for (guint i = 0; i < G_N_ELEMENTS (activate_keyvals); i++)
{
GtkShortcut *activate_shortcut = gtk_shortcut_new (gtk_keyval_trigger_new (activate_keyvals[i], 0),
g_object_ref (activate_action));
gtk_widget_class_add_shortcut (widget_class, activate_shortcut);
g_object_unref (activate_shortcut);
}
g_object_unref (activate_action);
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT); gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);
gtk_widget_class_set_css_name (widget_class, I_("checkbutton")); gtk_widget_class_set_css_name (widget_class, I_("checkbutton"));
gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_CHECKBOX); gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_CHECKBOX);

View File

@ -56,9 +56,10 @@ struct _GtkCheckButtonClass
GtkWidgetClass parent_class; GtkWidgetClass parent_class;
void (* toggled) (GtkCheckButton *check_button); void (* toggled) (GtkCheckButton *check_button);
void (* activate) (GtkCheckButton *check_button);
/*< private >*/ /*< private >*/
gpointer padding[8]; gpointer padding[7];
}; };