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 "Project.h"
15#include "../../ProjectAudioIO.h"
16#include "../../ProjectAudioManager.h"
17#include "ProjectHistory.h"
18#include "../../SelectUtilities.h"
19#include "../../RefreshCode.h"
20#include "Track.h"
21#include "../../TrackPanelAx.h"
22#include "../../TrackInfo.h"
23#include "../../TrackPanel.h"
24#include "../../TrackUtilities.h"
25#include "../../commands/CommandManager.h"
26#include "../../tracks/ui/TrackView.h"
27
29( const std::shared_ptr<Track> &pTrack, const wxRect &rect )
30 : ButtonHandle{ pTrack, rect }
31{}
32
34{
35}
36
38(const wxMouseEvent &, AudacityProject *pProject, wxWindow*)
39{
40 using namespace RefreshCode;
41
42 auto pTrack = mpTrack.lock();
43 if (pTrack)
44 {
45 auto channels = TrackList::Channels(pTrack.get());
46 bool wasMinimized = TrackView::Get( **channels.begin() ).GetMinimized();
47 for (auto channel : channels)
48 TrackView::Get( *channel ).SetMinimized( !wasMinimized );
49 ProjectHistory::Get( *pProject ).ModifyState(true);
50
51 // Redraw all tracks when any one of them expands or contracts
52 // (Could we invent a return code that draws only those at or below
53 // the affected track?)
55 }
56
57 return RefreshNone;
58}
59
61 const wxMouseState &, AudacityProject &) const
62{
63 auto pTrack = GetTrack();
64 return TrackView::Get( *pTrack ).GetMinimized()
65 ? XO("Expand") : XO("Collapse");
66}
67
69(std::weak_ptr<MinimizeButtonHandle> &holder,
70 const wxMouseState &state, const wxRect &rect, TrackPanelCell *pCell)
71{
72 wxRect buttonRect;
73 TrackInfo::GetMinimizeRect(rect, buttonRect);
74
75 if (buttonRect.Contains(state.m_x, state.m_y)) {
76 auto pTrack = static_cast<CommonTrackPanelCell*>(pCell)->FindTrack();
77 auto result = std::make_shared<MinimizeButtonHandle>( pTrack, buttonRect );
78 result = AssignUIHandlePtr(holder, result);
79 return result;
80 }
81 else
82 return {};
83}
84
87( const std::shared_ptr<Track> &pTrack, const wxRect &rect )
88 : ButtonHandle{ pTrack, rect }
89{}
90
92{
93}
94
96(const wxMouseEvent &event, AudacityProject *pProject, wxWindow*)
97{
98 using namespace RefreshCode;
99
100 auto pTrack = mpTrack.lock();
101 if (pTrack)
102 {
103 const bool unsafe = ProjectAudioIO::Get( *pProject ).IsAudioActive();
105 pTrack.get(), event.ShiftDown(), event.ControlDown(), !unsafe);
106// return RefreshAll ;
107 }
108
109 return RefreshNone;
110}
111
113 const wxMouseState &, AudacityProject &) const
114{
115 auto pTrack = GetTrack();
116#if defined(__WXMAC__)
117 return pTrack->GetSelected() ? XO("Command+Click to deselect") : XO("Select track");
118#else
119 return pTrack->GetSelected() ? XO("Ctrl+Click to deselect") : XO("Select track");
120#endif
121}
122
124(std::weak_ptr<SelectButtonHandle> &holder,
125 const wxMouseState &state, const wxRect &rect, TrackPanelCell *pCell)
126{
127 wxRect buttonRect;
128 TrackInfo::GetSelectButtonRect(rect, buttonRect);
129
130 if (buttonRect.Contains(state.m_x, state.m_y)) {
131 auto pTrack = static_cast<CommonTrackPanelCell*>(pCell)->FindTrack();
132 auto result = std::make_shared<SelectButtonHandle>( pTrack, buttonRect );
133 result = AssignUIHandlePtr(holder, result);
134 return result;
135 }
136 else
137 return {};
138}
139
141
143( const std::shared_ptr<Track> &pTrack, const wxRect &rect )
144 : ButtonHandle{ pTrack, rect }
145{}
146
148{
149}
150
152(const wxMouseEvent &, AudacityProject *pProject, wxWindow*)
153{
154 using namespace RefreshCode;
155 Result result = RefreshNone;
156
157 auto pTrack = mpTrack.lock();
158 if (pTrack)
159 {
160 auto toRemove = pTrack->SubstitutePendingChangedTrack();
162 if (!ProjectAudioIO::Get( *pProject ).IsAudioActive()) {
163 // This pushes an undo item:
164 TrackUtilities::DoRemoveTrack(*pProject, toRemove.get());
165 // Redraw all tracks when any one of them closes
166 // (Could we invent a return code that draws only those at or below
167 // the affected track?)
169 }
170 }
171
172 return result;
173}
174
176 const wxMouseState &, AudacityProject &project) const
177{
178 auto name = XO("Close");
179 auto focused =
180 TrackFocus::Get( project ).Get() == GetTrack().get();
181 if (!focused)
182 return name;
183
184 auto &commandManager = CommandManager::Get( project );
185 ComponentInterfaceSymbol command{ wxT("TrackClose"), name };
186 return commandManager.DescribeCommandsAndShortcuts( &command, 1u );
187}
188
190(std::weak_ptr<CloseButtonHandle> &holder,
191 const wxMouseState &state, const wxRect &rect, TrackPanelCell *pCell)
192{
193 wxRect buttonRect;
194 TrackInfo::GetCloseBoxRect(rect, buttonRect);
195
196 if (buttonRect.Contains(state.m_x, state.m_y)) {
197 auto pTrack = static_cast<CommonTrackPanelCell*>(pCell)->FindTrack();
198 auto result = std::make_shared<CloseButtonHandle>( pTrack, buttonRect );
199 result = AssignUIHandlePtr(holder, result);
200 return result;
201 }
202 else
203 return {};
204}
205
207
209( const std::shared_ptr<TrackPanelCell> &pCell,
210 const std::shared_ptr<Track> &pTrack, const wxRect &rect )
211 : ButtonHandle{ pTrack, rect }
212 , mpCell{ pCell }
213{}
214
216{
217}
218
220(const wxMouseEvent &, AudacityProject *pProject, wxWindow *WXUNUSED(pParent))
221{
222 auto &trackPanel = TrackPanel::Get( *pProject );
223 auto pCell = mpCell.lock();
224 if (!pCell)
226 auto pTrack =
227 static_cast<CommonTrackPanelCell*>(pCell.get())->FindTrack();
228 if (!pTrack)
230 trackPanel.CallAfter(
231 [&trackPanel,pTrack]{ trackPanel.OnTrackMenu( pTrack.get() ); } );
233}
234
236 const wxMouseState &, AudacityProject &project) const
237{
238 auto name = XO("Open menu...");
239 auto focused =
240 TrackFocus::Get( project ).Get() == GetTrack().get();
241 if (!focused)
242 return name;
243
244 auto &commandManager = CommandManager::Get( project );
245 ComponentInterfaceSymbol command{ wxT("TrackMenu"), name };
246 return commandManager.DescribeCommandsAndShortcuts( &command, 1u );
247}
248
250(std::weak_ptr<MenuButtonHandle> &holder,
251 const wxMouseState &state, const wxRect &rect,
252 const std::shared_ptr<TrackPanelCell> &pCell)
253{
254 wxRect buttonRect;
255 TrackInfo::GetTitleBarRect(rect, buttonRect);
256
257 if (buttonRect.Contains(state.m_x, state.m_y)) {
258 auto pTrack = static_cast<CommonTrackPanelCell*>(pCell.get())->FindTrack();
259 auto result = std::make_shared<MenuButtonHandle>( pCell, pTrack, buttonRect );
260 result = AssignUIHandlePtr(holder, result);
261 return result;
262 }
263 else
264 return {};
265}
std::shared_ptr< UIHandle > UIHandlePtr
Definition: CellularPanel.h:28
const TranslatableString name
Definition: Distortion.cpp:82
#define XO(s)
Definition: Internat.h:31
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:151
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
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:72
std::shared_ptr< Track > GetTrack() const
Definition: ButtonHandle.h:30
Subclass & Get(const RegisteredFactory &key)
Get reference to an attachment, creating on demand if not present, down-cast it to Subclass.
Definition: ClientData.h:309
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
bool IsAudioActive() const
static ProjectAudioIO & Get(AudacityProject &project)
static ProjectAudioManager & Get(AudacityProject &project)
void ModifyState(bool bWantsAutoSave)
static ProjectHistory & Get(AudacityProject &project)
SelectButtonHandle(const SelectButtonHandle &)=delete
TranslatableString Tip(const wxMouseState &state, AudacityProject &) const override
Result CommitChanges(const wxMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
static UIHandlePtr HitTest(std::weak_ptr< SelectButtonHandle > &holder, const wxMouseState &state, const wxRect &rect, TrackPanelCell *pCell)
Track * Get()
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1533
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:227
void SetMinimized(bool minimized)
Definition: TrackView.cpp:93
bool GetMinimized() const
Definition: TrackView.h:52
static TrackView & Get(Track &)
Definition: TrackView.cpp:69
Holds a msgid for the translation catalog; may also bind format arguments.
unsigned Result
Definition: UIHandle.h:38
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16
void DoListSelection(AudacityProject &project, Track *t, bool shift, bool ctrl, bool modifyState)
AUDACITY_DLL_API void GetCloseBoxRect(const wxRect &rect, wxRect &dest)
Definition: TrackInfo.cpp:463
AUDACITY_DLL_API void GetTitleBarRect(const wxRect &rect, wxRect &dest)
Definition: TrackInfo.cpp:480
AUDACITY_DLL_API void GetMinimizeRect(const wxRect &rect, wxRect &dest)
Definition: TrackInfo.cpp:508
AUDACITY_DLL_API void GetSelectButtonRect(const wxRect &rect, wxRect &dest)
Definition: TrackInfo.cpp:534
void DoRemoveTrack(AudacityProject &project, Track *toRemove)
std::shared_ptr< Track > FindTrack(TrackPanelCell *pCell)
Definition: TrackPanel.cpp:521