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