EnterFieldGroup.st
changeset 278 7a01cd530452
parent 258 ae4b8f1a6738
child 316 1e27aa926710
equal deleted inserted replaced
277:243d138cf316 278:7a01cd530452
     9  other person.  No title to or ownership of the software is
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 
    12 
    13 Object subclass:#EnterFieldGroup
    13 Object subclass:#EnterFieldGroup
    14 	 instanceVariableNames:'fields currentField leaveAction wrap'
    14 	instanceVariableNames:'fields currentField leaveAction wrap'
    15 	 classVariableNames:''
    15 	classVariableNames:''
    16 	 poolDictionaries:''
    16 	poolDictionaries:''
    17 	 category:'Interface-Support'
    17 	category:'Interface-Support'
    18 !
    18 !
    19 
    19 
    20 !EnterFieldGroup class methodsFor:'documentation'!
    20 !EnterFieldGroup class methodsFor:'documentation'!
    21 
    21 
    22 copyright
    22 copyright
   304 	Transcript showCr:'value2: ' , value2.
   304 	Transcript showCr:'value2: ' , value2.
   305 	Transcript showCr:'value3: ' , value3.
   305 	Transcript showCr:'value3: ' , value3.
   306 "
   306 "
   307 ! !
   307 ! !
   308 
   308 
   309 !EnterFieldGroup class methodsFor:'instance creation'!
       
   310 
       
   311 new
       
   312     ^ self basicNew wrap:false
       
   313 ! !
       
   314 
       
   315 !EnterFieldGroup methodsFor:'accessing'!
   309 !EnterFieldGroup methodsFor:'accessing'!
       
   310 
       
   311 fields
       
   312     "return a collection of the inputFields contained in the group."
       
   313 
       
   314      ^ fields
       
   315 !
   316 
   316 
   317 leaveAction:aBlock
   317 leaveAction:aBlock
   318     "set the action to perform when the last field is left.
   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
   319      Usually, this is to accept the values of all fields and perform
   320      some additional processing (such as closing a dialog)."
   320      some additional processing (such as closing a dialog)."
   321 
   321 
   322     leaveAction := aBlock
   322     leaveAction := aBlock
   323 !
   323 !
   324 
   324 
   325 wrap:aBoolean
   325 wrap:aBoolean
   326     "specifies if leaveing the last field via non-Return
   326     "specifies if leaving the last field via non-Return
   327      should wrap back to the first, or leave the group"
   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."
   328 
   330 
   329     wrap := aBoolean
   331     wrap := aBoolean
   330 ! !
   332 ! !
   331 
   333 
   332 !EnterFieldGroup methodsFor:'adding / removing'!
   334 !EnterFieldGroup methodsFor:'adding / removing'!
   333 
   335 
   334 add:aField
   336 add:aField
   335     |thisIndex next action|
   337     |thisIndex next action|
   336 
   338 
   337     fields isNil ifTrue:[
   339     fields isNil ifTrue:[
   338 	fields := OrderedCollection new
   340         fields := OrderedCollection new
   339     ].
   341     ].
   340     fields add:aField.
   342     fields add:aField.
   341     thisIndex := fields size.
   343     thisIndex := fields size.
   342 
   344 
   343     aField delegate:self.
   345     aField delegate:self.
   350 "/ Transcript showCr:'enable field with: ' , aField editValue.
   352 "/ Transcript showCr:'enable field with: ' , aField editValue.
   351 "/        currentField notNil ifTrue:[
   353 "/        currentField notNil ifTrue:[
   352 "/            currentField disable
   354 "/            currentField disable
   353 "/        ].
   355 "/        ].
   354 "/        currentField := aField
   356 "/        currentField := aField
   355 	self makeActive:aField
   357         self makeActive:aField
   356     ].
   358     ].
   357 
   359 
   358     "set the fields leaveAction to enable next field"
   360     "set the fields leaveAction to enable next field"
   359 
   361 
   360     aField leaveAction:[:key |
   362     aField leaveAction:[:key |
   361 "/ Transcript showCr:'left field with: ' , aField editValue.
   363 "/ Transcript showCr:'left field with: ' , aField editValue.
   362 	currentField notNil ifTrue:[
   364         currentField notNil ifTrue:[
   363 	    currentField disable.
   365             currentField disable.
   364 	    currentField hideCursor.
   366             currentField hideCursor.
   365 	].
   367         ].
   366 
   368 
   367 	action := key.
   369         action := key.
   368 	((key == #CursorUp) or:[key == #PreviousField]) ifTrue:[
   370         ((key == #CursorUp) or:[key == #PreviousField]) ifTrue:[
   369 	    (thisIndex == 1) ifTrue:[
   371             (thisIndex == 1) ifTrue:[
   370 		next := fields size
   372                 next := fields size
   371 	    ] ifFalse:[
   373             ] ifFalse:[
   372 		next := thisIndex - 1
   374                 next := thisIndex - 1
   373 	    ]
   375             ]
   374 	].
   376         ].
   375 	((key == #CursorDown) 
   377         ((key == #CursorDown) 
   376 	or:[key == #NextField
   378         or:[key == #NextField
   377 	or:[key == #Tab]]) ifTrue:[
   379         or:[key == #Tab]]) ifTrue:[
   378 	    (thisIndex == (fields size)) ifTrue:[
   380             (thisIndex == (fields size)) ifTrue:[
   379 		wrap ifFalse:[
   381                 next := 1.
   380 		    action := #Return.
   382                 wrap == false ifTrue:[
   381 		] ifTrue:[
   383                     action := #Return.
   382 		    next := 1
   384                 ].
   383 		].
   385             ] ifFalse:[
   384 	    ] ifFalse:[
   386                 next := thisIndex + 1
   385 		next := thisIndex + 1
   387             ]
   386 	    ]
   388         ].
   387 	].
   389         (action == #Return) ifTrue:[
   388 	(action == #Return) ifTrue:[
   390             (thisIndex == (fields size)) ifTrue:[
   389 	    (thisIndex == (fields size)) ifTrue:[
   391                 leaveAction notNil ifTrue:[
   390 		leaveAction notNil ifTrue:[
   392                     currentField := nil.
   391 		    leaveAction value.
   393                     leaveAction value.
   392 		    currentField := nil
   394                     next := nil
   393 		] ifFalse:[
   395                 ] ifFalse:[
   394 		    next := 1
   396                     next := 1
   395 		]
   397                 ]
   396 	    ] ifFalse:[
   398             ] ifFalse:[
   397 		next := thisIndex + 1
   399                 next := thisIndex + 1
   398 	    ]
   400             ]
   399 	].
   401         ].
   400 	next notNil ifTrue:[
   402         next notNil ifTrue:[
   401 	    self makeActive:(fields at:next) 
   403             self makeActive:(fields at:next) 
   402 	]
   404         ]
   403     ].
   405     ].
   404 
   406 
   405     fields size == 1 ifTrue:[
   407     fields size == 1 ifTrue:[
   406 	"the first one"
   408         "the first one"
   407 	self makeActive:aField
   409         self makeActive:aField
   408     ]
   410     ]
   409 ! !
   411 ! !
   410 
   412 
   411 !EnterFieldGroup methodsFor:'event forwarding'!
   413 !EnterFieldGroup methodsFor:'event forwarding'!
   412 
   414 
   456     "key-press in any field - forward the key to the active field
   458     "key-press in any field - forward the key to the active field
   457      (with -1/-1 as coordinate to indicate that the key was pressed
   459      (with -1/-1 as coordinate to indicate that the key was pressed
   458       outside. However, this info is not used by any view currently)"
   460       outside. However, this info is not used by any view currently)"
   459 
   461 
   460     currentField notNil ifTrue:[
   462     currentField notNil ifTrue:[
   461 	currentField keyPress:key x:-1 y:-1
   463         currentField keyPress:key x:-1 y:-1
   462     ]
   464     ]
   463 !
   465 !
   464 
   466 
   465 keyRelease:key x:x y:y view:aView
   467 keyRelease:key x:x y:y view:aView
   466     "key-release in any field - forward the key to the active field.
   468     "key-release in any field - forward the key to the active field.
   499 ! !
   501 ! !
   500 
   502 
   501 !EnterFieldGroup class methodsFor:'documentation'!
   503 !EnterFieldGroup class methodsFor:'documentation'!
   502 
   504 
   503 version
   505 version
   504     ^ '$Header: /cvs/stx/stx/libwidg/EnterFieldGroup.st,v 1.16 1995-12-15 13:04:00 cg Exp $'
   506     ^ '$Header: /cvs/stx/stx/libwidg/EnterFieldGroup.st,v 1.17 1996-01-10 14:48:01 ca Exp $'
   505 ! !
   507 ! !