.
"
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.
"
'From Smalltalk/X, Version:2.10.4 on 28-dec-1994 at 1:57:21 pm'!
DialogBox subclass:#InfoBox
instanceVariableNames:'formLabel textLabel'
classVariableNames:'InfoBitmap'
poolDictionaries:''
category:'Views-DialogBoxes'
!
!InfoBox class methodsFor:'documentation'!
version
"
$Header: /cvs/stx/stx/libwidg/InfoBox.st,v 1.16 1995-06-06 04:14:05 claus Exp $
"
!
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 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
"
!
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 form:aForm
(the name 'form:' is historical - any bitmap or image is allowed).
Since this type of information is pretty common, a convenient information
method has been added to Object.
Thus, you can use:
self information:'hello world'
everwhere in your program.
standard box:
|box|
box := InfoBox title:'hello world '.
box open
changing the buttons label:
|box|
box := InfoBox title:'hello world '.
box okText:'wow'.
box open
changing the icon:
|box|
box := InfoBox title:'hello world '.
box form:(Image fromFile:'bitmaps/SBrowser.xbm').
box okText:'wow'.
box open
or even:
|box|
box := InfoBox title:'hello garfield '.
box form:((Image fromFile:'bitmaps/garfield.gif') magnifiedTo:200@100).
box okText:'wow'.
box open
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).
|box|
box := InfoBox title:'hello garfield '.
box form:((Image fromFile:'bitmaps/garfield.gif') magnifiedTo:200@100).
box okText:'wow'.
box open.
box title:'hello again'.
box open
"
!
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.
"
! !
!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'!
iconBitmap
"return the bitmap shown as icon in my instances.
The form is cached and reused, for faster opening."
InfoBitmap isNil ifTrue:[
InfoBitmap := Image fromFile:'bitmaps/Information.xbm'.
InfoBitmap notNil ifTrue:[
InfoBitmap := InfoBitmap on:Display
]
].
^ InfoBitmap
! !
!InfoBox class methodsFor:'styles'!
updateStyleCache
|img|
img := StyleSheet at:'informationBoxIcon'.
img notNil ifTrue:[InfoBitmap := img on:Display].
! !
!InfoBox methodsFor:'accessing'!
form:aForm
"define a form to be displayed left of the title
- usually an exclamation-mark"
formLabel form:aForm.
formLabel forceResize.
shown ifTrue:[self resize]
!
formLabel
"return the formLabel = can be used to change its appearance"
^ formLabel
!
title:aString
"set the boxes title string"
aString ~= textLabel label ifTrue:[
textLabel label:aString.
textLabel 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
! !
!InfoBox methodsFor:'queries'!
preferredExtent
"return my preferred extent"
|w h|
"/ formLabel resize.
"/ textLabel resize.
w := margin +
ViewSpacing +
formLabel widthIncludingBorder +
ViewSpacing + textLabel width + ViewSpacing +
margin.
w := w max:(okButton preferredExtent x + (ViewSpacing * 2)).
h := ViewSpacing
+ ((formLabel heightIncludingBorder) max:(textLabel height))
+ (ViewSpacing * 4)
+ okButton heightIncludingBorder
+ ViewSpacing.
^ w @ h
! !
!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)
!
initialize
|mm|
super initialize.
self addOkButton.
label := 'Info'.
mm := ViewSpacing.
formLabel := Label in:self.
self initFormBitmap.
formLabel borderWidth:0.
formLabel origin:(mm @ mm).
textLabel := Label label:'Information' in:self.
textLabel borderWidth:0.
textLabel origin:[(mm + formLabel widthIncludingBorder + mm)
@
mm].
"
|b|
b := InfoBox new.
b title:'hello'.
b open
"
! !