0
|
1 |
"
|
3
|
2 |
COPYRIGHT (c) 1991-93 by Claus Gittinger
|
0
|
3 |
All Rights Reserved
|
|
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
|
|
14 |
instanceVariableNames:'formLabel textLabel buttons actions'
|
|
15 |
classVariableNames:'warnBitmap'
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Views-Interactors'
|
|
18 |
!
|
|
19 |
|
|
20 |
OptionBox comment:'
|
|
21 |
|
3
|
22 |
COPYRIGHT (c) 1991-93 by Claus Gittinger
|
0
|
23 |
All Rights Reserved
|
|
24 |
|
|
25 |
like a YesNoBox but with as many as you like buttons in it;
|
|
26 |
will finally be a superclass of WarnBox and YesNoBox.
|
|
27 |
|
3
|
28 |
$Header: /cvs/stx/stx/libwidg/OptionBox.st,v 1.2 1993-10-13 01:03:03 claus Exp $
|
0
|
29 |
|
|
30 |
written Nov 91 by claus
|
|
31 |
'!
|
|
32 |
|
|
33 |
!OptionBox class methodsFor:'instance creation'!
|
|
34 |
|
|
35 |
title:titleString numberOfOptions:nOptions
|
|
36 |
"create a new optionBox with title, aTitleString and nOptions options"
|
|
37 |
|
|
38 |
|box|
|
|
39 |
|
|
40 |
box := (self basicNew) numberOfOptions:nOptions.
|
|
41 |
box device:ModalDisplay.
|
|
42 |
box initialize.
|
|
43 |
box title:titleString.
|
|
44 |
^ box
|
|
45 |
! !
|
|
46 |
|
|
47 |
!OptionBox methodsFor:'accessing'!
|
|
48 |
|
|
49 |
title:aString numberOfOptions:nOptions
|
|
50 |
"set the title and number of options"
|
|
51 |
|
|
52 |
textLabel label:aString.
|
|
53 |
textLabel resize.
|
|
54 |
buttons grow:nOptions.
|
|
55 |
actions grow:nOptions
|
|
56 |
!
|
|
57 |
|
|
58 |
title:aString
|
|
59 |
"set the title"
|
|
60 |
|
|
61 |
textLabel label:aString.
|
|
62 |
textLabel resize.
|
|
63 |
self resize
|
|
64 |
!
|
|
65 |
|
|
66 |
numberOfOptions:nOptions
|
|
67 |
"set the number of options"
|
|
68 |
|
|
69 |
buttons := Array new:nOptions.
|
|
70 |
actions := Array new:nOptions
|
|
71 |
!
|
|
72 |
|
|
73 |
buttonTitles:titles
|
|
74 |
|index|
|
|
75 |
|
|
76 |
index := 1.
|
|
77 |
titles do:[:aString |
|
|
78 |
(buttons at:index) label:aString.
|
|
79 |
index := index + 1
|
|
80 |
].
|
|
81 |
self resize
|
|
82 |
!
|
|
83 |
|
|
84 |
actions:actionBlocks
|
|
85 |
actions := actionBlocks
|
|
86 |
!
|
|
87 |
|
|
88 |
buttonTitles:titles actions:actionBlocks
|
|
89 |
|index|
|
|
90 |
|
|
91 |
index := 1.
|
|
92 |
titles do:[:aString |
|
|
93 |
(buttons at:index) label:aString.
|
|
94 |
index := index + 1
|
|
95 |
].
|
|
96 |
actions := actionBlocks.
|
|
97 |
self resize
|
|
98 |
!
|
|
99 |
|
|
100 |
numberOfOptions
|
|
101 |
"return the number of options"
|
|
102 |
|
|
103 |
^ buttons size
|
|
104 |
! !
|
|
105 |
|
|
106 |
!OptionBox methodsFor:'initializing'!
|
|
107 |
|
|
108 |
initialize
|
|
109 |
|nButt|
|
|
110 |
|
|
111 |
super initialize.
|
|
112 |
|
|
113 |
warnBitmap isNil ifTrue:[
|
|
114 |
warnBitmap := Form fromFile:'Warning.xbm' resolution:100 on:device
|
|
115 |
].
|
|
116 |
|
|
117 |
formLabel := Label form:warnBitmap in:self.
|
|
118 |
formLabel borderWidth:0.
|
|
119 |
formLabel origin:(ViewSpacing @ ViewSpacing).
|
|
120 |
|
|
121 |
textLabel := Label label:'Warning' in:self.
|
|
122 |
textLabel borderWidth:0.
|
|
123 |
textLabel origin:((ViewSpacing + formLabel width + ViewSpacing) @ ViewSpacing).
|
|
124 |
|
|
125 |
nButt := buttons size.
|
|
126 |
|
|
127 |
1 to:nButt do:[:b |
|
|
128 |
buttons at:b put:(Button label:'press'
|
|
129 |
action:[(buttons at:b) turnOff.
|
|
130 |
self hide.
|
|
131 |
(actions at:b) notNil ifTrue:[
|
|
132 |
(actions at:b) value
|
|
133 |
]
|
|
134 |
]
|
|
135 |
in:self).
|
|
136 |
(buttons at:b) origin:[( (b - 1) * ((width - ViewSpacing) // nButt) + (ViewSpacing // 2) )
|
|
137 |
@
|
|
138 |
(height - ViewSpacing - (buttons at:b) height)].
|
|
139 |
(buttons at:b) extent:[(width // nButt - ViewSpacing) @ (buttons at:b) height]
|
|
140 |
]
|
|
141 |
! !
|
|
142 |
|
|
143 |
!OptionBox methodsFor:'private'!
|
|
144 |
|
|
145 |
resize
|
|
146 |
"resize myself to make everything fit into myself"
|
|
147 |
|
|
148 |
|w w1 w2 h extra|
|
|
149 |
|
|
150 |
w1 := ViewSpacing + formLabel width + ViewSpacing + textLabel width + ViewSpacing.
|
|
151 |
|
|
152 |
w2 := 0.
|
|
153 |
buttons do:[:butt |
|
|
154 |
w2 := w2 + butt width "labelWidth".
|
|
155 |
w2 := w2 + ViewSpacing
|
|
156 |
].
|
|
157 |
w2 := w2 + (4 * ViewSpacing).
|
|
158 |
w := w1 max:w2.
|
|
159 |
|
|
160 |
h := ViewSpacing
|
|
161 |
+ ((formLabel height) max:(textLabel height))
|
|
162 |
+ ViewSpacing + ViewSpacing
|
|
163 |
+ (buttons at:1) height
|
|
164 |
+ ViewSpacing.
|
|
165 |
|
|
166 |
extra := margin * 2.
|
|
167 |
super extent:(w + extra) @ (h + extra)
|
|
168 |
! !
|
|
169 |
|