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
|
122
|
14 |
instanceVariableNames:'fields currentField leaveAction
|
|
15 |
wrap'
|
69
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Views-Support'
|
0
|
19 |
!
|
|
20 |
|
|
21 |
EnterFieldGroup comment:'
|
5
|
22 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
69
|
23 |
All Rights Reserved
|
0
|
24 |
|
122
|
25 |
$Header: /cvs/stx/stx/libwidg/EnterFieldGroup.st,v 1.9 1995-05-07 00:15:50 claus Exp $
|
38
|
26 |
'!
|
|
27 |
|
|
28 |
!EnterFieldGroup class methodsFor:'documentation'!
|
|
29 |
|
|
30 |
copyright
|
|
31 |
"
|
|
32 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
69
|
33 |
All Rights Reserved
|
0
|
34 |
|
38
|
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 |
version
|
|
45 |
"
|
122
|
46 |
$Header: /cvs/stx/stx/libwidg/EnterFieldGroup.st,v 1.9 1995-05-07 00:15:50 claus Exp $
|
38
|
47 |
"
|
|
48 |
!
|
|
49 |
|
|
50 |
documentation
|
|
51 |
"
|
|
52 |
EnterFieldGroup controlls the interaction between EnterFields
|
121
|
53 |
enabling next/prev field when a field is left.
|
|
54 |
Instances of this class keep track of which field of the group is the
|
|
55 |
currentField (i.e. the one getting keyboard input) and forwards input
|
|
56 |
to the active field (having the inputField delegate its input to me).
|
|
57 |
|
38
|
58 |
The block accessable as leaveAction is evaluated when the last
|
121
|
59 |
field of the group is left (by cursor-down or cr).
|
|
60 |
Usually this block triggers accept on the fields and/or performs some
|
|
61 |
followup processing and closes the topview (for example: in a dialog).
|
122
|
62 |
|
|
63 |
EnterFieldGroups can be used as a delegate (of the topView) to forward
|
|
64 |
input (entered into the topView) to the currently active field.
|
|
65 |
|
|
66 |
Stepping to previous field is via CursorUp/PreviousField,
|
|
67 |
to next field via CursorDown/NextField/Tab.
|
|
68 |
Notice, that by default, the editField takes the tab-character as
|
|
69 |
a normal character. To step using tab, you have to add the Tab key to the
|
|
70 |
fields leaveKeys.
|
|
71 |
|
|
72 |
Instance variables:
|
|
73 |
|
|
74 |
fields <Collection of EditField> the fields of the group
|
|
75 |
|
|
76 |
currentField <EditField> the active field
|
|
77 |
|
|
78 |
leaveAction <nil|Block> action to perform, when the
|
|
79 |
last field is left by a non-wrap
|
|
80 |
|
|
81 |
wrap <Boolean> if true, non-return next-keys wrap
|
|
82 |
back to the first field.
|
|
83 |
If false (the default), next in
|
|
84 |
the last field is taken as return.
|
|
85 |
This is ignored, if no leaveAction was
|
|
86 |
defined.
|
121
|
87 |
"
|
|
88 |
!
|
|
89 |
|
|
90 |
examples
|
|
91 |
"
|
122
|
92 |
without a group - user has to enter mouse into the next field to activate it;
|
|
93 |
Cursor-keys dont work:
|
121
|
94 |
|
|
95 |
|top panel field1 field2 field3|
|
|
96 |
|
|
97 |
top := StandardSystemView new.
|
|
98 |
top extent:200@200.
|
|
99 |
|
|
100 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
|
|
101 |
|
|
102 |
panel add:(field1 := EditField extent:(1.0 @ nil)).
|
|
103 |
panel add:(field2 := EditField extent:(1.0 @ nil)).
|
|
104 |
panel add:(field3 := EditField extent:(1.0 @ nil)).
|
|
105 |
|
|
106 |
top open
|
|
107 |
|
|
108 |
|
|
109 |
with a group - Return-key or CursorKey enables next field:
|
122
|
110 |
(but still, mouse pointer has to be moved into any of the fields,
|
|
111 |
because the topView does not forward its input into the fields)
|
121
|
112 |
|
|
113 |
|top panel group field1 field2 field3|
|
|
114 |
|
|
115 |
top := StandardSystemView new.
|
|
116 |
top extent:200@200.
|
|
117 |
|
|
118 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
|
|
119 |
|
|
120 |
panel add:(field1 := EditField extent:(1.0 @ nil)).
|
|
121 |
panel add:(field2 := EditField extent:(1.0 @ nil)).
|
|
122 |
panel add:(field3 := EditField extent:(1.0 @ nil)).
|
|
123 |
|
|
124 |
group := EnterFieldGroup new.
|
|
125 |
group add:field1; add:field2; add:field3.
|
|
126 |
|
|
127 |
top open
|
|
128 |
|
|
129 |
|
|
130 |
|
122
|
131 |
same, enables tabbing via the Tab key:
|
|
132 |
|
|
133 |
|top panel group field1 field2 field3|
|
|
134 |
|
|
135 |
top := StandardSystemView new.
|
|
136 |
top extent:200@200.
|
|
137 |
|
|
138 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
|
|
139 |
|
|
140 |
panel add:(field1 := EditField extent:(1.0 @ nil)).
|
|
141 |
panel add:(field2 := EditField extent:(1.0 @ nil)).
|
|
142 |
panel add:(field3 := EditField extent:(1.0 @ nil)).
|
|
143 |
|
|
144 |
group := EnterFieldGroup new.
|
|
145 |
group add:field1; add:field2; add:field3.
|
|
146 |
|
|
147 |
field1 leaveKeys:(EditField defaultLeaveKeys copyWith:#Tab).
|
|
148 |
field2 leaveKeys:(EditField defaultLeaveKeys copyWith:#Tab).
|
|
149 |
field3 leaveKeys:(EditField defaultLeaveKeys copyWith:#Tab).
|
|
150 |
top open
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
with a group - Return-key or CursorKey enables next field:
|
|
155 |
input into topView is forwarded to the group:
|
|
156 |
|
|
157 |
|top panel group field1 field2 field3|
|
|
158 |
|
|
159 |
top := StandardSystemView new.
|
|
160 |
top extent:200@200.
|
|
161 |
|
|
162 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
|
|
163 |
|
|
164 |
panel add:(field1 := EditField extent:(1.0 @ nil)).
|
|
165 |
panel add:(field2 := EditField extent:(1.0 @ nil)).
|
|
166 |
panel add:(field3 := EditField extent:(1.0 @ nil)).
|
|
167 |
|
|
168 |
group := EnterFieldGroup new.
|
|
169 |
group add:field1; add:field2; add:field3.
|
|
170 |
|
|
171 |
top delegate:group.
|
|
172 |
top open
|
|
173 |
|
|
174 |
|
|
175 |
|
|
176 |
as above, but close the box when the last field is left:
|
|
177 |
|
|
178 |
|top panel group field1 field2 field3|
|
|
179 |
|
|
180 |
top := StandardSystemView new.
|
|
181 |
top extent:200@200.
|
|
182 |
|
|
183 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
|
|
184 |
|
|
185 |
panel add:(field1 := EditField extent:(1.0 @ nil)).
|
|
186 |
panel add:(field2 := EditField extent:(1.0 @ nil)).
|
|
187 |
panel add:(field3 := EditField extent:(1.0 @ nil)).
|
|
188 |
|
|
189 |
group := EnterFieldGroup new.
|
|
190 |
group add:field1; add:field2; add:field3.
|
|
191 |
group leaveAction:[top destroy].
|
|
192 |
|
|
193 |
top delegate:group.
|
|
194 |
top open
|
|
195 |
|
|
196 |
|
|
197 |
|
|
198 |
same as above, with Tab-key stepping:
|
121
|
199 |
|
|
200 |
|top panel group field1 field2 field3|
|
|
201 |
|
|
202 |
top := StandardSystemView new.
|
|
203 |
top extent:200@200.
|
|
204 |
|
|
205 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
|
|
206 |
|
|
207 |
panel add:(field1 := EditField extent:(1.0 @ nil)).
|
|
208 |
panel add:(field2 := EditField extent:(1.0 @ nil)).
|
|
209 |
panel add:(field3 := EditField extent:(1.0 @ nil)).
|
|
210 |
|
|
211 |
group := EnterFieldGroup new.
|
|
212 |
group add:field1; add:field2; add:field3.
|
|
213 |
group leaveAction:[top destroy].
|
|
214 |
|
122
|
215 |
field1 leaveKeys:(EditField defaultLeaveKeys copyWith:#Tab).
|
|
216 |
field2 leaveKeys:(EditField defaultLeaveKeys copyWith:#Tab).
|
|
217 |
field3 leaveKeys:(EditField defaultLeaveKeys copyWith:#Tab).
|
|
218 |
|
|
219 |
top delegate:group.
|
121
|
220 |
top open
|
122
|
221 |
|
|
222 |
|
|
223 |
|
|
224 |
the next example shows that the input order is defined by the
|
|
225 |
order in the group; NOT by the physical layout of the fields in the superview:
|
|
226 |
|
|
227 |
|top panel group field1 field2 field3|
|
|
228 |
|
|
229 |
top := StandardSystemView new.
|
|
230 |
top extent:200@200.
|
|
231 |
|
|
232 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
|
|
233 |
|
|
234 |
panel add:(field1 := EditField extent:(1.0 @ nil)).
|
|
235 |
panel add:(field2 := EditField extent:(1.0 @ nil)).
|
|
236 |
panel add:(field3 := EditField extent:(1.0 @ nil)).
|
|
237 |
|
|
238 |
group := EnterFieldGroup new.
|
|
239 |
group add:field3; add:field2; add:field1.
|
|
240 |
group leaveAction:[top destroy].
|
|
241 |
|
|
242 |
top delegate:group.
|
|
243 |
top open
|
|
244 |
|
|
245 |
|
|
246 |
|
|
247 |
using a single model for all fields:
|
|
248 |
(here, we use a Plug to simulate a more complex model):
|
|
249 |
|
|
250 |
|top panel group field1 field2 field3 model
|
|
251 |
value1 value2 value3|
|
|
252 |
|
|
253 |
top := StandardSystemView new.
|
|
254 |
top extent:200@200.
|
|
255 |
|
|
256 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
|
|
257 |
|
|
258 |
panel add:(field1 := EditField extent:(1.0 @ nil)).
|
|
259 |
panel add:(field2 := EditField extent:(1.0 @ nil)).
|
|
260 |
panel add:(field3 := EditField extent:(1.0 @ nil)).
|
|
261 |
|
|
262 |
group := EnterFieldGroup new.
|
|
263 |
group add:field1; add:field2; add:field3.
|
|
264 |
group leaveAction:[top destroy].
|
|
265 |
|
|
266 |
value1 := 'one'. value2 := 'two'. value3 := 'three'.
|
|
267 |
|
|
268 |
model := Plug new.
|
|
269 |
model respondTo:#value1 with:[value1].
|
|
270 |
model respondTo:#value1: with:[:arg | value1 := arg].
|
|
271 |
model respondTo:#value2 with:[value2].
|
|
272 |
model respondTo:#value2: with:[:arg | value2 := arg].
|
|
273 |
model respondTo:#value3 with:[value3].
|
|
274 |
model respondTo:#value3: with:[:arg | value3 := arg].
|
|
275 |
|
|
276 |
field1 model:model; aspect:#value1; change:#value1:.
|
|
277 |
field2 model:model; aspect:#value2; change:#value2:.
|
|
278 |
field3 model:model; aspect:#value3; change:#value3:.
|
|
279 |
|
|
280 |
top delegate:group.
|
|
281 |
top openModal.
|
|
282 |
|
|
283 |
Transcript showCr:'value1: ' , value1.
|
|
284 |
Transcript showCr:'value2: ' , value2.
|
|
285 |
Transcript showCr:'value3: ' , value3.
|
|
286 |
|
|
287 |
|
|
288 |
the above is done automatically for you, if you add inputFields
|
|
289 |
to a dialogBox:
|
|
290 |
|
|
291 |
|box model
|
|
292 |
value1 value2 value3|
|
|
293 |
|
|
294 |
box := DialogBox new.
|
|
295 |
box extent:200@200.
|
|
296 |
|
|
297 |
value1 := 'one'. value2 := 'two'. value3 := 'three'.
|
|
298 |
|
|
299 |
model := Plug new.
|
|
300 |
model respondTo:#value1 with:[value1].
|
|
301 |
model respondTo:#value1: with:[:arg | value1 := arg].
|
|
302 |
model respondTo:#value2 with:[value2].
|
|
303 |
model respondTo:#value2: with:[:arg | value2 := arg].
|
|
304 |
model respondTo:#value3 with:[value3].
|
|
305 |
model respondTo:#value3: with:[:arg | value3 := arg].
|
|
306 |
|
|
307 |
(box addInputFieldOn:model) aspect:#value1; change:#value1:.
|
|
308 |
box addVerticalSpace.
|
|
309 |
(box addInputFieldOn:model) aspect:#value2; change:#value2:.
|
|
310 |
box addVerticalSpace.
|
|
311 |
(box addInputFieldOn:model) aspect:#value3; change:#value3:.
|
|
312 |
|
|
313 |
box open.
|
|
314 |
|
|
315 |
Transcript showCr:'value1: ' , value1.
|
|
316 |
Transcript showCr:'value2: ' , value2.
|
|
317 |
Transcript showCr:'value3: ' , value3.
|
38
|
318 |
"
|
|
319 |
! !
|
0
|
320 |
|
122
|
321 |
!EnterFieldGroup class methodsFor:'instance creation'!
|
|
322 |
|
|
323 |
new
|
|
324 |
^ self basicNew wrap:false
|
|
325 |
! !
|
|
326 |
|
0
|
327 |
!EnterFieldGroup methodsFor:'adding / removing'!
|
|
328 |
|
|
329 |
add:aField
|
122
|
330 |
|thisIndex next action|
|
0
|
331 |
|
|
332 |
fields isNil ifTrue:[
|
69
|
333 |
fields := OrderedCollection new
|
0
|
334 |
].
|
|
335 |
fields add:aField.
|
|
336 |
thisIndex := fields size.
|
121
|
337 |
|
7
|
338 |
aField delegate:self.
|
121
|
339 |
aField hideCursor.
|
0
|
340 |
aField disable.
|
|
341 |
|
|
342 |
"set the fields enableAction to disable active field"
|
|
343 |
|
|
344 |
aField enableAction:[
|
121
|
345 |
"/ Transcript showCr:'enable field with: ' , aField editValue.
|
69
|
346 |
currentField notNil ifTrue:[
|
|
347 |
currentField disable
|
|
348 |
].
|
|
349 |
currentField := aField
|
0
|
350 |
].
|
|
351 |
|
|
352 |
"set the fields leaveAction to enable next field"
|
|
353 |
|
|
354 |
aField leaveAction:[:key |
|
121
|
355 |
"/ Transcript showCr:'left field with: ' , aField editValue.
|
69
|
356 |
currentField notNil ifTrue:[
|
121
|
357 |
currentField disable.
|
|
358 |
currentField hideCursor.
|
69
|
359 |
].
|
122
|
360 |
|
|
361 |
action := key.
|
121
|
362 |
((key == #CursorUp) or:[key == #PreviousField]) ifTrue:[
|
69
|
363 |
(thisIndex == 1) ifTrue:[
|
|
364 |
next := fields size
|
|
365 |
] ifFalse:[
|
|
366 |
next := thisIndex - 1
|
|
367 |
]
|
|
368 |
].
|
122
|
369 |
((key == #CursorDown)
|
|
370 |
or:[key == #NextField
|
|
371 |
or:[key == #Tab]]) ifTrue:[
|
69
|
372 |
(thisIndex == (fields size)) ifTrue:[
|
122
|
373 |
wrap ifFalse:[
|
|
374 |
action := #Return.
|
|
375 |
] ifTrue:[
|
|
376 |
next := 1
|
|
377 |
].
|
69
|
378 |
] ifFalse:[
|
|
379 |
next := thisIndex + 1
|
|
380 |
]
|
|
381 |
].
|
122
|
382 |
(action == #Return) ifTrue:[
|
69
|
383 |
(thisIndex == (fields size)) ifTrue:[
|
|
384 |
leaveAction notNil ifTrue:[
|
|
385 |
leaveAction value.
|
|
386 |
currentField := nil
|
|
387 |
] ifFalse:[
|
|
388 |
next := 1
|
|
389 |
]
|
|
390 |
] ifFalse:[
|
|
391 |
next := thisIndex + 1
|
|
392 |
]
|
|
393 |
].
|
|
394 |
next notNil ifTrue:[
|
121
|
395 |
self makeActive:(fields at:next)
|
69
|
396 |
]
|
121
|
397 |
].
|
|
398 |
|
|
399 |
fields size == 1 ifTrue:[
|
|
400 |
"the first one"
|
|
401 |
self makeActive:aField
|
0
|
402 |
]
|
|
403 |
! !
|
|
404 |
|
|
405 |
!EnterFieldGroup methodsFor:'accessing'!
|
|
406 |
|
122
|
407 |
wrap:aBoolean
|
|
408 |
"specifies if leaveing the last field via non-Return
|
|
409 |
should wrap back to the first, or leave the group"
|
|
410 |
|
|
411 |
wrap := aBoolean
|
|
412 |
!
|
|
413 |
|
0
|
414 |
leaveAction:aBlock
|
121
|
415 |
"set the action to perform when the last field is left.
|
|
416 |
Usually, this is to accept the values of all fields and perform
|
|
417 |
some additional processing (such as closing a dialog)."
|
|
418 |
|
0
|
419 |
leaveAction := aBlock
|
|
420 |
! !
|
|
421 |
|
121
|
422 |
!EnterFieldGroup methodsFor:'misc'!
|
|
423 |
|
|
424 |
activateFirst
|
|
425 |
"pass controll to my first field"
|
|
426 |
|
|
427 |
fields notNil ifTrue:[
|
|
428 |
self makeActive:(fields first)
|
|
429 |
]
|
|
430 |
! !
|
|
431 |
|
|
432 |
!EnterFieldGroup methodsFor:'private'!
|
0
|
433 |
|
7
|
434 |
makeActive:aField
|
121
|
435 |
"make a specific field the active one"
|
|
436 |
|
7
|
437 |
currentField notNil ifTrue:[
|
121
|
438 |
currentField disable.
|
|
439 |
currentField hideCursor.
|
|
440 |
currentField hasKeyboardFocus:false.
|
7
|
441 |
].
|
|
442 |
currentField := aField.
|
|
443 |
currentField enable.
|
121
|
444 |
currentField showCursor.
|
|
445 |
currentField hasKeyboardFocus:true.
|
|
446 |
! !
|
7
|
447 |
|
121
|
448 |
!EnterFieldGroup methodsFor:'event forwarding'!
|
|
449 |
|
|
450 |
handlesKeyPress:key inView:aView
|
|
451 |
"query from event processor: am I interrested in key-events ?
|
|
452 |
yes I am (to forward it to the active field)."
|
|
453 |
|
0
|
454 |
^ true
|
|
455 |
!
|
|
456 |
|
121
|
457 |
handlesButtonPress:button inView:aView
|
|
458 |
"query from event processor: am I interrested in button-events ?
|
|
459 |
yes I am (to activate the clicked-on field)."
|
59
|
460 |
|
121
|
461 |
^ true
|
59
|
462 |
!
|
|
463 |
|
121
|
464 |
handlesButtonShiftPress:button inView:aView
|
|
465 |
"query from event processor: am I interrested in button-events ?
|
|
466 |
yes I am (to activate the clicked-on field)."
|
59
|
467 |
|
121
|
468 |
^ true
|
59
|
469 |
!
|
|
470 |
|
7
|
471 |
keyPress:key x:x y:y view:aView
|
121
|
472 |
"key-press in any field - forward the key to the active field"
|
0
|
473 |
|
|
474 |
currentField notNil ifTrue:[
|
69
|
475 |
currentField keyPress:key x:0 y:0
|
0
|
476 |
]
|
|
477 |
!
|
|
478 |
|
7
|
479 |
buttonPress:button x:x y:y view:aView
|
121
|
480 |
"clicking on a field activates it and forwards the click to it"
|
|
481 |
|
7
|
482 |
self makeActive:aView.
|
|
483 |
aView buttonPress:button x:x y:y
|
0
|
484 |
!
|
|
485 |
|
7
|
486 |
buttonShiftPress:button x:x y:y view:aView
|
121
|
487 |
"clicking on a field activates it and forwards the click to it"
|
|
488 |
|
7
|
489 |
self makeActive:aView.
|
0
|
490 |
aView buttonShiftPress:button x:x y:y
|
|
491 |
! !
|