author | Claus Gittinger <cg@exept.de> |
Wed, 10 Sep 2003 17:13:48 +0200 | |
changeset 2803 | 9f75a923238d |
parent 2711 | e18e9edca978 |
child 2898 | b7ba089497d6 |
permissions | -rw-r--r-- |
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 |
||
2212
7475e8be57bb
recompute label origin, if the form changes
Claus Gittinger <cg@exept.de>
parents:
2162
diff
changeset
|
13 |
"{ Package: 'stx:libwidg' }" |
7475e8be57bb
recompute label origin, if the form changes
Claus Gittinger <cg@exept.de>
parents:
2162
diff
changeset
|
14 |
|
740
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
15 |
DialogBox subclass:#OptionBox |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
16 |
instanceVariableNames:'formLabel textLabel buttons actions defaultButtonIndex' |
355 | 17 |
classVariableNames:'WarnBitmap' |
18 |
poolDictionaries:'' |
|
19 |
category:'Views-DialogBoxes' |
|
0 | 20 |
! |
21 |
||
847 | 22 |
!OptionBox class methodsFor:'documentation'! |
7 | 23 |
|
38 | 24 |
copyright |
25 |
" |
|
26 |
COPYRIGHT (c) 1991 by Claus Gittinger |
|
59 | 27 |
All Rights Reserved |
38 | 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 |
||
7 | 38 |
documentation |
39 |
" |
|
646 | 40 |
CAVEAT: this is a leftover - functionality has been merged into DialogBox |
41 |
PLEASE use one of the `Dialog chooseXXX' methods nstead of OptionBox. |
|
42 |
||
43 |
||
355 | 44 |
Historic note: |
646 | 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. |
|
355 | 49 |
|
646 | 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). |
|
355 | 53 |
|
54 |
||
38 | 55 |
OptionBoxes are like YesNoBoxes but with as many buttons as you like; |
91 | 56 |
this will finally be a superclass of WarnBox and YesNoBox - or maybe merged |
38 | 57 |
all into DialogBox.. |
97 | 58 |
Use them for multiway questions. |
91 | 59 |
For a consistent user interface, the rightmost button is the default return |
97 | 60 |
button (i.e. pressing return in the box performs this buttons function). |
91 | 61 |
|
646 | 62 |
[author:] |
63 |
Claus Gittinger |
|
91 | 64 |
|
646 | 65 |
[see also:] |
66 |
DialogBox |
|
67 |
" |
|
68 |
! |
|
91 | 69 |
|
646 | 70 |
examples |
71 |
" |
|
72 |
[exBegin] |
|
73 |
|box| |
|
97 | 74 |
|
646 | 75 |
box := OptionBox title:'hello' numberOfOptions:4. |
76 |
box showAtPointer |
|
77 |
[exEnd] |
|
97 | 78 |
|
79 |
||
646 | 80 |
[exBegin] |
81 |
|box| |
|
82 |
box := OptionBox title:'hello' numberOfOptions:3. |
|
83 |
box buttonTitles:#('one' 'two' 'three'). |
|
84 |
box showAtPointer |
|
85 |
[exEnd] |
|
97 | 86 |
|
646 | 87 |
performing an action: |
97 | 88 |
|
646 | 89 |
[exBegin] |
90 |
|box| |
|
91 |
box := OptionBox title:'hello' numberOfOptions:3. |
|
92 |
box buttonTitles:#('one' 'two' 'three'). |
|
93 |
box action:[:which | Transcript show:'button '; |
|
94 |
show: which; |
|
655 | 95 |
showCR:' was pressed']. |
646 | 96 |
box showAtPointer |
97 |
[exEnd] |
|
97 | 98 |
|
646 | 99 |
returning a value: |
100 |
[exBegin] |
|
101 |
|what| |
|
133 | 102 |
|
646 | 103 |
what := OptionBox |
104 |
request:('text has not been accepted.\\Your modifications will be lost when continuing.') withCRs |
|
105 |
label:' Attention' |
|
106 |
form:(WarningBox iconBitmap) |
|
107 |
buttonLabels:#('abort' 'accept' 'continue') |
|
108 |
values:#(#abort #accept #continue). |
|
655 | 109 |
Transcript showCR:what. |
646 | 110 |
[exEnd] |
7 | 111 |
" |
197 | 112 |
! ! |
113 |
||
847 | 114 |
!OptionBox class methodsFor:'instance creation'! |
197 | 115 |
|
116 |
title:titleString numberOfOptions:nOptions |
|
117 |
"create a new optionBox with title, aTitleString and nOptions options" |
|
118 |
||
119 |
|box| |
|
120 |
||
121 |
box := (self basicNew) numberOfOptions:nOptions. |
|
122 |
box device:Screen current. |
|
123 |
box initialize. |
|
124 |
box title:titleString. |
|
125 |
^ box |
|
7 | 126 |
! ! |
127 |
||
2449 | 128 |
!OptionBox class methodsFor:'easy startup'! |
95 | 129 |
|
2585 | 130 |
forRequest:title label:label form:aForm buttonLabels:labels values:values default:defaultValue |
131 |
"create a new optionBox and return it. |
|
132 |
Does not open the box." |
|
133 |
||
134 |
|box| |
|
135 |
||
136 |
box := OptionBox title:title numberOfOptions:(labels size). |
|
137 |
box buttonTitles:labels. |
|
138 |
box defaultButtonIndex:(values indexOf:defaultValue). |
|
139 |
box label:label; form:aForm. |
|
140 |
^ box |
|
141 |
||
142 |
"Modified: / 23.2.2000 / 11:59:32 / cg" |
|
143 |
! |
|
144 |
||
2668 | 145 |
request:title buttonLabels:labels values:values |
146 |
"create a new optionBox, open it modal and return the value of |
|
2711
e18e9edca978
by default, return nil if cancelled
Claus Gittinger <cg@exept.de>
parents:
2700
diff
changeset
|
147 |
the corresponding values collection. Return nil if cancelled" |
2668 | 148 |
|
2711
e18e9edca978
by default, return nil if cancelled
Claus Gittinger <cg@exept.de>
parents:
2700
diff
changeset
|
149 |
^ self |
e18e9edca978
by default, return nil if cancelled
Claus Gittinger <cg@exept.de>
parents:
2700
diff
changeset
|
150 |
request:title label:title buttonLabels:labels values:values |
2668 | 151 |
|
152 |
" |
|
153 |
OptionBox |
|
154 |
request:'please select any' |
|
155 |
buttonLabels:#('one' 'two' 'three') |
|
156 |
values:#(1 2 3) |
|
157 |
" |
|
158 |
! |
|
159 |
||
2669 | 160 |
request:title buttonLabels:labels values:values default:defaultValue |
161 |
"create a new optionBox, open it modal and return the value of |
|
2711
e18e9edca978
by default, return nil if cancelled
Claus Gittinger <cg@exept.de>
parents:
2700
diff
changeset
|
162 |
the corresponding values collection. Return nil if cancelled." |
2669 | 163 |
|
164 |
^ self |
|
165 |
request:title label:title form:(YesNoBox iconBitmap) buttonLabels:labels values:values |
|
2711
e18e9edca978
by default, return nil if cancelled
Claus Gittinger <cg@exept.de>
parents:
2700
diff
changeset
|
166 |
default:defaultValue onCancel:nil |
2669 | 167 |
|
168 |
" |
|
169 |
OptionBox |
|
170 |
request:'please select' |
|
171 |
buttonLabels:#('one' 'two' 'three') |
|
172 |
values:#(1 2 3) |
|
173 |
default:3 |
|
174 |
" |
|
175 |
! |
|
176 |
||
2405 | 177 |
request:title label:label buttonLabels:labels values:values |
178 |
"create a new optionBox, open it modal and return the value of |
|
2711
e18e9edca978
by default, return nil if cancelled
Claus Gittinger <cg@exept.de>
parents:
2700
diff
changeset
|
179 |
the corresponding values collection. Return nil if cancelled" |
2405 | 180 |
|
181 |
^ self |
|
182 |
request:title label:label form:(YesNoBox iconBitmap) |
|
183 |
buttonLabels:labels values:values default:nil onCancel:nil |
|
2668 | 184 |
|
185 |
" |
|
186 |
OptionBox |
|
187 |
request:'please select' |
|
188 |
label:'select any' |
|
189 |
buttonLabels:#('one' 'two' 'three') |
|
190 |
values:#(1 2 3) |
|
191 |
" |
|
2405 | 192 |
! |
193 |
||
194 |
request:title label:label buttonLabels:labels values:values default:defaultValue |
|
195 |
"create a new optionBox, open it modal and return the value of |
|
2711
e18e9edca978
by default, return nil if cancelled
Claus Gittinger <cg@exept.de>
parents:
2700
diff
changeset
|
196 |
the corresponding values collection. Return nil if cancelled" |
2405 | 197 |
|
198 |
^ self |
|
199 |
request:title label:label form:(YesNoBox iconBitmap) buttonLabels:labels values:values |
|
2711
e18e9edca978
by default, return nil if cancelled
Claus Gittinger <cg@exept.de>
parents:
2700
diff
changeset
|
200 |
default:defaultValue onCancel:nil |
2668 | 201 |
|
202 |
" |
|
203 |
OptionBox |
|
204 |
request:'please select' |
|
205 |
label:'select any' |
|
206 |
buttonLabels:#('one' 'two' 'three') |
|
207 |
values:#(1 2 3) |
|
208 |
default:3 |
|
209 |
" |
|
2405 | 210 |
! |
211 |
||
212 |
request:title label:label buttonLabels:labels values:values default:defaultValue onCancel:cancelValue |
|
213 |
"create a new optionBox, open it modal and return the value of |
|
2711
e18e9edca978
by default, return nil if cancelled
Claus Gittinger <cg@exept.de>
parents:
2700
diff
changeset
|
214 |
the corresponding values collection. Return cancelValue if cancelled." |
2405 | 215 |
|
216 |
^ self |
|
217 |
request:title label:label form:(YesNoBox iconBitmap) buttonLabels:labels values:values |
|
218 |
default:defaultValue onCancel:cancelValue |
|
2668 | 219 |
|
220 |
" |
|
221 |
OptionBox |
|
222 |
request:'please select' |
|
223 |
label:'select any' |
|
224 |
buttonLabels:#('one' 'two' 'three') |
|
225 |
values:#(1 2 3) |
|
226 |
default:3 |
|
227 |
onCancel:2 |
|
228 |
" |
|
2405 | 229 |
! |
230 |
||
133 | 231 |
request:title label:label form:aForm buttonLabels:labels values:values |
232 |
"create a new optionBox, open it modal and return the value of |
|
2711
e18e9edca978
by default, return nil if cancelled
Claus Gittinger <cg@exept.de>
parents:
2700
diff
changeset
|
233 |
the corresponding values collection. Return nil, if cancelled." |
133 | 234 |
|
2711
e18e9edca978
by default, return nil if cancelled
Claus Gittinger <cg@exept.de>
parents:
2700
diff
changeset
|
235 |
^ self |
e18e9edca978
by default, return nil if cancelled
Claus Gittinger <cg@exept.de>
parents:
2700
diff
changeset
|
236 |
request:title label:label form:aForm buttonLabels:labels values:values |
e18e9edca978
by default, return nil if cancelled
Claus Gittinger <cg@exept.de>
parents:
2700
diff
changeset
|
237 |
default:nil onCancel:nil |
2668 | 238 |
|
239 |
" |
|
240 |
OptionBox |
|
241 |
request:'please select' |
|
242 |
label:'select any' |
|
243 |
form:(WarningBox iconBitmap) |
|
244 |
buttonLabels:#('one' 'two' 'three') |
|
245 |
values:#(1 2 3) |
|
246 |
" |
|
133 | 247 |
! |
248 |
||
249 |
request:title label:label form:aForm buttonLabels:labels values:values default:defaultValue |
|
95 | 250 |
"create a new optionBox, open it modal and return the value of |
2711
e18e9edca978
by default, return nil if cancelled
Claus Gittinger <cg@exept.de>
parents:
2700
diff
changeset
|
251 |
the corresponding values collection. Return nil if cancelled." |
95 | 252 |
|
2390 | 253 |
^ self |
254 |
request:title label:label form:aForm buttonLabels:labels values:values |
|
2711
e18e9edca978
by default, return nil if cancelled
Claus Gittinger <cg@exept.de>
parents:
2700
diff
changeset
|
255 |
default:defaultValue onCancel:nil |
2668 | 256 |
|
257 |
" |
|
258 |
OptionBox |
|
259 |
request:'please select' |
|
260 |
label:'select any' |
|
261 |
form:(WarningBox iconBitmap) |
|
262 |
buttonLabels:#('one' 'two' 'three') |
|
263 |
values:#(1 2 3) |
|
264 |
default:3 |
|
265 |
" |
|
2390 | 266 |
! |
267 |
||
268 |
request:title label:label form:aForm buttonLabels:labels values:values default:defaultValue onCancel:cancelValue |
|
269 |
"create a new optionBox, open it modal and return the value of |
|
2711
e18e9edca978
by default, return nil if cancelled
Claus Gittinger <cg@exept.de>
parents:
2700
diff
changeset
|
270 |
the corresponding values collection. Return cancelValue if cancelled." |
2390 | 271 |
|
2162 | 272 |
|box retVal| |
95 | 273 |
|
2390 | 274 |
retVal := cancelValue. |
2585 | 275 |
box := self |
276 |
forRequest:title |
|
277 |
label:label |
|
278 |
form:aForm |
|
279 |
buttonLabels:labels |
|
280 |
values:values |
|
281 |
default:defaultValue. |
|
282 |
||
2162 | 283 |
box action:[:n | retVal := values at:n]. |
95 | 284 |
box showAtPointer. |
920 | 285 |
box destroy. |
2389 | 286 |
|
2162 | 287 |
^ retVal |
95 | 288 |
|
289 |
" |
|
2668 | 290 |
OptionBox |
291 |
request:'please select' |
|
292 |
label:'select any' |
|
293 |
form:(WarningBox iconBitmap) |
|
294 |
buttonLabels:#('one' 'two' 'three') |
|
295 |
values:#(1 2 3) |
|
296 |
default:3 |
|
297 |
onCancel:nil |
|
95 | 298 |
" |
920 | 299 |
|
2162 | 300 |
"Modified: / 23.2.2000 / 11:59:32 / cg" |
95 | 301 |
! ! |
302 |
||
197 | 303 |
!OptionBox methodsFor:'accessing'! |
304 |
||
305 |
action:actionBlock |
|
306 |
"define a single the action for all buttons. |
|
307 |
The action will be evaluated with the button index as argument." |
|
308 |
||
309 |
buttons keysAndValuesDo:[:index :button | |
|
310 |
button action:[ |
|
311 |
button turnOffWithoutRedraw. |
|
312 |
self hide. |
|
313 |
actionBlock value:index |
|
314 |
] |
|
315 |
]. |
|
316 |
! |
|
317 |
||
318 |
actions:actionBlocks |
|
319 |
"define the actions" |
|
0 | 320 |
|
197 | 321 |
actions := actionBlocks |
322 |
! |
|
323 |
||
324 |
buttonTitles:titles actions:actionBlocks |
|
325 |
"define both button titles and actions" |
|
326 |
||
327 |
self buttonTitles:titles. |
|
328 |
actions := actionBlocks. |
|
329 |
! |
|
0 | 330 |
|
197 | 331 |
buttons |
332 |
"return the buttons collection" |
|
333 |
||
334 |
^ buttons |
|
335 |
! |
|
336 |
||
337 |
defaultButtonIndex:index |
|
847 | 338 |
"define which button is the default (i.e. return-) button. |
339 |
By default, no returnButton is setup. The argument must be an |
|
340 |
index 1..nButtons, or nil" |
|
341 |
||
197 | 342 |
defaultButtonIndex notNil ifTrue:[ |
847 | 343 |
(buttons at:defaultButtonIndex) isReturnButton:false |
197 | 344 |
]. |
345 |
(index notNil and:[index ~~ 0]) ifTrue:[ |
|
847 | 346 |
defaultButtonIndex := index. |
347 |
defaultButtonIndex notNil ifTrue:[ |
|
348 |
(buttons at:defaultButtonIndex) isReturnButton:true |
|
349 |
]. |
|
197 | 350 |
] |
847 | 351 |
|
352 |
"Modified: 18.10.1996 / 14:53:36 / cg" |
|
197 | 353 |
! |
354 |
||
355 |
numberOfOptions |
|
356 |
"return the number of options" |
|
357 |
||
358 |
^ buttons size |
|
359 |
! |
|
360 |
||
361 |
numberOfOptions:nOptions |
|
847 | 362 |
"set the number of options - this is a private interface" |
197 | 363 |
|
364 |
buttons := (OrderedCollection new:nOptions) grow:nOptions. |
|
365 |
actions := (OrderedCollection new:nOptions) grow:nOptions |
|
847 | 366 |
|
367 |
"Modified: 18.10.1996 / 14:54:30 / cg" |
|
740
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
368 |
! ! |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
369 |
|
2227 | 370 |
!OptionBox methodsFor:'accessing-look'! |
740
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
371 |
|
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
372 |
buttonTitles:titles |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
373 |
"set the button titles" |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
374 |
|
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
375 |
titles keysAndValuesDo:[:index :aString | |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
376 |
|b| |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
377 |
|
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
378 |
(b := buttons at:index) label:aString. |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
379 |
b resize. |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
380 |
]. |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
381 |
shown ifTrue:[self resize] |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
382 |
! |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
383 |
|
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
384 |
form:aFormOrImage |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
385 |
"set the image shown in the label-view" |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
386 |
|
2212
7475e8be57bb
recompute label origin, if the form changes
Claus Gittinger <cg@exept.de>
parents:
2162
diff
changeset
|
387 |
|mm| |
7475e8be57bb
recompute label origin, if the form changes
Claus Gittinger <cg@exept.de>
parents:
2162
diff
changeset
|
388 |
|
7475e8be57bb
recompute label origin, if the form changes
Claus Gittinger <cg@exept.de>
parents:
2162
diff
changeset
|
389 |
mm := ViewSpacing. |
7475e8be57bb
recompute label origin, if the form changes
Claus Gittinger <cg@exept.de>
parents:
2162
diff
changeset
|
390 |
formLabel form:aFormOrImage. |
7475e8be57bb
recompute label origin, if the form changes
Claus Gittinger <cg@exept.de>
parents:
2162
diff
changeset
|
391 |
textLabel origin:((mm + formLabel width + mm) @ mm). |
7475e8be57bb
recompute label origin, if the form changes
Claus Gittinger <cg@exept.de>
parents:
2162
diff
changeset
|
392 |
|
740
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
393 |
! |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
394 |
|
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
395 |
formLabel |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
396 |
"return the label-view which displays a bitmap" |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
397 |
|
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
398 |
^ formLabel |
197 | 399 |
! |
0 | 400 |
|
2476 | 401 |
image:aFormOrImage |
402 |
"set the image shown in the label-view" |
|
403 |
||
404 |
self form:aFormOrImage |
|
405 |
||
406 |
"Created: / 16.11.2001 / 15:20:02 / cg" |
|
407 |
! |
|
408 |
||
2328 | 409 |
textLabel |
410 |
"return the label-view which displays a message string" |
|
411 |
||
412 |
^ textLabel |
|
413 |
! |
|
414 |
||
0 | 415 |
title:aString |
16 | 416 |
"set the boxes title" |
0 | 417 |
|
16 | 418 |
aString ~= textLabel label ifTrue:[ |
59 | 419 |
textLabel label:aString withoutSeparators. |
110 | 420 |
textLabel forceResize. |
97 | 421 |
shown ifTrue:[self resize] |
16 | 422 |
] |
0 | 423 |
! |
424 |
||
97 | 425 |
title:aString numberOfOptions:nOptions |
426 |
"set the boxes title and number of options" |
|
427 |
||
428 |
self title:aString. |
|
429 |
buttons grow:nOptions. |
|
430 |
actions grow:nOptions |
|
197 | 431 |
! ! |
97 | 432 |
|
197 | 433 |
!OptionBox methodsFor:'events'! |
77 | 434 |
|
197 | 435 |
keyPress:aKey x:x y:y |
2700 | 436 |
"return-key duplicates ok-function if acceptReturnAsOK is true" |
77 | 437 |
|
490 | 438 |
<resource: #keyboard (#Return)> |
439 |
||
197 | 440 |
|action| |
77 | 441 |
|
197 | 442 |
defaultButtonIndex notNil ifTrue:[ |
490 | 443 |
(aKey == #Return) ifTrue:[ |
444 |
self hide. |
|
445 |
action := actions at:defaultButtonIndex. |
|
446 |
action notNil ifTrue:[ |
|
447 |
action value |
|
448 |
] |
|
449 |
] |
|
197 | 450 |
]. |
451 |
super keyPress:aKey x:x y:y |
|
490 | 452 |
|
453 |
"Modified: 7.3.1996 / 13:17:36 / cg" |
|
197 | 454 |
! ! |
0 | 455 |
|
2523 | 456 |
!OptionBox methodsFor:'initialization'! |
7 | 457 |
|
197 | 458 |
initFormBitmap |
459 |
WarnBitmap isNil ifTrue:[ |
|
1914 | 460 |
WarnBitmap := WarningBox iconBitmap. |
461 |
"/ WarnBitmap := Image fromFile:'bitmaps/Warning.xbm' resolution:100 on:Display |
|
0 | 462 |
]. |
197 | 463 |
formLabel form:WarnBitmap |
899 | 464 |
|
1914 | 465 |
"Modified: / 25.5.1999 / 16:08:06 / cg" |
0 | 466 |
! |
467 |
||
468 |
initialize |
|
372 | 469 |
|nButt mm| |
0 | 470 |
|
471 |
super initialize. |
|
472 |
||
372 | 473 |
mm := ViewSpacing. |
474 |
||
38 | 475 |
formLabel := Label in:self. |
476 |
self initFormBitmap. |
|
0 | 477 |
formLabel borderWidth:0. |
372 | 478 |
formLabel origin:(mm @ mm). |
0 | 479 |
|
188 | 480 |
textLabel := Label label:'Select' in:self. |
0 | 481 |
textLabel borderWidth:0. |
372 | 482 |
textLabel origin:((mm + formLabel width + mm) @ mm). |
0 | 483 |
|
1612
e7d3bc88a533
oops - two buttonPanels where created (MD's fix).
Claus Gittinger <cg@exept.de>
parents:
953
diff
changeset
|
484 |
"/ buttonPanel isNil ifTrue:[ |
e7d3bc88a533
oops - two buttonPanels where created (MD's fix).
Claus Gittinger <cg@exept.de>
parents:
953
diff
changeset
|
485 |
"/ buttonPanel := HorizontalPanelView origin:(0.0 @ 1.0) corner:(1.0 @ 1.0) in:self. |
e7d3bc88a533
oops - two buttonPanels where created (MD's fix).
Claus Gittinger <cg@exept.de>
parents:
953
diff
changeset
|
486 |
"/ ]. |
130 | 487 |
buttonPanel |
372 | 488 |
bottomInset:mm; |
489 |
topInset:(font height + mm * 2) negated. |
|
130 | 490 |
buttonPanel |
372 | 491 |
borderWidth:0; |
492 |
horizontalLayout:#fitSpace. |
|
59 | 493 |
|
0 | 494 |
nButt := buttons size. |
495 |
||
7 | 496 |
1 to:nButt do:[:index | |
372 | 497 |
|button| |
7 | 498 |
|
372 | 499 |
button := Button label:'press'. |
500 |
button action:[ |
|
501 |
|action| |
|
7 | 502 |
|
372 | 503 |
(buttons at:index) turnOffWithoutRedraw. |
504 |
self hide. |
|
505 |
action := actions at:index. |
|
506 |
action notNil ifTrue:[ |
|
507 |
action value |
|
508 |
] |
|
509 |
]. |
|
133 | 510 |
"/ index == nButt ifTrue:[ |
511 |
"/ button isReturnButton:true |
|
512 |
"/ ]. |
|
372 | 513 |
buttonPanel addSubView:button. |
514 |
buttons at:index put:button. |
|
91 | 515 |
]. |
516 |
||
517 |
" |
|
518 |
|box| |
|
519 |
||
520 |
box := OptionBox title:'hello' numberOfOptions:4. |
|
521 |
box open |
|
522 |
" |
|
372 | 523 |
|
1612
e7d3bc88a533
oops - two buttonPanels where created (MD's fix).
Claus Gittinger <cg@exept.de>
parents:
953
diff
changeset
|
524 |
"Modified: / 27.7.1998 / 19:37:17 / cg" |
133 | 525 |
! ! |
526 |
||
63 | 527 |
!OptionBox methodsFor:'queries'! |
0 | 528 |
|
130 | 529 |
preferredExtent |
59 | 530 |
"return a size to make everything fit into myself" |
531 |
||
371 | 532 |
|w w1 h maxH prefPanel mm| |
0 | 533 |
|
799 | 534 |
"/ If I have an explicit preferredExtent .. |
535 |
||
713
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
536 |
preferredExtent notNil ifTrue:[ |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
537 |
^ preferredExtent |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
538 |
]. |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
539 |
|
371 | 540 |
mm := ViewSpacing. |
541 |
||
542 |
w1 := (mm * 3) + formLabel width + textLabel width. |
|
130 | 543 |
prefPanel := buttonPanel preferredExtent. |
91 | 544 |
w := w1 max:prefPanel x. |
38 | 545 |
|
97 | 546 |
"/ maxH := 0. |
547 |
"/ buttons do:[:button | |
|
130 | 548 |
"/ maxH := maxH max:(button preferredExtent y) |
97 | 549 |
"/ ]. |
550 |
maxH := prefPanel y. |
|
0 | 551 |
|
371 | 552 |
h := (mm * 4) |
553 |
+ ((formLabel height) max:(textLabel height)) |
|
554 |
+ maxH. |
|
0 | 555 |
|
59 | 556 |
^ w @ h |
371 | 557 |
|
799 | 558 |
"Modified: 19.7.1996 / 20:45:11 / cg" |
0 | 559 |
! ! |
197 | 560 |
|
847 | 561 |
!OptionBox class methodsFor:'documentation'! |
243 | 562 |
|
563 |
version |
|
2711
e18e9edca978
by default, return nil if cancelled
Claus Gittinger <cg@exept.de>
parents:
2700
diff
changeset
|
564 |
^ '$Header: /cvs/stx/stx/libwidg/OptionBox.st,v 1.56 2003-03-21 09:41:12 cg Exp $' |
243 | 565 |
! ! |