1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-01 16:19:43 +02:00

static BackgroundCell::Get()...

... not member functions of AudacityProject.

This frees BackgroundCell.cpp from dependency cycles
This commit is contained in:
Paul Licameli 2019-01-22 15:18:02 -05:00
parent 0923bc19a9
commit 004997cec1
5 changed files with 30 additions and 14 deletions

View File

@ -161,7 +161,6 @@ scroll information. It also has some status flags.
#include "toolbars/ToolsToolBar.h"
#include "toolbars/TranscriptionToolBar.h"
#include "tracks/ui/BackgroundCell.h"
#include "tracks/ui/EditCursorOverlay.h"
#include "tracks/ui/PlayIndicatorOverlay.h"
#include "tracks/ui/Scrubbing.h"
@ -1232,8 +1231,6 @@ AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id,
mCursorOverlay = std::make_shared<EditCursorOverlay>(this);
mBackgroundCell = std::make_shared<BackgroundCell>(this);
#ifdef EXPERIMENTAL_SCRUBBING_BASIC
mScrubOverlay = std::make_shared<ScrubbingOverlay>(this);
#endif
@ -1251,8 +1248,6 @@ AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id,
MenuManager::Get( project ).CreateMenusAndCommands( project );
mTrackPanel->SetBackgroundCell(mBackgroundCell);
// LLL: When Audacity starts or becomes active after returning from
// another application, the first window that can accept focus
// will be given the focus even if we try to SetFocus(). By

View File

@ -92,7 +92,6 @@ enum class UndoPush : unsigned char;
class Track;
class WaveClip;
class BackgroundCell;
AudacityProject *CreateNewAudacityProject();
@ -654,8 +653,6 @@ private:
std::shared_ptr<Overlay>
mIndicatorOverlay, mCursorOverlay;
std::shared_ptr<BackgroundCell> mBackgroundCell;
#ifdef EXPERIMENTAL_SCRUBBING_BASIC
std::shared_ptr<Overlay> mScrubOverlay;
private:
@ -698,8 +695,6 @@ private:
public:
PlaybackScroller &GetPlaybackScroller() { return *mPlaybackScroller; }
std::shared_ptr<BackgroundCell> GetBackgroundCell() const
{ return mBackgroundCell; }
DECLARE_EVENT_TABLE()
};

View File

@ -12,9 +12,11 @@ Paul Licameli split from TrackPanel.cpp
#include "BackgroundCell.h"
#include "../../HitTestResult.h"
#include "../../Project.h"
#include "../../RefreshCode.h"
#include "../../SelectionState.h"
#include "../../Track.h"
#include "../../TrackPanel.h"
#include "../../TrackPanelMouseEvent.h"
#include "../../UIHandle.h"
@ -76,6 +78,24 @@ public:
{ return RefreshCode::RefreshNone; }
};
static const AudacityProject::AttachedObjects::RegisteredFactory key{
[]( AudacityProject &parent ){
auto result = std::make_shared< BackgroundCell >( &parent );
parent.GetTrackPanel()->SetBackgroundCell( result );
return result;
}
};
BackgroundCell &BackgroundCell::Get( AudacityProject &project )
{
return project.AttachedObjects::Get< BackgroundCell >( key );
}
const BackgroundCell &BackgroundCell::Get( const AudacityProject &project )
{
return Get( const_cast< AudacityProject & >( project ) );
}
BackgroundCell::~BackgroundCell()
{
}

View File

@ -11,6 +11,7 @@ Paul Licameli split from TrackPanel.cpp
#ifndef __AUDACITY_BACKGROUND_CELL__
#define __AUDACITY_BACKGROUND_CELL__
#include "ClientData.h"
#include "CommonTrackPanelCell.h"
class AudacityProject;
@ -21,9 +22,14 @@ class ZoomHandle;
/// \brief Class representing the background of a Track. It
/// provides the hit test function that tells us what was hit.
class BackgroundCell final : public CommonTrackPanelCell
class BackgroundCell final
: public CommonTrackPanelCell
, public ClientData::Base
{
public:
static BackgroundCell &Get( AudacityProject &project );
static const BackgroundCell &Get( const AudacityProject &project );
BackgroundCell(AudacityProject *pProject)
: mpProject(pProject)
{}
@ -44,7 +50,7 @@ private:
public:
// For want of a better place...
std::weak_ptr<ZoomHandle> mZoomHandle;
mutable std::weak_ptr<ZoomHandle> mZoomHandle;
};
#endif

View File

@ -40,7 +40,7 @@ std::vector<UIHandlePtr> Track::HitTest
// Zoom tool is a non-selecting tool that takes precedence in all tracks
// over all other tools, no matter what detail you point at.
result = ZoomHandle::HitAnywhere(
pProject->GetBackgroundCell()->mZoomHandle);
BackgroundCell::Get( *pProject ).mZoomHandle );
results.push_back(result);
return results;
}
@ -63,7 +63,7 @@ std::vector<UIHandlePtr> Track::HitTest
// other detailed hits.
if ( isMultiTool ) {
result = ZoomHandle::HitTest(
pProject->GetBackgroundCell()->mZoomHandle, st.state);
BackgroundCell::Get( *pProject ).mZoomHandle, st.state);
if (result)
results.push_back(result);
}