0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
3 |
All Rights Reserved
|
|
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 |
|
|
13 |
ModalBox subclass:#InfoBox
|
38
|
14 |
instanceVariableNames:'formLabel textLabel buttonPanel okButton okAction
|
8
|
15 |
acceptReturnAsOK'
|
0
|
16 |
classVariableNames:'InfoBitmap'
|
|
17 |
poolDictionaries:''
|
38
|
18 |
category:'Views-DialogBoxes'
|
0
|
19 |
!
|
|
20 |
|
|
21 |
InfoBox comment:'
|
|
22 |
|
5
|
23 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
24 |
All Rights Reserved
|
|
25 |
|
38
|
26 |
$Header: /cvs/stx/stx/libwidg/InfoBox.st,v 1.6 1994-08-07 13:22:40 claus Exp $
|
0
|
27 |
written Spring/Summer 89 by claus
|
|
28 |
'!
|
|
29 |
|
8
|
30 |
!InfoBox class methodsFor:'documentation'!
|
|
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.
|
|
38 |
InfoBox is a superclass of some other boxes - see WaringBox, YesNoBox etc.
|
|
39 |
|
|
40 |
They are created with:
|
|
41 |
|
|
42 |
aBox := InfoBox title:'some title'.
|
|
43 |
|
|
44 |
and shown with:
|
|
45 |
|
|
46 |
aBox showAtPointer
|
|
47 |
|
|
48 |
The default box shows 'yes' in its button; this can be changed with:
|
|
49 |
|
|
50 |
aBox okText:'some string'.
|
|
51 |
|
|
52 |
the boxes bitmap-image can be changed with:
|
|
53 |
|
|
54 |
aBox form:aForm
|
|
55 |
|
|
56 |
(the name 'form:' is historical - any bitmap or image is allowed).
|
|
57 |
|
|
58 |
|
|
59 |
Examples:
|
|
60 |
|
|
61 |
|aBox|
|
|
62 |
aBox := InfoBox title:'a simple Info'.
|
|
63 |
aBox showAtPointer.
|
|
64 |
|
|
65 |
|aBox|
|
|
66 |
aBox := InfoBox title:'a simple Info'.
|
|
67 |
aBox showAt:0@0.
|
|
68 |
|
|
69 |
|aBox|
|
|
70 |
aBox := InfoBox title:'a simple Info'.
|
|
71 |
aBox acceptReturnAsOK:false.
|
|
72 |
aBox showAtPointer.
|
|
73 |
|
|
74 |
|aBox|
|
|
75 |
aBox := InfoBox title:'Press ''YES'' to continue\(or type return)' withCRs.
|
|
76 |
aBox okText:'YES'.
|
|
77 |
aBox showAtPointer.
|
|
78 |
|
|
79 |
|aBox|
|
|
80 |
aBox := InfoBox title:'another one'.
|
|
81 |
aBox form:(Form fromFile:'SBrowser.xbm').
|
|
82 |
aBox showAtPointer
|
|
83 |
|
|
84 |
|aBox|
|
|
85 |
aBox := InfoBox title:'a nice one'.
|
|
86 |
aBox form:(Image fromFile:'bitmaps/garfield.gif').
|
|
87 |
aBox showAtPointer
|
|
88 |
|
|
89 |
|aBox|
|
|
90 |
aBox := InfoBox title:'a nice one'.
|
|
91 |
aBox form:((Image fromFile:'bitmaps/garfield.gif') magnifyBy:0.3@0.3).
|
|
92 |
aBox showAtPointer
|
|
93 |
|
|
94 |
|aBox|
|
|
95 |
aBox := InfoBox title:'a nice one'.
|
|
96 |
aBox form:((Image fromFile:'bitmaps/garfield.gif') magnifyBy:0.3@0.3).
|
|
97 |
aBox formLabel level:-1.
|
|
98 |
aBox showAtPointer
|
|
99 |
|
|
100 |
|aBox|
|
|
101 |
aBox := InfoBox title:'a nice one'.
|
|
102 |
aBox form:((Image fromFile:'bitmaps/garfield.gif') magnifyBy:0.3@0.3).
|
|
103 |
aBox formLabel borderWidth:2.
|
|
104 |
aBox formLabel borderColor:Color red.
|
|
105 |
aBox showAtPointer
|
|
106 |
|
|
107 |
|aBox|
|
|
108 |
aBox := InfoBox title:'start printing'.
|
|
109 |
aBox form:(Image fromFile:'bitmaps/ljet3.xpm').
|
|
110 |
aBox formLabel level:-2.
|
|
111 |
aBox okText:'print'.
|
|
112 |
aBox showAtPointer
|
8
|
113 |
"
|
|
114 |
! !
|
|
115 |
|
0
|
116 |
!InfoBox class methodsFor:'instance creation'!
|
|
117 |
|
|
118 |
title:titleString
|
|
119 |
"create a new infoBox with title, aTitleString"
|
|
120 |
|
|
121 |
^ (self new) title:titleString
|
|
122 |
! !
|
|
123 |
|
|
124 |
!InfoBox methodsFor:'initialization'!
|
|
125 |
|
|
126 |
initialize
|
|
127 |
super initialize.
|
|
128 |
|
8
|
129 |
acceptReturnAsOK := true.
|
|
130 |
|
0
|
131 |
formLabel := Label in:self.
|
|
132 |
self initFormBitmap.
|
|
133 |
formLabel borderWidth:0.
|
|
134 |
formLabel origin:(ViewSpacing @ ViewSpacing).
|
|
135 |
|
|
136 |
textLabel := Label label:'Information' in:self.
|
|
137 |
textLabel borderWidth:0.
|
38
|
138 |
"
|
0
|
139 |
textLabel origin:((ViewSpacing + formLabel width + ViewSpacing) @ ViewSpacing).
|
38
|
140 |
"
|
|
141 |
textLabel origin:[(ViewSpacing + formLabel widthIncludingBorder + ViewSpacing) @ ViewSpacing].
|
0
|
142 |
|
38
|
143 |
okButton := Button
|
|
144 |
label:(resources at:'ok')
|
|
145 |
action:[
|
|
146 |
okButton turnOffWithoutRedraw.
|
|
147 |
self okPressed
|
|
148 |
]
|
|
149 |
in:self.
|
0
|
150 |
|
8
|
151 |
okButton isReturnButton:true.
|
38
|
152 |
okButton origin:[((width - okButton width) // 2)
|
|
153 |
@
|
|
154 |
(height - ViewSpacing - okButton heightIncludingBorder" - okButton borderWidth")].
|
|
155 |
|
0
|
156 |
!
|
|
157 |
|
|
158 |
initFormBitmap
|
8
|
159 |
"setup the bitmap shown in the upper left -
|
|
160 |
extracted into a separate method for easier redefinition
|
|
161 |
in subclasses"
|
|
162 |
|
38
|
163 |
InfoBitmap isNil ifTrue:[
|
|
164 |
InfoBitmap := Form fromFile:'Information.xbm' resolution:100 on:Display
|
|
165 |
].
|
|
166 |
|
0
|
167 |
formLabel form:InfoBitmap
|
|
168 |
! !
|
|
169 |
|
|
170 |
!InfoBox methodsFor:'realization'!
|
|
171 |
|
7
|
172 |
positionOffset
|
|
173 |
"return the delta, by which the box should be displayed
|
8
|
174 |
from the mouse pointer. Value returned here makes center of
|
7
|
175 |
okButton appear under the cursor"
|
0
|
176 |
|
7
|
177 |
^ (okButton originRelativeTo:self) + (okButton extent // 2)
|
0
|
178 |
! !
|
|
179 |
|
|
180 |
!InfoBox methodsFor:'accessing'!
|
|
181 |
|
8
|
182 |
acceptReturnAsOK:aBoolean
|
|
183 |
"turn on/off interpretation of return-key as ok.
|
|
184 |
Default is on"
|
|
185 |
|
|
186 |
acceptReturnAsOK := aBoolean.
|
|
187 |
okButton isReturnButton:aBoolean.
|
|
188 |
!
|
|
189 |
|
0
|
190 |
form:aForm
|
|
191 |
"define a form to be displayed left of the title
|
|
192 |
- usually an exclamation-mark"
|
|
193 |
|
|
194 |
formLabel form:aForm.
|
|
195 |
formLabel resize.
|
|
196 |
self resize
|
|
197 |
!
|
|
198 |
|
38
|
199 |
textLabel
|
|
200 |
"return the textLabel = can be used to change its appearance"
|
|
201 |
|
|
202 |
^ textLabel
|
|
203 |
!
|
|
204 |
|
|
205 |
formLabel
|
|
206 |
"return the formLabel = can be used to change its appearance"
|
|
207 |
|
|
208 |
^ formLabel
|
|
209 |
!
|
|
210 |
|
0
|
211 |
title:aString
|
8
|
212 |
"set the boxes title string"
|
0
|
213 |
|
8
|
214 |
aString ~= textLabel label ifTrue:[
|
|
215 |
textLabel label:aString.
|
|
216 |
textLabel resize.
|
|
217 |
self resize
|
|
218 |
]
|
0
|
219 |
!
|
|
220 |
|
|
221 |
title
|
8
|
222 |
"return the boxes title string"
|
0
|
223 |
|
|
224 |
^ textLabel label
|
|
225 |
!
|
|
226 |
|
38
|
227 |
okButton
|
|
228 |
"return the okButton"
|
|
229 |
|
|
230 |
^ okButton
|
|
231 |
!
|
|
232 |
|
0
|
233 |
okAction:aBlock
|
|
234 |
"define the action to be performed when ok is pressed"
|
|
235 |
|
|
236 |
okAction := aBlock
|
|
237 |
!
|
|
238 |
|
|
239 |
okText:aString
|
|
240 |
"define the text in the ok-button"
|
|
241 |
|
8
|
242 |
aString ~= okButton label ifTrue:[
|
|
243 |
okButton label:aString.
|
38
|
244 |
okButton resize.
|
8
|
245 |
self resize
|
|
246 |
]
|
0
|
247 |
! !
|
|
248 |
|
|
249 |
!InfoBox methodsFor:'private'!
|
|
250 |
|
|
251 |
resize
|
8
|
252 |
"resize myself to make everything fit into myself.
|
|
253 |
This method should be called after every change in
|
|
254 |
the title, form-field or button(s)."
|
0
|
255 |
|
|
256 |
|w h extra|
|
|
257 |
|
38
|
258 |
w := ViewSpacing + formLabel widthIncludingBorder + ViewSpacing + textLabel width + ViewSpacing.
|
|
259 |
w := w max:(okButton preferredExtent x + (ViewSpacing * 2)).
|
0
|
260 |
h := ViewSpacing
|
38
|
261 |
+ ((formLabel heightIncludingBorder) max:(textLabel height))
|
0
|
262 |
+ ViewSpacing + ViewSpacing
|
38
|
263 |
+ okButton heightIncludingBorder
|
0
|
264 |
+ ViewSpacing.
|
|
265 |
|
8
|
266 |
extra := 0 "margin * 2".
|
0
|
267 |
super extent:(w + extra) @ (h + extra)
|
|
268 |
! !
|
|
269 |
|
|
270 |
!InfoBox methodsFor:'user interaction'!
|
|
271 |
|
|
272 |
hideAndEvaluate:aBlock
|
|
273 |
"make myself invisible and evaluate aBlock"
|
|
274 |
|
|
275 |
self hide.
|
|
276 |
aBlock notNil ifTrue:[aBlock value]
|
|
277 |
!
|
|
278 |
|
|
279 |
okPressed
|
|
280 |
"user pressed ok-button; make myself invisible and if an action was
|
|
281 |
specified do it"
|
|
282 |
|
|
283 |
self hideAndEvaluate:okAction
|
|
284 |
!
|
|
285 |
|
|
286 |
keyPress:aKey x:x y:y
|
|
287 |
"return-key dublicates ok-function"
|
|
288 |
|
8
|
289 |
acceptReturnAsOK ifTrue:[
|
|
290 |
(aKey == #Return) ifTrue:[self okPressed]
|
|
291 |
]
|
0
|
292 |
! !
|