author | Claus Gittinger <cg@exept.de> |
Fri, 31 May 1996 22:18:55 +0200 | |
changeset 740 | 2d5cb01c7e11 |
parent 713 | 0c38ad51016d |
child 799 | 64f8700489a4 |
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 |
||
7 | 20 |
!OptionBox class methodsFor:'documentation'! |
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 |
||
112 |
!OptionBox class methodsFor:'instance creation'! |
|
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 |
||
95 | 126 |
!OptionBox class methodsFor:'easy startup '! |
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). |
95 | 144 |
box action:[:n | ^ values at:n]. |
145 |
box label:label; form:aForm. |
|
146 |
box showAtPointer. |
|
133 | 147 |
^ defaultValue |
95 | 148 |
|
149 |
" |
|
97 | 150 |
OptionBox request:'please select' |
95 | 151 |
label:'select any' |
152 |
form:(WarningBox iconBitmap) |
|
153 |
buttonLabels:#('one' 'two' 'three') |
|
154 |
values:#(1 2 3) |
|
133 | 155 |
default:3 |
95 | 156 |
" |
157 |
! ! |
|
158 |
||
197 | 159 |
!OptionBox methodsFor:'accessing'! |
160 |
||
161 |
action:actionBlock |
|
162 |
"define a single the action for all buttons. |
|
163 |
The action will be evaluated with the button index as argument." |
|
164 |
||
165 |
buttons keysAndValuesDo:[:index :button | |
|
166 |
button action:[ |
|
167 |
button turnOffWithoutRedraw. |
|
168 |
self hide. |
|
169 |
actionBlock value:index |
|
170 |
] |
|
171 |
]. |
|
172 |
! |
|
173 |
||
174 |
actions:actionBlocks |
|
175 |
"define the actions" |
|
0 | 176 |
|
197 | 177 |
actions := actionBlocks |
178 |
! |
|
179 |
||
180 |
buttonTitles:titles actions:actionBlocks |
|
181 |
"define both button titles and actions" |
|
182 |
||
183 |
self buttonTitles:titles. |
|
184 |
actions := actionBlocks. |
|
185 |
! |
|
0 | 186 |
|
197 | 187 |
buttons |
188 |
"return the buttons collection" |
|
189 |
||
190 |
^ buttons |
|
191 |
! |
|
192 |
||
193 |
defaultButtonIndex:index |
|
194 |
defaultButtonIndex notNil ifTrue:[ |
|
195 |
(buttons at:defaultButtonIndex) isReturnButton:false |
|
196 |
]. |
|
197 |
(index notNil and:[index ~~ 0]) ifTrue:[ |
|
198 |
defaultButtonIndex := index. |
|
199 |
defaultButtonIndex notNil ifTrue:[ |
|
200 |
(buttons at:defaultButtonIndex) isReturnButton:true |
|
201 |
]. |
|
202 |
] |
|
203 |
! |
|
204 |
||
205 |
numberOfOptions |
|
206 |
"return the number of options" |
|
207 |
||
208 |
^ buttons size |
|
209 |
! |
|
210 |
||
211 |
numberOfOptions:nOptions |
|
212 |
"set the number of options" |
|
213 |
||
214 |
buttons := (OrderedCollection new:nOptions) grow:nOptions. |
|
215 |
actions := (OrderedCollection new:nOptions) grow:nOptions |
|
740
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
216 |
! ! |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
217 |
|
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
218 |
!OptionBox methodsFor:'accessing - look'! |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
219 |
|
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
220 |
buttonTitles:titles |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
221 |
"set the button titles" |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
222 |
|
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
223 |
titles keysAndValuesDo:[:index :aString | |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
224 |
|b| |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
225 |
|
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
226 |
(b := buttons at:index) label:aString. |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
227 |
b resize. |
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 |
shown ifTrue:[self resize] |
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 |
|
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
232 |
form:aFormOrImage |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
233 |
"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
|
234 |
|
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
235 |
formLabel form:aFormOrImage |
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 |
|
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
238 |
formLabel |
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
239 |
"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
|
240 |
|
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
241 |
^ formLabel |
197 | 242 |
! |
0 | 243 |
|
244 |
title:aString |
|
16 | 245 |
"set the boxes title" |
0 | 246 |
|
16 | 247 |
aString ~= textLabel label ifTrue:[ |
59 | 248 |
textLabel label:aString withoutSeparators. |
110 | 249 |
textLabel forceResize. |
97 | 250 |
shown ifTrue:[self resize] |
16 | 251 |
] |
0 | 252 |
! |
253 |
||
97 | 254 |
title:aString numberOfOptions:nOptions |
255 |
"set the boxes title and number of options" |
|
256 |
||
257 |
self title:aString. |
|
258 |
buttons grow:nOptions. |
|
259 |
actions grow:nOptions |
|
197 | 260 |
! ! |
97 | 261 |
|
197 | 262 |
!OptionBox methodsFor:'events'! |
77 | 263 |
|
197 | 264 |
keyPress:aKey x:x y:y |
265 |
"return-key dublicates ok-function if acceptReturnAsOK is true" |
|
77 | 266 |
|
490 | 267 |
<resource: #keyboard (#Return)> |
268 |
||
197 | 269 |
|action| |
77 | 270 |
|
197 | 271 |
defaultButtonIndex notNil ifTrue:[ |
490 | 272 |
(aKey == #Return) ifTrue:[ |
273 |
self hide. |
|
274 |
action := actions at:defaultButtonIndex. |
|
275 |
action notNil ifTrue:[ |
|
276 |
action value |
|
277 |
] |
|
278 |
] |
|
197 | 279 |
]. |
280 |
super keyPress:aKey x:x y:y |
|
490 | 281 |
|
282 |
"Modified: 7.3.1996 / 13:17:36 / cg" |
|
197 | 283 |
! ! |
0 | 284 |
|
197 | 285 |
!OptionBox methodsFor:'initializing'! |
7 | 286 |
|
197 | 287 |
initFormBitmap |
288 |
WarnBitmap isNil ifTrue:[ |
|
289 |
WarnBitmap := Form fromFile:'Warning.xbm' resolution:100 on:Display |
|
0 | 290 |
]. |
197 | 291 |
formLabel form:WarnBitmap |
0 | 292 |
! |
293 |
||
294 |
initialize |
|
372 | 295 |
|nButt mm| |
0 | 296 |
|
297 |
super initialize. |
|
298 |
||
372 | 299 |
mm := ViewSpacing. |
300 |
||
38 | 301 |
formLabel := Label in:self. |
302 |
self initFormBitmap. |
|
0 | 303 |
formLabel borderWidth:0. |
372 | 304 |
formLabel origin:(mm @ mm). |
0 | 305 |
|
188 | 306 |
textLabel := Label label:'Select' in:self. |
0 | 307 |
textLabel borderWidth:0. |
372 | 308 |
textLabel origin:((mm + formLabel width + mm) @ mm). |
0 | 309 |
|
77 | 310 |
buttonPanel := HorizontalPanelView origin:(0.0 @ 1.0) corner:(1.0 @ 1.0) in:self. |
130 | 311 |
buttonPanel |
372 | 312 |
bottomInset:mm; |
313 |
topInset:(font height + mm * 2) negated. |
|
130 | 314 |
buttonPanel |
372 | 315 |
borderWidth:0; |
316 |
horizontalLayout:#fitSpace. |
|
59 | 317 |
|
0 | 318 |
nButt := buttons size. |
319 |
||
7 | 320 |
1 to:nButt do:[:index | |
372 | 321 |
|button| |
7 | 322 |
|
372 | 323 |
button := Button label:'press'. |
324 |
button action:[ |
|
325 |
|action| |
|
7 | 326 |
|
372 | 327 |
(buttons at:index) turnOffWithoutRedraw. |
328 |
self hide. |
|
329 |
action := actions at:index. |
|
330 |
action notNil ifTrue:[ |
|
331 |
action value |
|
332 |
] |
|
333 |
]. |
|
133 | 334 |
"/ index == nButt ifTrue:[ |
335 |
"/ button isReturnButton:true |
|
336 |
"/ ]. |
|
372 | 337 |
buttonPanel addSubView:button. |
338 |
buttons at:index put:button. |
|
91 | 339 |
]. |
340 |
||
341 |
" |
|
342 |
|box| |
|
343 |
||
344 |
box := OptionBox title:'hello' numberOfOptions:4. |
|
345 |
box open |
|
346 |
" |
|
372 | 347 |
|
348 |
"Modified: 21.2.1996 / 01:03:19 / cg" |
|
133 | 349 |
! ! |
350 |
||
63 | 351 |
!OptionBox methodsFor:'queries'! |
0 | 352 |
|
16 | 353 |
positionOffset |
354 |
"return the delta, by which the box should be displayed |
|
355 |
from the mouse pointer. Value returned here makes |
|
110 | 356 |
the return-button appear under the cursor" |
357 |
||
119 | 358 |
|idx butt| |
16 | 359 |
|
110 | 360 |
buttonPanel setChildPositionsIfChanged. |
361 |
idx := buttons findFirst:[:b | b isReturnButton]. |
|
119 | 362 |
idx ~~ 0 ifTrue:[ |
363 |
butt := buttons at:idx. |
|
364 |
^ (butt originRelativeTo:self) + (butt extent // 2) |
|
365 |
]. |
|
366 |
^ self extent // 2 |
|
16 | 367 |
! |
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 |
|
713
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
374 |
preferredExtent notNil ifTrue:[ |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
375 |
^ preferredExtent |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
376 |
]. |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
377 |
|
371 | 378 |
mm := ViewSpacing. |
379 |
||
380 |
w1 := (mm * 3) + formLabel width + textLabel width. |
|
130 | 381 |
prefPanel := buttonPanel preferredExtent. |
91 | 382 |
w := w1 max:prefPanel x. |
38 | 383 |
|
97 | 384 |
"/ maxH := 0. |
385 |
"/ buttons do:[:button | |
|
130 | 386 |
"/ maxH := maxH max:(button preferredExtent y) |
97 | 387 |
"/ ]. |
388 |
maxH := prefPanel y. |
|
0 | 389 |
|
371 | 390 |
h := (mm * 4) |
391 |
+ ((formLabel height) max:(textLabel height)) |
|
392 |
+ maxH. |
|
0 | 393 |
|
59 | 394 |
^ w @ h |
371 | 395 |
|
713
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
396 |
"Modified: 29.5.1996 / 12:11:21 / cg" |
0 | 397 |
! ! |
197 | 398 |
|
243 | 399 |
!OptionBox class methodsFor:'documentation'! |
400 |
||
401 |
version |
|
740
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
713
diff
changeset
|
402 |
^ '$Header: /cvs/stx/stx/libwidg/OptionBox.st,v 1.33 1996-05-31 20:17:52 cg Exp $' |
243 | 403 |
! ! |