Audacity  2.2.2
KeyView.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  KeyView.h
6 
7 **********************************************************************/
8 
9 #ifndef __AUDACITY_WIDGETS_KEYVIEW__
10 #define __AUDACITY_WIDGETS_KEYVIEW__
11 
12 #include "../Audacity.h"
13 
14 #include <wx/defs.h>
15 #include <wx/arrstr.h>
16 #include <wx/string.h>
17 #include <wx/vlbox.h>
18 
19 // Class holding all information about a node. Rather than a real tree
20 // we store these in an array and simulate a tree.
21 class KeyNode
22 {
23 public:
25  {
26  index = -1;
27  line = -1;
28  depth = -1;
29  iscat = false;
30  ispfx = false;
31  isparent = false;
32  isopen = false;
33  }
34  KeyNode( const KeyNode & ) = default;
35  KeyNode &operator = ( const KeyNode & ) = default;
36  //KeyNode( KeyNode && ) = default;
37  //KeyNode &operator = ( KeyNode && ) = default;
38 
39 public:
40  wxString name;
41  wxString category;
42  wxString prefix;
43  wxString label;
45  int index;
46  int line;
47  int depth;
48  bool iscat;
49  bool ispfx;
50  bool isparent;
51  bool isopen;
52 };
53 
54 // Declare the KeyNode arrays
55 
56 // Types of view currently supported
58 {
62 };
63 
64 #if wxUSE_ACCESSIBILITY
65 #include <wx/access.h>
66 #include "WindowAccessible.h"
67 
68 // Forward reference accessibility provideer
69 class KeyViewAx;
70 #endif
71 
72 // The KeyView class
73 class KeyView final : public wxVListBox
74 {
75 public:
76  KeyView(wxWindow *parent,
77  wxWindowID id = wxID_ANY,
78  const wxPoint & pos = wxDefaultPosition,
79  const wxSize & size = wxDefaultSize);
80  virtual ~KeyView();
81  wxString GetName() const; // Gets the control name from the base class
82 
83  void RefreshBindings(const wxArrayString & names,
84  const wxArrayString & categories,
85  const wxArrayString & prefixes,
86  const wxArrayString & labels,
87  const std::vector<NormalizedKeyString> & keys,
88  bool bSort);
89 
90  int GetSelected() const;
91 
92  wxString GetLabel(int index) const;
93  wxString GetFullLabel(int index) const;
94 
95  int GetIndexByName(const wxString & name) const;
96  wxString GetName(int index) const;
97  wxString GetNameByKey(const NormalizedKeyString & key) const;
98 
99  int GetIndexByKey(const NormalizedKeyString & key) const;
100  NormalizedKeyString GetKey(int index) const;
101  bool CanSetKey(int index) const;
102  bool SetKey(int index, const NormalizedKeyString & key);
103  bool SetKeyByName(const wxString & name, const NormalizedKeyString & key);
104 
105  void SetView(ViewByType type);
106 
107  void SetFilter(const wxString & filter);
108 
109  void ExpandAll();
110  void CollapseAll();
111 
112  void SelectNode(int index);
113 
114 private:
115  void RecalcExtents();
116  void UpdateHScroll();
117  void RefreshLines(bool bSort = true);
118 
119  int LineToIndex(int line) const;
120  int IndexToLine(int index) const;
121 
122  void OnDrawBackground(wxDC & dc, const wxRect & rect, size_t line) const;
123  void OnDrawItem(wxDC & dc, const wxRect & rect, size_t line) const;
124  wxCoord OnMeasureItem(size_t line) const;
125 
126  void OnSelected(wxCommandEvent & event);
127  void OnSetFocus(wxFocusEvent & event);
128  void OnKillFocus(wxFocusEvent & event);
129  void OnSize(wxSizeEvent & event);
130  void OnScroll(wxScrollWinEvent & event);
131  void OnKeyDown(wxKeyEvent & event);
132  void OnLeftDown(wxMouseEvent & event);
133 
134 
135  static wxString CommandTranslated;
136  static bool CmpKeyNodeByTree(KeyNode *n1, KeyNode *n2);
137  static bool CmpKeyNodeByName(KeyNode *n1, KeyNode *n2);
138  static bool CmpKeyNodeByKey(KeyNode *n1, KeyNode *n2);
139 
140 #if wxUSE_ACCESSIBILITY
141  friend class KeyViewAx;
142 
143  bool HasChildren(int line);
144  bool IsExpanded(int line);
145  wxCoord GetLineHeight(int line);
146  wxString GetValue(int line);
147  ViewByType GetViewType();
148 #endif
149 
150 private:
151  std::vector<KeyNode> mNodes;
152  std::vector<KeyNode*> mLines;
153 
155  wxString mFilter;
156 
157  wxCoord mScrollX;
158  wxCoord mWidth;
159 
160  size_t mLineCount;
161  wxCoord mLineHeight;
162  wxCoord mKeyX;
164  wxCoord mKeyWidth;
165 
166 #if wxUSE_ACCESSIBILITY
167  KeyViewAx *mAx;
168 #endif
169 
170  DECLARE_EVENT_TABLE()
171 };
172 
173 #if wxUSE_ACCESSIBILITY
174 
175 // ----------------------------------------------------------------------------
176 // KeyViewAx
177 //
178 // wxAccessible object providing information for KeyView.
179 // ----------------------------------------------------------------------------
180 
181 class KeyViewAx final : public WindowAccessible
182 {
183 public:
184 
185  KeyViewAx(KeyView *view);
186 
187  void SetCurrentLine(int row);
188  void ListUpdated();
189  bool LineToId(int line, int & childId);
190  bool IdToLine(int childId, int & line);
191 
192  // Can return either a child object, or an integer
193  // representing the child element, starting from 1.
194  wxAccStatus HitTest(const wxPoint & pt, int *childId, wxAccessible **childObject) override;
195 
196  // Retrieves the address of an IDispatch interface for the specified child.
197  // All objects must support this property.
198  wxAccStatus GetChild(int childId, wxAccessible **child) override;
199 
200  // Gets the number of children.
201  wxAccStatus GetChildCount(int *childCount) override;
202 
203  // Gets the default action for this object (0) or > 0 (the action for a child).
204  // Return wxACC_OK even if there is no action. actionName is the action, or the empty
205  // string if there is no action.
206  // The retrieved string describes the action that is performed on an object,
207  // not what the object does as a result. For example, a toolbar button that prints
208  // a document has a default action of "Press" rather than "Prints the current document."
209  wxAccStatus GetDefaultAction(int childId, wxString *actionName) override;
210 
211  // Returns the description for this object or a child.
212  wxAccStatus GetDescription(int childId, wxString *description) override;
213 
214  // Gets the window with the keyboard focus.
215  // If childId is 0 and child is NULL, no object in
216  // this subhierarchy has the focus.
217  // If this object has the focus, child should be 'this'.
218  wxAccStatus GetFocus(int *childId, wxAccessible **child) override;
219 
220  // Returns help text for this object or a child, similar to tooltip text.
221  wxAccStatus GetHelpText(int childId, wxString *helpText) override;
222 
223  // Returns the keyboard shortcut for this object or child.
224  // Return e.g. ALT+K
225  wxAccStatus GetKeyboardShortcut(int childId, wxString *shortcut) override;
226 
227  // Returns the rectangle for this object (id = 0) or a child element (id > 0).
228  // rect is in screen coordinates.
229  wxAccStatus GetLocation(wxRect & rect, int elementId) override;
230 
231  // Navigates from fromId to toId/toObject.
232  wxAccStatus Navigate(wxNavDir navDir, int fromId,
233  int *toId, wxAccessible **toObject) override;
234 
235  // Gets the name of the specified object.
236  wxAccStatus GetName(int childId, wxString *name) override;
237 
238  // Gets the parent, or NULL.
239  wxAccStatus GetParent(wxAccessible **parent) override;
240 
241  // Returns a role constant.
242  wxAccStatus GetRole(int childId, wxAccRole *role) override;
243 
244  // Gets a variant representing the selected children
245  // of this object.
246  // Acceptable values:
247  // - a null variant (IsNull() returns TRUE)
248  // - a list variant (GetType() == wxT("list"))
249  // - an integer representing the selected child element,
250  // or 0 if this object is selected (GetType() == wxT("long"))
251  // - a "void*" pointer to a wxAccessible child object
252  wxAccStatus GetSelections(wxVariant *selections) override;
253 
254  // Returns a state constant.
255  wxAccStatus GetState(int childId, long *state) override;
256 
257  // Returns a localized string representing the value for the object
258  // or child.
259  wxAccStatus GetValue(int childId, wxString *strValue) override;
260 
261 #if defined(__WXMAC__)
262  // Selects the object or child.
263  wxAccStatus Select(int childId, wxAccSelectionFlags selectFlags) override;
264 #endif
265 
266 private:
267  KeyView *mView;
268  int mLastId;
269 };
270 
271 #endif
272 
273 #endif
274 
wxString GetLabel(int index) const
Definition: KeyView.cpp:103
wxString prefix
Definition: KeyView.h:42
static wxArrayString names()
Definition: Tags.cpp:697
ViewByType
Definition: KeyView.h:57
void RecalcExtents()
Definition: KeyView.cpp:432
virtual ~KeyView()
Definition: KeyView.cpp:76
static wxString CommandTranslated
Definition: KeyView.h:135
void OnSelected(wxCommandEvent &event)
Definition: KeyView.cpp:1213
wxCoord mLineHeight
Definition: KeyView.h:161
wxString GetNameByKey(const NormalizedKeyString &key) const
Definition: KeyView.cpp:181
NormalizedKeyString GetKey(int index) const
Definition: KeyView.cpp:221
static bool CmpKeyNodeByName(KeyNode *n1, KeyNode *n2)
Definition: KeyView.cpp:1596
wxString mFilter
Definition: KeyView.h:155
size_t mLineCount
Definition: KeyView.h:160
void ExpandAll()
Definition: KeyView.cpp:388
void RefreshBindings(const wxArrayString &names, const wxArrayString &categories, const wxArrayString &prefixes, const wxArrayString &labels, const std::vector< NormalizedKeyString > &keys, bool bSort)
Definition: KeyView.cpp:521
wxString GetName() const
Definition: KeyView.cpp:93
void OnSetFocus(wxFocusEvent &event)
Definition: KeyView.cpp:1228
void SelectNode(int index)
Definition: KeyView.cpp:987
void UpdateHScroll()
Definition: KeyView.cpp:487
int index
Definition: KeyView.h:45
static bool CmpKeyNodeByKey(KeyNode *n1, KeyNode *n2)
Definition: KeyView.cpp:1630
int GetSelected() const
Definition: KeyView.cpp:84
void OnKillFocus(wxFocusEvent &event)
Definition: KeyView.cpp:1251
NormalizedKeyString key
Definition: KeyView.h:44
wxCoord OnMeasureItem(size_t line) const
Definition: KeyView.cpp:1201
bool ispfx
Definition: KeyView.h:49
bool CanSetKey(int index) const
Definition: KeyView.cpp:237
wxString category
Definition: KeyView.h:41
wxCoord mKeyX
Definition: KeyView.h:162
wxString label
Definition: KeyView.h:43
std::vector< KeyNode > mNodes
Definition: KeyView.h:151
An alternative to using wxWindowAccessible, which in wxWidgets 3.1.1 contained GetParent() which was ...
wxString name
Definition: KeyView.h:40
int GetIndexByKey(const NormalizedKeyString &key) const
Definition: KeyView.cpp:201
bool iscat
Definition: KeyView.h:48
void SetView(ViewByType type)
Definition: KeyView.cpp:313
KeyNode & operator=(const KeyNode &)=default
int depth
Definition: KeyView.h:47
void SetFilter(const wxString &filter)
Definition: KeyView.cpp:364
bool isopen
Definition: KeyView.h:51
void RefreshLines(bool bSort=true)
Definition: KeyView.cpp:733
void OnLeftDown(wxMouseEvent &event)
Definition: KeyView.cpp:1504
wxCoord mKeyWidth
Definition: KeyView.h:164
int mCommandWidth
Definition: KeyView.h:163
void OnDrawItem(wxDC &dc, const wxRect &rect, size_t line) const
Definition: KeyView.cpp:1117
int line
Definition: KeyView.h:46
ViewByType mViewType
Definition: KeyView.h:154
int LineToIndex(int line) const
Definition: KeyView.cpp:1014
std::vector< KeyNode * > mLines
Definition: KeyView.h:152
void OnKeyDown(wxKeyEvent &event)
Definition: KeyView.cpp:1299
void OnSize(wxSizeEvent &event)
Definition: KeyView.cpp:1267
wxCoord mScrollX
Definition: KeyView.h:157
int GetIndexByName(const wxString &name) const
Definition: KeyView.cpp:145
bool SetKeyByName(const wxString &name, const NormalizedKeyString &key)
Definition: KeyView.cpp:295
static bool CmpKeyNodeByTree(KeyNode *n1, KeyNode *n2)
Definition: KeyView.cpp:1566
bool isparent
Definition: KeyView.h:50
const wxChar * name
Definition: Distortion.cpp:94
KeyNode()
Definition: KeyView.h:24
void OnDrawBackground(wxDC &dc, const wxRect &rect, size_t line) const
Definition: KeyView.cpp:1044
wxCoord mWidth
Definition: KeyView.h:158
bool SetKey(int index, const NormalizedKeyString &key)
Definition: KeyView.cpp:254
wxString GetFullLabel(int index) const
Definition: KeyView.cpp:119
int IndexToLine(int index) const
Definition: KeyView.cpp:1028
void OnScroll(wxScrollWinEvent &event)
Definition: KeyView.cpp:1277
KeyView(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
Definition: KeyView.cpp:54
void CollapseAll()
Definition: KeyView.cpp:410
Provides multiple views of keyboard shortcuts.
Definition: KeyView.h:73