EFGroup.st
author claus
Sat, 08 Jan 1994 18:27:56 +0100
changeset 21 9ef599238fea
parent 7 15a9291b9bd0
child 38 4b9b70b2cc87
permissions -rw-r--r--
*** empty log message ***

"
 COPYRIGHT (c) 1992 by Claus Gittinger
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"

Object subclass:#EnterFieldGroup
         instanceVariableNames:'fields currentField leaveAction'
         classVariableNames:''
         poolDictionaries:''
         category:'Views-Support'
!

EnterFieldGroup comment:'

COPYRIGHT (c) 1992 by Claus Gittinger
              All Rights Reserved

EnterFieldGroup controlls the interaction between EnterFields
enabling next/prev field when a field is left. Instances of
this class keep track of which field of the group is the currentField
(i.e. the one getting keyboard input).
The block accessable as leaveAction is evaluated when the last
field of the group is left (by cursor-down or cr). Usually this block
triggers some action on the fields.

$Header: /cvs/stx/stx/libwidg/Attic/EFGroup.st,v 1.4 1993-12-11 01:42:31 claus Exp $
written nov 91 by claus
'!

!EnterFieldGroup methodsFor:'adding / removing'!

add:aField
    |thisIndex next|

    fields isNil ifTrue:[
        fields := OrderedCollection new
    ].
    fields add:aField.
    thisIndex := fields size.
    aField delegate:self.
    aField disable.

    "set the fields enableAction to disable active field"

    aField enableAction:[
        currentField notNil ifTrue:[
            currentField disable
        ].
        currentField := aField
    ].

    "set the fields leaveAction to enable next field"

    aField leaveAction:[:key |
        currentField notNil ifTrue:[
            currentField disable
        ].
        (key == #Up) ifTrue:[
            (thisIndex == 1) ifTrue:[
                next := fields size
            ] ifFalse:[
                next := thisIndex - 1
            ]
        ].
        (key == #Down) ifTrue:[
            (thisIndex == (fields size)) ifTrue:[
                next := 1
            ] ifFalse:[
                next := thisIndex + 1
            ]
        ].
        (key == #Return) ifTrue:[
            (thisIndex == (fields size)) ifTrue:[
                leaveAction notNil ifTrue:[
                    leaveAction value.
                    currentField := nil
                ] ifFalse:[
                    next := 1
                ]
            ] ifFalse:[
                next := thisIndex + 1
            ]
        ].
        next notNil ifTrue:[
            (fields at:next) enable.
            currentField := fields at:next
        ]
    ]
! !

!EnterFieldGroup methodsFor:'accessing'!

leaveAction:aBlock
    leaveAction := aBlock
! !

!EnterFieldGroup methodsFor:'controlling'!

makeActive:aField
    currentField notNil ifTrue:[
        currentField disable
    ].
    currentField := aField.
    currentField enable.
!

canHandle:aKey
    ^ true
!

keyPress:key x:x y:y view:aView
    "key-press in a field"

    currentField notNil ifTrue:[
        currentField keyPress:key x:0 y:0
    ]
!

buttonPress:button x:x y:y view:aView
    self makeActive:aView.
    aView buttonPress:button x:x y:y
!

buttonShiftPress:button x:x y:y view:aView
    self makeActive:aView.
    aView buttonShiftPress:button x:x y:y
!

buttonMultiPress:button x:x y:y view:aView
    self makeActive:aView.
    aView buttonMultiPress:button x:x y:y
!

buttonRelease:button x:x y:y view:aView
    aView buttonRelease:button x:x y:y
!

buttonMotion:state x:x y:y view:aView
    aView buttonMotion:state x:x y:y
! !