Audacity 3.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
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 "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.
25{
26public:
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
42public:
44 wxString category;
45 wxString prefix;
46 wxString label;
48 int index;
49 int line;
50 int depth;
51 bool iscat;
52 bool ispfx;
54 bool isopen;
55};
56
57// Declare the KeyNode arrays
58
59// Types of view currently supported
60enum ViewByType : int
61{
65};
66
67#if wxUSE_ACCESSIBILITY
68class KeyViewAx;
69#endif
70
71// The KeyView class
72class KeyView final : public wxVListBox
73{
74public:
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
113private:
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
148private:
149 std::vector<KeyNode> mNodes;
150 std::vector<KeyNode*> mLines;
151
153 wxString mFilter;
154
155 wxCoord mScrollX;
156 wxCoord mWidth;
157
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
std::vector< CommandID > CommandIDs
Definition: Identifier.h:233
ViewByType
Definition: KeyView.h:61
@ ViewByTree
Definition: KeyView.h:62
@ ViewByKey
Definition: KeyView.h:64
@ ViewByName
Definition: KeyView.h:63
static const AudacityProject::AttachedObjects::RegisteredFactory key
wxString name
Definition: TagsEditor.cpp:166
static TranslatableStrings names
Definition: TagsEditor.cpp:153
std::vector< TranslatableString > TranslatableStrings
int depth
Definition: KeyView.h:50
bool isopen
Definition: KeyView.h:54
KeyNode()
Definition: KeyView.h:27
wxString label
Definition: KeyView.h:46
CommandID name
Definition: KeyView.h:43
NormalizedKeyString key
Definition: KeyView.h:47
bool isparent
Definition: KeyView.h:53
bool iscat
Definition: KeyView.h:51
KeyNode(const KeyNode &)=default
int index
Definition: KeyView.h:48
wxString category
Definition: KeyView.h:44
KeyNode & operator=(const KeyNode &)=default
bool ispfx
Definition: KeyView.h:52
wxString prefix
Definition: KeyView.h:45
int line
Definition: KeyView.h:49
Provides multiple views of keyboard shortcuts.
Definition: KeyView.h:73
bool CanSetKey(int index) const
Definition: KeyView.cpp:338
std::vector< KeyNode * > mLines
Definition: KeyView.h:150
int mCommandWidth
Definition: KeyView.h:161
void CollapseAll()
Definition: KeyView.cpp:525
void OnSetFocus(wxFocusEvent &event)
Definition: KeyView.cpp:1346
void OnLeftDown(wxMouseEvent &event)
Definition: KeyView.cpp:1622
void ExpandAll()
Definition: KeyView.cpp:503
void OnDrawBackground(wxDC &dc, const wxRect &rect, size_t line) const override
Definition: KeyView.cpp:1162
ViewByType mViewType
Definition: KeyView.h:152
size_t mLineCount
Definition: KeyView.h:158
int GetIndexByName(const CommandID &name) const
Definition: KeyView.cpp:246
int GetIndexByKey(const NormalizedKeyString &key) const
Definition: KeyView.cpp:302
int GetSelected() const
Definition: KeyView.cpp:185
wxCoord mScrollX
Definition: KeyView.h:155
void OnKillFocus(wxFocusEvent &event)
Definition: KeyView.cpp:1369
void OnDrawItem(wxDC &dc, const wxRect &rect, size_t line) const override
Definition: KeyView.cpp:1235
bool SetKey(int index, const NormalizedKeyString &key)
Definition: KeyView.cpp:355
void OnSelected(wxCommandEvent &event)
Definition: KeyView.cpp:1331
wxString GetLabel(int index) const
Definition: KeyView.cpp:204
void OnSize(wxSizeEvent &event)
Definition: KeyView.cpp:1385
void RefreshLines(bool bSort=true)
Definition: KeyView.cpp:851
void SelectNode(int index)
Definition: KeyView.cpp:1105
wxCoord mWidth
Definition: KeyView.h:156
void SetView(ViewByType type)
Definition: KeyView.cpp:414
KeyView(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
Definition: KeyView.cpp:155
void SetFilter(const wxString &filter)
Definition: KeyView.cpp:472
void RecalcExtents()
Definition: KeyView.cpp:547
static bool CmpKeyNodeByTree(KeyNode *n1, KeyNode *n2)
Definition: KeyView.cpp:1692
wxCoord OnMeasureItem(size_t line) const override
Definition: KeyView.cpp:1319
wxCoord mKeyWidth
Definition: KeyView.h:162
void OnScroll(wxScrollWinEvent &event)
Definition: KeyView.cpp:1395
std::vector< KeyNode > mNodes
Definition: KeyView.h:149
wxString GetFullLabel(int index) const
Definition: KeyView.cpp:220
void OnKeyDown(wxKeyEvent &event)
Definition: KeyView.cpp:1417
static bool CmpKeyNodeByName(KeyNode *n1, KeyNode *n2)
Definition: KeyView.cpp:1722
int IndexToLine(int index) const
Definition: KeyView.cpp:1146
wxCoord mLineHeight
Definition: KeyView.h:159
NormalizedKeyString GetKey(int index) const
Definition: KeyView.cpp:322
void UpdateHScroll()
Definition: KeyView.cpp:602
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
bool SetKeyByName(const CommandID &name, const NormalizedKeyString &key)
Definition: KeyView.cpp:396
virtual ~KeyView()
Definition: KeyView.cpp:177
wxString mFilter
Definition: KeyView.h:153
wxCoord mKeyX
Definition: KeyView.h:160
wxString GetName() const override
Definition: KeyView.cpp:194
CommandID GetNameByKey(const NormalizedKeyString &key) const
Definition: KeyView.cpp:282
int LineToIndex(int line) const
Definition: KeyView.cpp:1132
static bool CmpKeyNodeByKey(KeyNode *n1, KeyNode *n2)
Definition: KeyView.cpp:1756