From 845988e0ed209d1af3f381b10d3008def695930f Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Sat, 11 Jul 2020 19:31:40 +0200 Subject: [PATCH] Don't allow wxSpinCtrl range to include negative values if base != 10 (wxGTK) Hexadecimal numbers are always unsigned in the native wxSpinCtrl implementation under wxMSW so for the sake of consistency we need to prevent: - Setting a range including negative values if base == 16. - Setting base != 10 if current range includes negative values. See #18805. --- interface/wx/spinctrl.h | 8 ++++---- src/gtk/spinctrl.cpp | 10 ++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/interface/wx/spinctrl.h b/interface/wx/spinctrl.h index edb2ac83b6..edec9b6dff 100644 --- a/interface/wx/spinctrl.h +++ b/interface/wx/spinctrl.h @@ -149,8 +149,8 @@ public: the numbers in the specified base when they are changed using the spin control arrows. - @note Under wxMSW setting a base to 16 is allowed only if current range - does not include negative values. + @note Under wxMSW and wxGTK setting a base to 16 is allowed only if + current range does not include negative values. @param base Numeric base, currently only 10 and 16 are supported. @@ -171,8 +171,8 @@ public: it is less than it now. However no @c wxEVT_SPINCTRL event is generated, even if it the value does change. - @note Under wxMSW setting a range including negative values is silently - ignored if current base is set to 16. + @note Under wxMSW and wxGTK setting a range including negative values + is silently ignored if current base is set to 16. */ void SetRange(int minVal, int maxVal); diff --git a/src/gtk/spinctrl.cpp b/src/gtk/spinctrl.cpp index 85205b652a..14793ec74c 100644 --- a/src/gtk/spinctrl.cpp +++ b/src/gtk/spinctrl.cpp @@ -270,6 +270,12 @@ void wxSpinCtrlGTKBase::DoSetRange(double minVal, double maxVal) { wxCHECK_RET( (m_widget != NULL), wxT("invalid spin button") ); + // Negative values in the range are allowed only if base == 10 + if ( !wxSpinCtrlImpl::IsBaseCompatibleWithRange(minVal, maxVal, GetBase()) ) + { + return; + } + wxSpinCtrlEventDisabler disable(this); gtk_spin_button_set_range( GTK_SPIN_BUTTON(m_widget), minVal, maxVal); @@ -447,6 +453,10 @@ bool wxSpinCtrl::SetBase(int base) if ( base == m_base ) return true; + // For negative values in the range only base == 10 is allowed + if ( !wxSpinCtrlImpl::IsBaseCompatibleWithRange(static_cast(DoGetMin()), static_cast(DoGetMax()), base) ) + return false; + m_base = base; // We need to be able to enter letters for any base greater than 10.