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:
parent
8e1611724c
commit
8be10866ce
@ -111,7 +111,7 @@ protected:
|
||||
const wxString& label,
|
||||
const wxPoint& pos,
|
||||
const wxSize& size,
|
||||
int groupID = 0);
|
||||
uint8_t groupID = 0);
|
||||
inline bool IsPalmControl() const { return m_palmControl; }
|
||||
|
||||
bool PalmCreateField(const wxString& label,
|
||||
|
@ -34,7 +34,7 @@ public:
|
||||
const wxSize& size = wxDefaultSize,
|
||||
int n = 0, const wxString choices[] = NULL,
|
||||
int majorDim = 0,
|
||||
long style = wxRA_HORIZONTAL,
|
||||
long style = wxRA_SPECIFY_COLS,
|
||||
const wxValidator& val = wxDefaultValidator,
|
||||
const wxString& name = wxRadioBoxNameStr)
|
||||
{
|
||||
@ -48,7 +48,7 @@ public:
|
||||
const wxSize& size,
|
||||
const wxArrayString& choices,
|
||||
int majorDim = 0,
|
||||
long style = wxRA_HORIZONTAL,
|
||||
long style = wxRA_SPECIFY_COLS,
|
||||
const wxValidator& val = wxDefaultValidator,
|
||||
const wxString& name = wxRadioBoxNameStr)
|
||||
{
|
||||
@ -65,7 +65,7 @@ public:
|
||||
const wxSize& size = wxDefaultSize,
|
||||
int n = 0, const wxString choices[] = NULL,
|
||||
int majorDim = 0,
|
||||
long style = wxRA_HORIZONTAL,
|
||||
long style = wxRA_SPECIFY_COLS,
|
||||
const wxValidator& val = wxDefaultValidator,
|
||||
const wxString& name = wxRadioBoxNameStr);
|
||||
|
||||
@ -76,7 +76,7 @@ public:
|
||||
const wxSize& size,
|
||||
const wxArrayString& choices,
|
||||
int majorDim = 0,
|
||||
long style = wxRA_HORIZONTAL,
|
||||
long style = wxRA_SPECIFY_COLS,
|
||||
const wxValidator& val = wxDefaultValidator,
|
||||
const wxString& name = wxRadioBoxNameStr);
|
||||
|
||||
|
@ -51,6 +51,7 @@ public:
|
||||
|
||||
// implementation only from now on
|
||||
virtual void Command(wxCommandEvent& event);
|
||||
void SetGroup(uint8_t group);
|
||||
|
||||
// send a notification event, return true if processed
|
||||
bool SendClickEvent();
|
||||
@ -66,6 +67,8 @@ private:
|
||||
// common part of all ctors
|
||||
void Init();
|
||||
|
||||
uint8_t m_groupID;
|
||||
|
||||
// pushButtonCtl or checkboxCtl
|
||||
ControlStyleType m_radioStyle;
|
||||
DECLARE_DYNAMIC_CLASS_NO_COPY(wxRadioButton)
|
||||
|
@ -85,8 +85,9 @@ protected:
|
||||
private:
|
||||
|
||||
void Init();
|
||||
int m_oldPos;
|
||||
int m_lineSize;
|
||||
int m_oldPos; // needed for tracing thumb position during scrolling
|
||||
int m_oldValue; // needed for comparing thumb position before and after scrolling
|
||||
int m_lineSize; // imitate line size
|
||||
|
||||
DECLARE_DYNAMIC_CLASS_NO_COPY(wxSlider)
|
||||
};
|
||||
|
@ -111,7 +111,7 @@ bool wxControl::PalmCreateControl(ControlStyleType style,
|
||||
const wxString& label,
|
||||
const wxPoint& pos,
|
||||
const wxSize& size,
|
||||
int groupID)
|
||||
uint8_t groupID)
|
||||
{
|
||||
FormType* form = GetParentForm();
|
||||
if(form==NULL)
|
||||
|
@ -42,6 +42,8 @@
|
||||
#include "wx/tooltip.h"
|
||||
#endif // wxUSE_TOOLTIPS
|
||||
|
||||
#include "wx/radiobut.h"
|
||||
|
||||
// TODO: wxCONSTRUCTOR
|
||||
#if 0 // wxUSE_EXTENDED_RTTI
|
||||
WX_DEFINE_FLAGS( wxRadioBoxStyle )
|
||||
@ -152,7 +154,28 @@ bool wxRadioBox::Create(wxWindow *parent,
|
||||
const wxValidator& val,
|
||||
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,
|
||||
@ -166,7 +189,10 @@ bool wxRadioBox::Create(wxWindow *parent,
|
||||
const wxValidator& val,
|
||||
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()
|
||||
|
@ -103,6 +103,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl)
|
||||
void wxRadioButton::Init()
|
||||
{
|
||||
m_radioStyle = pushButtonCtl;
|
||||
m_groupID = 0;
|
||||
}
|
||||
|
||||
bool wxRadioButton::Create(wxWindow *parent,
|
||||
@ -126,10 +127,16 @@ bool wxRadioButton::Create(wxWindow *parent,
|
||||
m_radioStyle == checkboxCtl ? checkboxCtl : pushButtonCtl,
|
||||
label,
|
||||
pos,
|
||||
size
|
||||
size,
|
||||
m_groupID
|
||||
);
|
||||
}
|
||||
|
||||
void wxRadioButton::SetGroup(uint8_t group)
|
||||
{
|
||||
m_groupID = group;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxRadioButton functions
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -100,7 +100,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl)
|
||||
// Slider
|
||||
void wxSlider::Init()
|
||||
{
|
||||
m_oldPos = 0;
|
||||
m_oldValue = m_oldPos = 0;
|
||||
m_lineSize = 1;
|
||||
}
|
||||
|
||||
@ -120,7 +120,7 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id,
|
||||
// wxSL_INVERSE is ignored - always off
|
||||
// wxSL_VERTICAL is impossible in native form
|
||||
wxCHECK_MSG(!(style & wxSL_VERTICAL), false, _T("non vertical slider on PalmOS"));
|
||||
|
||||
|
||||
if(!wxControl::Create(parent, id, pos, size, style, validator, name))
|
||||
return false;
|
||||
|
||||
@ -128,7 +128,7 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id,
|
||||
if(form==NULL)
|
||||
return false;
|
||||
|
||||
m_oldPos = value;
|
||||
m_oldValue = m_oldPos = value;
|
||||
|
||||
SliderControlType *slider = CtlNewSliderControl (
|
||||
(void **)&form,
|
||||
@ -201,7 +201,7 @@ int wxSlider::GetValue() const
|
||||
void wxSlider::SetValue(int value)
|
||||
{
|
||||
SetIntValue(value);
|
||||
m_oldPos = value;
|
||||
m_oldValue = m_oldPos = value;
|
||||
}
|
||||
|
||||
wxSize wxSlider::DoGetBestSize() const
|
||||
@ -298,65 +298,42 @@ bool wxSlider::SendUpdatedEvent()
|
||||
{
|
||||
m_oldPos = GetValue();
|
||||
|
||||
// first track event
|
||||
// first thumb event
|
||||
wxScrollEvent eventWxTrack(wxEVT_SCROLL_THUMBRELEASE, GetId());
|
||||
eventWxTrack.SetPosition(m_oldPos);
|
||||
eventWxTrack.SetEventObject(this);
|
||||
GetEventHandler()->ProcessEvent(eventWxTrack);
|
||||
bool handled = GetEventHandler()->ProcessEvent(eventWxTrack);
|
||||
|
||||
// then scroll event
|
||||
wxCommandEvent event(wxEVT_COMMAND_SLIDER_UPDATED, GetId());
|
||||
event.SetEventObject(this);
|
||||
event.SetInt(m_oldPos);
|
||||
return ProcessCommand(event);
|
||||
// then slider event if position changed
|
||||
if( m_oldValue != m_oldPos )
|
||||
{
|
||||
m_oldValue = m_oldPos;
|
||||
wxCommandEvent event(wxEVT_COMMAND_SLIDER_UPDATED, GetId());
|
||||
event.SetEventObject(this);
|
||||
event.SetInt(m_oldPos);
|
||||
return ProcessCommand(event);
|
||||
}
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
bool wxSlider::SendScrollEvent(EventType* event)
|
||||
{
|
||||
wxEventType scrollEvent;
|
||||
int newPos = event->data.ctlRepeat.value;
|
||||
if ( newPos == GetMax() )
|
||||
{
|
||||
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
|
||||
if ( newPos == m_oldPos )
|
||||
{
|
||||
// nothing changed since last event
|
||||
return false;
|
||||
}
|
||||
|
||||
m_oldPos = newPos;
|
||||
|
||||
// first track event
|
||||
wxScrollEvent eventWxTrack(wxEVT_SCROLL_THUMBTRACK, GetId());
|
||||
eventWxTrack.SetPosition(newPos);
|
||||
eventWxTrack.SetEventObject(this);
|
||||
GetEventHandler()->ProcessEvent(eventWxTrack);
|
||||
|
||||
// then scroll event
|
||||
wxScrollEvent eventWxScroll(scrollEvent, GetId());
|
||||
eventWxScroll.SetPosition(newPos);
|
||||
eventWxScroll.SetEventObject(this);
|
||||
return GetEventHandler()->ProcessEvent(eventWxScroll);
|
||||
wxScrollEvent eventWx(wxEVT_SCROLL_THUMBTRACK, GetId());
|
||||
eventWx.SetPosition(newPos);
|
||||
eventWx.SetEventObject(this);
|
||||
return GetEventHandler()->ProcessEvent(eventWx);
|
||||
}
|
||||
|
||||
void wxSlider::Command (wxCommandEvent & event)
|
||||
|
Loading…
Reference in New Issue
Block a user