author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Wed, 08 Feb 2017 23:58:18 +0000 | |
branch | jv |
changeset 7969 | 2bac4f32553f |
parent 7856 | 7c52e7a9a087 |
child 8035 | 8bbd397fe321 |
permissions | -rw-r--r-- |
0 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
72 | 3 |
All Rights Reserved |
0 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
5280 | 12 |
"{ Package: 'stx:libview' }" |
0 | 13 |
|
7856
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
14 |
"{ NameSpace: Smalltalk }" |
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
15 |
|
244 | 16 |
IdentityDictionary subclass:#KeyboardMap |
7856
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
17 |
instanceVariableNames:'parent current' |
598 | 18 |
classVariableNames:'' |
19 |
poolDictionaries:'' |
|
5280 | 20 |
category:'Interface-Support-UI' |
0 | 21 |
! |
22 |
||
46 | 23 |
!KeyboardMap class methodsFor:'documentation'! |
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
72 | 28 |
All Rights Reserved |
0 | 29 |
|
46 | 30 |
This software is furnished under a license and may be used |
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
0 | 38 |
|
46 | 39 |
documentation |
40 |
" |
|
7856
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
41 |
Instances of KeyboardMap are used for mapping keystrokes AND sequences |
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
42 |
of keystrokes to a logical function which is used by UI code. For |
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
43 |
example, it maps #Ctrls to #Accept logical function which is then |
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
44 |
used menu items and so on. |
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
45 |
|
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
46 |
This allows for changing a shortcut without changing the code. |
89 | 47 |
|
7856
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
48 |
Keyboard maps may chained together, if a mapping is not found in |
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
49 |
a particular key map, lookup continues in its parent map (if any). |
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
50 |
Usually the grand-parent is device's standard map, see |
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
51 |
DeviceWorkstation >> keyboardMap (but not necessarily!!) |
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
52 |
|
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
53 |
The setup of device's map is done in the 'smalltalk.rc' or one of the |
6663 | 54 |
'keyboard.rc' files during startup. |
7856
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
55 |
|
89 | 56 |
To add a mapping (for example, to attach the logical function 'DoIt' to |
57 |
the key-combination Cmd-'d'): |
|
58 |
||
598 | 59 |
|m| |
89 | 60 |
|
598 | 61 |
m := Display keyboardMap. |
62 |
m bindValue:#DoIt to:#Cmdd. |
|
89 | 63 |
|
64 |
Key sequences can also be defined (hey emacs fans ;-) as in: |
|
65 |
||
598 | 66 |
|m| |
89 | 67 |
|
598 | 68 |
m := Display keyboardMap. |
69 |
m bindValue:#DoIt to:#Ctrlx followedBy:#Ctrld |
|
89 | 70 |
|
71 |
Key prefixes are defined in the DeviceWorkstation>>translateKey: method. |
|
72 |
Typical prefixes are Cmd (for Alt or Meta), Ctrl etc. |
|
73 |
Some keyboards offer both Alt and Meta keys - on those, the first has a |
|
74 |
prefix of Alt, the second has Cmd as prefix. Keyboards with only an Alt |
|
75 |
key will will create prefix codes of Cmd for that. |
|
76 |
||
77 |
To remove a mapping, use the same value for both logical and physical key, |
|
78 |
as in: |
|
79 |
||
598 | 80 |
|m| |
89 | 81 |
|
598 | 82 |
m := Display keyboardMap. |
83 |
m bindValue:#Cmdd to:#Cmdd. |
|
84 |
||
85 |
[see also:] |
|
86 |
WindowEvent WindowSensor WindowGroup |
|
87 |
View DeviceWorkstation |
|
612 | 88 |
|
89 |
[author:] |
|
90 |
Claus Gittinger |
|
46 | 91 |
" |
92 |
! ! |
|
0 | 93 |
|
94 |
!KeyboardMap methodsFor:'accessing'! |
|
95 |
||
89 | 96 |
bindValue:logicalKey to:aKey |
598 | 97 |
"bind aLogicalKey to a rawKey. |
98 |
The event mechanism uses this to pass logical keyboard events |
|
99 |
to the application (such as #Copy, #Cut etc.) |
|
100 |
instead of physical ones (such as #AltC, #AltX)" |
|
101 |
||
89 | 102 |
aKey == logicalKey ifTrue:[ |
1120 | 103 |
self removeKey:aKey ifAbsent:nil |
89 | 104 |
] ifFalse:[ |
598 | 105 |
self at:aKey put:logicalKey |
89 | 106 |
] |
598 | 107 |
|
1120 | 108 |
"Modified: 12.11.1996 / 10:30:56 / cg" |
0 | 109 |
! |
110 |
||
89 | 111 |
bindValue:logicalKey to:key1 followedBy:key2 |
598 | 112 |
"bind aLogicalKey to a sequence of two rawKeys. |
113 |
The event mechanism uses this to pass logical keyboard events |
|
114 |
to the application (such as #Copy, #Cut etc.) |
|
115 |
instead of physical ones (such as #AltC, #AltX)" |
|
116 |
||
0 | 117 |
|submap| |
118 |
||
89 | 119 |
submap := self at:key1 ifAbsent:[]. |
0 | 120 |
submap isNil ifTrue:[ |
598 | 121 |
submap := KeyboardMap new. |
122 |
self at:key1 put:submap. |
|
0 | 123 |
]. |
89 | 124 |
submap at:key2 put:logicalKey |
598 | 125 |
|
126 |
"Modified: 23.4.1996 / 21:55:04 / cg" |
|
0 | 127 |
! |
128 |
||
6556 | 129 |
hasBindingFor:aKey |
130 |
"retrieve a logical key" |
|
131 |
||
7856
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
132 |
current notNil ifTrue:[ |
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
133 |
^ current includesKey:aKey |
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
134 |
]. |
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
135 |
(self includesKey:aKey) ifTrue:[ ^ true ]. |
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
136 |
parent notNil ifTrue:[ |
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
137 |
parent hasBindingFor:aKey |
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
138 |
]. |
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
139 |
^ false |
6556 | 140 |
|
7856
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
141 |
"Modified: / 02-02-2017 / 00:13:32 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
142 |
! |
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
143 |
|
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
144 |
parent |
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
145 |
^ parent |
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
146 |
! |
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
147 |
|
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
148 |
parent:aKeyboardMap |
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
149 |
parent := aKeyboardMap. |
6556 | 150 |
! |
151 |
||
7969
2bac4f32553f
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7856
diff
changeset
|
152 |
rawKeysForLogical: logicalKey |
2bac4f32553f
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7856
diff
changeset
|
153 |
"Return all raw keys for given )possibly) logical key. |
2bac4f32553f
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7856
diff
changeset
|
154 |
Example: |
2bac4f32553f
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7856
diff
changeset
|
155 |
#Copy -> #(Ctrlc) - depending on mappings |
2bac4f32553f
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7856
diff
changeset
|
156 |
" |
2bac4f32553f
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7856
diff
changeset
|
157 |
| map rawKeys | |
2bac4f32553f
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7856
diff
changeset
|
158 |
|
2bac4f32553f
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7856
diff
changeset
|
159 |
map := self. |
2bac4f32553f
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7856
diff
changeset
|
160 |
rawKeys := #(). |
2bac4f32553f
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7856
diff
changeset
|
161 |
[ rawKeys isEmpty and:[ map notNil ] ] whileTrue:[ |
2bac4f32553f
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7856
diff
changeset
|
162 |
map keysAndValuesDo:[ :raw :logical | logical == logicalKey ifTrue:[ rawKeys := rawKeys copyWith: raw ] ]. |
2bac4f32553f
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7856
diff
changeset
|
163 |
map := map parent. |
2bac4f32553f
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7856
diff
changeset
|
164 |
]. |
2bac4f32553f
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7856
diff
changeset
|
165 |
^ rawKeys |
2bac4f32553f
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7856
diff
changeset
|
166 |
|
2bac4f32553f
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7856
diff
changeset
|
167 |
" |
2bac4f32553f
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7856
diff
changeset
|
168 |
Screen current keyboardMap rawKeysForLogical: #Copy |
2bac4f32553f
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7856
diff
changeset
|
169 |
" |
2bac4f32553f
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7856
diff
changeset
|
170 |
|
2bac4f32553f
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7856
diff
changeset
|
171 |
"Created: / 08-02-2017 / 23:43:26 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2bac4f32553f
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7856
diff
changeset
|
172 |
! |
2bac4f32553f
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7856
diff
changeset
|
173 |
|
0 | 174 |
valueFor:aKey |
598 | 175 |
"retrieve a logical key" |
176 |
||
6556 | 177 |
|whichMap value| |
0 | 178 |
|
6556 | 179 |
whichMap := (current notNil ifTrue:[current] ifFalse:[self]). |
0 | 180 |
|
7856
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
181 |
value := whichMap at:aKey ifAbsent:[ nil ]. |
0 | 182 |
(value isMemberOf:KeyboardMap) ifTrue:[ |
598 | 183 |
current := value. |
184 |
^ nil. |
|
0 | 185 |
]. |
186 |
current := nil. |
|
7856
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
187 |
value isNil ifTrue:[ |
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
188 |
parent notNil ifTrue:[ |
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
189 |
^ parent valueFor: aKey |
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
190 |
]. |
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
191 |
"/ No mapping for given key, return it unmapped |
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
192 |
^ aKey |
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
193 |
]. |
0 | 194 |
^ value |
598 | 195 |
|
7856
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
196 |
"Modified: / 23-04-1996 / 21:55:22 / cg" |
7c52e7a9a087
Allow individual applications to define their own shortcut mapping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6663
diff
changeset
|
197 |
"Modified: / 04-02-2017 / 22:24:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
0 | 198 |
! ! |
244 | 199 |
|
251 | 200 |
!KeyboardMap class methodsFor:'documentation'! |
201 |
||
202 |
version |
|
6663 | 203 |
^ '$Header: /cvs/stx/stx/libview/KeyboardMap.st,v 1.15 2014-12-18 16:13:06 cg Exp $' |
251 | 204 |
! ! |
6556 | 205 |