-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathKbdWnd.h
157 lines (135 loc) · 4.68 KB
/
KbdWnd.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
/*****************************************************************************/
/* KbdWnd.h : CKbdWnd declaration */
/*****************************************************************************/
/*
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 _KbdWnd_h__included_
#define _KbdWnd_h__included_
#include "KbdGuiLayout.h"
/*****************************************************************************/
/* CKbdWnd class declaration */
/*****************************************************************************/
class CKbdWnd : public wxPanel
{
public:
enum KeyState
{
ksUnpressed,
ksPressed,
ksReleased,
ksAlert,
ksLEDOn,
ksStates,
ksHighlighted = (1 << 3)
};
enum
{
// Timers
Kbd_Timer1 = 1,
};
struct KeyLayout
{
int rects;
wxRect rect[2];
KeyState state;
GuiKey const *def;
};
struct KeyClrs
{
// brushes for up to 2 rectangles
wxBrush &br1, &br2; // 1: key bkgnd 2: led bkgnd
wxPen &pen1, &pen2; // 1: boundary 2: rect overlap
};
public:
CKbdWnd(wxWindow *parent,
wxWindowID id = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxT("Keyboard"));
virtual ~CKbdWnd(void);
void SetLayout(KbdGui const &newlayout);
void SetKeyState(KeyLayout *key, int newstate, bool passOn = false);
void SetKeyState(int hidcode, int newstate, bool passOn = false)
{ SetKeyState(FindHID(hidcode), newstate, passOn); }
void SetKeyState(int matrixrow, int matrixcol, int newstate, bool passOn = false)
{ SetKeyState(FindMatrix(matrixrow, matrixcol), newstate, passOn); }
void ResetKeyState()
{
for (size_t i = 0; i < keys.size(); i++)
SetKeyState(&keys[i], ksUnpressed);
}
wxColour const &GetBkgndColour() { return clrBkgnd; }
void SetBkgndColour(wxColour const &newClr)
{
clrBkgnd = newClr;
Refresh();
}
wxColour const &GetColour(int ks)
{ return clrKey[ks & ~ksHighlighted][!!(ks & ksHighlighted)]; }
void SetColour(int ks, wxColour const &newClr)
{
clrKey[ks & ~ksHighlighted][!!(ks & ksHighlighted)] = newClr;
Refresh();
}
bool GetLEDStates() { return getLEDStates; }
void GetLEDStates(bool bOn) { getLEDStates = bOn; }
bool CapturingAllKeys() { return bAllKeys; }
void CaptureAllKeys(bool bOn = true);
KeyLayout *FindHID(int hidcode)
{ return hid2Key[hidcode]; }
KeyLayout *FindMatrix(int row, int col)
{ return matrix2Key[(row << 24) | col]; }
// Functionality to pass on GUI key events to keyboard window
void PassOnKeyDown(wxKeyEvent &ev);
void PassOnChar(wxKeyEvent &ev);
void PassOnKeyUp(wxKeyEvent &ev);
// Functionality to prohinit GUI key propagation
static void HookLLKeyboard(bool bOn = true); // needs a better name sometime
static void InhibitGuiKey(bool bOn = true);
private:
wxDECLARE_EVENT_TABLE();
void OnPaint(wxPaintEvent &ev);
void OnKeyDown(wxKeyEvent &);
void OnChar(wxKeyEvent &);
void OnKeyUp(wxKeyEvent &);
void OnLButtonDown(wxMouseEvent& event);
void OnReadLEDTimer(wxTimerEvent& event);
protected:
#ifdef __WXMSW__
virtual WXLRESULT
MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
#endif // __WXMSW__
void DrawKey(wxDC &dc, KeyLayout const &key, KeyClrs const &clrs);
void RefreshKey(KeyLayout *key)
{
RefreshRect(key->rect[0]);
RefreshRect(key->rect[1]);
// Update();
}
protected:
KbdGui layout;
wxVector<KeyLayout> keys;
WX_DECLARE_HASH_MAP(wxUint32, KeyLayout *, wxIntegerHash, wxIntegerEqual, KbdIndex2Key);
KbdIndex2Key hid2Key;
KbdIndex2Key matrix2Key;
wxColour clrBkgnd, clrBorder;
wxColour clrKey[ksStates][2];
wxFont keyFont;
wxTimer t;
bool bLEDState[3], getLEDStates;
bool bAllKeys;
protected:
wxSize CalcLayout(wxSize sz);
};
#endif // defined(_KbdWnd_h__included_)