author | Claus Gittinger <cg@exept.de> |
Tue, 25 May 1999 16:14:41 +0200 | |
changeset 1914 | f337a7fd99f5 |
parent 1612 | e7d3bc88a533 |
child 2162 | 9ef1004f8e74 |
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 |
||
740
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
13 |
DialogBox subclass:#OptionBox |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
14 |
instanceVariableNames:'formLabel textLabel buttons actions defaultButtonIndex' |
355 | 15 |
classVariableNames:'WarnBitmap' |
16 |
poolDictionaries:'' |
|
17 |
category:'Views-DialogBoxes' |
|
0 | 18 |
! |
19 |
||
847 | 20 |
!OptionBox class methodsFor:'documentation'! |
7 | 21 |
|
38 | 22 |
copyright |
23 |
" |
|
24 |
COPYRIGHT (c) 1991 by Claus Gittinger |
|
59 | 25 |
All Rights Reserved |
38 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
7 | 36 |
documentation |
37 |
" |
|
646 | 38 |
CAVEAT: this is a leftover - functionality has been merged into DialogBox |
39 |
PLEASE use one of the `Dialog chooseXXX' methods nstead of OptionBox. |
|
40 |
||
41 |
||
355 | 42 |
Historic note: |
646 | 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. |
|
355 | 47 |
|
646 | 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). |
|
355 | 51 |
|
52 |
||
38 | 53 |
OptionBoxes are like YesNoBoxes but with as many buttons as you like; |
91 | 54 |
this will finally be a superclass of WarnBox and YesNoBox - or maybe merged |
38 | 55 |
all into DialogBox.. |
97 | 56 |
Use them for multiway questions. |
91 | 57 |
For a consistent user interface, the rightmost button is the default return |
97 | 58 |
button (i.e. pressing return in the box performs this buttons function). |
91 | 59 |
|
646 | 60 |
[author:] |
61 |
Claus Gittinger |
|
91 | 62 |
|
646 | 63 |
[see also:] |
64 |
DialogBox |
|
65 |
" |
|
66 |
! |
|
91 | 67 |
|
646 | 68 |
examples |
69 |
" |
|
70 |
[exBegin] |
|
71 |
|box| |
|
97 | 72 |
|
646 | 73 |
box := OptionBox title:'hello' numberOfOptions:4. |
74 |
box showAtPointer |
|
75 |
[exEnd] |
|
97 | 76 |
|
77 |
||
646 | 78 |
[exBegin] |
79 |
|box| |
|
80 |
box := OptionBox title:'hello' numberOfOptions:3. |
|
81 |
box buttonTitles:#('one' 'two' 'three'). |
|
82 |
box showAtPointer |
|
83 |
[exEnd] |
|
97 | 84 |
|
646 | 85 |
performing an action: |
97 | 86 |
|
646 | 87 |
[exBegin] |
88 |
|box| |
|
89 |
box := OptionBox title:'hello' numberOfOptions:3. |
|
90 |
box buttonTitles:#('one' 'two' 'three'). |
|
91 |
box action:[:which | Transcript show:'button '; |
|
92 |
show: which; |
|
655 | 93 |
showCR:' was pressed']. |
646 | 94 |
box showAtPointer |
95 |
[exEnd] |
|
97 | 96 |
|
646 | 97 |
returning a value: |
98 |
[exBegin] |
|
99 |
|what| |
|
133 | 100 |
|
646 | 101 |
what := OptionBox |
102 |
request:('text has not been accepted.\\Your modifications will be lost when continuing.') withCRs |
|
103 |
label:' Attention' |
|
104 |
form:(WarningBox iconBitmap) |
|
105 |
buttonLabels:#('abort' 'accept' 'continue') |
|
106 |
values:#(#abort #accept #continue). |
|
655 | 107 |
Transcript showCR:what. |
646 | 108 |
[exEnd] |
7 | 109 |
" |
197 | 110 |
! ! |
111 |
||
847 | 112 |
!OptionBox class methodsFor:'instance creation'! |
197 | 113 |
|
114 |
title:titleString numberOfOptions:nOptions |
|
115 |
"create a new optionBox with title, aTitleString and nOptions options" |
|
116 |
||
117 |
|box| |
|
118 |
||
119 |
box := (self basicNew) numberOfOptions:nOptions. |
|
120 |
box device:Screen current. |
|
121 |
box initialize. |
|
122 |
box title:titleString. |
|
123 |
^ box |
|
7 | 124 |
! ! |
125 |
||
847 | 126 |
!OptionBox class methodsFor:'easy startup '! |
95 | 127 |
|
133 | 128 |
request:title label:label form:aForm buttonLabels:labels values:values |
129 |
"create a new optionBox, open it modal and return the value of |
|
130 |
the corresponding values collection." |
|
131 |
||
132 |
^ self request:title label:label form:aForm buttonLabels:labels values:values default:nil |
|
133 |
! |
|
134 |
||
135 |
request:title label:label form:aForm buttonLabels:labels values:values default:defaultValue |
|
95 | 136 |
"create a new optionBox, open it modal and return the value of |
137 |
the corresponding values collection." |
|
138 |
||
139 |
|box| |
|
140 |
||
141 |
box := OptionBox title:title numberOfOptions:(labels size). |
|
142 |
box buttonTitles:labels. |
|
133 | 143 |
box defaultButtonIndex:(values indexOf:defaultValue). |
920 | 144 |
box action:[:n | box destroy. ^ values at:n]. |
95 | 145 |
box label:label; form:aForm. |
146 |
box showAtPointer. |
|
920 | 147 |
box destroy. |
133 | 148 |
^ defaultValue |
95 | 149 |
|
150 |
" |
|
97 | 151 |
OptionBox request:'please select' |
920 | 152 |
label:'select any' |
153 |
form:(WarningBox iconBitmap) |
|
154 |
buttonLabels:#('one' 'two' 'three') |
|
155 |
values:#(1 2 3) |
|
156 |
default:3 |
|
95 | 157 |
" |
920 | 158 |
|
159 |
"Modified: 7.1.1997 / 22:59:21 / cg" |
|
95 | 160 |
! ! |
161 |
||
197 | 162 |
!OptionBox methodsFor:'accessing'! |
163 |
||
164 |
action:actionBlock |
|
165 |
"define a single the action for all buttons. |
|
166 |
The action will be evaluated with the button index as argument." |
|
167 |
||
168 |
buttons keysAndValuesDo:[:index :button | |
|
169 |
button action:[ |
|
170 |
button turnOffWithoutRedraw. |
|
171 |
self hide. |
|
172 |
actionBlock value:index |
|
173 |
] |
|
174 |
]. |
|
175 |
! |
|
176 |
||
177 |
actions:actionBlocks |
|
178 |
"define the actions" |
|
0 | 179 |
|
197 | 180 |
actions := actionBlocks |
181 |
! |
|
182 |
||
183 |
buttonTitles:titles actions:actionBlocks |
|
184 |
"define both button titles and actions" |
|
185 |
||
186 |
self buttonTitles:titles. |
|
187 |
actions := actionBlocks. |
|
188 |
! |
|
0 | 189 |
|
197 | 190 |
buttons |
191 |
"return the buttons collection" |
|
192 |
||
193 |
^ buttons |
|
194 |
! |
|
195 |
||
196 |
defaultButtonIndex:index |
|
847 | 197 |
"define which button is the default (i.e. return-) button. |
198 |
By default, no returnButton is setup. The argument must be an |
|
199 |
index 1..nButtons, or nil" |
|
200 |
||
197 | 201 |
defaultButtonIndex notNil ifTrue:[ |
847 | 202 |
(buttons at:defaultButtonIndex) isReturnButton:false |
197 | 203 |
]. |
204 |
(index notNil and:[index ~~ 0]) ifTrue:[ |
|
847 | 205 |
defaultButtonIndex := index. |
206 |
defaultButtonIndex notNil ifTrue:[ |
|
207 |
(buttons at:defaultButtonIndex) isReturnButton:true |
|
208 |
]. |
|
197 | 209 |
] |
847 | 210 |
|
211 |
"Modified: 18.10.1996 / 14:53:36 / cg" |
|
197 | 212 |
! |
213 |
||
214 |
numberOfOptions |
|
215 |
"return the number of options" |
|
216 |
||
217 |
^ buttons size |
|
218 |
! |
|
219 |
||
220 |
numberOfOptions:nOptions |
|
847 | 221 |
"set the number of options - this is a private interface" |
197 | 222 |
|
223 |
buttons := (OrderedCollection new:nOptions) grow:nOptions. |
|
224 |
actions := (OrderedCollection new:nOptions) grow:nOptions |
|
847 | 225 |
|
226 |
"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
|
227 |
! ! |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
228 |
|
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
229 |
!OptionBox methodsFor:'accessing - look'! |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
230 |
|
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
231 |
buttonTitles:titles |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
232 |
"set the button titles" |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
233 |
|
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
234 |
titles keysAndValuesDo:[:index :aString | |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
235 |
|b| |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
236 |
|
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
237 |
(b := buttons at:index) label:aString. |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
238 |
b resize. |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
239 |
]. |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
240 |
shown ifTrue:[self resize] |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
241 |
! |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
242 |
|
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
243 |
form:aFormOrImage |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
244 |
"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
|
245 |
|
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
246 |
formLabel form:aFormOrImage |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
247 |
! |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
248 |
|
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
249 |
formLabel |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
250 |
"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
|
251 |
|
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
252 |
^ formLabel |
197 | 253 |
! |
0 | 254 |
|
255 |
title:aString |
|
16 | 256 |
"set the boxes title" |
0 | 257 |
|
16 | 258 |
aString ~= textLabel label ifTrue:[ |
59 | 259 |
textLabel label:aString withoutSeparators. |
110 | 260 |
textLabel forceResize. |
97 | 261 |
shown ifTrue:[self resize] |
16 | 262 |
] |
0 | 263 |
! |
264 |
||
97 | 265 |
title:aString numberOfOptions:nOptions |
266 |
"set the boxes title and number of options" |
|
267 |
||
268 |
self title:aString. |
|
269 |
buttons grow:nOptions. |
|
270 |
actions grow:nOptions |
|
197 | 271 |
! ! |
97 | 272 |
|
197 | 273 |
!OptionBox methodsFor:'events'! |
77 | 274 |
|
197 | 275 |
keyPress:aKey x:x y:y |
276 |
"return-key dublicates ok-function if acceptReturnAsOK is true" |
|
77 | 277 |
|
490 | 278 |
<resource: #keyboard (#Return)> |
279 |
||
197 | 280 |
|action| |
77 | 281 |
|
197 | 282 |
defaultButtonIndex notNil ifTrue:[ |
490 | 283 |
(aKey == #Return) ifTrue:[ |
284 |
self hide. |
|
285 |
action := actions at:defaultButtonIndex. |
|
286 |
action notNil ifTrue:[ |
|
287 |
action value |
|
288 |
] |
|
289 |
] |
|
197 | 290 |
]. |
291 |
super keyPress:aKey x:x y:y |
|
490 | 292 |
|
293 |
"Modified: 7.3.1996 / 13:17:36 / cg" |
|
197 | 294 |
! ! |
0 | 295 |
|
197 | 296 |
!OptionBox methodsFor:'initializing'! |
7 | 297 |
|
197 | 298 |
initFormBitmap |
299 |
WarnBitmap isNil ifTrue:[ |
|
1914 | 300 |
WarnBitmap := WarningBox iconBitmap. |
301 |
"/ WarnBitmap := Image fromFile:'bitmaps/Warning.xbm' resolution:100 on:Display |
|
0 | 302 |
]. |
197 | 303 |
formLabel form:WarnBitmap |
899 | 304 |
|
1914 | 305 |
"Modified: / 25.5.1999 / 16:08:06 / cg" |
0 | 306 |
! |
307 |
||
308 |
initialize |
|
372 | 309 |
|nButt mm| |
0 | 310 |
|
311 |
super initialize. |
|
312 |
||
372 | 313 |
mm := ViewSpacing. |
314 |
||
38 | 315 |
formLabel := Label in:self. |
316 |
self initFormBitmap. |
|
0 | 317 |
formLabel borderWidth:0. |
372 | 318 |
formLabel origin:(mm @ mm). |
0 | 319 |
|
188 | 320 |
textLabel := Label label:'Select' in:self. |
0 | 321 |
textLabel borderWidth:0. |
372 | 322 |
textLabel origin:((mm + formLabel width + mm) @ mm). |
0 | 323 |
|
1612
e7d3bc88a533
oops - two buttonPanels where created (MD's fix).
Claus Gittinger <cg@exept.de>
parents:
953
diff
changeset
|
324 |
"/ buttonPanel isNil ifTrue:[ |
e7d3bc88a533
oops - two buttonPanels where created (MD's fix).
Claus Gittinger <cg@exept.de>
parents:
953
diff
changeset
|
325 |
"/ 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
|
326 |
"/ ]. |
130 | 327 |
buttonPanel |
372 | 328 |
bottomInset:mm; |
329 |
topInset:(font height + mm * 2) negated. |
|
130 | 330 |
buttonPanel |
372 | 331 |
borderWidth:0; |
332 |
horizontalLayout:#fitSpace. |
|
59 | 333 |
|
0 | 334 |
nButt := buttons size. |
335 |
||
7 | 336 |
1 to:nButt do:[:index | |
372 | 337 |
|button| |
7 | 338 |
|
372 | 339 |
button := Button label:'press'. |
340 |
button action:[ |
|
341 |
|action| |
|
7 | 342 |
|
372 | 343 |
(buttons at:index) turnOffWithoutRedraw. |
344 |
self hide. |
|
345 |
action := actions at:index. |
|
346 |
action notNil ifTrue:[ |
|
347 |
action value |
|
348 |
] |
|
349 |
]. |
|
133 | 350 |
"/ index == nButt ifTrue:[ |
351 |
"/ button isReturnButton:true |
|
352 |
"/ ]. |
|
372 | 353 |
buttonPanel addSubView:button. |
354 |
buttons at:index put:button. |
|
91 | 355 |
]. |
356 |
||
357 |
" |
|
358 |
|box| |
|
359 |
||
360 |
box := OptionBox title:'hello' numberOfOptions:4. |
|
361 |
box open |
|
362 |
" |
|
372 | 363 |
|
1612
e7d3bc88a533
oops - two buttonPanels where created (MD's fix).
Claus Gittinger <cg@exept.de>
parents:
953
diff
changeset
|
364 |
"Modified: / 27.7.1998 / 19:37:17 / cg" |
133 | 365 |
! ! |
366 |
||
63 | 367 |
!OptionBox methodsFor:'queries'! |
0 | 368 |
|
130 | 369 |
preferredExtent |
59 | 370 |
"return a size to make everything fit into myself" |
371 |
||
371 | 372 |
|w w1 h maxH prefPanel mm| |
0 | 373 |
|
799 | 374 |
"/ If I have an explicit preferredExtent .. |
375 |
||
713
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
376 |
preferredExtent notNil ifTrue:[ |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
377 |
^ preferredExtent |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
378 |
]. |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
379 |
|
371 | 380 |
mm := ViewSpacing. |
381 |
||
382 |
w1 := (mm * 3) + formLabel width + textLabel width. |
|
130 | 383 |
prefPanel := buttonPanel preferredExtent. |
91 | 384 |
w := w1 max:prefPanel x. |
38 | 385 |
|
97 | 386 |
"/ maxH := 0. |
387 |
"/ buttons do:[:button | |
|
130 | 388 |
"/ maxH := maxH max:(button preferredExtent y) |
97 | 389 |
"/ ]. |
390 |
maxH := prefPanel y. |
|
0 | 391 |
|
371 | 392 |
h := (mm * 4) |
393 |
+ ((formLabel height) max:(textLabel height)) |
|
394 |
+ maxH. |
|
0 | 395 |
|
59 | 396 |
^ w @ h |
371 | 397 |
|
799 | 398 |
"Modified: 19.7.1996 / 20:45:11 / cg" |
0 | 399 |
! ! |
197 | 400 |
|
847 | 401 |
!OptionBox class methodsFor:'documentation'! |
243 | 402 |
|
403 |
version |
|
1914 | 404 |
^ '$Header: /cvs/stx/stx/libwidg/OptionBox.st,v 1.41 1999-05-25 14:14:41 cg Exp $' |
243 | 405 |
! ! |