X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ca288f2afe1f31e6135dffc559ddd8b86d1d386e..e0dec8753abaf97e006ea1185bfb6775b28df0a8:/samples/widgets/spinbtn.cpp?ds=sidebyside diff --git a/samples/widgets/spinbtn.cpp b/samples/widgets/spinbtn.cpp index c5b506f504..b037345b02 100644 --- a/samples/widgets/spinbtn.cpp +++ b/samples/widgets/spinbtn.cpp @@ -6,7 +6,7 @@ // Created: 16.04.01 // Id: $Id$ // Copyright: (c) 2001 Vadim Zeitlin -// License: wxWindows license +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -58,10 +58,12 @@ enum SpinBtnPage_Clear, SpinBtnPage_SetValue, SpinBtnPage_SetMinAndMax, + SpinBtnPage_SetBase, SpinBtnPage_CurValueText, SpinBtnPage_ValueText, SpinBtnPage_MinText, SpinBtnPage_MaxText, + SpinBtnPage_BaseText, SpinBtnPage_SpinBtn, SpinBtnPage_SpinCtrl, SpinBtnPage_SpinCtrlDouble @@ -105,6 +107,7 @@ protected: void OnButtonClear(wxCommandEvent& event); void OnButtonSetValue(wxCommandEvent& event); void OnButtonSetMinAndMax(wxCommandEvent& event); + void OnButtonSetBase(wxCommandEvent& event); void OnCheckOrRadioBox(wxCommandEvent& event); @@ -118,6 +121,7 @@ protected: void OnUpdateUIValueButton(wxUpdateUIEvent& event); void OnUpdateUIMinMaxButton(wxUpdateUIEvent& event); + void OnUpdateUIBaseButton(wxUpdateUIEvent& event); void OnUpdateUIResetButton(wxUpdateUIEvent& event); @@ -136,6 +140,9 @@ protected: // the spinbtn range int m_min, m_max; + // and numeric base + int m_base; + // the controls // ------------ @@ -144,7 +151,7 @@ protected: *m_chkArrowKeys, *m_chkWrap, *m_chkProcessEnter; - wxRadioBox *m_radioAlign; + wxRadioBox *m_radioAlign; // the spinbtn and the spinctrl and the sizer containing them wxSpinButton *m_spinbtn; @@ -156,7 +163,8 @@ protected: // the text entries for set value/range wxTextCtrl *m_textValue, *m_textMin, - *m_textMax; + *m_textMax, + *m_textBase; private: DECLARE_EVENT_TABLE() @@ -171,9 +179,11 @@ BEGIN_EVENT_TABLE(SpinBtnWidgetsPage, WidgetsPage) EVT_BUTTON(SpinBtnPage_Reset, SpinBtnWidgetsPage::OnButtonReset) EVT_BUTTON(SpinBtnPage_SetValue, SpinBtnWidgetsPage::OnButtonSetValue) EVT_BUTTON(SpinBtnPage_SetMinAndMax, SpinBtnWidgetsPage::OnButtonSetMinAndMax) + EVT_BUTTON(SpinBtnPage_SetBase, SpinBtnWidgetsPage::OnButtonSetBase) EVT_UPDATE_UI(SpinBtnPage_SetValue, SpinBtnWidgetsPage::OnUpdateUIValueButton) EVT_UPDATE_UI(SpinBtnPage_SetMinAndMax, SpinBtnWidgetsPage::OnUpdateUIMinMaxButton) + EVT_UPDATE_UI(SpinBtnPage_SetBase, SpinBtnWidgetsPage::OnUpdateUIBaseButton) EVT_UPDATE_UI(SpinBtnPage_Reset, SpinBtnWidgetsPage::OnUpdateUIResetButton) @@ -187,6 +197,7 @@ BEGIN_EVENT_TABLE(SpinBtnWidgetsPage, WidgetsPage) EVT_TEXT(SpinBtnPage_SpinCtrl, SpinBtnWidgetsPage::OnSpinText) EVT_TEXT_ENTER(SpinBtnPage_SpinCtrl, SpinBtnWidgetsPage::OnSpinTextEnter) EVT_TEXT(SpinBtnPage_SpinCtrlDouble, SpinBtnWidgetsPage::OnSpinText) + EVT_TEXT_ENTER(SpinBtnPage_SpinCtrlDouble, SpinBtnWidgetsPage::OnSpinTextEnter) EVT_CHECKBOX(wxID_ANY, SpinBtnWidgetsPage::OnCheckOrRadioBox) EVT_RADIOBOX(wxID_ANY, SpinBtnWidgetsPage::OnCheckOrRadioBox) @@ -218,13 +229,16 @@ SpinBtnWidgetsPage::SpinBtnWidgetsPage(WidgetsBookCtrl *book, m_spinbtn = NULL; m_spinctrl = NULL; m_spinctrldbl = NULL; - m_textValue = NULL; - m_textMin = NULL; - m_textMax = NULL; + m_textValue = + m_textMin = + m_textMax = + m_textBase = NULL; m_min = 0; m_max = 10; + m_base = 10; + m_sizerSpin = NULL; } @@ -295,6 +309,13 @@ void SpinBtnWidgetsPage::CreateContent() sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); + sizerRow = CreateSizerWithTextAndButton(SpinBtnPage_SetBase, + "Set &base", + SpinBtnPage_BaseText, + &m_textBase); + m_textBase->SetValue("10"); + sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); + // right pane wxSizer *sizerRight = new wxBoxSizer(wxVERTICAL); sizerRight->SetMinSize(150, 0); @@ -445,6 +466,22 @@ void SpinBtnWidgetsPage::OnButtonSetMinAndMax(wxCommandEvent& WXUNUSED(event)) m_spinctrldbl->SetRange(minNew, maxNew); } +void SpinBtnWidgetsPage::OnButtonSetBase(wxCommandEvent& WXUNUSED(event)) +{ + unsigned long base; + if ( !m_textBase->GetValue().ToULong(&base) || !base ) + { + wxLogWarning("Invalid base value."); + return; + } + + m_base = base; + if ( !m_spinctrl->SetBase(m_base) ) + { + wxLogWarning("Setting base %d failed.", m_base); + } +} + void SpinBtnWidgetsPage::OnButtonSetValue(wxCommandEvent& WXUNUSED(event)) { long val; @@ -474,6 +511,12 @@ void SpinBtnWidgetsPage::OnUpdateUIMinMaxButton(wxUpdateUIEvent& event) mn <= mx); } +void SpinBtnWidgetsPage::OnUpdateUIBaseButton(wxUpdateUIEvent& event) +{ + unsigned long base; + event.Enable( m_textBase->GetValue().ToULong(&base) && base ); +} + void SpinBtnWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event) { event.Enable( !m_chkVert->GetValue() ||