Audacity 3.2.0
Grid.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 Grid.h
6
7 Leland Lucius
8
9**********************************************************************/
10
11#ifndef __AUDACITY_WIDGETS_GRID__
12#define __AUDACITY_WIDGETS_GRID__
13
14#include <vector>
15#include <wx/setup.h> // for wxUSE_* macros
16#include <wx/defs.h>
17#include <wx/grid.h> // to inherit wxGridCellEditor
18#include "NumericTextCtrl.h" // for NumericConverter::Type
19
20#if wxUSE_ACCESSIBILITY
21class GridAx;
22#endif
23
24class wxArrayString;
25class wxChoice;
26class NumericTextCtrl;
27
28/**********************************************************************/
34#define GRID_VALUE_TIME wxT("Time")
35#define GRID_VALUE_FREQUENCY wxT("Frequency")
36
37class AUDACITY_DLL_API NumericEditor /* not final */ : public wxGridCellEditor
38{
39public:
40
42 (NumericConverter::Type type, const NumericFormatSymbol &format, double rate);
43
45
46 // Precondition: parent != NULL
47 void Create(wxWindow *parent, wxWindowID id, wxEvtHandler *handler) override;
48
49 bool IsAcceptedKey(wxKeyEvent &event) override;
50
51 void SetSize(const wxRect &rect) override;
52
53 void BeginEdit(int row, int col, wxGrid *grid) override;
54
55 bool EndEdit(int row, int col, const wxGrid *grid, const wxString &oldval, wxString *newval) override;
56
57 void ApplyEdit(int row, int col, wxGrid *grid) override;
58
59 void Reset() override;
60
61 NumericFormatSymbol GetFormat() const;
62 double GetRate() const;
63 void SetFormat(const NumericFormatSymbol &format);
64 void SetRate(double rate);
65
66 wxGridCellEditor *Clone() const override;
67 wxString GetValue() const override;
68
70 { return static_cast<NumericTextCtrl *>(m_control); }
71
72 private:
73
75 double mRate;
77 double mOld;
78 wxString mOldString;
80};
81
82/**********************************************************************/
86class NumericRenderer final : public wxGridCellRenderer
87{
88 public:
90 ~NumericRenderer() override;
91
92 void Draw(wxGrid &grid,
93 wxGridCellAttr &attr,
94 wxDC &dc,
95 const wxRect &rect,
96 int row,
97 int col,
98 bool isSelected) override;
99
100 wxSize GetBestSize(wxGrid &grid,
101 wxGridCellAttr &attr,
102 wxDC &dc,
103 int row,
104 int col) override;
105
106 wxGridCellRenderer *Clone() const override;
107
108private:
110};
111
112/**********************************************************************/
117#define GRID_VALUE_CHOICE wxT("Choice")
118
119class AUDACITY_DLL_API ChoiceEditor final
120 : public wxGridCellEditor, wxEvtHandler
121{
122public:
123
124 ChoiceEditor(size_t count = 0,
125 const wxString choices[] = NULL);
126
127 ChoiceEditor(const wxArrayString &choices);
128
130
131 void Create(wxWindow *parent,
132 wxWindowID id,
133 wxEvtHandler *evtHandler) override;
134
135 void SetSize(const wxRect &rect) override;
136 void BeginEdit(int row, int col, wxGrid *grid) override;
137 bool EndEdit(int row, int col, wxGrid *grid);
138 bool EndEdit(int row, int col, const wxGrid *grid,
139 const wxString &oldval, wxString *newval) override;
140 void ApplyEdit(int row, int col, wxGrid *grid) override;
141 void Reset() override;
142
143 wxGridCellEditor *Clone() const override;
144
145 void SetChoices(const wxArrayString &choices);
146 wxString GetValue() const override;
147
148 protected:
149
150 wxChoice *Choice() const { return (wxChoice *)m_control; }
151
152 private:
153
154 // A whole separate class just to get rid of Visual C++ warning C4407
155 class FocusHandler:wxEvtHandler
156 {
157 public:
158 void ConnectEvent(wxWindow *w)
159 {
160 // Need to use a named function pointer, not a lambda, so that we
161 // can unbind the same later
162 w->GetEventHandler()->Bind(wxEVT_KILL_FOCUS, OnKillFocus);
163 };
164 void DisconnectEvent(wxWindow *w)
165 {
166 w->GetEventHandler()->Unbind(wxEVT_KILL_FOCUS, OnKillFocus);
167 };
168 static void OnKillFocus(wxFocusEvent & WXUNUSED(event))
169 {
170 return;
171 };
172 } mHandler;
173
174 wxArrayString mChoices;
175 wxString mOld;
177};
178
179/**********************************************************************/
184class AUDACITY_DLL_API Grid final : public wxGrid
185{
186
187 public:
188
189 Grid(wxWindow *parent,
190 wxWindowID id,
191 const wxPoint& pos = wxDefaultPosition,
192 const wxSize& size = wxDefaultSize,
193 long style = wxWANTS_CHARS | wxBORDER,
194 const wxString& name = wxPanelNameStr);
195
196 ~Grid();
197
198#if wxUSE_ACCESSIBILITY
199 void ClearGrid();
200 bool InsertRows(int pos = 0, int numRows = 1, bool updateLabels = true);
201 bool AppendRows(int numRows = 1, bool updateLabels = true);
202 bool DeleteRows(int pos = 0, int numRows = 1, bool updateLabels = true);
203 bool InsertCols(int pos = 0, int numCols = 1, bool updateLabels = true);
204 bool AppendCols(int numCols = 1, bool updateLabels = true);
205 bool DeleteCols(int pos = 0, int numCols = 1, bool updateLabels = true);
206
207 GridAx *GetNextAx(GridAx *parent, wxAccRole role, int row, int col);
208#endif
209
210 protected:
211
212 void OnSetFocus(wxFocusEvent &event);
213 void OnSelectCell(wxGridEvent &event);
214 void OnEditorShown(wxGridEvent &event);
215 void OnKeyDown(wxKeyEvent &event);
216
217 private:
218
219#if wxUSE_ACCESSIBILITY
220 GridAx *mAx;
221 std::vector<std::unique_ptr<GridAx>> mChildren;
222 int mObjNdx;
223#endif
224
225 public:
226
227 DECLARE_EVENT_TABLE()
228};
229
230#endif
231
const TranslatableString name
Definition: Distortion.cpp:82
int format
Definition: ExportPCM.cpp:56
void ConnectEvent(wxWindow *w)
Definition: Grid.h:158
void DisconnectEvent(wxWindow *w)
Definition: Grid.h:164
static void OnKillFocus(wxFocusEvent &WXUNUSED(event))
Definition: Grid.h:168
Modified version of wxGridChoiceEditor using wxChoice instead of wxComboBox.
Definition: Grid.h:121
wxChoice * Choice() const
Definition: Grid.h:150
wxArrayString mChoices
Definition: Grid.h:174
wxString mOld
Definition: Grid.h:175
wxString mValueAsString
Definition: Grid.h:176
bool EndEdit(int row, int col, const wxGrid *grid, const wxString &oldval, wxString *newval) override
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Supplies an accessible grid based on wxGrid.
Definition: Grid.h:185
wxGridCellEditor for the NumericTextCtrl.
Definition: Grid.h:38
wxString mOldString
Definition: Grid.h:78
NumericTextCtrl * GetNumericTextControl() const
Definition: Grid.h:69
NumericFormatSymbol mFormat
Definition: Grid.h:74
NumericConverter::Type mType
Definition: Grid.h:76
double mOld
Definition: Grid.h:77
wxString mValueAsString
Definition: Grid.h:79
double mRate
Definition: Grid.h:75
wxGridCellRenderer for the NumericTextCtrl.
Definition: Grid.h:87
NumericConverter::Type mType
Definition: Grid.h:109
wxGridCellRenderer * Clone() const override
Definition: Grid.cpp:341
~NumericRenderer() override
Definition: Grid.cpp:245
void Draw(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &rect, int row, int col, bool isSelected) override
Definition: Grid.cpp:249
wxSize GetBestSize(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col) override
Definition: Grid.cpp:311
NumericRenderer(NumericConverter::Type type)
Definition: Grid.h:89