mirror of
https://github.com/cookiengineer/audacity
synced 2025-07-05 23:19:06 +02:00
ToolManager does not depend on ProjectWindow
This commit is contained in:
parent
0b897c81b0
commit
e1908ab8e2
@ -1887,3 +1887,12 @@ void ProjectWindow::ZoomOutByFactor( double ZoomFactor )
|
|||||||
// newh = (newh > 0) ? newh : 0;
|
// newh = (newh > 0) ? newh : 0;
|
||||||
TP_ScrollWindow(newh);
|
TP_ScrollWindow(newh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct InstallTopPanelHook{ InstallTopPanelHook() {
|
||||||
|
ToolManager::SetGetTopPanelHook(
|
||||||
|
[]( wxWindow &window ){
|
||||||
|
auto pProjectWindow = dynamic_cast< ProjectWindow* >( &window );
|
||||||
|
return pProjectWindow ? pProjectWindow->GetTopPanel() : nullptr;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}} installTopPanelHook;
|
||||||
|
@ -57,7 +57,6 @@
|
|||||||
#include "../ImageManipulation.h"
|
#include "../ImageManipulation.h"
|
||||||
#include "../Prefs.h"
|
#include "../Prefs.h"
|
||||||
#include "../Project.h"
|
#include "../Project.h"
|
||||||
#include "../ProjectWindow.h"
|
|
||||||
#include "../widgets/AButton.h"
|
#include "../widgets/AButton.h"
|
||||||
#include "../widgets/ASlider.h"
|
#include "../widgets/ASlider.h"
|
||||||
#include "../widgets/MeterPanelBase.h"
|
#include "../widgets/MeterPanelBase.h"
|
||||||
@ -73,7 +72,7 @@
|
|||||||
//
|
//
|
||||||
ToolFrame::ToolFrame
|
ToolFrame::ToolFrame
|
||||||
( AudacityProject *parent, ToolManager *manager, ToolBar *bar, wxPoint pos )
|
( AudacityProject *parent, ToolManager *manager, ToolBar *bar, wxPoint pos )
|
||||||
: wxFrame( ProjectWindow::Find( parent ),
|
: wxFrame( FindProjectFrame( parent ),
|
||||||
bar->GetId(),
|
bar->GetId(),
|
||||||
wxEmptyString,
|
wxEmptyString,
|
||||||
pos,
|
pos,
|
||||||
@ -312,10 +311,26 @@ BEGIN_EVENT_TABLE( ToolManager, wxEvtHandler )
|
|||||||
EVT_TIMER( wxID_ANY, ToolManager::OnTimer )
|
EVT_TIMER( wxID_ANY, ToolManager::OnTimer )
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
|
static ToolManager::GetTopPanelHook &getTopPanelHook()
|
||||||
|
{
|
||||||
|
static ToolManager::GetTopPanelHook theHook;
|
||||||
|
return theHook;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto ToolManager::SetGetTopPanelHook( const GetTopPanelHook &hook )
|
||||||
|
-> GetTopPanelHook
|
||||||
|
{
|
||||||
|
auto &theHook = getTopPanelHook();
|
||||||
|
auto result = theHook;
|
||||||
|
theHook = hook;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
static const AudacityProject::AttachedObjects::RegisteredFactory key{
|
static const AudacityProject::AttachedObjects::RegisteredFactory key{
|
||||||
[]( AudacityProject &parent ){
|
[]( AudacityProject &parent ){
|
||||||
auto &window = ProjectWindow::Get( parent );
|
auto &window = GetProjectFrame( parent );
|
||||||
return std::make_shared< ToolManager >( &parent, window.GetTopPanel() ); }
|
return std::make_shared< ToolManager >(
|
||||||
|
&parent, getTopPanelHook()( window ) ); }
|
||||||
};
|
};
|
||||||
|
|
||||||
ToolManager &ToolManager::Get( AudacityProject &project )
|
ToolManager &ToolManager::Get( AudacityProject &project )
|
||||||
@ -334,7 +349,10 @@ const ToolManager &ToolManager::Get( const AudacityProject &project )
|
|||||||
ToolManager::ToolManager( AudacityProject *parent, wxWindow *topDockParent )
|
ToolManager::ToolManager( AudacityProject *parent, wxWindow *topDockParent )
|
||||||
: wxEvtHandler()
|
: wxEvtHandler()
|
||||||
{
|
{
|
||||||
auto &window = ProjectWindow::Get( *parent );
|
if ( !topDockParent )
|
||||||
|
THROW_INCONSISTENCY_EXCEPTION;
|
||||||
|
|
||||||
|
auto &window = GetProjectFrame( *parent );
|
||||||
wxPoint pt[ 3 ];
|
wxPoint pt[ 3 ];
|
||||||
|
|
||||||
#if defined(__WXMAC__)
|
#if defined(__WXMAC__)
|
||||||
@ -653,7 +671,7 @@ int ToolManager::FilterEvent(wxEvent &event)
|
|||||||
if ( window &&
|
if ( window &&
|
||||||
!dynamic_cast<Grabber*>( window ) &&
|
!dynamic_cast<Grabber*>( window ) &&
|
||||||
!dynamic_cast<ToolFrame*>( window ) &&
|
!dynamic_cast<ToolFrame*>( window ) &&
|
||||||
top == ProjectWindow::Find( mParent ) )
|
top == FindProjectFrame( mParent ) )
|
||||||
// Note this is a dangle-proof wxWindowRef:
|
// Note this is a dangle-proof wxWindowRef:
|
||||||
mLastFocus = window;
|
mLastFocus = window;
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
#ifndef __AUDACITY_TOOLMANAGER__
|
#ifndef __AUDACITY_TOOLMANAGER__
|
||||||
#define __AUDACITY_TOOLMANAGER__
|
#define __AUDACITY_TOOLMANAGER__
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
#include <wx/defs.h>
|
#include <wx/defs.h>
|
||||||
#include <wx/eventfilter.h> // to inherit
|
#include <wx/eventfilter.h> // to inherit
|
||||||
#include <wx/frame.h> // to inherit
|
#include <wx/frame.h> // to inherit
|
||||||
@ -48,6 +50,9 @@ class ToolManager final
|
|||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
// a hook function to break dependency of ToolManager on ProjectWindow
|
||||||
|
using GetTopPanelHook = std::function< wxWindow*( wxWindow& ) >;
|
||||||
|
static GetTopPanelHook SetGetTopPanelHook( const GetTopPanelHook& );
|
||||||
|
|
||||||
static ToolManager &Get( AudacityProject &project );
|
static ToolManager &Get( AudacityProject &project );
|
||||||
static const ToolManager &Get( const AudacityProject &project );
|
static const ToolManager &Get( const AudacityProject &project );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user