Audacity  3.0.3
LabelTrackView.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 LabelTrackView.h
6 
7 Paul Licameli split from class LabelTrack
8 
9 **********************************************************************/
10 
11 #ifndef __AUDACITY_LABEL_TRACK_VIEW__
12 #define __AUDACITY_LABEL_TRACK_VIEW__
13 
14 #include "../../ui/CommonTrackView.h"
15 
16 class LabelGlyphHandle;
17 class LabelTextHandle;
19 class LabelStruct;
20 class LabelTrack;
21 struct LabelTrackEvent;
22 struct LabelTrackHit;
24 class SelectedRegion;
26 class ZoomInfo;
27 
28 class wxBitmap;
29 class wxCommandEvent;
30 class wxDC;
31 class wxMouseEvent;
32 
33 constexpr int NUM_GLYPH_CONFIGS = 3;
34 constexpr int NUM_GLYPH_HIGHLIGHTS = 4;
35 constexpr int MAX_NUM_ROWS =80;
36 
37 class wxKeyEvent;
38 
39 class AUDACITY_DLL_API LabelTrackView final : public CommonTrackView
40 {
41  LabelTrackView( const LabelTrackView& ) = delete;
43 
44  void Reparent( const std::shared_ptr<Track> &parent ) override;
45 
46 public:
47  enum : int { DefaultFontSize = 0 }; //system preferred
48  static constexpr int TextFramePadding { 2 };
49  static constexpr int TextFrameYOffset { -1 };
50  static constexpr int LabelBarHeight { 6 };
51 
52  explicit
53  LabelTrackView( const std::shared_ptr<Track> &pTrack );
54  ~LabelTrackView() override;
55 
56  static LabelTrackView &Get( LabelTrack& );
57  static const LabelTrackView &Get( const LabelTrack& );
58 
59  bool DoCaptureKey( AudacityProject &project, wxKeyEvent &event );
60  bool DoKeyDown(
61  AudacityProject &project, NotifyingSelectedRegion &sel, wxKeyEvent & event);
62  bool DoChar(
63  AudacityProject &project, NotifyingSelectedRegion &sel, wxKeyEvent & event);
64 
65  //This returns the index of the label we just added.
66  int AddLabel(const SelectedRegion &region,
67  const wxString &title = {},
68  int restoreFocus = -1);
69 
70 private:
71  void BindTo( LabelTrack *pParent );
72  void UnbindFrom( 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<TrackVRulerControls> DoGetVRulerControls() override;
92 
93  // Preserve some view state too for undo/redo purposes
94  void CopyTo( Track &track ) const override;
95 
96 public:
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 
106 private:
107  void CreateCustomGlyphs();
108 
109 public:
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 PasteSelectedText(
118  AudacityProject &project, double sel0, double sel1 );
119 
120  static void OverGlyph(
121  const LabelTrack &track, LabelTrackHit &hit, int x, int y );
122 
123 private:
124  static wxBitmap & GetGlyph( int i);
125 
126  struct Index
127  {
128  Index();
129  Index(int index);
130  operator int() const;
131  Index &operator =(int index);
132  Index &operator ++();
133  Index &operator --();
134 
135  bool IsModified() const;
136  void SetModified(bool modified);
137 
138  private:
139  int mIndex;
140  bool mModified;
141  };
142 
143 public:
144  struct Flags {
145  int mInitialCursorPos, mCurrentCursorPos;
148  wxString mUndoLabel;
149  };
150 
151  void ResetFlags();
152  Flags SaveFlags() const;
153  void RestoreFlags( const Flags& flags );
154 
155  static int OverATextBox( const LabelTrack &track, int xx, int yy );
156 
157  static bool OverTextBox( const LabelStruct *pLabel, int x, int y );
158 
159 private:
160  static bool IsTextClipSupported();
161 
162 public:
163  void AddedLabel( const wxString &title, int pos );
164  void DeletedLabel( int index );
165 
166 private:
167  //And this tells us the index, if there is a label already there.
168  int GetLabelIndex(double t, double t1);
169 
170 public:
171  //get current cursor position,
172  // relative to the left edge of the track panel
173  bool CalcCursorX( AudacityProject &project, int * x ) const;
174 
175 private:
176  void CalcHighlightXs(int *x1, int *x2) const;
177 
178 public:
179  void ShowContextMenu( AudacityProject &project );
180 
181 private:
182  void OnContextMenu( AudacityProject &project, wxCommandEvent & evt);
183 
186  mutable Index mNavigationIndex{ -1 };
188  mutable Index mTextEditIndex{ -1 };
189 
190  mutable wxString mUndoLabel;
191 
192  static int mIconHeight;
193  static int mIconWidth;
194  static int mTextHeight;
195 
196  static bool mbGlyphsReady;
197  static wxBitmap mBoundaryGlyphs[NUM_GLYPH_CONFIGS * NUM_GLYPH_HIGHLIGHTS];
198 
199  static int mFontHeight;
200  mutable int mCurrentCursorPos;
201  mutable int mInitialCursorPos;
202 
203 
204  int mRestoreFocus{-2};
205 
207  void ComputeTextPosition(const wxRect & r, int index) const;
208  void ComputeLayout(const wxRect & r, const ZoomInfo &zoomInfo) const;
209  static void DrawLines( wxDC & dc, const LabelStruct &ls, const wxRect & r);
210  static void DrawGlyphs( wxDC & dc, const LabelStruct &ls, const wxRect & r,
211  int GlyphLeft, int GlyphRight);
212  static int GetTextFrameHeight();
213  static void DrawText( wxDC & dc, const LabelStruct &ls, const wxRect & r);
214  static void DrawTextBox( wxDC & dc, const LabelStruct &ls, const wxRect & r);
215  static void DrawBar(wxDC& dc, const LabelStruct& ls, const wxRect& r);
216  static void DrawHighlight(
217  wxDC & dc, const LabelStruct &ls, int xPos1, int xPos2, int charHeight);
218 
219 public:
221  int FindCursorPosition(int labelIndex, wxCoord xPos);
222  int GetCurrentCursorPosition() const { return mCurrentCursorPos; }
223  void SetCurrentCursorPosition(int pos);
224  int GetInitialCursorPosition() const { return mInitialCursorPos; }
225 
228  void SetTextSelection(int labelIndex, int start = 1, int end = 1);
229  int GetTextEditIndex(AudacityProject& project) const;
230  void ResetTextSelection();
231 
232  void SetNavigationIndex(int index);
233  int GetNavigationIndex(AudacityProject& project) const;
234 
235 private:
236 
237  // TrackPanelDrawable implementation
238  void Draw(
239  TrackPanelDrawingContext &context,
240  const wxRect &rect, unsigned iPass ) override;
241 
242  static void calculateFontHeight(wxDC & dc);
243 
244  bool IsValidIndex(const Index& index, AudacityProject& project) const;
245 
246 private:
247  void RemoveSelectedText();
248 
249  void OnLabelAdded( LabelTrackEvent& );
250  void OnLabelDeleted( LabelTrackEvent& );
251  void OnLabelPermuted( LabelTrackEvent& );
252  void OnSelectionChange( LabelTrackEvent& );
253 
254  std::shared_ptr<LabelTrack> FindLabelTrack();
255  std::shared_ptr<const LabelTrack> FindLabelTrack() const;
256 
257  std::weak_ptr<LabelGlyphHandle> mGlyphHandle;
258  std::weak_ptr<LabelTextHandle> mTextHandle;
259 
260  static wxFont msFont;
261 
262  // Bug #2571: See explanation in ShowContextMenu()
264 };
265 
266 #endif
size
size_t size
Definition: ffmpeg-2.3.6-single-header.h:412
LabelDefaultClickHandle
Definition: LabelDefaultClickHandle.h:22
LabelTextHandle
Definition: LabelTextHandle.h:24
LabelTrackView::mGlyphHandle
std::weak_ptr< LabelGlyphHandle > mGlyphHandle
Definition: LabelTrackView.h:257
CommonTrackView
Definition: CommonTrackView.h:20
LabelTrackView::mCurrentCursorPos
int mCurrentCursorPos
Definition: LabelTrackView.h:200
TrackView::Get
static TrackView & Get(Track &)
Definition: TrackView.cpp:63
LabelTrackView::mTextHeight
static int mTextHeight
Definition: LabelTrackView.h:194
ZoomInfo
Definition: ZoomInfo.h:47
NUM_GLYPH_HIGHLIGHTS
constexpr int NUM_GLYPH_HIGHLIGHTS
Definition: LabelTrackView.h:34
TrackPanelCell::KeyDown
virtual unsigned KeyDown(wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent, AudacityProject *project)
Definition: TrackPanelCell.cpp:62
LabelTrackView::mIconHeight
static int mIconHeight
Definition: LabelTrackView.h:192
TrackPanelDrawingContext
Definition: TrackPanelDrawingContext.h:22
ViewInfo
Definition: ViewInfo.h:202
LabelTrack
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:88
LabelTrackView::msFont
static wxFont msFont
Definition: LabelTrackView.h:260
NUM_GLYPH_CONFIGS
constexpr int NUM_GLYPH_CONFIGS
Definition: LabelTrackView.h:33
LabelStruct
A LabelStruct holds information for ONE label in a LabelTrack.
Definition: LabelTrack.h:30
LabelTrackView::mbGlyphsReady
static bool mbGlyphsReady
Definition: LabelTrackView.h:196
LabelTrackView::mIconWidth
static int mIconWidth
Definition: LabelTrackView.h:193
LabelTrackView::GetCurrentCursorPosition
int GetCurrentCursorPosition() const
Definition: LabelTrackView.h:222
LabelTrackView
Definition: LabelTrackView.h:40
LabelTrackView::mFontHeight
static int mFontHeight
Definition: LabelTrackView.h:199
LabelTrackView::mEditIndex
int mEditIndex
Definition: LabelTrackView.h:263
LabelTrackEvent
Definition: LabelTrack.h:184
TrackPanelCell::CaptureKey
virtual unsigned CaptureKey(wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent, AudacityProject *project)
Definition: TrackPanelCell.cpp:55
LabelTrackView::Flags::mUndoLabel
wxString mUndoLabel
Definition: LabelTrackView.h:148
LabelTrackView::Flags::mInitialCursorPos
int mInitialCursorPos
Definition: LabelTrackView.h:145
LabelTrackView::mUndoLabel
wxString mUndoLabel
Definition: LabelTrackView.h:190
LabelTrackView::GetInitialCursorPosition
int GetInitialCursorPosition() const
Definition: LabelTrackView.h:224
LabelGlyphHandle
Definition: LabelGlyphHandle.h:50
LabelTrackView::mInitialCursorPos
int mInitialCursorPos
current cursor position
Definition: LabelTrackView.h:201
title
static const auto title
Definition: NoUpdatesAvailableDialog.cpp:22
LabelTrackView::Flags::mNavigationIndex
Index mNavigationIndex
Definition: LabelTrackView.h:146
LabelTrackView::LabelTrackView
LabelTrackView(const LabelTrackView &)=delete
Track
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:239
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:92
TrackPanelMouseState
Definition: TrackPanelMouseEvent.h:28
TrackView::CopyTo
void CopyTo(Track &track) const override
Definition: TrackView.cpp:52
CommonTrackCell::Reparent
virtual void Reparent(const std::shared_ptr< Track > &parent)
Definition: CommonTrackPanelCell.cpp:142
LabelTrackView::mTextHandle
std::weak_ptr< LabelTextHandle > mTextHandle
Definition: LabelTrackView.h:258
LabelTrackView::operator=
LabelTrackView & operator=(const LabelTrackView &)=delete
CommonTrackView::DetailedHitTest
virtual std::vector< UIHandlePtr > DetailedHitTest(const TrackPanelMouseState &, const AudacityProject *pProject, int currentTool, bool bMultiTool)=0
LabelTrackHit
Definition: LabelGlyphHandle.h:33
LabelTrackView::AddedLabel
void AddedLabel(const wxString &title, int pos)
LabelTrackView::Index
Definition: LabelTrackView.h:127
LabelTrackView::Index::mModified
bool mModified
Definition: LabelTrackView.h:140
LabelTrackView::Index::mIndex
int mIndex
Definition: LabelTrackView.h:139
TrackPanelCell::Char
virtual unsigned Char(wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent, AudacityProject *project)
Definition: TrackPanelCell.cpp:76
LabelTrackView::Flags::mTextEditIndex
Index mTextEditIndex
Definition: LabelTrackView.h:147
LabelTrackView::DeletedLabel
void DeletedLabel(int index)
MAX_NUM_ROWS
constexpr int MAX_NUM_ROWS
Definition: LabelTrackView.h:35
TrackView::DoGetVRulerControls
virtual std::shared_ptr< TrackVRulerControls > DoGetVRulerControls()=0
LabelTrackView::Flags
Definition: LabelTrackView.h:144
NotifyingSelectedRegion
Definition: ViewInfo.h:44
SelectedRegion
Defines a selected portion of a project.
Definition: SelectedRegion.h:35
TrackPanelDrawable::Draw
virtual void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass)
Definition: TrackPanelDrawable.cpp:17