0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1991 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 |
|
|
13 |
ModalBox subclass:#OptionBox
|
91
|
14 |
instanceVariableNames:'formLabel textLabel buttonPanel buttons actions'
|
59
|
15 |
classVariableNames:'WarnBitmap'
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Views-DialogBoxes'
|
0
|
18 |
!
|
|
19 |
|
|
20 |
OptionBox comment:'
|
5
|
21 |
COPYRIGHT (c) 1991 by Claus Gittinger
|
59
|
22 |
All Rights Reserved
|
0
|
23 |
|
130
|
24 |
$Header: /cvs/stx/stx/libwidg/OptionBox.st,v 1.17 1995-06-06 04:14:35 claus Exp $
|
0
|
25 |
'!
|
|
26 |
|
7
|
27 |
!OptionBox class methodsFor:'documentation'!
|
|
28 |
|
38
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1991 by Claus Gittinger
|
59
|
32 |
All Rights Reserved
|
38
|
33 |
|
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
|
42 |
|
|
43 |
version
|
|
44 |
"
|
130
|
45 |
$Header: /cvs/stx/stx/libwidg/OptionBox.st,v 1.17 1995-06-06 04:14:35 claus Exp $
|
38
|
46 |
"
|
|
47 |
!
|
|
48 |
|
7
|
49 |
documentation
|
|
50 |
"
|
38
|
51 |
OptionBoxes are like YesNoBoxes but with as many buttons as you like;
|
91
|
52 |
this will finally be a superclass of WarnBox and YesNoBox - or maybe merged
|
38
|
53 |
all into DialogBox..
|
97
|
54 |
Use them for multiway questions.
|
91
|
55 |
For a consistent user interface, the rightmost button is the default return
|
97
|
56 |
button (i.e. pressing return in the box performs this buttons function).
|
91
|
57 |
|
|
58 |
examples:
|
|
59 |
|
|
60 |
|box|
|
|
61 |
|
|
62 |
box := OptionBox title:'hello' numberOfOptions:4.
|
|
63 |
box showAtPointer
|
|
64 |
|
|
65 |
|
97
|
66 |
|
91
|
67 |
|box|
|
|
68 |
box := OptionBox title:'hello' numberOfOptions:3.
|
|
69 |
box buttonTitles:#('one' 'two' 'three').
|
|
70 |
box showAtPointer
|
97
|
71 |
|
|
72 |
|
|
73 |
performing an action:
|
|
74 |
|
|
75 |
|box|
|
|
76 |
box := OptionBox title:'hello' numberOfOptions:3.
|
|
77 |
box buttonTitles:#('one' 'two' 'three').
|
|
78 |
box action:[:which | Transcript show:'button ';
|
|
79 |
show: which;
|
|
80 |
showCr:' was pressed'].
|
|
81 |
box showAtPointer
|
|
82 |
|
|
83 |
|
|
84 |
returning a value:
|
|
85 |
|
|
86 |
|what|
|
|
87 |
what := OptionBox
|
|
88 |
request:('text has not been accepted.\\Your modifications will be lost when continuing.') withCRs
|
|
89 |
label:' Attention'
|
|
90 |
form:(WarningBox iconBitmap)
|
|
91 |
buttonLabels:#('abort' 'accept' 'continue')
|
|
92 |
values:#(#abort #accept #continue).
|
|
93 |
|
|
94 |
...
|
|
95 |
someObject perform:what.
|
|
96 |
...
|
7
|
97 |
"
|
|
98 |
! !
|
|
99 |
|
95
|
100 |
!OptionBox class methodsFor:'easy startup '!
|
|
101 |
|
|
102 |
request:title label:label form:aForm buttonLabels:labels values:values
|
|
103 |
"create a new optionBox, open it modal and return the value of
|
|
104 |
the corresponding values collection."
|
|
105 |
|
|
106 |
|box|
|
|
107 |
|
|
108 |
box := OptionBox title:title numberOfOptions:(labels size).
|
|
109 |
box buttonTitles:labels.
|
|
110 |
box action:[:n | ^ values at:n].
|
|
111 |
box label:label; form:aForm.
|
|
112 |
box showAtPointer.
|
|
113 |
^ nil
|
|
114 |
|
|
115 |
"
|
97
|
116 |
OptionBox request:'please select'
|
95
|
117 |
label:'select any'
|
|
118 |
form:(WarningBox iconBitmap)
|
|
119 |
buttonLabels:#('one' 'two' 'three')
|
|
120 |
values:#(1 2 3)
|
|
121 |
"
|
|
122 |
! !
|
|
123 |
|
0
|
124 |
!OptionBox class methodsFor:'instance creation'!
|
|
125 |
|
|
126 |
title:titleString numberOfOptions:nOptions
|
|
127 |
"create a new optionBox with title, aTitleString and nOptions options"
|
|
128 |
|
|
129 |
|box|
|
|
130 |
|
|
131 |
box := (self basicNew) numberOfOptions:nOptions.
|
38
|
132 |
box device:Display.
|
0
|
133 |
box initialize.
|
|
134 |
box title:titleString.
|
|
135 |
^ box
|
|
136 |
! !
|
|
137 |
|
|
138 |
!OptionBox methodsFor:'accessing'!
|
|
139 |
|
|
140 |
title:aString
|
16
|
141 |
"set the boxes title"
|
0
|
142 |
|
16
|
143 |
aString ~= textLabel label ifTrue:[
|
59
|
144 |
textLabel label:aString withoutSeparators.
|
110
|
145 |
textLabel forceResize.
|
97
|
146 |
shown ifTrue:[self resize]
|
16
|
147 |
]
|
0
|
148 |
!
|
|
149 |
|
97
|
150 |
title:aString numberOfOptions:nOptions
|
|
151 |
"set the boxes title and number of options"
|
|
152 |
|
|
153 |
self title:aString.
|
|
154 |
buttons grow:nOptions.
|
|
155 |
actions grow:nOptions
|
|
156 |
!
|
|
157 |
|
77
|
158 |
formLabel
|
|
159 |
"return the label-view which displays a bitmap"
|
|
160 |
|
|
161 |
^ formLabel
|
|
162 |
!
|
|
163 |
|
|
164 |
form:aFormOrImage
|
|
165 |
"set the image shown in the label-view"
|
|
166 |
|
|
167 |
formLabel form:aFormOrImage
|
|
168 |
!
|
|
169 |
|
0
|
170 |
numberOfOptions:nOptions
|
|
171 |
"set the number of options"
|
|
172 |
|
85
|
173 |
buttons := (OrderedCollection new:nOptions) grow:nOptions.
|
|
174 |
actions := (OrderedCollection new:nOptions) grow:nOptions
|
0
|
175 |
!
|
|
176 |
|
7
|
177 |
numberOfOptions
|
|
178 |
"return the number of options"
|
|
179 |
|
|
180 |
^ buttons size
|
|
181 |
!
|
|
182 |
|
21
|
183 |
buttons
|
|
184 |
"return the buttons collection"
|
|
185 |
|
|
186 |
^ buttons
|
|
187 |
!
|
|
188 |
|
0
|
189 |
buttonTitles:titles
|
7
|
190 |
"set the button titles"
|
|
191 |
|
97
|
192 |
titles keysAndValuesDo:[:index :aString |
|
|
193 |
|b|
|
0
|
194 |
|
97
|
195 |
(b := buttons at:index) label:aString.
|
|
196 |
b resize.
|
0
|
197 |
].
|
97
|
198 |
shown ifTrue:[self resize]
|
0
|
199 |
!
|
|
200 |
|
|
201 |
actions:actionBlocks
|
7
|
202 |
"define the actions"
|
|
203 |
|
0
|
204 |
actions := actionBlocks
|
|
205 |
!
|
|
206 |
|
95
|
207 |
action:actionBlock
|
|
208 |
"define a single the action for all buttons.
|
|
209 |
The action will be evaluated with the button index as argument."
|
|
210 |
|
97
|
211 |
buttons keysAndValuesDo:[:index :button |
|
95
|
212 |
button action:[
|
97
|
213 |
button turnOffWithoutRedraw.
|
95
|
214 |
self hide.
|
|
215 |
actionBlock value:index
|
|
216 |
]
|
|
217 |
].
|
|
218 |
!
|
|
219 |
|
0
|
220 |
buttonTitles:titles actions:actionBlocks
|
7
|
221 |
"define both button titles and actions"
|
0
|
222 |
|
7
|
223 |
self buttonTitles:titles.
|
0
|
224 |
actions := actionBlocks.
|
|
225 |
! !
|
|
226 |
|
|
227 |
!OptionBox methodsFor:'initializing'!
|
|
228 |
|
|
229 |
initialize
|
91
|
230 |
|nButt|
|
0
|
231 |
|
|
232 |
super initialize.
|
|
233 |
|
38
|
234 |
formLabel := Label in:self.
|
|
235 |
self initFormBitmap.
|
0
|
236 |
formLabel borderWidth:0.
|
|
237 |
formLabel origin:(ViewSpacing @ ViewSpacing).
|
|
238 |
|
|
239 |
textLabel := Label label:'Warning' in:self.
|
|
240 |
textLabel borderWidth:0.
|
|
241 |
textLabel origin:((ViewSpacing + formLabel width + ViewSpacing) @ ViewSpacing).
|
|
242 |
|
77
|
243 |
buttonPanel := HorizontalPanelView origin:(0.0 @ 1.0) corner:(1.0 @ 1.0) in:self.
|
130
|
244 |
buttonPanel
|
|
245 |
bottomInset:ViewSpacing;
|
|
246 |
topInset:(font height + ViewSpacing * 2) negated.
|
|
247 |
buttonPanel
|
|
248 |
borderWidth:0;
|
|
249 |
horizontalLayout:#fitSpace.
|
59
|
250 |
|
0
|
251 |
nButt := buttons size.
|
|
252 |
|
7
|
253 |
1 to:nButt do:[:index |
|
59
|
254 |
|button|
|
7
|
255 |
|
91
|
256 |
button := Button label:'press'.
|
|
257 |
button action:[
|
|
258 |
|action|
|
7
|
259 |
|
91
|
260 |
(buttons at:index) turnOffWithoutRedraw.
|
|
261 |
self hide.
|
|
262 |
action := actions at:index.
|
|
263 |
action notNil ifTrue:[
|
|
264 |
action value
|
|
265 |
]
|
|
266 |
].
|
|
267 |
index == nButt ifTrue:[
|
|
268 |
button isReturnButton:true
|
|
269 |
].
|
|
270 |
buttonPanel addSubView:button.
|
59
|
271 |
buttons at:index put:button.
|
91
|
272 |
].
|
|
273 |
|
|
274 |
"
|
|
275 |
|box|
|
|
276 |
|
|
277 |
box := OptionBox title:'hello' numberOfOptions:4.
|
|
278 |
box open
|
|
279 |
"
|
38
|
280 |
!
|
|
281 |
|
|
282 |
initFormBitmap
|
|
283 |
WarnBitmap isNil ifTrue:[
|
59
|
284 |
WarnBitmap := Form fromFile:'Warning.xbm' resolution:100 on:Display
|
38
|
285 |
].
|
|
286 |
formLabel form:WarnBitmap
|
77
|
287 |
!
|
|
288 |
|
|
289 |
focusSequence
|
|
290 |
^ buttons
|
0
|
291 |
! !
|
|
292 |
|
63
|
293 |
!OptionBox methodsFor:'queries'!
|
0
|
294 |
|
16
|
295 |
positionOffset
|
|
296 |
"return the delta, by which the box should be displayed
|
|
297 |
from the mouse pointer. Value returned here makes
|
110
|
298 |
the return-button appear under the cursor"
|
|
299 |
|
119
|
300 |
|idx butt|
|
16
|
301 |
|
110
|
302 |
buttonPanel setChildPositionsIfChanged.
|
|
303 |
idx := buttons findFirst:[:b | b isReturnButton].
|
119
|
304 |
idx ~~ 0 ifTrue:[
|
|
305 |
butt := buttons at:idx.
|
|
306 |
^ (butt originRelativeTo:self) + (butt extent // 2)
|
|
307 |
].
|
|
308 |
^ self extent // 2
|
16
|
309 |
!
|
|
310 |
|
130
|
311 |
preferredExtent
|
59
|
312 |
"return a size to make everything fit into myself"
|
|
313 |
|
91
|
314 |
|w w1 w2 h maxH prefPanel|
|
0
|
315 |
|
|
316 |
w1 := ViewSpacing + formLabel width + ViewSpacing + textLabel width + ViewSpacing.
|
130
|
317 |
prefPanel := buttonPanel preferredExtent.
|
91
|
318 |
w := w1 max:prefPanel x.
|
38
|
319 |
|
97
|
320 |
"/ maxH := 0.
|
|
321 |
"/ buttons do:[:button |
|
130
|
322 |
"/ maxH := maxH max:(button preferredExtent y)
|
97
|
323 |
"/ ].
|
|
324 |
maxH := prefPanel y.
|
0
|
325 |
|
|
326 |
h := ViewSpacing
|
59
|
327 |
+ ((formLabel height) max:(textLabel height))
|
|
328 |
+ ViewSpacing + ViewSpacing
|
|
329 |
+ maxH
|
|
330 |
+ ViewSpacing.
|
0
|
331 |
|
59
|
332 |
^ w @ h
|
0
|
333 |
! !
|