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();
119  { name, wxT("TrackClose") } );
120  return commandManager->DescribeCommandsAndShortcuts(commands);
121 }
122 
124 (std::weak_ptr<CloseButtonHandle> &holder,
125  const wxMouseState &state, const wxRect &rect, TrackPanelCell *pCell)
126 {
127  wxRect buttonRect;
128  TrackInfo::GetCloseBoxRect(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<CloseButtonHandle>( pTrack, buttonRect );
133  result = AssignUIHandlePtr(holder, result);
134  return result;
135  }
136  else
137  return {};
138 }
139 
141 
143 ( const std::shared_ptr<TrackPanelCell> &pCell,
144  const std::shared_ptr<Track> &pTrack, const wxRect &rect )
145  : ButtonHandle{ pTrack, rect }
146  , mpCell{ pCell }
147 {}
148 
150 {
151 }
152 
154 (const wxMouseEvent &, AudacityProject *pProject, wxWindow *WXUNUSED(pParent))
155 {
156  auto pPanel = pProject->GetTrackPanel();
157  auto pCell = mpCell.lock();
158  if (!pCell)
159  return RefreshCode::Cancelled;
160  auto pTrack =
161  static_cast<CommonTrackPanelCell*>(pCell.get())->FindTrack();
162  if (!pTrack)
163  return RefreshCode::Cancelled;
164  pPanel->CallAfter( [=]{ pPanel->OnTrackMenu( pTrack.get() ); } );
166 }
167 
168 wxString MenuButtonHandle::Tip(const wxMouseState &) const
169 {
170  auto name = _("Open menu...");
171  auto project = ::GetActiveProject();
172  auto focused =
173  project->GetTrackPanel()->GetFocusedTrack() == GetTrack().get();
174  if (!focused)
175  return name;
176 
177  auto commandManager = project->GetCommandManager();
179  { name, wxT("TrackMenu") } );
180  return commandManager->DescribeCommandsAndShortcuts(commands);
181 }
182 
184 (std::weak_ptr<MenuButtonHandle> &holder,
185  const wxMouseState &state, const wxRect &rect,
186  const std::shared_ptr<TrackPanelCell> &pCell)
187 {
188  wxRect buttonRect;
189  TrackInfo::GetTitleBarRect(rect, buttonRect);
190 
191  if (buttonRect.Contains(state.m_x, state.m_y)) {
192  auto pTrack = static_cast<CommonTrackPanelCell*>(pCell.get())->FindTrack();
193  auto result = std::make_shared<MenuButtonHandle>( pCell, pTrack, buttonRect );
194  result = AssignUIHandlePtr(holder, result);
195  return result;
196  }
197  else
198  return {};
199 }
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:158
unsigned Result
Definition: UIHandle.h:37
std::vector< LocalizedCommandName > LocalizedCommandNameVector
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:1423
void ModifyState(bool bWantsAutoSave)
Definition: Project.cpp:4547
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)
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
void RemoveTrack(Track *toRemove)
Removes the specified track. Called from HandleClosing.
Definition: Project.cpp:5560
const wxChar * name
Definition: Distortion.cpp:94
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:300
void StopIfPaused()
Definition: Menus.cpp:2209
TrackPanel * GetTrackPanel()
Definition: Project.h:289
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:162
MenuButtonHandle(const MenuButtonHandle &)=delete