Laxkit
0.0.7.1
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
lax
shortcuts.h
1
//
2
//
3
// The Laxkit, a windowing toolkit
4
// Please consult http://laxkit.sourceforge.net about where to send any
5
// correspondence about this software.
6
//
7
// This library is free software; you can redistribute it and/or
8
// modify it under the terms of the GNU Library General Public
9
// License as published by the Free Software Foundation; either
10
// version 2 of the License, or (at your option) any later version.
11
//
12
// This library is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
// Library General Public License for more details.
16
//
17
// You should have received a copy of the GNU Library General Public
18
// License along with this library; if not, write to the Free Software
19
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
//
21
// Copyright (C) 2010-2012 by Tom Lechner
22
//
23
#ifndef _LAX_SHORTCUT_H
24
#define _LAX_SHORTCUT_H
25
26
27
#include <cstdlib>
28
29
#include <lax/lists.h>
30
#include <lax/anobject.h>
31
#include <lax/refptrstack.h>
32
#include <lax/tagged.h>
33
#include <lax/dump.h>
34
35
36
namespace
Laxkit {
37
38
//----------------------------------- KeyInfo ------------------------------------
39
class
KeyInfo
40
{
41
public
:
42
unsigned
int
key;
43
unsigned
long
state
;
44
clock_t time;
45
KeyInfo
*next;
46
KeyInfo
(
unsigned
int
k,
unsigned
int
mods, clock_t t) : key(k),
state
(mods), time(t), next(NULL) {}
47
KeyInfo
() : key(0),
state
(0), time(0), next(NULL) {}
48
virtual
~KeyInfo() {
if
(next)
delete
next; }
49
};
50
51
52
//----------------------------------- ShortcutDef ------------------------------------
53
class
ShortcutDef
54
{
55
public
:
56
KeyInfo
*keys;
57
int
mode;
//this shortcut only activated when win_mode==mode
58
int
action;
59
60
ShortcutDef
(
unsigned
int
key,
unsigned
int
state,
int
a,
int
m=-1);
61
virtual
~
ShortcutDef
();
62
virtual
int
match
(
unsigned
int
key,
unsigned
int
state);
63
};
64
65
//----------------------------------- ShortcutDefs ------------------------------------
66
class
ShortcutDefs
:
public
PtrStack
<ShortcutDef>,
public
anObject
67
{
68
public
:
69
char
*name;
70
char
*description;
71
ShortcutDefs
();
72
virtual
~
ShortcutDefs
();
73
virtual
int
Add(
unsigned
int
key,
unsigned
int
state,
int
a,
int
m=-1);
74
virtual
ShortcutDef
*
FindShortcutFromAction
(
int
action,
int
startingfrom);
75
};
76
77
78
//----------------------------------- WindowAction ------------------------------------
79
class
WindowAction
:
public
Tagged
80
{
81
public
:
82
int
id;
// <- corresponds to shortcut->action
83
char
*name;
//such as for a menu line
84
char
*description;
//short description
85
char
*iconname;
86
int
mode;
//win_mode window must be in for action to be acted on
87
int
assignable;
//whether to not allow keys to directly bind to them, or be visible to user in menus
88
char
*
customcode
;
89
90
WindowAction
(
int
nid,
const
char
*nname,
const
char
*desc,
const
char
*icon,
int
nmode,
int
assign);
91
virtual
~
WindowAction
();
92
};
93
94
//---------------------------------- WindowModeInfo ------------------------------------------
95
class
WindowModeInfo
96
{
97
public
:
98
int
mode;
99
char
*mode_str;
100
char
*name;
101
char
*description;
102
WindowModeInfo
(
int
m,
const
char
*modestr,
const
char
*Name,
const
char
*desc);
103
virtual
~
WindowModeInfo
();
104
};
105
106
//----------------------------------- WindowActions ------------------------------------
107
class
WindowActions
:
public
anObject
,
public
PtrStack
<WindowAction>
108
{
109
public
:
110
char
*name;
111
char
*description;
112
ShortcutDefs
*default_shortcuts;
113
PtrStack<WindowModeInfo>
modes;
114
WindowActions
();
115
virtual
~
WindowActions
();
116
virtual
const
char
*Name() {
return
object_idstr; }
117
virtual
int
Add(
int
nid,
const
char
*nname,
const
char
*desc,
const
char
*icon,
int
nmode,
int
assign);
118
virtual
int
AddMode(
int
mode,
const
char
*modestr,
const
char
*name,
const
char
*desc);
119
virtual
WindowAction
*
FindAction
(
int
action);
120
};
121
122
123
//----------------------------------- ShortcutHandler ------------------------------------
124
class
ShortcutHandler
:
public
Laxkit::anObject
125
{
126
protected
:
127
ShortcutDefs
*shortcuts;
128
WindowActions
*actions;
129
130
int
index;
//which is the active shortcut
131
int
keyindex;
//how far into a shortcut chain to look
132
int
deviceid;
//id of the active keyboard
133
public
:
134
char
*area;
135
136
ShortcutHandler
(
const
char
*areaname=NULL,
ShortcutDefs
*cuts=NULL,
WindowActions
*wactions=NULL);
137
virtual
~
ShortcutHandler
();
138
virtual
ShortcutHandler
*
duplicate
();
139
140
virtual
int
NumActions();
141
virtual
WindowAction
*
Action
(
int
i);
142
virtual
WindowActions
*Actions();
143
virtual
WindowAction
*
FindAction
(
unsigned
int
key,
unsigned
int
state,
int
mode);
144
virtual
int
FindActionNumber
(
unsigned
int
key,
unsigned
int
state,
int
mode);
145
virtual
int
FindActionNumber
(
const
char
*actionname,
int
len=-1);
146
147
virtual
int
NumShortcuts();
148
virtual
ShortcutDef
*
Shortcut
(
int
i);
149
virtual
ShortcutDefs
*Shortcuts();
150
virtual
int
FindShortcutIndex
(
unsigned
int
key,
unsigned
int
state,
int
mode);
151
virtual
int
FindShortcutFromAction(
int
action,
int
startingfrom);
152
virtual
int
InstallShortcuts(
ShortcutDefs
*cuts);
153
154
virtual
int
AddMode(
int
mode,
const
char
*modestr,
const
char
*name,
const
char
*desc);
155
virtual
int
AddShortcut
(
unsigned
int
key,
unsigned
int
state,
unsigned
int
mode,
unsigned
int
action);
156
//virtual int AddShortcutChain(const char *keys, unsigned int *states, int n, unsigned int action, unsigned int mode);
157
virtual
unsigned
int
AddAction
(
unsigned
int
action,
const
char
*nname,
const
char
*desc,
const
char
*icon,
unsigned
int
mode,
int
assign);
158
virtual
unsigned
int
Add
(
unsigned
int
action,
unsigned
int
key,
unsigned
int
state,
unsigned
int
mode,
159
const
char
*nname,
const
char
*desc,
const
char
*icon,
int
assign);
160
virtual
int
RemoveAction
(
int
action);
161
virtual
int
ClearShortcut(
unsigned
int
key,
unsigned
int
state,
int
mode);
162
virtual
int
ClearShortcut(
int
i);
163
virtual
int
UpdateKey
(
unsigned
int
key,
unsigned
int
state,
unsigned
int
mode,
unsigned
int
newaction);
164
virtual
int
ReassignKey
(
unsigned
int
newkey,
unsigned
int
newstate,
165
unsigned
int
oldkey,
unsigned
int
oldstate,
166
unsigned
int
mode,
unsigned
int
action);
167
};
168
169
//--------------------------------- ShortcutManager ------------------------------------
170
class
ShortcutManager
:
public
LaxFiles::DumpUtility
,
public
anObject
171
{
172
protected
:
173
174
public
:
175
char
*setname, *setfile;
176
LaxFiles::Attribute
tree;
177
RefPtrStack<ShortcutHandler>
shortcuts;
178
// map zone -- ShortcutHandler
179
180
ShortcutManager
();
181
virtual
~
ShortcutManager
();
182
183
virtual
int
AddArea
(
const
char
*area,
ShortcutDefs
*cuts,
WindowActions
*actions);
184
virtual
int
AddArea
(
const
char
*area,
ShortcutHandler
*handler);
185
virtual
int
AreaParent(
const
char
*area,
const
char
*parent);
186
virtual
ShortcutHandler
*
NewHandler
(
const
char
*area);
187
virtual
ShortcutHandler
*
FindHandler
(
const
char
*area);
188
189
virtual
int
Load
(
const
char
*file=NULL);
190
virtual
int
LoadKeysOnly
(
const
char
*file);
191
virtual
int
Save
(
const
char
*file=NULL,
const
char
*header=NULL);
192
virtual
int
SaveHTML(
const
char
*file=NULL);
193
virtual
void
dump_out
(FILE *f,
int
indent,
int
what,
Laxkit::anObject
*savecontext);
194
virtual
void
dump_in_atts
(
LaxFiles::Attribute
*att,
int
flag,
Laxkit::anObject
*loadcontext);
195
virtual
char
*
ShortcutString
(
ShortcutDef
*def,
char
*buffer);
196
virtual
char
*
ShortcutString
(
unsigned
int
key,
unsigned
long
state,
char
*buffer);
197
virtual
int
KeyAndState
(
const
char
*str,
unsigned
int
*key,
unsigned
int
*state);
198
199
virtual
int
ClearKeys
();
200
virtual
int
UpdateKey
(
const
char
*area,
unsigned
int
key,
unsigned
int
state,
unsigned
int
mode,
unsigned
int
newaction);
201
virtual
int
ReassignKey(
const
char
*area,
unsigned
int
newkey,
unsigned
int
newstate,
202
unsigned
int
oldkey,
unsigned
int
oldstate,
203
unsigned
int
mode,
unsigned
int
action);
204
};
205
206
void
InstallShortcutManager
(
ShortcutManager
*manager);
207
ShortcutManager
*
GetDefaultShortcutManager
();
208
void
FinalizeShortcutManager
();
209
210
211
}
//namespace Laxkit
212
213
#endif //_LAX_SHORTCUT_H
214
Mon Feb 17 2014 11:52:57, Laxkit