Allow clearing spin controls in the widgets sample

Calling wxSpinCtrl::SetValue("") is always valid.

See #19140.
This commit is contained in:
Dummy
2021-04-19 23:38:03 +02:00
committed by Vadim Zeitlin
parent 34ab87ce4d
commit f64da1eb36

View File

@@ -483,6 +483,14 @@ void SpinBtnWidgetsPage::OnButtonSetBase(wxCommandEvent& WXUNUSED(event))
void SpinBtnWidgetsPage::OnButtonSetValue(wxCommandEvent& WXUNUSED(event)) void SpinBtnWidgetsPage::OnButtonSetValue(wxCommandEvent& WXUNUSED(event))
{ {
if ( m_textValue->IsEmpty() )
{
m_spinctrl->SetValue( wxEmptyString );
m_spinctrldbl->SetValue( wxEmptyString );
return;
}
long val; long val;
if ( !m_textValue->GetValue().ToLong(&val) || !IsValidValue(val) ) if ( !m_textValue->GetValue().ToLong(&val) || !IsValidValue(val) )
{ {
@@ -499,7 +507,8 @@ void SpinBtnWidgetsPage::OnButtonSetValue(wxCommandEvent& WXUNUSED(event))
void SpinBtnWidgetsPage::OnUpdateUIValueButton(wxUpdateUIEvent& event) void SpinBtnWidgetsPage::OnUpdateUIValueButton(wxUpdateUIEvent& event)
{ {
long val; long val;
event.Enable( m_textValue->GetValue().ToLong(&val) && IsValidValue(val) ); event.Enable( m_textValue->IsEmpty() ||
( m_textValue->GetValue().ToLong(&val) && IsValidValue(val) ) );
} }
void SpinBtnWidgetsPage::OnUpdateUIMinMaxButton(wxUpdateUIEvent& event) void SpinBtnWidgetsPage::OnUpdateUIMinMaxButton(wxUpdateUIEvent& event)