author | Claus Gittinger <cg@exept.de> |
Tue, 28 Oct 1997 21:02:59 +0100 | |
changeset 1365 | aa6a855b5013 |
parent 1172 | d10e4627b0e3 |
child 1991 | d3759873aed7 |
permissions | -rw-r--r-- |
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 |
DialogBox subclass:#InfoBox |
|
355 | 16 |
instanceVariableNames:'formLabel textLabel' |
17 |
classVariableNames:'InfoBitmap' |
|
18 |
poolDictionaries:'' |
|
19 |
category:'Views-DialogBoxes' |
|
0 | 20 |
! |
21 |
||
1172
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
22 |
!InfoBox class methodsFor:'documentation'! |
0 | 23 |
|
197 | 24 |
copyright |
25 |
" |
|
26 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
27 |
All Rights Reserved |
|
28 |
||
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
||
37 |
||
77 | 38 |
! |
8 | 39 |
|
40 |
documentation |
|
41 |
" |
|
355 | 42 |
Historic note: |
43 |
originally, ST/X had separate classes for the various entry methods; |
|
44 |
there were YesNoBox, EnterBox, InfoBox and so on. |
|
45 |
In the meantime, the DialogBox class (and therefore its alias: Dialog) |
|
46 |
is going to duplicate most funcionality found in these classes. |
|
47 |
||
48 |
In the future, those existing subclasses' functionality is going to |
|
49 |
be moved fully into Dialog, and the subclasses will be replaced by dummy |
|
50 |
delegators. (They will be kept for backward compatibility, though). |
|
51 |
||
52 |
||
53 |
||
38 | 54 |
this class implements a pop-up box to show an information message. |
55 |
It has a single ok-Button, which closes the box. |
|
56 |
Also entering return has (by default) the same effect as pressing |
|
57 |
the ok-button. |
|
59 | 58 |
InfoBox is a superclass of some other boxes - see WarningBox, YesNoBox etc. |
59 |
most of them simply redefine the icon shown in the upper left or |
|
60 |
add buttons. |
|
61 |
||
585 | 62 |
[instance variables:] |
59 | 63 |
|
355 | 64 |
formLabel <Label> shows a bitmap (warning, question-mark) |
59 | 65 |
|
355 | 66 |
textLabel <Label> shows the boxes text |
59 | 67 |
|
585 | 68 |
|
69 |
[author:] |
|
70 |
Claus Gittinger |
|
77 | 71 |
" |
59 | 72 |
|
77 | 73 |
! |
38 | 74 |
|
77 | 75 |
examples |
76 |
" |
|
59 | 77 |
InfoBoxes are created with: |
78 |
||
370 | 79 |
aBox := InfoBox title:'some title'. |
38 | 80 |
|
81 |
and shown with: |
|
82 |
||
370 | 83 |
aBox showAtPointer |
59 | 84 |
or |
370 | 85 |
aBox open |
38 | 86 |
|
87 |
The default box shows 'yes' in its button; this can be changed with: |
|
88 |
||
370 | 89 |
aBox okText:'some string'. |
38 | 90 |
|
91 |
the boxes bitmap-image can be changed with: |
|
92 |
||
370 | 93 |
aBox image:aForm |
77 | 94 |
|
95 |
||
96 |
Since this type of information is pretty common, a convenient information |
|
97 |
method has been added to Object. |
|
98 |
Thus, you can use: |
|
593 | 99 |
[exBegin] |
370 | 100 |
self information:'hello world' |
593 | 101 |
[exEnd] |
370 | 102 |
|
77 | 103 |
everwhere in your program. |
370 | 104 |
for ST-80 compatibility, you can also use: |
593 | 105 |
[exBegin] |
370 | 106 |
Dialog information:'hello world' |
593 | 107 |
[exEnd] |
370 | 108 |
|
109 |
||
77 | 110 |
|
111 |
standard box: |
|
593 | 112 |
[exBegin] |
370 | 113 |
|box| |
77 | 114 |
|
370 | 115 |
box := InfoBox title:'hello world '. |
116 |
box open |
|
593 | 117 |
[exEnd] |
77 | 118 |
|
119 |
||
120 |
changing the buttons label: |
|
593 | 121 |
[exBegin] |
370 | 122 |
|box| |
77 | 123 |
|
370 | 124 |
box := InfoBox title:'hello world '. |
125 |
box okText:'wow'. |
|
126 |
box open |
|
593 | 127 |
[exEnd] |
77 | 128 |
|
129 |
||
130 |
changing the icon: |
|
131 |
||
593 | 132 |
[exBegin] |
133 |
|box| |
|
77 | 134 |
|
370 | 135 |
box := InfoBox title:'hello world '. |
136 |
box image:(Image fromFile:'bitmaps/SBrowser.xbm'). |
|
137 |
box okText:'wow'. |
|
138 |
box open |
|
593 | 139 |
[exEnd] |
77 | 140 |
|
141 |
or even: |
|
593 | 142 |
[exBegin] |
370 | 143 |
|box| |
77 | 144 |
|
370 | 145 |
box := InfoBox title:'hello garfield '. |
146 |
box image:((Image fromFile:'bitmaps/garfield.gif') magnifiedTo:200@100). |
|
147 |
box okText:'wow'. |
|
148 |
box open |
|
593 | 149 |
[exEnd] |
77 | 150 |
|
151 |
||
152 |
If you plan to use boxes as in the last example, you may want to |
|
153 |
keep the box around for reuse (since the image magnification takes some time). |
|
593 | 154 |
[exBegin] |
370 | 155 |
|box| |
77 | 156 |
|
370 | 157 |
box := InfoBox title:'hello garfield '. |
158 |
box image:((Image fromFile:'bitmaps/garfield.gif') magnifiedTo:200@100). |
|
159 |
box okText:'wow'. |
|
160 |
box open. |
|
77 | 161 |
|
370 | 162 |
box title:'hello again'. |
163 |
box open |
|
593 | 164 |
[exEnd] |
77 | 165 |
|
63 | 166 |
" |
77 | 167 |
! ! |
168 |
||
1172
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
169 |
!InfoBox class methodsFor:'instance creation'! |
38 | 170 |
|
77 | 171 |
title:titleString |
172 |
"create a new infoBox with title, aTitleString" |
|
173 |
||
174 |
^ (self new) title:titleString |
|
38 | 175 |
|
77 | 176 |
" |
177 |
(InfoBox title:'hello') open |
|
178 |
" |
|
179 |
! ! |
|
60 | 180 |
|
1172
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
181 |
!InfoBox class methodsFor:'defaults'! |
60 | 182 |
|
574 | 183 |
defaultLabel |
184 |
"return the boxes default window title." |
|
185 |
||
186 |
^ 'Info' |
|
187 |
||
188 |
"Created: 23.4.1996 / 17:12:33 / cg" |
|
189 |
! |
|
190 |
||
77 | 191 |
iconBitmap |
192 |
"return the bitmap shown as icon in my instances. |
|
1172
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
193 |
This is the default image; you can overwrite this in a concrete |
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
194 |
instance with the #image: message" |
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
195 |
|
1365 | 196 |
<resource: #style (#'infoBox.icon' #'infoBox.iconFile')> |
1172
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
197 |
|
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
198 |
|img imgFileName| |
38 | 199 |
|
77 | 200 |
InfoBitmap isNil ifTrue:[ |
1365 | 201 |
img := StyleSheet at:'infoBox.icon'. |
1172
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
202 |
img notNil ifTrue:[ |
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
203 |
InfoBitmap := img |
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
204 |
] ifFalse:[ |
1365 | 205 |
imgFileName := StyleSheet at:'infoBox.iconFile' default:'bitmaps/Information.xbm'. |
1172
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
206 |
InfoBitmap := Image fromFile:imgFileName. |
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
207 |
]. |
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
208 |
InfoBitmap notNil ifTrue:[ |
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
209 |
InfoBitmap := InfoBitmap on:Display |
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
210 |
] |
77 | 211 |
]. |
212 |
^ InfoBitmap |
|
1172
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
213 |
|
1365 | 214 |
"Modified: / 26.10.1997 / 17:02:51 / cg" |
59 | 215 |
! ! |
216 |
||
1172
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
217 |
!InfoBox class methodsFor:'styles'! |
59 | 218 |
|
219 |
updateStyleCache |
|
1172
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
220 |
"extract values from the styleSheet and cache them in class variables. |
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
221 |
Here, the cached infoBitmap is simply flushed." |
440
2beb33cb0146
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
370
diff
changeset
|
222 |
|
1172
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
223 |
InfoBitmap := nil |
38 | 224 |
|
1172
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
225 |
"Modified: 1.4.1997 / 14:44:50 / cg" |
59 | 226 |
! ! |
227 |
||
0 | 228 |
!InfoBox methodsFor:'accessing'! |
229 |
||
184 | 230 |
form:aFormOrImage |
231 |
"historical leftover - define a form to be displayed left of the title" |
|
232 |
||
233 |
self image:aFormOrImage |
|
234 |
! |
|
235 |
||
38 | 236 |
formLabel |
237 |
"return the formLabel = can be used to change its appearance" |
|
238 |
||
239 |
^ formLabel |
|
240 |
! |
|
241 |
||
197 | 242 |
image:aForm |
243 |
"define a form to be displayed left of the title |
|
244 |
- usually left as defaulted: |
|
245 |
an exclamation-mark here, warn-sign in warningBox, |
|
246 |
others in other subclasses." |
|
0 | 247 |
|
197 | 248 |
formLabel form:aForm. |
249 |
formLabel forceResize. |
|
250 |
shown ifTrue:[self resize] |
|
0 | 251 |
! |
252 |
||
77 | 253 |
textLabel |
254 |
"return the textLabel = can be used to change its appearance" |
|
255 |
||
256 |
^ textLabel |
|
257 |
! |
|
258 |
||
0 | 259 |
title |
8 | 260 |
"return the boxes title string" |
0 | 261 |
|
262 |
^ textLabel label |
|
197 | 263 |
! |
0 | 264 |
|
197 | 265 |
title:aString |
266 |
"set the boxes title string" |
|
60 | 267 |
|
197 | 268 |
aString ~= textLabel label ifTrue:[ |
269 |
textLabel label:aString. |
|
270 |
textLabel forceResize. |
|
271 |
shown ifTrue:[self resize] |
|
272 |
] |
|
0 | 273 |
! ! |
274 |
||
77 | 275 |
!InfoBox methodsFor:'initialization'! |
0 | 276 |
|
77 | 277 |
initFormBitmap |
278 |
"setup the bitmap shown in the upper left - |
|
279 |
extracted into a separate method for easier redefinition |
|
280 |
in subclasses" |
|
0 | 281 |
|
77 | 282 |
formLabel form:(self class iconBitmap) |
0 | 283 |
! |
284 |
||
180
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
285 |
initFormLabel |
570 | 286 |
"setup the icon shown in the infoBox. |
287 |
Can be redefined in subclasses." |
|
288 |
||
180
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
289 |
|mm| |
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
290 |
|
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
291 |
mm := ViewSpacing. |
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
292 |
|
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
293 |
formLabel := Label in:self. |
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
294 |
formLabel borderWidth:0. |
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
295 |
formLabel origin:(mm @ mm). |
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
296 |
|
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
297 |
"Created: 16.11.1995 / 18:32:32 / cg" |
570 | 298 |
"Modified: 22.4.1996 / 18:15:37 / cg" |
180
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
299 |
! |
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
300 |
|
77 | 301 |
initialize |
1172
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
302 |
|mm sep| |
77 | 303 |
|
304 |
super initialize. |
|
305 |
self addOkButton. |
|
0 | 306 |
|
574 | 307 |
"/ label := 'Info'. |
77 | 308 |
|
309 |
mm := ViewSpacing. |
|
310 |
||
180
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
311 |
self initFormLabel. |
77 | 312 |
self initFormBitmap. |
0 | 313 |
|
77 | 314 |
textLabel := Label label:'Information' in:self. |
315 |
textLabel borderWidth:0. |
|
367 | 316 |
textLabel origin:[(mm + formLabel widthIncludingBorder + mm) @ mm]. |
0 | 317 |
|
1172
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
318 |
(styleSheet at:'infoBoxSeparator' default:false) ifTrue:[ |
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
319 |
sep := Separator in:self. |
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
320 |
sep origin:[0.0 @ ((formLabel bottom max:textLabel bottom) + ViewSpacing)]. |
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
321 |
sep extent:(1.0 @ sep preferredExtent y). |
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
322 |
]. |
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
323 |
|
77 | 324 |
" |
325 |
|b| |
|
326 |
||
327 |
b := InfoBox new. |
|
328 |
b title:'hello'. |
|
329 |
b open |
|
330 |
" |
|
367 | 331 |
|
1172
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
332 |
"Modified: 1.4.1997 / 14:53:16 / cg" |
0 | 333 |
! ! |
197 | 334 |
|
335 |
!InfoBox methodsFor:'queries'! |
|
336 |
||
337 |
preferredExtent |
|
338 |
"return my preferred extent" |
|
339 |
||
370 | 340 |
|w h mm| |
197 | 341 |
|
797 | 342 |
"/ If I have an explicit preferredExtent .. |
343 |
||
713
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
344 |
preferredExtent notNil ifTrue:[ |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
345 |
^ preferredExtent |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
346 |
]. |
197 | 347 |
|
370 | 348 |
mm := ViewSpacing. |
349 |
||
350 |
w := ((margin + mm) * 2) + |
|
351 |
formLabel widthIncludingBorder + |
|
352 |
mm + textLabel width. |
|
353 |
||
354 |
w := w max:(okButton preferredExtent x + (mm * 2)). |
|
355 |
||
356 |
h := (mm * 6) |
|
357 |
+ ((formLabel heightIncludingBorder) max:(textLabel height)) |
|
358 |
+ okButton heightIncludingBorder. |
|
197 | 359 |
|
1172
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
360 |
(styleSheet at:'infoBoxSeparator' default:false) ifTrue:[ |
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
361 |
h := h + (ViewSpacing * 3) |
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
362 |
]. |
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
363 |
|
197 | 364 |
^ w @ h |
370 | 365 |
|
1172
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
366 |
"Modified: 1.4.1997 / 14:53:35 / cg" |
197 | 367 |
! ! |
368 |
||
1172
d10e4627b0e3
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
797
diff
changeset
|
369 |
!InfoBox class methodsFor:'documentation'! |
243 | 370 |
|
371 |
version |
|
1365 | 372 |
^ '$Header: /cvs/stx/stx/libwidg/InfoBox.st,v 1.33 1997-10-28 20:02:34 cg Exp $' |
243 | 373 |
! ! |