-void gtk_scrollbar_callback( GtkWidget *WXUNUSED(widget), wxScrollBar *win )
-{
-/*
- printf( "OnScroll from " );
- if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
- printf( win->GetClassInfo()->GetClassName() );
- printf( ".\n" );
-*/
-
- if (!win->HasVMT()) return;
+extern void wxapp_install_idle_handler();
+extern bool g_isIdle;
+
+//-----------------------------------------------------------------------------
+// data
+//-----------------------------------------------------------------------------
+
+extern bool g_blockEventsOnDrag;
+extern bool g_blockEventsOnScroll;
+static wxEventType g_currentUpDownEvent = wxEVT_NULL;
+
+static const float sensitivity = 0.02;
+
+//-----------------------------------------------------------------------------
+// "value_changed"
+//-----------------------------------------------------------------------------
+
+// FIXME: is GtkScrollType really passed to us as 2nd argument?
+
+extern "C" {
+static void gtk_scrollbar_callback( GtkAdjustment *adjust,
+ SCROLLBAR_CBACK_ARG
+ wxScrollBar *win )
+{
+ if (g_isIdle) wxapp_install_idle_handler();
+
+ if (!win->m_hasVMT) return;
+ if (g_blockEventsOnDrag) return;
+
+ float diff = adjust->value - win->m_oldPos;
+ if (fabs(diff) < sensitivity) return;
+
+ win->m_oldPos = adjust->value;
+
+ wxEventType command = GtkScrollTypeToWx(GET_SCROLL_TYPE(win->m_widget));
+
+ double dvalue = adjust->value;
+ int value = (int)(dvalue < 0 ? dvalue - 0.5 : dvalue + 0.5);
+
+ int orient = win->HasFlag(wxSB_VERTICAL) ? wxVERTICAL : wxHORIZONTAL;
+
+ // throw a LINEUP / LINEDOWN event if necessary
+ if (g_currentUpDownEvent != wxEVT_NULL)
+ {
+ wxScrollEvent event( g_currentUpDownEvent, win->GetId(), value, orient );
+ event.SetEventObject( win );
+ win->GetEventHandler()->ProcessEvent( event );
+ }