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
33{
35}
36
38(const TrackPanelMouseEvent &evt, AudacityProject *pProject)
39{
40 using namespace RefreshCode;
41 auto pTrack = TrackList::Get( *pProject ).Lock(mpTrack);
42 if ( !pTrack )
43 return Cancelled;
44
45 const wxMouseEvent &event = evt.event;
46 if (!event.Button(wxMOUSE_BTN_LEFT))
47 return Cancelled;
48
49 // Come here for left click or double click
50 if (mRect.Contains(event.m_x, event.m_y)) {
51 mWasIn = true;
52 mIsClicked = true;
53 // Toggle visible button state
54 return RefreshCell;
55 }
56 else
57 return Cancelled;
58}
59
61(const TrackPanelMouseEvent &evt, AudacityProject *pProject)
62{
63 const wxMouseEvent &event = evt.event;
64 using namespace RefreshCode;
65 auto pTrack = TrackList::Get( *pProject ).Lock(mpTrack);
66 if (!pTrack)
67 return Cancelled;
68
69 auto isIn = mRect.Contains(event.m_x, event.m_y);
70 auto result = (isIn == mWasIn) ? RefreshNone : RefreshCell;
71 mWasIn = isIn;
72 return result;
73}
74
76(const TrackPanelMouseState &st, AudacityProject *project)
77{
78 // No special cursor
79 TranslatableString message;
80 if (project)
81 message = Tip(st.state, *project);
82 return { message, {}, message };
83}
84
86(const TrackPanelMouseEvent &evt, AudacityProject *pProject,
87 wxWindow *pParent)
88{
89 using namespace RefreshCode;
90 auto pTrack = TrackList::Get( *pProject ).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}
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:72
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:73
Result Cancel(AudacityProject *pProject) final override
HitTestPreview Preview(const TrackPanelMouseState &state, AudacityProject *pProject) final override
void Enter(bool forward, AudacityProject *) final override
std::shared_ptr< Subclass > Lock(const std::weak_ptr< Subclass > &wTrack)
Definition: Track.h:1603
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:486
Holds a msgid for the translation catalog; may also bind format arguments.
Result mChangeHighlight
Definition: UIHandle.h:139
unsigned Result
Definition: UIHandle.h:38
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16