author | Claus Gittinger <cg@exept.de> |
Thu, 23 Nov 2000 18:10:12 +0100 | |
changeset 1435 | d7c6c5cf4d31 |
parent 1423 | 0e391ec230be |
child 1443 | fecba7db7523 |
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. |
|
86 |
^ rawKey size == 4 and:[rawKey startsWith:'Cmd']! ! |
|
87 |
||
1388 | 88 |
!KeyboardProcessor methodsFor:'Compatibility - ST80'! |
1124 | 89 |
|
90 |
keyboardConsumers |
|
91 |
^ #() |
|
92 |
||
93 |
"Created: 6.3.1997 / 15:16:32 / cg" |
|
94 |
! |
|
95 |
||
96 |
removeKeyboardReceiver:aController |
|
97 |
||
98 |
"Created: / 31.10.1997 / 01:56:54 / cg" |
|
99 |
! |
|
100 |
||
101 |
sendKeyboardTo:aController |
|
102 |
||
103 |
"Created: / 31.10.1997 / 01:57:15 / cg" |
|
104 |
! |
|
105 |
||
106 |
setActive:aWidget |
|
107 |
||
108 |
"Created: 3.3.1997 / 18:31:09 / cg" |
|
109 |
! ! |
|
110 |
||
111 |
!KeyboardProcessor methodsFor:'accessing'! |
|
112 |
||
1251 | 113 |
addAccelerator:aKey action:aSelectorOrBlock |
114 |
"add a global accelerator - these are handled even if no corresponding |
|
115 |
menu shortcut is defined" |
|
116 |
||
117 |
globalAccelerators isNil ifTrue:[ |
|
118 |
globalAccelerators := Dictionary new |
|
119 |
]. |
|
120 |
globalAccelerators at:aKey put:aSelectorOrBlock |
|
121 |
! |
|
122 |
||
1124 | 123 |
escapeIsCancelInDialog:aBoolean |
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
124 |
"set the escapeIsCancel flag. |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
125 |
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
|
126 |
|
1124 | 127 |
escapeIsCancelInDialog := aBoolean |
128 |
! |
|
129 |
||
130 |
menuBar |
|
131 |
"return the value of the instance variable 'menuBar' (automatically generated)" |
|
132 |
||
133 |
^ menuBar! |
|
134 |
||
135 |
menuBar:something |
|
136 |
"set the value of the instance variable 'menuBar' (automatically generated)" |
|
137 |
||
138 |
menuBar := something.! |
|
139 |
||
140 |
returnIsOKInDialog:aBoolean |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
141 |
"set the returnIsOK flag. |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
142 |
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
|
143 |
|
1124 | 144 |
returnIsOKInDialog := aBoolean |
145 |
||
146 |
! ! |
|
147 |
||
148 |
!KeyboardProcessor methodsFor:'event handling'! |
|
149 |
||
1135 | 150 |
processEvent:event forModalView:modalTopOrNil |
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
151 |
"process a key-event; return true, if handled & eaten; false if not. |
1251 | 152 |
Here, first, we look for a globalAccelerator, |
153 |
then for Return and Escape in modal applications, |
|
154 |
(which lead to Accept & Cancel resp.) |
|
155 |
Finally, menu-shortcuts are handled." |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
156 |
|
1251 | 157 |
|key topView app view action| |
1124 | 158 |
|
159 |
view := event view. |
|
160 |
||
161 |
event isKeyPressEvent ifTrue:[ |
|
162 |
key := event key. |
|
1135 | 163 |
topView := modalTopOrNil ? view topView. |
1124 | 164 |
app := topView application. |
165 |
||
1251 | 166 |
"/ how about global accelerators ? |
167 |
(globalAccelerators notNil |
|
168 |
and:[(action := globalAccelerators at:key ifAbsent:nil) notNil]) |
|
169 |
ifTrue:[ |
|
170 |
action isSymbol ifTrue:[ |
|
1422 | 171 |
app notNil ifTrue:[ |
172 |
action numArgs == 1 ifTrue:[ |
|
173 |
app perform:action with:event |
|
174 |
] ifFalse:[ |
|
175 |
app perform:action |
|
176 |
]. |
|
177 |
] |
|
1251 | 178 |
] ifFalse:[ |
179 |
action numArgs == 1 ifTrue:[ |
|
180 |
action value:event |
|
181 |
] ifFalse:[ |
|
182 |
action value |
|
183 |
] |
|
184 |
]. |
|
185 |
^ true |
|
186 |
]. |
|
1422 | 187 |
app notNil ifTrue:[ |
188 |
topView isModal ifTrue:[ |
|
189 |
topView windowGroup explicitFocusView isNil ifTrue:[ |
|
190 |
(returnIsOKInDialog and:[key == #Return]) ifTrue:[ |
|
191 |
self requestGlobalAutoAccept ifFalse:[^ true]. |
|
192 |
app doAccept. |
|
193 |
^ true |
|
194 |
]. |
|
195 |
]. |
|
1251 | 196 |
|
1422 | 197 |
(escapeIsCancelInDialog and:[key == #Escape]) ifTrue:[ |
198 |
app doCancel. |
|
1134
758151d73aac
only do autoAccept, if there is no focus view.
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
199 |
^ true |
758151d73aac
only do autoAccept, if there is no focus view.
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
200 |
]. |
1124 | 201 |
]. |
1422 | 202 |
]. |
1134
758151d73aac
only do autoAccept, if there is no focus view.
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
203 |
|
1422 | 204 |
event rawKey isSymbol ifTrue:[ |
205 |
(self class isMnemonicKeyEvent:event) ifTrue:[ |
|
206 |
(topView windowGroup mnemonicViewNext:event) ifTrue:[ |
|
207 |
^ true |
|
208 |
] |
|
209 |
]. |
|
210 |
(topView windowGroup processShortcut:event) ifTrue:[ |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
211 |
^ true |
1124 | 212 |
]. |
1422 | 213 |
]. |
1124 | 214 |
]. |
215 |
||
1423 | 216 |
"/ let view dispatch it. |
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
217 |
^ false |
1423 | 218 |
! |
1124 | 219 |
|
220 |
requestForWindowClose |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
221 |
"about to close the window." |
1124 | 222 |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
223 |
^ true |
1124 | 224 |
! |
225 |
||
226 |
requestGlobalAutoAccept |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
227 |
"about to close the window via return ok accept. |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
228 |
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
|
229 |
did." |
1124 | 230 |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
231 |
autoAcceptListeners notNil ifTrue:[ |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
232 |
autoAcceptListeners do:[:aListener | |
1133 | 233 |
(aListener requestAutoAccept) ifFalse:[^ false]. |
234 |
]. |
|
235 |
^ true |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
236 |
]. |
1133 | 237 |
^ false |
1124 | 238 |
|
239 |
! ! |
|
240 |
||
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
241 |
!KeyboardProcessor methodsFor:'setup'! |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
242 |
|
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
243 |
addAutoAcceptListener:aListener |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
244 |
"add a aListener to my autoAcceptListeners. |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
245 |
Typically, inputFields add themself, to be notified (via requestForAutoAccept) |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
246 |
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
|
247 |
(of course, other listeners are also invited ;-)" |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
248 |
|
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
249 |
autoAcceptListeners isNil ifTrue:[ |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
250 |
autoAcceptListeners := IdentitySet new. |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
251 |
]. |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
252 |
autoAcceptListeners add:aListener |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
253 |
! ! |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
254 |
|
1124 | 255 |
!KeyboardProcessor class methodsFor:'documentation'! |
256 |
||
257 |
version |
|
1423 | 258 |
^ '$Header: /cvs/stx/stx/libview2/KeyboardProcessor.st,v 1.13 2000-11-09 19:42:15 cg Exp $' |
1124 | 259 |
! ! |