Audacity 3.2.0
TrackButtonHandles.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5TrackButtonHandles.cpp
6
7Paul Licameli split from TrackPanel.cpp
8
9**********************************************************************/
10
11
12#include "TrackButtonHandles.h"
13
14#include "PendingTracks.h"
15#include "Project.h"
16#include "ProjectAudioIO.h"
17#include "../../ProjectAudioManager.h"
18#include "ProjectHistory.h"
19#include "../../SelectUtilities.h"
20#include "../../RefreshCode.h"
21#include "Track.h"
22#include "TrackFocus.h"
23#include "CommonTrackInfo.h"
24#include "../../TrackPanel.h"
25#include "../../TrackUtilities.h"
26#include "CommandManager.h"
27#include "../../tracks/ui/ChannelView.h"
28
30( const std::shared_ptr<Track> &pTrack, const wxRect &rect )
31 : ButtonHandle{ pTrack, rect }
32{}
33
35{
36}
37
39(const wxMouseEvent &, AudacityProject *pProject, wxWindow*)
40{
41 using namespace RefreshCode;
42
43 if (auto pTrack = mpTrack.lock()) {
44 auto channels = pTrack->Channels();
45 bool wasMinimized = ChannelView::Get(**channels.begin()).GetMinimized();
46 for (auto pChannel : channels)
47 ChannelView::Get(*pChannel).SetMinimized( !wasMinimized );
48 ProjectHistory::Get(*pProject).ModifyState(true);
49
50 // Redraw all tracks when any one of them expands or contracts
51 // (Could we invent a return code that draws only those at or below
52 // the affected track?)
54 }
55
56 return RefreshNone;
57}
58
60 const wxMouseState &, AudacityProject &) const
61{
62 auto pTrack = GetTrack();
63 return ChannelView::Get(*pTrack->GetChannel(0)).GetMinimized()
64 ? XO("Expand") : XO("Collapse");
65}
66
68(std::weak_ptr<MinimizeButtonHandle> &holder,
69 const wxMouseState &state, const wxRect &rect, TrackPanelCell *pCell)
70{
71 wxRect buttonRect;
72 CommonTrackInfo::GetMinimizeRect(rect, buttonRect);
73
74 if (buttonRect.Contains(state.m_x, state.m_y)) {
75 auto pTrack = static_cast<CommonTrackPanelCell*>(pCell)->FindTrack();
76 auto result = std::make_shared<MinimizeButtonHandle>( pTrack, buttonRect );
77 result = AssignUIHandlePtr(holder, result);
78 return result;
79 }
80 else
81 return {};
82}
83
85
87( const std::shared_ptr<Track> &pTrack, const wxRect &rect )
88 : ButtonHandle{ pTrack, rect }
89{}
90
92{
93}
94
96 AudacityProject *pProject, wxWindow*)
97{
98 using namespace RefreshCode;
99 Result result = RefreshNone;
100
101 auto pTrack = mpTrack.lock();
102 if (pTrack) {
103 auto &toRemove = PendingTracks::Get(*pProject)
106 if (!ProjectAudioIO::Get( *pProject ).IsAudioActive()) {
107 // This pushes an undo item:
108 TrackUtilities::DoRemoveTrack(*pProject, toRemove);
109 // Redraw all tracks when any one of them closes
110 // (Could we invent a return code that draws only those at or below
111 // the affected track?)
113 }
114 }
115
116 return result;
117}
118
120 const wxMouseState &, AudacityProject &project) const
121{
122 auto name = XO("Delete Track");
123 auto focused =
124 TrackFocus::Get( project ).Get() == GetTrack().get();
125 if (!focused)
126 return name;
127
128 auto &commandManager = CommandManager::Get( project );
129 ComponentInterfaceSymbol command{ wxT("TrackClose"), name };
130 return commandManager.DescribeCommandsAndShortcuts( &command, 1u );
131}
132
134(std::weak_ptr<CloseButtonHandle> &holder,
135 const wxMouseState &state, const wxRect &rect, TrackPanelCell *pCell)
136{
137 wxRect buttonRect;
138 CommonTrackInfo::GetCloseBoxRect(rect, buttonRect);
139
140 if (buttonRect.Contains(state.m_x, state.m_y)) {
141 auto pTrack = static_cast<CommonTrackPanelCell*>(pCell)->FindTrack();
142 auto result = std::make_shared<CloseButtonHandle>( pTrack, buttonRect );
143 result = AssignUIHandlePtr(holder, result);
144 return result;
145 }
146 else
147 return {};
148}
149
151
153( const std::shared_ptr<TrackPanelCell> &pCell,
154 const std::shared_ptr<Track> &pTrack, const wxRect &rect )
155 : ButtonHandle{ pTrack, rect }
156 , mpCell{ pCell }
157{}
158
160{
161}
162
164(const wxMouseEvent &, AudacityProject *pProject, wxWindow *WXUNUSED(pParent))
165{
166 auto &trackPanel = TrackPanel::Get( *pProject );
167 auto pCell = mpCell.lock();
168 if (!pCell)
170 auto pTrack =
171 static_cast<CommonTrackPanelCell*>(pCell.get())->FindTrack();
172 if (!pTrack)
174 trackPanel.CallAfter(
175 [&trackPanel,pTrack]{ trackPanel.OnTrackMenu( pTrack.get() ); } );
177}
178
180 const wxMouseState &, AudacityProject &project) const
181{
182 auto name = XO("Open menu...");
183 auto focused =
184 TrackFocus::Get( project ).Get() == GetTrack().get();
185 if (!focused)
186 return name;
187
188 auto &commandManager = CommandManager::Get( project );
189 ComponentInterfaceSymbol command{ wxT("TrackMenu"), name };
190 return commandManager.DescribeCommandsAndShortcuts( &command, 1u );
191}
192
194(std::weak_ptr<MenuButtonHandle> &holder,
195 const wxMouseState &state, const wxRect &rect,
196 const std::shared_ptr<TrackPanelCell> &pCell)
197{
198 wxRect buttonRect;
200
201 if (buttonRect.Contains(state.m_x, state.m_y)) {
202 auto pTrack = static_cast<CommonTrackPanelCell*>(pCell.get())->FindTrack();
203 auto result = std::make_shared<MenuButtonHandle>( pCell, pTrack, buttonRect );
204 result = AssignUIHandlePtr(holder, result);
205 return result;
206 }
207 else
208 return {};
209}
wxT("CloseDown"))
std::shared_ptr< UIHandle > UIHandlePtr
Definition: CellularPanel.h:28
const TranslatableString name
Definition: Distortion.cpp:76
XO("Cut/Copy/Paste")
const auto project
declares abstract base class Track, TrackList, and iterators over TrackList
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:164
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
A UIHandle for a TrackPanel button, such as the Mute and Solo buttons.
Definition: ButtonHandle.h:26
std::weak_ptr< Track > mpTrack
Definition: ButtonHandle.h:74
std::shared_ptr< Track > GetTrack() const
Definition: ButtonHandle.h:30
std::shared_ptr< const Track > FindTrack() const override
static ChannelView & Get(Channel &channel)
bool GetMinimized() const
Definition: ChannelView.h:69
void SetMinimized(bool minimized)
Subclass & Get(const RegisteredFactory &key)
Get reference to an attachment, creating on demand if not present, down-cast it to Subclass.
Definition: ClientData.h:318
CloseButtonHandle(const CloseButtonHandle &)=delete
static UIHandlePtr HitTest(std::weak_ptr< CloseButtonHandle > &holder, const wxMouseState &state, const wxRect &rect, TrackPanelCell *pCell)
TranslatableString Tip(const wxMouseState &state, AudacityProject &project) const override
Result CommitChanges(const wxMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
static CommandManager & Get(AudacityProject &project)
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
MenuButtonHandle(const MenuButtonHandle &)=delete
Result CommitChanges(const wxMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
static UIHandlePtr HitTest(std::weak_ptr< MenuButtonHandle > &holder, const wxMouseState &state, const wxRect &rect, const std::shared_ptr< TrackPanelCell > &pCell)
TranslatableString Tip(const wxMouseState &state, AudacityProject &) const override
std::weak_ptr< TrackPanelCell > mpCell
MinimizeButtonHandle(const MinimizeButtonHandle &)=delete
Result CommitChanges(const wxMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
static UIHandlePtr HitTest(std::weak_ptr< MinimizeButtonHandle > &holder, const wxMouseState &state, const wxRect &rect, TrackPanelCell *pCell)
TranslatableString Tip(const wxMouseState &state, AudacityProject &) const override
Track & SubstitutePendingChangedTrack(Track &track) const
static PendingTracks & Get(AudacityProject &project)
bool IsAudioActive() const
static ProjectAudioIO & Get(AudacityProject &project)
static ProjectAudioManager & Get(AudacityProject &project)
void ModifyState(bool bWantsAutoSave)
static ProjectHistory & Get(AudacityProject &project)
Track * Get()
Definition: TrackFocus.cpp:156
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:234
Holds a msgid for the translation catalog; may also bind format arguments.
unsigned Result
Definition: UIHandle.h:40
AUDACITY_DLL_API void GetCloseBoxRect(const wxRect &rect, wxRect &dest)
AUDACITY_DLL_API void GetTrackMenuButtonRect(const wxRect &rect, wxRect &dest)
AUDACITY_DLL_API void GetMinimizeRect(const wxRect &rect, wxRect &dest)
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16
AUDACITY_DLL_API void DoRemoveTrack(AudacityProject &project, Track &toRemove)