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.
This commit is contained in:
Artur Wieczorek
2020-07-11 19:31:40 +02:00
parent ae1e93cbae
commit 845988e0ed
2 changed files with 14 additions and 4 deletions

View File

@@ -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);

View File

@@ -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<int>(DoGetMin()), static_cast<int>(DoGetMax()), base) )
return false;
m_base = base;
// We need to be able to enter letters for any base greater than 10.