ListSelectionBox.st
author claus
Sun, 07 Aug 1994 15:23:42 +0200
changeset 38 4b9b70b2cc87
parent 12 1c8e8c53e8cf
child 59 450ce95a72a4
permissions -rw-r--r--
2.10.3 pre-final version

"
 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.5 1994-08-07 13:22:42 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.5 1994-08-07 13:22:42 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).
    typical use is:

        |box|

        box := ListSelectionBox new.
        box title:'select something:'.
        box list:#('foo' 'bar' 'baz').
        box okAction:[:sel | Transcript showCr:'the selection was:' , sel].
        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 v|

    super initialize.

    "need more space than an enterBox"

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

    space2 := 2 * ViewSpacing.

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

    "kludge: see note in EnterBox"
    v origin:(ViewSpacing
              @
              (enterField origin y + enterField height + ViewSpacing)).
    v extent:((width - space2 - (v borderWidth * 2))
              @ 
              (height  
               - ViewSpacing - labelField heightIncludingBorder
               - ViewSpacing - enterField heightIncludingBorder
               - buttonPanel heightIncludingBorder - ViewSpacing
               - space2)
             ).
    v origin:[ViewSpacing
              @
              (enterField origin y + enterField height + ViewSpacing)]
      extent:[(width - space2 - (v borderWidth * 2))
              @ 
              (height
               - ViewSpacing - labelField heightIncludingBorder
               - ViewSpacing - enterField heightIncludingBorder
               - buttonPanel heightIncludingBorder - ViewSpacing
               - space2)
             ].
    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
    ].
    "
     mhm: the lists keyboard functions are disabled,
     and input passed to the enterfield
    "
    selectionList keyboardHandler:self 
!

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

    ^ self
!

realize
    self updateList.
    super realize
! !

!ListSelectionBox methodsFor:'private'!

resize
    "resize myself 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 height +
               ViewSpacing.

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

!ListSelectionBox methodsFor:'accessing'!

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

    selectionList list:aList
! !