Audacity 3.2.0
CommonTrackPanelCell.h
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5CommonTrackPanelCell.h
6
7Paul Licameli split from TrackPanel.cpp
8
9**********************************************************************/
10
11#ifndef __AUDACITY_COMMON_TRACK_PANEL_CELL__
12#define __AUDACITY_COMMON_TRACK_PANEL_CELL__
13
14#include "TrackPanelCell.h"
15#include "ChannelAttachments.h" // to inherit
16
17#include <stdlib.h>
18#include <memory>
19#include <functional>
20#include <type_traits>
22#include "GlobalVariable.h"
23
24#include "XMLTagHandler.h"
25
26class Channel;
27class ChannelGroup;
28class CommandContext;
29class Track;
30class XMLWriter;
31
32class AUDACITY_DLL_API CommonTrackPanelCell /* not final */
33 : public TrackPanelCell
34{
35public:
36 // Function to dispatch mouse wheel events
37 struct AUDACITY_DLL_API MouseWheelHook : GlobalHook<MouseWheelHook,
38 unsigned(const TrackPanelMouseEvent &evt, AudacityProject *pProject)
39 >{};
40
42 {}
43
44 virtual ~CommonTrackPanelCell() = 0;
45
46 // Default to the arrow cursor
48 (const TrackPanelMouseState &, const AudacityProject *) override;
49
50 std::shared_ptr<Track> FindTrack() { return DoFindTrack(); }
51 std::shared_ptr<const Track> FindTrack() const
52 { return const_cast<CommonTrackPanelCell*>(this)->DoFindTrack(); }
53
54 struct MenuItem {
55 using Action = std::function< void(const CommandContext &) >;
56
57 MenuItem() = default;
59 Action action = {}, bool enabled = true )
60 : symbol{ internal, msgid }, action{ move(action) }, enabled{ enabled }
61 {}
62
65 bool enabled;
66 };
67
69
84 virtual std::vector<MenuItem> GetMenuItems(
85 const wxRect &rect, const wxPoint *pPosition, AudacityProject *pProject );
86
87protected:
88 virtual std::shared_ptr<Track> DoFindTrack() = 0;
89
90 unsigned DoContextMenu(
91 const wxRect &rect,
92 wxWindow *pParent, const wxPoint *pPosition, AudacityProject *pProject)
93 override;
94
95 unsigned HandleWheelRotation
96 (const TrackPanelMouseEvent &event,
97 AudacityProject *pProject) override;
98
99};
100
101class AUDACITY_DLL_API CommonTrackCell /* not final */
103{
104public:
106 CommonTrackCell(const std::shared_ptr<Track> &pTrack);
107
109
110 std::shared_ptr<Track> DoFindTrack() override;
111
112 void Reparent(const std::shared_ptr<Track> &parent) override;
113
114private:
115 std::weak_ptr<Track> mwTrack;
116};
117
118class AUDACITY_DLL_API CommonChannelCell /* not final */
120{
121public:
123 CommonChannelCell(const std::shared_ptr<Channel> &pChannel);
124
126
127 std::shared_ptr<Track> DoFindTrack() override;
128
129 void Reparent(const std::shared_ptr<Track> &parent, size_t iChannel)
130 override;
131
133 template<typename Subtype = Channel>
135 -> std::shared_ptr<Subtype>
136 { return std::dynamic_pointer_cast<Subtype>(DoFindChannel()); }
137
139 template<typename Subtype = const Channel>
140 auto FindChannel() const
141 -> std::enable_if_t<std::is_const_v<Subtype>,
142 std::shared_ptr<Subtype>
143 >
144 { return std::dynamic_pointer_cast<Subtype>(DoFindChannel()); }
145
146private:
147 std::shared_ptr<Channel> DoFindChannel();
148 std::shared_ptr<const Channel> DoFindChannel() const;
149
150 std::weak_ptr<Channel> mwChannel;
151};
152
153#endif
Adapts TrackAttachment interface with extra channel index argument.
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
auto FindChannel() const -> std::enable_if_t< std::is_const_v< Subtype >, std::shared_ptr< Subtype > >
May return null.
auto FindChannel() -> std::shared_ptr< Subtype >
May return null.
std::weak_ptr< Channel > mwChannel
std::weak_ptr< Track > mwTrack
std::shared_ptr< Track > FindTrack()
std::shared_ptr< const Track > FindTrack() const
virtual std::shared_ptr< Track > DoFindTrack()=0
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Global function-valued variable, adding a convenient Call()
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:110
virtual unsigned DoContextMenu(const wxRect &rect, wxWindow *pParent, const wxPoint *pPosition, AudacityProject *pProject)
virtual HitTestPreview DefaultPreview(const TrackPanelMouseState &state, const AudacityProject *pProject)
virtual unsigned HandleWheelRotation(const TrackPanelMouseEvent &event, AudacityProject *pProject)
Holds a msgid for the translation catalog; may also bind format arguments.
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:25
STL namespace.
MenuItem(const Identifier &internal, const TranslatableString &msgid, Action action={}, bool enabled=true)
std::function< void(const CommandContext &) > Action
ComponentInterfaceSymbol symbol