wxSlider event handling as described by Vadim in thread 'Slider events' at wx-dev. More changes towards wxRadioBox on Palm.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31852 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -111,7 +111,7 @@ protected:
|
|||||||
const wxString& label,
|
const wxString& label,
|
||||||
const wxPoint& pos,
|
const wxPoint& pos,
|
||||||
const wxSize& size,
|
const wxSize& size,
|
||||||
int groupID = 0);
|
uint8_t groupID = 0);
|
||||||
inline bool IsPalmControl() const { return m_palmControl; }
|
inline bool IsPalmControl() const { return m_palmControl; }
|
||||||
|
|
||||||
bool PalmCreateField(const wxString& label,
|
bool PalmCreateField(const wxString& label,
|
||||||
|
@@ -34,7 +34,7 @@ public:
|
|||||||
const wxSize& size = wxDefaultSize,
|
const wxSize& size = wxDefaultSize,
|
||||||
int n = 0, const wxString choices[] = NULL,
|
int n = 0, const wxString choices[] = NULL,
|
||||||
int majorDim = 0,
|
int majorDim = 0,
|
||||||
long style = wxRA_HORIZONTAL,
|
long style = wxRA_SPECIFY_COLS,
|
||||||
const wxValidator& val = wxDefaultValidator,
|
const wxValidator& val = wxDefaultValidator,
|
||||||
const wxString& name = wxRadioBoxNameStr)
|
const wxString& name = wxRadioBoxNameStr)
|
||||||
{
|
{
|
||||||
@@ -48,7 +48,7 @@ public:
|
|||||||
const wxSize& size,
|
const wxSize& size,
|
||||||
const wxArrayString& choices,
|
const wxArrayString& choices,
|
||||||
int majorDim = 0,
|
int majorDim = 0,
|
||||||
long style = wxRA_HORIZONTAL,
|
long style = wxRA_SPECIFY_COLS,
|
||||||
const wxValidator& val = wxDefaultValidator,
|
const wxValidator& val = wxDefaultValidator,
|
||||||
const wxString& name = wxRadioBoxNameStr)
|
const wxString& name = wxRadioBoxNameStr)
|
||||||
{
|
{
|
||||||
@@ -65,7 +65,7 @@ public:
|
|||||||
const wxSize& size = wxDefaultSize,
|
const wxSize& size = wxDefaultSize,
|
||||||
int n = 0, const wxString choices[] = NULL,
|
int n = 0, const wxString choices[] = NULL,
|
||||||
int majorDim = 0,
|
int majorDim = 0,
|
||||||
long style = wxRA_HORIZONTAL,
|
long style = wxRA_SPECIFY_COLS,
|
||||||
const wxValidator& val = wxDefaultValidator,
|
const wxValidator& val = wxDefaultValidator,
|
||||||
const wxString& name = wxRadioBoxNameStr);
|
const wxString& name = wxRadioBoxNameStr);
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ public:
|
|||||||
const wxSize& size,
|
const wxSize& size,
|
||||||
const wxArrayString& choices,
|
const wxArrayString& choices,
|
||||||
int majorDim = 0,
|
int majorDim = 0,
|
||||||
long style = wxRA_HORIZONTAL,
|
long style = wxRA_SPECIFY_COLS,
|
||||||
const wxValidator& val = wxDefaultValidator,
|
const wxValidator& val = wxDefaultValidator,
|
||||||
const wxString& name = wxRadioBoxNameStr);
|
const wxString& name = wxRadioBoxNameStr);
|
||||||
|
|
||||||
|
@@ -51,6 +51,7 @@ public:
|
|||||||
|
|
||||||
// implementation only from now on
|
// implementation only from now on
|
||||||
virtual void Command(wxCommandEvent& event);
|
virtual void Command(wxCommandEvent& event);
|
||||||
|
void SetGroup(uint8_t group);
|
||||||
|
|
||||||
// send a notification event, return true if processed
|
// send a notification event, return true if processed
|
||||||
bool SendClickEvent();
|
bool SendClickEvent();
|
||||||
@@ -66,6 +67,8 @@ private:
|
|||||||
// common part of all ctors
|
// common part of all ctors
|
||||||
void Init();
|
void Init();
|
||||||
|
|
||||||
|
uint8_t m_groupID;
|
||||||
|
|
||||||
// pushButtonCtl or checkboxCtl
|
// pushButtonCtl or checkboxCtl
|
||||||
ControlStyleType m_radioStyle;
|
ControlStyleType m_radioStyle;
|
||||||
DECLARE_DYNAMIC_CLASS_NO_COPY(wxRadioButton)
|
DECLARE_DYNAMIC_CLASS_NO_COPY(wxRadioButton)
|
||||||
|
@@ -85,8 +85,9 @@ protected:
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
void Init();
|
void Init();
|
||||||
int m_oldPos;
|
int m_oldPos; // needed for tracing thumb position during scrolling
|
||||||
int m_lineSize;
|
int m_oldValue; // needed for comparing thumb position before and after scrolling
|
||||||
|
int m_lineSize; // imitate line size
|
||||||
|
|
||||||
DECLARE_DYNAMIC_CLASS_NO_COPY(wxSlider)
|
DECLARE_DYNAMIC_CLASS_NO_COPY(wxSlider)
|
||||||
};
|
};
|
||||||
|
@@ -111,7 +111,7 @@ bool wxControl::PalmCreateControl(ControlStyleType style,
|
|||||||
const wxString& label,
|
const wxString& label,
|
||||||
const wxPoint& pos,
|
const wxPoint& pos,
|
||||||
const wxSize& size,
|
const wxSize& size,
|
||||||
int groupID)
|
uint8_t groupID)
|
||||||
{
|
{
|
||||||
FormType* form = GetParentForm();
|
FormType* form = GetParentForm();
|
||||||
if(form==NULL)
|
if(form==NULL)
|
||||||
|
@@ -42,6 +42,8 @@
|
|||||||
#include "wx/tooltip.h"
|
#include "wx/tooltip.h"
|
||||||
#endif // wxUSE_TOOLTIPS
|
#endif // wxUSE_TOOLTIPS
|
||||||
|
|
||||||
|
#include "wx/radiobut.h"
|
||||||
|
|
||||||
// TODO: wxCONSTRUCTOR
|
// TODO: wxCONSTRUCTOR
|
||||||
#if 0 // wxUSE_EXTENDED_RTTI
|
#if 0 // wxUSE_EXTENDED_RTTI
|
||||||
WX_DEFINE_FLAGS( wxRadioBoxStyle )
|
WX_DEFINE_FLAGS( wxRadioBoxStyle )
|
||||||
@@ -152,7 +154,28 @@ bool wxRadioBox::Create(wxWindow *parent,
|
|||||||
const wxValidator& val,
|
const wxValidator& val,
|
||||||
const wxString& name)
|
const wxString& name)
|
||||||
{
|
{
|
||||||
return false;
|
// initialize members
|
||||||
|
m_majorDim = majorDim == 0 ? n : majorDim;
|
||||||
|
|
||||||
|
if(!wxControl::Create(parent, id, pos, size, style, val, name))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for(int i=0; i<n; i++)
|
||||||
|
{
|
||||||
|
wxRadioButton* rb = new wxRadioButton();
|
||||||
|
rb->SetGroup( id );
|
||||||
|
rb->Create(
|
||||||
|
this,
|
||||||
|
wxID_ANY,
|
||||||
|
choices[n],
|
||||||
|
pos,
|
||||||
|
size,
|
||||||
|
( n == 0 ? wxRB_GROUP : 0 ) |
|
||||||
|
( style & wxRA_USE_CHECKBOX ) ? wxRB_USE_CHECKBOX : 0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
SetSize(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxRadioBox::Create(wxWindow *parent,
|
bool wxRadioBox::Create(wxWindow *parent,
|
||||||
@@ -166,7 +189,10 @@ bool wxRadioBox::Create(wxWindow *parent,
|
|||||||
const wxValidator& val,
|
const wxValidator& val,
|
||||||
const wxString& name)
|
const wxString& name)
|
||||||
{
|
{
|
||||||
return false;
|
wxCArrayString chs(choices);
|
||||||
|
|
||||||
|
return Create( parent, id, title, pos, size, chs.GetCount(),
|
||||||
|
chs.GetStrings(), majorDim, style, val, name );
|
||||||
}
|
}
|
||||||
|
|
||||||
wxRadioBox::~wxRadioBox()
|
wxRadioBox::~wxRadioBox()
|
||||||
|
@@ -103,6 +103,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl)
|
|||||||
void wxRadioButton::Init()
|
void wxRadioButton::Init()
|
||||||
{
|
{
|
||||||
m_radioStyle = pushButtonCtl;
|
m_radioStyle = pushButtonCtl;
|
||||||
|
m_groupID = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxRadioButton::Create(wxWindow *parent,
|
bool wxRadioButton::Create(wxWindow *parent,
|
||||||
@@ -126,10 +127,16 @@ bool wxRadioButton::Create(wxWindow *parent,
|
|||||||
m_radioStyle == checkboxCtl ? checkboxCtl : pushButtonCtl,
|
m_radioStyle == checkboxCtl ? checkboxCtl : pushButtonCtl,
|
||||||
label,
|
label,
|
||||||
pos,
|
pos,
|
||||||
size
|
size,
|
||||||
|
m_groupID
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxRadioButton::SetGroup(uint8_t group)
|
||||||
|
{
|
||||||
|
m_groupID = group;
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxRadioButton functions
|
// wxRadioButton functions
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@@ -100,7 +100,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl)
|
|||||||
// Slider
|
// Slider
|
||||||
void wxSlider::Init()
|
void wxSlider::Init()
|
||||||
{
|
{
|
||||||
m_oldPos = 0;
|
m_oldValue = m_oldPos = 0;
|
||||||
m_lineSize = 1;
|
m_lineSize = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +120,7 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id,
|
|||||||
// wxSL_INVERSE is ignored - always off
|
// wxSL_INVERSE is ignored - always off
|
||||||
// wxSL_VERTICAL is impossible in native form
|
// wxSL_VERTICAL is impossible in native form
|
||||||
wxCHECK_MSG(!(style & wxSL_VERTICAL), false, _T("non vertical slider on PalmOS"));
|
wxCHECK_MSG(!(style & wxSL_VERTICAL), false, _T("non vertical slider on PalmOS"));
|
||||||
|
|
||||||
if(!wxControl::Create(parent, id, pos, size, style, validator, name))
|
if(!wxControl::Create(parent, id, pos, size, style, validator, name))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -128,7 +128,7 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id,
|
|||||||
if(form==NULL)
|
if(form==NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_oldPos = value;
|
m_oldValue = m_oldPos = value;
|
||||||
|
|
||||||
SliderControlType *slider = CtlNewSliderControl (
|
SliderControlType *slider = CtlNewSliderControl (
|
||||||
(void **)&form,
|
(void **)&form,
|
||||||
@@ -201,7 +201,7 @@ int wxSlider::GetValue() const
|
|||||||
void wxSlider::SetValue(int value)
|
void wxSlider::SetValue(int value)
|
||||||
{
|
{
|
||||||
SetIntValue(value);
|
SetIntValue(value);
|
||||||
m_oldPos = value;
|
m_oldValue = m_oldPos = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxSize wxSlider::DoGetBestSize() const
|
wxSize wxSlider::DoGetBestSize() const
|
||||||
@@ -298,65 +298,42 @@ bool wxSlider::SendUpdatedEvent()
|
|||||||
{
|
{
|
||||||
m_oldPos = GetValue();
|
m_oldPos = GetValue();
|
||||||
|
|
||||||
// first track event
|
// first thumb event
|
||||||
wxScrollEvent eventWxTrack(wxEVT_SCROLL_THUMBRELEASE, GetId());
|
wxScrollEvent eventWxTrack(wxEVT_SCROLL_THUMBRELEASE, GetId());
|
||||||
eventWxTrack.SetPosition(m_oldPos);
|
eventWxTrack.SetPosition(m_oldPos);
|
||||||
eventWxTrack.SetEventObject(this);
|
eventWxTrack.SetEventObject(this);
|
||||||
GetEventHandler()->ProcessEvent(eventWxTrack);
|
bool handled = GetEventHandler()->ProcessEvent(eventWxTrack);
|
||||||
|
|
||||||
// then scroll event
|
// then slider event if position changed
|
||||||
wxCommandEvent event(wxEVT_COMMAND_SLIDER_UPDATED, GetId());
|
if( m_oldValue != m_oldPos )
|
||||||
event.SetEventObject(this);
|
{
|
||||||
event.SetInt(m_oldPos);
|
m_oldValue = m_oldPos;
|
||||||
return ProcessCommand(event);
|
wxCommandEvent event(wxEVT_COMMAND_SLIDER_UPDATED, GetId());
|
||||||
|
event.SetEventObject(this);
|
||||||
|
event.SetInt(m_oldPos);
|
||||||
|
return ProcessCommand(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
return handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxSlider::SendScrollEvent(EventType* event)
|
bool wxSlider::SendScrollEvent(EventType* event)
|
||||||
{
|
{
|
||||||
wxEventType scrollEvent;
|
wxEventType scrollEvent;
|
||||||
int newPos = event->data.ctlRepeat.value;
|
int newPos = event->data.ctlRepeat.value;
|
||||||
if ( newPos == GetMax() )
|
if ( newPos == m_oldPos )
|
||||||
{
|
|
||||||
scrollEvent = wxEVT_SCROLL_TOP;
|
|
||||||
}
|
|
||||||
else if ( newPos == GetMin() )
|
|
||||||
{
|
|
||||||
scrollEvent = wxEVT_SCROLL_BOTTOM;
|
|
||||||
}
|
|
||||||
else if ( newPos == ( m_oldPos + GetLineSize() ) )
|
|
||||||
{
|
|
||||||
scrollEvent = wxEVT_SCROLL_LINEUP;
|
|
||||||
}
|
|
||||||
else if ( newPos == ( m_oldPos - GetLineSize() ) )
|
|
||||||
{
|
|
||||||
scrollEvent = wxEVT_SCROLL_LINEDOWN;
|
|
||||||
}
|
|
||||||
else if ( newPos == ( m_oldPos + GetPageSize() ) )
|
|
||||||
{
|
|
||||||
scrollEvent = wxEVT_SCROLL_PAGEUP;
|
|
||||||
}
|
|
||||||
else if ( newPos == ( m_oldPos - GetPageSize() ) )
|
|
||||||
{
|
|
||||||
scrollEvent = wxEVT_SCROLL_PAGEDOWN;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
|
// nothing changed since last event
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_oldPos = newPos;
|
m_oldPos = newPos;
|
||||||
|
|
||||||
// first track event
|
// first track event
|
||||||
wxScrollEvent eventWxTrack(wxEVT_SCROLL_THUMBTRACK, GetId());
|
wxScrollEvent eventWx(wxEVT_SCROLL_THUMBTRACK, GetId());
|
||||||
eventWxTrack.SetPosition(newPos);
|
eventWx.SetPosition(newPos);
|
||||||
eventWxTrack.SetEventObject(this);
|
eventWx.SetEventObject(this);
|
||||||
GetEventHandler()->ProcessEvent(eventWxTrack);
|
return GetEventHandler()->ProcessEvent(eventWx);
|
||||||
|
|
||||||
// then scroll event
|
|
||||||
wxScrollEvent eventWxScroll(scrollEvent, GetId());
|
|
||||||
eventWxScroll.SetPosition(newPos);
|
|
||||||
eventWxScroll.SetEventObject(this);
|
|
||||||
return GetEventHandler()->ProcessEvent(eventWxScroll);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxSlider::Command (wxCommandEvent & event)
|
void wxSlider::Command (wxCommandEvent & event)
|
||||||
|
Reference in New Issue
Block a user