X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ce0ee9aec1fe43a5645390bd1e45f27a2518a03b..66f75561893ea7b4bf429d1882d9cc0407ba932d:/src/msw/slider.cpp diff --git a/src/msw/slider.cpp b/src/msw/slider.cpp index 4d08687349..ffa5d3919a 100644 --- a/src/msw/slider.cpp +++ b/src/msw/slider.cpp @@ -712,6 +712,11 @@ void wxSlider::SetValue(int value) void wxSlider::SetRange(int minValue, int maxValue) { + // Remember the old logical value if we need to update the physical control + // value after changing its range in wxSL_INVERSE case (and avoid an + // unnecessary call to GetValue() otherwise as it's just not needed). + const int valueOld = HasFlag(wxSL_INVERSE) ? GetValue() : 0; + m_rangeMin = minValue; m_rangeMax = maxValue; @@ -725,6 +730,14 @@ void wxSlider::SetRange(int minValue, int maxValue) ::SetWindowText((*m_labels)[SliderLabel_Max], Format(ValueInvertOrNot(m_rangeMax)).wx_str()); } + + // When emulating wxSL_INVERSE style in wxWidgets, we need to update the + // value after changing the range to ensure that the value seen by the user + // code, i.e. the one returned by GetValue(), does not change. + if ( HasFlag(wxSL_INVERSE) ) + { + ::SendMessage(GetHwnd(), TBM_SETPOS, TRUE, ValueInvertOrNot(valueOld)); + } } void wxSlider::SetTickFreq(int n, int pos)