forked from audacity/audacity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyView.h
More file actions
172 lines (134 loc) · 4.15 KB
/
Copy pathKeyView.h
File metadata and controls
172 lines (134 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/**********************************************************************
Audacity: A Digital Audio Editor
KeyView.h
**********************************************************************/
#ifndef __AUDACITY_WIDGETS_KEYVIEW__
#define __AUDACITY_WIDGETS_KEYVIEW__
#include "../Audacity.h"
#include "audacity/Types.h"
#include <vector>
#include <wx/setup.h> // for wxUSE_* macros
#include <wx/defs.h>
#include <wx/vlbox.h> // to inherit wxVListBox
#include "../commands/Keyboard.h"
// Class holding all information about a node. Rather than a real tree
// we store these in an array and simulate a tree.
class KeyNode
{
public:
KeyNode()
{
index = -1;
line = -1;
depth = -1;
iscat = false;
ispfx = false;
isparent = false;
isopen = false;
}
KeyNode( const KeyNode & ) = default;
KeyNode &operator = ( const KeyNode & ) = default;
//KeyNode( KeyNode && ) = default;
//KeyNode &operator = ( KeyNode && ) = default;
public:
CommandID name;
wxString category;
wxString prefix;
wxString label;
NormalizedKeyString key;
int index;
int line;
int depth;
bool iscat;
bool ispfx;
bool isparent;
bool isopen;
};
// Declare the KeyNode arrays
// Types of view currently supported
enum ViewByType : int
{
ViewByTree,
ViewByName,
ViewByKey
};
#if wxUSE_ACCESSIBILITY
class KeyViewAx;
#endif
// The KeyView class
class KeyView final : public wxVListBox
{
public:
KeyView(wxWindow *parent,
wxWindowID id = wxID_ANY,
const wxPoint & pos = wxDefaultPosition,
const wxSize & size = wxDefaultSize);
virtual ~KeyView();
wxString GetName() const override; // Gets the control name from the base class
void RefreshBindings(const CommandIDs & names,
const TranslatableStrings & categories,
const TranslatableStrings & prefixes,
const TranslatableStrings & labels,
const std::vector<NormalizedKeyString> & keys,
bool bSort);
int GetSelected() const;
wxString GetLabel(int index) const;
wxString GetFullLabel(int index) const;
int GetIndexByName(const CommandID & name) const;
CommandID GetName(int index) const;
CommandID GetNameByKey(const NormalizedKeyString & key) const;
int GetIndexByKey(const NormalizedKeyString & key) const;
NormalizedKeyString GetKey(int index) const;
bool CanSetKey(int index) const;
bool SetKey(int index, const NormalizedKeyString & key);
bool SetKeyByName(const CommandID & name, const NormalizedKeyString & key);
void SetView(ViewByType type);
void SetFilter(const wxString & filter);
void ExpandAll();
void CollapseAll();
void SelectNode(int index);
private:
void RecalcExtents();
void UpdateHScroll();
void RefreshLines(bool bSort = true);
int LineToIndex(int line) const;
int IndexToLine(int index) const;
void OnDrawBackground(wxDC & dc, const wxRect & rect, size_t line) const override;
void OnDrawItem(wxDC & dc, const wxRect & rect, size_t line) const override;
wxCoord OnMeasureItem(size_t line) const override;
void OnSelected(wxCommandEvent & event);
void OnSetFocus(wxFocusEvent & event);
void OnKillFocus(wxFocusEvent & event);
void OnSize(wxSizeEvent & event);
void OnScroll(wxScrollWinEvent & event);
void OnKeyDown(wxKeyEvent & event);
void OnLeftDown(wxMouseEvent & event);
static bool CmpKeyNodeByTree(KeyNode *n1, KeyNode *n2);
static bool CmpKeyNodeByName(KeyNode *n1, KeyNode *n2);
static bool CmpKeyNodeByKey(KeyNode *n1, KeyNode *n2);
#if wxUSE_ACCESSIBILITY
friend class KeyViewAx;
bool HasChildren(int line);
bool IsExpanded(int line);
wxCoord GetLineHeight(int line);
wxString GetValue(int line);
ViewByType GetViewType();
#endif
private:
std::vector<KeyNode> mNodes;
std::vector<KeyNode*> mLines;
ViewByType mViewType;
wxString mFilter;
wxCoord mScrollX;
wxCoord mWidth;
size_t mLineCount;
wxCoord mLineHeight;
wxCoord mKeyX;
int mCommandWidth;
wxCoord mKeyWidth;
#if wxUSE_ACCESSIBILITY
KeyViewAx *mAx;
#endif
DECLARE_EVENT_TABLE()
};
#endif