ComboBoxView.st
author Claus Gittinger <cg@exept.de>
Fri, 09 Feb 1996 20:28:11 +0100
changeset 126 888d8ccd35af
parent 125 db1c1a8e0384
child 127 9d5cc59863e8
permissions -rw-r--r--
better sizing; forward unknown messages to my inputField

View subclass:#ComboBoxView
	instanceVariableNames:'enterField pullDownButton list'
	classVariableNames:''
	poolDictionaries:''
	category:'Views-Interactors'
!

!ComboBoxView class methodsFor:'documentation'!

documentation
"
    A comboBoxView combines an inputField with a list of default inputs;
    choosing any from the pulled list presets the string in the field.
    In contrast to a popUpList, the string can still be edited -
    the list is actually only a set of values for the convenience of the user.

    This is a first attempt in a comboBox implementation.
    Not yet finished.
"
!

examples
"
     |top b|

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

     b := ComboBoxView 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.



  model operation:

     |model top b|

     model := 'foo' asValue.

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

     b := ComboBoxView 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).


  in a dialog:

     |model1 model2 dialog b|

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

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

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

     (b := dialog addComboBoxOn: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).
"
! !

!ComboBoxView class methodsFor:'defaults'!

buttonForm
    |form|

    form  := Form fromFile:'ComboDn_win.xbm'.
    ^ form on:Display
! !

!ComboBoxView methodsFor:'accessing-components'!

editor
    "return the inputField component"

    ^ enterField

    "Created: 9.2.1996 / 20:18:03 / cg"
!

menuButton
    "return the menuButton component"

    ^ pullDownButton

    "Created: 9.2.1996 / 20:18:18 / cg"
! !

!ComboBoxView methodsFor:'accessing-contents'!

list:aList
    list := aList

    "Created: 9.2.1996 / 00:51:25 / cg"
    "Modified: 9.2.1996 / 00:51:56 / cg"
! !

!ComboBoxView methodsFor:'accessing-mvc'!

action:aBlock 
    enterField action:aBlock

    "Created: 9.2.1996 / 01:44:20 / cg"
!

model
    ^ enterField model

    "Created: 9.2.1996 / 00:50:18 / cg"
!

model:aModel
    enterField model:aModel.

    "Created: 9.2.1996 / 00:50:12 / cg"
! !

!ComboBoxView methodsFor:'initialization'!

initialize
    |ext|

    super initialize.

    enterField := EditField in:self.
    enterField origin:0.0@0.0 corner:1.0@1.0.

    enterField model:('' asValue).

    pullDownButton := Toggle in:self.
    pullDownButton label:(self class buttonForm).
    pullDownButton showLamp:false.
    pullDownButton activeLevel == pullDownButton passiveLevel ifTrue:[
        pullDownButton activeLevel:0.
    ].
    ext := pullDownButton preferredExtent.
    pullDownButton origin:1.0@0.0 corner:1.0@1.0.
    pullDownButton leftInset:(ext x "+ (ViewSpacing//2)") negated.
"/    pullDownButton rightInset:(ViewSpacing//2).

    enterField rightInset:(ext x + (ViewSpacing//2)).

    pullDownButton pressAction:[self pullMenu].

    self height:enterField preferredExtent y + ViewSpacing.

    "
     all of my input goes to the enterfield
    "
    self delegate:(KeyboardForwarder toView:enterField).

    "
     |b|

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

    "Created: 9.2.1996 / 00:05:24 / cg"
    "Modified: 9.2.1996 / 20:06:08 / cg"
! !

!ComboBoxView methodsFor:'message delegation'!

doesNotUnderstand:aMessage
    (enterField respondsTo:aMessage selector) ifTrue:[
        ^ aMessage sendTo:enterField
    ].
    ^ super doesNotUnderstand:aMessage

    "Created: 9.2.1996 / 19:22:51 / cg"
! !

!ComboBoxView methodsFor:'queries'!

preferredExtent
    |pref1 pref2 m mPrefX|

    list isNil ifTrue:[
        mPrefX := 0
    ] ifFalse:[
        m := MenuView labels:list.
        mPrefX := m preferredExtent x.
    ].

    pref1 := enterField preferredExtent.
    pref2 := pullDownButton preferredExtent.
    ^ ((pref1 x + pref2 x) max:mPrefX) @ (pref1 y max:pref2 y)

    "Created: 9.2.1996 / 01:08:47 / cg"
    "Modified: 9.2.1996 / 19:29:58 / cg"
! !

!ComboBoxView methodsFor:'user interaction'!

entryChanged:what
    enterField contents:what.
    enterField accept.
    pullDownButton turnOff.

    "Created: 9.2.1996 / 01:06:01 / cg"
    "Modified: 9.2.1996 / 01:42:38 / cg"
!

pullMenu
    |m org|

    list isNil ifTrue:[^ self].

    m := PopUpMenu
                labels:list
                selectors:#entryChanged:
                args:list
                receiver:self.

    m menuView resize.
    m menuView width:(self width).
    m menuView sizeFixed:true.
    m hideOnRelease:false.

    org := device translatePoint:(0 @ self height) 
                            from:(self id)
                              to:(device rootView id).

    m showAt:org.
    pullDownButton turnOff.

    "Created: 9.2.1996 / 00:36:49 / cg"
    "Modified: 9.2.1996 / 19:23:19 / cg"
! !

!ComboBoxView class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libwidg2/ComboBoxView.st,v 1.3 1996-02-09 19:28:11 cg Exp $'
! !