Debian Codegraph @

src/tracks/playabletrack/wavetrack/ui/WaveChannelView.h

raw
1 /**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 WaveChannelView.h
6
7 Paul Licameli split from class WaveTrack
8
9 **********************************************************************/
10
11 #ifndef __AUDACITY_WAVE_TRACK_VIEW__
12 #define __AUDACITY_WAVE_TRACK_VIEW__
13
14 #include "../../../ui/CommonChannelView.h"
15 #include "ClientData.h"
16 #include "SampleCount.h"
17 #include "WaveTrack.h"
18 namespace WaveChannelViewConstants{ enum Display : int; }
19 struct WaveChannelSubViewType;
20
21 class ClipTimes;
22 class CutlineHandle;
23 class TranslatableString;
24 class WaveChannel;
25 class WaveChannelView;
26 class WaveClipAdjustBorderHandle;
27 class ZoomInfo;
28
29
30 class TrackPanelResizeHandle;
31 class WaveTrackAffordanceHandle;
32
33 class SubViewCloseHandle;
34 class SubViewAdjustHandle;
35 class SubViewRearrangeHandle;
36
37 class wxDC;
38
39 class AUDACITY_DLL_API WaveChannelSubView : public CommonChannelView
40 {
41 public:
42
43 using Display = WaveChannelViewConstants::Display;
44 using Type = WaveChannelSubViewType;
45
46 explicit
47 WaveChannelSubView(WaveChannelView &waveChannelView);
48
49 std::shared_ptr<WaveChannel> FindWaveChannel();
50
51 virtual const Type &SubViewType() const = 0;
52
53 // For undo and redo purpose
54 // Empty abstract method to be inherited, for copying the spectral data in SpectrumSubView
55 virtual void CopyToSubView(WaveChannelSubView *destSubView) const;
56
57 std::pair<
58 bool, // if true, hit-testing is finished
59 std::vector<UIHandlePtr>
60 > DoDetailedHitTest(
61 const TrackPanelMouseState &state,
62 const AudacityProject *pProject, int currentTool, bool bMultiTool,
63 const std::shared_ptr<WaveChannel> &wt);
64
65 protected:
66 static void DrawBoldBoundaries(
67 TrackPanelDrawingContext &context, const WaveChannel &channel,
68 const wxRect &rect);
69
70 std::weak_ptr<WaveChannelView> GetWaveChannelView() const;
71
72 std::vector<MenuItem> GetMenuItems(
73 const wxRect &rect, const wxPoint *pPosition, AudacityProject *pProject )
74 override;
75
76 private:
77 std::weak_ptr<SubViewCloseHandle> mCloseHandle;
78 std::weak_ptr<TrackPanelResizeHandle> mResizeHandle;
79 std::weak_ptr<SubViewAdjustHandle> mAdjustHandle;
80 std::weak_ptr<SubViewRearrangeHandle> mRearrangeHandle;
81 std::weak_ptr<WaveClipAdjustBorderHandle> mClipBorderAdjustHandle;
82 std::weak_ptr<CutlineHandle> mCutlineHandle;
83 std::weak_ptr<WaveChannelView> mwWaveChannelView;
84 };
85
86 struct WaveChannelSubViewPlacement {
87 int index;
88 float fraction;
89 };
90 using WaveChannelSubViewPlacements = std::vector<WaveChannelSubViewPlacement>;
91
92 class WaveChannelView;
93 using WaveChannelSubViews = ClientData::Site<
94 WaveChannelView, WaveChannelSubView, ClientData::SkipCopying, std::shared_ptr
95 >;
96
97 class AUDACITY_DLL_API WaveChannelView final
98 : public CommonChannelView
99 , public WaveChannelSubViews
100 {
101 WaveChannelView(const WaveChannelView&) = delete;
102 WaveChannelView &operator=(const WaveChannelView&) = delete;
103
104 public:
105 static constexpr int kChannelSeparatorThickness{ 8 };
106
107 using Display = WaveChannelViewConstants::Display;
108
109 static WaveChannelView &Get(WaveChannel &channel);
110 static const WaveChannelView &Get(const WaveChannel &channel);
111 static WaveChannelView *Find(WaveChannel *pChannel);
112 static const WaveChannelView *Find(const WaveChannel *pChannel);
113
114 //! Get the view of the first channel
115 static WaveChannelView &GetFirst(WaveTrack &wt);
116
117 //! Get the view of the first channel
118 static const WaveChannelView &GetFirst(const WaveTrack &wt);
119
120 //! If pWt is not null, return a pointer to the view of the first channel
121 static WaveChannelView *FindFirst(WaveTrack *pWt);
122
123 //! If pWt is not null, return a pointer to the view of the first channel
124 static const WaveChannelView *FindFirst(const WaveTrack *pWt);
125
126 using CommonChannelView::CommonChannelView;
127 ~WaveChannelView() override;
128
129 std::shared_ptr<WaveChannel> FindWaveChannel();
130
131 // Preserve some view state too for undo/redo purposes
132 void CopyTo(Track &track, size_t iChannel) const override;
133
134 std::shared_ptr<ChannelVRulerControls> DoGetVRulerControls() override;
135
136 // CommonChannelView implementation
137 void Reparent(const std::shared_ptr<Track> &parent, size_t iChannel)
138 override;
139
140 static std::pair<
141 bool, // if true, hit-testing is finished
142 std::vector<UIHandlePtr>
143 > DoDetailedHitTest(
144 const TrackPanelMouseState &state,
145 const AudacityProject *pProject, int currentTool, bool bMultiTool,
146 const std::shared_ptr<WaveChannel> &wt,
147 CommonChannelView &view);
148
149 std::vector<WaveChannelSubView::Type> GetDisplays() const;
150 void SetDisplay(Display display, bool exclusive = true);
151
152 const WaveChannelSubViewPlacements &SavePlacements() const
153 { return DoGetPlacements(); }
154 void RestorePlacements(const WaveChannelSubViewPlacements &placements)
155 { DoGetPlacements() = placements; }
156
157 // Return true if successful. Fails if you try to toggle off the only
158 // sub-view.
159 bool ToggleSubView( Display id );
160
161 // Get all the sub-views, in a sequence that is unspecified but in
162 // correspondence with the result of SavePlacements
163 std::vector<std::shared_ptr<WaveChannelSubView>> GetAllSubViews();
164
165 // Return cached height of rect in last call of GetSubViews
166 wxCoord GetLastHeight() const { return mLastHeight; }
167
168 bool GetMultiView() const { return DoGetMultiView(); }
169 void SetMultiView( bool value ) { DoGetMultiView() = value; }
170
171 WaveTrack::IntervalHolder GetSelectedClip();
172
173 // Returns a visible subset of subviews, sorted in the same
174 // order as they are supposed to be displayed
175
176
177 // Get the visible sub-views,
178 // if rect is provided then result will contain
179 // y coordinate for each subview within this rect
180 Refinement GetSubViews(const wxRect* rect = nullptr);
181
182 unsigned CaptureKey
183 (wxKeyEvent& event, ViewInfo& viewInfo, wxWindow* pParent,
184 AudacityProject* project) override;
185
186 unsigned KeyDown(wxKeyEvent& event, ViewInfo& viewInfo, wxWindow* pParent,
187 AudacityProject* project) override;
188
189 unsigned Char
190 (wxKeyEvent& event, ViewInfo& viewInfo, wxWindow* pParent,
191 AudacityProject* project) override;
192
193 unsigned LoseFocus(AudacityProject *project) override;
194
195 static bool ClipDetailsVisible(
196 const ClipTimes& clip, const ZoomInfo& zoomInfo, const wxRect& viewRect);
197 static wxRect ClipHitTestArea(const ClipTimes& clip,
198 const ZoomInfo& zoomInfo, const wxRect& viewRect);
199 static bool HitTest(const ClipTimes& clip, const ZoomInfo& zoomInfo, const wxRect& rect, const wxPoint& pos);
200
201 //FIXME: These functions do not push state to undo history
202 //because attempt to do so leads to a focus lose which, in
203 //turn finalizes text editing (state is saved after text
204 //editing was intentionally finished instead)
205
206 bool CutSelectedText(AudacityProject& project);
207 bool CopySelectedText(AudacityProject& project);
208 bool PasteText(AudacityProject& project);
209 bool SelectAllText(AudacityProject& project);
210
211 std::shared_ptr<CommonTrackCell> GetAffordanceControls() override;
212
213 private:
214 void BuildSubViews() const;
215 void DoSetDisplay(Display display, bool exclusive = true);
216 bool SelectNextClip(ViewInfo& viewInfo, AudacityProject* project, bool forward);
217
218 // TrackPanelDrawable implementation
219 void Draw(
220 TrackPanelDrawingContext &context,
221 const wxRect &rect, unsigned iPass ) override;
222
223 std::vector<UIHandlePtr> DetailedHitTest
224 (const TrackPanelMouseState &state,
225 const AudacityProject *pProject, int currentTool, bool bMultiTool)
226 override;
227
228 // ChannelView implementation
229 Refinement GetSubViews(const wxRect& rect) override;
230
231 private:
232
233 void DoSetMinimized( bool minimized ) override;
234
235 // Placements are in correspondence with the array of sub-views
236 // in the WaveChannelSubViews base class, though their sequence is
237 // unspecified and maybe different in different platforms.
238 WaveChannelSubViewPlacements &DoGetPlacements();
239 const WaveChannelSubViewPlacements &DoGetPlacements() const;
240 mutable wxCoord mLastHeight{};
241
242 bool &DoGetMultiView();
243 bool DoGetMultiView() const;
244
245 std::shared_ptr<CommonTrackCell> DoGetAffordance(Track& track);
246
247 std::shared_ptr<CommonTrackCell> mpAffordanceCellControl;
248
249 std::weak_ptr<TrackPanelCell> mKeyEventDelegate;
250
251 std::weak_ptr<WaveTrackAffordanceHandle> mAffordanceHandle;
252 };
253 #endif