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, size_t iChannel)
46 override;
47
48public:
49 enum : int { DefaultFontSize = 0 }; //system preferred
50 static constexpr int TextFramePadding { 2 };
51 static constexpr int TextFrameYOffset { -1 };
52 static constexpr int LabelBarHeight { 6 };
53
54 explicit
55 LabelTrackView(const std::shared_ptr<Channel> &pChannel);
56 ~LabelTrackView() override;
57
58 static LabelTrackView &Get( LabelTrack& );
59 static const LabelTrackView &Get( const LabelTrack& );
60
61 bool DoCaptureKey( AudacityProject &project, wxKeyEvent &event );
62 bool DoKeyDown(
63 AudacityProject &project, NotifyingSelectedRegion &sel, wxKeyEvent & event);
64 bool DoChar(
65 AudacityProject &project, NotifyingSelectedRegion &sel, wxKeyEvent & event);
66
67 //This returns the index of the label we just added.
68 int AddLabel(const SelectedRegion &region,
69 const wxString &title = {},
70 int restoreFocus = -1);
71
72private:
73 void BindTo( LabelTrack *pParent );
74
75 std::vector<UIHandlePtr> DetailedHitTest
76 (const TrackPanelMouseState &state,
77 const AudacityProject *pProject, int currentTool, bool bMultiTool)
78 override;
79
80 unsigned CaptureKey
81 (wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent,
82 AudacityProject *project) override;
83
84 unsigned KeyDown
85 (wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent,
86 AudacityProject *project) override;
87
88 unsigned Char
89 (wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent,
90 AudacityProject *project) override;
91
92 std::shared_ptr<ChannelVRulerControls> DoGetVRulerControls() override;
93
94 // Preserve some view state too for undo/redo purposes
95 void CopyTo(Track &track, size_t iChannel) const override;
96
97public:
98 static void DoEditLabels(
99 AudacityProject &project, LabelTrack *lt = nullptr, int index = -1);
100
101 static int DialogForLabelName(
102 AudacityProject &project, const SelectedRegion& region,
103 const wxString& initialValue, wxString& value);
104
105 bool IsTextSelected( AudacityProject &project ) const;
106
107private:
108 void CreateCustomGlyphs();
109
110public:
111 static wxFont GetFont(const wxString &faceName, int size = DefaultFontSize);
112 static void ResetFont();
113
114 void Draw( TrackPanelDrawingContext &context, const wxRect & r ) const;
115
116 bool CutSelectedText( AudacityProject &project );
117 bool CopySelectedText( AudacityProject &project );
118 bool SelectAllText(AudacityProject& project);
119
120 bool PasteSelectedText(
121 AudacityProject &project, double sel0, double sel1 );
122
123 static void OverGlyph(
124 const LabelTrack &track, LabelTrackHit &hit, int x, int y );
125
126private:
127 static wxBitmap & GetGlyph( int i);
128
129 struct Index
130 {
131 Index();
132 Index(int index);
133 operator int() const;
134 Index &operator =(int index);
135 Index &operator ++();
136 Index &operator --();
137
138 bool IsModified() const;
139 void SetModified(bool modified);
140
141 private:
144 };
145
146public:
147 struct Flags {
148 int mInitialCursorPos, mCurrentCursorPos;
151 wxString mUndoLabel;
152 };
153
154 void ResetFlags();
155 Flags SaveFlags() const;
156 void RestoreFlags( const Flags& flags );
157
158 static int OverATextBox( const LabelTrack &track, int xx, int yy );
159
160 static bool OverTextBox( const LabelStruct *pLabel, int x, int y );
161
162private:
163 static bool IsTextClipSupported();
164
165public:
166 void AddedLabel( const wxString &title, int pos );
167 void DeletedLabel( int index );
168
169private:
170 //And this tells us the index, if there is a label already there.
171 int GetLabelIndex(double t, double t1);
172
173public:
174 //get current cursor position,
175 // relative to the left edge of the track panel
176 bool CalcCursorX( AudacityProject &project, int * x ) const;
177
178private:
179 void CalcHighlightXs(int *x1, int *x2) const;
180
181public:
182 void ShowContextMenu( AudacityProject &project );
183
184private:
185 void OnContextMenu( AudacityProject &project, wxCommandEvent & evt);
186
189 mutable Index mNavigationIndex{ -1 };
191 mutable Index mTextEditIndex{ -1 };
192
193 mutable wxString mUndoLabel;
194
195 static int mIconHeight;
196 static int mIconWidth;
197 static int mTextHeight;
198
199 static bool mbGlyphsReady;
200 static wxBitmap mBoundaryGlyphs[NUM_GLYPH_CONFIGS * NUM_GLYPH_HIGHLIGHTS];
201
202 static int mFontHeight;
203 mutable int mCurrentCursorPos;
204 mutable int mInitialCursorPos;
205
206
207 int mRestoreFocus{-2};
209
210 void ComputeTextPosition(const wxRect & r, int index) const;
211 void ComputeLayout(const wxRect & r, const ZoomInfo &zoomInfo) const;
212 static void DrawLines( wxDC & dc, const LabelStruct &ls, const wxRect & r);
213 static void DrawGlyphs( wxDC & dc, const LabelStruct &ls, const wxRect & r,
214 int GlyphLeft, int GlyphRight);
215 static int GetTextFrameHeight();
216 static void DrawText( wxDC & dc, const LabelStruct &ls, const wxRect & r);
217 static void DrawTextBox( wxDC & dc, const LabelStruct &ls, const wxRect & r);
218 static void DrawBar(wxDC& dc, const LabelStruct& ls, const wxRect& r);
219 static void DrawHighlight(
220 wxDC & dc, const LabelStruct &ls, int xPos1, int xPos2, int charHeight);
221
222public:
224 int FindCursorPosition(int labelIndex, wxCoord xPos);
225 int GetCurrentCursorPosition() const { return mCurrentCursorPos; }
226 void SetCurrentCursorPosition(int pos);
227 int GetInitialCursorPosition() const { return mInitialCursorPos; }
228
231 void SetTextSelection(int labelIndex, int start = 1, int end = 1);
232 int GetTextEditIndex(AudacityProject& project) const;
233 void ResetTextSelection();
234
235 void SetNavigationIndex(int index);
236 int GetNavigationIndex(AudacityProject& project) const;
237
238private:
239
240 // TrackPanelDrawable implementation
241 void Draw(
243 const wxRect &rect, unsigned iPass ) override;
244
245 static void calculateFontHeight(wxDC & dc);
246
247 bool IsValidIndex(const Index& index, AudacityProject& project) const;
248
249private:
250 void RemoveSelectedText();
251
252 void OnLabelAdded( const LabelTrackEvent& );
253 void OnLabelDeleted( const LabelTrackEvent& );
254 void OnLabelPermuted( const LabelTrackEvent& );
255 void OnSelectionChange( const LabelTrackEvent& );
256
258
259 std::shared_ptr<LabelTrack> FindLabelTrack();
260 std::shared_ptr<const LabelTrack> FindLabelTrack() const;
261
262 std::weak_ptr<LabelGlyphHandle> mGlyphHandle;
263 std::weak_ptr<LabelTextHandle> mTextHandle;
264
265 static wxFont msFont;
266
267 // Bug #2571: See explanation in ShowContextMenu()
269};
270
271#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
void Reparent(const std::shared_ptr< Track > &parent, size_t iChannel) override
Object may be shared among tracks but hold a special back-pointer to one of them; reassign it.
Definition: ChannelView.cpp:31
static ChannelView & Get(Channel &channel)
void CopyTo(Track &track, size_t iChannel) const override
Copy state, for undo/redo purposes.
Definition: ChannelView.cpp:67
Implements some hit-testing shared by many ChannelView subtypes.
virtual std::vector< UIHandlePtr > DetailedHitTest(const TrackPanelMouseState &, const AudacityProject *pProject, int currentTool, bool bMultiTool)=0
A LabelStruct holds information for ONE label in a LabelTrack.
Definition: LabelTrack.h:40
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:98
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:110
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)
const char * end(const char *str) noexcept
Definition: StringUtils.h:106