- if (!win->m_hasVMT) return;
- if (g_blockEventsOnDrag) return;
-
- float diff = win->m_adjust->value - win->m_oldPos;
- if (fabs(diff) < 0.2) return;
- win->m_oldPos = win->m_adjust->value;
-
- wxEventType command = wxEVT_NULL;
-
- float line_step = win->m_adjust->step_increment;
- float page_step = win->m_adjust->page_increment;
-
- if (fabs(win->m_adjust->value-win->m_adjust->lower) < 0.2) command = wxEVT_SCROLL_BOTTOM;
- else if (fabs(win->m_adjust->value-win->m_adjust->upper) < 0.2) command = wxEVT_SCROLL_TOP;
- else if (fabs(diff-line_step) < 0.2) command = wxEVT_SCROLL_LINEDOWN;
- else if (fabs(diff+line_step) < 0.2) command = wxEVT_SCROLL_LINEUP;
- else if (fabs(diff-page_step) < 0.2) command = wxEVT_SCROLL_PAGEDOWN;
- else if (fabs(diff+page_step) < 0.2) command = wxEVT_SCROLL_PAGEUP;
- else command = wxEVT_SCROLL_THUMBTRACK;
-
- int value = (int)ceil(win->m_adjust->value);
-
- int orient = wxHORIZONTAL;
- if (win->GetWindowStyleFlag() & wxSB_VERTICAL == wxSB_VERTICAL) orient = wxVERTICAL;
-
- wxScrollEvent event( command, win->GetId(), value, orient );
+static inline int AdjustValueToInt(double x)
+{
+ // we want to round to the nearest integer, i.e. 0.9 is rounded to 1 and
+ // -0.9 is rounded to -1
+ return (int)(x < 0 ? x - 0.5 : x + 0.5);
+}
+
+// process a scroll event
+static void
+ProcessScrollEvent(wxSlider *win, wxEventType evtType, double dvalue)
+{
+ int orient = win->GetWindowStyleFlag() & wxSL_VERTICAL ? wxVERTICAL
+ : wxHORIZONTAL;
+
+ int value = (int)(dvalue < 0 ? dvalue - 0.5 : dvalue + 0.5);
+ wxScrollEvent event( evtType, win->GetId(), value, orient );