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