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