0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
69
|
3 |
All Rights Reserved
|
0
|
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 |
|
7
|
13 |
Object subclass:#EnterFieldGroup
|
69
|
14 |
instanceVariableNames:'fields currentField leaveAction'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Views-Support'
|
0
|
18 |
!
|
|
19 |
|
|
20 |
EnterFieldGroup comment:'
|
5
|
21 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
69
|
22 |
All Rights Reserved
|
0
|
23 |
|
121
|
24 |
$Header: /cvs/stx/stx/libwidg/EnterFieldGroup.st,v 1.8 1995-05-06 14:16:40 claus Exp $
|
38
|
25 |
'!
|
|
26 |
|
|
27 |
!EnterFieldGroup class methodsFor:'documentation'!
|
|
28 |
|
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
69
|
32 |
All Rights Reserved
|
0
|
33 |
|
38
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
|
42 |
|
|
43 |
version
|
|
44 |
"
|
121
|
45 |
$Header: /cvs/stx/stx/libwidg/EnterFieldGroup.st,v 1.8 1995-05-06 14:16:40 claus Exp $
|
38
|
46 |
"
|
|
47 |
!
|
|
48 |
|
|
49 |
documentation
|
|
50 |
"
|
|
51 |
EnterFieldGroup controlls the interaction between EnterFields
|
121
|
52 |
enabling next/prev field when a field is left.
|
|
53 |
Instances of this class keep track of which field of the group is the
|
|
54 |
currentField (i.e. the one getting keyboard input) and forwards input
|
|
55 |
to the active field (having the inputField delegate its input to me).
|
|
56 |
|
38
|
57 |
The block accessable as leaveAction is evaluated when the last
|
121
|
58 |
field of the group is left (by cursor-down or cr).
|
|
59 |
Usually this block triggers accept on the fields and/or performs some
|
|
60 |
followup processing and closes the topview (for example: in a dialog).
|
|
61 |
"
|
|
62 |
!
|
|
63 |
|
|
64 |
examples
|
|
65 |
"
|
|
66 |
without a group - user has to click on next field to activate it:
|
|
67 |
|
|
68 |
|top panel field1 field2 field3|
|
|
69 |
|
|
70 |
top := StandardSystemView new.
|
|
71 |
top extent:200@200.
|
|
72 |
|
|
73 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
|
|
74 |
|
|
75 |
panel add:(field1 := EditField extent:(1.0 @ nil)).
|
|
76 |
panel add:(field2 := EditField extent:(1.0 @ nil)).
|
|
77 |
panel add:(field3 := EditField extent:(1.0 @ nil)).
|
|
78 |
|
|
79 |
top open
|
|
80 |
|
|
81 |
|
|
82 |
with a group - Return-key or CursorKey enables next field:
|
|
83 |
|
|
84 |
|top panel group field1 field2 field3|
|
|
85 |
|
|
86 |
top := StandardSystemView new.
|
|
87 |
top extent:200@200.
|
|
88 |
|
|
89 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
|
|
90 |
|
|
91 |
panel add:(field1 := EditField extent:(1.0 @ nil)).
|
|
92 |
panel add:(field2 := EditField extent:(1.0 @ nil)).
|
|
93 |
panel add:(field3 := EditField extent:(1.0 @ nil)).
|
|
94 |
|
|
95 |
group := EnterFieldGroup new.
|
|
96 |
group add:field1; add:field2; add:field3.
|
|
97 |
|
|
98 |
top open
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
with a group - close the box when the last field is left:
|
|
103 |
|
|
104 |
|top panel group field1 field2 field3|
|
|
105 |
|
|
106 |
top := StandardSystemView new.
|
|
107 |
top extent:200@200.
|
|
108 |
|
|
109 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
|
|
110 |
|
|
111 |
panel add:(field1 := EditField extent:(1.0 @ nil)).
|
|
112 |
panel add:(field2 := EditField extent:(1.0 @ nil)).
|
|
113 |
panel add:(field3 := EditField extent:(1.0 @ nil)).
|
|
114 |
|
|
115 |
group := EnterFieldGroup new.
|
|
116 |
group add:field1; add:field2; add:field3.
|
|
117 |
group leaveAction:[top destroy].
|
|
118 |
|
|
119 |
top open
|
38
|
120 |
"
|
|
121 |
! !
|
0
|
122 |
|
|
123 |
!EnterFieldGroup methodsFor:'adding / removing'!
|
|
124 |
|
|
125 |
add:aField
|
|
126 |
|thisIndex next|
|
|
127 |
|
|
128 |
fields isNil ifTrue:[
|
69
|
129 |
fields := OrderedCollection new
|
0
|
130 |
].
|
|
131 |
fields add:aField.
|
|
132 |
thisIndex := fields size.
|
121
|
133 |
|
7
|
134 |
aField delegate:self.
|
121
|
135 |
aField hideCursor.
|
0
|
136 |
aField disable.
|
|
137 |
|
|
138 |
"set the fields enableAction to disable active field"
|
|
139 |
|
|
140 |
aField enableAction:[
|
121
|
141 |
"/ Transcript showCr:'enable field with: ' , aField editValue.
|
69
|
142 |
currentField notNil ifTrue:[
|
|
143 |
currentField disable
|
|
144 |
].
|
|
145 |
currentField := aField
|
0
|
146 |
].
|
|
147 |
|
|
148 |
"set the fields leaveAction to enable next field"
|
|
149 |
|
|
150 |
aField leaveAction:[:key |
|
121
|
151 |
"/ Transcript showCr:'left field with: ' , aField editValue.
|
69
|
152 |
currentField notNil ifTrue:[
|
121
|
153 |
currentField disable.
|
|
154 |
currentField hideCursor.
|
69
|
155 |
].
|
121
|
156 |
((key == #CursorUp) or:[key == #PreviousField]) ifTrue:[
|
69
|
157 |
(thisIndex == 1) ifTrue:[
|
|
158 |
next := fields size
|
|
159 |
] ifFalse:[
|
|
160 |
next := thisIndex - 1
|
|
161 |
]
|
|
162 |
].
|
121
|
163 |
((key == #CursorDown) or:[key == #NextField]) ifTrue:[
|
69
|
164 |
(thisIndex == (fields size)) ifTrue:[
|
|
165 |
next := 1
|
|
166 |
] ifFalse:[
|
|
167 |
next := thisIndex + 1
|
|
168 |
]
|
|
169 |
].
|
|
170 |
(key == #Return) ifTrue:[
|
|
171 |
(thisIndex == (fields size)) ifTrue:[
|
|
172 |
leaveAction notNil ifTrue:[
|
|
173 |
leaveAction value.
|
|
174 |
currentField := nil
|
|
175 |
] ifFalse:[
|
|
176 |
next := 1
|
|
177 |
]
|
|
178 |
] ifFalse:[
|
|
179 |
next := thisIndex + 1
|
|
180 |
]
|
|
181 |
].
|
|
182 |
next notNil ifTrue:[
|
121
|
183 |
self makeActive:(fields at:next)
|
|
184 |
"/ (fields at:next) enable.
|
|
185 |
"/ currentField := fields at:next
|
69
|
186 |
]
|
121
|
187 |
].
|
|
188 |
|
|
189 |
fields size == 1 ifTrue:[
|
|
190 |
"the first one"
|
|
191 |
self makeActive:aField
|
0
|
192 |
]
|
|
193 |
! !
|
|
194 |
|
|
195 |
!EnterFieldGroup methodsFor:'accessing'!
|
|
196 |
|
|
197 |
leaveAction:aBlock
|
121
|
198 |
"set the action to perform when the last field is left.
|
|
199 |
Usually, this is to accept the values of all fields and perform
|
|
200 |
some additional processing (such as closing a dialog)."
|
|
201 |
|
0
|
202 |
leaveAction := aBlock
|
|
203 |
! !
|
|
204 |
|
121
|
205 |
!EnterFieldGroup methodsFor:'misc'!
|
|
206 |
|
|
207 |
activateFirst
|
|
208 |
"pass controll to my first field"
|
|
209 |
|
|
210 |
fields notNil ifTrue:[
|
|
211 |
self makeActive:(fields first)
|
|
212 |
]
|
|
213 |
! !
|
|
214 |
|
|
215 |
!EnterFieldGroup methodsFor:'private'!
|
0
|
216 |
|
7
|
217 |
makeActive:aField
|
121
|
218 |
"make a specific field the active one"
|
|
219 |
|
7
|
220 |
currentField notNil ifTrue:[
|
121
|
221 |
currentField disable.
|
|
222 |
currentField hideCursor.
|
|
223 |
currentField hasKeyboardFocus:false.
|
7
|
224 |
].
|
|
225 |
currentField := aField.
|
|
226 |
currentField enable.
|
121
|
227 |
currentField showCursor.
|
|
228 |
currentField hasKeyboardFocus:true.
|
|
229 |
! !
|
7
|
230 |
|
121
|
231 |
!EnterFieldGroup methodsFor:'event forwarding'!
|
|
232 |
|
|
233 |
handlesKeyPress:key inView:aView
|
|
234 |
"query from event processor: am I interrested in key-events ?
|
|
235 |
yes I am (to forward it to the active field)."
|
|
236 |
|
0
|
237 |
^ true
|
|
238 |
!
|
|
239 |
|
121
|
240 |
handlesButtonPress:button inView:aView
|
|
241 |
"query from event processor: am I interrested in button-events ?
|
|
242 |
yes I am (to activate the clicked-on field)."
|
59
|
243 |
|
121
|
244 |
^ true
|
59
|
245 |
!
|
|
246 |
|
121
|
247 |
handlesButtonShiftPress:button inView:aView
|
|
248 |
"query from event processor: am I interrested in button-events ?
|
|
249 |
yes I am (to activate the clicked-on field)."
|
59
|
250 |
|
121
|
251 |
^ true
|
59
|
252 |
!
|
|
253 |
|
7
|
254 |
keyPress:key x:x y:y view:aView
|
121
|
255 |
"key-press in any field - forward the key to the active field"
|
0
|
256 |
|
|
257 |
currentField notNil ifTrue:[
|
69
|
258 |
currentField keyPress:key x:0 y:0
|
0
|
259 |
]
|
|
260 |
!
|
|
261 |
|
121
|
262 |
keyPress:key x:x y:y
|
|
263 |
"key-press in an enclosing view (via delegation)
|
|
264 |
forward the key to the active field"
|
|
265 |
|
|
266 |
currentField notNil ifTrue:[
|
|
267 |
currentField keyPress:key x:-1 y:-1
|
|
268 |
]
|
|
269 |
!
|
|
270 |
|
7
|
271 |
buttonPress:button x:x y:y view:aView
|
121
|
272 |
"clicking on a field activates it and forwards the click to it"
|
|
273 |
|
7
|
274 |
self makeActive:aView.
|
|
275 |
aView buttonPress:button x:x y:y
|
0
|
276 |
!
|
|
277 |
|
7
|
278 |
buttonShiftPress:button x:x y:y view:aView
|
121
|
279 |
"clicking on a field activates it and forwards the click to it"
|
|
280 |
|
7
|
281 |
self makeActive:aView.
|
0
|
282 |
aView buttonShiftPress:button x:x y:y
|
|
283 |
! !
|