From: Robert Roebling Date: Thu, 8 Jan 2009 10:46:18 +0000 (+0000) Subject: Override mouse wheel scrolling steps from GTK and make the default 3 steps, also... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/7f25155930ef1a6f68562a68e2caa7d87d2368de Override mouse wheel scrolling steps from GTK and make the default 3 steps, also catch mouse wheel when over scrollbars git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57900 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 3de7239792..e5a5cd7ab1 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -1547,6 +1547,38 @@ gtk_window_motion_notify_callback( GtkWidget * WXUNUSED(widget), // "scroll_event" (mouse wheel event) //----------------------------------------------------------------------------- +static gboolean +window_scroll_event_hscrollbar(GtkWidget*, GdkEventScroll* gdk_event, wxWindow* win) +{ + if (gdk_event->direction != GDK_SCROLL_LEFT && + gdk_event->direction != GDK_SCROLL_RIGHT) + { + return false; + } + + wxMouseEvent event(wxEVT_MOUSEWHEEL); + InitMouseEvent(win, event, gdk_event); + + GtkRange *range = win->m_scrollBar[wxWindow::ScrollDir_Horz]; + if (!range) return FALSE; + + if (range && GTK_WIDGET_VISIBLE (range)) + { + GtkAdjustment *adj = range->adjustment; + gdouble delta = adj->step_increment * 3; + if (gdk_event->direction == GDK_SCROLL_LEFT) + delta = -delta; + + gdouble new_value = CLAMP (adj->value + delta, adj->lower, adj->upper - adj->page_size); + + gtk_adjustment_set_value (adj, new_value); + + return TRUE; + } + + return FALSE; +} + static gboolean window_scroll_event(GtkWidget*, GdkEventScroll* gdk_event, wxWindow* win) { @@ -1567,7 +1599,27 @@ window_scroll_event(GtkWidget*, GdkEventScroll* gdk_event, wxWindow* win) else event.m_wheelRotation = -120; - return win->GTKProcessEvent(event); + if (win->GTKProcessEvent(event)) + return TRUE; + + GtkRange *range = win->m_scrollBar[wxWindow::ScrollDir_Vert]; + if (!range) return FALSE; + + if (range && GTK_WIDGET_VISIBLE (range)) + { + GtkAdjustment *adj = range->adjustment; + gdouble delta = adj->step_increment * 3; + if (gdk_event->direction == GDK_SCROLL_UP) + delta = -delta; + + gdouble new_value = CLAMP (adj->value + delta, adj->lower, adj->upper - adj->page_size); + + gtk_adjustment_set_value (adj, new_value); + + return TRUE; + } + + return FALSE; } //----------------------------------------------------------------------------- @@ -1707,7 +1759,7 @@ gtk_scrollbar_value_changed(GtkRange* range, wxWindow* win) // find the scrollbar which generated the event wxWindowGTK::ScrollDir dir = win->ScrollDirFromRange(range); - + // generate the corresponding wx event const int orient = wxWindow::OrientFromScrollDir(dir); wxScrollWinEvent event(eventType, win->GetScrollPos(orient), orient); @@ -2356,8 +2408,16 @@ void wxWindowGTK::ConnectWidget( GtkWidget *widget ) G_CALLBACK (gtk_window_button_release_callback), this); g_signal_connect (widget, "motion_notify_event", G_CALLBACK (gtk_window_motion_notify_callback), this); + g_signal_connect (widget, "scroll_event", G_CALLBACK (window_scroll_event), this); + if (m_scrollBar[ScrollDir_Horz]) + g_signal_connect (m_scrollBar[ScrollDir_Horz], "scroll_event", + G_CALLBACK (window_scroll_event_hscrollbar), this); + if (m_scrollBar[ScrollDir_Vert]) + g_signal_connect (m_scrollBar[ScrollDir_Vert], "scroll_event", + G_CALLBACK (window_scroll_event), this); + g_signal_connect (widget, "popup_menu", G_CALLBACK (wxgtk_window_popup_menu_callback), this); g_signal_connect (widget, "enter_notify_event", @@ -4097,7 +4157,7 @@ void wxWindowGTK::SetScrollbar(int orient, GtkAdjustment * const adj = sb->adjustment; adj->step_increment = 1; - adj->page_increment = + adj->page_increment = adj->page_size = thumbVisible; adj->value = pos; @@ -4216,7 +4276,7 @@ void wxWindowGTK::ScrollWindow( int dx, int dy, const wxRect* WXUNUSED(rect) ) // No scrolling requested. if ((dx == 0) && (dy == 0)) return; - + m_clipPaintRegion = true; WX_PIZZA(m_wxwindow)->scroll(dx, dy);