diff options
Diffstat (limited to 'gtk/gtkwidget.c')
-rw-r--r-- | gtk/gtkwidget.c | 116 |
1 files changed, 109 insertions, 7 deletions
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index ab9de00cd2..b2636ffa58 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -885,7 +885,6 @@ gtk_widget_class_init (GtkWidgetClass *klass) gobject_class->set_property = gtk_widget_set_property; gobject_class->get_property = gtk_widget_get_property; - klass->activate_signal = 0; klass->show = gtk_widget_real_show; klass->hide = gtk_widget_real_hide; klass->map = gtk_widget_real_map; @@ -4296,11 +4295,31 @@ gtk_widget_mnemonic_activate (GtkWidget *widget, return handled; } +/*< private > + * gtk_widget_can_activate: + * @self: a #GtkWidget + * + * Checks whether a #GtkWidget can be activated using + * gtk_widget_activate(). + */ +gboolean +gtk_widget_can_activate (GtkWidget *self) +{ + g_return_val_if_fail (GTK_IS_WIDGET (self), FALSE); + + GtkWidgetClass *widget_class = GTK_WIDGET_GET_CLASS (self); + + if (widget_class->priv->activate_signal != 0) + return TRUE; + + return FALSE; +} + static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget, gboolean group_cycling) { - if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal) + if (!group_cycling && gtk_widget_can_activate (widget)) gtk_widget_activate (widget); else if (gtk_widget_get_can_focus (widget)) return gtk_widget_grab_focus (widget); @@ -4563,13 +4582,95 @@ gtk_widget_event (GtkWidget *widget, } /** + * gtk_widget_class_get_activate_signal: + * @widget_class: a #GtkWidgetClass + * + * Retrieves the signal id for the activation signal set using + * gtk_widget_class_set_activate_signal(). + * + * Returns: a signal id, or 0 if the widget class does not + * specify an activation signal + */ +guint +gtk_widget_class_get_activate_signal (GtkWidgetClass *widget_class) +{ + g_return_val_if_fail (GTK_IS_WIDGET_CLASS (widget_class), 0); + + return widget_class->priv->activate_signal; +} + +/** + * gtk_widget_class_set_activate_signal: + * @widget_class: a #GtkWidgetClass + * @signal_id: the id for the activate signal + * + * Sets the #GtkWidgetClass.activate_signal field with the + * given @signal_id; the signal will be emitted when calling + * gtk_widget_activate(). + * + * The @signal_id must have been registered with g_signal_new() + * or g_signal_newv() before calling this function. + */ +void +gtk_widget_class_set_activate_signal (GtkWidgetClass *widget_class, + guint signal_id) +{ + g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class)); + g_return_if_fail (signal_id != 0); + + widget_class->priv->activate_signal = signal_id; +} + +/** + * gtk_widget_class_set_activate_signal_from_name: + * @widget_class: a #GtkWidgetClass + * @signal_name: the name of the activate signal of @widget_type + * + * Sets the #GtkWidgetClass.activate_signal field with the signal id for + * the given @signal_name; the signal will be emitted when calling + * gtk_widget_activate(). + * + * The @signal_name of @widget_type must have been registered with + * g_signal_new() or g_signal_newv() before calling this function. + */ +void +gtk_widget_class_set_activate_signal_from_name (GtkWidgetClass *widget_class, + const char *signal_name) +{ + guint signal_id; + + g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class)); + g_return_if_fail (signal_name != NULL); + + signal_id = g_signal_lookup (signal_name, G_TYPE_FROM_CLASS (widget_class)); + if (signal_id == 0) + { + g_critical ("Widget type “%s” does not have a “%s” signal", + G_OBJECT_CLASS_NAME (widget_class), + signal_name); + return; + } + + widget_class->priv->activate_signal = signal_id; +} + +/** * gtk_widget_activate: * @widget: a #GtkWidget that’s activatable * * For widgets that can be “activated” (buttons, menu items, etc.) - * this function activates them. Activation is what happens when you - * press Enter on a widget during key navigation. If @widget isn't - * activatable, the function returns %FALSE. + * this function activates them. The activation will emit the signal + * set using gtk_widget_class_set_activate_signal() during class + * initialization. + * + * Activation is what happens when you press Enter on a widget during + * key navigation. + * + * If you wish to handle the activation keybinding yourself, it is + * recommended to use gtk_widget_class_add_shortcut() with an action + * created with gtk_signal_action_new(). + * + * If @widget isn't activatable, the function returns %FALSE. * * Returns: %TRUE if the widget was activatable **/ @@ -4578,10 +4679,11 @@ gtk_widget_activate (GtkWidget *widget) { g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); - if (GTK_WIDGET_GET_CLASS (widget)->activate_signal) + if (gtk_widget_can_activate (widget)) { + GtkWidgetClass *widget_class = GTK_WIDGET_GET_CLASS (widget); /* FIXME: we should eventually check the signals signature here */ - g_signal_emit (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal, 0); + g_signal_emit (widget, widget_class->priv->activate_signal, 0); return TRUE; } |