mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-04 17:49:45 +02:00
Bug1432 partial: Dragging toolbar should't change focus...
... Only the case that you click the grabber and release, or you drag the toolbar ending in a docked position. Doesn't work yet when drag ends un-docked.
This commit is contained in:
parent
b521fb8422
commit
b3c8f5db3d
@ -334,7 +334,7 @@ IMPLEMENT_CLASS( ToolDock, wxPanelWrapper );
|
||||
//
|
||||
// Custom event
|
||||
//
|
||||
DEFINE_EVENT_TYPE( EVT_TOOLBAR_FLOAT );
|
||||
//DEFINE_EVENT_TYPE( EVT_TOOLBAR_FLOAT );
|
||||
|
||||
BEGIN_EVENT_TABLE( ToolDock, wxPanelWrapper )
|
||||
EVT_GRABBER( wxID_ANY, ToolDock::OnGrabber )
|
||||
|
@ -67,6 +67,8 @@
|
||||
#include "../Project.h"
|
||||
#include "../Theme.h"
|
||||
#include "../widgets/AButton.h"
|
||||
#include "../widgets/ASlider.h"
|
||||
#include "../widgets/Meter.h"
|
||||
#include "../widgets/Grabber.h"
|
||||
|
||||
#include "../Experimental.h"
|
||||
@ -80,7 +82,7 @@
|
||||
// Constructor
|
||||
//
|
||||
ToolFrame::ToolFrame
|
||||
( wxWindow *parent, ToolManager *manager, ToolBar *bar, wxPoint pos )
|
||||
( AudacityProject *parent, ToolManager *manager, ToolBar *bar, wxPoint pos )
|
||||
: wxFrame( parent,
|
||||
bar->GetId(),
|
||||
wxEmptyString,
|
||||
@ -92,6 +94,7 @@ ToolFrame::ToolFrame
|
||||
wxFRAME_TOOL_WINDOW |
|
||||
#endif
|
||||
wxFRAME_FLOAT_ON_PARENT )
|
||||
, mParent{ parent }
|
||||
{
|
||||
int width = bar->GetSize().x;
|
||||
int border;
|
||||
@ -113,7 +116,6 @@ ToolFrame::ToolFrame
|
||||
#endif
|
||||
|
||||
// Save parameters
|
||||
mParent = parent;
|
||||
mManager = manager;
|
||||
mBar = bar;
|
||||
|
||||
@ -434,6 +436,8 @@ ToolManager::ToolManager( AudacityProject *parent, wxWindow *topDockParent )
|
||||
|
||||
// Process the toolbar config settings
|
||||
ReadConfig();
|
||||
|
||||
wxEvtHandler::AddFilter(this);
|
||||
}
|
||||
|
||||
//
|
||||
@ -441,6 +445,8 @@ ToolManager::ToolManager( AudacityProject *parent, wxWindow *topDockParent )
|
||||
//
|
||||
ToolManager::~ToolManager()
|
||||
{
|
||||
wxEvtHandler::RemoveFilter(this);
|
||||
|
||||
// Save the toolbar states
|
||||
WriteConfig();
|
||||
|
||||
@ -639,6 +645,35 @@ void ToolManager::RegenerateTooltips()
|
||||
}
|
||||
}
|
||||
|
||||
int ToolManager::FilterEvent(wxEvent &event)
|
||||
{
|
||||
// Snoop the global event stream for changes of focused window. Remember
|
||||
// the last one of our own that is not a grabber.
|
||||
|
||||
if (event.GetEventType() == wxEVT_KILL_FOCUS) {
|
||||
auto &focusEvent = static_cast<wxFocusEvent&>(event);
|
||||
auto window = focusEvent.GetWindow();
|
||||
auto top = wxGetTopLevelParent(window);
|
||||
if(auto toolFrame = dynamic_cast<ToolFrame*>(top))
|
||||
top = toolFrame->GetParent();
|
||||
// window is that which will GET the focus
|
||||
if ( window &&
|
||||
!dynamic_cast<Grabber*>( window ) &&
|
||||
!dynamic_cast<ToolFrame*>( window ) &&
|
||||
top == mParent )
|
||||
mLastFocus = window;
|
||||
}
|
||||
else if (event.GetEventType() == wxEVT_CLOSE_WINDOW) {
|
||||
auto &closeEvent = static_cast<wxCloseEvent&>(event);
|
||||
auto window = closeEvent.GetEventObject();
|
||||
if (window == mLastFocus)
|
||||
// Avoid a dangling pointer!
|
||||
mLastFocus = nullptr;
|
||||
}
|
||||
|
||||
return Event_Skip;
|
||||
}
|
||||
|
||||
//
|
||||
// Read the toolbar states
|
||||
//
|
||||
@ -1076,7 +1111,7 @@ void ToolManager::OnMouse( wxMouseEvent & event )
|
||||
// Can't do anything if we're not dragging. This also prevents
|
||||
// us from intercepting events that don't belong to us from the
|
||||
// parent since we're Connect()ed to a couple.
|
||||
if( !mDragWindow )
|
||||
if( !mClicked )
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -1090,11 +1125,16 @@ void ToolManager::OnMouse( wxMouseEvent & event )
|
||||
wxPoint pos =
|
||||
( (wxWindow *)event.GetEventObject() )->ClientToScreen( event.GetPosition() ) - mDragOffset;
|
||||
|
||||
// Button was released...finish the drag
|
||||
|
||||
if( !event.LeftIsDown() )
|
||||
{
|
||||
// Button was released...finish the drag
|
||||
// Transition the bar to a dock
|
||||
if( mDragDock && !event.ShiftDown() )
|
||||
if (!mDidDrag) {
|
||||
DoneDragging();
|
||||
return;
|
||||
}
|
||||
else if( mDragDock && !event.ShiftDown() )
|
||||
{
|
||||
// Trip over...everyone ashore that's going ashore...
|
||||
mDragDock->Dock( mDragBar, true, mDragBefore );
|
||||
@ -1115,6 +1155,15 @@ void ToolManager::OnMouse( wxMouseEvent & event )
|
||||
}
|
||||
else if( event.Dragging() && pos != mLastPos )
|
||||
{
|
||||
if (!mDidDrag) {
|
||||
// Must set the bar afloat if it's currently docked
|
||||
mDidDrag = true;
|
||||
wxPoint mp = event.GetPosition();
|
||||
mp = mParent->ClientToScreen(mp);
|
||||
if (!mDragWindow)
|
||||
UndockBar(mp);
|
||||
}
|
||||
|
||||
// Make toolbar follow the mouse
|
||||
mDragWindow->Move( pos );
|
||||
|
||||
@ -1310,6 +1359,36 @@ void ToolManager::OnIndicatorCreate( wxWindowCreateEvent & event )
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
void ToolManager::UndockBar( wxPoint mp )
|
||||
{
|
||||
#if defined(__WXMAC__)
|
||||
// Disable window animation
|
||||
wxSystemOptions::SetOption( wxMAC_WINDOW_PLAIN_TRANSITION, 1 );
|
||||
#endif
|
||||
|
||||
// Adjust the starting position
|
||||
mp -= mDragOffset;
|
||||
|
||||
// Inform toolbar of change
|
||||
mDragBar->SetDocked( NULL, true );
|
||||
mDragBar->SetPositioned();
|
||||
|
||||
// Construct a NEW floater
|
||||
wxASSERT(mParent);
|
||||
mDragWindow = safenew ToolFrame( mParent, this, mDragBar, mp );
|
||||
|
||||
// Make sure the ferry is visible
|
||||
mDragWindow->Show();
|
||||
|
||||
// Notify parent of change
|
||||
Updated();
|
||||
|
||||
#if defined(__WXMAC__)
|
||||
// Reinstate original transition
|
||||
wxSystemOptions::SetOption( wxMAC_WINDOW_PLAIN_TRANSITION, mTransition );
|
||||
#endif
|
||||
}
|
||||
|
||||
//
|
||||
// Transition a toolbar from float to dragging
|
||||
//
|
||||
@ -1340,35 +1419,10 @@ void ToolManager::OnGrabber( GrabberEvent & event )
|
||||
mDragBar->GetParent()->ClientToScreen( mDragBar->GetPosition() ) +
|
||||
wxPoint( 1, 1 );
|
||||
|
||||
// Must set the bar afloat if it's currently docked
|
||||
mClicked = true;
|
||||
if( mPrevDock )
|
||||
{
|
||||
#if defined(__WXMAC__)
|
||||
// Disable window animation
|
||||
wxSystemOptions::SetOption( wxMAC_WINDOW_PLAIN_TRANSITION, 1 );
|
||||
#endif
|
||||
|
||||
// Adjust the starting position
|
||||
mp -= mDragOffset;
|
||||
|
||||
// Inform toolbar of change
|
||||
mDragBar->SetDocked( NULL, true );
|
||||
mDragBar->SetPositioned();
|
||||
|
||||
// Construct a NEW floater
|
||||
wxASSERT(mParent);
|
||||
mDragWindow = safenew ToolFrame( mParent, this, mDragBar, mp );
|
||||
|
||||
// Make sure the ferry is visible
|
||||
mDragWindow->Show();
|
||||
|
||||
// Notify parent of change
|
||||
Updated();
|
||||
|
||||
#if defined(__WXMAC__)
|
||||
// Reinstate original transition
|
||||
wxSystemOptions::SetOption( wxMAC_WINDOW_PLAIN_TRANSITION, mTransition );
|
||||
#endif
|
||||
mDragWindow = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1434,4 +1488,14 @@ void ToolManager::DoneDragging()
|
||||
mLastPos.x = mBarPos.x = -1;
|
||||
mLastPos.y = mBarPos.y = -1;
|
||||
mTimer.Stop();
|
||||
mDidDrag = false;
|
||||
mClicked = false;
|
||||
|
||||
if (mLastFocus) {
|
||||
auto temp1 = AButton::TemporarilyAllowFocus();
|
||||
auto temp2 = ASlider::TemporarilyAllowFocus();
|
||||
auto temp3 = Meter::TemporarilyAllowFocus();
|
||||
auto parent = mLastFocus->GetParent();
|
||||
mLastFocus->SetFocus();
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
#include "../MemoryX.h"
|
||||
#include <wx/defs.h>
|
||||
#include <wx/eventfilter.h>
|
||||
#include <wx/frame.h>
|
||||
#include <wx/timer.h>
|
||||
|
||||
@ -41,7 +42,7 @@ class ToolFrame;
|
||||
/// class ToolManager
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
class ToolManager final : public wxEvtHandler
|
||||
class ToolManager final : public wxEvtHandler, public wxEventFilter
|
||||
{
|
||||
|
||||
public:
|
||||
@ -68,6 +69,8 @@ class ToolManager final : public wxEvtHandler
|
||||
void Reset();
|
||||
void RegenerateTooltips();
|
||||
|
||||
int FilterEvent(wxEvent &event) override;
|
||||
|
||||
private:
|
||||
|
||||
ToolBar *Float( ToolBar *t, wxPoint & pos );
|
||||
@ -75,6 +78,7 @@ class ToolManager final : public wxEvtHandler
|
||||
void OnTimer( wxTimerEvent & event );
|
||||
void OnMouse( wxMouseEvent & event );
|
||||
void OnCaptureLost( wxMouseCaptureLostEvent & event );
|
||||
void UndockBar( wxPoint mp );
|
||||
void OnGrabber( GrabberEvent & event );
|
||||
void HandleEscapeKey();
|
||||
void DoneDragging();
|
||||
@ -87,6 +91,7 @@ class ToolManager final : public wxEvtHandler
|
||||
void Updated();
|
||||
|
||||
AudacityProject *mParent;
|
||||
wxWindow *mLastFocus{};
|
||||
|
||||
ToolFrame *mDragWindow;
|
||||
ToolDock *mDragDock;
|
||||
@ -119,6 +124,8 @@ class ToolManager final : public wxEvtHandler
|
||||
ToolBarConfiguration::Position mPrevSlot
|
||||
{ ToolBarConfiguration::UnspecifiedPosition };
|
||||
ToolBarConfiguration mPrevConfiguration;
|
||||
bool mDidDrag{};
|
||||
bool mClicked{};
|
||||
|
||||
public:
|
||||
|
||||
@ -135,7 +142,7 @@ class ToolFrame final : public wxFrame
|
||||
{
|
||||
public:
|
||||
|
||||
ToolFrame( wxWindow *parent, ToolManager *manager, ToolBar *bar, wxPoint pos );
|
||||
ToolFrame( AudacityProject *parent, ToolManager *manager, ToolBar *bar, wxPoint pos );
|
||||
|
||||
~ToolFrame();
|
||||
|
||||
@ -171,9 +178,11 @@ public:
|
||||
|
||||
void Resize( const wxSize &size );
|
||||
|
||||
AudacityProject *GetParent() const { return mParent; }
|
||||
|
||||
private:
|
||||
|
||||
wxWindow *mParent;
|
||||
AudacityProject *const mParent;
|
||||
ToolManager *mManager;
|
||||
ToolBar *mBar;
|
||||
wxSize mMinSize;
|
||||
|
Loading…
x
Reference in New Issue
Block a user