author | Claus Gittinger <cg@exept.de> |
Thu, 11 Jan 2001 18:37:46 +0100 | |
changeset 1453 | 2cf5a2b1e1cb |
parent 1448 | 0c7834bd6c0f |
child 1455 | 6d385add9b96 |
permissions | -rw-r--r-- |
1124 | 1 |
" |
2 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
3 |
All Rights Reserved |
|
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 |
" |
|
12 |
||
13 |
||
14 |
||
15 |
||
16 |
||
1388 | 17 |
"{ Package: 'stx:libview2' }" |
18 |
||
1124 | 19 |
Object subclass:#KeyboardProcessor |
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
20 |
instanceVariableNames:'returnIsOKInDialog escapeIsCancelInDialog menuBar |
1251 | 21 |
autoAcceptListeners globalAccelerators' |
1124 | 22 |
classVariableNames:'' |
23 |
poolDictionaries:'' |
|
24 |
category:'Interface-Support-UI' |
|
25 |
! |
|
26 |
||
27 |
!KeyboardProcessor class methodsFor:'documentation'! |
|
28 |
||
29 |
copyright |
|
30 |
" |
|
31 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
32 |
All Rights Reserved |
|
33 |
||
34 |
This software is furnished under a license and may be used |
|
35 |
only in accordance with the terms of that license and with the |
|
36 |
inclusion of the above copyright notice. This software may not |
|
37 |
be provided or otherwise made available to, or used by, any |
|
38 |
other person. No title to or ownership of the software is |
|
39 |
hereby transferred. |
|
40 |
" |
|
41 |
||
42 |
||
43 |
||
44 |
||
45 |
! |
|
46 |
||
47 |
documentation |
|
48 |
" |
|
49 |
ST80 compatibility (mimicry) class. |
|
50 |
||
51 |
The class is not completed yet and certainly not bug free. |
|
52 |
||
53 |
Notice: |
|
54 |
this class was implemented using protocol information |
|
55 |
from alpha testers, literature and by reading public domain code |
|
56 |
- it may not be complete or compatible to |
|
57 |
the corresponding ST-80 class. |
|
58 |
If you encounter any incompatibilities, please forward a note |
|
59 |
describing the incompatibility verbal (i.e. no code) to the ST/X team. |
|
60 |
||
1160 | 61 |
KeyboardProcessor is going to take over the focus control |
62 |
mechanism (which are currently located in the windowGroup). |
|
63 |
Currently, it keeps track of inputFields, and allows for |
|
64 |
a global accept to be forced. |
|
65 |
This is especially useful with dialogs, where a global accept |
|
66 |
should be performed on all inputFields, when the OK button |
|
67 |
is pressed. |
|
68 |
||
1124 | 69 |
[author:] |
1160 | 70 |
Claus Gittinger |
1124 | 71 |
" |
72 |
||
73 |
||
74 |
||
75 |
||
76 |
! ! |
|
77 |
||
1422 | 78 |
!KeyboardProcessor class methodsFor:'defaults'! |
79 |
||
80 |
isMnemonicKeyEvent:aKeyEvent |
|
81 |
"returns true if the key event is a mnemonic key |
|
82 |
" |
|
83 |
|rawKey| |
|
84 |
||
85 |
rawKey := aKeyEvent rawKey. |
|
1443 | 86 |
^ rawKey size == 4 and:[rawKey startsWith:'Cmd'] |
87 |
! ! |
|
1422 | 88 |
|
1388 | 89 |
!KeyboardProcessor methodsFor:'Compatibility - ST80'! |
1124 | 90 |
|
91 |
keyboardConsumers |
|
92 |
^ #() |
|
93 |
||
94 |
"Created: 6.3.1997 / 15:16:32 / cg" |
|
95 |
! |
|
96 |
||
97 |
removeKeyboardReceiver:aController |
|
98 |
||
99 |
"Created: / 31.10.1997 / 01:56:54 / cg" |
|
100 |
! |
|
101 |
||
102 |
sendKeyboardTo:aController |
|
103 |
||
104 |
"Created: / 31.10.1997 / 01:57:15 / cg" |
|
105 |
! |
|
106 |
||
107 |
setActive:aWidget |
|
108 |
||
109 |
"Created: 3.3.1997 / 18:31:09 / cg" |
|
110 |
! ! |
|
111 |
||
112 |
!KeyboardProcessor methodsFor:'accessing'! |
|
113 |
||
1251 | 114 |
addAccelerator:aKey action:aSelectorOrBlock |
115 |
"add a global accelerator - these are handled even if no corresponding |
|
116 |
menu shortcut is defined" |
|
117 |
||
118 |
globalAccelerators isNil ifTrue:[ |
|
119 |
globalAccelerators := Dictionary new |
|
120 |
]. |
|
121 |
globalAccelerators at:aKey put:aSelectorOrBlock |
|
122 |
! |
|
123 |
||
1124 | 124 |
escapeIsCancelInDialog:aBoolean |
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
125 |
"set the escapeIsCancel flag. |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
126 |
If off, Escape is NOT handled as cancel (however, the default is true)" |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
127 |
|
1124 | 128 |
escapeIsCancelInDialog := aBoolean |
129 |
! |
|
130 |
||
131 |
menuBar |
|
132 |
"return the value of the instance variable 'menuBar' (automatically generated)" |
|
133 |
||
1443 | 134 |
^ menuBar |
135 |
! |
|
1124 | 136 |
|
137 |
menuBar:something |
|
138 |
"set the value of the instance variable 'menuBar' (automatically generated)" |
|
139 |
||
1443 | 140 |
menuBar := something. |
141 |
! |
|
1124 | 142 |
|
143 |
returnIsOKInDialog:aBoolean |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
144 |
"set the returnIsOK flag. |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
145 |
If off, Return is NOT handled as accept (however, the default is true)" |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
146 |
|
1124 | 147 |
returnIsOKInDialog := aBoolean |
148 |
||
149 |
! ! |
|
150 |
||
151 |
!KeyboardProcessor methodsFor:'event handling'! |
|
152 |
||
1135 | 153 |
processEvent:event forModalView:modalTopOrNil |
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
154 |
"process a key-event; return true, if handled & eaten; false if not. |
1251 | 155 |
Here, first, we look for a globalAccelerator, |
156 |
then for Return and Escape in modal applications, |
|
157 |
(which lead to Accept & Cancel resp.) |
|
158 |
Finally, menu-shortcuts are handled." |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
159 |
|
1448
0c7834bd6c0f
early bailOut for cursorKeys (do not check for shortCuts)
Claus Gittinger <cg@exept.de>
parents:
1445
diff
changeset
|
160 |
|key rawKey topView wg app view action| |
1124 | 161 |
|
162 |
view := event view. |
|
163 |
||
164 |
event isKeyPressEvent ifTrue:[ |
|
165 |
key := event key. |
|
1448
0c7834bd6c0f
early bailOut for cursorKeys (do not check for shortCuts)
Claus Gittinger <cg@exept.de>
parents:
1445
diff
changeset
|
166 |
rawKey := event rawKey. |
1135 | 167 |
topView := modalTopOrNil ? view topView. |
1445
50bf6580e064
care for topViews without windowGroup (which should not happen - but...)
tm
parents:
1443
diff
changeset
|
168 |
wg := topView windowGroup. |
1124 | 169 |
app := topView application. |
170 |
||
1251 | 171 |
"/ how about global accelerators ? |
172 |
(globalAccelerators notNil |
|
173 |
and:[(action := globalAccelerators at:key ifAbsent:nil) notNil]) |
|
174 |
ifTrue:[ |
|
175 |
action isSymbol ifTrue:[ |
|
1422 | 176 |
app notNil ifTrue:[ |
177 |
action numArgs == 1 ifTrue:[ |
|
178 |
app perform:action with:event |
|
179 |
] ifFalse:[ |
|
180 |
app perform:action |
|
181 |
]. |
|
182 |
] |
|
1251 | 183 |
] ifFalse:[ |
184 |
action numArgs == 1 ifTrue:[ |
|
185 |
action value:event |
|
186 |
] ifFalse:[ |
|
187 |
action value |
|
188 |
] |
|
189 |
]. |
|
190 |
^ true |
|
191 |
]. |
|
1422 | 192 |
app notNil ifTrue:[ |
193 |
topView isModal ifTrue:[ |
|
1445
50bf6580e064
care for topViews without windowGroup (which should not happen - but...)
tm
parents:
1443
diff
changeset
|
194 |
(wg notNil and:[wg explicitFocusView isNil]) ifTrue:[ |
1422 | 195 |
(returnIsOKInDialog and:[key == #Return]) ifTrue:[ |
196 |
self requestGlobalAutoAccept ifFalse:[^ true]. |
|
197 |
app doAccept. |
|
198 |
^ true |
|
199 |
]. |
|
200 |
]. |
|
1251 | 201 |
|
1422 | 202 |
(escapeIsCancelInDialog and:[key == #Escape]) ifTrue:[ |
203 |
app doCancel. |
|
1134
758151d73aac
only do autoAccept, if there is no focus view.
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
204 |
^ true |
758151d73aac
only do autoAccept, if there is no focus view.
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
205 |
]. |
1124 | 206 |
]. |
1422 | 207 |
]. |
1134
758151d73aac
only do autoAccept, if there is no focus view.
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
208 |
|
1448
0c7834bd6c0f
early bailOut for cursorKeys (do not check for shortCuts)
Claus Gittinger <cg@exept.de>
parents:
1445
diff
changeset
|
209 |
rawKey isSymbol ifTrue:[ |
0c7834bd6c0f
early bailOut for cursorKeys (do not check for shortCuts)
Claus Gittinger <cg@exept.de>
parents:
1445
diff
changeset
|
210 |
( #(Up Down Left Right |
0c7834bd6c0f
early bailOut for cursorKeys (do not check for shortCuts)
Claus Gittinger <cg@exept.de>
parents:
1445
diff
changeset
|
211 |
) includes:rawKey) |
0c7834bd6c0f
early bailOut for cursorKeys (do not check for shortCuts)
Claus Gittinger <cg@exept.de>
parents:
1445
diff
changeset
|
212 |
ifFalse:[ |
1453
2cf5a2b1e1cb
dont check for shortCuts with Control-key (alone)
Claus Gittinger <cg@exept.de>
parents:
1448
diff
changeset
|
213 |
( #( #'Control_L' #'Control_R' #'Control' |
2cf5a2b1e1cb
dont check for shortCuts with Control-key (alone)
Claus Gittinger <cg@exept.de>
parents:
1448
diff
changeset
|
214 |
) includes:key) |
2cf5a2b1e1cb
dont check for shortCuts with Control-key (alone)
Claus Gittinger <cg@exept.de>
parents:
1448
diff
changeset
|
215 |
ifFalse:[ |
2cf5a2b1e1cb
dont check for shortCuts with Control-key (alone)
Claus Gittinger <cg@exept.de>
parents:
1448
diff
changeset
|
216 |
wg notNil ifTrue:[ |
2cf5a2b1e1cb
dont check for shortCuts with Control-key (alone)
Claus Gittinger <cg@exept.de>
parents:
1448
diff
changeset
|
217 |
(self class isMnemonicKeyEvent:event) ifTrue:[ |
2cf5a2b1e1cb
dont check for shortCuts with Control-key (alone)
Claus Gittinger <cg@exept.de>
parents:
1448
diff
changeset
|
218 |
(wg processMnemonic:event) ifTrue:[ |
2cf5a2b1e1cb
dont check for shortCuts with Control-key (alone)
Claus Gittinger <cg@exept.de>
parents:
1448
diff
changeset
|
219 |
^ true |
2cf5a2b1e1cb
dont check for shortCuts with Control-key (alone)
Claus Gittinger <cg@exept.de>
parents:
1448
diff
changeset
|
220 |
] |
2cf5a2b1e1cb
dont check for shortCuts with Control-key (alone)
Claus Gittinger <cg@exept.de>
parents:
1448
diff
changeset
|
221 |
]. |
2cf5a2b1e1cb
dont check for shortCuts with Control-key (alone)
Claus Gittinger <cg@exept.de>
parents:
1448
diff
changeset
|
222 |
(wg processShortcut:event) ifTrue:[ |
1448
0c7834bd6c0f
early bailOut for cursorKeys (do not check for shortCuts)
Claus Gittinger <cg@exept.de>
parents:
1445
diff
changeset
|
223 |
^ true |
1453
2cf5a2b1e1cb
dont check for shortCuts with Control-key (alone)
Claus Gittinger <cg@exept.de>
parents:
1448
diff
changeset
|
224 |
]. |
1448
0c7834bd6c0f
early bailOut for cursorKeys (do not check for shortCuts)
Claus Gittinger <cg@exept.de>
parents:
1445
diff
changeset
|
225 |
]. |
1445
50bf6580e064
care for topViews without windowGroup (which should not happen - but...)
tm
parents:
1443
diff
changeset
|
226 |
]. |
1124 | 227 |
]. |
1422 | 228 |
]. |
1124 | 229 |
]. |
230 |
||
1423 | 231 |
"/ let view dispatch it. |
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
232 |
^ false |
1423 | 233 |
! |
1124 | 234 |
|
235 |
requestForWindowClose |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
236 |
"about to close the window." |
1124 | 237 |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
238 |
^ true |
1124 | 239 |
! |
240 |
||
241 |
requestGlobalAutoAccept |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
242 |
"about to close the window via return ok accept. |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
243 |
Ask all acceptListeners to accept their value and return true, if all of those fields |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
244 |
did." |
1124 | 245 |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
246 |
autoAcceptListeners notNil ifTrue:[ |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
247 |
autoAcceptListeners do:[:aListener | |
1133 | 248 |
(aListener requestAutoAccept) ifFalse:[^ false]. |
249 |
]. |
|
250 |
^ true |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
251 |
]. |
1133 | 252 |
^ false |
1124 | 253 |
|
254 |
! ! |
|
255 |
||
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
256 |
!KeyboardProcessor methodsFor:'setup'! |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
257 |
|
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
258 |
addAutoAcceptListener:aListener |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
259 |
"add a aListener to my autoAcceptListeners. |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
260 |
Typically, inputFields add themself, to be notified (via requestForAutoAccept) |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
261 |
when the dialog is about to be closed with returnIsOK or accept. |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
262 |
(of course, other listeners are also invited ;-)" |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
263 |
|
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
264 |
autoAcceptListeners isNil ifTrue:[ |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
265 |
autoAcceptListeners := IdentitySet new. |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
266 |
]. |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
267 |
autoAcceptListeners add:aListener |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
268 |
! ! |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
269 |
|
1124 | 270 |
!KeyboardProcessor class methodsFor:'documentation'! |
271 |
||
272 |
version |
|
1453
2cf5a2b1e1cb
dont check for shortCuts with Control-key (alone)
Claus Gittinger <cg@exept.de>
parents:
1448
diff
changeset
|
273 |
^ '$Header: /cvs/stx/stx/libview2/KeyboardProcessor.st,v 1.17 2001-01-11 17:37:46 cg Exp $' |
1124 | 274 |
! ! |