Audacity  3.0.3
TrackButtonHandles.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 TrackButtonHandles.cpp
6 
7 Paul 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?)
54  return RefreshAll | FixScrollbars;
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();
161  ProjectAudioManager::Get( *pProject ).StopIfPaused();
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)
225  return RefreshCode::Cancelled;
226  auto pTrack =
227  static_cast<CommonTrackPanelCell*>(pCell.get())->FindTrack();
228  if (!pTrack)
229  return RefreshCode::Cancelled;
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 }
ProjectHistory::ModifyState
void ModifyState(bool bWantsAutoSave)
Definition: ProjectHistory.cpp:124
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
RefreshCode::FixScrollbars
@ FixScrollbars
Definition: RefreshCode.h:27
MenuButtonHandle::~MenuButtonHandle
virtual ~MenuButtonHandle()
Definition: TrackButtonHandles.cpp:215
MenuButtonHandle::HitTest
static UIHandlePtr HitTest(std::weak_ptr< MenuButtonHandle > &holder, const wxMouseState &state, const wxRect &rect, const std::shared_ptr< TrackPanelCell > &pCell)
Definition: TrackButtonHandles.cpp:250
CloseButtonHandle::Tip
TranslatableString Tip(const wxMouseState &state, AudacityProject &project) const override
Definition: TrackButtonHandles.cpp:175
ProjectAudioManager::Get
static ProjectAudioManager & Get(AudacityProject &project)
Definition: ProjectAudioManager.cpp:55
SelectButtonHandle::CommitChanges
Result CommitChanges(const wxMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
Definition: TrackButtonHandles.cpp:96
RefreshCode::RefreshAll
@ RefreshAll
Definition: RefreshCode.h:26
TrackView::Get
static TrackView & Get(Track &)
Definition: TrackView.cpp:63
TrackView::SetMinimized
void SetMinimized(bool minimized)
Definition: TrackView.cpp:77
RefreshCode::RefreshNone
@ RefreshNone
Definition: RefreshCode.h:21
CloseButtonHandle::CommitChanges
Result CommitChanges(const wxMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
Definition: TrackButtonHandles.cpp:152
CloseButtonHandle::~CloseButtonHandle
virtual ~CloseButtonHandle()
Definition: TrackButtonHandles.cpp:147
TrackInfo::GetCloseBoxRect
AUDACITY_DLL_API void GetCloseBoxRect(const wxRect &rect, wxRect &dest)
Definition: TrackInfo.cpp:462
TrackView::GetMinimized
bool GetMinimized() const
Definition: TrackView.h:49
Project.h
ClientData::Site::Get
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
TrackList::Channels
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1484
ButtonHandle::mpTrack
std::weak_ptr< Track > mpTrack
Definition: ButtonHandle.h:72
RefreshCode::Cancelled
@ Cancelled
Definition: RefreshCode.h:23
TrackPanel::Get
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:227
XO
#define XO(s)
Definition: Internat.h:31
MinimizeButtonHandle::MinimizeButtonHandle
MinimizeButtonHandle(const MinimizeButtonHandle &)=delete
ButtonHandle::GetTrack
std::shared_ptr< Track > GetTrack() const
Definition: ButtonHandle.h:30
ProjectAudioIO::Get
static ProjectAudioIO & Get(AudacityProject &project)
Definition: ProjectAudioIO.cpp:22
ProjectAudioIO::IsAudioActive
bool IsAudioActive() const
Definition: ProjectAudioIO.cpp:51
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterfaceSymbol.h:27
TrackInfo::GetTitleBarRect
AUDACITY_DLL_API void GetTitleBarRect(const wxRect &rect, wxRect &dest)
Definition: TrackInfo.cpp:479
SelectButtonHandle::~SelectButtonHandle
virtual ~SelectButtonHandle()
Definition: TrackButtonHandles.cpp:91
SelectButtonHandle::Tip
TranslatableString Tip(const wxMouseState &state, AudacityProject &) const override
Definition: TrackButtonHandles.cpp:112
MenuButtonHandle::Tip
TranslatableString Tip(const wxMouseState &state, AudacityProject &) const override
Definition: TrackButtonHandles.cpp:235
CloseButtonHandle::HitTest
static UIHandlePtr HitTest(std::weak_ptr< CloseButtonHandle > &holder, const wxMouseState &state, const wxRect &rect, TrackPanelCell *pCell)
Definition: TrackButtonHandles.cpp:190
ButtonHandle
A UIHandle for a TrackPanel button, such as the Mute and Solo buttons.
Definition: ButtonHandle.h:26
MinimizeButtonHandle::Tip
TranslatableString Tip(const wxMouseState &state, AudacityProject &) const override
Definition: TrackButtonHandles.cpp:60
UIHandle::Result
unsigned Result
Definition: UIHandle.h:38
TrackInfo::GetSelectButtonRect
AUDACITY_DLL_API void GetSelectButtonRect(const wxRect &rect, wxRect &dest)
Definition: TrackInfo.cpp:533
SelectButtonHandle::SelectButtonHandle
SelectButtonHandle(const SelectButtonHandle &)=delete
name
const TranslatableString name
Definition: Distortion.cpp:98
UIHandlePtr
std::shared_ptr< UIHandle > UIHandlePtr
Definition: CellularPanel.h:28
MenuButtonHandle::CommitChanges
Result CommitChanges(const wxMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
Definition: TrackButtonHandles.cpp:220
RefreshCode::Resize
@ Resize
Definition: RefreshCode.h:28
TrackPanelCell
Definition: TrackPanelCell.h:74
TrackFocus::Get
Track * Get()
Definition: TrackPanelAx.cpp:755
anonymous_namespace{TrackPanel.cpp}::FindTrack
std::shared_ptr< Track > FindTrack(TrackPanelCell *pCell)
Definition: TrackPanel.cpp:530
RefreshCode::DestroyedCell
@ DestroyedCell
Definition: RefreshCode.h:34
MenuButtonHandle::MenuButtonHandle
MenuButtonHandle(const MenuButtonHandle &)=delete
MenuButtonHandle::mpCell
std::weak_ptr< TrackPanelCell > mpCell
Definition: TrackButtonHandles.h:126
SelectButtonHandle::HitTest
static UIHandlePtr HitTest(std::weak_ptr< SelectButtonHandle > &holder, const wxMouseState &state, const wxRect &rect, TrackPanelCell *pCell)
Definition: TrackButtonHandles.cpp:124
TrackUtilities::DoRemoveTrack
void DoRemoveTrack(AudacityProject &project, Track *toRemove)
Definition: TrackUtilities.cpp:163
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:92
CloseButtonHandle::CloseButtonHandle
CloseButtonHandle(const CloseButtonHandle &)=delete
TrackInfo::GetMinimizeRect
AUDACITY_DLL_API void GetMinimizeRect(const wxRect &rect, wxRect &dest)
Definition: TrackInfo.cpp:507
TrackButtonHandles.h
MinimizeButtonHandle::~MinimizeButtonHandle
virtual ~MinimizeButtonHandle()
Definition: TrackButtonHandles.cpp:33
MinimizeButtonHandle::HitTest
static UIHandlePtr HitTest(std::weak_ptr< MinimizeButtonHandle > &holder, const wxMouseState &state, const wxRect &rect, TrackPanelCell *pCell)
Definition: TrackButtonHandles.cpp:69
ProjectAudioManager::StopIfPaused
void StopIfPaused()
Definition: ProjectAudioManager.cpp:1220
AssignUIHandlePtr
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:151
SelectUtilities::DoListSelection
void DoListSelection(AudacityProject &project, Track *t, bool shift, bool ctrl, bool modifyState)
Definition: SelectUtilities.cpp:118
CommonTrackPanelCell
Definition: CommonTrackPanelCell.h:28
CommandManager::Get
static CommandManager & Get(AudacityProject &project)
Definition: CommandManager.cpp:207
RefreshCode
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16
ProjectHistory::Get
static ProjectHistory & Get(AudacityProject &project)
Definition: ProjectHistory.cpp:26
MinimizeButtonHandle::CommitChanges
Result CommitChanges(const wxMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
Definition: TrackButtonHandles.cpp:38