author | Claus Gittinger <cg@exept.de> |
Wed, 21 Feb 1996 00:56:21 +0100 | |
changeset 370 | dc5b51904d3f |
parent 367 | bc778f90e42d |
child 440 | 2beb33cb0146 |
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 |
||
77 | 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 |
||
62 |
instance variables: |
|
63 |
||
355 | 64 |
formLabel <Label> shows a bitmap (warning, question-mark) |
59 | 65 |
|
355 | 66 |
textLabel <Label> shows the boxes text |
59 | 67 |
|
77 | 68 |
" |
59 | 69 |
|
77 | 70 |
! |
38 | 71 |
|
77 | 72 |
examples |
73 |
" |
|
59 | 74 |
InfoBoxes are created with: |
75 |
||
370 | 76 |
aBox := InfoBox title:'some title'. |
38 | 77 |
|
78 |
and shown with: |
|
79 |
||
370 | 80 |
aBox showAtPointer |
59 | 81 |
or |
370 | 82 |
aBox open |
38 | 83 |
|
84 |
The default box shows 'yes' in its button; this can be changed with: |
|
85 |
||
370 | 86 |
aBox okText:'some string'. |
38 | 87 |
|
88 |
the boxes bitmap-image can be changed with: |
|
89 |
||
370 | 90 |
aBox image:aForm |
77 | 91 |
|
92 |
||
93 |
Since this type of information is pretty common, a convenient information |
|
94 |
method has been added to Object. |
|
95 |
Thus, you can use: |
|
370 | 96 |
|
97 |
self information:'hello world' |
|
98 |
||
77 | 99 |
everwhere in your program. |
370 | 100 |
for ST-80 compatibility, you can also use: |
101 |
||
102 |
Dialog information:'hello world' |
|
103 |
||
104 |
||
77 | 105 |
|
106 |
standard box: |
|
107 |
||
370 | 108 |
|box| |
77 | 109 |
|
370 | 110 |
box := InfoBox title:'hello world '. |
111 |
box open |
|
77 | 112 |
|
113 |
||
114 |
changing the buttons label: |
|
115 |
||
370 | 116 |
|box| |
77 | 117 |
|
370 | 118 |
box := InfoBox title:'hello world '. |
119 |
box okText:'wow'. |
|
120 |
box open |
|
77 | 121 |
|
122 |
||
123 |
changing the icon: |
|
124 |
||
370 | 125 |
|box| |
77 | 126 |
|
370 | 127 |
box := InfoBox title:'hello world '. |
128 |
box image:(Image fromFile:'bitmaps/SBrowser.xbm'). |
|
129 |
box okText:'wow'. |
|
130 |
box open |
|
77 | 131 |
|
132 |
or even: |
|
133 |
||
370 | 134 |
|box| |
77 | 135 |
|
370 | 136 |
box := InfoBox title:'hello garfield '. |
137 |
box image:((Image fromFile:'bitmaps/garfield.gif') magnifiedTo:200@100). |
|
138 |
box okText:'wow'. |
|
139 |
box open |
|
77 | 140 |
|
141 |
||
142 |
If you plan to use boxes as in the last example, you may want to |
|
143 |
keep the box around for reuse (since the image magnification takes some time). |
|
144 |
||
370 | 145 |
|box| |
77 | 146 |
|
370 | 147 |
box := InfoBox title:'hello garfield '. |
148 |
box image:((Image fromFile:'bitmaps/garfield.gif') magnifiedTo:200@100). |
|
149 |
box okText:'wow'. |
|
150 |
box open. |
|
77 | 151 |
|
370 | 152 |
box title:'hello again'. |
153 |
box open |
|
77 | 154 |
|
63 | 155 |
" |
77 | 156 |
! ! |
157 |
||
158 |
!InfoBox class methodsFor:'instance creation'! |
|
38 | 159 |
|
77 | 160 |
title:titleString |
161 |
"create a new infoBox with title, aTitleString" |
|
162 |
||
163 |
^ (self new) title:titleString |
|
38 | 164 |
|
77 | 165 |
" |
166 |
(InfoBox title:'hello') open |
|
167 |
" |
|
168 |
! ! |
|
60 | 169 |
|
77 | 170 |
!InfoBox class methodsFor:'defaults'! |
60 | 171 |
|
77 | 172 |
iconBitmap |
173 |
"return the bitmap shown as icon in my instances. |
|
174 |
The form is cached and reused, for faster opening." |
|
38 | 175 |
|
77 | 176 |
InfoBitmap isNil ifTrue:[ |
108 | 177 |
InfoBitmap := Image fromFile:'bitmaps/Information.xbm'. |
178 |
InfoBitmap notNil ifTrue:[ |
|
179 |
InfoBitmap := InfoBitmap on:Display |
|
180 |
] |
|
77 | 181 |
]. |
182 |
^ InfoBitmap |
|
59 | 183 |
! ! |
184 |
||
185 |
!InfoBox class methodsFor:'styles'! |
|
186 |
||
187 |
updateStyleCache |
|
188 |
|img| |
|
38 | 189 |
|
59 | 190 |
img := StyleSheet at:'informationBoxIcon'. |
72 | 191 |
img notNil ifTrue:[InfoBitmap := img on:Display]. |
59 | 192 |
! ! |
193 |
||
0 | 194 |
!InfoBox methodsFor:'accessing'! |
195 |
||
184 | 196 |
form:aFormOrImage |
197 |
"historical leftover - define a form to be displayed left of the title" |
|
198 |
||
199 |
self image:aFormOrImage |
|
200 |
! |
|
201 |
||
38 | 202 |
formLabel |
203 |
"return the formLabel = can be used to change its appearance" |
|
204 |
||
205 |
^ formLabel |
|
206 |
! |
|
207 |
||
197 | 208 |
image:aForm |
209 |
"define a form to be displayed left of the title |
|
210 |
- usually left as defaulted: |
|
211 |
an exclamation-mark here, warn-sign in warningBox, |
|
212 |
others in other subclasses." |
|
0 | 213 |
|
197 | 214 |
formLabel form:aForm. |
215 |
formLabel forceResize. |
|
216 |
shown ifTrue:[self resize] |
|
0 | 217 |
! |
218 |
||
77 | 219 |
textLabel |
220 |
"return the textLabel = can be used to change its appearance" |
|
221 |
||
222 |
^ textLabel |
|
223 |
! |
|
224 |
||
0 | 225 |
title |
8 | 226 |
"return the boxes title string" |
0 | 227 |
|
228 |
^ textLabel label |
|
197 | 229 |
! |
0 | 230 |
|
197 | 231 |
title:aString |
232 |
"set the boxes title string" |
|
60 | 233 |
|
197 | 234 |
aString ~= textLabel label ifTrue:[ |
235 |
textLabel label:aString. |
|
236 |
textLabel forceResize. |
|
237 |
shown ifTrue:[self resize] |
|
238 |
] |
|
0 | 239 |
! ! |
240 |
||
77 | 241 |
!InfoBox methodsFor:'initialization'! |
0 | 242 |
|
77 | 243 |
initFormBitmap |
244 |
"setup the bitmap shown in the upper left - |
|
245 |
extracted into a separate method for easier redefinition |
|
246 |
in subclasses" |
|
0 | 247 |
|
77 | 248 |
formLabel form:(self class iconBitmap) |
0 | 249 |
! |
250 |
||
180
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
251 |
initFormLabel |
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
252 |
|mm| |
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
253 |
|
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
254 |
mm := ViewSpacing. |
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
255 |
|
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
256 |
formLabel := Label in:self. |
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
257 |
formLabel borderWidth:0. |
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
258 |
formLabel origin:(mm @ mm). |
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
259 |
|
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
260 |
"Created: 16.11.1995 / 18:32:32 / cg" |
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
261 |
! |
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
262 |
|
77 | 263 |
initialize |
264 |
|mm| |
|
265 |
||
266 |
super initialize. |
|
267 |
self addOkButton. |
|
0 | 268 |
|
77 | 269 |
label := 'Info'. |
270 |
||
271 |
mm := ViewSpacing. |
|
272 |
||
180
0eb12501889e
hook to create different labelView in subclasses
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
273 |
self initFormLabel. |
77 | 274 |
self initFormBitmap. |
0 | 275 |
|
77 | 276 |
textLabel := Label label:'Information' in:self. |
277 |
textLabel borderWidth:0. |
|
367 | 278 |
textLabel origin:[(mm + formLabel widthIncludingBorder + mm) @ mm]. |
0 | 279 |
|
77 | 280 |
" |
281 |
|b| |
|
282 |
||
283 |
b := InfoBox new. |
|
284 |
b title:'hello'. |
|
285 |
b open |
|
286 |
" |
|
367 | 287 |
|
288 |
"Modified: 20.2.1996 / 20:22:43 / cg" |
|
0 | 289 |
! ! |
197 | 290 |
|
291 |
!InfoBox methodsFor:'queries'! |
|
292 |
||
293 |
preferredExtent |
|
294 |
"return my preferred extent" |
|
295 |
||
370 | 296 |
|w h mm| |
197 | 297 |
|
298 |
"/ formLabel resize. |
|
299 |
"/ textLabel resize. |
|
300 |
||
370 | 301 |
mm := ViewSpacing. |
302 |
||
303 |
w := ((margin + mm) * 2) + |
|
304 |
formLabel widthIncludingBorder + |
|
305 |
mm + textLabel width. |
|
306 |
||
307 |
w := w max:(okButton preferredExtent x + (mm * 2)). |
|
308 |
||
309 |
h := (mm * 6) |
|
310 |
+ ((formLabel heightIncludingBorder) max:(textLabel height)) |
|
311 |
+ okButton heightIncludingBorder. |
|
197 | 312 |
|
313 |
^ w @ h |
|
370 | 314 |
|
315 |
"Modified: 21.2.1996 / 00:54:19 / cg" |
|
197 | 316 |
! ! |
317 |
||
243 | 318 |
!InfoBox class methodsFor:'documentation'! |
319 |
||
320 |
version |
|
370 | 321 |
^ '$Header: /cvs/stx/stx/libwidg/InfoBox.st,v 1.24 1996-02-20 23:56:21 cg Exp $' |
243 | 322 |
! ! |