Audacity 3.2.0
TextEditHelper.h
Go to the documentation of this file.
1/*!********************************************************************
2*
3 Audacity: A Digital Audio Editor
4
5 TextEditHelper.h
6
7 Vitaly Sverchinsky
8
9 **********************************************************************/
10
11#pragma once
12
13#include <wx/string.h>
14#include <wx/font.h>
15
16#include "UIHandle.h"
17#include <wx/colour.h>
18
19class wxDC;
20class wxMouseEvent;
21
22class AudacityProject;
24class Track;
25
26//Used as a delegate for TextEditHelper
28{
29public:
30
32
33 virtual void OnTextEditFinished(AudacityProject* project, const wxString& text) = 0;
35 virtual void OnTextModified(AudacityProject* project, const wxString& text) = 0;
36 virtual void OnTextContextMenu(AudacityProject* project, const wxPoint& position) = 0;
37
38};
39
40
41//Used as a helper object for drawing, editing
42//and text navigation in TrackPanel
44{
45 wxString mText;
46 wxFont mFont;
47 wxRect mBBox;
48
50 wxColor mTextColor;
51
52 bool mRightDragging{ false };
53 //Index of the symbol from which text drawing should start,
54 //in cases where the whole text cannot fit into provided "view"
55 //rectangle. Used both in hit testing and drawing.
56 int mOffset{ 0 };
59
60 // TextEditHelper will send messages about changes to the object
61 // that implements TextEditDelegate, if present
62 std::weak_ptr<TextEditDelegate> mDelegate;
63
64public:
65 static bool IsGoodEditKeyCode(int keyCode);
66
67 TextEditHelper(const std::weak_ptr<TextEditDelegate>& delegate, const wxString& text, const wxFont& font);
68
70 {
71 }
72
73 void SetTextColor(const wxColor& textColor);
74 void SetTextSelectionColor(const wxColor& textSelectionColor);
75
78
79 std::pair<int, int> GetSelection() const;
80 void SetSelection(int from, int to);
81 void SelectAll();
82 bool IsSelectionEmpty();
83
84 bool CaptureKey(int keyCode, int mods);
85 bool OnKeyDown(int keyCode, int mods, AudacityProject* project);
86 bool OnChar(int charCode, AudacityProject* project);
87
88 bool OnClick(const wxMouseEvent& event, AudacityProject* project);
89 bool OnDrag(const wxMouseEvent& event, AudacityProject* project);
90 bool OnRelease(const wxMouseEvent& event, AudacityProject* project);
91
92 bool Draw(wxDC& dc, const wxRect& rect);
93
97
98 bool GetCharPositionX(int index, int* outX);
99
100 const wxRect& GetBBox() const;
101
102protected:
103
104 bool HandleDragRelease(const wxMouseEvent& event, AudacityProject* project);
105
107 int FindCursorIndex(const wxPoint& point);
108
109};
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 ~TextEditDelegate()
virtual void OnTextModified(AudacityProject *project, const wxString &text)=0
virtual void OnTextEditCancelled(AudacityProject *project)=0
virtual void OnTextEditFinished(AudacityProject *project, const wxString &text)=0
virtual void OnTextContextMenu(AudacityProject *project, const wxPoint &position)=0
bool HandleDragRelease(const wxMouseEvent &event, AudacityProject *project)
void SetTextSelectionColor(const wxColor &textSelectionColor)
bool OnChar(int charCode, AudacityProject *project)
bool OnDrag(const wxMouseEvent &event, AudacityProject *project)
static bool IsGoodEditKeyCode(int keyCode)
bool OnKeyDown(int keyCode, int mods, AudacityProject *project)
void Finish(AudacityProject *project)
wxColor mTextColor
bool OnClick(const wxMouseEvent &event, AudacityProject *project)
bool CaptureKey(int keyCode, int mods)
int FindCursorIndex(const wxPoint &point)
bool CutSelectedText(AudacityProject &project)
bool GetCharPositionX(int index, int *outX)
bool Draw(wxDC &dc, const wxRect &rect)
void RemoveSelectedText(AudacityProject *project)
const wxRect & GetBBox() const
TextEditHelper(const std::weak_ptr< TextEditDelegate > &delegate, const wxString &text, const wxFont &font)
void SetSelection(int from, int to)
bool PasteSelectedText(AudacityProject &project)
bool OnRelease(const wxMouseEvent &event, AudacityProject *project)
void SetTextColor(const wxColor &textColor)
bool CopySelectedText(AudacityProject &project)
void Cancel(AudacityProject *project)
std::pair< int, int > GetSelection() const
wxColor mTextSelectionColor
std::weak_ptr< TextEditDelegate > mDelegate
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:110