#include "wx/sizer.h"
#include "widgets.h"
-
#include "icons/slider.xpm"
// ----------------------------------------------------------------------------
// control ids
enum
{
- SliderPage_Reset = 100,
+ SliderPage_Reset = wxID_HIGHEST,
SliderPage_Clear,
SliderPage_SetValue,
SliderPage_SetMinAndMax,
void OnCheckOrRadioBox(wxCommandEvent& event);
- void OnSlider(wxCommandEvent& event);
+ void OnSlider(wxScrollEvent& event);
void OnUpdateUIOtherSide(wxUpdateUIEvent& event);
void OnUpdateUIValueButton(wxUpdateUIEvent& event);
*m_textTickFreq;
private:
- DECLARE_EVENT_TABLE();
- DECLARE_WIDGETS_PAGE(SliderWidgetsPage);
+ DECLARE_EVENT_TABLE()
+ DECLARE_WIDGETS_PAGE(SliderWidgetsPage)
};
// ----------------------------------------------------------------------------
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)
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);
// 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();
// 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
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)
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());
}