From 086793ceef65348815a8dd211ecea2df37745420 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Sat, 23 Sep 2017 19:08:29 +0200 Subject: [PATCH] Fix sending SPIN_UP/DOWN events when value wraps around (wxGTK) SPIN_UP/DOWN events should represent the arrow being pressed, not a direction in which the value changed (see documentation). Closes #17957. --- src/gtk/spinbutt.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/gtk/spinbutt.cpp b/src/gtk/spinbutt.cpp index 5147f09557..0f7c1253db 100644 --- a/src/gtk/spinbutt.cpp +++ b/src/gtk/spinbutt.cpp @@ -30,8 +30,7 @@ extern "C" { static void gtk_value_changed(GtkSpinButton* spinbutton, wxSpinButton* win) { - const double value = gtk_spin_button_get_value(spinbutton); - const int pos = int(value); + const int pos = gtk_spin_button_get_value_as_int(spinbutton); const int oldPos = win->m_pos; if (g_blockEventsOnDrag || pos == oldPos) { @@ -39,7 +38,19 @@ gtk_value_changed(GtkSpinButton* spinbutton, wxSpinButton* win) return; } - wxSpinEvent event(pos > oldPos ? wxEVT_SCROLL_LINEUP : wxEVT_SCROLL_LINEDOWN, win->GetId()); + int inc = pos - oldPos; + // Adjust for wrap arounds + // (Doesn't work for degenerated cases, like [0..1] range.) + if ( win->HasFlag(wxSP_WRAP) ) + { + if ( inc > 1 ) + inc = -1; + else if ( inc < -1 ) + inc = 1; + } + wxASSERT( inc == 1 || inc == -1 ); + + wxSpinEvent event(inc > 0 ? wxEVT_SCROLL_LINEUP : wxEVT_SCROLL_LINEDOWN, win->GetId()); event.SetPosition(pos); event.SetEventObject(win);