YesNoBox.st
author claus
Mon, 13 Dec 1993 18:07:34 +0100
changeset 9 3ba6bca844c8
parent 5 7b4fb1b170e5
child 38 4b9b70b2cc87
permissions -rw-r--r--
*** empty log message ***

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

WarningBox subclass:#YesNoBox
       instanceVariableNames:'noButton noAction'
       classVariableNames:'RequestBitmap'
       poolDictionaries:''
       category:'Views-Interactors'
!

YesNoBox comment:'

COPYRIGHT (c) 1989 by Claus Gittinger
              All Rights Reserved

this class implements yes-no boxes by adding another (no-)
Button to the View.

$Header: /cvs/stx/stx/libwidg/YesNoBox.st,v 1.4 1993-12-13 17:07:34 claus Exp $
written spring/summer 89 by claus
'!

!YesNoBox methodsFor:'initialization'!

initialize
    |space3|

    RequestBitmap isNil ifTrue:[
        RequestBitmap := Form fromFile:'Request.xbm' resolution:100 on:device
    ].

    super initialize.

    textLabel label:'Confirm'.
    okButton label:(resources at:'yes').

    noButton := Button label:(resources at:'no')
                      action:[
                                noButton turnOffWithoutRedraw.
                                self noPressed
                             ]
                          in:self.

    space3 := 3 * ViewSpacing.
    noButton origin:[ViewSpacing @ (height - ViewSpacing - noButton height)]
             extent:[((width - space3) // 2) @ noButton height].
    okButton origin:[((width + ViewSpacing) // 2)
                     @
                     (height - ViewSpacing - okButton height)]
             extent:[((width - space3) // 2) @ okButton height]
!

initFormBitmap
    formLabel form:RequestBitmap
! !

!YesNoBox methodsFor:'accessing'!

yesButton
    "return the yes-button"

    ^ okButton
!

noButton
    "return the no-button"

    ^ noButton
!

yesAction:aBlock 
    "define the action to be performed when yes is pressed"

    okAction := aBlock
!

noAction:aBlock
    "define the action to be performed when no is pressed"

    noAction := aBlock
!

yesAction:yesBlock noAction:noBlock
    "define both actions"

    okAction := yesBlock.
    noAction := noBlock
!

yesText:aString
    "define the label of the yes-button"

    self okText:aString
!

noText:aString
    "define the label of the no-button"

    aString ~= noButton label ifTrue:[
        noButton label:aString.
        self resize
    ]
!

yesText:yesString noText:noString
    "define the labels of both buttons"

    ((yesString ~= okButton label) or:[noString ~= noButton label]) ifTrue:[
        okButton label:yesString.
        noButton label:noString.
        self resize
    ]
!

title:aString yesAction:yesBlock noAction:noBlock
    "define title and actions"

    self title:aString.
    okAction := yesBlock.
    noAction := noBlock
! !

!YesNoBox methodsFor:'user interaction'!

noPressed
    "user pressed the no-button;
     hide myself and evaluate the action"

    self hideAndEvaluate:noAction
! !

!YesNoBox methodsFor:'private'!

resize
    "resize myself to make everything fit into myself"

    |w h extra|

    w := (formLabel width + textLabel width) max:(okButton width + noButton width).
    w := w + (3 * ViewSpacing).
    h := (3 * ViewSpacing)
         + ((formLabel height) max:(textLabel height))
         + okButton height.

    extra := 0 "margin * 2".
    super extent:(w + extra) @ (h + extra).
    formLabel origin:(ViewSpacing @ ViewSpacing).
    textLabel origin:(ViewSpacing + formLabel width + ViewSpacing) @ ViewSpacing.
    noButton origin:((width // 4) - (noButton width // 2)) @ (height - ViewSpacing - noButton height).
    okButton origin:((width // 4) * 3 - (okButton width // 2)) @ (height - ViewSpacing - okButton height)
! !