summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Garnacho <carlosg@gnome.org>2017-09-15 13:52:55 +0200
committerCarlos Garnacho <carlosg@gnome.org>2017-09-15 21:07:18 +0200
commit108d1e15b2c78976dee726563a5ac110f37e18f2 (patch)
tree93b31dad75aa2e2b57e3d83dc99a0697a13d63f6
parent654cefacced83af328ec044f3fa86f2e48b1b926 (diff)
downloadgtk+-108d1e15b2c78976dee726563a5ac110f37e18f2.tar.gz
gtkcombobox: Use scroll event controller
-rw-r--r--gtk/gtkcombobox.c40
1 files changed, 25 insertions, 15 deletions
diff --git a/gtk/gtkcombobox.c b/gtk/gtkcombobox.c
index c702529a54..4aa64e9bc0 100644
--- a/gtk/gtkcombobox.c
+++ b/gtk/gtkcombobox.c
@@ -163,6 +163,8 @@ struct _GtkComboBoxPrivate
GtkTreeViewRowSeparatorFunc row_separator_func;
gpointer row_separator_data;
GDestroyNotify row_separator_destroy;
+
+ GtkEventController *scroll_controller;
};
/* There are 2 modes to this widget, which can be characterized as follows:
@@ -247,8 +249,6 @@ static void gtk_combo_box_unset_model (GtkComboBox *combo_box)
static void gtk_combo_box_forall (GtkContainer *container,
GtkCallback callback,
gpointer callback_data);
-static gboolean gtk_combo_box_scroll_event (GtkWidget *widget,
- GdkEventScroll *event);
static void gtk_combo_box_set_active_internal (GtkComboBox *combo_box,
GtkTreePath *path);
@@ -257,6 +257,11 @@ static void gtk_combo_box_real_move_active (GtkComboBox *combo_box,
static void gtk_combo_box_real_popup (GtkComboBox *combo_box);
static gboolean gtk_combo_box_real_popdown (GtkComboBox *combo_box);
+static void gtk_combo_box_scroll_controller_scroll (GtkEventControllerScroll *scroll,
+ gdouble dx,
+ gdouble dy,
+ GtkComboBox *combo_box);
+
/* listening to the model */
static void gtk_combo_box_model_row_inserted (GtkTreeModel *model,
GtkTreePath *path,
@@ -433,7 +438,6 @@ gtk_combo_box_class_init (GtkComboBoxClass *klass)
widget_class = (GtkWidgetClass *)klass;
widget_class->size_allocate = gtk_combo_box_size_allocate;
- widget_class->scroll_event = gtk_combo_box_scroll_event;
widget_class->mnemonic_activate = gtk_combo_box_mnemonic_activate;
widget_class->grab_focus = gtk_combo_box_grab_focus;
widget_class->measure = gtk_combo_box_measure;
@@ -979,6 +983,14 @@ gtk_combo_box_init (GtkComboBox *combo_box)
gtk_menu_attach_to_widget (GTK_MENU (menu),
GTK_WIDGET (combo_box),
NULL);
+
+ priv->scroll_controller =
+ gtk_event_controller_scroll_new (GTK_WIDGET (combo_box),
+ GTK_EVENT_CONTROLLER_SCROLL_VERTICAL |
+ GTK_EVENT_CONTROLLER_SCROLL_DISCRETE);
+ g_signal_connect (priv->scroll_controller, "scroll",
+ G_CALLBACK (gtk_combo_box_scroll_controller_scroll),
+ combo_box);
}
static void
@@ -1846,30 +1858,28 @@ tree_first (GtkComboBox *combo,
return search_data.set;
}
-static gboolean
-gtk_combo_box_scroll_event (GtkWidget *widget,
- GdkEventScroll *event)
+static void
+gtk_combo_box_scroll_controller_scroll (GtkEventControllerScroll *scroll,
+ gdouble dx,
+ gdouble dy,
+ GtkComboBox *combo_box)
{
- GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
GtkComboBoxPrivate *priv = combo_box->priv;
gboolean found = FALSE;
GtkTreeIter iter;
GtkTreeIter new_iter;
if (!gtk_combo_box_get_active_iter (combo_box, &iter))
- return TRUE;
+ return;
- if (event->direction == GDK_SCROLL_UP)
- found = tree_prev (combo_box, priv->model,
- &iter, &new_iter);
- else if (event->direction == GDK_SCROLL_DOWN)
- found = tree_next (combo_box, priv->model,
- &iter, &new_iter);
+ if (dy < 0)
+ found = tree_prev (combo_box, priv->model, &iter, &new_iter);
+ else if (dy > 0)
+ found = tree_next (combo_box, priv->model, &iter, &new_iter);
if (found)
gtk_combo_box_set_active_iter (combo_box, &new_iter);
- return TRUE;
}
/* callbacks */