Use separate event handlers to handle various mouse events in wxPGSpinButton
One common event handler for all mouse events is less readable than code split into separate handlers dedicated to specific event type.
This commit is contained in:
@@ -146,9 +146,9 @@ public:
|
|||||||
m_hasCapture = false;
|
m_hasCapture = false;
|
||||||
m_spins = 1;
|
m_spins = 1;
|
||||||
|
|
||||||
Bind(wxEVT_LEFT_DOWN, &wxPGSpinButton::OnMouseEvent, this);
|
Bind(wxEVT_LEFT_DOWN, &wxPGSpinButton::OnMouseLeftDown, this);
|
||||||
Bind(wxEVT_LEFT_UP, &wxPGSpinButton::OnMouseEvent, this);
|
Bind(wxEVT_LEFT_UP, &wxPGSpinButton::OnMouseLeftUp, this);
|
||||||
Bind(wxEVT_MOTION, &wxPGSpinButton::OnMouseEvent, this);
|
Bind(wxEVT_MOTION, &wxPGSpinButton::OnMouseMove, this);
|
||||||
Bind(wxEVT_MOUSE_CAPTURE_LOST, &wxPGSpinButton::OnMouseCaptureLost, this);
|
Bind(wxEVT_MOUSE_CAPTURE_LOST, &wxPGSpinButton::OnMouseCaptureLost, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,44 +200,46 @@ private:
|
|||||||
SetCursor(wxNullCursor);
|
SetCursor(wxNullCursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnMouseEvent(wxMouseEvent& event)
|
void OnMouseLeftDown(wxMouseEvent& evt)
|
||||||
{
|
{
|
||||||
if ( event.GetEventType() == wxEVT_LEFT_DOWN )
|
m_bLeftDown = true;
|
||||||
|
m_ptPosition = evt.GetPosition();
|
||||||
|
evt.Skip();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnMouseLeftUp(wxMouseEvent& evt)
|
||||||
|
{
|
||||||
|
Release();
|
||||||
|
m_bLeftDown = false;
|
||||||
|
evt.Skip();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnMouseMove(wxMouseEvent& evt)
|
||||||
|
{
|
||||||
|
if ( m_bLeftDown )
|
||||||
{
|
{
|
||||||
m_bLeftDown = true;
|
int dy = m_ptPosition.y - evt.GetPosition().y;
|
||||||
m_ptPosition = event.GetPosition();
|
if ( dy )
|
||||||
}
|
|
||||||
else if ( event.GetEventType() == wxEVT_LEFT_UP )
|
|
||||||
{
|
|
||||||
Release();
|
|
||||||
m_bLeftDown = false;
|
|
||||||
}
|
|
||||||
else if ( event.GetEventType() == wxEVT_MOTION )
|
|
||||||
{
|
|
||||||
if ( m_bLeftDown )
|
|
||||||
{
|
{
|
||||||
int dy = m_ptPosition.y - event.GetPosition().y;
|
Capture();
|
||||||
if ( dy )
|
m_ptPosition = evt.GetPosition();
|
||||||
{
|
|
||||||
Capture();
|
|
||||||
m_ptPosition = event.GetPosition();
|
|
||||||
|
|
||||||
wxSpinEvent evtscroll( (dy >= 0) ? wxEVT_SCROLL_LINEUP :
|
wxSpinEvent evtscroll( (dy >= 0) ? wxEVT_SCROLL_LINEUP :
|
||||||
wxEVT_SCROLL_LINEDOWN,
|
wxEVT_SCROLL_LINEDOWN,
|
||||||
GetId() );
|
GetId() );
|
||||||
evtscroll.SetEventObject(this);
|
evtscroll.SetEventObject(this);
|
||||||
|
|
||||||
wxASSERT( m_spins == 1 );
|
wxASSERT( m_spins == 1 );
|
||||||
|
|
||||||
m_spins = abs(dy);
|
m_spins = abs(dy);
|
||||||
GetEventHandler()->ProcessEvent(evtscroll);
|
GetEventHandler()->ProcessEvent(evtscroll);
|
||||||
m_spins = 1;
|
m_spins = 1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
event.Skip();
|
evt.Skip();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnMouseCaptureLost(wxMouseCaptureLostEvent& WXUNUSED(event))
|
void OnMouseCaptureLost(wxMouseCaptureLostEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
Release();
|
Release();
|
||||||
|
Reference in New Issue
Block a user