Audacity 3.2.0
LabelTrackView.h
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5LabelTrackView.h
6
7Paul Licameli split from class LabelTrack
8
9**********************************************************************/
10
11#ifndef __AUDACITY_LABEL_TRACK_VIEW__
12#define __AUDACITY_LABEL_TRACK_VIEW__
13
14#include "../../ui/CommonChannelView.h"
15#include "Observer.h"
16
18class LabelTextHandle;
20class LabelStruct;
21class LabelTrack;
22struct LabelTrackEvent;
23struct LabelTrackHit;
25class SelectedRegion;
27class ZoomInfo;
28
29class wxBitmap;
30class wxCommandEvent;
31class wxDC;
32class wxMouseEvent;
33
34constexpr int NUM_GLYPH_CONFIGS = 3;
35constexpr int NUM_GLYPH_HIGHLIGHTS = 4;
36constexpr int MAX_NUM_ROWS =80;
37
38class wxKeyEvent;
39
40class AUDACITY_DLL_API LabelTrackView final : public CommonChannelView
41{
42 LabelTrackView( const LabelTrackView& ) = delete;
44
45 void Reparent( const std::shared_ptr<Track> &parent ) override;
46
47public:
48 enum : int { DefaultFontSize = 0 }; //system preferred
49 static constexpr int TextFramePadding { 2 };
50 static constexpr int TextFrameYOffset { -1 };
51 static constexpr int LabelBarHeight { 6 };
52
53 explicit
54 LabelTrackView( const std::shared_ptr<Track> &pTrack );
55 ~LabelTrackView() override;
56
57 static LabelTrackView &Get( LabelTrack& );
58 static const LabelTrackView &Get( const LabelTrack& );
59
60 bool DoCaptureKey( AudacityProject &project, wxKeyEvent &event );
61 bool DoKeyDown(
62 AudacityProject &project, NotifyingSelectedRegion &sel, wxKeyEvent & event);
63 bool DoChar(
64 AudacityProject &project, NotifyingSelectedRegion &sel, wxKeyEvent & event);
65
66 //This returns the index of the label we just added.
67 int AddLabel(const SelectedRegion &region,
68 const wxString &title = {},
69 int restoreFocus = -1);
70
71private:
72 void BindTo( LabelTrack *pParent );
73
74 std::vector<UIHandlePtr> DetailedHitTest
75 (const TrackPanelMouseState &state,
76 const AudacityProject *pProject, int currentTool, bool bMultiTool)
77 override;
78
79 unsigned CaptureKey
80 (wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent,
81 AudacityProject *project) override;
82
83 unsigned KeyDown
84 (wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent,
85 AudacityProject *project) override;
86
87 unsigned Char
88 (wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent,
89 AudacityProject *project) override;
90
91 std::shared_ptr<ChannelVRulerControls> DoGetVRulerControls() override;
92
93 // Preserve some view state too for undo/redo purposes
94 void CopyTo( Track &track ) const override;
95
96public:
97 static void DoEditLabels(
98 AudacityProject &project, LabelTrack *lt = nullptr, int index = -1);
99
100 static int DialogForLabelName(
101 AudacityProject &project, const SelectedRegion& region,
102 const wxString& initialValue, wxString& value);
103
104 bool IsTextSelected( AudacityProject &project ) const;
105
106private:
107 void CreateCustomGlyphs();
108
109public:
110 static wxFont GetFont(const wxString &faceName, int size = DefaultFontSize);
111 static void ResetFont();
112
113 void Draw( TrackPanelDrawingContext &context, const wxRect & r ) const;
114
115 bool CutSelectedText( AudacityProject &project );
116 bool CopySelectedText( AudacityProject &project );
117 bool SelectAllText(AudacityProject& project);
118
119 bool PasteSelectedText(
120 AudacityProject &project, double sel0, double sel1 );
121
122 static void OverGlyph(
123 const LabelTrack &track, LabelTrackHit &hit, int x, int y );
124
125private:
126 static wxBitmap & GetGlyph( int i);
127
128 struct Index
129 {
130 Index();
131 Index(int index);
132 operator int() const;
133 Index &operator =(int index);
134 Index &operator ++();
135 Index &operator --();
136
137 bool IsModified() const;
138 void SetModified(bool modified);
139
140 private:
143 };
144
145public:
146 struct Flags {
147 int mInitialCursorPos, mCurrentCursorPos;
150 wxString mUndoLabel;
151 };
152
153 void ResetFlags();
154 Flags SaveFlags() const;
155 void RestoreFlags( const Flags& flags );
156
157 static int OverATextBox( const LabelTrack &track, int xx, int yy );
158
159 static bool OverTextBox( const LabelStruct *pLabel, int x, int y );
160
161private:
162 static bool IsTextClipSupported();
163
164public:
165 void AddedLabel( const wxString &title, int pos );
166 void DeletedLabel( int index );
167
168private:
169 //And this tells us the index, if there is a label already there.
170 int GetLabelIndex(double t, double t1);
171
172public:
173 //get current cursor position,
174 // relative to the left edge of the track panel
175 bool CalcCursorX( AudacityProject &project, int * x ) const;
176
177private:
178 void CalcHighlightXs(int *x1, int *x2) const;
179
180public:
181 void ShowContextMenu( AudacityProject &project );
182
183private:
184 void OnContextMenu( AudacityProject &project, wxCommandEvent & evt);
185
188 mutable Index mNavigationIndex{ -1 };
190 mutable Index mTextEditIndex{ -1 };
191
192 mutable wxString mUndoLabel;
193
194 static int mIconHeight;
195 static int mIconWidth;
196 static int mTextHeight;
197
198 static bool mbGlyphsReady;
199 static wxBitmap mBoundaryGlyphs[NUM_GLYPH_CONFIGS * NUM_GLYPH_HIGHLIGHTS];
200
201 static int mFontHeight;
202 mutable int mCurrentCursorPos;
203 mutable int mInitialCursorPos;
204
205
206 int mRestoreFocus{-2};
208
209 void ComputeTextPosition(const wxRect & r, int index) const;
210 void ComputeLayout(const wxRect & r, const ZoomInfo &zoomInfo) const;
211 static void DrawLines( wxDC & dc, const LabelStruct &ls, const wxRect & r);
212 static void DrawGlyphs( wxDC & dc, const LabelStruct &ls, const wxRect & r,
213 int GlyphLeft, int GlyphRight);
214 static int GetTextFrameHeight();
215 static void DrawText( wxDC & dc, const LabelStruct &ls, const wxRect & r);
216 static void DrawTextBox( wxDC & dc, const LabelStruct &ls, const wxRect & r);
217 static void DrawBar(wxDC& dc, const LabelStruct& ls, const wxRect& r);
218 static void DrawHighlight(
219 wxDC & dc, const LabelStruct &ls, int xPos1, int xPos2, int charHeight);
220
221public:
223 int FindCursorPosition(int labelIndex, wxCoord xPos);
224 int GetCurrentCursorPosition() const { return mCurrentCursorPos; }
225 void SetCurrentCursorPosition(int pos);
226 int GetInitialCursorPosition() const { return mInitialCursorPos; }
227
230 void SetTextSelection(int labelIndex, int start = 1, int end = 1);
231 int GetTextEditIndex(AudacityProject& project) const;
232 void ResetTextSelection();
233
234 void SetNavigationIndex(int index);
235 int GetNavigationIndex(AudacityProject& project) const;
236
237private:
238
239 // TrackPanelDrawable implementation
240 void Draw(
242 const wxRect &rect, unsigned iPass ) override;
243
244 static void calculateFontHeight(wxDC & dc);
245
246 bool IsValidIndex(const Index& index, AudacityProject& project) const;
247
248private:
249 void RemoveSelectedText();
250
251 void OnLabelAdded( const LabelTrackEvent& );
252 void OnLabelDeleted( const LabelTrackEvent& );
253 void OnLabelPermuted( const LabelTrackEvent& );
254 void OnSelectionChange( const LabelTrackEvent& );
255
257
258 std::shared_ptr<LabelTrack> FindLabelTrack();
259 std::shared_ptr<const LabelTrack> FindLabelTrack() const;
260
261 std::weak_ptr<LabelGlyphHandle> mGlyphHandle;
262 std::weak_ptr<LabelTextHandle> mTextHandle;
263
264 static wxFont msFont;
265
266 // Bug #2571: See explanation in ShowContextMenu()
268};
269
270#endif
constexpr int NUM_GLYPH_HIGHLIGHTS
constexpr int MAX_NUM_ROWS
constexpr int NUM_GLYPH_CONFIGS
static const auto title
const auto project
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
virtual std::shared_ptr< ChannelVRulerControls > DoGetVRulerControls()=0
static ChannelView & Get(Channel &channel)
void CopyTo(Track &track) const override
Copy state, for undo/redo purposes.
Definition: ChannelView.cpp:60
Implements some hit-testing shared by many ChannelView subtypes.
virtual std::vector< UIHandlePtr > DetailedHitTest(const TrackPanelMouseState &, const AudacityProject *pProject, int currentTool, bool bMultiTool)=0
void Reparent(const std::shared_ptr< Track > &parent) override
Object may be shared among tracks but hold a special back-pointer to one of them; reassign it.
A LabelStruct holds information for ONE label in a LabelTrack.
Definition: LabelTrack.h:29
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:87
int GetInitialCursorPosition() const
int GetCurrentCursorPosition() const
static int mTextHeight
void DeletedLabel(int index)
static wxFont msFont
static int mFontHeight
static bool mbGlyphsReady
LabelTrackView & operator=(const LabelTrackView &)=delete
void AddedLabel(const wxString &title, int pos)
int mInitialCursorPos
current cursor position
LabelTrackView(const LabelTrackView &)=delete
std::weak_ptr< LabelTextHandle > mTextHandle
static int mIconWidth
std::weak_ptr< LabelGlyphHandle > mGlyphHandle
static int mIconHeight
Observer::Subscription mSubscription
wxString mUndoLabel
A move-only handle representing a connection to a Publisher.
Definition: Observer.h:70
Defines a selected portion of a project.
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:122
virtual unsigned KeyDown(wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent, AudacityProject *project)
virtual unsigned CaptureKey(wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent, AudacityProject *project)
virtual unsigned Char(wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent, AudacityProject *project)
virtual void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass)
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159