1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-04 17:49:45 +02:00

CellularPanel saves and restores focus for each click-drag-release...

... while the project makes note of which window has temporarily given up the
focus; and TrackPanel can detect that, so that the yellow border of the focused
track is still drawn while the panel "lends" the focus.

Why do all this?  So that, when the ruler is another CellularPanel, ESC key
will work to abort drags in the ruler, but TrackPanel appearance won't change
during the drags.
This commit is contained in:
Paul Licameli 2018-08-02 11:45:27 -04:00
parent 7cbe85facf
commit ff98ca5a32
4 changed files with 27 additions and 6 deletions

View File

@ -106,6 +106,10 @@ void CellularPanel::Uncapture(wxMouseState *pState)
if (HasCapture())
ReleaseMouse();
HandleMotion( *pState );
auto lender = GetProject()->mFocusLender.get();
if (lender)
lender->SetFocus();
}
bool CellularPanel::CancelDragging()
@ -654,10 +658,6 @@ try
GetParent()->GetEventHandler()->ProcessEvent(e);
}
if (event.ButtonDown()) {
SetFocus();
}
if (event.Leaving())
{
if ( !state.mUIHandle )
@ -775,6 +775,9 @@ void CellularPanel::HandleClick( const TrackPanelMouseEvent &tpmEvent )
if (refreshResult & RefreshCode::Cancelled)
state.mUIHandle.reset(), handle.reset(), ClearTargets();
else {
if( !HasFocus() )
SetFocus();
state.mpClickedCell = pCell;
// Perhaps the clicked handle wants to update cursor and state message
@ -812,13 +815,20 @@ void CellularPanel::DoContextMenu( TrackPanelCell *pCell )
ProcessUIHandleResult(pCell, pCell, refreshResult);
}
void CellularPanel::OnSetFocus(wxFocusEvent & WXUNUSED(event))
void CellularPanel::OnSetFocus(wxFocusEvent &event)
{
auto &ptr = GetProject()->mFocusLender;
if ( !ptr )
ptr = event.GetWindow();
SetFocusedCell();
}
void CellularPanel::OnKillFocus(wxFocusEvent & WXUNUSED(event))
{
// Forget any borrowing of focus
GetProject()->mFocusLender = NULL;
if (AudacityProject::HasKeyboardCapture(this))
{
AudacityProject::ReleaseKeyboard(this);

View File

@ -6258,3 +6258,8 @@ void AudacityProject::PlaybackScroller::OnTimer(wxCommandEvent &event)
trackPanel->Refresh(false);
}
}
bool AudacityProject::IsFocused( const wxWindow *window ) const
{
return window == mFocusLender || window == wxWindow::FindFocus();
}

View File

@ -834,6 +834,12 @@ public:
std::shared_ptr<BackgroundCell> GetBackgroundCell() const
{ return mBackgroundCell; }
wxWindowRef mFocusLender;
// Return true if the window is really focused, or if focus was borrowed
// from it
bool IsFocused( const wxWindow *window ) const;
DECLARE_EVENT_TABLE()
};

View File

@ -1270,7 +1270,7 @@ void TrackPanel::DrawEverythingElse(TrackPanelDrawingContext &context,
// if (GetFocusedTrack() != NULL) {
// the highlight was reportedly drawn even when something else
// was the focus and no highlight should be drawn. -RBD
if (GetFocusedTrack() != NULL && wxWindow::FindFocus() == this) {
if (GetFocusedTrack() != NULL && GetProject()->IsFocused( this )) {
HighlightFocusedTrack(dc, focusRect);
}