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
20class AudacityProject;
21
22#if wxUSE_ACCESSIBILITY
23class GridAx;
24#endif
25
26class wxArrayString;
27class wxChoice;
28class NumericTextCtrl;
29
30/**********************************************************************/
36#define GRID_VALUE_TIME wxT("Time")
37#define GRID_VALUE_FREQUENCY wxT("Frequency")
38
39class AUDACITY_DLL_API NumericEditor /* not final */ : public wxGridCellEditor
40{
41public:
42
44 (const FormatterContext& context, NumericConverterType type, const NumericFormatID &format);
45
47
48 // Precondition: parent != NULL
49 void Create(wxWindow *parent, wxWindowID id, wxEvtHandler *handler) override;
50
51 bool IsAcceptedKey(wxKeyEvent &event) override;
52
53 void SetSize(const wxRect &rect) override;
54
55 void BeginEdit(int row, int col, wxGrid *grid) override;
56
57 bool EndEdit(int row, int col, const wxGrid *grid, const wxString &oldval, wxString *newval) override;
58
59 void ApplyEdit(int row, int col, wxGrid *grid) override;
60
61 void Reset() override;
62
63 NumericFormatID GetFormat() const;
64 void SetFormat(const NumericFormatID &format);
65
66 wxGridCellEditor *Clone() const override;
67 wxString GetValue() const override;
68
70 { return static_cast<NumericTextCtrl *>(m_control); }
71
72 private:
73
76 double mOld;
77 wxString mOldString;
79
81};
82
83/**********************************************************************/
87class NumericRenderer final : public wxGridCellRenderer
88{
89 public:
91 : mType { std::move(type) }
92 , mContext { context }
93 {
94 }
95 ~NumericRenderer() override;
96
97 void Draw(wxGrid &grid,
98 wxGridCellAttr &attr,
99 wxDC &dc,
100 const wxRect &rect,
101 int row,
102 int col,
103 bool isSelected) override;
104
105 wxSize GetBestSize(wxGrid &grid,
106 wxGridCellAttr &attr,
107 wxDC &dc,
108 int row,
109 int col) override;
110
111 wxGridCellRenderer *Clone() const override;
112
113private:
116};
117
118/**********************************************************************/
123#define GRID_VALUE_CHOICE wxT("Choice")
124
125class AUDACITY_DLL_API ChoiceEditor final
126 : public wxGridCellEditor, wxEvtHandler
127{
128public:
129
130 ChoiceEditor(size_t count = 0,
131 const wxString choices[] = NULL);
132 ChoiceEditor(const wxArrayString &choices);
133
135
136 void Create(wxWindow *parent,
137 wxWindowID id,
138 wxEvtHandler *evtHandler) override;
139
140 void SetSize(const wxRect &rect) override;
141 void BeginEdit(int row, int col, wxGrid *grid) override;
142 bool EndEdit(int row, int col, wxGrid *grid);
143 bool EndEdit(int row, int col, const wxGrid *grid,
144 const wxString &oldval, wxString *newval) override;
145 void ApplyEdit(int row, int col, wxGrid *grid) override;
146 void Reset() override;
147
148 wxGridCellEditor *Clone() const override;
149
150 void SetChoices(const wxArrayString &choices);
151 wxString GetValue() const override;
152
153 protected:
154
155 wxChoice *Choice() const { return (wxChoice *)m_control; }
156
157 private:
158
159 // A whole separate class just to get rid of Visual C++ warning C4407
160 class FocusHandler:wxEvtHandler
161 {
162 public:
163 void ConnectEvent(wxWindow *w)
164 {
165 // Need to use a named function pointer, not a lambda, so that we
166 // can unbind the same later
167 w->GetEventHandler()->Bind(wxEVT_KILL_FOCUS, OnKillFocus);
168 };
169 void DisconnectEvent(wxWindow *w)
170 {
171 w->GetEventHandler()->Unbind(wxEVT_KILL_FOCUS, OnKillFocus);
172 };
173 static void OnKillFocus(wxFocusEvent & WXUNUSED(event))
174 {
175 return;
176 };
177 } mHandler;
178
179 wxArrayString mChoices;
180 wxString mOld;
182};
183
184/**********************************************************************/
189class AUDACITY_DLL_API Grid final : public wxGrid
190{
191
192 public:
193
194 Grid(
195 const FormatterContext& context, wxWindow* parent,
196 wxWindowID id,
197 const wxPoint& pos = wxDefaultPosition,
198 const wxSize& size = wxDefaultSize,
199 long style = wxWANTS_CHARS | wxBORDER,
200 const wxString& name = wxPanelNameStr);
201
202 ~Grid();
203
204#if wxUSE_ACCESSIBILITY
205 void ClearGrid();
206 bool InsertRows(int pos = 0, int numRows = 1, bool updateLabels = true);
207 bool AppendRows(int numRows = 1, bool updateLabels = true);
208 bool DeleteRows(int pos = 0, int numRows = 1, bool updateLabels = true);
209 bool InsertCols(int pos = 0, int numCols = 1, bool updateLabels = true);
210 bool AppendCols(int numCols = 1, bool updateLabels = true);
211 bool DeleteCols(int pos = 0, int numCols = 1, bool updateLabels = true);
212
213 GridAx *GetNextAx(GridAx *parent, wxAccRole role, int row, int col);
214#endif
215
216 protected:
217
218 void OnSetFocus(wxFocusEvent &event);
219 void OnSelectCell(wxGridEvent &event);
220 void OnEditorShown(wxGridEvent &event);
221 void OnKeyDown(wxKeyEvent &event);
222
223 private:
224
226
227#if wxUSE_ACCESSIBILITY
228 GridAx *mAx;
229 std::vector<std::unique_ptr<GridAx>> mChildren;
230 int mObjNdx;
231#endif
232
233 public:
234
235 DECLARE_EVENT_TABLE()
236};
237
238#endif
239
const TranslatableString name
Definition: Distortion.cpp:76
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
void ConnectEvent(wxWindow *w)
Definition: Grid.h:163
void DisconnectEvent(wxWindow *w)
Definition: Grid.h:169
static void OnKillFocus(wxFocusEvent &WXUNUSED(event))
Definition: Grid.h:173
Modified version of wxGridChoiceEditor using wxChoice instead of wxComboBox.
Definition: Grid.h:127
wxChoice * Choice() const
Definition: Grid.h:155
wxArrayString mChoices
Definition: Grid.h:179
wxString mOld
Definition: Grid.h:180
wxString mValueAsString
Definition: Grid.h:181
bool EndEdit(int row, int col, const wxGrid *grid, const wxString &oldval, wxString *newval) override
A context in which formatter operates.
Supplies an accessible grid based on wxGrid.
Definition: Grid.h:190
FormatterContext mContext
Definition: Grid.h:225
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
wxGridCellEditor for the NumericTextCtrl.
Definition: Grid.h:40
wxString mOldString
Definition: Grid.h:77
NumericFormatID mFormat
Definition: Grid.h:74
NumericTextCtrl * GetNumericTextControl() const
Definition: Grid.h:69
NumericConverterType mType
Definition: Grid.h:75
FormatterContext mContext
Definition: Grid.h:80
double mOld
Definition: Grid.h:76
wxString mValueAsString
Definition: Grid.h:78
wxGridCellRenderer for the NumericTextCtrl.
Definition: Grid.h:88
NumericRenderer(const FormatterContext &context, NumericConverterType type)
Definition: Grid.h:90
FormatterContext mContext
Definition: Grid.h:115
wxGridCellRenderer * Clone() const override
Definition: Grid.cpp:330
~NumericRenderer() override
Definition: Grid.cpp:236
void Draw(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &rect, int row, int col, bool isSelected) override
Definition: Grid.cpp:240
NumericConverterType mType
Definition: Grid.h:114
wxSize GetBestSize(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col) override
Definition: Grid.cpp:301
STL namespace.