author | Claus Gittinger <cg@exept.de> |
Thu, 04 Feb 2010 23:07:53 +0100 | |
changeset 2821 | f4e296477b96 |
parent 2585 | 8b60021d3d15 |
child 2929 | fcf03ac9e8f5 |
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 |
" |
|
1388 | 12 |
"{ Package: 'stx:libview2' }" |
13 |
||
1124 | 14 |
Object subclass:#KeyboardProcessor |
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
15 |
instanceVariableNames:'returnIsOKInDialog escapeIsCancelInDialog menuBar |
2443
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
16 |
autoAcceptListeners globalAccelerators componentWithInitialFocus |
2821 | 17 |
altFunctionWasExecuted eventFilter' |
1124 | 18 |
classVariableNames:'' |
19 |
poolDictionaries:'' |
|
2360 | 20 |
category:'Interface-Framework' |
1124 | 21 |
! |
22 |
||
23 |
!KeyboardProcessor class methodsFor:'documentation'! |
|
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
28 |
All Rights Reserved |
|
29 |
||
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 |
||
38 |
||
39 |
||
40 |
||
41 |
! |
|
42 |
||
43 |
documentation |
|
44 |
" |
|
45 |
ST80 compatibility (mimicry) class. |
|
46 |
||
47 |
The class is not completed yet and certainly not bug free. |
|
48 |
||
49 |
Notice: |
|
50 |
this class was implemented using protocol information |
|
51 |
from alpha testers, literature and by reading public domain code |
|
52 |
- it may not be complete or compatible to |
|
53 |
the corresponding ST-80 class. |
|
54 |
If you encounter any incompatibilities, please forward a note |
|
55 |
describing the incompatibility verbal (i.e. no code) to the ST/X team. |
|
56 |
||
1160 | 57 |
KeyboardProcessor is going to take over the focus control |
58 |
mechanism (which are currently located in the windowGroup). |
|
59 |
Currently, it keeps track of inputFields, and allows for |
|
60 |
a global accept to be forced. |
|
61 |
This is especially useful with dialogs, where a global accept |
|
62 |
should be performed on all inputFields, when the OK button |
|
63 |
is pressed. |
|
64 |
||
2821 | 65 |
specials: |
66 |
eventFilter ....................... if non-nil, a block to return false, if |
|
67 |
the event is to be ignored. |
|
68 |
||
1124 | 69 |
[author:] |
1160 | 70 |
Claus Gittinger |
1124 | 71 |
" |
72 |
! ! |
|
73 |
||
1422 | 74 |
!KeyboardProcessor class methodsFor:'defaults'! |
75 |
||
2488
ed0fabedfe4e
also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents:
2447
diff
changeset
|
76 |
isCommandKey:aKeyCode |
ed0fabedfe4e
also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents:
2447
diff
changeset
|
77 |
"returns true if the keyCode is for a Command key (such as Cmda)" |
ed0fabedfe4e
also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents:
2447
diff
changeset
|
78 |
|
ed0fabedfe4e
also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents:
2447
diff
changeset
|
79 |
^ aKeyCode size == 4 "/ only CMD-single letter !! |
ed0fabedfe4e
also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents:
2447
diff
changeset
|
80 |
and:[aKeyCode startsWith:'Cmd'] "/ CmdMenu for right-alt in vmware ??? |
ed0fabedfe4e
also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents:
2447
diff
changeset
|
81 |
! |
ed0fabedfe4e
also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents:
2447
diff
changeset
|
82 |
|
ed0fabedfe4e
also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents:
2447
diff
changeset
|
83 |
isFunctionKey:aKeyCode |
ed0fabedfe4e
also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents:
2447
diff
changeset
|
84 |
"returns true if the key code is for a Function key (such as F10)" |
ed0fabedfe4e
also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents:
2447
diff
changeset
|
85 |
|
ed0fabedfe4e
also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents:
2447
diff
changeset
|
86 |
(aKeyCode startsWith:'F') ifTrue:[ |
ed0fabedfe4e
also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents:
2447
diff
changeset
|
87 |
(aKeyCode size between:2 and:3) ifTrue:[ |
ed0fabedfe4e
also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents:
2447
diff
changeset
|
88 |
(aKeyCode at:2) isDigit ifFalse:[^ false]. |
ed0fabedfe4e
also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents:
2447
diff
changeset
|
89 |
aKeyCode size == 2 ifTrue:[^ true]. |
ed0fabedfe4e
also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents:
2447
diff
changeset
|
90 |
^ (aKeyCode at:3) isDigit |
ed0fabedfe4e
also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents:
2447
diff
changeset
|
91 |
]. |
ed0fabedfe4e
also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents:
2447
diff
changeset
|
92 |
]. |
ed0fabedfe4e
also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents:
2447
diff
changeset
|
93 |
^ false |
ed0fabedfe4e
also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents:
2447
diff
changeset
|
94 |
! |
ed0fabedfe4e
also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents:
2447
diff
changeset
|
95 |
|
1455
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
96 |
isKeyEventIgnoredAsShortcut:aKeyEvent |
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
97 |
"returns true if the key event ignored is a shortCut key |
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
98 |
" |
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
99 |
|rawKey| |
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
100 |
|
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
101 |
rawKey := aKeyEvent rawKey. |
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
102 |
rawKey isSymbol ifFalse:[^ true]. |
1503
b3c4b1b1bfbb
cursor keys ARE allowed as accelerators (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1499
diff
changeset
|
103 |
"/ "/ ignore cursor keys |
b3c4b1b1bfbb
cursor keys ARE allowed as accelerators (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1499
diff
changeset
|
104 |
"/ (#( |
b3c4b1b1bfbb
cursor keys ARE allowed as accelerators (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1499
diff
changeset
|
105 |
"/ Up Down Left Right |
b3c4b1b1bfbb
cursor keys ARE allowed as accelerators (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1499
diff
changeset
|
106 |
"/ CursorUp CursorDown CursorLeft CursorRight |
b3c4b1b1bfbb
cursor keys ARE allowed as accelerators (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1499
diff
changeset
|
107 |
"/ ) includes:rawKey) ifTrue:[^ true]. |
1455
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
108 |
|
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
109 |
"/ ignore some meta keys |
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
110 |
(#( |
1499 | 111 |
#'Control_L' #'Control_R' #'Control' #'Ctrl' |
112 |
#'CmdMenu' #'BackSpace' #Tab |
|
2443
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
113 |
#'Cmd_L' #'Cmd_R' #'Cmd' #'Menu' |
1499 | 114 |
#'Shift_L' #'Shift_R' Shift |
115 |
#'Alt_L' #'Alt_R' #'Alt' |
|
116 |
#'Super_R' #'Super_L' #'Super' |
|
1455
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
117 |
) includes:aKeyEvent key) ifTrue:[^ true]. |
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
118 |
|
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
119 |
^ false |
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
120 |
|
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
121 |
"Created: / 17.1.2001 / 11:57:07 / cg" |
1457 | 122 |
"Modified: / 17.1.2001 / 13:05:46 / cg" |
1455
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
123 |
! |
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
124 |
|
1422 | 125 |
isMnemonicKeyEvent:aKeyEvent |
2386 | 126 |
"returns true if the key event is a mnemonic key (such as Cmda) |
1422 | 127 |
" |
128 |
|rawKey| |
|
129 |
||
130 |
rawKey := aKeyEvent rawKey. |
|
2488
ed0fabedfe4e
also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents:
2447
diff
changeset
|
131 |
rawKey isSymbol ifFalse:[^ false]. |
ed0fabedfe4e
also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents:
2447
diff
changeset
|
132 |
(self isCommandKey:rawKey) ifTrue:[^ true]. |
ed0fabedfe4e
also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents:
2447
diff
changeset
|
133 |
(self isFunctionKey:rawKey) ifTrue:[^ true]. |
ed0fabedfe4e
also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents:
2447
diff
changeset
|
134 |
^ false |
1443 | 135 |
! ! |
1422 | 136 |
|
1763 | 137 |
!KeyboardProcessor methodsFor:'Compatibility-VW'! |
1124 | 138 |
|
139 |
keyboardConsumers |
|
140 |
^ #() |
|
141 |
||
142 |
"Created: 6.3.1997 / 15:16:32 / cg" |
|
143 |
! |
|
144 |
||
145 |
removeKeyboardReceiver:aController |
|
146 |
||
147 |
"Created: / 31.10.1997 / 01:56:54 / cg" |
|
148 |
! |
|
149 |
||
150 |
sendKeyboardTo:aController |
|
151 |
||
152 |
"Created: / 31.10.1997 / 01:57:15 / cg" |
|
153 |
! |
|
154 |
||
155 |
setActive:aWidget |
|
156 |
||
157 |
"Created: 3.3.1997 / 18:31:09 / cg" |
|
158 |
! ! |
|
159 |
||
160 |
!KeyboardProcessor methodsFor:'accessing'! |
|
161 |
||
1251 | 162 |
addAccelerator:aKey action:aSelectorOrBlock |
163 |
"add a global accelerator - these are handled even if no corresponding |
|
164 |
menu shortcut is defined" |
|
165 |
||
166 |
globalAccelerators isNil ifTrue:[ |
|
167 |
globalAccelerators := Dictionary new |
|
168 |
]. |
|
169 |
globalAccelerators at:aKey put:aSelectorOrBlock |
|
170 |
! |
|
171 |
||
1983 | 172 |
componentWithInitialFocus |
173 |
^ componentWithInitialFocus |
|
174 |
! |
|
175 |
||
176 |
componentWithInitialFocus:aComponent |
|
177 |
componentWithInitialFocus := aComponent |
|
178 |
! |
|
179 |
||
1124 | 180 |
escapeIsCancelInDialog:aBoolean |
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
181 |
"set the escapeIsCancel flag. |
1635 | 182 |
If off, Escape is NOT handled as cancel (the builder defaults it to true,)" |
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
183 |
|
1124 | 184 |
escapeIsCancelInDialog := aBoolean |
185 |
! |
|
186 |
||
2821 | 187 |
eventFilter:something |
188 |
eventFilter := something. |
|
189 |
! |
|
190 |
||
1124 | 191 |
menuBar |
192 |
"return the value of the instance variable 'menuBar' (automatically generated)" |
|
193 |
||
1443 | 194 |
^ menuBar |
195 |
! |
|
1124 | 196 |
|
197 |
menuBar:something |
|
198 |
"set the value of the instance variable 'menuBar' (automatically generated)" |
|
199 |
||
1443 | 200 |
menuBar := something. |
201 |
! |
|
1124 | 202 |
|
203 |
returnIsOKInDialog:aBoolean |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
204 |
"set the returnIsOK flag. |
1635 | 205 |
If off, Return is NOT handled as accept (the builder defaults it to true,)" |
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
206 |
|
1124 | 207 |
returnIsOKInDialog := aBoolean |
208 |
! ! |
|
209 |
||
210 |
!KeyboardProcessor methodsFor:'event handling'! |
|
211 |
||
1135 | 212 |
processEvent:event forModalView:modalTopOrNil |
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
213 |
"process a key-event; return true, if handled & eaten; false if not. |
1251 | 214 |
Here, first, we look for a globalAccelerator, |
215 |
then for Return and Escape in modal applications, |
|
216 |
(which lead to Accept & Cancel resp.) |
|
217 |
Finally, menu-shortcuts are handled." |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
218 |
|
2007
014e4bfe31f1
must accept an inputField before
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
219 |
|key rawKey topView wg app view action explicitFocusView focusView| |
1124 | 220 |
|
2443
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
221 |
event isKeyEvent ifFalse:[ ^ false ]. |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
222 |
|
2821 | 223 |
eventFilter notNil ifTrue:[ |
224 |
(eventFilter value:event) ifFalse:[ |
|
225 |
^ false. |
|
226 |
] |
|
227 |
]. |
|
228 |
||
2443
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
229 |
key := event key. |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
230 |
rawKey := event rawKey. |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
231 |
|
1124 | 232 |
view := event view. |
233 |
||
2443
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
234 |
topView := modalTopOrNil ? view topView. |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
235 |
wg := topView windowGroup. |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
236 |
app := topView application. |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
237 |
|
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
238 |
"/ little state machine, to detect if the alt-key was pressed |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
239 |
"/ without a concrete command key. |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
240 |
"/ this will bring the focus to the menuPanel, if there is one. |
2447
ecb0212e1c8d
ALT-key processing disabled (temporarily)
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
241 |
"/ cg: disabled for now; |
ecb0212e1c8d
ALT-key processing disabled (temporarily)
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
242 |
"/ leads to occasional leftover popupmenus floating around; |
ecb0212e1c8d
ALT-key processing disabled (temporarily)
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
243 |
"/ ca has to look for this first. |
ecb0212e1c8d
ALT-key processing disabled (temporarily)
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
244 |
false ifTrue:[ |
2443
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
245 |
key = #'Cmd' ifTrue:[ |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
246 |
event isKeyPressEvent ifTrue:[ |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
247 |
altFunctionWasExecuted := false. |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
248 |
] ifFalse:[ |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
249 |
event isKeyReleaseEvent ifTrue:[ |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
250 |
altFunctionWasExecuted ifFalse:[ |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
251 |
(wg processShortcut:event) ifTrue:[ |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
252 |
^ true |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
253 |
]. |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
254 |
]. |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
255 |
]. |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
256 |
]. |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
257 |
] ifFalse:[ |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
258 |
altFunctionWasExecuted := true. |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
259 |
]. |
2447
ecb0212e1c8d
ALT-key processing disabled (temporarily)
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
260 |
]. |
2443
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
261 |
|
1124 | 262 |
event isKeyPressEvent ifTrue:[ |
2443
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
263 |
"/ key startsWith:'Cmd' |
1124 | 264 |
|
1251 | 265 |
"/ how about global accelerators ? |
266 |
(globalAccelerators notNil |
|
267 |
and:[(action := globalAccelerators at:key ifAbsent:nil) notNil]) |
|
268 |
ifTrue:[ |
|
1492 | 269 |
event consumed:true. |
1251 | 270 |
action isSymbol ifTrue:[ |
1422 | 271 |
app notNil ifTrue:[ |
2585
8b60021d3d15
return-key handling (dont care for non-keyboard-consumers)
Claus Gittinger <cg@exept.de>
parents:
2488
diff
changeset
|
272 |
app perform:action withOptionalArgument:event |
1422 | 273 |
] |
1251 | 274 |
] ifFalse:[ |
2585
8b60021d3d15
return-key handling (dont care for non-keyboard-consumers)
Claus Gittinger <cg@exept.de>
parents:
2488
diff
changeset
|
275 |
action valueWithOptionalArgument:event |
1251 | 276 |
]. |
1492 | 277 |
"/ ^ true |
278 |
^ event consumed |
|
1251 | 279 |
]. |
1488
9fa3505d2d85
optionBox: cancel-value corrected
Claus Gittinger <cg@exept.de>
parents:
1458
diff
changeset
|
280 |
|
9fa3505d2d85
optionBox: cancel-value corrected
Claus Gittinger <cg@exept.de>
parents:
1458
diff
changeset
|
281 |
topView isModal ifTrue:[ |
1637 | 282 |
(key == #Return and:[returnIsOKInDialog ? true]) ifTrue:[ |
283 |
(wg notNil |
|
2007
014e4bfe31f1
must accept an inputField before
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
284 |
and:[(explicitFocusView := wg explicitFocusView) isNil |
2585
8b60021d3d15
return-key handling (dont care for non-keyboard-consumers)
Claus Gittinger <cg@exept.de>
parents:
2488
diff
changeset
|
285 |
or:[ false "explicitFocusView isKeyboardConsumer not" |
8b60021d3d15
return-key handling (dont care for non-keyboard-consumers)
Claus Gittinger <cg@exept.de>
parents:
2488
diff
changeset
|
286 |
or:[ explicitFocusView isInputField ]] |
2007
014e4bfe31f1
must accept an inputField before
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
287 |
]) ifTrue:[ |
014e4bfe31f1
must accept an inputField before
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
288 |
((focusView := wg focusView) notNil and:[focusView isTextView]) ifTrue:[ |
014e4bfe31f1
must accept an inputField before
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
289 |
focusView isInputField ifFalse:[ |
014e4bfe31f1
must accept an inputField before
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
290 |
"/ modalBox with a TextView |
014e4bfe31f1
must accept an inputField before
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
291 |
^ false |
014e4bfe31f1
must accept an inputField before
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
292 |
]. |
2585
8b60021d3d15
return-key handling (dont care for non-keyboard-consumers)
Claus Gittinger <cg@exept.de>
parents:
2488
diff
changeset
|
293 |
"/ this is a kludge for subcanvases input-fields, which |
2008
bc367a4d7d6a
kludge for subcanvas-inputfields
Claus Gittinger <cg@exept.de>
parents:
2007
diff
changeset
|
294 |
"/ are not affected by #requestGlobalAutoAccept below. |
2007
014e4bfe31f1
must accept an inputField before
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
295 |
focusView isAcceptOnReturn ifTrue:[ |
014e4bfe31f1
must accept an inputField before
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
296 |
focusView accept |
014e4bfe31f1
must accept an inputField before
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
297 |
]. |
2006
83d2e7259fcf
ignore return (do not close) if the current
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
298 |
]. |
83d2e7259fcf
ignore return (do not close) if the current
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
299 |
|
1488
9fa3505d2d85
optionBox: cancel-value corrected
Claus Gittinger <cg@exept.de>
parents:
1458
diff
changeset
|
300 |
self requestGlobalAutoAccept ifFalse:[^ true]. |
1636
c9ed206b5d32
escapeIsCancel/returnIsOK in popup with same app as mainapp
ca
parents:
1635
diff
changeset
|
301 |
|
c9ed206b5d32
escapeIsCancel/returnIsOK in popup with same app as mainapp
ca
parents:
1635
diff
changeset
|
302 |
"/ only care for RETURN and ESC if the window is the |
c9ed206b5d32
escapeIsCancel/returnIsOK in popup with same app as mainapp
ca
parents:
1635
diff
changeset
|
303 |
"/ apps topView (not if its a popup or dialog of it) |
c9ed206b5d32
escapeIsCancel/returnIsOK in popup with same app as mainapp
ca
parents:
1635
diff
changeset
|
304 |
(app notNil and:[app window == topView]) ifTrue:[ |
1794
81e71050bce2
extra hooks for ok/cancel via keyboard
Claus Gittinger <cg@exept.de>
parents:
1763
diff
changeset
|
305 |
app doAcceptByReturnKey. |
1488
9fa3505d2d85
optionBox: cancel-value corrected
Claus Gittinger <cg@exept.de>
parents:
1458
diff
changeset
|
306 |
] ifFalse:[ |
9fa3505d2d85
optionBox: cancel-value corrected
Claus Gittinger <cg@exept.de>
parents:
1458
diff
changeset
|
307 |
"/ oldStyle modalBox - for now, let Box handle it itself |
9fa3505d2d85
optionBox: cancel-value corrected
Claus Gittinger <cg@exept.de>
parents:
1458
diff
changeset
|
308 |
^ false |
1422 | 309 |
]. |
1134
758151d73aac
only do autoAccept, if there is no focus view.
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
310 |
^ true |
758151d73aac
only do autoAccept, if there is no focus view.
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
311 |
]. |
1124 | 312 |
]. |
1637 | 313 |
(key == #Escape and:[escapeIsCancelInDialog ? true]) ifTrue:[ |
1636
c9ed206b5d32
escapeIsCancel/returnIsOK in popup with same app as mainapp
ca
parents:
1635
diff
changeset
|
314 |
"/ only care for RETURN and ESC if the window is the |
c9ed206b5d32
escapeIsCancel/returnIsOK in popup with same app as mainapp
ca
parents:
1635
diff
changeset
|
315 |
"/ apps topView (not if its a popup or dialog of it) |
c9ed206b5d32
escapeIsCancel/returnIsOK in popup with same app as mainapp
ca
parents:
1635
diff
changeset
|
316 |
(app notNil and:[app window == topView]) ifTrue:[ |
1794
81e71050bce2
extra hooks for ok/cancel via keyboard
Claus Gittinger <cg@exept.de>
parents:
1763
diff
changeset
|
317 |
app doCancelByEscapeKey. |
1488
9fa3505d2d85
optionBox: cancel-value corrected
Claus Gittinger <cg@exept.de>
parents:
1458
diff
changeset
|
318 |
] ifFalse:[ |
9fa3505d2d85
optionBox: cancel-value corrected
Claus Gittinger <cg@exept.de>
parents:
1458
diff
changeset
|
319 |
"/ oldStyle modalBox - for now, let Box handle it itself |
9fa3505d2d85
optionBox: cancel-value corrected
Claus Gittinger <cg@exept.de>
parents:
1458
diff
changeset
|
320 |
^ false |
9fa3505d2d85
optionBox: cancel-value corrected
Claus Gittinger <cg@exept.de>
parents:
1458
diff
changeset
|
321 |
]. |
9fa3505d2d85
optionBox: cancel-value corrected
Claus Gittinger <cg@exept.de>
parents:
1458
diff
changeset
|
322 |
^ true |
9fa3505d2d85
optionBox: cancel-value corrected
Claus Gittinger <cg@exept.de>
parents:
1458
diff
changeset
|
323 |
]. |
1422 | 324 |
]. |
1488
9fa3505d2d85
optionBox: cancel-value corrected
Claus Gittinger <cg@exept.de>
parents:
1458
diff
changeset
|
325 |
|
1455
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
326 |
wg notNil ifTrue:[ |
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
327 |
(self class isMnemonicKeyEvent:event) ifTrue:[ |
1456 | 328 |
"/Transcript showCR:event rawKey. |
329 |
"/Transcript showCR:event key. |
|
1455
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
330 |
(wg processMnemonic:event) ifTrue:[ |
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
331 |
^ true |
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
332 |
] |
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
333 |
]. |
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
334 |
(self class isKeyEventIgnoredAsShortcut:event) ifFalse:[ |
1456 | 335 |
"/Transcript showCR:event rawKey. |
336 |
"/Transcript showCR:event key. |
|
1455
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
337 |
(wg processShortcut:event) ifTrue:[ |
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
338 |
^ true |
1445
50bf6580e064
care for topViews without windowGroup (which should not happen - but...)
tm
parents:
1443
diff
changeset
|
339 |
]. |
1124 | 340 |
]. |
2400
b47e642dd9bc
support ALT-F4 (close window)
Claus Gittinger <cg@exept.de>
parents:
2398
diff
changeset
|
341 |
]. |
b47e642dd9bc
support ALT-F4 (close window)
Claus Gittinger <cg@exept.de>
parents:
2398
diff
changeset
|
342 |
"/ support ALT-F4 (close window) |
b47e642dd9bc
support ALT-F4 (close window)
Claus Gittinger <cg@exept.de>
parents:
2398
diff
changeset
|
343 |
(key == #CloseWindowRequest) ifTrue:[ |
b47e642dd9bc
support ALT-F4 (close window)
Claus Gittinger <cg@exept.de>
parents:
2398
diff
changeset
|
344 |
app notNil ifTrue:[ |
b47e642dd9bc
support ALT-F4 (close window)
Claus Gittinger <cg@exept.de>
parents:
2398
diff
changeset
|
345 |
app closeRequest |
b47e642dd9bc
support ALT-F4 (close window)
Claus Gittinger <cg@exept.de>
parents:
2398
diff
changeset
|
346 |
] ifFalse:[ |
b47e642dd9bc
support ALT-F4 (close window)
Claus Gittinger <cg@exept.de>
parents:
2398
diff
changeset
|
347 |
topView closeRequest |
b47e642dd9bc
support ALT-F4 (close window)
Claus Gittinger <cg@exept.de>
parents:
2398
diff
changeset
|
348 |
]. |
b47e642dd9bc
support ALT-F4 (close window)
Claus Gittinger <cg@exept.de>
parents:
2398
diff
changeset
|
349 |
]. |
1124 | 350 |
]. |
351 |
||
1423 | 352 |
"/ let view dispatch it. |
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
353 |
^ false |
1455
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
354 |
|
1552 | 355 |
"Modified: / 23.12.2001 / 13:12:55 / cg" |
1423 | 356 |
! |
1124 | 357 |
|
358 |
requestForWindowClose |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
359 |
"about to close the window." |
1124 | 360 |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
361 |
^ true |
1124 | 362 |
! |
363 |
||
364 |
requestGlobalAutoAccept |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
365 |
"about to close the window via return ok accept. |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
366 |
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
|
367 |
did." |
1124 | 368 |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
369 |
autoAcceptListeners notNil ifTrue:[ |
2249
150a384a74a6
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
2008
diff
changeset
|
370 |
^ autoAcceptListeners conform:[:aListener | (aListener requestAutoAccept)] |
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
371 |
]. |
1458
43c22152a2f5
accept autoAccept (RETURN) if no input field widget is present
Claus Gittinger <cg@exept.de>
parents:
1457
diff
changeset
|
372 |
"/ if no input field (or comparable widget) is present ... |
43c22152a2f5
accept autoAccept (RETURN) if no input field widget is present
Claus Gittinger <cg@exept.de>
parents:
1457
diff
changeset
|
373 |
"/ ^ false <- wrong. |
43c22152a2f5
accept autoAccept (RETURN) if no input field widget is present
Claus Gittinger <cg@exept.de>
parents:
1457
diff
changeset
|
374 |
^ true. |
2249
150a384a74a6
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
2008
diff
changeset
|
375 |
|
150a384a74a6
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
2008
diff
changeset
|
376 |
"Modified: / 13-10-2006 / 12:56:02 / cg" |
1124 | 377 |
! ! |
378 |
||
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
379 |
!KeyboardProcessor methodsFor:'setup'! |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
380 |
|
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
381 |
addAutoAcceptListener:aListener |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
382 |
"add a aListener to my autoAcceptListeners. |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
383 |
Typically, inputFields add themself, to be notified (via requestForAutoAccept) |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
384 |
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
|
385 |
(of course, other listeners are also invited ;-)" |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
386 |
|
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
387 |
autoAcceptListeners isNil ifTrue:[ |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
388 |
autoAcceptListeners := IdentitySet new. |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
389 |
]. |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
390 |
autoAcceptListeners add:aListener |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
391 |
! ! |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
392 |
|
1124 | 393 |
!KeyboardProcessor class methodsFor:'documentation'! |
394 |
||
395 |
version |
|
2821 | 396 |
^ '$Header: /cvs/stx/stx/libview2/KeyboardProcessor.st,v 1.48 2010-02-04 22:07:53 cg Exp $' |
397 |
! |
|
398 |
||
399 |
version_CVS |
|
400 |
^ '$Header: /cvs/stx/stx/libview2/KeyboardProcessor.st,v 1.48 2010-02-04 22:07:53 cg Exp $' |
|
1124 | 401 |
! ! |