ListSelectionBox.st
author Claus Gittinger <cg@exept.de>
Thu, 07 Dec 1995 23:25:03 +0100
changeset 243 5c411425097d
parent 197 00927189c882
child 319 d78f5fbdee27
permissions -rw-r--r--
checkin from browser

"
 COPYRIGHT (c) 1990 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.
"

EnterBox subclass:#ListSelectionBox
	 instanceVariableNames:'selectionList'
	 classVariableNames:''
	 poolDictionaries:''
	 category:'Views-DialogBoxes'
!

!ListSelectionBox class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1990 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.
"
!

documentation
"
    this class implements boxes for selection from a list. It offers
    both an ok- and abort-buttons. The ok-button, if pressed will
    evaluate the okAction (see EnterBox>>action).
    see examples for typical uses.

    Notice, for file selections there is a specialized FileSelectionBox,
    which supports matchPatterns, changing directory etc.
"
!

examples 
"
    simple:

	|box|

	box := ListSelectionBox new.
	box title:'select something:'.
	box list:#('foo' 'bar' 'baz').
	box okAction:[:sel | Transcript showCr:'the selection was:' , sel].
	box showAtPointer


    with a default:

	|box|

	box := ListSelectionBox new.
	box title:'select something:'.
	box list:#('foo' 'bar' 'baz').
	box okAction:[:sel | Transcript showCr:'the selection was:' , sel].
	box initialText:'foo'.
	box showAtPointer


    opening the box modeless (a stand-by box):
    (in this case, the default ok- and abortActions do not hide the box;
     therefore, we have to set those explicitely)

	|box|

	box := ListSelectionBox new.
	box title:'select something:'.
	box list:#('foo' 'bar' 'baz').
	box abortText:'close'.
	box okText:'apply'.
	box okAction:[:sel | Transcript showCr:'the selection was:' , sel].
	box abortAction:[:dummy | box hide].
	box openModeless
"
! !

!ListSelectionBox class methodsFor:'instance creation'!

title:titleString okText:okText abortText:abortText list:aList action:aBlock
    "create and return a new listSelectionBox with list already defined"

    |newBox|

    newBox := super title:titleString okText:okText abortText:abortText
		    action:aBlock.
    ^ newBox list:aList
! !

!ListSelectionBox class methodsFor:'defaults'!

defaultExtent
    ^ (Display pixelPerMillimeter * (80 @ 100)) rounded
!

listViewType
    "return the type of listView 
     - for easier redefinition in subclasses"

    ^ SelectionInListView
! !

!ListSelectionBox methodsFor:'accessing'!

initialText:someString
    "in addition to showing the initial text, also select it in the list"

    super initialText:someString.
    selectionList selectElement:someString.
!

list:aList
    "set the list to be displayed in selection list"

    selectionList list:aList
! !

!ListSelectionBox methodsFor:'accessing-components'!

listView
    "return the listView component"

    ^ selectionList

    "Created: 26.10.1995 / 17:08:32 / cg"
! !

!ListSelectionBox methodsFor:'accessing-look'!

noEnterField
    enterField destroy.
    enterField := nil

    "Created: 26.10.1995 / 17:12:38 / cg"
! !

!ListSelectionBox methodsFor:'initialization'!

focusSequence
    ^ Array with:enterField with:selectionList with:abortButton with:okButton 
!

initialize
    |space2 halfSpace v vbw eH|

    super initialize.

    label := 'Select or enter'.

    "need more space than an enterBox"

    "self height:(height + (font height * 5)).  "

    space2 := 2 * ViewSpacing.
    halfSpace := ViewSpacing // 2.

    v := ScrollableView for:(self class listViewType) in:self.

"/ old:
"/    v origin:[0.0
"/              @
"/              (enterField origin y + enterField height + ViewSpacing)]
"/      extent:[1.0
"/              @ 
"/              (height
"/               - ViewSpacing - labelField heightIncludingBorder
"/               - ViewSpacing - enterField heightIncludingBorder
"/               - buttonPanel heightIncludingBorder - ViewSpacing
"/               - space2)
"/             ].

"/ new:
    v origin:[enterField notNil ifTrue:[
		0.0 @ (enterField origin y + enterField height + ViewSpacing)
	      ] ifFalse:[
		0.0 @ (labelField origin y + labelField height + ViewSpacing)
	      ]
	     ]
      corner:(1.0 @ 1.0).
    v bottomInset:(buttonPanel preferredExtent y + ViewSpacing).

    vbw := v borderWidth.
    v leftInset:halfSpace+vbw;
      rightInset:halfSpace+vbw.

    selectionList := v scrolledView.

    "self updateList."

    "I am interested in what is done int the selectionList
     (could also create a SelectionInList-model and catch its changes ...)"
    selectionList action:[:lineNr | self selectionChanged].
    selectionList doubleClickAction:[:lineNr | self doubleClick].

    enterField removeDependent:self. "dont want preferredExtent-changes"

    "
     mhm: the lists keyboard functions are disabled,
     and input passed to the enterfield
    "
    selectionList delegate:(KeyboardForwarder toView:enterField condition:#noFocus)

    "Modified: 26.10.1995 / 17:18:23 / cg"
!

realize
    self updateList.
    super realize
!

updateList
    "setup contents of list; nothing done here but redefined in subclasses"

    ^ self
! !

!ListSelectionBox methodsFor:'queries'!

preferredExtent
    "return my preferred extent - thats the minimum size 
     I like to have, to make everything visible"

    |wWanted hWanted eH|

    wWanted := labelField width + ViewSpacing + ViewSpacing.
    (wWanted > width) ifFalse:[
	wWanted := width
    ].

    enterField notNil ifTrue:[
	eH := enterField height + ViewSpacing
    ] ifFalse:[
	eH := 0
    ].
    hWanted := ViewSpacing + labelField height +
	       eH +
	       ViewSpacing + selectionList height +
	       ViewSpacing + buttonPanel preferredExtent y +
	       ViewSpacing - (ViewSpacing * 2).

    (hWanted < height) ifTrue:[
	hWanted := height
    ].
    ^ (wWanted @ hWanted)

    "Modified: 26.10.1995 / 17:13:53 / cg"
! !

!ListSelectionBox methodsFor:'user actions'!

doubleClick
    "doubleClick on an entry is select & ok"

    enterField contents:(selectionList selectionValue).
    self okPressed
!

selectionChanged
    "selections in list get forwarded to enterfield"

    enterField notNil ifTrue:[
	enterField contents:(selectionList selectionValue)
    ]

    "Modified: 26.10.1995 / 17:20:06 / cg"
! !

!ListSelectionBox class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libwidg/ListSelectionBox.st,v 1.21 1995-12-07 22:23:33 cg Exp $'
! !