// "scroll_event" (mouse wheel event)
//-----------------------------------------------------------------------------
-static gboolean
-window_scroll_event_hscrollbar(GtkWidget*, GdkEventScroll* gdk_event, wxWindow* win)
+// Compute lines/columns per action the same way as private GTK+ function
+// _gtk_range_get_wheel_delta()
+static inline int GetWheelScrollActionDelta(GtkRange* range)
{
- if (gdk_event->direction != GDK_SCROLL_LEFT &&
- gdk_event->direction != GDK_SCROLL_RIGHT)
- {
- return false;
- }
-
- GtkRange *range = win->m_scrollBar[wxWindow::ScrollDir_Horz];
-
- if (range && gtk_widget_get_visible(GTK_WIDGET(range)))
+ int d = 3;
+ if (range)
{
GtkAdjustment* adj = gtk_range_get_adjustment(range);
- double delta = gtk_adjustment_get_step_increment(adj) * 3;
- if (gdk_event->direction == GDK_SCROLL_LEFT)
- delta = -delta;
-
- gtk_range_set_value(range, gtk_adjustment_get_value(adj) + delta);
-
- return TRUE;
+ const double page_size = gtk_adjustment_get_page_size(adj);
+ d = wxRound(pow(page_size, 2.0 / 3.0));
}
-
- return FALSE;
+ return d;
}
static gboolean
wxMouseEvent event(wxEVT_MOUSEWHEEL);
InitMouseEvent(win, event, gdk_event);
- // FIXME: Get these values from GTK or GDK
- event.m_linesPerAction = 3;
- event.m_columnsPerAction = 3;
event.m_wheelDelta = 120;
- // Determine the scroll direction.
- switch (gdk_event->direction)
- {
- case GDK_SCROLL_UP:
- case GDK_SCROLL_RIGHT:
- event.m_wheelRotation = 120;
- break;
-
- case GDK_SCROLL_DOWN:
- case GDK_SCROLL_LEFT:
- event.m_wheelRotation = -120;
- break;
-#if GTK_CHECK_VERSION(3,4,0)
- case GDK_SCROLL_SMOOTH:
- // TODO
-#endif
- default:
- return false; // Unknown/unhandled direction
- }
-
- // And the scroll axis.
- switch (gdk_event->direction)
- {
- case GDK_SCROLL_UP:
- case GDK_SCROLL_DOWN:
- event.m_wheelAxis = wxMOUSE_WHEEL_VERTICAL;
- break;
-
- case GDK_SCROLL_LEFT:
- case GDK_SCROLL_RIGHT:
- event.m_wheelAxis = wxMOUSE_WHEEL_HORIZONTAL;
- break;
-#if GTK_CHECK_VERSION(3,4,0)
- case GDK_SCROLL_SMOOTH:
- // TODO
- break;
-#endif
- }
-
- if (win->GTKProcessEvent(event))
- return TRUE;
-
GtkRange *range;
switch (gdk_event->direction)
{
case GDK_SCROLL_UP:
case GDK_SCROLL_DOWN:
range = win->m_scrollBar[wxWindow::ScrollDir_Vert];
+ event.m_wheelAxis = wxMOUSE_WHEEL_VERTICAL;
break;
-
case GDK_SCROLL_LEFT:
case GDK_SCROLL_RIGHT:
range = win->m_scrollBar[wxWindow::ScrollDir_Horz];
+ event.m_wheelAxis = wxMOUSE_WHEEL_HORIZONTAL;
break;
-
default:
return false;
}
- if (range && gtk_widget_get_visible(GTK_WIDGET(range)))
+ event.m_wheelRotation = event.m_wheelDelta;
+ if (gdk_event->direction == GDK_SCROLL_UP ||
+ gdk_event->direction == GDK_SCROLL_LEFT)
{
- GtkAdjustment* adj = gtk_range_get_adjustment(range);
- double delta = gtk_adjustment_get_step_increment(adj) * 3;
- if (gdk_event->direction == GDK_SCROLL_UP ||
- gdk_event->direction == GDK_SCROLL_LEFT)
- delta = -delta;
-
- gtk_range_set_value(range, gtk_adjustment_get_value(adj) + delta);
-
- return TRUE;
+ event.m_wheelRotation = -event.m_wheelRotation;
}
+ event.m_linesPerAction = GetWheelScrollActionDelta(range);
+ event.m_columnsPerAction = event.m_linesPerAction;
- return FALSE;
+ return win->GTKProcessEvent(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);
+ G_CALLBACK (window_scroll_event), this);
if (m_scrollBar[ScrollDir_Vert])
g_signal_connect (m_scrollBar[ScrollDir_Vert], "scroll_event",
G_CALLBACK (window_scroll_event), this);