YesNoBox.st
author claus
Wed, 13 Oct 1993 02:04:14 +0100
changeset 3 9d7eefb5e69f
parent 0 e6a541c1c0eb
child 5 7b4fb1b170e5
permissions -rw-r--r--
(none)

"
 COPYRIGHT (c) 1989-93 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-93 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.2 1993-10-13 01:04:09 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"

    okButton label:aString.
    self resize
!

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

    noButton label:aString.
    self resize
!

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

    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 := 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)
! !