From 7a5fbbc06f649567237a329fbf63fc268c9da6d7 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Mon, 24 Jun 2019 23:37:10 +0200 Subject: [PATCH] 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. --- src/propgrid/advprops.cpp | 64 ++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/src/propgrid/advprops.cpp b/src/propgrid/advprops.cpp index 4f34d7b2b5..cf7fffe374 100644 --- a/src/propgrid/advprops.cpp +++ b/src/propgrid/advprops.cpp @@ -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,44 +200,46 @@ private: 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; - m_ptPosition = event.GetPosition(); - } - 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 - evt.GetPosition().y; + if ( dy ) { - int dy = m_ptPosition.y - event.GetPosition().y; - if ( dy ) - { - Capture(); - m_ptPosition = event.GetPosition(); + Capture(); + m_ptPosition = evt.GetPosition(); - wxSpinEvent evtscroll( (dy >= 0) ? wxEVT_SCROLL_LINEUP : - wxEVT_SCROLL_LINEDOWN, - GetId() ); - evtscroll.SetEventObject(this); + wxSpinEvent evtscroll( (dy >= 0) ? wxEVT_SCROLL_LINEUP : + wxEVT_SCROLL_LINEDOWN, + GetId() ); + evtscroll.SetEventObject(this); - wxASSERT( m_spins == 1 ); + wxASSERT( m_spins == 1 ); - m_spins = abs(dy); - GetEventHandler()->ProcessEvent(evtscroll); - m_spins = 1; - } + m_spins = abs(dy); + GetEventHandler()->ProcessEvent(evtscroll); + m_spins = 1; } } - event.Skip(); + evt.Skip(); } + void OnMouseCaptureLost(wxMouseCaptureLostEvent& WXUNUSED(event)) { Release();