author | Claus Gittinger <cg@exept.de> |
Wed, 03 Dec 2008 13:01:17 +0100 | |
changeset 2573 | 8259385b69e3 |
parent 2488 | ed0fabedfe4e |
child 2585 | 8b60021d3d15 |
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 |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
17 |
altFunctionWasExecuted' |
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 |
||
1124 | 65 |
[author:] |
1160 | 66 |
Claus Gittinger |
1124 | 67 |
" |
68 |
||
69 |
||
70 |
||
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 |
||
187 |
menuBar |
|
188 |
"return the value of the instance variable 'menuBar' (automatically generated)" |
|
189 |
||
1443 | 190 |
^ menuBar |
191 |
! |
|
1124 | 192 |
|
193 |
menuBar:something |
|
194 |
"set the value of the instance variable 'menuBar' (automatically generated)" |
|
195 |
||
1443 | 196 |
menuBar := something. |
197 |
! |
|
1124 | 198 |
|
199 |
returnIsOKInDialog:aBoolean |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
200 |
"set the returnIsOK flag. |
1635 | 201 |
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
|
202 |
|
1124 | 203 |
returnIsOKInDialog := aBoolean |
204 |
! ! |
|
205 |
||
206 |
!KeyboardProcessor methodsFor:'event handling'! |
|
207 |
||
1135 | 208 |
processEvent:event forModalView:modalTopOrNil |
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
209 |
"process a key-event; return true, if handled & eaten; false if not. |
1251 | 210 |
Here, first, we look for a globalAccelerator, |
211 |
then for Return and Escape in modal applications, |
|
212 |
(which lead to Accept & Cancel resp.) |
|
213 |
Finally, menu-shortcuts are handled." |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
214 |
|
2007
014e4bfe31f1
must accept an inputField before
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
215 |
|key rawKey topView wg app view action explicitFocusView focusView| |
1124 | 216 |
|
2443
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
217 |
event isKeyEvent ifFalse:[ ^ false ]. |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
218 |
|
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
219 |
key := event key. |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
220 |
rawKey := event rawKey. |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
221 |
|
1124 | 222 |
view := event view. |
223 |
||
2443
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
224 |
topView := modalTopOrNil ? view topView. |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
225 |
wg := topView windowGroup. |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
226 |
app := topView application. |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
227 |
|
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
228 |
"/ 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
|
229 |
"/ without a concrete command key. |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
230 |
"/ 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
|
231 |
"/ cg: disabled for now; |
ecb0212e1c8d
ALT-key processing disabled (temporarily)
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
232 |
"/ leads to occasional leftover popupmenus floating around; |
ecb0212e1c8d
ALT-key processing disabled (temporarily)
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
233 |
"/ ca has to look for this first. |
ecb0212e1c8d
ALT-key processing disabled (temporarily)
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
234 |
false ifTrue:[ |
2443
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
235 |
key = #'Cmd' ifTrue:[ |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
236 |
event isKeyPressEvent ifTrue:[ |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
237 |
altFunctionWasExecuted := false. |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
238 |
] ifFalse:[ |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
239 |
event isKeyReleaseEvent ifTrue:[ |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
240 |
altFunctionWasExecuted ifFalse:[ |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
241 |
(wg processShortcut:event) ifTrue:[ |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
242 |
^ true |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
243 |
]. |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
244 |
]. |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
245 |
]. |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
246 |
]. |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
247 |
] ifFalse:[ |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
248 |
altFunctionWasExecuted := true. |
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
249 |
]. |
2447
ecb0212e1c8d
ALT-key processing disabled (temporarily)
Claus Gittinger <cg@exept.de>
parents:
2443
diff
changeset
|
250 |
]. |
2443
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
251 |
|
1124 | 252 |
event isKeyPressEvent ifTrue:[ |
2443
1043b37a4a5a
Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents:
2400
diff
changeset
|
253 |
"/ key startsWith:'Cmd' |
1124 | 254 |
|
1251 | 255 |
"/ how about global accelerators ? |
256 |
(globalAccelerators notNil |
|
257 |
and:[(action := globalAccelerators at:key ifAbsent:nil) notNil]) |
|
258 |
ifTrue:[ |
|
1492 | 259 |
event consumed:true. |
1251 | 260 |
action isSymbol ifTrue:[ |
1422 | 261 |
app notNil ifTrue:[ |
262 |
action numArgs == 1 ifTrue:[ |
|
263 |
app perform:action with:event |
|
264 |
] ifFalse:[ |
|
265 |
app perform:action |
|
266 |
]. |
|
267 |
] |
|
1251 | 268 |
] ifFalse:[ |
269 |
action numArgs == 1 ifTrue:[ |
|
270 |
action value:event |
|
271 |
] ifFalse:[ |
|
272 |
action value |
|
273 |
] |
|
274 |
]. |
|
1492 | 275 |
"/ ^ true |
276 |
^ event consumed |
|
1251 | 277 |
]. |
1488
9fa3505d2d85
optionBox: cancel-value corrected
Claus Gittinger <cg@exept.de>
parents:
1458
diff
changeset
|
278 |
|
9fa3505d2d85
optionBox: cancel-value corrected
Claus Gittinger <cg@exept.de>
parents:
1458
diff
changeset
|
279 |
topView isModal ifTrue:[ |
1637 | 280 |
(key == #Return and:[returnIsOKInDialog ? true]) ifTrue:[ |
281 |
(wg notNil |
|
2007
014e4bfe31f1
must accept an inputField before
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
282 |
and:[(explicitFocusView := wg explicitFocusView) isNil |
014e4bfe31f1
must accept an inputField before
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
283 |
or:[ explicitFocusView isKeyboardConsumer not |
014e4bfe31f1
must accept an inputField before
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
284 |
or:[ explicitFocusView isInputField ] ] |
014e4bfe31f1
must accept an inputField before
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
285 |
]) ifTrue:[ |
014e4bfe31f1
must accept an inputField before
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
286 |
((focusView := wg focusView) notNil and:[focusView isTextView]) ifTrue:[ |
014e4bfe31f1
must accept an inputField before
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
287 |
focusView isInputField ifFalse:[ |
014e4bfe31f1
must accept an inputField before
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
288 |
"/ modalBox with a TextView |
014e4bfe31f1
must accept an inputField before
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
289 |
^ false |
014e4bfe31f1
must accept an inputField before
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
290 |
]. |
2008
bc367a4d7d6a
kludge for subcanvas-inputfields
Claus Gittinger <cg@exept.de>
parents:
2007
diff
changeset
|
291 |
"/ this is a kludge for subcanvas' input-fields, which |
bc367a4d7d6a
kludge for subcanvas-inputfields
Claus Gittinger <cg@exept.de>
parents:
2007
diff
changeset
|
292 |
"/ are not affected by #requestGlobalAutoAccept below. |
2007
014e4bfe31f1
must accept an inputField before
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
293 |
focusView isAcceptOnReturn ifTrue:[ |
014e4bfe31f1
must accept an inputField before
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
294 |
focusView accept |
014e4bfe31f1
must accept an inputField before
Claus Gittinger <cg@exept.de>
parents:
2006
diff
changeset
|
295 |
]. |
2006
83d2e7259fcf
ignore return (do not close) if the current
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
296 |
]. |
83d2e7259fcf
ignore return (do not close) if the current
Claus Gittinger <cg@exept.de>
parents:
1983
diff
changeset
|
297 |
|
1488
9fa3505d2d85
optionBox: cancel-value corrected
Claus Gittinger <cg@exept.de>
parents:
1458
diff
changeset
|
298 |
self requestGlobalAutoAccept ifFalse:[^ true]. |
1636
c9ed206b5d32
escapeIsCancel/returnIsOK in popup with same app as mainapp
ca
parents:
1635
diff
changeset
|
299 |
|
c9ed206b5d32
escapeIsCancel/returnIsOK in popup with same app as mainapp
ca
parents:
1635
diff
changeset
|
300 |
"/ 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
|
301 |
"/ 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
|
302 |
(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
|
303 |
app doAcceptByReturnKey. |
1488
9fa3505d2d85
optionBox: cancel-value corrected
Claus Gittinger <cg@exept.de>
parents:
1458
diff
changeset
|
304 |
] ifFalse:[ |
9fa3505d2d85
optionBox: cancel-value corrected
Claus Gittinger <cg@exept.de>
parents:
1458
diff
changeset
|
305 |
"/ oldStyle modalBox - for now, let Box handle it itself |
9fa3505d2d85
optionBox: cancel-value corrected
Claus Gittinger <cg@exept.de>
parents:
1458
diff
changeset
|
306 |
^ false |
1422 | 307 |
]. |
1134
758151d73aac
only do autoAccept, if there is no focus view.
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
308 |
^ true |
758151d73aac
only do autoAccept, if there is no focus view.
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
309 |
]. |
1124 | 310 |
]. |
1637 | 311 |
(key == #Escape and:[escapeIsCancelInDialog ? true]) ifTrue:[ |
1636
c9ed206b5d32
escapeIsCancel/returnIsOK in popup with same app as mainapp
ca
parents:
1635
diff
changeset
|
312 |
"/ 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
|
313 |
"/ 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
|
314 |
(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
|
315 |
app doCancelByEscapeKey. |
1488
9fa3505d2d85
optionBox: cancel-value corrected
Claus Gittinger <cg@exept.de>
parents:
1458
diff
changeset
|
316 |
] ifFalse:[ |
9fa3505d2d85
optionBox: cancel-value corrected
Claus Gittinger <cg@exept.de>
parents:
1458
diff
changeset
|
317 |
"/ oldStyle modalBox - for now, let Box handle it itself |
9fa3505d2d85
optionBox: cancel-value corrected
Claus Gittinger <cg@exept.de>
parents:
1458
diff
changeset
|
318 |
^ false |
9fa3505d2d85
optionBox: cancel-value corrected
Claus Gittinger <cg@exept.de>
parents:
1458
diff
changeset
|
319 |
]. |
9fa3505d2d85
optionBox: cancel-value corrected
Claus Gittinger <cg@exept.de>
parents:
1458
diff
changeset
|
320 |
^ true |
9fa3505d2d85
optionBox: cancel-value corrected
Claus Gittinger <cg@exept.de>
parents:
1458
diff
changeset
|
321 |
]. |
1422 | 322 |
]. |
1488
9fa3505d2d85
optionBox: cancel-value corrected
Claus Gittinger <cg@exept.de>
parents:
1458
diff
changeset
|
323 |
|
1455
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
324 |
wg notNil ifTrue:[ |
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
325 |
(self class isMnemonicKeyEvent:event) ifTrue:[ |
1456 | 326 |
"/Transcript showCR:event rawKey. |
327 |
"/Transcript showCR:event key. |
|
1455
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
328 |
(wg processMnemonic:event) ifTrue:[ |
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
329 |
^ true |
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
330 |
] |
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
331 |
]. |
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
332 |
(self class isKeyEventIgnoredAsShortcut:event) ifFalse:[ |
1456 | 333 |
"/Transcript showCR:event rawKey. |
334 |
"/Transcript showCR:event key. |
|
1455
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
335 |
(wg processShortcut:event) ifTrue:[ |
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
336 |
^ true |
1445
50bf6580e064
care for topViews without windowGroup (which should not happen - but...)
tm
parents:
1443
diff
changeset
|
337 |
]. |
1124 | 338 |
]. |
2400
b47e642dd9bc
support ALT-F4 (close window)
Claus Gittinger <cg@exept.de>
parents:
2398
diff
changeset
|
339 |
]. |
b47e642dd9bc
support ALT-F4 (close window)
Claus Gittinger <cg@exept.de>
parents:
2398
diff
changeset
|
340 |
"/ support ALT-F4 (close window) |
b47e642dd9bc
support ALT-F4 (close window)
Claus Gittinger <cg@exept.de>
parents:
2398
diff
changeset
|
341 |
(key == #CloseWindowRequest) ifTrue:[ |
b47e642dd9bc
support ALT-F4 (close window)
Claus Gittinger <cg@exept.de>
parents:
2398
diff
changeset
|
342 |
app notNil ifTrue:[ |
b47e642dd9bc
support ALT-F4 (close window)
Claus Gittinger <cg@exept.de>
parents:
2398
diff
changeset
|
343 |
app closeRequest |
b47e642dd9bc
support ALT-F4 (close window)
Claus Gittinger <cg@exept.de>
parents:
2398
diff
changeset
|
344 |
] ifFalse:[ |
b47e642dd9bc
support ALT-F4 (close window)
Claus Gittinger <cg@exept.de>
parents:
2398
diff
changeset
|
345 |
topView closeRequest |
b47e642dd9bc
support ALT-F4 (close window)
Claus Gittinger <cg@exept.de>
parents:
2398
diff
changeset
|
346 |
]. |
b47e642dd9bc
support ALT-F4 (close window)
Claus Gittinger <cg@exept.de>
parents:
2398
diff
changeset
|
347 |
]. |
1124 | 348 |
]. |
349 |
||
1423 | 350 |
"/ let view dispatch it. |
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
351 |
^ false |
1455
6d385add9b96
shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents:
1453
diff
changeset
|
352 |
|
1552 | 353 |
"Modified: / 23.12.2001 / 13:12:55 / cg" |
1423 | 354 |
! |
1124 | 355 |
|
356 |
requestForWindowClose |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
357 |
"about to close the window." |
1124 | 358 |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
359 |
^ true |
1124 | 360 |
! |
361 |
||
362 |
requestGlobalAutoAccept |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
363 |
"about to close the window via return ok accept. |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
364 |
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
|
365 |
did." |
1124 | 366 |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
367 |
autoAcceptListeners notNil ifTrue:[ |
2249
150a384a74a6
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
2008
diff
changeset
|
368 |
^ autoAcceptListeners conform:[:aListener | (aListener requestAutoAccept)] |
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
369 |
]. |
1458
43c22152a2f5
accept autoAccept (RETURN) if no input field widget is present
Claus Gittinger <cg@exept.de>
parents:
1457
diff
changeset
|
370 |
"/ 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
|
371 |
"/ ^ false <- wrong. |
43c22152a2f5
accept autoAccept (RETURN) if no input field widget is present
Claus Gittinger <cg@exept.de>
parents:
1457
diff
changeset
|
372 |
^ true. |
2249
150a384a74a6
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
2008
diff
changeset
|
373 |
|
150a384a74a6
code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
2008
diff
changeset
|
374 |
"Modified: / 13-10-2006 / 12:56:02 / cg" |
1124 | 375 |
! ! |
376 |
||
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
377 |
!KeyboardProcessor methodsFor:'setup'! |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
378 |
|
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
379 |
addAutoAcceptListener:aListener |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
380 |
"add a aListener to my autoAcceptListeners. |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
381 |
Typically, inputFields add themself, to be notified (via requestForAutoAccept) |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
382 |
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
|
383 |
(of course, other listeners are also invited ;-)" |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
384 |
|
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
385 |
autoAcceptListeners isNil ifTrue:[ |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
386 |
autoAcceptListeners := IdentitySet new. |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
387 |
]. |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
388 |
autoAcceptListeners add:aListener |
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 |
|
1124 | 391 |
!KeyboardProcessor class methodsFor:'documentation'! |
392 |
||
393 |
version |
|
2488
ed0fabedfe4e
also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents:
2447
diff
changeset
|
394 |
^ '$Header: /cvs/stx/stx/libview2/KeyboardProcessor.st,v 1.46 2008-06-04 09:05:35 cg Exp $' |
1124 | 395 |
! ! |