ListSelectionBox.st
author claus
Wed, 17 May 1995 14:26:27 +0200
changeset 128 06a050529335
parent 125 3ffa271732f7
child 130 338e856bddc9
permissions -rw-r--r--
.

"
 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 comment:'
COPYRIGHT (c) 1990 by Claus Gittinger
	      All Rights Reserved

$Header: /cvs/stx/stx/libwidg/ListSelectionBox.st,v 1.13 1995-05-17 12:25:14 claus Exp $
'!

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

version
"
$Header: /cvs/stx/stx/libwidg/ListSelectionBox.st,v 1.13 1995-05-17 12:25:14 claus Exp $
"
!

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

!ListSelectionBox class methodsFor:'defaults'!

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

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

    ^ SelectionInListView
! !

!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 methodsFor:'initialization'!

initialize
    |space2 halfSpace v|

    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.

    "kludge: see note in EnterBox"
"/    v origin:(0.0 
"/              @
"/              (enterField origin y + enterField height + ViewSpacing)).
"/    v extent:(1.0
"/              @ 
"/              (height  
"/               - ViewSpacing - labelField heightIncludingBorder
"/               - ViewSpacing - enterField heightIncludingBorder
"/               - buttonPanel heightIncludingBorder - ViewSpacing
"/               - space2)
"/             ).
    v origin:[0.0
	      @
	      (enterField origin y + enterField height + ViewSpacing)]
      extent:[1.0
	      @ 
	      (height
	       - ViewSpacing - labelField heightIncludingBorder
	       - ViewSpacing - enterField heightIncludingBorder
	       - buttonPanel heightIncludingBorder - ViewSpacing
	       - space2)
	     ].
    v leftInset:halfSpace; rightInset:halfSpace.

    selectionList := v scrolledView.

    "self updateList."

    "selections in list get forwarded to enterfield"
    selectionList action:[:lineNr |
	enterField contents:(selectionList selectionValue)
    ].
    selectionList doubleClickAction:[:lineNr |
	enterField contents:(selectionList selectionValue).
	self okPressed
    ].
    enterField removeDependent:self. "dont want preferedExtent-changes"

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

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

    ^ self
!

realize
    self updateList.
    super realize
!

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

!ListSelectionBox methodsFor:'queries'!

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

    |wWanted hWanted|


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

    hWanted := ViewSpacing + labelField height +
	       ViewSpacing + enterField height +
	       ViewSpacing + selectionList height +
	       ViewSpacing + buttonPanel preferedExtent y +
	       ViewSpacing - (ViewSpacing * 2).

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

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