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:
Artur Wieczorek
2019-06-24 23:37:10 +02:00
parent 8c0a210a75
commit 7a5fbbc06f

View File

@@ -146,9 +146,9 @@ public:
m_hasCapture = false;
m_spins = 1;
Bind(wxEVT_LEFT_DOWN, &wxPGSpinButton::OnMouseEvent, this);
Bind(wxEVT_LEFT_UP, &wxPGSpinButton::OnMouseEvent, this);
Bind(wxEVT_MOTION, &wxPGSpinButton::OnMouseEvent, this);
Bind(wxEVT_LEFT_DOWN, &wxPGSpinButton::OnMouseLeftDown, this);
Bind(wxEVT_LEFT_UP, &wxPGSpinButton::OnMouseLeftUp, this);
Bind(wxEVT_MOTION, &wxPGSpinButton::OnMouseMove, this);
Bind(wxEVT_MOUSE_CAPTURE_LOST, &wxPGSpinButton::OnMouseCaptureLost, this);
}
@@ -200,27 +200,29 @@ private:
SetCursor(wxNullCursor);
}
void OnMouseEvent(wxMouseEvent& event)
{
if ( event.GetEventType() == wxEVT_LEFT_DOWN )
void OnMouseLeftDown(wxMouseEvent& evt)
{
m_bLeftDown = true;
m_ptPosition = event.GetPosition();
m_ptPosition = evt.GetPosition();
evt.Skip();
}
else if ( event.GetEventType() == wxEVT_LEFT_UP )
void OnMouseLeftUp(wxMouseEvent& evt)
{
Release();
m_bLeftDown = false;
evt.Skip();
}
else if ( event.GetEventType() == wxEVT_MOTION )
void OnMouseMove(wxMouseEvent& evt)
{
if ( m_bLeftDown )
{
int dy = m_ptPosition.y - event.GetPosition().y;
int dy = m_ptPosition.y - evt.GetPosition().y;
if ( dy )
{
Capture();
m_ptPosition = event.GetPosition();
m_ptPosition = evt.GetPosition();
wxSpinEvent evtscroll( (dy >= 0) ? wxEVT_SCROLL_LINEUP :
wxEVT_SCROLL_LINEDOWN,
@@ -234,10 +236,10 @@ private:
m_spins = 1;
}
}
evt.Skip();
}
event.Skip();
}
void OnMouseCaptureLost(wxMouseCaptureLostEvent& WXUNUSED(event))
{
Release();