0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
3 |
All Rights Reserved
|
0
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
77
|
13 |
|
|
14 |
|
|
15 |
'From Smalltalk/X, Version:2.10.4 on 28-dec-1994 at 1:57:21 pm'!
|
|
16 |
|
|
17 |
DialogBox subclass:#InfoBox
|
|
18 |
instanceVariableNames:'formLabel textLabel'
|
|
19 |
classVariableNames:'InfoBitmap'
|
|
20 |
poolDictionaries:''
|
|
21 |
category:'Views-DialogBoxes'
|
0
|
22 |
!
|
|
23 |
|
77
|
24 |
!InfoBox class methodsFor:'documentation'!
|
0
|
25 |
|
77
|
26 |
version
|
|
27 |
"
|
108
|
28 |
$Header: /cvs/stx/stx/libwidg/InfoBox.st,v 1.13 1995-03-20 11:49:23 claus Exp $
|
77
|
29 |
"
|
|
30 |
!
|
8
|
31 |
|
|
32 |
documentation
|
|
33 |
"
|
38
|
34 |
this class implements a pop-up box to show an information message.
|
|
35 |
It has a single ok-Button, which closes the box.
|
|
36 |
Also entering return has (by default) the same effect as pressing
|
|
37 |
the ok-button.
|
59
|
38 |
InfoBox is a superclass of some other boxes - see WarningBox, YesNoBox etc.
|
|
39 |
most of them simply redefine the icon shown in the upper left or
|
|
40 |
add buttons.
|
|
41 |
|
|
42 |
instance variables:
|
|
43 |
|
|
44 |
formLabel <Label> shows a bitmap (warning, question-mark)
|
|
45 |
|
|
46 |
textLabel <Label> shows the boxes text
|
|
47 |
|
77
|
48 |
"
|
59
|
49 |
|
77
|
50 |
!
|
38
|
51 |
|
77
|
52 |
examples
|
|
53 |
"
|
59
|
54 |
InfoBoxes are created with:
|
|
55 |
|
|
56 |
aBox := InfoBox title:'some title'.
|
38
|
57 |
|
|
58 |
and shown with:
|
|
59 |
|
59
|
60 |
aBox showAtPointer
|
|
61 |
or
|
|
62 |
aBox open
|
38
|
63 |
|
|
64 |
The default box shows 'yes' in its button; this can be changed with:
|
|
65 |
|
59
|
66 |
aBox okText:'some string'.
|
38
|
67 |
|
|
68 |
the boxes bitmap-image can be changed with:
|
|
69 |
|
59
|
70 |
aBox form:aForm
|
38
|
71 |
|
|
72 |
(the name 'form:' is historical - any bitmap or image is allowed).
|
77
|
73 |
|
|
74 |
|
|
75 |
Since this type of information is pretty common, a convenient information
|
|
76 |
method has been added to Object.
|
|
77 |
Thus, you can use:
|
|
78 |
self information:'hello world'
|
|
79 |
everwhere in your program.
|
|
80 |
|
|
81 |
standard box:
|
|
82 |
|
|
83 |
|box|
|
|
84 |
|
|
85 |
box := InfoBox title:'hello world '.
|
|
86 |
box open
|
|
87 |
|
|
88 |
|
|
89 |
changing the buttons label:
|
|
90 |
|
|
91 |
|box|
|
|
92 |
|
|
93 |
box := InfoBox title:'hello world '.
|
|
94 |
box okText:'wow'.
|
|
95 |
box open
|
|
96 |
|
|
97 |
|
|
98 |
changing the icon:
|
|
99 |
|
|
100 |
|box|
|
|
101 |
|
|
102 |
box := InfoBox title:'hello world '.
|
|
103 |
box form:(Image fromFile:'bitmaps/SBrowser.xbm').
|
|
104 |
box okText:'wow'.
|
|
105 |
box open
|
|
106 |
|
|
107 |
or even:
|
|
108 |
|
|
109 |
|box|
|
|
110 |
|
|
111 |
box := InfoBox title:'hello garfield '.
|
|
112 |
box form:((Image fromFile:'bitmaps/garfield.gif') magnifyTo:200@100).
|
|
113 |
box okText:'wow'.
|
|
114 |
box open
|
|
115 |
|
|
116 |
|
|
117 |
If you plan to use boxes as in the last example, you may want to
|
|
118 |
keep the box around for reuse (since the image magnification takes some time).
|
|
119 |
|
|
120 |
|box|
|
|
121 |
|
|
122 |
box := InfoBox title:'hello garfield '.
|
|
123 |
box form:((Image fromFile:'bitmaps/garfield.gif') magnifyTo:200@100).
|
|
124 |
box okText:'wow'.
|
|
125 |
box open.
|
|
126 |
|
|
127 |
box title:'hello again'.
|
|
128 |
box open
|
|
129 |
|
63
|
130 |
"
|
|
131 |
!
|
38
|
132 |
|
77
|
133 |
copyright
|
63
|
134 |
"
|
77
|
135 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
|
136 |
All Rights Reserved
|
59
|
137 |
|
77
|
138 |
This software is furnished under a license and may be used
|
|
139 |
only in accordance with the terms of that license and with the
|
|
140 |
inclusion of the above copyright notice. This software may not
|
|
141 |
be provided or otherwise made available to, or used by, any
|
|
142 |
other person. No title to or ownership of the software is
|
|
143 |
hereby transferred.
|
|
144 |
"
|
59
|
145 |
|
38
|
146 |
|
77
|
147 |
! !
|
|
148 |
|
|
149 |
!InfoBox class methodsFor:'instance creation'!
|
38
|
150 |
|
77
|
151 |
title:titleString
|
|
152 |
"create a new infoBox with title, aTitleString"
|
|
153 |
|
|
154 |
^ (self new) title:titleString
|
38
|
155 |
|
77
|
156 |
"
|
|
157 |
(InfoBox title:'hello') open
|
|
158 |
"
|
|
159 |
! !
|
60
|
160 |
|
77
|
161 |
!InfoBox class methodsFor:'defaults'!
|
60
|
162 |
|
77
|
163 |
iconBitmap
|
|
164 |
"return the bitmap shown as icon in my instances.
|
|
165 |
The form is cached and reused, for faster opening."
|
38
|
166 |
|
77
|
167 |
InfoBitmap isNil ifTrue:[
|
108
|
168 |
InfoBitmap := Image fromFile:'bitmaps/Information.xbm'.
|
|
169 |
InfoBitmap notNil ifTrue:[
|
|
170 |
InfoBitmap := InfoBitmap on:Display
|
|
171 |
]
|
77
|
172 |
].
|
|
173 |
^ InfoBitmap
|
59
|
174 |
! !
|
|
175 |
|
|
176 |
!InfoBox class methodsFor:'styles'!
|
|
177 |
|
|
178 |
updateStyleCache
|
|
179 |
|img|
|
38
|
180 |
|
59
|
181 |
img := StyleSheet at:'informationBoxIcon'.
|
72
|
182 |
img notNil ifTrue:[InfoBitmap := img on:Display].
|
59
|
183 |
! !
|
|
184 |
|
0
|
185 |
!InfoBox methodsFor:'accessing'!
|
|
186 |
|
|
187 |
form:aForm
|
|
188 |
"define a form to be displayed left of the title
|
|
189 |
- usually an exclamation-mark"
|
|
190 |
|
|
191 |
formLabel form:aForm.
|
|
192 |
formLabel resize.
|
97
|
193 |
shown ifTrue:[self resize]
|
0
|
194 |
!
|
|
195 |
|
38
|
196 |
formLabel
|
|
197 |
"return the formLabel = can be used to change its appearance"
|
|
198 |
|
|
199 |
^ formLabel
|
|
200 |
!
|
|
201 |
|
0
|
202 |
title:aString
|
8
|
203 |
"set the boxes title string"
|
0
|
204 |
|
8
|
205 |
aString ~= textLabel label ifTrue:[
|
59
|
206 |
textLabel label:aString.
|
|
207 |
textLabel resize.
|
97
|
208 |
shown ifTrue:[self resize]
|
8
|
209 |
]
|
0
|
210 |
!
|
|
211 |
|
77
|
212 |
textLabel
|
|
213 |
"return the textLabel = can be used to change its appearance"
|
|
214 |
|
|
215 |
^ textLabel
|
|
216 |
!
|
|
217 |
|
0
|
218 |
title
|
8
|
219 |
"return the boxes title string"
|
0
|
220 |
|
|
221 |
^ textLabel label
|
|
222 |
! !
|
|
223 |
|
63
|
224 |
!InfoBox methodsFor:'queries'!
|
0
|
225 |
|
59
|
226 |
preferedExtent
|
|
227 |
"return my prefered extent"
|
|
228 |
|
|
229 |
|w h extra|
|
|
230 |
|
60
|
231 |
formLabel resize.
|
|
232 |
textLabel resize.
|
|
233 |
|
|
234 |
w := margin +
|
|
235 |
ViewSpacing +
|
|
236 |
formLabel widthIncludingBorder +
|
|
237 |
ViewSpacing + textLabel width + ViewSpacing +
|
|
238 |
margin.
|
59
|
239 |
w := w max:(okButton preferedExtent x + (ViewSpacing * 2)).
|
|
240 |
h := ViewSpacing
|
|
241 |
+ ((formLabel heightIncludingBorder) max:(textLabel height))
|
60
|
242 |
+ ViewSpacing + ViewSpacing + ViewSpacing + ViewSpacing
|
59
|
243 |
+ okButton heightIncludingBorder
|
|
244 |
+ ViewSpacing.
|
|
245 |
|
|
246 |
extra := 0 "margin * 2".
|
|
247 |
^ (w + extra) @ (h + extra)
|
0
|
248 |
! !
|
|
249 |
|
77
|
250 |
!InfoBox methodsFor:'initialization'!
|
0
|
251 |
|
77
|
252 |
initFormBitmap
|
|
253 |
"setup the bitmap shown in the upper left -
|
|
254 |
extracted into a separate method for easier redefinition
|
|
255 |
in subclasses"
|
0
|
256 |
|
77
|
257 |
formLabel form:(self class iconBitmap)
|
0
|
258 |
!
|
|
259 |
|
77
|
260 |
initialize
|
|
261 |
|mm|
|
|
262 |
|
|
263 |
super initialize.
|
|
264 |
self addOkButton.
|
0
|
265 |
|
77
|
266 |
label := 'Info'.
|
|
267 |
|
|
268 |
mm := ViewSpacing.
|
|
269 |
|
|
270 |
formLabel := Label in:self.
|
|
271 |
self initFormBitmap.
|
|
272 |
formLabel borderWidth:0.
|
|
273 |
formLabel origin:(mm @ mm).
|
0
|
274 |
|
77
|
275 |
textLabel := Label label:'Information' in:self.
|
|
276 |
textLabel borderWidth:0.
|
|
277 |
textLabel origin:[(mm + formLabel widthIncludingBorder + mm)
|
|
278 |
@
|
|
279 |
mm].
|
0
|
280 |
|
77
|
281 |
"
|
|
282 |
|b|
|
|
283 |
|
|
284 |
b := InfoBox new.
|
|
285 |
b title:'hello'.
|
|
286 |
b open
|
|
287 |
"
|
0
|
288 |
! !
|