Audacity  2.2.2
ButtonHandle.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 ButtonHandle.cpp
6 
7 Paul Licameli
8 
9 **********************************************************************/
10 
11 #include "../../Audacity.h"
12 #include "ButtonHandle.h"
13 
14 #include "../../MemoryX.h"
15 
16 #include "../../HitTestResult.h"
17 #include "../../Project.h"
18 #include "../../RefreshCode.h"
19 #include "../../Track.h"
20 #include "../../TrackPanelMouseEvent.h"
21 #include "../ui/TrackControls.h"
22 
24 ( const std::shared_ptr<Track> &pTrack, const wxRect &rect )
25  : mpTrack{ pTrack }
26  , mRect{ rect }
27 {
28 }
29 
31 {
32 }
33 
35 {
37 }
38 
40 (const TrackPanelMouseEvent &evt, AudacityProject *pProject)
41 {
42  using namespace RefreshCode;
43  auto pTrack = pProject->GetTracks()->Lock(mpTrack);
44  if ( !pTrack )
45  return Cancelled;
46 
47  const wxMouseEvent &event = evt.event;
48  if (!event.Button(wxMOUSE_BTN_LEFT))
49  return Cancelled;
50 
51  // Come here for left click or double click
52  if (mRect.Contains(event.m_x, event.m_y)) {
53  mWasIn = true;
54  mIsClicked = true;
55  // Toggle visible button state
56  return RefreshCell;
57  }
58  else
59  return Cancelled;
60 }
61 
63 (const TrackPanelMouseEvent &evt, AudacityProject *pProject)
64 {
65  const wxMouseEvent &event = evt.event;
66  using namespace RefreshCode;
67  auto pTrack = pProject->GetTracks()->Lock(mpTrack);
68  if (!pTrack)
69  return Cancelled;
70 
71  auto isIn = mRect.Contains(event.m_x, event.m_y);
72  auto result = (isIn == mWasIn) ? RefreshNone : RefreshCell;
73  mWasIn = isIn;
74  return result;
75 }
76 
79 {
80  // No special cursor
81  auto message = Tip(st.state);
82  return { message, {}, message };
83 }
84 
86 (const TrackPanelMouseEvent &evt, AudacityProject *pProject,
87  wxWindow *pParent)
88 {
89  using namespace RefreshCode;
90  auto pTrack = pProject->GetTracks()->Lock(mpTrack);
91  if (!pTrack)
92  return Cancelled;
93 
94  Result result = RefreshNone;
95  const wxMouseEvent &event = evt.event;
96  if (pTrack && mRect.Contains(event.m_x, event.m_y))
97  result |= RefreshCell | CommitChanges(event, pProject, pParent);
98  return result;
99 }
100 
102 {
103  using namespace RefreshCode;
104  return RefreshCell; // perhaps unnecessarily if pointer is out of the box
105 }
Result Click(const TrackPanelMouseEvent &event, AudacityProject *pProject) finaloverride
Result Release(const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) finaloverride
ButtonHandle(const ButtonHandle &)=delete
Result mChangeHighlight
Definition: UIHandle.h:150
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
unsigned Result
Definition: UIHandle.h:37
Result Drag(const TrackPanelMouseEvent &event, AudacityProject *pProject) finaloverride
Result Cancel(AudacityProject *pProject) finaloverride
std::shared_ptr< Subclass > Lock(const std::weak_ptr< Subclass > &wTrack)
Definition: Track.h:733
void Enter(bool forward) finaloverride
virtual ~ButtonHandle()
HitTestPreview Preview(const TrackPanelMouseState &state, const AudacityProject *pProject) finaloverride
TrackList * GetTracks()
Definition: Project.h:192