X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/32b8ec418aee4e38877d4cb79e2984c766dcc358..e9561b3b2bfd2f54793c1503901edd91cd16e548:/samples/widgets/slider.cpp diff --git a/samples/widgets/slider.cpp b/samples/widgets/slider.cpp index bdac12d8cf..ec1d8f5a76 100644 --- a/samples/widgets/slider.cpp +++ b/samples/widgets/slider.cpp @@ -39,7 +39,6 @@ #include "wx/sizer.h" #include "widgets.h" - #include "icons/slider.xpm" // ---------------------------------------------------------------------------- @@ -49,7 +48,7 @@ // control ids enum { - SliderPage_Reset = 100, + SliderPage_Reset = wxID_HIGHEST, SliderPage_Clear, SliderPage_SetValue, SliderPage_SetMinAndMax, @@ -83,7 +82,7 @@ protected: void OnCheckOrRadioBox(wxCommandEvent& event); - void OnSlider(wxCommandEvent& event); + void OnSlider(wxScrollEvent& event); void OnUpdateUIOtherSide(wxUpdateUIEvent& event); void OnUpdateUIValueButton(wxUpdateUIEvent& event); @@ -130,8 +129,8 @@ protected: *m_textTickFreq; private: - DECLARE_EVENT_TABLE(); - DECLARE_WIDGETS_PAGE(SliderWidgetsPage); + DECLARE_EVENT_TABLE() + DECLARE_WIDGETS_PAGE(SliderWidgetsPage) }; // ---------------------------------------------------------------------------- @@ -155,7 +154,7 @@ BEGIN_EVENT_TABLE(SliderWidgetsPage, WidgetsPage) EVT_UPDATE_UI(SliderPage_CurValueText, SliderWidgetsPage::OnUpdateUICurValueText) - EVT_SLIDER(SliderPage_Slider, SliderWidgetsPage::OnSlider) + EVT_COMMAND_SCROLL(SliderPage_Slider, SliderWidgetsPage::OnSlider) EVT_CHECKBOX(-1, SliderWidgetsPage::OnCheckOrRadioBox) EVT_RADIOBOX(-1, SliderWidgetsPage::OnCheckOrRadioBox) @@ -232,8 +231,8 @@ SliderWidgetsPage::SliderWidgetsPage(wxNotebook *notebook, m_textMax = new wxTextCtrl(this, SliderPage_MaxText, _T("")); sizerRow->Add(m_textMax, 1, wxLEFT | wxALIGN_CENTRE_VERTICAL, 5); - m_textMin->SetValue(wxString::Format(_T("%lu"), m_min)); - m_textMax->SetValue(wxString::Format(_T("%lu"), m_max)); + m_textMin->SetValue( wxString::Format(_T("%d"), m_min) ); + m_textMax->SetValue( wxString::Format(_T("%d"), m_max) ); sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); @@ -248,7 +247,7 @@ SliderWidgetsPage::SliderWidgetsPage(wxNotebook *notebook, // right pane wxSizer *sizerRight = new wxBoxSizer(wxHORIZONTAL); - sizerRight->SetMinSize(250, 0); + sizerRight->SetMinSize(150, 0); m_sizerSlider = sizerRight; // save it to modify it later Reset(); @@ -256,7 +255,7 @@ SliderWidgetsPage::SliderWidgetsPage(wxNotebook *notebook, // the 3 panes panes compose the window sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10); - sizerTop->Add(sizerMiddle, 1, wxGROW | wxALL, 10); + sizerTop->Add(sizerMiddle, 0, wxGROW | wxALL, 10); sizerTop->Add(sizerRight, 1, wxGROW | (wxALL & ~wxRIGHT), 10); // final initializations @@ -450,7 +449,7 @@ void SliderWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& event) void SliderWidgetsPage::OnUpdateUICurValueText(wxUpdateUIEvent& event) { - event.SetText( wxString::Format(_T("%d"), m_slider->GetValue())); + event.SetText( wxString::Format(_T("%d"), m_slider->GetValue()) ); } void SliderWidgetsPage::OnUpdateUIOtherSide(wxUpdateUIEvent& event) @@ -458,13 +457,48 @@ void SliderWidgetsPage::OnUpdateUIOtherSide(wxUpdateUIEvent& event) event.Enable( m_chkLabels->GetValue() ); } -void SliderWidgetsPage::OnSlider(wxCommandEvent& event) +void SliderWidgetsPage::OnSlider(wxScrollEvent& event) { - int value = event.GetInt(); + long value = event.GetInt(); wxASSERT_MSG( value == m_slider->GetValue(), - _T("slider value should be the same") ); + wxT("slider value should be the same") ); + + wxEventType eventType = event.GetEventType(); - wxLogMessage(_T("Slider value changed, now %d"), value); + /* + This array takes the EXACT order of the declarations in + include/wx/event.h + (section "wxScrollBar and wxSlider event identifiers") + */ + static const wxChar *eventNames[] = + { + wxT("wxEVT_SCROLL_TOP"), + wxT("wxEVT_SCROLL_BOTTOM"), + wxT("wxEVT_SCROLL_LINEUP"), + wxT("wxEVT_SCROLL_LINEDOWN"), + wxT("wxEVT_SCROLL_PAGEUP"), + wxT("wxEVT_SCROLL_PAGEDOWN"), + wxT("wxEVT_SCROLL_THUMBTRACK"), + wxT("wxEVT_SCROLL_THUMBRELEASE"), + wxT("wxEVT_SCROLL_ENDSCROLL") + }; + + int index = eventType - wxEVT_SCROLL_TOP; + + /* + If this assert is triggered, there is an unknown slider event which + should be added to the above eventNames array. + */ + wxASSERT_MSG(index >= 0 && (size_t)index < WXSIZEOF(eventNames), + wxT("Unknown slider event") ); + + + static int s_numSliderEvents = 0; + + wxLogMessage(wxT("Slider event #%d: %s (pos = %d)"), + s_numSliderEvents++, + eventNames[index], + event.GetPosition()); }