Add wxSpinCtrl::SetIncrement() and implement it for all ports
SetIncrement() was already available in wxSpinCtrlDouble and GTK version of wxSpinCtrl, now implement support for it in wxMSW and wxOSX as well. In fact, in wxMSW, implement it at wxSpinButton level, so that both this class and wxSpinCtrl inheriting from it (in wxMSW only) support setting custom increment now. Also add support for it to XRC, show it in the sample and add a unit test verifying that it works. Closes #2597.
This commit is contained in:
committed by
Vadim Zeitlin
parent
57b4a11f24
commit
995c6e6df5
@@ -55,11 +55,13 @@ enum
|
||||
SpinBtnPage_SetValue,
|
||||
SpinBtnPage_SetMinAndMax,
|
||||
SpinBtnPage_SetBase,
|
||||
SpinBtnPage_SetIncrement,
|
||||
SpinBtnPage_CurValueText,
|
||||
SpinBtnPage_ValueText,
|
||||
SpinBtnPage_MinText,
|
||||
SpinBtnPage_MaxText,
|
||||
SpinBtnPage_BaseText,
|
||||
SpinBtnPage_SetIncrementText,
|
||||
SpinBtnPage_SpinBtn,
|
||||
SpinBtnPage_SpinCtrl,
|
||||
SpinBtnPage_SpinCtrlDouble
|
||||
@@ -103,7 +105,7 @@ protected:
|
||||
void OnButtonSetValue(wxCommandEvent& event);
|
||||
void OnButtonSetMinAndMax(wxCommandEvent& event);
|
||||
void OnButtonSetBase(wxCommandEvent& event);
|
||||
|
||||
void OnButtonSetIncrement(wxCommandEvent &event);
|
||||
void OnCheckOrRadioBox(wxCommandEvent& event);
|
||||
|
||||
void OnSpinBtn(wxSpinEvent& event);
|
||||
@@ -138,6 +140,9 @@ protected:
|
||||
// and numeric base
|
||||
int m_base;
|
||||
|
||||
// the increment
|
||||
int m_increment;
|
||||
|
||||
// the controls
|
||||
// ------------
|
||||
|
||||
@@ -159,7 +164,8 @@ protected:
|
||||
wxTextCtrl *m_textValue,
|
||||
*m_textMin,
|
||||
*m_textMax,
|
||||
*m_textBase;
|
||||
*m_textBase,
|
||||
*m_textIncrement;
|
||||
|
||||
private:
|
||||
wxDECLARE_EVENT_TABLE();
|
||||
@@ -175,6 +181,7 @@ wxBEGIN_EVENT_TABLE(SpinBtnWidgetsPage, WidgetsPage)
|
||||
EVT_BUTTON(SpinBtnPage_SetValue, SpinBtnWidgetsPage::OnButtonSetValue)
|
||||
EVT_BUTTON(SpinBtnPage_SetMinAndMax, SpinBtnWidgetsPage::OnButtonSetMinAndMax)
|
||||
EVT_BUTTON(SpinBtnPage_SetBase, SpinBtnWidgetsPage::OnButtonSetBase)
|
||||
EVT_BUTTON(SpinBtnPage_SetIncrement, SpinBtnWidgetsPage::OnButtonSetIncrement)
|
||||
|
||||
EVT_UPDATE_UI(SpinBtnPage_SetValue, SpinBtnWidgetsPage::OnUpdateUIValueButton)
|
||||
EVT_UPDATE_UI(SpinBtnPage_SetMinAndMax, SpinBtnWidgetsPage::OnUpdateUIMinMaxButton)
|
||||
@@ -227,12 +234,14 @@ SpinBtnWidgetsPage::SpinBtnWidgetsPage(WidgetsBookCtrl *book,
|
||||
m_textValue =
|
||||
m_textMin =
|
||||
m_textMax =
|
||||
m_textBase = NULL;
|
||||
m_textBase =
|
||||
m_textIncrement = NULL;
|
||||
|
||||
m_min = 0;
|
||||
m_max = 10;
|
||||
|
||||
m_base = 10;
|
||||
m_increment = 1;
|
||||
|
||||
m_sizerSpin = NULL;
|
||||
}
|
||||
@@ -311,6 +320,13 @@ void SpinBtnWidgetsPage::CreateContent()
|
||||
m_textBase->SetValue("10");
|
||||
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
|
||||
|
||||
sizerRow = CreateSizerWithTextAndButton( SpinBtnPage_SetIncrement,
|
||||
"Set Increment",
|
||||
SpinBtnPage_SetIncrementText,
|
||||
&m_textIncrement );
|
||||
m_textIncrement->SetValue( "1" );
|
||||
sizerMiddle->Add( sizerRow, 0, wxALL | wxGROW, 5 );
|
||||
|
||||
// right pane
|
||||
wxSizer *sizerRight = new wxBoxSizer(wxVERTICAL);
|
||||
sizerRight->SetMinSize(150, 0);
|
||||
@@ -481,6 +497,20 @@ void SpinBtnWidgetsPage::OnButtonSetBase(wxCommandEvent& WXUNUSED(event))
|
||||
m_sizerSpin->Layout();
|
||||
}
|
||||
|
||||
void SpinBtnWidgetsPage::OnButtonSetIncrement(wxCommandEvent& WXUNUSED (event))
|
||||
{
|
||||
int increment = wxAtoi( m_textIncrement->GetValue() );
|
||||
if ( !increment )
|
||||
{
|
||||
wxLogWarning("Invalid increment value.");
|
||||
return;
|
||||
}
|
||||
|
||||
m_increment = increment;
|
||||
m_spinctrl->SetIncrement(m_increment);
|
||||
wxLogWarning("Setting increment to %d.", m_increment);
|
||||
}
|
||||
|
||||
void SpinBtnWidgetsPage::OnButtonSetValue(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
if ( m_textValue->IsEmpty() )
|
||||
|
||||
Reference in New Issue
Block a user