-
Notifications
You must be signed in to change notification settings - Fork 2
/
MainFrm.h
264 lines (218 loc) · 8.47 KB
/
MainFrm.h
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/*****************************************************************************/
/* MainFrm.h : interface of the CMainFrame class */
/*****************************************************************************/
/*
Copyright (C) 2019 Hermann Seib
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, version 3.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef _MainFrm_h__included_
#define _MainFrm_h__included_
#include "KbdGuiLayout.h"
#include "MatrixWnd.h"
#include "KbdWnd.h"
/*===========================================================================*/
/* Constants */
/*===========================================================================*/
// menu commands and controls ids
enum
{
// file menu
Blusb_Quit = wxID_EXIT,
Blusb_About = wxID_ABOUT,
// Timers
Blusb_Timer1 = 1,
// navigation menu
Blusb_TabForward = 200,
Blusb_TabBackward,
Blusb_LayerCount,
Blusb_Debounce,
Blusb_PwmUsb,
Blusb_PwmBt,
Blusb_ResetLayout,
Blusb_ReadLayout,
Blusb_WriteLayout,
Blusb_ReadFile,
Blusb_WriteFile,
Blusb_ServiceMode,
Blusb_Kbd_ANSI,
Blusb_Kbd_ISO,
Blusb_Kbd_ANSI121,
Blusb_Kbd_ISO122,
Blusb_Kbd_Reset,
Blusb_Kbd_Load,
Blusb_Kbd_Save,
Blusb_Max
};
/*****************************************************************************/
/* CMatrixPanel : a matrix panel and its associated matrix window */
/*****************************************************************************/
class CKbdWnd;
class CMatrixPanel : public wxPanel
{
public:
CMatrixPanel(wxWindow *parent,
int numRows = NUMROWS, int numCols = NUMCOLS,
wxWindowID winid = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxTAB_TRAVERSAL | wxNO_BORDER,
const wxString& name = wxPanelNameStr)
: wxPanel(parent, winid, pos, size, style, name)
{
pMatrix = new CMatrixWnd(this, numRows, numCols);
szMatrix = pMatrix->GetMinSize();
}
CMatrixWnd *GetMatrix() { return pMatrix; }
void SetLayer(int layer) { pMatrix->SetLayer(layer); }
int GetLayer() { return pMatrix->GetLayer(); }
void SetKbdMatrix(KbdMatrix const &kbm)
{ pMatrix->SetKbdMatrix(kbm); }
void SelectMatrix(int row, int col)
{ pMatrix->SelectMatrix(row, col); }
void SetKbdWnd(CKbdWnd *pKbdWnd = NULL)
{ pMatrix->SetKbdWnd(pKbdWnd); }
bool Layout();
protected:
CMatrixWnd *pMatrix;
wxSize szMatrix;
};
/*****************************************************************************/
/* CKbdPanel : panel containing the on-screen keyboard and associated buttons*/
/*****************************************************************************/
class CKbdPanel : public wxPanel
{
public:
CKbdPanel(wxWindow *parent,
wxWindowID winid = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxTAB_TRAVERSAL | wxNO_BORDER,
const wxString& name = wxPanelNameStr);
CKbdWnd *GetKbdWnd() { return pKbd; }
void SetKbdLayout(KbdGui const &newlayout)
{ pKbd->SetLayout(newlayout); }
void SetKeyState(int hidcode, int newstate)
{ if (pKbd) pKbd->SetKeyState(hidcode, newstate); }
void SetKeyState(int matrixrow, int matrixcol, int newstate)
{ if (pKbd) pKbd->SetKeyState(matrixrow, matrixcol, newstate); }
void ResetKeyState()
{ if (pKbd) pKbd->ResetKeyState(); }
wxColour const &GetKbdBkgndColour()
{ return pKbd->GetBkgndColour(); }
void SetKbdBkgndColour(wxColour const &newClr)
{ pKbd->SetBkgndColour(newClr); }
wxColour const &GetKbdColour(int ks)
{ return pKbd->GetColour(ks); }
void SetKbdColour(int ks, wxColour const &newClr)
{ pKbd->SetColour(ks, newClr); }
bool Layout();
protected:
CKbdWnd *pKbd;
wxSize szKbd;
};
/*****************************************************************************/
/* CMainPanel : panel on main window */
/*****************************************************************************/
class CMainPanel : public wxPanel
{
public:
CMainPanel(wxWindow *parent);
int GetLayerChoice() { return pLayers->GetSelection() + 1; }
int GetLayers() { return (int)matrices.size(); }
bool SetLayers(int nLayers, bool resetExisting = false);
int GetDebounce() { return pDebounce ? (pDebounce->GetSelection() + 1) : 0; }
int GetPwmUsb() { return pPwmUsb ? pPwmUsb->GetSelection() : 0; }
int GetPwmBt() { return pPwmBt ? pPwmBt->GetSelection() : 0; }
void SetKbdLayout(KbdLayout &layout);
void SetKbdGuiLayout(KbdGui &layout)
{
pKbd->SetKbdLayout(layout);
kbdGuiLayout = layout;
}
KbdGui &GetKbdGuiLayout() { return kbdGuiLayout; }
void SelectMatrix(int row, int col);
void SetKeyState(int hidcode, int newstate)
{ if (pKbd) pKbd->SetKeyState(hidcode, newstate); }
void SetKeyState(int matrixrow, int matrixcol, int newstate)
{ if (pKbd) pKbd->SetKeyState(matrixrow, matrixcol, newstate); }
void ResetKeyState()
{ if (pKbd) pKbd->ResetKeyState(); }
protected:
CMatrixPanel *CreateMatrixPage(wxWindow *parent,
int numRows = NUMROWS, int numCols = NUMCOLS);
wxChoice *pLayers;
wxChoice *pDebounce;
wxChoice *pPwmUsb, *pPwmBt;
wxNotebook *pMatrixNotebook;
wxVector<CMatrixPanel *> matrices;
CKbdPanel *pKbd;
KbdGui kbdGuiLayout;
};
/*****************************************************************************/
/* CMainFrame : main frame window class */
/*****************************************************************************/
class CMainFrame : public wxFrame
{
public:
CMainFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
private:
wxDECLARE_EVENT_TABLE();
private:
void OnKeyDown(wxKeyEvent &);
void OnChar(wxKeyEvent &);
void OnKeyUp(wxKeyEvent &);
// void OnHello(wxCommandEvent& event);
void OnExit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
void OnClose(wxCloseEvent &event);
void OnReadMatrixTimer(wxTimerEvent& event);
void OnLayerCount(wxCommandEvent& event);
void OnDebounce(wxCommandEvent& event);
void OnPwmUsb(wxCommandEvent& event);
void OnPwmBt(wxCommandEvent& event);
void OnReset(wxCommandEvent& event);
void OnReadLayout(wxCommandEvent& event);
void OnUpdateReadLayout(wxUpdateUIEvent& event);
void OnWriteLayout(wxCommandEvent& event);
void OnUpdateWriteLayout(wxUpdateUIEvent& event);
void OnServiceMode(wxCommandEvent& event);
void OnUpdateServiceMode(wxUpdateUIEvent& event);
void OnReadFile(wxCommandEvent& event);
void OnWriteFile(wxCommandEvent& event);
void OnKbdANSI(wxCommandEvent& event);
void OnUpdateKbdANSI(wxUpdateUIEvent& event);
void OnKbdISO(wxCommandEvent& event);
void OnUpdateKbdISO(wxUpdateUIEvent& event);
void OnKbdANSI121(wxCommandEvent& event);
void OnUpdateKbdANSI121(wxUpdateUIEvent& event);
void OnKbdISO122(wxCommandEvent& event);
void OnUpdateKbdISO122(wxUpdateUIEvent& event);
void OnKbdReset(wxCommandEvent& event);
void OnKbdLoad(wxCommandEvent& event);
void OnKbdSave(wxCommandEvent& event);
public:
void SetKbdLayout(KbdLayout &layout)
{ if (m_panel) m_panel->SetKbdLayout(layout); }
bool SetKbdGuiLayout(KbdGui &layout);
void SelectMatrix(int row, int col)
{ if (m_panel) m_panel->SelectMatrix(row, col); }
void SetKeyState(int hidcode, int newstate)
{ if (m_panel) m_panel->SetKeyState(hidcode, newstate); }
void SetKeyState(int matrixrow, int matrixcol, int newstate)
{ if (m_panel) m_panel->SetKeyState(matrixrow, matrixcol, newstate); }
void ResetKeyState()
{ if (m_panel) m_panel->ResetKeyState(); }
private:
CMainPanel *m_panel;
wxTimer t;
wxUint8 bufferLast[8];
};
#endif // defined(_MainFrm_h__included_)