diff --git a/src/CellularPanel.cpp b/src/CellularPanel.cpp index edb477404..d7b3b2363 100644 --- a/src/CellularPanel.cpp +++ b/src/CellularPanel.cpp @@ -94,7 +94,7 @@ void CellularPanel::HandleInterruptedDrag() } } -void CellularPanel::Uncapture(wxMouseState *pState) +void CellularPanel::Uncapture(bool escaping, wxMouseState *pState) { auto state = ::wxGetMouseState(); if (!pState) { @@ -107,12 +107,14 @@ void CellularPanel::Uncapture(wxMouseState *pState) ReleaseMouse(); HandleMotion( *pState ); - auto lender = GetProject()->mFocusLender.get(); - if (lender) - lender->SetFocus(); + if (escaping || !TakesFocus()) { + auto lender = GetProject()->mFocusLender.get(); + if (lender) + lender->SetFocus(); + } } -bool CellularPanel::CancelDragging() +bool CellularPanel::CancelDragging( bool escaping ) { auto &state = *mState; if (state.mUIHandle) { @@ -127,7 +129,7 @@ bool CellularPanel::CancelDragging() refreshResult | state.mMouseOverUpdateFlags ); state.mpClickedCell.reset(); state.mUIHandle.reset(), handle.reset(), ClearTargets(); - Uncapture(); + Uncapture( escaping ); return true; } return false; @@ -148,7 +150,7 @@ bool CellularPanel::HandleEscapeKey(bool down) auto &state = *mState; if (state.mUIHandle) { - CancelDragging(); + CancelDragging( true ); return true; } @@ -690,7 +692,7 @@ try ::wxGetMouseState().ButtonIsDown(wxMOUSE_BTN_ANY); if(!buttons) { - CancelDragging(); + CancelDragging( false ); #if defined(__WXMAC__) @@ -717,7 +719,7 @@ try // Drag decided to abort itself state.mUIHandle.reset(), handle.reset(), ClearTargets(); state.mpClickedCell.reset(); - Uncapture( &event ); + Uncapture( false, &event ); } else { UpdateMouseState(event); @@ -753,15 +755,15 @@ try } if (event.ButtonUp()) - Uncapture(); + Uncapture( false ); } catch( ... ) { // Abort any dragging, as if by hitting Esc - if ( CancelDragging() ) + if ( CancelDragging( true ) ) ; else { - Uncapture(); + Uncapture( true ); Refresh(false); } throw; diff --git a/src/CellularPanel.h b/src/CellularPanel.h index c41d3bdb2..00eda5f5e 100644 --- a/src/CellularPanel.h +++ b/src/CellularPanel.h @@ -58,6 +58,10 @@ public: virtual void UpdateStatusMessage( const wxString & ) = 0; + // Whether this panel keeps focus after a click and drag, or only borrows + // it. + virtual bool TakesFocus() const = 0; + public: UIHandlePtr Target(); @@ -71,7 +75,7 @@ public: protected: bool HasEscape(); - bool CancelDragging(); + bool CancelDragging( bool escaping ); void DoContextMenu( TrackPanelCell *pCell = nullptr ); void ClearTargets(); @@ -92,7 +96,7 @@ private: void OnContextMenu(wxContextMenuEvent & event); void HandleInterruptedDrag(); - void Uncapture( wxMouseState *pState = nullptr ); + void Uncapture( bool escaping, wxMouseState *pState = nullptr ); bool HandleEscapeKey(bool down); void UpdateMouseState(const wxMouseState &state); void HandleModifierKey(); diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index 3a2e46dde..b7b8ddecc 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -721,6 +721,11 @@ void TrackPanel::UpdateStatusMessage( const wxString &st ) mListener->TP_DisplayStatusMessage(status); } +bool TrackPanel::TakesFocus() const +{ + return true; +} + void TrackPanel::UpdateSelectionDisplay() { // Full refresh since the label area may need to indicate diff --git a/src/TrackPanel.h b/src/TrackPanel.h index 9df28299c..c990ce7b7 100644 --- a/src/TrackPanel.h +++ b/src/TrackPanel.h @@ -482,6 +482,8 @@ protected: void UpdateStatusMessage( const wxString &status ) override; + bool TakesFocus() const override; + // friending GetInfoCommand allow automation to get sizes of the // tracks, track control panel and such. friend class GetInfoCommand; diff --git a/src/widgets/Ruler.cpp b/src/widgets/Ruler.cpp index 540e3bb72..e41730317 100644 --- a/src/widgets/Ruler.cpp +++ b/src/widgets/Ruler.cpp @@ -2727,7 +2727,7 @@ void AdornedRulerPanel::OnRecordStartStop(wxCommandEvent & evt) if (evt.GetInt() != 0) { mIsRecording = true; - this->CellularPanel::CancelDragging(); + this->CellularPanel::CancelDragging( false ); this->CellularPanel::ClearTargets(); UpdateButtonStates(); @@ -3780,6 +3780,11 @@ void AdornedRulerPanel::UpdateStatusMessage( const wxString &message ) GetProject()->TP_DisplayStatusMessage(message); } +bool AdornedRulerPanel::TakesFocus() const +{ + return false; +} + void AdornedRulerPanel::CreateOverlays() { if (!mOverlay) diff --git a/src/widgets/Ruler.h b/src/widgets/Ruler.h index 98b7fb5a2..78410767a 100644 --- a/src/widgets/Ruler.h +++ b/src/widgets/Ruler.h @@ -466,6 +466,8 @@ private: void UpdateStatusMessage( const wxString & ) override; + bool TakesFocus() const override; + void CreateOverlays(); // Cooperating objects