Audacity 3.2.0
ButtonHandle.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5ButtonHandle.cpp
6
7Paul Licameli
8
9**********************************************************************/
10
11
12#include "ButtonHandle.h"
13
14#include "../../HitTestResult.h"
15#include "../../RefreshCode.h"
16#include "Track.h"
17#include "../../TrackPanelMouseEvent.h"
18
19#include <wx/event.h>
20
22( const std::shared_ptr<Track> &pTrack, const wxRect &rect )
23 : mpTrack{ pTrack }
24 , mRect{ rect }
25{
26}
27
29{
30}
31
32std::shared_ptr<const Track> ButtonHandle::FindTrack() const
33{
34 return mpTrack.lock();
35}
36
38{
39 return mIsDragging;
40}
41
43{
45}
46
48(const TrackPanelMouseEvent &evt, AudacityProject *pProject)
49{
50 using namespace RefreshCode;
51 auto pTrack = TrackList::Get( *pProject ).Lock(mpTrack);
52 if ( !pTrack )
53 return Cancelled;
54
55 const wxMouseEvent &event = evt.event;
56 if (!event.Button(wxMOUSE_BTN_LEFT))
57 return Cancelled;
58
59 // Come here for left click or double click
60 if (mRect.Contains(event.m_x, event.m_y)) {
61 mWasIn = true;
62 mIsDragging = true;
63 // Toggle visible button state
64 return RefreshCell;
65 }
66 else
67 return Cancelled;
68}
69
71(const TrackPanelMouseEvent &evt, AudacityProject *pProject)
72{
73 const wxMouseEvent &event = evt.event;
74 using namespace RefreshCode;
75 auto pTrack = TrackList::Get( *pProject ).Lock(mpTrack);
76 if (!pTrack)
77 return Cancelled;
78
79 auto isIn = mRect.Contains(event.m_x, event.m_y);
80 auto result = (isIn == mWasIn) ? RefreshNone : RefreshCell;
81 mWasIn = isIn;
82 return result;
83}
84
87{
88 // No special cursor
89 TranslatableString message;
90 if (project)
91 message = Tip(st.state, *project);
92 return { message, {}, message };
93}
94
96(const TrackPanelMouseEvent &evt, AudacityProject *pProject,
97 wxWindow *pParent)
98{
99 using namespace RefreshCode;
100 auto pTrack = TrackList::Get( *pProject ).Lock(mpTrack);
101 if (!pTrack)
102 return Cancelled;
103
104 Result result = RefreshNone;
105 const wxMouseEvent &event = evt.event;
106 if (pTrack && mRect.Contains(event.m_x, event.m_y))
107 result |= RefreshCell | CommitChanges(event, pProject, pParent);
108 return result;
109}
110
112{
113 using namespace RefreshCode;
114 return RefreshCell; // perhaps unnecessarily if pointer is out of the box
115}
const auto project
declares abstract base class Track, TrackList, and iterators over TrackList
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
std::weak_ptr< Track > mpTrack
Definition: ButtonHandle.h:74
Result Click(const TrackPanelMouseEvent &event, AudacityProject *pProject) final override
Result Release(const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) final override
ButtonHandle(const ButtonHandle &)=delete
virtual ~ButtonHandle()
virtual Result CommitChanges(const wxMouseEvent &event, AudacityProject *pProject, wxWindow *pParent)=0
Result Drag(const TrackPanelMouseEvent &event, AudacityProject *pProject) final override
virtual TranslatableString Tip(const wxMouseState &state, AudacityProject &project) const =0
wxRect mRect
Definition: ButtonHandle.h:75
bool mIsDragging
Definition: ButtonHandle.h:77
Result Cancel(AudacityProject *pProject) final override
std::shared_ptr< const Track > FindTrack() const override
HitTestPreview Preview(const TrackPanelMouseState &state, AudacityProject *pProject) final override
void Enter(bool forward, AudacityProject *) final override
bool IsDragging() const override
std::shared_ptr< Subclass > Lock(const std::weak_ptr< Subclass > &wTrack)
Definition: Track.h:1079
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
Holds a msgid for the translation catalog; may also bind format arguments.
Result mChangeHighlight
Definition: UIHandle.h:152
unsigned Result
Definition: UIHandle.h:40
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16