InfoBox.st
author Claus Gittinger <cg@exept.de>
Thu, 17 May 2001 14:17:46 +0200
changeset 2362 f6ace7307e4d
parent 2076 e863a4bf58d4
child 2469 da097548025a
permissions -rw-r--r--
examples fixed (bitmaps access)

"
 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.
"



"{ Package: 'stx:libwidg' }"

DialogBox subclass:#InfoBox
	instanceVariableNames:'formLabel textLabel'
	classVariableNames:'InfoBitmap'
	poolDictionaries:''
	category:'Views-DialogBoxes'
!

!InfoBox class methodsFor:'documentation'!

copyright
"
 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.
"


!

documentation
"
   Historic note:
        originally, ST/X had separate classes for the various entry methods;
        there were YesNoBox, EnterBox, InfoBox and so on.
        In the meantime, the DialogBox class (and therefore its alias: Dialog)
        is going to duplicate most funcionality found in these classes.

        In the future, those existing subclasses' functionality is going to
        be moved fully into Dialog, and the subclasses will be replaced by dummy
        delegators. (They will be kept for backward compatibility, though).



    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 is a superclass of some other boxes - see WarningBox, YesNoBox etc.
    most of them simply redefine the icon shown in the upper left or
    add buttons.

    [instance variables:]

        formLabel        <Label>        shows a bitmap (warning, question-mark)

        textLabel        <Label>        shows the boxes text


    [author:]
        Claus Gittinger
"

!

examples
"
    InfoBoxes are created with:

        aBox := InfoBox title:'some title'.

    and shown with:

        aBox showAtPointer
    or
        aBox open

    The default box shows 'yes' in its button; this can be changed with:

        aBox okText:'some string'.

    the boxes bitmap-image can be changed with:

        aBox image:aForm


    Since this type of information is pretty common, a convenient information
    method has been added to Object.
    Thus, you can use:
                                                                        [exBegin]
        self information:'hello world'
                                                                        [exEnd]

    everwhere in your program.
    for ST-80 compatibility, you can also use:
                                                                        [exBegin]
        Dialog information:'hello world'
                                                                        [exEnd]



    standard box:
                                                                        [exBegin]
        |box|

        box := InfoBox title:'hello world '.
        box open
                                                                        [exEnd]


    changing the buttons label:
                                                                        [exBegin]
        |box|

        box := InfoBox title:'hello world '.
        box okText:'wow'.
        box open
                                                                        [exEnd]


    changing the icon:

                                                                        [exBegin]
        |box|

        box := InfoBox title:'hello world '.
        box image:(Image fromFile:'bitmaps/SBrowser.xbm' inPackage:'stx:libtool').
        box okText:'wow'.
        box open
                                                                        [exEnd]

    or even:
                                                                        [exBegin]
        |box|

        box := InfoBox title:'hello garfield '.
        box image:((Image fromFile:'garfield.gif' inPackage:'stx:goodies/bitmaps/gifImages') magnifiedTo:200@100).
        box okText:'wow'.
        box open
                                                                        [exEnd]


    If you plan to use boxes as in the last example, you may want to
    keep the box around for reuse (since the image magnification takes some time).
                                                                        [exBegin]
        |box|

        box := InfoBox title:'hello garfield '.
        box image:((Image fromFile:'garfield.gif' inPackage:'stx:goodies/bitmaps/gifImages') magnifiedTo:200@100).
        box okText:'wow'.
        box open.

        box title:'hello again'.
        box open
                                                                        [exEnd]

"
! !

!InfoBox class methodsFor:'instance creation'!

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

    ^ (self new) title:titleString

    "
     (InfoBox title:'hello') open
    "
! !

!InfoBox class methodsFor:'defaults'!

defaultLabel
    "return the boxes default window title."

    ^ 'Info'

    "Created: 23.4.1996 / 17:12:33 / cg"
!

iconBitmap
    "return the bitmap shown as icon in my instances.
     This is the default image; you can overwrite this in a concrete
     instance with the #image: message"

    <resource: #style (#'infoBox.icon' #'infoBox.iconFile')>

    |img imgFileName|

    InfoBitmap isNil ifTrue:[
        img := StyleSheet at:'infoBox.icon'.
        img notNil ifTrue:[
            InfoBitmap := img
        ] ifFalse:[
            imgFileName := StyleSheet at:'infoBox.iconFile' default:'bitmaps/Information.xbm'.
            InfoBitmap := Smalltalk imageFromFileNamed:imgFileName forClass:self.
        ].
        InfoBitmap notNil ifTrue:[
            InfoBitmap := InfoBitmap onDevice:Display
        ]
    ].
    ^ InfoBitmap

    "Modified: / 26.10.1997 / 17:02:51 / cg"
! !

!InfoBox class methodsFor:'styles'!

updateStyleCache
    "extract values from the styleSheet and cache them in class variables.
     Here, the cached infoBitmap is simply flushed."

    InfoBitmap := nil

    "Modified: 1.4.1997 / 14:44:50 / cg"
! !

!InfoBox methodsFor:'accessing'!

form:aFormOrImage
    "historical leftover - define a form to be displayed left of the title"

    self image:aFormOrImage
!

formLabel
    "return the formLabel = can be used to change its appearance"

    ^ formLabel
!

image:aForm
    "define a form to be displayed left of the title
     - usually left as defaulted:
	an exclamation-mark here, warn-sign in warningBox,
	others in other subclasses."

    formLabel form:aForm.
    formLabel forceResize.
    shown ifTrue:[self resize]
!

textLabel
    "return the textLabel = can be used to change its appearance"

    ^ textLabel
!

title
    "return the boxes title string"

    ^ textLabel label
!

title:aString
    "set the boxes title string"

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

!InfoBox methodsFor:'initialization'!

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

    formLabel form:(self class iconBitmap)
!

initFormLabel
    "setup the icon shown in the infoBox.
     Can be redefined in subclasses."

    |mm|

    mm := ViewSpacing.

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

    "Created: 16.11.1995 / 18:32:32 / cg"
    "Modified: 22.4.1996 / 18:15:37 / cg"
!

initialize
    |mm sep|

    super initialize.
    self addOkButton.

"/    label := 'Info'.

    mm := ViewSpacing.

    self initFormLabel.
    self initFormBitmap.

    textLabel := Label label:'Information' in:self.
    textLabel borderWidth:0.
    textLabel origin:[(mm + formLabel widthIncludingBorder + mm) @ mm].

    (styleSheet at:'infoBoxSeparator' default:false) ifTrue:[
        sep := Separator in:self.
        sep origin:[0.0 @ ((formLabel bottom max:textLabel bottom) + ViewSpacing)].
        sep extent:(1.0 @ sep preferredExtent y).
    ].

    "
     |b|

     b := InfoBox new.
     b title:'hello'.
     b open
    "

    "Modified: 1.4.1997 / 14:53:16 / cg"
! !

!InfoBox methodsFor:'queries'!

preferredExtent 
    "return my preferred extent"

    |w h mm|

    "/ If I have an explicit preferredExtent ..

    preferredExtent notNil ifTrue:[
        ^ preferredExtent
    ].

    mm := ViewSpacing.

    w := ((margin + mm) * 2) + 
         formLabel widthIncludingBorder + 
         mm + textLabel width.

    w := w max:(okButton preferredExtent x + (mm * 2)).

    h := (mm * 6)
         + ((formLabel heightIncludingBorder) max:(textLabel height))
         + okButton heightIncludingBorder.

    (styleSheet at:'infoBoxSeparator' default:false) ifTrue:[
        h := h + (ViewSpacing * 3)
    ].

    ^ w @ h

    "Modified: 1.4.1997 / 14:53:35 / cg"
! !

!InfoBox class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libwidg/InfoBox.st,v 1.37 2001-05-17 12:17:40 cg Exp $'
! !