-
Notifications
You must be signed in to change notification settings - Fork 0
/
KeyboardDialog.h
277 lines (227 loc) · 10.4 KB
/
KeyboardDialog.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
265
266
267
268
269
270
271
272
273
274
275
276
277
/***********************************************************************
KeyboardDialog - Vrui PopupWindow which implements a keyboard
interface.
Copyright (c) 2008 Voltaic
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; either version 2 of the License, or (at your
option) any later version.
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, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***********************************************************************/
#ifndef KEYBOARDDIALOG_INCLUDED
#define KEYBOARDDIALOG_INCLUDED
#include <string>
#include <Misc/Time.h>
#include <Vrui/Vrui.h>
#include <GLMotif/PopupWindow.h>
#include <GLMotif/Label.h>
#include <GLMotif/Button.h>
#include <GLMotif/ToggleButton.h>
namespace Voltaic {
class KeyboardDialog :
public GLMotif::PopupWindow
{
public:
enum
{
MODIFIER_BIT_SHIFT = 0x01,
MODIFIER_BIT_CONTROL = 0x02,
MODIFIER_BIT_ALT = 0x04,
MODIFIER_BIT_PLATFORM = 0x08,
MODIFIER_KEY_VARIATIONS = 16
};
public:
class KeyValueDef
{
public:
typedef uint32_t keysym_t;
public:
KeyValueDef( keysym_t v____, keysym_t v___S = 0, keysym_t v__C_ = 0, keysym_t v__CS = 0,
keysym_t v_A__ = 0, keysym_t v_A_S = 0, keysym_t v_AC_ = 0, keysym_t v_ACS = 0,
keysym_t vP___ = 0, keysym_t vP__S = 0, keysym_t vP_C_ = 0, keysym_t vP_CS = 0,
keysym_t vPA__ = 0, keysym_t vPA_S = 0, keysym_t vPAC_ = 0, keysym_t vPACS = 0 );
public:
keysym_t getKeysym(unsigned modifierMask) const { return values[modifierMask]; }
char getChar(unsigned modifierMask) const
{
const keysym_t keysym = getKeysym(modifierMask);
return (keysym > 0xff) ? (char)0 : (char)(keysym & 0xff);
}
protected:
keysym_t values[MODIFIER_KEY_VARIATIONS];
};
public:
class KeyButton : public GLMotif::Button
{
public:
KeyButton( const char* name,
GLMotif::Container* parent,
KeyboardDialog& keyboard,
bool repeatable );
virtual ~KeyButton();
protected:
virtual void armCallback(GLMotif::Button::ArmCallbackData* cbData); // for repeatable keys
void selectCallback(GLMotif::Button::SelectCallbackData* cbData); // for nonrepeatable keys
virtual void fire() = 0;
protected:
KeyboardDialog& keyboard;
const bool repeatable;
bool keyArmed;
Misc::Time keyArmTime;
double lastKeyFireTimeDelta;
};
class ValueKeyButton : public KeyButton
{
public:
ValueKeyButton( const char* name,
GLMotif::Container* parent,
KeyboardDialog& keyboard,
bool repeatable,
KeyValueDef::keysym_t v____, KeyValueDef::keysym_t v___S = 0, KeyValueDef::keysym_t v__C_ = 0, KeyValueDef::keysym_t v__CS = 0,
KeyValueDef::keysym_t v_A__ = 0, KeyValueDef::keysym_t v_A_S = 0, KeyValueDef::keysym_t v_AC_ = 0, KeyValueDef::keysym_t v_ACS = 0,
KeyValueDef::keysym_t vP___ = 0, KeyValueDef::keysym_t vP__S = 0, KeyValueDef::keysym_t vP_C_ = 0, KeyValueDef::keysym_t vP_CS = 0,
KeyValueDef::keysym_t vPA__ = 0, KeyValueDef::keysym_t vPA_S = 0, KeyValueDef::keysym_t vPAC_ = 0, KeyValueDef::keysym_t vPACS = 0 );
protected:
virtual void fire();
protected:
KeyValueDef valueDef;
};
class UpdatingValueKeyButton : public ValueKeyButton
{
public:
UpdatingValueKeyButton( const char* name,
GLMotif::Container* parent,
KeyboardDialog& keyboard,
bool repeatable,
KeyValueDef::keysym_t v____, KeyValueDef::keysym_t v___S = 0, KeyValueDef::keysym_t v__C_ = 0, KeyValueDef::keysym_t v__CS = 0,
KeyValueDef::keysym_t v_A__ = 0, KeyValueDef::keysym_t v_A_S = 0, KeyValueDef::keysym_t v_AC_ = 0, KeyValueDef::keysym_t v_ACS = 0,
KeyValueDef::keysym_t vP___ = 0, KeyValueDef::keysym_t vP__S = 0, KeyValueDef::keysym_t vP_C_ = 0, KeyValueDef::keysym_t vP_CS = 0,
KeyValueDef::keysym_t vPA__ = 0, KeyValueDef::keysym_t vPA_S = 0, KeyValueDef::keysym_t vPAC_ = 0, KeyValueDef::keysym_t vPACS = 0 );
public:
virtual void updateFromModifierMask(unsigned modifierMask);
};
class ActionKeyButton : public KeyButton
{
public:
ActionKeyButton( const char* name,
GLMotif::Container* parent,
KeyboardDialog& keyboard,
bool repeatable,
void (KeyboardDialog::*action)() );
protected:
virtual void fire();
protected:
void (KeyboardDialog::* action)();
};
class ModifierKeyButton : public GLMotif::ToggleButton
{
public:
class UpdateValueKeyButtonFunctor
{
protected:
const unsigned modifierMask;
public:
UpdateValueKeyButtonFunctor(unsigned modifierMask) :
modifierMask(modifierMask)
{
}
virtual void operator()(GLMotif::Widget* widget) const;
};
public:
ModifierKeyButton( const char* name,
GLMotif::Container* parent,
KeyboardDialog& keyboard,
bool& modifierFlag );
protected:
virtual void selectCallback(GLMotif::Button::SelectCallbackData* cbData);
protected:
KeyboardDialog& keyboard;
bool& modifierFlag;
};
class SwitchButton : public GLMotif::ToggleButton
{
public:
SwitchButton( const char* name,
GLMotif::Container* parent,
KeyboardDialog& keyboard,
bool& switchFlag,
void (KeyboardDialog::*updateAction)() );
protected:
virtual void selectCallback(GLMotif::Button::SelectCallbackData* cbData);
protected:
KeyboardDialog& keyboard;
bool& switchFlag;
void (KeyboardDialog::*updateAction)();
};
friend class ValueKeyButton;
friend class ModifierKeyButton;
friend class ActionKeyButton;
friend class SwitchButton;
public:
class CompletionCallback
{
public:
virtual void keyboardDialogDidComplete(KeyboardDialog& keyboardDialog, bool cancelled) = 0;
};
public:
KeyboardDialog( const char* name,
GLMotif::WidgetManager* manager,
const char* titleString,
const char* initialValue = 0,
double autoRepeatDelay = 0.5,
double autoRepeatInterval = 0.25 );
virtual ~KeyboardDialog();
public:
virtual void activate( CompletionCallback& theCompletionCallback,
bool theObscureEntryFlag = false );
const std::string& getBuffer() const { return buffer; }
unsigned getModifierMask() const
{
return (unsigned)( (shiftKeyDown ? MODIFIER_BIT_SHIFT : 0) |
(controlKeyDown ? MODIFIER_BIT_CONTROL : 0) |
(altKeyDown ? MODIFIER_BIT_ALT : 0) |
(platformKeyDown ? MODIFIER_BIT_PLATFORM : 0) );
}
public:
double getAutoRepeatDelay() const { return autoRepeatDelay; }
virtual void setAutoRepeatDelay(double value);
double getAutoRepeatInterval() const { return autoRepeatInterval; }
virtual void setAutoRepeatInterval(double value);
protected:
virtual void updateDisplay();
virtual void addChar(char ch);
virtual void backspace();
virtual void reset();
virtual void clear();
virtual void submit(); // causes callback to be called with cancelled = false
virtual void cancel(); // causes callback to be called with cancelled = true
protected:
double autoRepeatDelay;
double autoRepeatInterval;
CompletionCallback* completionCallback; // 0 ==> inactive
bool obscureEntry;
bool shiftKeyDown;
bool controlKeyDown;
bool altKeyDown;
bool platformKeyDown;
SwitchButton* obscureEntryToggle;
ModifierKeyButton* leftShiftToggle;
ModifierKeyButton* rightShiftToggle;
ModifierKeyButton* controlToggle;
ModifierKeyButton* altToggle;
ModifierKeyButton* platformToggle;
GLMotif::Label* display;
std::string buffer;
private:
// Disable these copiers:
KeyboardDialog& operator=(const KeyboardDialog&);
KeyboardDialog(const KeyboardDialog&);
};
} // end of namespace Voltaic
#endif // KEYBOARDDIALOG_INCLUDED