mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-06 14:52:34 +02:00
Resizing of meter toolbars (docked or undocked) responds to ESC key
This commit is contained in:
parent
fad249a603
commit
42bdc274dd
@ -67,7 +67,8 @@ public:
|
||||
virtual ~ToolBarResizer();
|
||||
|
||||
// We don't need or want to accept focus.
|
||||
bool AcceptsFocus() const;
|
||||
// PRL: except for ESC key now.
|
||||
// bool AcceptsFocus() const;
|
||||
|
||||
private:
|
||||
void OnErase(wxEraseEvent & event);
|
||||
@ -77,11 +78,14 @@ private:
|
||||
void OnEnter(wxMouseEvent & event);
|
||||
void OnLeave(wxMouseEvent & event);
|
||||
void OnMotion(wxMouseEvent & event);
|
||||
void ResizeBar(const wxSize &size);
|
||||
void OnCaptureLost(wxMouseCaptureLostEvent & event);
|
||||
void OnKeyDown(wxKeyEvent &event);
|
||||
|
||||
private:
|
||||
ToolBar *mBar;
|
||||
wxPoint mResizeStart;
|
||||
wxSize mOrigSize;
|
||||
|
||||
DECLARE_EVENT_TABLE();
|
||||
};
|
||||
@ -96,6 +100,7 @@ BEGIN_EVENT_TABLE( ToolBarResizer, wxWindow )
|
||||
EVT_LEFT_UP( ToolBarResizer::OnLeftUp )
|
||||
EVT_MOTION( ToolBarResizer::OnMotion )
|
||||
EVT_MOUSE_CAPTURE_LOST( ToolBarResizer::OnCaptureLost )
|
||||
EVT_KEY_DOWN( ToolBarResizer::OnKeyDown )
|
||||
END_EVENT_TABLE();
|
||||
|
||||
ToolBarResizer::ToolBarResizer(ToolBar *bar)
|
||||
@ -109,10 +114,12 @@ ToolBarResizer::~ToolBarResizer()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
bool ToolBarResizer::AcceptsFocus() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
//
|
||||
// Handle background erasure
|
||||
@ -157,6 +164,8 @@ void ToolBarResizer::OnLeftDown( wxMouseEvent & event )
|
||||
// Retrieve the mouse position
|
||||
mResizeStart = ClientToScreen( event.GetPosition() );
|
||||
|
||||
mOrigSize = mBar->GetSize();
|
||||
|
||||
// We want all of the mouse events
|
||||
CaptureMouse();
|
||||
}
|
||||
@ -181,7 +190,7 @@ void ToolBarResizer::OnMotion( wxMouseEvent & event )
|
||||
wxPoint raw_pos = event.GetPosition();
|
||||
wxPoint pos = ClientToScreen( raw_pos );
|
||||
|
||||
if( event.Dragging() )
|
||||
if( HasCapture() && event.Dragging() )
|
||||
{
|
||||
wxRect r = mBar->GetRect();
|
||||
wxSize msz = mBar->GetMinSize();
|
||||
@ -212,18 +221,22 @@ void ToolBarResizer::OnMotion( wxMouseEvent & event )
|
||||
mResizeStart = pos;
|
||||
}
|
||||
|
||||
// Resize the bar
|
||||
mBar->SetSize( r.GetSize() );
|
||||
|
||||
// Tell everyone we've changed sizes
|
||||
mBar->Updated();
|
||||
|
||||
// Refresh our world
|
||||
mBar->GetParent()->Refresh();
|
||||
mBar->GetParent()->Update();
|
||||
ResizeBar( r.GetSize() );
|
||||
}
|
||||
}
|
||||
|
||||
void ToolBarResizer::ResizeBar(const wxSize &size)
|
||||
{
|
||||
mBar->SetSize( size );
|
||||
|
||||
// Tell everyone we've changed sizes
|
||||
mBar->Updated();
|
||||
|
||||
// Refresh our world
|
||||
mBar->GetParent()->Refresh();
|
||||
mBar->GetParent()->Update();
|
||||
}
|
||||
|
||||
void ToolBarResizer::OnCaptureLost( wxMouseCaptureLostEvent & WXUNUSED(event) )
|
||||
{
|
||||
if( HasCapture() )
|
||||
@ -232,6 +245,15 @@ void ToolBarResizer::OnCaptureLost( wxMouseCaptureLostEvent & WXUNUSED(event) )
|
||||
}
|
||||
}
|
||||
|
||||
void ToolBarResizer::OnKeyDown(wxKeyEvent &event)
|
||||
{
|
||||
event.Skip();
|
||||
if (HasCapture() && WXK_ESCAPE == event.GetKeyCode()) {
|
||||
ResizeBar( mOrigSize );
|
||||
ReleaseMouse();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Methods for ToolBar
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -234,10 +234,7 @@ class ToolFrame final : public wxFrame
|
||||
rect.height = mMinSize.y;
|
||||
}
|
||||
|
||||
SetMinSize( rect.GetSize() );
|
||||
SetSize( rect.GetSize() );
|
||||
Layout();
|
||||
Refresh( false );
|
||||
Resize( rect.GetSize() );
|
||||
}
|
||||
else if( HasCapture() && event.LeftUp() )
|
||||
{
|
||||
@ -256,6 +253,8 @@ class ToolFrame final : public wxFrame
|
||||
// Is left click within resize grabber?
|
||||
if( r.Contains( pos ) && !event.Leaving() )
|
||||
{
|
||||
mOrigSize = GetSize();
|
||||
|
||||
SetCursor( wxCURSOR_SIZENWSE );
|
||||
if( event.LeftDown() )
|
||||
{
|
||||
@ -286,12 +285,30 @@ class ToolFrame final : public wxFrame
|
||||
event.Veto();
|
||||
}
|
||||
|
||||
private:
|
||||
void OnKeyDown( wxKeyEvent &event )
|
||||
{
|
||||
event.Skip();
|
||||
if( HasCapture() && event.GetKeyCode() == WXK_ESCAPE ) {
|
||||
Resize( mOrigSize );
|
||||
ReleaseMouse();
|
||||
}
|
||||
}
|
||||
|
||||
void Resize( const wxSize &size )
|
||||
{
|
||||
SetMinSize( size );
|
||||
SetSize( size );
|
||||
Layout();
|
||||
Refresh( false );
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
wxWindow *mParent;
|
||||
ToolManager *mManager;
|
||||
ToolBar *mBar;
|
||||
wxSize mMinSize;
|
||||
wxSize mOrigSize;
|
||||
|
||||
public:
|
||||
|
||||
@ -308,6 +325,7 @@ BEGIN_EVENT_TABLE( ToolFrame, wxFrame )
|
||||
EVT_MOUSE_CAPTURE_LOST( ToolFrame::OnCaptureLost )
|
||||
EVT_CLOSE( ToolFrame::OnClose )
|
||||
EVT_COMMAND( wxID_ANY, EVT_TOOLBAR_UPDATED, ToolFrame::OnToolBarUpdate )
|
||||
EVT_KEY_DOWN( ToolFrame::OnKeyDown )
|
||||
END_EVENT_TABLE()
|
||||
|
||||
IMPLEMENT_CLASS( ToolManager, wxEvtHandler );
|
||||
|
@ -231,8 +231,12 @@ void Grabber::OnPaint(wxPaintEvent & WXUNUSED(event))
|
||||
|
||||
void Grabber::OnKeyDown(wxKeyEvent &event)
|
||||
{
|
||||
if(event.GetKeyCode() == WXK_ESCAPE)
|
||||
event.Skip();
|
||||
|
||||
if(event.GetKeyCode() == WXK_ESCAPE) {
|
||||
// We must not only skip this key event, but propagate it up the window
|
||||
// hierarchy, so that ToolFrame detects it too.
|
||||
event.ResumePropagation(wxEVENT_PROPAGATE_MAX);
|
||||
SendEvent(EVT_GRABBER_CLICKED, wxPoint{ -1, -1 }, true);
|
||||
else
|
||||
event.Skip();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user