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