Audacity 3.2.0
BackgroundCell.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5BackgroundCell.cpp
6
7Paul Licameli split from TrackPanel.cpp
8
9**********************************************************************/
10
11
12#include "BackgroundCell.h"
13
14#include "AColor.h"
15#include "../../HitTestResult.h"
16#include "Project.h"
17#include "../../RefreshCode.h"
18#include "SelectionState.h"
19#include "Track.h"
20#include "../../TrackArtist.h"
21#include "../../TrackPanel.h"
22#include "../../TrackPanelConstants.h"
23#include "../../TrackPanelDrawingContext.h"
24#include "../../TrackPanelMouseEvent.h"
25#include "../../UIHandle.h"
26#include "ViewInfo.h"
27
28#include <wx/cursor.h>
29
30// Define this, just so the click to deselect can dispatch here
31// This handle class, unlike most, doesn't associate with any particular cell.
33{
36
37public:
39
42
44 {
45 static wxCursor arrowCursor{ wxCURSOR_ARROW };
46 return { {}, &arrowCursor };
47 }
48
50 {}
51
52 std::shared_ptr<const Track> FindTrack() const override
53 { return nullptr; }
54
56 (const TrackPanelMouseEvent &evt, AudacityProject *pProject) override
57 {
58 using namespace RefreshCode;
59 const wxMouseEvent &event = evt.event;
60 // Do not start a drag
61 Result result = Cancelled;
62
63 // AS: If the user clicked outside all tracks, make nothing
64 // selected.
65 if ((event.ButtonDown() || event.ButtonDClick())) {
67 TrackList::Get( *pProject ) );
68 result |= RefreshAll;
69 }
70
71 return result;
72 }
73
75 (const TrackPanelMouseEvent &, AudacityProject *) override
76 { return RefreshCode::RefreshNone; }
77
79 (const TrackPanelMouseState &, AudacityProject *) override
80 { return HitPreview(); }
81
84 wxWindow *) override
85 { return RefreshCode::RefreshNone; }
86
88 { return RefreshCode::RefreshNone; }
89};
90
92 []( AudacityProject &parent ){
93 auto result = std::make_shared< BackgroundCell >( &parent );
94 TrackPanel::Get( parent ).SetBackgroundCell( result );
95 return result;
96 }
97};
98
100{
101 return project.AttachedObjects::Get< BackgroundCell >( key );
102}
103
105{
106 return Get( const_cast< AudacityProject & >( project ) );
107}
108
110{
111}
112
113std::vector<UIHandlePtr> BackgroundCell::HitTest
114(const TrackPanelMouseState &,
115 const AudacityProject *)
116{
117 auto result = AssignUIHandlePtr(mHandle, std::make_shared<BackgroundHandle>());
118 return { result };
119}
120
121std::shared_ptr<Track> BackgroundCell::DoFindTrack()
122{
123 return {};
124}
125
128 const wxRect &rect, unsigned iPass )
129{
130 if ( iPass == TrackArtist::PassBackground ) {
131 auto &dc = context.dc;
132 // Paint over the part below the tracks
133 AColor::TrackPanelBackground( &dc, false );
134 dc.DrawRectangle( rect );
135 }
136}
137
140 const wxRect &rect, const wxRect &, unsigned iPass )
141{
142 if ( iPass == TrackArtist::PassBackground )
143 // If there are any tracks, extend the drawing area up, to cover the
144 // bottom ends of any zooming guide lines.
145 return {
146 rect.x,
147 rect.y - kTopMargin,
148 rect.width,
149 rect.height + kTopMargin
150 };
151 else
152 return rect;
153}
154
156 const wxRect &, const wxPoint *, AudacityProject * )
157 -> std::vector<MenuItem>
158{
159 // These commands exist in toolbar menus too, but maybe with other labels
160 // TODO: devise a system of registration so that BackgroundCell has no
161 // special knowledge about track sub-types
162 return {
163 { L"NewMonoTrack", XO("Add Mono Track")},
164 { L"NewStereoTrack", XO("Add Stereo Track") },
165 { L"NewLabelTrack", XO("Add Label Track"), },
166 {},
167 { L"Export", XO("Export Audio..."), },
168 {},
169 { L"SelectAll", XO("Select All") },
170 };
171}
static const AudacityProject::AttachedObjects::RegisteredFactory key
XO("Cut/Copy/Paste")
const auto project
declares abstract base class Track, TrackList, and iterators over TrackList
@ kTopMargin
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:164
static void TrackPanelBackground(wxDC *dc, bool selected)
Definition: AColor.cpp:432
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
Class representing the background of a Track. It provides the hit test function that tells us what wa...
static BackgroundCell & Get(AudacityProject &project)
std::vector< MenuItem > GetMenuItems(const wxRect &rect, const wxPoint *pPosition, AudacityProject *pProject) override
Return a list of items for DoContextMenu() (empties for separators)
std::shared_ptr< Track > DoFindTrack() override
virtual ~BackgroundCell()
std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &state, const AudacityProject *) override
wxRect DrawingArea(TrackPanelDrawingContext &, const wxRect &rect, const wxRect &panelRect, unsigned iPass) override
std::weak_ptr< BackgroundHandle > mHandle
void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
Result Release(const TrackPanelMouseEvent &, AudacityProject *, wxWindow *) override
Result Cancel(AudacityProject *) override
BackgroundHandle(const BackgroundHandle &)=delete
Result Drag(const TrackPanelMouseEvent &, AudacityProject *) override
BackgroundHandle & operator=(const BackgroundHandle &)=delete
std::shared_ptr< const Track > FindTrack() const override
BackgroundHandle & operator=(BackgroundHandle &&)=default
BackgroundHandle(BackgroundHandle &&)=default
virtual ~BackgroundHandle()
HitTestPreview Preview(const TrackPanelMouseState &, AudacityProject *) override
Result Click(const TrackPanelMouseEvent &evt, AudacityProject *pProject) override
static HitTestPreview HitPreview()
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
Definition: ClientData.h:275
void SelectNone(TrackList &tracks)
static SelectionState & Get(AudacityProject &project)
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:234
void SetBackgroundCell(const std::shared_ptr< CommonTrackPanelCell > &pCell)
Definition: TrackPanel.cpp:885
Short-lived drawing and event-handling object associated with a TrackPanelCell.
Definition: UIHandle.h:37
unsigned Result
Definition: UIHandle.h:40
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16