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