mirror of
https://github.com/cookiengineer/audacity
synced 2025-12-09 06:06:24 +01:00
ESC key can abort the rearranging of toolbars.
This commit is contained in:
@@ -452,6 +452,11 @@ void ToolDock::Expose( int type, bool show )
|
||||
Updated();
|
||||
}
|
||||
|
||||
int ToolDock::Find(ToolBar *bar) const
|
||||
{
|
||||
return mDockedBars.Index(bar);
|
||||
}
|
||||
|
||||
//
|
||||
// Queues an EVT_TOOLBAR_UPDATED command event to notify any
|
||||
// interested parties of an updated toolbar or dock layout
|
||||
@@ -468,13 +473,16 @@ void ToolDock::Updated()
|
||||
//
|
||||
void ToolDock::OnGrabber( GrabberEvent & event )
|
||||
{
|
||||
ToolBar *t = mBars[ event.GetId() ];
|
||||
auto pos = event.GetPosition();
|
||||
if (!event.IsEscaping()) {
|
||||
ToolBar *t = mBars[ event.GetId() ];
|
||||
|
||||
// Pass it on to the manager since it isn't in the handling hierarchy
|
||||
mManager->ProcessEvent( event );
|
||||
// Pass it on to the manager since it isn't in the handling hierarchy
|
||||
mManager->ProcessEvent( event );
|
||||
|
||||
// We no longer have control
|
||||
mDockedBars.Remove( t );
|
||||
// We no longer have control
|
||||
mDockedBars.Remove( t );
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -57,6 +57,7 @@ class ToolDock final : public wxPanel
|
||||
|
||||
void LayoutToolBars();
|
||||
void Expose( int type, bool show );
|
||||
int Find(ToolBar *bar) const;
|
||||
int GetOrder( ToolBar *bar );
|
||||
int GetBarCount();
|
||||
void Dock( ToolBar *bar, int ndx = -1 );
|
||||
|
||||
@@ -988,15 +988,6 @@ void ToolManager::OnMouse( wxMouseEvent & event )
|
||||
// Button was released...finish the drag
|
||||
if( !event.LeftIsDown() )
|
||||
{
|
||||
// Release capture
|
||||
if( mParent->HasCapture() )
|
||||
{
|
||||
mParent->ReleaseMouse();
|
||||
}
|
||||
|
||||
// Hide the indicator
|
||||
mIndicator->Hide();
|
||||
|
||||
// Transition the bar to a dock
|
||||
if( mDragDock && !event.ShiftDown() )
|
||||
{
|
||||
@@ -1013,13 +1004,7 @@ void ToolManager::OnMouse( wxMouseEvent & event )
|
||||
mDragBar->SetDocked( NULL, false );
|
||||
}
|
||||
|
||||
// Done dragging
|
||||
mDragWindow = NULL;
|
||||
mDragDock = NULL;
|
||||
mDragBar = NULL;
|
||||
mLastPos.x = mBarPos.x = -1;
|
||||
mLastPos.y = mBarPos.y = -1;
|
||||
mTimer.Stop();
|
||||
DoneDragging();
|
||||
}
|
||||
else if( event.Dragging() && pos != mLastPos )
|
||||
{
|
||||
@@ -1221,17 +1206,29 @@ void ToolManager::OnGrabber( GrabberEvent & event )
|
||||
// No need to propagate any further
|
||||
event.Skip( false );
|
||||
|
||||
if(event.IsEscaping())
|
||||
return HandleEscapeKey();
|
||||
|
||||
// Remember which bar we're dragging
|
||||
mDragBar = mBars[ event.GetId() ];
|
||||
|
||||
// Remember state, in case of ESCape key later
|
||||
if (mDragBar->IsDocked()) {
|
||||
mPrevDock = dynamic_cast<ToolDock*>(mDragBar->GetParent());
|
||||
wxASSERT(mPrevDock);
|
||||
mPrevSlot = mPrevDock->Find(mDragBar);
|
||||
}
|
||||
else
|
||||
mPrevPosition = mDragBar->GetParent()->GetPosition();
|
||||
|
||||
// Calculate the drag offset
|
||||
wxPoint mp = event.GetPosition();
|
||||
mDragOffset = mp -
|
||||
mDragBar->GetParent()->ClientToScreen( mDragBar->GetPosition() ) +
|
||||
wxPoint( 1, 1 );
|
||||
wxPoint( 1, 1 );
|
||||
|
||||
// Must set the bar afloat if it's currently docked
|
||||
if( mDragBar->IsDocked() )
|
||||
if( mPrevDock )
|
||||
{
|
||||
#if defined(__WXMAC__)
|
||||
// Disable window animation
|
||||
@@ -1271,3 +1268,51 @@ void ToolManager::OnGrabber( GrabberEvent & event )
|
||||
mLastState = wxGetKeyState( WXK_SHIFT );
|
||||
mTimer.Start( 100 );
|
||||
}
|
||||
|
||||
|
||||
void ToolManager::HandleEscapeKey()
|
||||
{
|
||||
if (mDragBar) {
|
||||
if(mPrevDock) {
|
||||
// Sheriff John Stone,
|
||||
// Why don't you leave me alone?
|
||||
// Well, I feel so break up
|
||||
// I want to go home.
|
||||
mPrevDock->Dock( mDragBar, mPrevSlot );
|
||||
|
||||
// Done with the floater
|
||||
mDragWindow->Destroy();
|
||||
mDragBar->Refresh(false);
|
||||
}
|
||||
else {
|
||||
// Floater remains, and returns to where it begain
|
||||
auto parent = mDragBar->GetParent();
|
||||
parent->SetPosition(mPrevPosition);
|
||||
mDragBar->SetDocked(NULL, false);
|
||||
}
|
||||
|
||||
DoneDragging();
|
||||
}
|
||||
}
|
||||
|
||||
void ToolManager::DoneDragging()
|
||||
{
|
||||
// Done dragging
|
||||
// Release capture
|
||||
if( mParent->HasCapture() )
|
||||
{
|
||||
mParent->ReleaseMouse();
|
||||
}
|
||||
|
||||
// Hide the indicator
|
||||
mIndicator->Hide();
|
||||
|
||||
mDragWindow = NULL;
|
||||
mDragDock = NULL;
|
||||
mDragBar = NULL;
|
||||
mPrevDock = NULL;
|
||||
mPrevSlot = -1;
|
||||
mLastPos.x = mBarPos.x = -1;
|
||||
mLastPos.y = mBarPos.y = -1;
|
||||
mTimer.Stop();
|
||||
}
|
||||
|
||||
@@ -75,6 +75,8 @@ class ToolManager final : public wxEvtHandler
|
||||
void OnMouse( wxMouseEvent & event );
|
||||
void OnCaptureLost( wxMouseCaptureLostEvent & event );
|
||||
void OnGrabber( GrabberEvent & event );
|
||||
void HandleEscapeKey();
|
||||
void DoneDragging();
|
||||
|
||||
void OnIndicatorCreate( wxWindowCreateEvent & event );
|
||||
void OnIndicatorPaint( wxPaintEvent & event );
|
||||
@@ -87,7 +89,7 @@ class ToolManager final : public wxEvtHandler
|
||||
|
||||
ToolFrame *mDragWindow;
|
||||
ToolDock *mDragDock;
|
||||
ToolBar *mDragBar;
|
||||
ToolBar *mDragBar {};
|
||||
wxPoint mDragOffset;
|
||||
int mDragBefore;
|
||||
|
||||
@@ -112,6 +114,10 @@ class ToolManager final : public wxEvtHandler
|
||||
|
||||
ToolBar *mBars[ ToolBarCount ];
|
||||
|
||||
wxPoint mPrevPosition {};
|
||||
ToolDock *mPrevDock {};
|
||||
int mPrevSlot {-1};
|
||||
|
||||
public:
|
||||
|
||||
DECLARE_CLASS( ToolManager );
|
||||
|
||||
Reference in New Issue
Block a user