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