Audacity  3.0.3
CellularPanel.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  CellularPanel.h
6 
7  Paul Licameli
8 
9  **********************************************************************/
10 
11 #ifndef __AUDACITY_CELLULAR_PANEL__
12 #define __AUDACITY_CELLULAR_PANEL__
13 
14 #include "widgets/OverlayPanel.h" // to inherit
15 
16 class ViewInfo;
17 class AudacityProject;
18 
19 class TrackPanelCell;
21 class TrackPanelGroup;
22 class TrackPanelNode;
25 class TranslatableString;
26 
27 class UIHandle;
28 using UIHandlePtr = std::shared_ptr<UIHandle>;
29 
30 // This class manages a panel divided into a number of sub-rectangles called
31 // cells, that each implement hit tests returning click-drag-release handler
32 // objects, and other services.
33 // It has no dependency on the Track class.
34 class AUDACITY_DLL_API CellularPanel : public OverlayPanel {
35 public:
36  CellularPanel(wxWindow * parent, wxWindowID id,
37  const wxPoint & pos,
38  const wxSize & size,
39  ViewInfo *viewInfo,
40  // default as for wxPanel:
41  long style = wxTAB_TRAVERSAL | wxNO_BORDER);
42  ~CellularPanel() override;
43 
44  // Overridables:
45 
46  virtual AudacityProject *GetProject() const = 0;
47 
48  // Get the root object defining a recursive subdivision of the panel's
49  // area into cells
50  virtual std::shared_ptr<TrackPanelNode> Root() = 0;
51 
53  virtual void SetFocusedCell() = 0;
54 
55  virtual void ProcessUIHandleResult
56  (TrackPanelCell *pClickedCell, TrackPanelCell *pLatestCell,
57  unsigned refreshResult) = 0;
58 
59  virtual void UpdateStatusMessage( const TranslatableString & ) = 0;
60 
61 public:
62  // Structure and functions for generalized visitation of the subdivision
63  struct Visitor {
64  virtual ~Visitor();
65  virtual void VisitCell( const wxRect &rect, TrackPanelCell &cell );
66  virtual void BeginGroup( const wxRect &rect, TrackPanelGroup &group );
67  virtual void EndGroup( const wxRect &rect, TrackPanelGroup &group );
68  };
69 
70  // Most general visit
71  void Visit( Visitor &visitor );
72 
73  // Easier visit when you care only about cells
75  std::function< void( const wxRect &rect, TrackPanelCell &cell ) >;
76  void VisitCells( const SimpleCellVisitor &visitor );
77 
78  // Easier visits when you want to visit each node once only
80  std::function< void( const wxRect &rect, TrackPanelNode &node ) >;
81  void VisitPreorder( const SimpleNodeVisitor &visitor );
82  void VisitPostorder( const SimpleNodeVisitor &visitor );
83 
84  // Find cell by coordinate
85  struct FoundCell {
86  std::shared_ptr< TrackPanelCell > pCell;
87  wxRect rect;
88  };
89 
90  FoundCell FindCell(int mouseX, int mouseY);
91 
92  // Search the tree of subdivisions of the panel area for the given cell.
93  // If more than one sub-area is associated with the same cell object, it
94  // is not specified which rectangle is returned.
95  wxRect FindRect(const TrackPanelCell &cell);
96 
97  // Search the tree of subdivisions of the panel area for a node (group or
98  // cell) satisfying the predicate. If more than one sub-area is associated
99  // with some node satisfying the predicate, it is not specified which
100  // rectangle is returned.
101  wxRect FindRect(const std::function< bool( TrackPanelNode& ) > &pred);
102 
103  UIHandlePtr Target();
104 
105  std::shared_ptr<TrackPanelCell> LastCell() const;
106 
107  bool IsMouseCaptured();
108 
109  wxCoord MostRecentXCoord() const;
110 
111  void HandleCursorForPresentMouseState(bool doHit = true);
112 
113  // Visit the Draw functions of all cells that intersect the panel area,
114  // and of handles associated with such cells,
115  // and of all groups of cells,
116  // repeatedly with a pass count from 0 to nPasses - 1
117  void Draw( TrackPanelDrawingContext &context, unsigned nPasses );
118 
119 protected:
120  bool HasEscape();
121  bool CancelDragging( bool escaping );
122  void DoContextMenu( TrackPanelCell *pCell = nullptr );
123  void ClearTargets();
124 
125 private:
126  void Visit(
127  const wxRect &rect, const std::shared_ptr<TrackPanelNode> &node,
128  Visitor &visitor );
129 
130  bool HasRotation();
131  bool ChangeTarget(bool forward, bool cycle);
132 
133  void OnMouseEvent(wxMouseEvent & event);
134  void OnCaptureLost(wxMouseCaptureLostEvent & event);
135  void OnCaptureKey(wxCommandEvent & event);
136  void OnKeyDown(wxKeyEvent & event);
137  void OnChar(wxKeyEvent & event);
138  void OnKeyUp(wxKeyEvent & event);
139 
140  void OnSetFocus(wxFocusEvent & event);
141  void OnKillFocus(wxFocusEvent & event);
142 
143  void OnContextMenu(wxContextMenuEvent & event);
144 
145  void HandleInterruptedDrag();
146  void Uncapture( bool escaping, wxMouseState *pState = nullptr );
147  bool HandleEscapeKey(bool down);
148  void UpdateMouseState(const wxMouseState &state);
149  void HandleModifierKey();
150 
151  void HandleClick( const TrackPanelMouseEvent &tpmEvent );
152  void HandleWheelRotation( TrackPanelMouseEvent &tpmEvent );
153 
154  void HandleMotion( wxMouseState &state, bool doHit = true );
155  void HandleMotion
156  ( const TrackPanelMouseState &tpmState, bool doHit = true );
157  void Leave();
158 
159 
160 protected:
162 
163  // To do: make a drawing method and make this private
164  wxMouseState mLastMouseState;
165 
166 private:
167  struct State;
168  std::unique_ptr<State> mState;
169 
170  struct Filter;
171 
172  DECLARE_EVENT_TABLE()
173 };
174 
175 #endif
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
CellularPanel::GetFocusedCell
virtual TrackPanelCell * GetFocusedCell()=0
CellularPanel::FoundCell
Definition: CellularPanel.h:85
OverlayPanel.h
CellularPanel::mViewInfo
ViewInfo * mViewInfo
Definition: CellularPanel.h:161
TrackPanelDrawingContext
Definition: TrackPanelDrawingContext.h:22
ViewInfo
Definition: ViewInfo.h:172
CellularPanel::SimpleCellVisitor
std::function< void(const wxRect &rect, TrackPanelCell &cell) > SimpleCellVisitor
Definition: CellularPanel.h:75
CellularPanel::ProcessUIHandleResult
virtual void ProcessUIHandleResult(TrackPanelCell *pClickedCell, TrackPanelCell *pLatestCell, unsigned refreshResult)=0
UIHandle
Short-lived drawing and event-handling object associated with a TrackPanelCell.
Definition: UIHandle.h:34
CellularPanel::Root
virtual std::shared_ptr< TrackPanelNode > Root()=0
TrackPanelNode
The TrackPanel is built up of nodes, subtrees of the CellularPanel's area Common base class for Track...
Definition: TrackPanelCell.h:39
Registry::Visit
void Visit(Visitor &visitor, BaseItem *pTopItem, const GroupItem *pRegistry)
Definition: Registry.cpp:713
CellularPanel::State
Definition: CellularPanel.cpp:79
CellularPanel::mState
std::unique_ptr< State > mState
Definition: CellularPanel.h:167
UIHandlePtr
std::shared_ptr< UIHandle > UIHandlePtr
Definition: CellularPanel.h:28
TrackPanelCell
Definition: TrackPanelCell.h:74
CellularPanel::SimpleNodeVisitor
std::function< void(const wxRect &rect, TrackPanelNode &node) > SimpleNodeVisitor
Definition: CellularPanel.h:80
TrackPanelGroup
Definition: TrackPanelCell.h:47
CellularPanel::FoundCell::rect
wxRect rect
Definition: CellularPanel.h:87
CellularPanel::FoundCell::pCell
std::shared_ptr< TrackPanelCell > pCell
Definition: CellularPanel.h:86
CellularPanel::SetFocusedCell
virtual void SetFocusedCell()=0
CellularPanel::UpdateStatusMessage
virtual void UpdateStatusMessage(const TranslatableString &)=0
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
CellularPanel
Formerly part of TrackPanel, this abstract base class has no special knowledge of Track objects and i...
Definition: CellularPanel.h:34
TrackPanelMouseEvent
Definition: TrackPanelMouseEvent.h:46
TrackPanelMouseState
Definition: TrackPanelMouseEvent.h:28
CellularPanel::mLastMouseState
wxMouseState mLastMouseState
Definition: CellularPanel.h:164
OverlayPanel
Definition: OverlayPanel.h:18
CellularPanel::Visitor
Definition: CellularPanel.h:63
CellularPanel::~CellularPanel
~CellularPanel() override
CellularPanel::Filter
Definition: CellularPanel.cpp:45
CellularPanel::GetProject
virtual AudacityProject * GetProject() const =0