Audacity  2.2.2
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 #include "../../Audacity.h"
12 #include "TrackButtonHandles.h"
13 
14 #include "../../HitTestResult.h"
15 #include "../../Project.h"
16 #include "../../RefreshCode.h"
17 #include "../../Track.h"
18 #include "../../TrackPanel.h"
19 
21 ( const std::shared_ptr<Track> &pTrack, const wxRect &rect )
22  : ButtonHandle{ pTrack, rect }
23 {}
24 
26 {
27 }
28 
30 (const wxMouseEvent &, AudacityProject *pProject, wxWindow*)
31 {
32  using namespace RefreshCode;
33 
34  auto pTrack = mpTrack.lock();
35  if (pTrack)
36  {
37  pTrack->SetMinimized(!pTrack->GetMinimized());
38  if (pTrack->GetLink())
39  pTrack->GetLink()->SetMinimized(pTrack->GetMinimized());
40  pProject->ModifyState(true);
41 
42  // Redraw all tracks when any one of them expands or contracts
43  // (Could we invent a return code that draws only those at or below
44  // the affected track?)
45  return RefreshAll | FixScrollbars;
46  }
47 
48  return RefreshNone;
49 }
50 
51 wxString MinimizeButtonHandle::Tip(const wxMouseState &) const
52 {
53  auto pTrack = GetTrack();
54  return pTrack->GetMinimized() ? _("Expand") : _("Collapse");
55 }
56 
58 (std::weak_ptr<MinimizeButtonHandle> &holder,
59  const wxMouseState &state, const wxRect &rect, TrackPanelCell *pCell)
60 {
61  wxRect buttonRect;
62  TrackInfo::GetMinimizeRect(rect, buttonRect);
63 
64  if (buttonRect.Contains(state.m_x, state.m_y)) {
65  auto pTrack = static_cast<CommonTrackPanelCell*>(pCell)->FindTrack();
66  auto result = std::make_shared<MinimizeButtonHandle>( pTrack, buttonRect );
67  result = AssignUIHandlePtr(holder, result);
68  return result;
69  }
70  else
71  return {};
72 }
73 
75 
77 ( const std::shared_ptr<Track> &pTrack, const wxRect &rect )
78  : ButtonHandle{ pTrack, rect }
79 {}
80 
82 {
83 }
84 
86 (const wxMouseEvent &, AudacityProject *pProject, wxWindow*)
87 {
88  using namespace RefreshCode;
89  Result result = RefreshNone;
90 
91  auto pTrack = mpTrack.lock();
92  if (pTrack)
93  {
94  pProject->StopIfPaused();
95  if (!pProject->IsAudioActive()) {
96  // This pushes an undo item:
97  pProject->RemoveTrack(pTrack.get());
98  // Redraw all tracks when any one of them closes
99  // (Could we invent a return code that draws only those at or below
100  // the affected track?)
102  }
103  }
104 
105  return result;
106 }
107 
108 wxString CloseButtonHandle::Tip(const wxMouseState &) const
109 {
110  auto name = _("Close");
111  auto project = ::GetActiveProject();
112  auto focused =
113  project->GetTrackPanel()->GetFocusedTrack() == GetTrack().get();
114  if (!focused)
115  return name;
116 
117  auto commandManager = project->GetCommandManager();
118  TranslatedInternalString command{ wxT("TrackClose"), name };
119  return commandManager->DescribeCommandsAndShortcuts( &command, 1u );
120 }
121 
123 (std::weak_ptr<CloseButtonHandle> &holder,
124  const wxMouseState &state, const wxRect &rect, TrackPanelCell *pCell)
125 {
126  wxRect buttonRect;
127  TrackInfo::GetCloseBoxRect(rect, buttonRect);
128 
129  if (buttonRect.Contains(state.m_x, state.m_y)) {
130  auto pTrack = static_cast<CommonTrackPanelCell*>(pCell)->FindTrack();
131  auto result = std::make_shared<CloseButtonHandle>( pTrack, buttonRect );
132  result = AssignUIHandlePtr(holder, result);
133  return result;
134  }
135  else
136  return {};
137 }
138 
140 
142 ( const std::shared_ptr<TrackPanelCell> &pCell,
143  const std::shared_ptr<Track> &pTrack, const wxRect &rect )
144  : ButtonHandle{ pTrack, rect }
145  , mpCell{ pCell }
146 {}
147 
149 {
150 }
151 
153 (const wxMouseEvent &, AudacityProject *pProject, wxWindow *WXUNUSED(pParent))
154 {
155  auto pPanel = pProject->GetTrackPanel();
156  auto pCell = mpCell.lock();
157  if (!pCell)
158  return RefreshCode::Cancelled;
159  auto pTrack =
160  static_cast<CommonTrackPanelCell*>(pCell.get())->FindTrack();
161  if (!pTrack)
162  return RefreshCode::Cancelled;
163  pPanel->CallAfter( [=]{ pPanel->OnTrackMenu( pTrack.get() ); } );
165 }
166 
167 wxString MenuButtonHandle::Tip(const wxMouseState &) const
168 {
169  auto name = _("Open menu...");
170  auto project = ::GetActiveProject();
171  auto focused =
172  project->GetTrackPanel()->GetFocusedTrack() == GetTrack().get();
173  if (!focused)
174  return name;
175 
176  auto commandManager = project->GetCommandManager();
177  TranslatedInternalString command{ wxT("TrackMenu"), name };
178  return commandManager->DescribeCommandsAndShortcuts( &command, 1u );
179 }
180 
182 (std::weak_ptr<MenuButtonHandle> &holder,
183  const wxMouseState &state, const wxRect &rect,
184  const std::shared_ptr<TrackPanelCell> &pCell)
185 {
186  wxRect buttonRect;
187  TrackInfo::GetTitleBarRect(rect, buttonRect);
188 
189  if (buttonRect.Contains(state.m_x, state.m_y)) {
190  auto pTrack = static_cast<CommonTrackPanelCell*>(pCell.get())->FindTrack();
191  auto result = std::make_shared<MenuButtonHandle>( pCell, pTrack, buttonRect );
192  result = AssignUIHandlePtr(holder, result);
193  return result;
194  }
195  else
196  return {};
197 }
Result CommitChanges(const wxMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
CloseButtonHandle(const CloseButtonHandle &)=delete
wxString Tip(const wxMouseState &state) const override
Result CommitChanges(const wxMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
static void GetCloseBoxRect(const wxRect &rect, wxRect &dest)
static UIHandlePtr HitTest(std::weak_ptr< MenuButtonHandle > &holder, const wxMouseState &state, const wxRect &rect, const std::shared_ptr< TrackPanelCell > &pCell)
Result CommitChanges(const wxMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
std::shared_ptr< Track > GetTrack() const
Definition: ButtonHandle.h:28
MinimizeButtonHandle(const MinimizeButtonHandle &)=delete
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
unsigned Result
Definition: UIHandle.h:37
wxString Tip(const wxMouseState &state) const override
static UIHandlePtr HitTest(std::weak_ptr< CloseButtonHandle > &holder, const wxMouseState &state, const wxRect &rect, TrackPanelCell *pCell)
wxString Tip(const wxMouseState &state) const override
bool IsAudioActive() const
Definition: Project.cpp:1447
void ModifyState(bool bWantsAutoSave)
Definition: Project.cpp:4740
std::shared_ptr< UIHandle > UIHandlePtr
Definition: TrackPanel.h:59
static void GetMinimizeRect(const wxRect &rect, wxRect &dest)
static UIHandlePtr HitTest(std::weak_ptr< MinimizeButtonHandle > &holder, const wxMouseState &state, const wxRect &rect, TrackPanelCell *pCell)
static void GetTitleBarRect(const wxRect &rect, wxRect &dest)
void RemoveTrack(Track *toRemove)
Removes the specified track. Called from HandleClosing.
Definition: Project.cpp:5734
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
const wxChar * name
Definition: Distortion.cpp:94
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
void StopIfPaused()
Definition: Menus.cpp:2349
TrackPanel * GetTrackPanel()
Definition: Project.h:307
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:162
MenuButtonHandle(const MenuButtonHandle &)=delete