From d79b005a943715c66bb7e4e976baf2159b7e639d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 9 Jul 2002 23:33:46 +0000 Subject: [PATCH] report the sider events git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16127 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/widgets/slider.cpp | 49 +++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/samples/widgets/slider.cpp b/samples/widgets/slider.cpp index 2aa0e4027b..d6a19916cc 100644 --- a/samples/widgets/slider.cpp +++ b/samples/widgets/slider.cpp @@ -39,7 +39,6 @@ #include "wx/sizer.h" #include "widgets.h" -#if 1 #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); @@ -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) @@ -458,14 +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(); wxASSERT_MSG( value == m_slider->GetValue(), - _T("slider value should be the same") ); + wxT("slider value should be the same") ); - wxLogMessage(_T("Slider value changed, now %d"), value); + wxEventType eventType = event.GetEventType(); + + /* + 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 && index < WXSIZEOF(eventNames), + wxT("Unknown slider event") ); + + + static int s_numSliderEvents = 0; + + wxLogMessage(wxT("Slider event #%d: %s (pos = %d)"), + numSliderEvents++, + eventNames[index], + event.GetPosition()); } -#endif \ No newline at end of file -- 2.47.2