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
|
355
|
14 |
instanceVariableNames:'formLabel textLabel buttonPanel buttons actions
|
|
15 |
defaultButtonIndex'
|
|
16 |
classVariableNames:'WarnBitmap'
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Views-DialogBoxes'
|
0
|
19 |
!
|
|
20 |
|
7
|
21 |
!OptionBox class methodsFor:'documentation'!
|
|
22 |
|
38
|
23 |
copyright
|
|
24 |
"
|
|
25 |
COPYRIGHT (c) 1991 by Claus Gittinger
|
59
|
26 |
All Rights Reserved
|
38
|
27 |
|
|
28 |
This software is furnished under a license and may be used
|
|
29 |
only in accordance with the terms of that license and with the
|
|
30 |
inclusion of the above copyright notice. This software may not
|
|
31 |
be provided or otherwise made available to, or used by, any
|
|
32 |
other person. No title to or ownership of the software is
|
|
33 |
hereby transferred.
|
|
34 |
"
|
|
35 |
!
|
|
36 |
|
7
|
37 |
documentation
|
|
38 |
"
|
355
|
39 |
Historic note:
|
|
40 |
originally, ST/X had separate classes for the various entry methods;
|
|
41 |
there were YesNoBox, EnterBox, InfoBox and so on.
|
|
42 |
In the meantime, the DialogBox class (and therefore its alias: Dialog)
|
|
43 |
is going to duplicate most funcionality found in these classes.
|
|
44 |
|
|
45 |
In the future, those existing subclasses' functionality is going to
|
|
46 |
be moved fully into Dialog, and the subclasses will be replaced by dummy
|
|
47 |
delegators. (They will be kept for backward compatibility, though).
|
|
48 |
|
|
49 |
|
|
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 |
|
355
|
60 |
|box|
|
91
|
61 |
|
355
|
62 |
box := OptionBox title:'hello' numberOfOptions:4.
|
|
63 |
box showAtPointer
|
91
|
64 |
|
|
65 |
|
97
|
66 |
|
355
|
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 |
|
355
|
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
|
97
|
82 |
|
|
83 |
|
|
84 |
returning a value:
|
|
85 |
|
355
|
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).
|
97
|
93 |
|
355
|
94 |
...
|
|
95 |
someObject perform:what.
|
|
96 |
...
|
133
|
97 |
|
|
98 |
CAVEAT: this is a leftover - functionality will be merged into DialogBox
|
7
|
99 |
"
|
197
|
100 |
! !
|
|
101 |
|
|
102 |
!OptionBox class methodsFor:'instance creation'!
|
|
103 |
|
|
104 |
title:titleString numberOfOptions:nOptions
|
|
105 |
"create a new optionBox with title, aTitleString and nOptions options"
|
|
106 |
|
|
107 |
|box|
|
|
108 |
|
|
109 |
box := (self basicNew) numberOfOptions:nOptions.
|
|
110 |
box device:Screen current.
|
|
111 |
box initialize.
|
|
112 |
box title:titleString.
|
|
113 |
^ box
|
7
|
114 |
! !
|
|
115 |
|
95
|
116 |
!OptionBox class methodsFor:'easy startup '!
|
|
117 |
|
133
|
118 |
request:title label:label form:aForm buttonLabels:labels values:values
|
|
119 |
"create a new optionBox, open it modal and return the value of
|
|
120 |
the corresponding values collection."
|
|
121 |
|
|
122 |
^ self request:title label:label form:aForm buttonLabels:labels values:values default:nil
|
|
123 |
!
|
|
124 |
|
|
125 |
request:title label:label form:aForm buttonLabels:labels values:values default:defaultValue
|
95
|
126 |
"create a new optionBox, open it modal and return the value of
|
|
127 |
the corresponding values collection."
|
|
128 |
|
|
129 |
|box|
|
|
130 |
|
|
131 |
box := OptionBox title:title numberOfOptions:(labels size).
|
|
132 |
box buttonTitles:labels.
|
133
|
133 |
box defaultButtonIndex:(values indexOf:defaultValue).
|
95
|
134 |
box action:[:n | ^ values at:n].
|
|
135 |
box label:label; form:aForm.
|
|
136 |
box showAtPointer.
|
133
|
137 |
^ defaultValue
|
95
|
138 |
|
|
139 |
"
|
97
|
140 |
OptionBox request:'please select'
|
95
|
141 |
label:'select any'
|
|
142 |
form:(WarningBox iconBitmap)
|
|
143 |
buttonLabels:#('one' 'two' 'three')
|
|
144 |
values:#(1 2 3)
|
133
|
145 |
default:3
|
95
|
146 |
"
|
|
147 |
! !
|
|
148 |
|
197
|
149 |
!OptionBox methodsFor:'accessing'!
|
|
150 |
|
|
151 |
action:actionBlock
|
|
152 |
"define a single the action for all buttons.
|
|
153 |
The action will be evaluated with the button index as argument."
|
|
154 |
|
|
155 |
buttons keysAndValuesDo:[:index :button |
|
|
156 |
button action:[
|
|
157 |
button turnOffWithoutRedraw.
|
|
158 |
self hide.
|
|
159 |
actionBlock value:index
|
|
160 |
]
|
|
161 |
].
|
|
162 |
!
|
|
163 |
|
|
164 |
actions:actionBlocks
|
|
165 |
"define the actions"
|
0
|
166 |
|
197
|
167 |
actions := actionBlocks
|
|
168 |
!
|
|
169 |
|
|
170 |
buttonTitles:titles
|
|
171 |
"set the button titles"
|
|
172 |
|
|
173 |
titles keysAndValuesDo:[:index :aString |
|
|
174 |
|b|
|
0
|
175 |
|
197
|
176 |
(b := buttons at:index) label:aString.
|
|
177 |
b resize.
|
|
178 |
].
|
|
179 |
shown ifTrue:[self resize]
|
|
180 |
!
|
|
181 |
|
|
182 |
buttonTitles:titles actions:actionBlocks
|
|
183 |
"define both button titles and actions"
|
|
184 |
|
|
185 |
self buttonTitles:titles.
|
|
186 |
actions := actionBlocks.
|
|
187 |
!
|
0
|
188 |
|
197
|
189 |
buttons
|
|
190 |
"return the buttons collection"
|
|
191 |
|
|
192 |
^ buttons
|
|
193 |
!
|
|
194 |
|
|
195 |
defaultButtonIndex:index
|
|
196 |
defaultButtonIndex notNil ifTrue:[
|
|
197 |
(buttons at:defaultButtonIndex) isReturnButton:false
|
|
198 |
].
|
|
199 |
(index notNil and:[index ~~ 0]) ifTrue:[
|
|
200 |
defaultButtonIndex := index.
|
|
201 |
defaultButtonIndex notNil ifTrue:[
|
|
202 |
(buttons at:defaultButtonIndex) isReturnButton:true
|
|
203 |
].
|
|
204 |
]
|
|
205 |
!
|
|
206 |
|
|
207 |
form:aFormOrImage
|
|
208 |
"set the image shown in the label-view"
|
0
|
209 |
|
197
|
210 |
formLabel form:aFormOrImage
|
|
211 |
!
|
|
212 |
|
|
213 |
formLabel
|
|
214 |
"return the label-view which displays a bitmap"
|
|
215 |
|
|
216 |
^ formLabel
|
|
217 |
!
|
|
218 |
|
|
219 |
numberOfOptions
|
|
220 |
"return the number of options"
|
|
221 |
|
|
222 |
^ buttons size
|
|
223 |
!
|
|
224 |
|
|
225 |
numberOfOptions:nOptions
|
|
226 |
"set the number of options"
|
|
227 |
|
|
228 |
buttons := (OrderedCollection new:nOptions) grow:nOptions.
|
|
229 |
actions := (OrderedCollection new:nOptions) grow:nOptions
|
|
230 |
!
|
0
|
231 |
|
|
232 |
title:aString
|
16
|
233 |
"set the boxes title"
|
0
|
234 |
|
16
|
235 |
aString ~= textLabel label ifTrue:[
|
59
|
236 |
textLabel label:aString withoutSeparators.
|
110
|
237 |
textLabel forceResize.
|
97
|
238 |
shown ifTrue:[self resize]
|
16
|
239 |
]
|
0
|
240 |
!
|
|
241 |
|
97
|
242 |
title:aString numberOfOptions:nOptions
|
|
243 |
"set the boxes title and number of options"
|
|
244 |
|
|
245 |
self title:aString.
|
|
246 |
buttons grow:nOptions.
|
|
247 |
actions grow:nOptions
|
197
|
248 |
! !
|
97
|
249 |
|
197
|
250 |
!OptionBox methodsFor:'events'!
|
77
|
251 |
|
197
|
252 |
keyPress:aKey x:x y:y
|
|
253 |
"return-key dublicates ok-function if acceptReturnAsOK is true"
|
77
|
254 |
|
197
|
255 |
|action|
|
77
|
256 |
|
197
|
257 |
defaultButtonIndex notNil ifTrue:[
|
|
258 |
(aKey == #Return) ifTrue:[
|
|
259 |
self hide.
|
|
260 |
action := actions at:defaultButtonIndex.
|
|
261 |
action notNil ifTrue:[
|
|
262 |
action value
|
|
263 |
]
|
|
264 |
]
|
|
265 |
].
|
|
266 |
super keyPress:aKey x:x y:y
|
|
267 |
! !
|
0
|
268 |
|
197
|
269 |
!OptionBox methodsFor:'initializing'!
|
7
|
270 |
|
197
|
271 |
focusSequence
|
21
|
272 |
^ buttons
|
|
273 |
!
|
|
274 |
|
197
|
275 |
initFormBitmap
|
|
276 |
WarnBitmap isNil ifTrue:[
|
|
277 |
WarnBitmap := Form fromFile:'Warning.xbm' resolution:100 on:Display
|
0
|
278 |
].
|
197
|
279 |
formLabel form:WarnBitmap
|
0
|
280 |
!
|
|
281 |
|
|
282 |
initialize
|
372
|
283 |
|nButt mm|
|
0
|
284 |
|
|
285 |
super initialize.
|
|
286 |
|
372
|
287 |
mm := ViewSpacing.
|
|
288 |
|
38
|
289 |
formLabel := Label in:self.
|
|
290 |
self initFormBitmap.
|
0
|
291 |
formLabel borderWidth:0.
|
372
|
292 |
formLabel origin:(mm @ mm).
|
0
|
293 |
|
188
|
294 |
textLabel := Label label:'Select' in:self.
|
0
|
295 |
textLabel borderWidth:0.
|
372
|
296 |
textLabel origin:((mm + formLabel width + mm) @ mm).
|
0
|
297 |
|
77
|
298 |
buttonPanel := HorizontalPanelView origin:(0.0 @ 1.0) corner:(1.0 @ 1.0) in:self.
|
130
|
299 |
buttonPanel
|
372
|
300 |
bottomInset:mm;
|
|
301 |
topInset:(font height + mm * 2) negated.
|
130
|
302 |
buttonPanel
|
372
|
303 |
borderWidth:0;
|
|
304 |
horizontalLayout:#fitSpace.
|
59
|
305 |
|
0
|
306 |
nButt := buttons size.
|
|
307 |
|
7
|
308 |
1 to:nButt do:[:index |
|
372
|
309 |
|button|
|
7
|
310 |
|
372
|
311 |
button := Button label:'press'.
|
|
312 |
button action:[
|
|
313 |
|action|
|
7
|
314 |
|
372
|
315 |
(buttons at:index) turnOffWithoutRedraw.
|
|
316 |
self hide.
|
|
317 |
action := actions at:index.
|
|
318 |
action notNil ifTrue:[
|
|
319 |
action value
|
|
320 |
]
|
|
321 |
].
|
133
|
322 |
"/ index == nButt ifTrue:[
|
|
323 |
"/ button isReturnButton:true
|
|
324 |
"/ ].
|
372
|
325 |
buttonPanel addSubView:button.
|
|
326 |
buttons at:index put:button.
|
91
|
327 |
].
|
|
328 |
|
|
329 |
"
|
|
330 |
|box|
|
|
331 |
|
|
332 |
box := OptionBox title:'hello' numberOfOptions:4.
|
|
333 |
box open
|
|
334 |
"
|
372
|
335 |
|
|
336 |
"Modified: 21.2.1996 / 01:03:19 / cg"
|
133
|
337 |
! !
|
|
338 |
|
63
|
339 |
!OptionBox methodsFor:'queries'!
|
0
|
340 |
|
16
|
341 |
positionOffset
|
|
342 |
"return the delta, by which the box should be displayed
|
|
343 |
from the mouse pointer. Value returned here makes
|
110
|
344 |
the return-button appear under the cursor"
|
|
345 |
|
119
|
346 |
|idx butt|
|
16
|
347 |
|
110
|
348 |
buttonPanel setChildPositionsIfChanged.
|
|
349 |
idx := buttons findFirst:[:b | b isReturnButton].
|
119
|
350 |
idx ~~ 0 ifTrue:[
|
|
351 |
butt := buttons at:idx.
|
|
352 |
^ (butt originRelativeTo:self) + (butt extent // 2)
|
|
353 |
].
|
|
354 |
^ self extent // 2
|
16
|
355 |
!
|
|
356 |
|
130
|
357 |
preferredExtent
|
59
|
358 |
"return a size to make everything fit into myself"
|
|
359 |
|
371
|
360 |
|w w1 h maxH prefPanel mm|
|
0
|
361 |
|
371
|
362 |
mm := ViewSpacing.
|
|
363 |
|
|
364 |
w1 := (mm * 3) + formLabel width + textLabel width.
|
130
|
365 |
prefPanel := buttonPanel preferredExtent.
|
91
|
366 |
w := w1 max:prefPanel x.
|
38
|
367 |
|
97
|
368 |
"/ maxH := 0.
|
|
369 |
"/ buttons do:[:button |
|
130
|
370 |
"/ maxH := maxH max:(button preferredExtent y)
|
97
|
371 |
"/ ].
|
|
372 |
maxH := prefPanel y.
|
0
|
373 |
|
371
|
374 |
h := (mm * 4)
|
|
375 |
+ ((formLabel height) max:(textLabel height))
|
|
376 |
+ maxH.
|
0
|
377 |
|
59
|
378 |
^ w @ h
|
371
|
379 |
|
|
380 |
"Modified: 21.2.1996 / 01:00:14 / cg"
|
0
|
381 |
! !
|
197
|
382 |
|
243
|
383 |
!OptionBox class methodsFor:'documentation'!
|
|
384 |
|
|
385 |
version
|
372
|
386 |
^ '$Header: /cvs/stx/stx/libwidg/OptionBox.st,v 1.27 1996-02-21 00:03:33 cg Exp $'
|
243
|
387 |
! !
|