InfoBox.st
author claus
Mon, 13 Dec 1993 18:06:07 +0100
changeset 8 82e87dc3540e
parent 7 15a9291b9bd0
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.
"

ModalBox subclass:#InfoBox
       instanceVariableNames:'formLabel textLabel okButton okAction
                              acceptReturnAsOK'
       classVariableNames:'InfoBitmap'
       poolDictionaries:''
       category:'Views-Interactors'
!

InfoBox comment:'

COPYRIGHT (c) 1989 by Claus Gittinger
              All Rights Reserved

$Header: /cvs/stx/stx/libwidg/InfoBox.st,v 1.5 1993-12-13 17:06:07 claus Exp $
written Spring/Summer 89 by claus
'!

!InfoBox class methodsFor:'documentation'!

documentation
"
this class implements a pop-up box to show an information message.
It has a single ok-Button, which closes the box.
Also entering return has (by default) the same effect as pressing
the ok-button.
"
! !

!InfoBox class methodsFor:'instance creation'!

title:titleString
    "create a new infoBox with title, aTitleString"

    ^ (self new) title:titleString
! !

!InfoBox methodsFor:'initialization'!

initialize
    super initialize.

    InfoBitmap isNil ifTrue:[
        InfoBitmap := Form fromFile:'Information.xbm' resolution:100 on:device
    ].

    acceptReturnAsOK := true.

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

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

    okButton := Button label:(resources at:'ok')
                       action:[
                                okButton turnOffWithoutRedraw.
                                self okPressed 
                              ]
                       in:self.

    okButton isReturnButton:true.
    okButton origin:[(width // 4) @ (height - ViewSpacing - okButton height)]
             extent:[(width // 2) @ okButton height]
!

initFormBitmap
    "setup the bitmap shown in the upper left -
     extracted into a separate method for easier redefinition
     in subclasses"

    formLabel form:InfoBitmap
! !

!InfoBox methodsFor:'realization'!

positionOffset
    "return the delta, by which the box should be displayed
     from the mouse pointer. Value returned here makes center of
     okButton appear under the cursor"

    ^ (okButton originRelativeTo:self) + (okButton extent // 2)
! !

!InfoBox methodsFor:'accessing'!

acceptReturnAsOK:aBoolean
    "turn on/off interpretation of return-key as ok.
     Default is on"

    acceptReturnAsOK := aBoolean.
    okButton isReturnButton:aBoolean.
!

form:aForm
    "define a form to be displayed left of the title
     - usually an exclamation-mark"

    formLabel form:aForm.
    formLabel resize.
    self resize
!

title:aString
    "set the boxes title string"

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

title
    "return the boxes title string"

    ^ textLabel label
!

okAction:aBlock
    "define the action to be performed when ok is pressed"

    okAction := aBlock
!

okText:aString
    "define the text in the ok-button"

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

!InfoBox methodsFor:'private'!

resize
    "resize myself to make everything fit into myself.
     This method should be called after every change in
     the title, form-field or button(s)."

    |w h extra|

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

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

!InfoBox methodsFor:'user interaction'!

hideAndEvaluate:aBlock
    "make myself invisible and evaluate aBlock"

    self hide.
    aBlock notNil ifTrue:[aBlock value]
!

okPressed
    "user pressed ok-button; make myself invisible and if an action was
     specified do it"

    self hideAndEvaluate:okAction
!

keyPress:aKey x:x y:y
    "return-key dublicates ok-function"

    acceptReturnAsOK ifTrue:[
        (aKey == #Return) ifTrue:[self okPressed]
    ]
! !