OptionBox.st
author claus
Wed, 13 Oct 1993 03:49:56 +0100
changeset 5 7b4fb1b170e5
parent 3 9d7eefb5e69f
child 7 15a9291b9bd0
permissions -rw-r--r--
(none)

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

ModalBox subclass:#OptionBox
         instanceVariableNames:'formLabel textLabel buttons actions'
         classVariableNames:'warnBitmap'
         poolDictionaries:''
         category:'Views-Interactors'
!

OptionBox comment:'

COPYRIGHT (c) 1991 by Claus Gittinger
             All Rights Reserved

like a YesNoBox but with as many as you like buttons in it;
will finally be a superclass of WarnBox and YesNoBox.

$Header: /cvs/stx/stx/libwidg/OptionBox.st,v 1.3 1993-10-13 02:48:40 claus Exp $

written Nov 91 by claus
'!

!OptionBox class methodsFor:'instance creation'!

title:titleString numberOfOptions:nOptions
    "create a new optionBox with title, aTitleString and nOptions options"

    |box|

    box := (self basicNew) numberOfOptions:nOptions.
    box device:ModalDisplay.
    box initialize.
    box title:titleString.
    ^ box
! !

!OptionBox methodsFor:'accessing'!

title:aString numberOfOptions:nOptions
    "set the title and number of options"

    textLabel label:aString.
    textLabel resize.
    buttons grow:nOptions.
    actions grow:nOptions
!

title:aString
    "set the title"

    textLabel label:aString.
    textLabel resize.
    self resize
!

numberOfOptions:nOptions
    "set the number of options"

    buttons := Array new:nOptions.
    actions := Array new:nOptions
!

buttonTitles:titles
    |index|

    index := 1.
    titles do:[:aString |
        (buttons at:index) label:aString.
        index := index + 1
    ].
    self resize
!

actions:actionBlocks
    actions := actionBlocks
!

buttonTitles:titles actions:actionBlocks
    |index|

    index := 1.
    titles do:[:aString |
        (buttons at:index) label:aString.
        index := index + 1
    ].
    actions := actionBlocks.
    self resize
!

numberOfOptions
    "return the number of options"

    ^ buttons size
! !

!OptionBox methodsFor:'initializing'!

initialize
    |nButt|

    super initialize.

    warnBitmap isNil ifTrue:[
        warnBitmap := Form fromFile:'Warning.xbm' resolution:100 on:device
    ].

    formLabel := Label form:warnBitmap in:self.
    formLabel borderWidth:0.
    formLabel origin:(ViewSpacing @ ViewSpacing).

    textLabel := Label label:'Warning' in:self.
    textLabel borderWidth:0.
    textLabel origin:((ViewSpacing + formLabel width + ViewSpacing) @ ViewSpacing).

    nButt := buttons size.

    1 to:nButt do:[:b |
        buttons at:b put:(Button label:'press'
                                action:[(buttons at:b) turnOff.
                                        self hide.
                                        (actions at:b) notNil ifTrue:[
                                            (actions at:b) value
                                        ]
                                       ]
                                    in:self).
        (buttons at:b) origin:[( (b - 1) * ((width - ViewSpacing) // nButt) + (ViewSpacing // 2) )
                               @
                               (height - ViewSpacing - (buttons at:b) height)].
        (buttons at:b) extent:[(width // nButt - ViewSpacing) @ (buttons at:b) height]
    ]
! !

!OptionBox methodsFor:'private'!

resize
    "resize myself to make everything fit into myself"

    |w w1 w2 h extra|

    w1 := ViewSpacing + formLabel width + ViewSpacing + textLabel width + ViewSpacing.

    w2 := 0.
    buttons do:[:butt |
        w2 := w2 + butt width "labelWidth".
        w2 := w2 + ViewSpacing
    ].
    w2 := w2 + (4 * ViewSpacing).
    w := w1 max:w2.

    h := ViewSpacing
         + ((formLabel height) max:(textLabel height))
         + ViewSpacing + ViewSpacing
         + (buttons at:1) height
         + ViewSpacing.

    extra := margin * 2.
    super extent:(w + extra) @ (h + extra)
! !