2001-06-26 17:05:06 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2004-05-25 07:20:37 -04:00
|
|
|
// Program: wxWidgets Widgets Sample
|
2001-06-26 17:05:06 -04:00
|
|
|
// Name: slider.cpp
|
|
|
|
// Purpose: Part of the widgets sample showing wxSlider
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Created: 16.04.01
|
|
|
|
// Id: $Id$
|
|
|
|
// Copyright: (c) 2001 Vadim Zeitlin
|
|
|
|
// License: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// declarations
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// for compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
2004-11-23 06:45:07 -05:00
|
|
|
#if wxUSE_SLIDER
|
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
// for all others, include the necessary headers
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/log.h"
|
|
|
|
|
2003-03-23 10:12:41 -05:00
|
|
|
#include "wx/bitmap.h"
|
2001-06-26 17:05:06 -04:00
|
|
|
#include "wx/button.h"
|
|
|
|
#include "wx/checkbox.h"
|
|
|
|
#include "wx/radiobox.h"
|
|
|
|
#include "wx/slider.h"
|
|
|
|
#include "wx/statbox.h"
|
|
|
|
#include "wx/textctrl.h"
|
|
|
|
#endif
|
|
|
|
|
2003-01-24 06:55:29 -05:00
|
|
|
#if wxUSE_TOOLTIPS
|
|
|
|
#include "wx/tooltip.h"
|
|
|
|
#endif
|
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
#include "wx/sizer.h"
|
|
|
|
|
|
|
|
#include "widgets.h"
|
2004-11-23 06:45:07 -05:00
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
#include "icons/slider.xpm"
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// control ids
|
|
|
|
enum
|
|
|
|
{
|
2002-07-09 19:33:46 -04:00
|
|
|
SliderPage_Reset = wxID_HIGHEST,
|
2001-06-26 17:05:06 -04:00
|
|
|
SliderPage_Clear,
|
|
|
|
SliderPage_SetValue,
|
|
|
|
SliderPage_SetMinAndMax,
|
2006-07-27 01:05:21 -04:00
|
|
|
SliderPage_SetLineSize,
|
|
|
|
SliderPage_SetPageSize,
|
2001-06-26 17:05:06 -04:00
|
|
|
SliderPage_SetTickFreq,
|
2003-01-24 06:55:29 -05:00
|
|
|
SliderPage_SetThumbLen,
|
2001-06-26 17:05:06 -04:00
|
|
|
SliderPage_CurValueText,
|
|
|
|
SliderPage_ValueText,
|
|
|
|
SliderPage_MinText,
|
|
|
|
SliderPage_MaxText,
|
2006-07-27 01:05:21 -04:00
|
|
|
SliderPage_LineSizeText,
|
|
|
|
SliderPage_PageSizeText,
|
2001-06-26 17:05:06 -04:00
|
|
|
SliderPage_TickFreqText,
|
2003-01-24 06:55:29 -05:00
|
|
|
SliderPage_ThumbLenText,
|
|
|
|
SliderPage_RadioSides,
|
|
|
|
SliderPage_BothSides,
|
2001-06-26 17:05:06 -04:00
|
|
|
SliderPage_Slider
|
|
|
|
};
|
|
|
|
|
2003-01-24 06:55:29 -05:00
|
|
|
// sides radiobox values
|
|
|
|
enum
|
|
|
|
{
|
2005-04-10 14:07:08 -04:00
|
|
|
SliderTicks_Top,
|
|
|
|
SliderTicks_Bottom,
|
|
|
|
SliderTicks_Left,
|
|
|
|
SliderTicks_Right
|
2003-01-24 06:55:29 -05:00
|
|
|
};
|
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// SliderWidgetsPage
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class SliderWidgetsPage : public WidgetsPage
|
|
|
|
{
|
|
|
|
public:
|
2006-05-17 15:49:09 -04:00
|
|
|
SliderWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist);
|
2004-10-04 16:25:15 -04:00
|
|
|
virtual ~SliderWidgetsPage(){};
|
2001-06-26 17:05:06 -04:00
|
|
|
|
2004-11-19 14:03:04 -05:00
|
|
|
virtual wxControl *GetWidget() const { return m_slider; }
|
2006-04-16 19:39:11 -04:00
|
|
|
virtual void RecreateWidget() { CreateSlider(); }
|
2004-11-19 14:03:04 -05:00
|
|
|
|
2006-06-06 10:10:06 -04:00
|
|
|
// lazy creation of the content
|
|
|
|
virtual void CreateContent();
|
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
protected:
|
|
|
|
// event handlers
|
|
|
|
void OnButtonReset(wxCommandEvent& event);
|
|
|
|
void OnButtonClear(wxCommandEvent& event);
|
|
|
|
void OnButtonSetValue(wxCommandEvent& event);
|
|
|
|
void OnButtonSetMinAndMax(wxCommandEvent& event);
|
2006-07-27 01:05:21 -04:00
|
|
|
void OnButtonSetLineSize(wxCommandEvent& event);
|
|
|
|
void OnButtonSetPageSize(wxCommandEvent& event);
|
2001-06-26 17:05:06 -04:00
|
|
|
void OnButtonSetTickFreq(wxCommandEvent& event);
|
2003-01-24 06:55:29 -05:00
|
|
|
void OnButtonSetThumbLen(wxCommandEvent& event);
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
void OnCheckOrRadioBox(wxCommandEvent& event);
|
|
|
|
|
2002-07-09 19:33:46 -04:00
|
|
|
void OnSlider(wxScrollEvent& event);
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
void OnUpdateUIValueButton(wxUpdateUIEvent& event);
|
|
|
|
void OnUpdateUIMinMaxButton(wxUpdateUIEvent& event);
|
2006-07-27 01:05:21 -04:00
|
|
|
void OnUpdateUILineSize(wxUpdateUIEvent& event);
|
|
|
|
void OnUpdateUIPageSize(wxUpdateUIEvent& event);
|
2001-06-26 17:05:06 -04:00
|
|
|
void OnUpdateUITickFreq(wxUpdateUIEvent& event);
|
2003-01-24 06:55:29 -05:00
|
|
|
void OnUpdateUIThumbLen(wxUpdateUIEvent& event);
|
|
|
|
void OnUpdateUIRadioSides(wxUpdateUIEvent& event);
|
|
|
|
void OnUpdateUIBothSides(wxUpdateUIEvent& event);
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
void OnUpdateUIResetButton(wxUpdateUIEvent& event);
|
|
|
|
|
|
|
|
void OnUpdateUICurValueText(wxUpdateUIEvent& event);
|
|
|
|
|
|
|
|
// reset the slider parameters
|
|
|
|
void Reset();
|
|
|
|
|
|
|
|
// (re)create the slider
|
|
|
|
void CreateSlider();
|
|
|
|
|
2006-07-27 01:05:21 -04:00
|
|
|
// set the line size from the text field value
|
|
|
|
void DoSetLineSize();
|
|
|
|
|
|
|
|
// set the page size from the text field value
|
|
|
|
void DoSetPageSize();
|
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
// set the tick frequency from the text field value
|
|
|
|
void DoSetTickFreq();
|
|
|
|
|
2003-01-24 06:55:29 -05:00
|
|
|
// set the thumb len from the text field value
|
|
|
|
void DoSetThumbLen();
|
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
// is this slider value in range?
|
|
|
|
bool IsValidValue(int val) const
|
|
|
|
{ return (val >= m_min) && (val <= m_max); }
|
|
|
|
|
|
|
|
// the slider range
|
|
|
|
int m_min, m_max;
|
|
|
|
|
|
|
|
// the controls
|
|
|
|
// ------------
|
|
|
|
|
|
|
|
// the check/radio boxes for styles
|
|
|
|
wxCheckBox *m_chkLabels,
|
2005-01-23 15:17:21 -05:00
|
|
|
*m_chkInverse,
|
2003-01-24 06:55:29 -05:00
|
|
|
*m_chkTicks,
|
|
|
|
*m_chkBothSides;
|
|
|
|
|
|
|
|
wxRadioBox *m_radioSides;
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
// the slider itself and the sizer it is in
|
|
|
|
wxSlider *m_slider;
|
|
|
|
wxSizer *m_sizerSlider;
|
|
|
|
|
|
|
|
// the text entries for set value/range
|
|
|
|
wxTextCtrl *m_textValue,
|
|
|
|
*m_textMin,
|
|
|
|
*m_textMax,
|
2006-07-27 01:05:21 -04:00
|
|
|
*m_textLineSize,
|
|
|
|
*m_textPageSize,
|
2003-01-24 06:55:29 -05:00
|
|
|
*m_textTickFreq,
|
|
|
|
*m_textThumbLen;
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
private:
|
2001-11-25 10:18:38 -05:00
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
DECLARE_WIDGETS_PAGE(SliderWidgetsPage)
|
2001-06-26 17:05:06 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// event tables
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(SliderWidgetsPage, WidgetsPage)
|
|
|
|
EVT_BUTTON(SliderPage_Reset, SliderWidgetsPage::OnButtonReset)
|
|
|
|
EVT_BUTTON(SliderPage_SetValue, SliderWidgetsPage::OnButtonSetValue)
|
|
|
|
EVT_BUTTON(SliderPage_SetMinAndMax, SliderWidgetsPage::OnButtonSetMinAndMax)
|
2006-07-27 01:05:21 -04:00
|
|
|
EVT_BUTTON(SliderPage_SetLineSize, SliderWidgetsPage::OnButtonSetLineSize)
|
|
|
|
EVT_BUTTON(SliderPage_SetPageSize, SliderWidgetsPage::OnButtonSetPageSize)
|
2001-06-26 17:05:06 -04:00
|
|
|
EVT_BUTTON(SliderPage_SetTickFreq, SliderWidgetsPage::OnButtonSetTickFreq)
|
2003-01-24 06:55:29 -05:00
|
|
|
EVT_BUTTON(SliderPage_SetThumbLen, SliderWidgetsPage::OnButtonSetThumbLen)
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
EVT_UPDATE_UI(SliderPage_SetValue, SliderWidgetsPage::OnUpdateUIValueButton)
|
|
|
|
EVT_UPDATE_UI(SliderPage_SetMinAndMax, SliderWidgetsPage::OnUpdateUIMinMaxButton)
|
2006-07-27 01:05:21 -04:00
|
|
|
EVT_UPDATE_UI(SliderPage_SetLineSize, SliderWidgetsPage::OnUpdateUILineSize)
|
|
|
|
EVT_UPDATE_UI(SliderPage_SetPageSize, SliderWidgetsPage::OnUpdateUIPageSize)
|
2001-06-26 17:05:06 -04:00
|
|
|
EVT_UPDATE_UI(SliderPage_SetTickFreq, SliderWidgetsPage::OnUpdateUITickFreq)
|
2003-01-24 06:55:29 -05:00
|
|
|
EVT_UPDATE_UI(SliderPage_SetThumbLen, SliderWidgetsPage::OnUpdateUIThumbLen)
|
|
|
|
EVT_UPDATE_UI(SliderPage_RadioSides, SliderWidgetsPage::OnUpdateUIRadioSides)
|
|
|
|
EVT_UPDATE_UI(SliderPage_BothSides, SliderWidgetsPage::OnUpdateUIBothSides)
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
EVT_UPDATE_UI(SliderPage_Reset, SliderWidgetsPage::OnUpdateUIResetButton)
|
|
|
|
|
|
|
|
EVT_UPDATE_UI(SliderPage_CurValueText, SliderWidgetsPage::OnUpdateUICurValueText)
|
|
|
|
|
2002-07-09 19:33:46 -04:00
|
|
|
EVT_COMMAND_SCROLL(SliderPage_Slider, SliderWidgetsPage::OnSlider)
|
2001-06-26 17:05:06 -04:00
|
|
|
|
2003-12-11 05:32:15 -05:00
|
|
|
EVT_CHECKBOX(wxID_ANY, SliderWidgetsPage::OnCheckOrRadioBox)
|
|
|
|
EVT_RADIOBOX(wxID_ANY, SliderWidgetsPage::OnCheckOrRadioBox)
|
2001-06-26 17:05:06 -04:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// implementation
|
|
|
|
// ============================================================================
|
|
|
|
|
2006-05-22 06:39:40 -04:00
|
|
|
#if defined(__WXUNIVERSAL__)
|
|
|
|
#define FAMILY_CTRLS UNIVERSAL_CTRLS
|
|
|
|
#else
|
|
|
|
#define FAMILY_CTRLS NATIVE_CTRLS
|
|
|
|
#endif
|
|
|
|
|
|
|
|
IMPLEMENT_WIDGETS_PAGE(SliderWidgetsPage, _T("Slider"), FAMILY_CTRLS );
|
2001-06-26 17:05:06 -04:00
|
|
|
|
2006-05-17 15:49:09 -04:00
|
|
|
SliderWidgetsPage::SliderWidgetsPage(WidgetsBookCtrl *book,
|
2004-11-23 06:45:07 -05:00
|
|
|
wxImageList *imaglist)
|
2006-05-26 10:07:47 -04:00
|
|
|
: WidgetsPage(book, imaglist, slider_xpm)
|
2001-06-26 17:05:06 -04:00
|
|
|
{
|
|
|
|
// init everything
|
|
|
|
m_min = 0;
|
|
|
|
m_max = 100;
|
|
|
|
|
2005-01-28 15:56:09 -05:00
|
|
|
m_chkInverse =
|
2001-06-26 17:05:06 -04:00
|
|
|
m_chkTicks =
|
|
|
|
m_chkLabels =
|
2003-01-24 06:55:29 -05:00
|
|
|
m_chkBothSides = (wxCheckBox *)NULL;
|
|
|
|
|
|
|
|
m_radioSides = (wxRadioBox *)NULL;
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
m_slider = (wxSlider *)NULL;
|
|
|
|
m_sizerSlider = (wxSizer *)NULL;
|
2006-06-06 10:10:06 -04:00
|
|
|
}
|
2001-06-26 17:05:06 -04:00
|
|
|
|
2006-06-06 10:10:06 -04:00
|
|
|
void SliderWidgetsPage::CreateContent()
|
|
|
|
{
|
2001-06-26 17:05:06 -04:00
|
|
|
wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
|
|
|
|
// left pane
|
2003-12-11 05:32:15 -05:00
|
|
|
wxStaticBox *box = new wxStaticBox(this, wxID_ANY, _T("&Set style"));
|
2001-06-26 17:05:06 -04:00
|
|
|
wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
|
|
|
|
|
2005-01-23 15:17:21 -05:00
|
|
|
m_chkInverse = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&Inverse"));
|
2001-06-26 17:05:06 -04:00
|
|
|
m_chkTicks = CreateCheckBoxAndAddToSizer(sizerLeft, _T("Show &ticks"));
|
|
|
|
m_chkLabels = CreateCheckBoxAndAddToSizer(sizerLeft, _T("Show &labels"));
|
2003-01-24 06:55:29 -05:00
|
|
|
static const wxString sides[] =
|
|
|
|
{
|
|
|
|
_T("top"),
|
|
|
|
_T("bottom"),
|
|
|
|
_T("left"),
|
|
|
|
_T("right"),
|
|
|
|
};
|
|
|
|
m_radioSides = new wxRadioBox(this, SliderPage_RadioSides, _T("&Ticks/Labels"),
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
WXSIZEOF(sides), sides,
|
|
|
|
1, wxRA_SPECIFY_COLS);
|
|
|
|
sizerLeft->Add(m_radioSides, 0, wxGROW | wxALL, 5);
|
|
|
|
m_chkBothSides = CreateCheckBoxAndAddToSizer
|
|
|
|
(sizerLeft, _T("&Both sides"), SliderPage_BothSides);
|
|
|
|
#if wxUSE_TOOLTIPS
|
|
|
|
m_chkBothSides->SetToolTip( _T("\"Both sides\" is only supported \nin Win95 and Universal") );
|
|
|
|
#endif // wxUSE_TOOLTIPS
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
|
|
|
|
|
|
|
|
wxButton *btn = new wxButton(this, SliderPage_Reset, _T("&Reset"));
|
|
|
|
sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
|
|
|
|
|
|
|
|
// middle pane
|
2003-12-11 05:32:15 -05:00
|
|
|
wxStaticBox *box2 = new wxStaticBox(this, wxID_ANY, _T("&Change slider value"));
|
2001-06-26 17:05:06 -04:00
|
|
|
wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL);
|
|
|
|
|
|
|
|
wxTextCtrl *text;
|
|
|
|
wxSizer *sizerRow = CreateSizerWithTextAndLabel(_T("Current value"),
|
|
|
|
SliderPage_CurValueText,
|
|
|
|
&text);
|
2003-12-11 05:32:15 -05:00
|
|
|
text->SetEditable(false);
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
|
|
|
|
|
|
|
|
sizerRow = CreateSizerWithTextAndButton(SliderPage_SetValue,
|
|
|
|
_T("Set &value"),
|
|
|
|
SliderPage_ValueText,
|
|
|
|
&m_textValue);
|
|
|
|
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
|
|
|
|
|
|
|
|
sizerRow = CreateSizerWithTextAndButton(SliderPage_SetMinAndMax,
|
|
|
|
_T("&Min and max"),
|
|
|
|
SliderPage_MinText,
|
|
|
|
&m_textMin);
|
|
|
|
|
2003-12-11 05:32:15 -05:00
|
|
|
m_textMax = new wxTextCtrl(this, SliderPage_MaxText, wxEmptyString);
|
2001-06-26 17:05:06 -04:00
|
|
|
sizerRow->Add(m_textMax, 1, wxLEFT | wxALIGN_CENTRE_VERTICAL, 5);
|
|
|
|
|
2002-08-01 15:12:24 -04:00
|
|
|
m_textMin->SetValue( wxString::Format(_T("%d"), m_min) );
|
|
|
|
m_textMax->SetValue( wxString::Format(_T("%d"), m_max) );
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
|
|
|
|
|
2006-07-27 01:05:21 -04:00
|
|
|
sizerRow = CreateSizerWithTextAndButton(SliderPage_SetLineSize,
|
|
|
|
_T("Li&ne size"),
|
|
|
|
SliderPage_LineSizeText,
|
|
|
|
&m_textLineSize);
|
|
|
|
|
|
|
|
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
|
|
|
|
|
|
|
|
sizerRow = CreateSizerWithTextAndButton(SliderPage_SetPageSize,
|
|
|
|
_T("P&age size"),
|
|
|
|
SliderPage_PageSizeText,
|
|
|
|
&m_textPageSize);
|
|
|
|
|
|
|
|
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
|
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
sizerRow = CreateSizerWithTextAndButton(SliderPage_SetTickFreq,
|
|
|
|
_T("Tick &frequency"),
|
|
|
|
SliderPage_TickFreqText,
|
|
|
|
&m_textTickFreq);
|
|
|
|
|
|
|
|
m_textTickFreq->SetValue(_T("10"));
|
|
|
|
|
|
|
|
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
|
|
|
|
|
2003-01-24 06:55:29 -05:00
|
|
|
sizerRow = CreateSizerWithTextAndButton(SliderPage_SetThumbLen,
|
2004-09-03 21:26:40 -04:00
|
|
|
_T("Thumb &length"),
|
2003-01-24 06:55:29 -05:00
|
|
|
SliderPage_ThumbLenText,
|
|
|
|
&m_textThumbLen);
|
|
|
|
|
|
|
|
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
|
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
// right pane
|
|
|
|
wxSizer *sizerRight = new wxBoxSizer(wxHORIZONTAL);
|
2003-01-24 06:55:29 -05:00
|
|
|
sizerRight->SetMinSize(150, 40);
|
2001-06-26 17:05:06 -04:00
|
|
|
m_sizerSlider = sizerRight; // save it to modify it later
|
|
|
|
|
|
|
|
Reset();
|
|
|
|
CreateSlider();
|
|
|
|
|
2006-07-27 01:05:21 -04:00
|
|
|
m_textLineSize->SetValue(wxString::Format(_T("%d"), m_slider->GetLineSize()));
|
|
|
|
m_textPageSize->SetValue(wxString::Format(_T("%d"), m_slider->GetPageSize()));
|
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
// the 3 panes panes compose the window
|
|
|
|
sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10);
|
2002-04-09 06:31:37 -04:00
|
|
|
sizerTop->Add(sizerMiddle, 0, wxGROW | wxALL, 10);
|
2001-06-26 17:05:06 -04:00
|
|
|
sizerTop->Add(sizerRight, 1, wxGROW | (wxALL & ~wxRIGHT), 10);
|
|
|
|
|
|
|
|
// final initializations
|
|
|
|
SetSizer(sizerTop);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// operations
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void SliderWidgetsPage::Reset()
|
|
|
|
{
|
2005-01-23 15:17:21 -05:00
|
|
|
m_chkInverse->SetValue(false);
|
2003-12-11 05:32:15 -05:00
|
|
|
m_chkTicks->SetValue(true);
|
|
|
|
m_chkLabels->SetValue(true);
|
|
|
|
m_chkBothSides->SetValue(false);
|
2003-01-24 06:55:29 -05:00
|
|
|
|
2005-04-10 14:07:08 -04:00
|
|
|
m_radioSides->SetSelection(SliderTicks_Top);
|
2001-06-26 17:05:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SliderWidgetsPage::CreateSlider()
|
|
|
|
{
|
2006-04-16 19:39:11 -04:00
|
|
|
int flags = ms_defaultFlags;
|
2001-06-26 17:05:06 -04:00
|
|
|
|
2005-01-23 15:17:21 -05:00
|
|
|
if ( m_chkInverse->GetValue() )
|
|
|
|
{
|
|
|
|
flags |= wxSL_INVERSE;
|
|
|
|
}
|
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
if ( m_chkLabels->GetValue() )
|
|
|
|
{
|
|
|
|
flags |= wxSL_LABELS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_chkTicks->GetValue() )
|
|
|
|
{
|
|
|
|
flags |= wxSL_AUTOTICKS;
|
|
|
|
}
|
|
|
|
|
2003-01-24 06:55:29 -05:00
|
|
|
switch ( m_radioSides->GetSelection() )
|
|
|
|
{
|
2005-04-10 14:07:08 -04:00
|
|
|
case SliderTicks_Top:
|
2003-01-24 06:55:29 -05:00
|
|
|
flags |= wxSL_TOP;
|
|
|
|
break;
|
2005-04-10 14:07:08 -04:00
|
|
|
|
|
|
|
case SliderTicks_Left:
|
2003-01-24 06:55:29 -05:00
|
|
|
flags |= wxSL_LEFT;
|
|
|
|
break;
|
2005-04-10 14:07:08 -04:00
|
|
|
|
|
|
|
case SliderTicks_Bottom:
|
2003-01-24 06:55:29 -05:00
|
|
|
flags |= wxSL_BOTTOM;
|
|
|
|
break;
|
2005-04-10 14:07:08 -04:00
|
|
|
|
|
|
|
case SliderTicks_Right:
|
2003-01-24 06:55:29 -05:00
|
|
|
flags |= wxSL_RIGHT;
|
|
|
|
break;
|
2005-04-10 14:07:08 -04:00
|
|
|
|
2003-01-24 06:55:29 -05:00
|
|
|
default:
|
|
|
|
wxFAIL_MSG(_T("unexpected radiobox selection"));
|
|
|
|
// fall through
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_chkBothSides->GetValue() )
|
|
|
|
{
|
|
|
|
flags |= wxSL_BOTH;
|
|
|
|
}
|
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
int val = m_min;
|
|
|
|
if ( m_slider )
|
|
|
|
{
|
|
|
|
int valOld = m_slider->GetValue();
|
|
|
|
if ( !IsValidValue(valOld) )
|
|
|
|
{
|
|
|
|
val = valOld;
|
|
|
|
}
|
|
|
|
|
Deprecated wxSizer::Remove( wxWindow* ), s/Remove/Detach/ in most places.
Made wxSizer child list typesafe. I've not added the wxList implicit
conversion kludge yet, let's see who complains first perhaps..
Deprecated wxSizer::{G,S}etOption in favour of {G,S}etProportion in line
with the parameter name change in the docs.
Added {G,S}etSpacer consistent with the accessors for windows/sizers.
Made all wxSizer index parameters size_t -- we support no sensible
interpretation for negative indexes in them. Hopefully this will
cause no real problems, but code doing (eg. Remove( 0 )) will need
to change to use 0u to resolve the ambiguity with overloaded members.
This is probably a Good Thing though, ymmv.
s/FALSE/false/g ; s/TRUE/true/g ; s/wxASSERT/wxASSERT_MSG/g in sizer.{cpp,h}
Fixed (I hope) the brokenness in wxSizer::Show -- I have no code to test
this yet, so it's a blind change, but spacers should now be hidden correctly
instead of ignored, and it should be properly reversable over multiple
calls now too.
removed pointless private scoping around DECLARE_CLASS macros.
Replace 0's I added previously with NULL -- not like that will end the
email thread either..
Added Add( wxSizerItem * ) & co. There are probably a couple of other
places we can usefully do something like this too. Stopped short of
refactoring everything to raise some issues about sizer method recursion
on -dev.
Updated wxSizer docs some more, they are still incomplete but getting
better.
wrapped KeyCode in wxDEPRECATED, converted all (gtk build) instances
to GetKeyCode. There may be a few left for other ports.
Fixed a couple of other random compile warnings along the way.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@18616 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2003-01-07 05:22:07 -05:00
|
|
|
m_sizerSlider->Detach( m_slider );
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
if ( m_sizerSlider->GetChildren().GetCount() )
|
|
|
|
{
|
|
|
|
// we have 2 spacers, remove them too
|
2003-01-26 09:03:29 -05:00
|
|
|
m_sizerSlider->Remove( 0 );
|
|
|
|
m_sizerSlider->Remove( 0 );
|
2001-06-26 17:05:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
delete m_slider;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_slider = new wxSlider(this, SliderPage_Slider,
|
|
|
|
val, m_min, m_max,
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
flags);
|
|
|
|
|
2005-04-10 14:07:08 -04:00
|
|
|
if ( m_slider->HasFlag(wxSL_VERTICAL) )
|
2001-06-26 17:05:06 -04:00
|
|
|
{
|
|
|
|
m_sizerSlider->Add(0, 0, 1);
|
|
|
|
m_sizerSlider->Add(m_slider, 0, wxGROW | wxALL, 5);
|
|
|
|
m_sizerSlider->Add(0, 0, 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_sizerSlider->Add(m_slider, 1, wxCENTRE | wxALL, 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_chkTicks->GetValue() )
|
|
|
|
{
|
|
|
|
DoSetTickFreq();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_sizerSlider->Layout();
|
|
|
|
}
|
|
|
|
|
2006-07-27 01:05:21 -04:00
|
|
|
void SliderWidgetsPage::DoSetLineSize()
|
|
|
|
{
|
|
|
|
long lineSize;
|
|
|
|
if ( !m_textLineSize->GetValue().ToLong(&lineSize) )
|
|
|
|
{
|
|
|
|
wxLogWarning(_T("Invalid slider line size"));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_slider->SetLineSize(lineSize);
|
|
|
|
|
|
|
|
if ( m_slider->GetLineSize() != lineSize )
|
|
|
|
{
|
|
|
|
wxLogWarning(_T("Invalid line size in slider."));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SliderWidgetsPage::DoSetPageSize()
|
|
|
|
{
|
|
|
|
long pageSize;
|
|
|
|
if ( !m_textPageSize->GetValue().ToLong(&pageSize) )
|
|
|
|
{
|
|
|
|
wxLogWarning(_T("Invalid slider page size"));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_slider->SetPageSize(pageSize);
|
|
|
|
|
|
|
|
if ( m_slider->GetPageSize() != pageSize )
|
|
|
|
{
|
|
|
|
wxLogWarning(_T("Invalid page size in slider."));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
void SliderWidgetsPage::DoSetTickFreq()
|
|
|
|
{
|
|
|
|
long freq;
|
|
|
|
if ( !m_textTickFreq->GetValue().ToLong(&freq) )
|
|
|
|
{
|
|
|
|
wxLogWarning(_T("Invalid slider tick frequency"));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_slider->SetTickFreq(freq, 0 /* unused */);
|
|
|
|
}
|
|
|
|
|
2003-01-24 06:55:29 -05:00
|
|
|
void SliderWidgetsPage::DoSetThumbLen()
|
|
|
|
{
|
|
|
|
long len;
|
|
|
|
if ( !m_textThumbLen->GetValue().ToLong(&len) )
|
|
|
|
{
|
2004-09-03 21:26:40 -04:00
|
|
|
wxLogWarning(_T("Invalid slider thumb length"));
|
2003-01-24 06:55:29 -05:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_slider->SetThumbLength(len);
|
|
|
|
}
|
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// event handlers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void SliderWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
|
|
|
|
CreateSlider();
|
|
|
|
}
|
|
|
|
|
2006-07-27 01:05:21 -04:00
|
|
|
void SliderWidgetsPage::OnButtonSetLineSize(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
DoSetLineSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SliderWidgetsPage::OnButtonSetPageSize(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
DoSetPageSize();
|
|
|
|
}
|
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
void SliderWidgetsPage::OnButtonSetTickFreq(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
DoSetTickFreq();
|
|
|
|
}
|
|
|
|
|
2003-01-24 06:55:29 -05:00
|
|
|
void SliderWidgetsPage::OnButtonSetThumbLen(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
DoSetThumbLen();
|
|
|
|
}
|
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
void SliderWidgetsPage::OnButtonSetMinAndMax(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
long minNew,
|
|
|
|
maxNew = 0; // init to suppress compiler warning
|
|
|
|
if ( !m_textMin->GetValue().ToLong(&minNew) ||
|
|
|
|
!m_textMax->GetValue().ToLong(&maxNew) ||
|
|
|
|
minNew >= maxNew )
|
|
|
|
{
|
|
|
|
wxLogWarning(_T("Invalid min/max values for the slider."));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_min = minNew;
|
|
|
|
m_max = maxNew;
|
|
|
|
|
|
|
|
m_slider->SetRange(minNew, maxNew);
|
2005-03-21 12:30:10 -05:00
|
|
|
|
|
|
|
if ( m_slider->GetMin() != m_min ||
|
|
|
|
m_slider->GetMax() != m_max )
|
|
|
|
{
|
|
|
|
wxLogWarning(_T("Invalid range in slider."));
|
|
|
|
}
|
2001-06-26 17:05:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SliderWidgetsPage::OnButtonSetValue(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
long val;
|
|
|
|
if ( !m_textValue->GetValue().ToLong(&val) || !IsValidValue(val) )
|
|
|
|
{
|
|
|
|
wxLogWarning(_T("Invalid slider value."));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_slider->SetValue(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SliderWidgetsPage::OnUpdateUIValueButton(wxUpdateUIEvent& event)
|
|
|
|
{
|
|
|
|
long val;
|
|
|
|
event.Enable( m_textValue->GetValue().ToLong(&val) && IsValidValue(val) );
|
|
|
|
}
|
|
|
|
|
2006-07-27 01:05:21 -04:00
|
|
|
void SliderWidgetsPage::OnUpdateUILineSize(wxUpdateUIEvent& event)
|
|
|
|
{
|
|
|
|
long lineSize;
|
|
|
|
event.Enable( m_textLineSize->GetValue().ToLong(&lineSize) &&
|
|
|
|
(lineSize > 0) && (lineSize <= m_max - m_min) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void SliderWidgetsPage::OnUpdateUIPageSize(wxUpdateUIEvent& event)
|
|
|
|
{
|
|
|
|
long pageSize;
|
|
|
|
event.Enable( m_textPageSize->GetValue().ToLong(&pageSize) &&
|
|
|
|
(pageSize > 0) && (pageSize <= m_max - m_min) );
|
|
|
|
}
|
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
void SliderWidgetsPage::OnUpdateUITickFreq(wxUpdateUIEvent& event)
|
|
|
|
{
|
|
|
|
long freq;
|
|
|
|
event.Enable( m_chkTicks->GetValue() &&
|
|
|
|
m_textTickFreq->GetValue().ToLong(&freq) &&
|
|
|
|
(freq > 0) && (freq <= m_max - m_min) );
|
|
|
|
}
|
|
|
|
|
2003-01-24 06:55:29 -05:00
|
|
|
void SliderWidgetsPage::OnUpdateUIThumbLen(wxUpdateUIEvent& event)
|
|
|
|
{
|
|
|
|
long val;
|
|
|
|
event.Enable( m_textThumbLen->GetValue().ToLong(&val));
|
|
|
|
}
|
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
void SliderWidgetsPage::OnUpdateUIMinMaxButton(wxUpdateUIEvent& event)
|
|
|
|
{
|
|
|
|
long mn, mx;
|
|
|
|
event.Enable( m_textMin->GetValue().ToLong(&mn) &&
|
|
|
|
m_textMax->GetValue().ToLong(&mx) &&
|
|
|
|
mn < mx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SliderWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event)
|
|
|
|
{
|
2005-04-10 14:07:08 -04:00
|
|
|
event.Enable( m_chkInverse->GetValue() ||
|
2003-01-24 06:55:29 -05:00
|
|
|
!m_chkTicks->GetValue() ||
|
2001-06-26 17:05:06 -04:00
|
|
|
!m_chkLabels->GetValue() ||
|
2005-04-10 14:07:08 -04:00
|
|
|
m_chkBothSides->GetValue() ||
|
|
|
|
m_radioSides->GetSelection() != SliderTicks_Top );
|
2001-06-26 17:05:06 -04:00
|
|
|
}
|
|
|
|
|
2003-07-31 09:59:28 -04:00
|
|
|
void SliderWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event))
|
2001-06-26 17:05:06 -04:00
|
|
|
{
|
|
|
|
CreateSlider();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SliderWidgetsPage::OnUpdateUICurValueText(wxUpdateUIEvent& event)
|
|
|
|
{
|
2002-08-01 15:12:24 -04:00
|
|
|
event.SetText( wxString::Format(_T("%d"), m_slider->GetValue()) );
|
2001-06-26 17:05:06 -04:00
|
|
|
}
|
|
|
|
|
2003-01-24 06:55:29 -05:00
|
|
|
void SliderWidgetsPage::OnUpdateUIRadioSides(wxUpdateUIEvent& event)
|
|
|
|
{
|
|
|
|
event.Enable( m_chkLabels->GetValue() || m_chkTicks->GetValue() );
|
|
|
|
}
|
|
|
|
|
|
|
|
void SliderWidgetsPage::OnUpdateUIBothSides(wxUpdateUIEvent& event)
|
2001-06-26 17:05:06 -04:00
|
|
|
{
|
2005-12-19 05:47:44 -05:00
|
|
|
#if defined(__WXMSW__) || defined(__WXUNIVERSAL__)
|
2003-01-24 06:55:29 -05:00
|
|
|
event.Enable( m_chkTicks->GetValue() );
|
|
|
|
#else
|
2003-12-11 05:32:15 -05:00
|
|
|
event.Enable( false );
|
2005-12-19 05:47:44 -05:00
|
|
|
#endif // defined(__WXMSW__) || defined(__WXUNIVERSAL__)
|
2001-06-26 17:05:06 -04:00
|
|
|
}
|
|
|
|
|
2002-07-09 19:33:46 -04:00
|
|
|
void SliderWidgetsPage::OnSlider(wxScrollEvent& event)
|
2001-06-26 17:05:06 -04:00
|
|
|
{
|
2002-12-04 09:11:26 -05:00
|
|
|
wxASSERT_MSG( event.GetInt() == m_slider->GetValue(),
|
|
|
|
wxT("slider value should be the same") );
|
2001-06-26 17:05:06 -04:00
|
|
|
|
2002-07-09 19:33:46 -04:00
|
|
|
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"),
|
2005-05-31 11:22:10 -04:00
|
|
|
wxT("wxEVT_SCROLL_CHANGED")
|
2002-07-09 19:33:46 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2002-08-22 15:22:52 -04:00
|
|
|
wxASSERT_MSG(index >= 0 && (size_t)index < WXSIZEOF(eventNames),
|
2002-07-09 19:33:46 -04:00
|
|
|
wxT("Unknown slider event") );
|
|
|
|
|
|
|
|
|
|
|
|
static int s_numSliderEvents = 0;
|
|
|
|
|
2006-04-28 13:07:14 -04:00
|
|
|
wxLogMessage(wxT("Slider event #%d: %s (pos = %d, int value = %d)"),
|
2002-07-10 10:11:05 -04:00
|
|
|
s_numSliderEvents++,
|
2002-07-09 19:33:46 -04:00
|
|
|
eventNames[index],
|
2005-01-23 15:17:21 -05:00
|
|
|
event.GetPosition(),
|
|
|
|
event.GetInt());
|
2001-06-26 17:05:06 -04:00
|
|
|
}
|
|
|
|
|
2004-11-23 06:45:07 -05:00
|
|
|
#endif // wxUSE_SLIDER
|