GtkSwitch: use regular activation

GtkSwitch was listening for Space/Enter keyreleases itself, instead
of providing an 'activate' action signal, like e.g GtkButton. As a
side-effect, this fixes
https://bugzilla.gnome.org/show_bug.cgi?id=643321
This commit is contained in:
Matthias Clasen 2011-02-25 15:47:03 -05:00
parent 6b91392afd
commit 46cc85fd7e
2 changed files with 38 additions and 16 deletions

View File

@ -47,6 +47,8 @@
#include "gtkprivate.h" #include "gtkprivate.h"
#include "gtktoggleaction.h" #include "gtktoggleaction.h"
#include "gtkwidget.h" #include "gtkwidget.h"
#include "gtkmarshalers.h"
#define DEFAULT_SLIDER_WIDTH (36) #define DEFAULT_SLIDER_WIDTH (36)
#define DEFAULT_SLIDER_HEIGHT (22) #define DEFAULT_SLIDER_HEIGHT (22)
@ -77,6 +79,14 @@ enum
LAST_PROP LAST_PROP
}; };
enum
{
ACTIVATE,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
static GParamSpec *switch_props[LAST_PROP] = { NULL, }; static GParamSpec *switch_props[LAST_PROP] = { NULL, };
static GType gtk_switch_accessible_factory_get_type (void); static GType gtk_switch_accessible_factory_get_type (void);
@ -262,22 +272,12 @@ gtk_switch_leave (GtkWidget *widget,
return FALSE; return FALSE;
} }
static gboolean static void
gtk_switch_key_release (GtkWidget *widget, gtk_switch_activate (GtkSwitch *sw)
GdkEventKey *event)
{ {
GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv; GtkSwitchPrivate *priv = sw->priv;
if (event->keyval == GDK_KEY_Return || gtk_switch_set_active (sw, !priv->is_active);
event->keyval == GDK_KEY_KP_Enter ||
event->keyval == GDK_KEY_ISO_Enter ||
event->keyval == GDK_KEY_space ||
event->keyval == GDK_KEY_KP_Space)
{
gtk_switch_set_active (GTK_SWITCH (widget), !priv->is_active);
}
return FALSE;
} }
static void static void
@ -756,9 +756,10 @@ gtk_switch_class_init (GtkSwitchClass *klass)
widget_class->motion_notify_event = gtk_switch_motion; widget_class->motion_notify_event = gtk_switch_motion;
widget_class->enter_notify_event = gtk_switch_enter; widget_class->enter_notify_event = gtk_switch_enter;
widget_class->leave_notify_event = gtk_switch_leave; widget_class->leave_notify_event = gtk_switch_leave;
widget_class->key_release_event = gtk_switch_key_release;
widget_class->get_accessible = gtk_switch_get_accessible; widget_class->get_accessible = gtk_switch_get_accessible;
klass->activate = gtk_switch_activate;
/** /**
* GtkSwitch:slider-width: * GtkSwitch:slider-width:
* *
@ -771,6 +772,26 @@ gtk_switch_class_init (GtkSwitchClass *klass)
DEFAULT_SLIDER_WIDTH, G_MAXINT, DEFAULT_SLIDER_WIDTH, G_MAXINT,
DEFAULT_SLIDER_WIDTH, DEFAULT_SLIDER_WIDTH,
GTK_PARAM_READABLE)); GTK_PARAM_READABLE));
/**
* GtkSwitch::activate:
* @widget: the object which received the signal.
*
* The ::activate signal on GtkSwitch is an action signal and
* emitting it causes the switch to animate.
* Applications should never connect to this signal, but use the
* notify::active signal.
*/
signals[ACTIVATE] =
g_signal_new (I_("activate"),
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkSwitchClass, activate),
NULL, NULL,
_gtk_marshal_VOID__VOID,
G_TYPE_NONE, 0);
widget_class->activate_signal = signals[ACTIVATE];
} }
static void static void

View File

@ -72,13 +72,14 @@ struct _GtkSwitchClass
/*< private >*/ /*< private >*/
GtkWidgetClass parent_class; GtkWidgetClass parent_class;
void (* activate) (GtkSwitch *sw);
void (* _switch_padding_1) (void); void (* _switch_padding_1) (void);
void (* _switch_padding_2) (void); void (* _switch_padding_2) (void);
void (* _switch_padding_3) (void); void (* _switch_padding_3) (void);
void (* _switch_padding_4) (void); void (* _switch_padding_4) (void);
void (* _switch_padding_5) (void); void (* _switch_padding_5) (void);
void (* _switch_padding_6) (void); void (* _switch_padding_6) (void);
void (* _switch_padding_7) (void);
}; };
GType gtk_switch_get_type (void) G_GNUC_CONST; GType gtk_switch_get_type (void) G_GNUC_CONST;