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>
20 
21 class Track;
22 class XMLWriter;
23 
24 class AUDACITY_DLL_API CommonTrackPanelCell /* not final */
25  : public TrackPanelCell
26 {
27 public:
28  // Type of function to dispatch mouse wheel events
29  using Hook = std::function<
30  unsigned(const TrackPanelMouseEvent &evt, AudacityProject *pProject)
31  >;
32  // Install a dispatcher function, returning the previous function
33  static Hook InstallMouseWheelHook( const Hook &hook );
34 
36  {}
37 
38  virtual ~CommonTrackPanelCell() = 0;
39 
40  // Default to the arrow cursor
42  (const TrackPanelMouseState &, const AudacityProject *) override;
43 
44  std::shared_ptr<Track> FindTrack() { return DoFindTrack(); }
45  std::shared_ptr<const Track> FindTrack() const
46  { return const_cast<CommonTrackPanelCell*>(this)->DoFindTrack(); }
47 
48 protected:
49  virtual std::shared_ptr<Track> DoFindTrack() = 0;
50 
51  unsigned HandleWheelRotation
52  (const TrackPanelMouseEvent &event,
53  AudacityProject *pProject) override;
54 
55 };
56 
57 class AUDACITY_DLL_API CommonTrackCell /* not final */
58  : public CommonTrackPanelCell
59 {
60 public:
61  explicit CommonTrackCell( const std::shared_ptr<Track> &pTrack );
62 
64 
65  // Copy state, for undo/redo purposes
66  // The default does nothing
67  virtual void CopyTo( Track &track ) const;
68 
69  std::shared_ptr<Track> DoFindTrack() override;
70 
71  virtual void Reparent( const std::shared_ptr<Track> &parent );
72 
73  // default does nothing
74  virtual void WriteXMLAttributes( XMLWriter & ) const;
75 
76  // default recognizes no attributes, and returns false
77  virtual bool HandleXMLAttribute( const wxChar *attr, const wxChar *value );
78 
79 private:
80  std::weak_ptr< Track > mwTrack;
81 };
82 
83 #endif
XMLWriter
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:23
CommonTrackPanelCell::Hook
std::function< unsigned(const TrackPanelMouseEvent &evt, AudacityProject *pProject) > Hook
Definition: CommonTrackPanelCell.h:31
CommonTrackPanelCell::FindTrack
std::shared_ptr< Track > FindTrack()
Definition: CommonTrackPanelCell.h:44
CommonTrackPanelCell::FindTrack
std::shared_ptr< const Track > FindTrack() const
Definition: CommonTrackPanelCell.h:45
CommonTrackCell::mwTrack
std::weak_ptr< Track > mwTrack
Definition: CommonTrackPanelCell.h:80
CommonTrackCell::~CommonTrackCell
~CommonTrackCell()
TrackPanelCell
Definition: TrackPanelCell.h:74
HitTestPreview
Definition: HitTestResult.h:20
Track
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:238
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:112
CommonTrackPanelCell::CommonTrackPanelCell
CommonTrackPanelCell()
Definition: CommonTrackPanelCell.h:35
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:26
CommonTrackCell
Definition: CommonTrackPanelCell.h:59
TrackPanelCell::HandleWheelRotation
virtual unsigned HandleWheelRotation(const TrackPanelMouseEvent &event, AudacityProject *pProject)
Definition: TrackPanelCell.cpp:44