Audacity  3.0.3
CommonTrackPanelCell.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 CommonTrackPanelCell.h
6 
7 Paul Licameli split from TrackPanel.cpp
8 
9 **********************************************************************/
10 
11 #ifndef __AUDACITY_COMMON_TRACK_PANEL_CELL__
12 #define __AUDACITY_COMMON_TRACK_PANEL_CELL__
13 
14 
15 #include "../../TrackPanelCell.h"
16 
17 #include <stdlib.h>
18 #include <memory>
19 #include <functional>
21 
22 class CommandContext;
23 class Track;
24 class XMLWriter;
25 
26 class AUDACITY_DLL_API CommonTrackPanelCell /* not final */
27  : public TrackPanelCell
28 {
29 public:
30  // Type of function to dispatch mouse wheel events
31  using Hook = std::function<
32  unsigned(const TrackPanelMouseEvent &evt, AudacityProject *pProject)
33  >;
34  // Install a dispatcher function, returning the previous function
35  static Hook InstallMouseWheelHook( const Hook &hook );
36 
38  {}
39 
40  virtual ~CommonTrackPanelCell() = 0;
41 
42  // Default to the arrow cursor
44  (const TrackPanelMouseState &, const AudacityProject *) override;
45 
46  std::shared_ptr<Track> FindTrack() { return DoFindTrack(); }
47  std::shared_ptr<const Track> FindTrack() const
48  { return const_cast<CommonTrackPanelCell*>(this)->DoFindTrack(); }
49 
50  struct MenuItem {
51  using Action = std::function< void(const CommandContext &) >;
52 
53  MenuItem() = default;
54  MenuItem( const Identifier &internal, const TranslatableString &msgid,
55  Action action = {}, bool enabled = true )
56  : symbol{ internal, msgid }, action{ move(action) }, enabled{ enabled }
57  {}
58 
61  bool enabled;
62  };
63 
65 
80  virtual std::vector<MenuItem> GetMenuItems(
81  const wxRect &rect, const wxPoint *pPosition, AudacityProject *pProject );
82 
83 protected:
84  virtual std::shared_ptr<Track> DoFindTrack() = 0;
85 
86  unsigned DoContextMenu(
87  const wxRect &rect,
88  wxWindow *pParent, const wxPoint *pPosition, AudacityProject *pProject)
89  override;
90 
91  unsigned HandleWheelRotation
92  (const TrackPanelMouseEvent &event,
93  AudacityProject *pProject) override;
94 
95 };
96 
97 class AUDACITY_DLL_API CommonTrackCell /* not final */
98  : public CommonTrackPanelCell
99 {
100 public:
101  explicit CommonTrackCell( const std::shared_ptr<Track> &pTrack );
102 
104 
105  // Copy state, for undo/redo purposes
106  // The default does nothing
107  virtual void CopyTo( Track &track ) const;
108 
109  std::shared_ptr<Track> DoFindTrack() override;
110 
111  virtual void Reparent( const std::shared_ptr<Track> &parent );
112 
113  // default does nothing
114  virtual void WriteXMLAttributes( XMLWriter & ) const;
115 
116  // default recognizes no attributes, and returns false
117  virtual bool HandleXMLAttribute( const wxChar *attr, const wxChar *value );
118 
119 private:
120  std::weak_ptr< Track > mwTrack;
121 };
122 
123 #endif
XMLWriter
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:23
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
CommonTrackPanelCell::MenuItem::symbol
ComponentInterfaceSymbol symbol
Definition: CommonTrackPanelCell.h:59
CommonTrackPanelCell::Hook
std::function< unsigned(const TrackPanelMouseEvent &evt, AudacityProject *pProject) > Hook
Definition: CommonTrackPanelCell.h:33
CommonTrackPanelCell::FindTrack
std::shared_ptr< Track > FindTrack()
Definition: CommonTrackPanelCell.h:46
TrackPanelCell::DoContextMenu
virtual unsigned DoContextMenu(const wxRect &rect, wxWindow *pParent, const wxPoint *pPosition, AudacityProject *pProject)
Definition: TrackPanelCell.cpp:50
CommonTrackPanelCell::FindTrack
std::shared_ptr< const Track > FindTrack() const
Definition: CommonTrackPanelCell.h:47
CommonTrackPanelCell::MenuItem::action
Action action
Definition: CommonTrackPanelCell.h:60
ComponentInterfaceSymbol.h
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterfaceSymbol.h:27
CommonTrackPanelCell::MenuItem
Definition: CommonTrackPanelCell.h:50
Identifier
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
CommonTrackCell::mwTrack
std::weak_ptr< Track > mwTrack
Definition: CommonTrackPanelCell.h:120
CommandContext
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
Definition: CommandContext.h:34
CommonTrackPanelCell::MenuItem::MenuItem
MenuItem(const Identifier &internal, const TranslatableString &msgid, Action action={}, bool enabled=true)
Definition: CommonTrackPanelCell.h:54
CommonTrackCell::~CommonTrackCell
~CommonTrackCell()
CommonTrackPanelCell::MenuItem::Action
std::function< void(const CommandContext &) > Action
Definition: CommonTrackPanelCell.h:51
TrackPanelCell
Definition: TrackPanelCell.h:74
HitTestPreview
Definition: HitTestResult.h:20
CommonTrackPanelCell::MenuItem::MenuItem
MenuItem()=default
Track
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:239
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:92
CommonTrackPanelCell::CommonTrackPanelCell
CommonTrackPanelCell()
Definition: CommonTrackPanelCell.h:37
TrackPanelMouseEvent
Definition: TrackPanelMouseEvent.h:46
TrackPanelMouseState
Definition: TrackPanelMouseEvent.h:28
CommonTrackPanelCell::DoFindTrack
virtual std::shared_ptr< Track > DoFindTrack()=0
TrackPanelCell::DefaultPreview
virtual HitTestPreview DefaultPreview(const TrackPanelMouseState &state, const AudacityProject *pProject)
Definition: TrackPanelCell.cpp:38
CommonTrackPanelCell
Definition: CommonTrackPanelCell.h:28
CommonTrackCell
Definition: CommonTrackPanelCell.h:99
TrackPanelCell::HandleWheelRotation
virtual unsigned HandleWheelRotation(const TrackPanelMouseEvent &event, AudacityProject *pProject)
Definition: TrackPanelCell.cpp:44
CommonTrackPanelCell::MenuItem::enabled
bool enabled
Definition: CommonTrackPanelCell.h:61