EnterFieldGroup.st
author claus
Sun, 07 Aug 1994 15:23:42 +0200
changeset 38 4b9b70b2cc87
parent 7 15a9291b9bd0
child 59 450ce95a72a4
permissions -rw-r--r--
2.10.3 pre-final version

"
 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

$Header: /cvs/stx/stx/libwidg/EnterFieldGroup.st,v 1.5 1994-08-07 13:21:19 claus Exp $
'!

!EnterFieldGroup class methodsFor:'documentation'!

copyright
"
 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.
"
!

version
"
$Header: /cvs/stx/stx/libwidg/EnterFieldGroup.st,v 1.5 1994-08-07 13:21:19 claus Exp $
"
!

documentation
"
    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.
"
! !

!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
! !