Bug1917: TrackPanel should keep focus after click or drag...

... though ruler won't, and if you start to drag in TrackPanel but abort it
with the ESC key, that too returns focus
This commit is contained in:
Paul Licameli 2018-08-07 10:39:32 -04:00
parent 3f0b3bf1b8
commit 22f85f244b
6 changed files with 35 additions and 15 deletions

View File

@ -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;

View File

@ -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();

View File

@ -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

View File

@ -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;

View File

@ -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)

View File

@ -466,6 +466,8 @@ private:
void UpdateStatusMessage( const wxString & ) override;
bool TakesFocus() const override;
void CreateOverlays();
// Cooperating objects