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