EnterFieldGroup.st
author claus
Tue, 22 Nov 1994 15:33:56 +0100
changeset 69 2b72a20e61c2
parent 59 450ce95a72a4
child 121 4e63bbdb266a
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

$Header: /cvs/stx/stx/libwidg/EnterFieldGroup.st,v 1.7 1994-11-22 14:33:52 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.7 1994-11-22 14:33:52 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
!

mappedView:aView
    "no interrest in this one ..."

    aView mapped
!

configureX:x y:y width:w height:h view:v
    "no interrest in this one ..."

    v configureX:x y:y width:w height:h
!

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:buttonMask x:x y:y view:aView
    aView buttonMotion:buttonMask x:x y:y
!

pointerEnter:state x:x y:y view:aView
    aView pointerEnter:state x:x y:y.
!

pointerLeave:state view:aView
    aView pointerLeave:state
! !