author | Claus Gittinger <cg@exept.de> |
Tue, 13 Jul 1999 17:38:21 +0200 | |
changeset 1201 | d8c4b4f52e7e |
parent 1160 | 4bd4457b1d90 |
child 1251 | 2b4223c2e092 |
permissions | -rw-r--r-- |
1124 | 1 |
" |
2 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
||
14 |
||
15 |
||
16 |
||
17 |
Object subclass:#KeyboardProcessor |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
18 |
instanceVariableNames:'returnIsOKInDialog escapeIsCancelInDialog menuBar |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
19 |
autoAcceptListeners' |
1124 | 20 |
classVariableNames:'' |
21 |
poolDictionaries:'' |
|
22 |
category:'Interface-Support-UI' |
|
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 |
||
1124 | 67 |
[author:] |
1160 | 68 |
Claus Gittinger |
1124 | 69 |
" |
70 |
||
71 |
||
72 |
||
73 |
||
74 |
! ! |
|
75 |
||
76 |
!KeyboardProcessor methodsFor:'ST80 - mimicri'! |
|
77 |
||
78 |
keyboardConsumers |
|
79 |
^ #() |
|
80 |
||
81 |
"Created: 6.3.1997 / 15:16:32 / cg" |
|
82 |
! |
|
83 |
||
84 |
removeKeyboardReceiver:aController |
|
85 |
||
86 |
"Created: / 31.10.1997 / 01:56:54 / cg" |
|
87 |
! |
|
88 |
||
89 |
sendKeyboardTo:aController |
|
90 |
||
91 |
"Created: / 31.10.1997 / 01:57:15 / cg" |
|
92 |
! |
|
93 |
||
94 |
setActive:aWidget |
|
95 |
||
96 |
"Created: 3.3.1997 / 18:31:09 / cg" |
|
97 |
! ! |
|
98 |
||
99 |
!KeyboardProcessor methodsFor:'accessing'! |
|
100 |
||
101 |
escapeIsCancelInDialog:aBoolean |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
102 |
"set the escapeIsCancel flag. |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
103 |
If off, Escape is NOT handled as cancel (however, the default is true)" |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
104 |
|
1124 | 105 |
escapeIsCancelInDialog := aBoolean |
106 |
! |
|
107 |
||
108 |
menuBar |
|
109 |
"return the value of the instance variable 'menuBar' (automatically generated)" |
|
110 |
||
111 |
^ menuBar! |
|
112 |
||
113 |
menuBar:something |
|
114 |
"set the value of the instance variable 'menuBar' (automatically generated)" |
|
115 |
||
116 |
menuBar := something.! |
|
117 |
||
118 |
returnIsOKInDialog:aBoolean |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
119 |
"set the returnIsOK flag. |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
120 |
If off, Return is NOT handled as accept (however, the default is true)" |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
121 |
|
1124 | 122 |
returnIsOKInDialog := aBoolean |
123 |
||
124 |
! ! |
|
125 |
||
126 |
!KeyboardProcessor methodsFor:'event handling'! |
|
127 |
||
1135 | 128 |
processEvent:event forModalView:modalTopOrNil |
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
129 |
"process a key-event; return true, if handled & eaten; false if not. |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
130 |
Here, Return and Escape are intercepted and lead to Accept & Cancel resp. |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
131 |
Also, in the future, menu-shortcuts will be handled here (does not work yet)" |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
132 |
|
1124 | 133 |
|key topView app view| |
134 |
||
135 |
view := event view. |
|
136 |
||
137 |
event isKeyPressEvent ifTrue:[ |
|
138 |
key := event key. |
|
1135 | 139 |
topView := modalTopOrNil ? view topView. |
1124 | 140 |
app := topView application. |
141 |
||
142 |
topView isModal ifTrue:[ |
|
1146 | 143 |
topView windowGroup explicitFocusView isNil ifTrue:[ |
1134
758151d73aac
only do autoAccept, if there is no focus view.
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
144 |
(returnIsOKInDialog and:[key == #Return]) ifTrue:[ |
758151d73aac
only do autoAccept, if there is no focus view.
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
145 |
self requestGlobalAutoAccept ifFalse:[^ true]. |
758151d73aac
only do autoAccept, if there is no focus view.
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
146 |
app doAccept. |
758151d73aac
only do autoAccept, if there is no focus view.
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
147 |
^ true |
758151d73aac
only do autoAccept, if there is no focus view.
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
148 |
]. |
1124 | 149 |
]. |
1134
758151d73aac
only do autoAccept, if there is no focus view.
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
150 |
|
1124 | 151 |
(escapeIsCancelInDialog and:[key == #Escape]) ifTrue:[ |
152 |
app doCancel. |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
153 |
^ true |
1124 | 154 |
]. |
155 |
]. |
|
156 |
||
157 |
"/ how about menu-shortkeys ? |
|
158 |
(menuBar notNil and:[(menuBar processShortcutKeyEventInMenuBar:event)]) ifTrue:[ |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
159 |
^ true |
1124 | 160 |
] |
161 |
]. |
|
162 |
||
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
163 |
^ false |
1124 | 164 |
|
165 |
"/ let view dispatch it. |
|
166 |
||
167 |
||
168 |
||
169 |
! |
|
170 |
||
171 |
requestForWindowClose |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
172 |
"about to close the window." |
1124 | 173 |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
174 |
^ true |
1124 | 175 |
! |
176 |
||
177 |
requestGlobalAutoAccept |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
178 |
"about to close the window via return ok accept. |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
179 |
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
|
180 |
did." |
1124 | 181 |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
182 |
autoAcceptListeners notNil ifTrue:[ |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
183 |
autoAcceptListeners do:[:aListener | |
1133 | 184 |
(aListener requestAutoAccept) ifFalse:[^ false]. |
185 |
]. |
|
186 |
^ true |
|
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
187 |
]. |
1133 | 188 |
^ false |
1124 | 189 |
|
190 |
! ! |
|
191 |
||
1128
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
192 |
!KeyboardProcessor methodsFor:'setup'! |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
193 |
|
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
194 |
addAutoAcceptListener:aListener |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
195 |
"add a aListener to my autoAcceptListeners. |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
196 |
Typically, inputFields add themself, to be notified (via requestForAutoAccept) |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
197 |
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
|
198 |
(of course, other listeners are also invited ;-)" |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
199 |
|
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
200 |
autoAcceptListeners isNil ifTrue:[ |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
201 |
autoAcceptListeners := IdentitySet new. |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
202 |
]. |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
203 |
autoAcceptListeners add:aListener |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
204 |
! ! |
7810bca304e3
added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents:
1124
diff
changeset
|
205 |
|
1124 | 206 |
!KeyboardProcessor class methodsFor:'documentation'! |
207 |
||
208 |
version |
|
1160 | 209 |
^ '$Header: /cvs/stx/stx/libview2/KeyboardProcessor.st,v 1.8 1999-04-15 12:11:25 cg Exp $' |
1124 | 210 |
! ! |