ComboListView.st
author Claus Gittinger <cg@exept.de>
Wed, 04 Sep 1996 23:11:12 +0200
changeset 238 6be113228de3
parent 232 23dd09b9fbdf
child 270 35558a88d500
permissions -rw-r--r--
checkin from browser

ComboView subclass:#ComboListView
	instanceVariableNames:'useIndex'
	classVariableNames:''
	poolDictionaries:''
	category:'Views-Interactors'
!

!ComboListView  class methodsFor:'documentation'!

documentation
"
    A ComboListView combines an label with a drop down list of default inputs;
    choosing any from the pulled list sets the string in the label.

    This is the same as a PopUpList or SelectionInListView, bit looks different.

    Not yet finished.
"
!

examples
"
                                                                [exBegin]
     |top b|

     top := StandardSystemView new.
     top extent:(300 @ 200).

     b := ComboListView in:top.
     b origin:(0.0 @ 0.0) corner:(1.0 @ 0.0).
     b bottomInset:(b preferredExtent y negated).

     b list:#('hello' 'world' 'this' 'is' 'st/x').
     top open.
                                                                [exEnd]



  model operation:
                                                                [exBegin]
     |model top b|

     model := 'foo' asValue.

     top := StandardSystemView new.
     top extent:(300 @ 200).

     b := ComboListView in:top.
     b origin:(0.0 @ 0.0) corner:(1.0 @ 0.0).
     b bottomInset:(b preferredExtent y negated).

     b list:#('hello' 'world' 'this' 'is' 'st/x').
     b model:model.

     top openModal.
     Transcript showCR:('comboBox''s value: ' , model value).
                                                                [exEnd]


  in a dialog:
                                                                [exBegin]
     |model1 model2 dialog b|

     model1 := 'foo' asValue.
     model2 := 'bar' asValue.

     dialog := Dialog new.
     (dialog addTextLabel:'ComboList example:') adjust:#left.
     dialog addVerticalSpace.

     (b := dialog addComboListOn:model1 tabable:true).
     b list:#('fee' 'foe' 'foo').
     dialog addVerticalSpace.

     (b := dialog addComboListOn:model2 tabable:true).
     b list:#('bar' 'baz' 'baloo').
     dialog addVerticalSpace.

     dialog addOkButton.

     dialog open.

     Transcript showCR:('1st comboBox''s value: ' , model1 value).
     Transcript showCR:('2nd comboBox''s value: ' , model2 value).
                                                                [exEnd]
"
! !

!ComboListView methodsFor:'accessing-behavior'!

useIndex:aBoolean
    "specify, if the selected components value or its index in the
     list should be sent to the model. The default is its value."

    useIndex := aBoolean.

    "Created: 26.7.1996 / 17:44:18 / cg"
! !

!ComboListView methodsFor:'accessing-components'!

label 
    "return the label component"

    ^ field

    "Modified: 28.2.1996 / 15:10:50 / cg"
    "Created: 28.2.1996 / 15:13:51 / cg"
! !

!ComboListView methodsFor:'accessing-contents'!

contents:something
    |m|

    (m := field model) notNil ifTrue:[
        m value:something
    ] ifFalse:[
        field label:something
    ]

    "Modified: 15.7.1996 / 12:27:39 / cg"
    "Created: 15.7.1996 / 13:16:49 / cg"
! !

!ComboListView methodsFor:'initialization'!

initialize
    useIndex isNil ifTrue:[useIndex := false].
    super initialize.

    "Created: 26.7.1996 / 17:44:57 / cg"
!

initializeField
    field := Label in:self.
    field level:-1.
    field adjust:#left.

    "
     |b|

     b := ComboListView new.
     b list:#('hello' 'world' 'this' 'is' 'st/x').
     b open
    "

    "Created: 28.2.1996 / 15:13:46 / cg"
    "Modified: 28.2.1996 / 15:18:40 / cg"
! !

!ComboListView methodsFor:'private'!

getValueFromModel
    |val|

    model notNil ifTrue:[
        (model respondsTo:#selection) ifTrue:[
            "/ mhmh - looks like a selectionInList model
            useIndex ifTrue:[
                val := list at:(model selectionIndex)
            ] ifFalse:[
                val := (model selection)
            ]
        ] ifFalse:[
            "/ mhmh - looks like a valueHolder
            useIndex ifTrue:[
                val := list at:(model value)
            ] ifFalse:[
                val := model value
            ].
        ].
        self contents:val
    ].

    "Created: 15.7.1996 / 12:28:53 / cg"
    "Modified: 26.7.1996 / 18:07:04 / cg"
! !

!ComboListView methodsFor:'user interaction'!

entryChanged:index
    |what|

    what := list at:index.
    field label:what.


    model notNil ifTrue:[
        useIndex ifTrue:[
            self sendChangeMessage:changeMsg with:index
"/            model value:index
        ] ifFalse:[
            self sendChangeMessage:changeMsg with:what
"/            model value:what
        ]
    ].
    pullDownButton turnOff.

    "Created: 28.2.1996 / 15:13:46 / cg"
    "Modified: 4.9.1996 / 22:38:57 / cg"
! !

!ComboListView  class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libwidg2/ComboListView.st,v 1.7 1996-09-04 21:11:12 cg Exp $'
! !