diff options
author | Carlos Garnacho <carlosg@gnome.org> | 2017-09-15 13:53:27 +0200 |
---|---|---|
committer | Carlos Garnacho <carlosg@gnome.org> | 2017-09-19 18:40:49 +0200 |
commit | d0e27ba760cc2a56e3da535d94cc8c22c6fe012e (patch) | |
tree | 68c8a3b19e23ab564b5df5f6a6caaea655708f18 /gtk/gtkmenu.c | |
parent | 215c4ed419bd610a80111e85ab29ad8e1356da61 (diff) | |
download | gtk+-d0e27ba760cc2a56e3da535d94cc8c22c6fe012e.tar.gz |
gtkmenu: Use scroll event controller
Diffstat (limited to 'gtk/gtkmenu.c')
-rw-r--r-- | gtk/gtkmenu.c | 45 |
1 files changed, 17 insertions, 28 deletions
diff --git a/gtk/gtkmenu.c b/gtk/gtkmenu.c index d161634f09..6d5eb92f52 100644 --- a/gtk/gtkmenu.c +++ b/gtk/gtkmenu.c @@ -240,8 +240,6 @@ static void gtk_menu_snapshot (GtkWidget *widget, GtkSnapshot *snapshot); static gboolean gtk_menu_key_press (GtkWidget *widget, GdkEventKey *event); -static gboolean gtk_menu_scroll (GtkWidget *widget, - GdkEventScroll *event); static gboolean gtk_menu_motion_notify (GtkWidget *widget, GdkEventMotion *event); static gboolean gtk_menu_enter_notify (GtkWidget *widget, @@ -255,6 +253,10 @@ static void gtk_menu_grab_notify (GtkWidget *widget, static gboolean gtk_menu_captured_event (GtkWidget *widget, GdkEvent *event); +static void gtk_menu_scroll_controller_scroll (GtkEventControllerScroll *scroll, + gdouble dx, + gdouble dy, + GtkMenu *menu); static void gtk_menu_stop_scrolling (GtkMenu *menu); static void gtk_menu_remove_scroll_timeout (GtkMenu *menu); @@ -513,7 +515,6 @@ gtk_menu_class_init (GtkMenuClass *class) widget_class->size_allocate = gtk_menu_size_allocate; widget_class->show = gtk_menu_show; widget_class->snapshot = gtk_menu_snapshot; - widget_class->scroll_event = gtk_menu_scroll; widget_class->key_press_event = gtk_menu_key_press; widget_class->motion_notify_event = gtk_menu_motion_notify; widget_class->enter_notify_event = gtk_menu_enter_notify; @@ -1203,6 +1204,12 @@ gtk_menu_init (GtkMenu *menu) gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (priv->click_gesture), GTK_PHASE_BUBBLE); g_signal_connect (priv->click_gesture, "pressed", G_CALLBACK (gtk_menu_pressed_cb), menu); g_signal_connect (priv->click_gesture, "released", G_CALLBACK (gtk_menu_released_cb), menu); + + priv->scroll_controller = + gtk_event_controller_scroll_new (GTK_WIDGET (menu), + GTK_EVENT_CONTROLLER_SCROLL_VERTICAL); + g_signal_connect (priv->scroll_controller, "scroll", + G_CALLBACK (gtk_menu_scroll_controller_scroll), menu); } static void @@ -1275,6 +1282,7 @@ gtk_menu_finalize (GObject *object) gtk_widget_unparent (priv->top_arrow_widget); gtk_widget_unparent (priv->bottom_arrow_widget); g_clear_object (&priv->click_gesture); + g_clear_object (&priv->scroll_controller); G_OBJECT_CLASS (gtk_menu_parent_class)->finalize (object); } @@ -3291,32 +3299,13 @@ gtk_menu_scroll_timeout (gpointer data) return TRUE; } -static gboolean -gtk_menu_scroll (GtkWidget *widget, - GdkEventScroll *event) +static void +gtk_menu_scroll_controller_scroll (GtkEventControllerScroll *scroll, + gdouble dx, + gdouble dy, + GtkMenu *menu) { - GtkMenu *menu = GTK_MENU (widget); - - if (gdk_event_get_pointer_emulated ((GdkEvent *) event)) - return GDK_EVENT_PROPAGATE; - - switch (event->direction) - { - case GDK_SCROLL_DOWN: - gtk_menu_scroll_by (menu, MENU_SCROLL_STEP2); - break; - case GDK_SCROLL_UP: - gtk_menu_scroll_by (menu, - MENU_SCROLL_STEP2); - break; - case GDK_SCROLL_SMOOTH: - gtk_menu_scroll_by (menu, event->delta_y * MENU_SCROLL_STEP2); - break; - default: - return GDK_EVENT_PROPAGATE; - break; - } - - return GDK_EVENT_STOP; + gtk_menu_scroll_by (menu, dy * MENU_SCROLL_STEP2); } static void |