diff options
author | Carlos Garnacho <carlosg@gnome.org> | 2018-06-26 13:35:26 +0200 |
---|---|---|
committer | Carlos Garnacho <carlosg@gnome.org> | 2018-06-26 13:35:26 +0200 |
commit | 40a4c0a7db599fddc6ea09545309222bee2a2069 (patch) | |
tree | ee197962e78218ed1bb2a4b0be6f56a2fff5e7a4 | |
parent | 9df5171962259b1ebc1c2ebcd461b6353aca73fa (diff) | |
download | gtk+-40a4c0a7db599fddc6ea09545309222bee2a2069.tar.gz |
gtkcombobox: Use controller to handle combobox keybindings in menus
Instead of an ::event callback.
-rw-r--r-- | gtk/gtkcombobox.c | 34 | ||||
-rw-r--r-- | gtk/ui/gtkcombobox.ui | 7 |
2 files changed, 27 insertions, 14 deletions
diff --git a/gtk/gtkcombobox.c b/gtk/gtkcombobox.c index f5844ad572..caf4042640 100644 --- a/gtk/gtkcombobox.c +++ b/gtk/gtkcombobox.c @@ -39,6 +39,7 @@ #include "gtktogglebutton.h" #include "gtktreemenu.h" #include "gtktypebuiltins.h" +#include "gtkeventcontrollerkey.h" #include "a11y/gtkcomboboxaccessible.h" @@ -275,9 +276,11 @@ static void gtk_combo_box_menu_activate (GtkWidget *menu, const gchar *path, GtkComboBox *combo_box); static void gtk_combo_box_update_sensitivity (GtkComboBox *combo_box); -static gboolean gtk_combo_box_menu_event (GtkWidget *widget, - GdkEvent *event, - gpointer data); +static gboolean gtk_combo_box_menu_key (GtkEventControllerKey *key, + guint keyval, + guint keycode, + GdkModifierType modifiers, + GtkComboBox *combo_box); static void gtk_combo_box_menu_popup (GtkComboBox *combo_box); /* cell layout */ @@ -843,7 +846,7 @@ gtk_combo_box_class_init (GtkComboBoxClass *klass) gtk_widget_class_bind_template_child_internal_private (widget_class, GtkComboBox, popup_widget); gtk_widget_class_bind_template_callback (widget_class, gtk_combo_box_button_toggled); gtk_widget_class_bind_template_callback (widget_class, gtk_combo_box_menu_activate); - gtk_widget_class_bind_template_callback (widget_class, gtk_combo_box_menu_event); + gtk_widget_class_bind_template_callback (widget_class, gtk_combo_box_menu_key); gtk_widget_class_bind_template_callback (widget_class, gtk_combo_box_menu_show); gtk_widget_class_bind_template_callback (widget_class, gtk_combo_box_menu_hide); @@ -1931,21 +1934,26 @@ gtk_combo_box_model_row_changed (GtkTreeModel *model, } static gboolean -gtk_combo_box_menu_event (GtkWidget *widget, - GdkEvent *event, - gpointer data) +gtk_combo_box_menu_key (GtkEventControllerKey *key, + guint keyval, + guint keycode, + GdkModifierType modifiers, + GtkComboBox *combo_box) { - GtkComboBox *combo_box = GTK_COMBO_BOX (data); + GtkWidget *widget; + GdkEvent *event; + + widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (key)); + event = gtk_get_current_event (); if (!gtk_bindings_activate_event (G_OBJECT (widget), (GdkEventKey *)event)) { - /* The menu hasn't managed the - * event, forward it to the combobox - */ - return gtk_bindings_activate_event (G_OBJECT (combo_box), (GdkEventKey *)event); + gtk_event_controller_key_forward (key, GTK_WIDGET (combo_box)); } - return GDK_EVENT_PROPAGATE; + g_object_unref (event); + + return TRUE; } /* diff --git a/gtk/ui/gtkcombobox.ui b/gtk/ui/gtkcombobox.ui index ef2d29c9df..cf6a81fd51 100644 --- a/gtk/ui/gtkcombobox.ui +++ b/gtk/ui/gtkcombobox.ui @@ -34,8 +34,13 @@ <object class="GtkTreeMenu" id="popup_widget"> <property name="cell-area">area</property> <signal name="menu-activate" handler="gtk_combo_box_menu_activate" swapped="no"/> - <signal name="event" handler="gtk_combo_box_menu_event" swapped="no"/> <signal name="show" handler="gtk_combo_box_menu_show" swapped="no"/> <signal name="hide" handler="gtk_combo_box_menu_hide" swapped="no"/> + <child> + <object class="GtkEventControllerKey"> + <signal name="key-pressed" handler="gtk_combo_box_menu_key" swapped="no"/> + <signal name="key-released" handler="gtk_combo_box_menu_key" swapped="no"/> + </object> + </child> </object> </interface> |