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
53 (const TrackPanelMouseEvent &evt, AudacityProject *pProject) override
54 {
55 using namespace RefreshCode;
56 const wxMouseEvent &event = evt.event;
57 // Do not start a drag
58 Result result = Cancelled;
59
60 // AS: If the user clicked outside all tracks, make nothing
61 // selected.
62 if ((event.ButtonDown() || event.ButtonDClick())) {
64 TrackList::Get( *pProject ) );
65 result |= RefreshAll;
66 }
67
68 return result;
69 }
70
72 (const TrackPanelMouseEvent &, AudacityProject *) override
73 { return RefreshCode::RefreshNone; }
74
76 (const TrackPanelMouseState &, AudacityProject *) override
77 { return HitPreview(); }
78
81 wxWindow *) override
82 { return RefreshCode::RefreshNone; }
83
85 { return RefreshCode::RefreshNone; }
86};
87
89 []( AudacityProject &parent ){
90 auto result = std::make_shared< BackgroundCell >( &parent );
91 TrackPanel::Get( parent ).SetBackgroundCell( result );
92 return result;
93 }
94};
95
97{
98 return project.AttachedObjects::Get< BackgroundCell >( key );
99}
100
102{
103 return Get( const_cast< AudacityProject & >( project ) );
104}
105
107{
108}
109
110std::vector<UIHandlePtr> BackgroundCell::HitTest
111(const TrackPanelMouseState &,
112 const AudacityProject *)
113{
114 auto result = AssignUIHandlePtr(mHandle, std::make_shared<BackgroundHandle>());
115 return { result };
116}
117
118std::shared_ptr<Track> BackgroundCell::DoFindTrack()
119{
120 return {};
121}
122
125 const wxRect &rect, unsigned iPass )
126{
127 if ( iPass == TrackArtist::PassBackground ) {
128 auto &dc = context.dc;
129 // Paint over the part below the tracks
130 AColor::TrackPanelBackground( &dc, false );
131 dc.DrawRectangle( rect );
132 }
133}
134
137 const wxRect &rect, const wxRect &, unsigned iPass )
138{
139 if ( iPass == TrackArtist::PassBackground )
140 // If there are any tracks, extend the drawing area up, to cover the
141 // bottom ends of any zooming guide lines.
142 return {
143 rect.x,
144 rect.y - kTopMargin,
145 rect.width,
146 rect.height + kTopMargin
147 };
148 else
149 return rect;
150}
151
153 const wxRect &, const wxPoint *, AudacityProject * )
154 -> std::vector<MenuItem>
155{
156 // These commands exist in toolbar menus too, but maybe with other labels
157 // TODO: devise a system of registration so that BackgroundCell has no
158 // special knowledge about track sub-types
159 return {
160 { L"NewMonoTrack", XO("Add Mono Track")},
161 { L"NewStereoTrack", XO("Add Stereo Track") },
162 { L"NewLabelTrack", XO("Add Label Track"), },
163 {},
164 { L"Export", XO("Export Audio..."), },
165 {},
166 { L"SelectAll", XO("Select All") },
167 };
168}
static const AudacityProject::AttachedObjects::RegisteredFactory key
XO("Cut/Copy/Paste")
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:151
static void TrackPanelBackground(wxDC *dc, bool selected)
Definition: AColor.cpp:454
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
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:266
void SelectNone(TrackList &tracks)
static SelectionState & Get(AudacityProject &project)
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:487
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:231
void SetBackgroundCell(const std::shared_ptr< CommonTrackPanelCell > &pCell)
Definition: TrackPanel.cpp:860
Short-lived drawing and event-handling object associated with a TrackPanelCell.
Definition: UIHandle.h:35
unsigned Result
Definition: UIHandle.h:38
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16