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 "TrackFocus.h"
22#include "CommonTrackInfo.h"
23#include "../../TrackPanel.h"
24#include "../../TrackUtilities.h"
25#include "CommandManager.h"
26#include "../../tracks/ui/ChannelView.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 if (auto pTrack = mpTrack.lock()) {
43 auto channels = pTrack->Channels();
44 bool wasMinimized = ChannelView::Get(**channels.begin()).GetMinimized();
45 for (auto pChannel : channels)
46 ChannelView::Get(*pChannel).SetMinimized( !wasMinimized );
47 ProjectHistory::Get(*pProject).ModifyState(true);
48
49 // Redraw all tracks when any one of them expands or contracts
50 // (Could we invent a return code that draws only those at or below
51 // the affected track?)
53 }
54
55 return RefreshNone;
56}
57
59 const wxMouseState &, AudacityProject &) const
60{
61 auto pTrack = GetTrack();
62 return ChannelView::Get(*pTrack->GetChannel(0)).GetMinimized()
63 ? XO("Expand") : XO("Collapse");
64}
65
67(std::weak_ptr<MinimizeButtonHandle> &holder,
68 const wxMouseState &state, const wxRect &rect, TrackPanelCell *pCell)
69{
70 wxRect buttonRect;
71 CommonTrackInfo::GetMinimizeRect(rect, buttonRect);
72
73 if (buttonRect.Contains(state.m_x, state.m_y)) {
74 auto pTrack = static_cast<CommonTrackPanelCell*>(pCell)->FindTrack();
75 auto result = std::make_shared<MinimizeButtonHandle>( pTrack, buttonRect );
76 result = AssignUIHandlePtr(holder, result);
77 return result;
78 }
79 else
80 return {};
81}
82
85( const std::shared_ptr<Track> &pTrack, const wxRect &rect )
86 : ButtonHandle{ pTrack, rect }
87{}
88
90{
91}
92
94(const wxMouseEvent &event, AudacityProject *pProject, wxWindow*)
95{
96 using namespace RefreshCode;
97
98 auto pTrack = mpTrack.lock();
99 if (pTrack)
100 {
101 const bool unsafe = ProjectAudioIO::Get( *pProject ).IsAudioActive();
103 *pTrack, event.ShiftDown(), event.ControlDown(), !unsafe);
104// return RefreshAll ;
105 }
106
107 return RefreshNone;
108}
109
111 const wxMouseState &, AudacityProject &) const
112{
113 auto pTrack = GetTrack();
114#if defined(__WXMAC__)
115 return pTrack->GetSelected() ? XO("Command+Click to deselect") : XO("Select track");
116#else
117 return pTrack->GetSelected() ? XO("Ctrl+Click to deselect") : XO("Select track");
118#endif
119}
120
122(std::weak_ptr<SelectButtonHandle> &holder,
123 const wxMouseState &state, const wxRect &rect, TrackPanelCell *pCell)
124{
125 wxRect buttonRect;
126 CommonTrackInfo::GetSelectButtonRect(rect, buttonRect);
127
128 if (buttonRect.Contains(state.m_x, state.m_y)) {
129 auto pTrack = static_cast<CommonTrackPanelCell*>(pCell)->FindTrack();
130 auto result = std::make_shared<SelectButtonHandle>( pTrack, buttonRect );
131 result = AssignUIHandlePtr(holder, result);
132 return result;
133 }
134 else
135 return {};
136}
137
139
141( const std::shared_ptr<Track> &pTrack, const wxRect &rect )
142 : ButtonHandle{ pTrack, rect }
143{}
144
146{
147}
148
150(const wxMouseEvent &, AudacityProject *pProject, wxWindow*)
151{
152 using namespace RefreshCode;
153 Result result = RefreshNone;
154
155 auto pTrack = mpTrack.lock();
156 if (pTrack)
157 {
158 auto toRemove = pTrack->SubstitutePendingChangedTrack();
160 if (!ProjectAudioIO::Get( *pProject ).IsAudioActive()) {
161 // This pushes an undo item:
162 TrackUtilities::DoRemoveTrack(*pProject, toRemove.get());
163 // Redraw all tracks when any one of them closes
164 // (Could we invent a return code that draws only those at or below
165 // the affected track?)
167 }
168 }
169
170 return result;
171}
172
174 const wxMouseState &, AudacityProject &project) const
175{
176 auto name = XO("Close");
177 auto focused =
178 TrackFocus::Get( project ).Get() == GetTrack().get();
179 if (!focused)
180 return name;
181
182 auto &commandManager = CommandManager::Get( project );
183 ComponentInterfaceSymbol command{ wxT("TrackClose"), name };
184 return commandManager.DescribeCommandsAndShortcuts( &command, 1u );
185}
186
188(std::weak_ptr<CloseButtonHandle> &holder,
189 const wxMouseState &state, const wxRect &rect, TrackPanelCell *pCell)
190{
191 wxRect buttonRect;
192 CommonTrackInfo::GetCloseBoxRect(rect, buttonRect);
193
194 if (buttonRect.Contains(state.m_x, state.m_y)) {
195 auto pTrack = static_cast<CommonTrackPanelCell*>(pCell)->FindTrack();
196 auto result = std::make_shared<CloseButtonHandle>( pTrack, buttonRect );
197 result = AssignUIHandlePtr(holder, result);
198 return result;
199 }
200 else
201 return {};
202}
203
205
207( const std::shared_ptr<TrackPanelCell> &pCell,
208 const std::shared_ptr<Track> &pTrack, const wxRect &rect )
209 : ButtonHandle{ pTrack, rect }
210 , mpCell{ pCell }
211{}
212
214{
215}
216
218(const wxMouseEvent &, AudacityProject *pProject, wxWindow *WXUNUSED(pParent))
219{
220 auto &trackPanel = TrackPanel::Get( *pProject );
221 auto pCell = mpCell.lock();
222 if (!pCell)
224 auto pTrack =
225 static_cast<CommonTrackPanelCell*>(pCell.get())->FindTrack();
226 if (!pTrack)
228 trackPanel.CallAfter(
229 [&trackPanel,pTrack]{ trackPanel.OnTrackMenu( pTrack.get() ); } );
231}
232
234 const wxMouseState &, AudacityProject &project) const
235{
236 auto name = XO("Open menu...");
237 auto focused =
238 TrackFocus::Get( project ).Get() == GetTrack().get();
239 if (!focused)
240 return name;
241
242 auto &commandManager = CommandManager::Get( project );
243 ComponentInterfaceSymbol command{ wxT("TrackMenu"), name };
244 return commandManager.DescribeCommandsAndShortcuts( &command, 1u );
245}
246
248(std::weak_ptr<MenuButtonHandle> &holder,
249 const wxMouseState &state, const wxRect &rect,
250 const std::shared_ptr<TrackPanelCell> &pCell)
251{
252 wxRect buttonRect;
253 CommonTrackInfo::GetTitleBarRect(rect, buttonRect);
254
255 if (buttonRect.Contains(state.m_x, state.m_y)) {
256 auto pTrack = static_cast<CommonTrackPanelCell*>(pCell.get())->FindTrack();
257 auto result = std::make_shared<MenuButtonHandle>( pCell, pTrack, buttonRect );
258 result = AssignUIHandlePtr(holder, result);
259 return result;
260 }
261 else
262 return {};
263}
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:159
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
static ChannelView & Get(Channel &channel)
bool GetMinimized() const
Definition: ChannelView.h:68
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:317
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()
Definition: TrackFocus.cpp:156
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:233
Holds a msgid for the translation catalog; may also bind format arguments.
unsigned Result
Definition: UIHandle.h:39
AUDACITY_DLL_API void GetCloseBoxRect(const wxRect &rect, wxRect &dest)
AUDACITY_DLL_API void GetSelectButtonRect(const wxRect &rect, wxRect &dest)
AUDACITY_DLL_API void GetMinimizeRect(const wxRect &rect, wxRect &dest)
AUDACITY_DLL_API void GetTitleBarRect(const wxRect &rect, wxRect &dest)
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)
void DoRemoveTrack(AudacityProject &project, Track *toRemove)
std::shared_ptr< Track > FindTrack(TrackPanelCell *pCell)
Definition: TrackPanel.cpp:537