Audacity  3.0.3
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 
13 #include "audacity/Types.h"
14 
15 #include <vector>
16 #include <wx/setup.h> // for wxUSE_* macros
17 #include <wx/defs.h>
18 #include <wx/vlbox.h> // to inherit wxVListBox
19 
20 #include "../commands/Keyboard.h"
21 
22 // Class holding all information about a node. Rather than a real tree
23 // we store these in an array and simulate a tree.
24 class KeyNode
25 {
26 public:
28  {
29  index = -1;
30  line = -1;
31  depth = -1;
32  iscat = false;
33  ispfx = false;
34  isparent = false;
35  isopen = false;
36  }
37  KeyNode( const KeyNode & ) = default;
38  KeyNode &operator = ( const KeyNode & ) = default;
39  //KeyNode( KeyNode && ) = default;
40  //KeyNode &operator = ( KeyNode && ) = default;
41 
42 public:
44  wxString category;
45  wxString prefix;
46  wxString label;
48  int index;
49  int line;
50  int depth;
51  bool iscat;
52  bool ispfx;
53  bool isparent;
54  bool isopen;
55 };
56 
57 // Declare the KeyNode arrays
58 
59 // Types of view currently supported
60 enum ViewByType : int
61 {
64  ViewByKey
65 };
66 
67 #if wxUSE_ACCESSIBILITY
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 override; // Gets the control name from the base class
81 
82  void RefreshBindings(const CommandIDs & names,
83  const TranslatableStrings & categories,
84  const TranslatableStrings & prefixes,
85  const TranslatableStrings & labels,
86  const std::vector<NormalizedKeyString> & 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 CommandID & name) const;
95  CommandID GetName(int index) const;
97 
98  int GetIndexByKey(const NormalizedKeyString & key) const;
99  NormalizedKeyString GetKey(int index) const;
100  bool CanSetKey(int index) const;
101  bool SetKey(int index, const NormalizedKeyString & key);
102  bool SetKeyByName(const CommandID & name, const NormalizedKeyString & 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 override;
122  void OnDrawItem(wxDC & dc, const wxRect & rect, size_t line) const override;
123  wxCoord OnMeasureItem(size_t line) const override;
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 bool CmpKeyNodeByTree(KeyNode *n1, KeyNode *n2);
135  static bool CmpKeyNodeByName(KeyNode *n1, KeyNode *n2);
136  static bool 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  std::vector<KeyNode> mNodes;
150  std::vector<KeyNode*> 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 #endif
172 
size
size_t size
Definition: ffmpeg-2.3.6-single-header.h:412
KeyView::mLineHeight
wxCoord mLineHeight
Definition: KeyView.h:159
KeyView::OnSelected
void OnSelected(wxCommandEvent &event)
Definition: KeyView.cpp:1331
KeyView::mWidth
wxCoord mWidth
Definition: KeyView.h:156
KeyView::mKeyWidth
wxCoord mKeyWidth
Definition: KeyView.h:162
KeyView::OnMeasureItem
wxCoord OnMeasureItem(size_t line) const override
Definition: KeyView.cpp:1319
KeyView::mKeyX
wxCoord mKeyX
Definition: KeyView.h:160
KeyView::RefreshBindings
void RefreshBindings(const CommandIDs &names, const TranslatableStrings &categories, const TranslatableStrings &prefixes, const TranslatableStrings &labels, const std::vector< NormalizedKeyString > &keys, bool bSort)
Definition: KeyView.cpp:636
KeyView::RefreshLines
void RefreshLines(bool bSort=true)
Definition: KeyView.cpp:851
KeyView::OnLeftDown
void OnLeftDown(wxMouseEvent &event)
Definition: KeyView.cpp:1622
TranslatableStrings
std::vector< TranslatableString > TranslatableStrings
Definition: TranslatableString.h:295
KeyView::mCommandWidth
int mCommandWidth
Definition: KeyView.h:161
KeyView::GetName
wxString GetName() const override
Definition: KeyView.cpp:194
KeyView::CmpKeyNodeByName
static bool CmpKeyNodeByName(KeyNode *n1, KeyNode *n2)
Definition: KeyView.cpp:1722
ViewByType
ViewByType
Definition: KeyView.h:61
KeyView::mNodes
std::vector< KeyNode > mNodes
Definition: KeyView.h:149
KeyNode::category
wxString category
Definition: KeyView.h:44
KeyNode::isparent
bool isparent
Definition: KeyView.h:53
KeyView::ExpandAll
void ExpandAll()
Definition: KeyView.cpp:503
KeyView::OnScroll
void OnScroll(wxScrollWinEvent &event)
Definition: KeyView.cpp:1395
KeyNode::KeyNode
KeyNode(const KeyNode &)=default
KeyView::GetSelected
int GetSelected() const
Definition: KeyView.cpp:185
KeyNode::ispfx
bool ispfx
Definition: KeyView.h:52
KeyNode::KeyNode
KeyNode()
Definition: KeyView.h:27
KeyView::SetKey
bool SetKey(int index, const NormalizedKeyString &key)
Definition: KeyView.cpp:355
KeyView::SetKeyByName
bool SetKeyByName(const CommandID &name, const NormalizedKeyString &key)
Definition: KeyView.cpp:396
KeyNode::depth
int depth
Definition: KeyView.h:50
KeyNode::name
CommandID name
Definition: KeyView.h:43
CommandIDs
std::vector< CommandID > CommandIDs
Definition: Identifier.h:233
KeyView::CmpKeyNodeByKey
static bool CmpKeyNodeByKey(KeyNode *n1, KeyNode *n2)
Definition: KeyView.cpp:1756
KeyNode::line
int line
Definition: KeyView.h:49
KeyView::GetFullLabel
wxString GetFullLabel(int index) const
Definition: KeyView.cpp:220
KeyNode::key
NormalizedKeyString key
Definition: KeyView.h:47
KeyView::mScrollX
wxCoord mScrollX
Definition: KeyView.h:155
KeyView::OnKillFocus
void OnKillFocus(wxFocusEvent &event)
Definition: KeyView.cpp:1369
KeyView::OnSize
void OnSize(wxSizeEvent &event)
Definition: KeyView.cpp:1385
KeyView::IndexToLine
int IndexToLine(int index) const
Definition: KeyView.cpp:1146
ViewByKey
@ ViewByKey
Definition: KeyView.h:64
KeyView::OnSetFocus
void OnSetFocus(wxFocusEvent &event)
Definition: KeyView.cpp:1346
name
const TranslatableString name
Definition: Distortion.cpp:98
KeyView::GetKey
NormalizedKeyString GetKey(int index) const
Definition: KeyView.cpp:322
KeyView::GetNameByKey
CommandID GetNameByKey(const NormalizedKeyString &key) const
Definition: KeyView.cpp:282
ViewByTree
@ ViewByTree
Definition: KeyView.h:62
KeyView::GetIndexByKey
int GetIndexByKey(const NormalizedKeyString &key) const
Definition: KeyView.cpp:302
KeyView::OnKeyDown
void OnKeyDown(wxKeyEvent &event)
Definition: KeyView.cpp:1417
NormalizedKeyString
Definition: Keyboard.h:24
Types.h
KeyView::KeyView
KeyView(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
Definition: KeyView.cpp:155
ViewByName
@ ViewByName
Definition: KeyView.h:63
KeyView::mFilter
wxString mFilter
Definition: KeyView.h:153
KeyView::LineToIndex
int LineToIndex(int line) const
Definition: KeyView.cpp:1132
KeyNode::operator=
KeyNode & operator=(const KeyNode &)=default
key
static const AudacityProject::AttachedObjects::RegisteredFactory key
Definition: CommandManager.cpp:201
KeyView::GetIndexByName
int GetIndexByName(const CommandID &name) const
Definition: KeyView.cpp:246
TaggedIdentifier< CommandIdTag, false >
KeyView::SetView
void SetView(ViewByType type)
Definition: KeyView.cpp:414
names
static TranslatableStrings names
Definition: Tags.cpp:744
KeyView::UpdateHScroll
void UpdateHScroll()
Definition: KeyView.cpp:602
KeyView::CmpKeyNodeByTree
static bool CmpKeyNodeByTree(KeyNode *n1, KeyNode *n2)
Definition: KeyView.cpp:1692
KeyNode::prefix
wxString prefix
Definition: KeyView.h:45
KeyView::mLineCount
size_t mLineCount
Definition: KeyView.h:158
KeyView
Provides multiple views of keyboard shortcuts.
Definition: KeyView.h:73
KeyView::RecalcExtents
void RecalcExtents()
Definition: KeyView.cpp:547
KeyView::SetFilter
void SetFilter(const wxString &filter)
Definition: KeyView.cpp:472
KeyNode::isopen
bool isopen
Definition: KeyView.h:54
KeyView::~KeyView
virtual ~KeyView()
Definition: KeyView.cpp:177
KeyView::SelectNode
void SelectNode(int index)
Definition: KeyView.cpp:1105
KeyView::OnDrawItem
void OnDrawItem(wxDC &dc, const wxRect &rect, size_t line) const override
Definition: KeyView.cpp:1235
KeyView::CanSetKey
bool CanSetKey(int index) const
Definition: KeyView.cpp:338
KeyNode::label
wxString label
Definition: KeyView.h:46
KeyNode::iscat
bool iscat
Definition: KeyView.h:51
KeyNode
Definition: KeyView.h:25
KeyView::GetLabel
wxString GetLabel(int index) const
Definition: KeyView.cpp:204
KeyView::CollapseAll
void CollapseAll()
Definition: KeyView.cpp:525
KeyNode::index
int index
Definition: KeyView.h:48
KeyView::mViewType
ViewByType mViewType
Definition: KeyView.h:152
KeyView::OnDrawBackground
void OnDrawBackground(wxDC &dc, const wxRect &rect, size_t line) const override
Definition: KeyView.cpp:1162
KeyView::mLines
std::vector< KeyNode * > mLines
Definition: KeyView.h:150