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
|
59
|
14 |
instanceVariableNames:'formLabel textLabel buttons actions'
|
|
15 |
classVariableNames:'WarnBitmap'
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Views-DialogBoxes'
|
0
|
18 |
!
|
|
19 |
|
|
20 |
OptionBox comment:'
|
5
|
21 |
COPYRIGHT (c) 1991 by Claus Gittinger
|
59
|
22 |
All Rights Reserved
|
0
|
23 |
|
63
|
24 |
$Header: /cvs/stx/stx/libwidg/OptionBox.st,v 1.9 1994-11-17 14:38:21 claus Exp $
|
0
|
25 |
'!
|
|
26 |
|
7
|
27 |
!OptionBox class methodsFor:'documentation'!
|
|
28 |
|
38
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1991 by Claus Gittinger
|
59
|
32 |
All Rights Reserved
|
38
|
33 |
|
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
|
42 |
|
|
43 |
version
|
|
44 |
"
|
63
|
45 |
$Header: /cvs/stx/stx/libwidg/OptionBox.st,v 1.9 1994-11-17 14:38:21 claus Exp $
|
38
|
46 |
"
|
|
47 |
!
|
|
48 |
|
7
|
49 |
documentation
|
|
50 |
"
|
38
|
51 |
OptionBoxes are like YesNoBoxes but with as many buttons as you like;
|
|
52 |
will finally be a superclass of WarnBox and YesNoBox - or maybe merged
|
|
53 |
all into DialogBox..
|
|
54 |
Used for multiway questions.
|
7
|
55 |
"
|
|
56 |
! !
|
|
57 |
|
0
|
58 |
!OptionBox class methodsFor:'instance creation'!
|
|
59 |
|
|
60 |
title:titleString numberOfOptions:nOptions
|
|
61 |
"create a new optionBox with title, aTitleString and nOptions options"
|
|
62 |
|
|
63 |
|box|
|
|
64 |
|
|
65 |
box := (self basicNew) numberOfOptions:nOptions.
|
38
|
66 |
box device:Display.
|
0
|
67 |
box initialize.
|
|
68 |
box title:titleString.
|
|
69 |
^ box
|
|
70 |
! !
|
|
71 |
|
|
72 |
!OptionBox methodsFor:'accessing'!
|
|
73 |
|
|
74 |
title:aString numberOfOptions:nOptions
|
16
|
75 |
"set the boxes title and number of options"
|
0
|
76 |
|
16
|
77 |
aString ~= textLabel label ifTrue:[
|
59
|
78 |
textLabel label:aString.
|
|
79 |
textLabel resize.
|
16
|
80 |
].
|
0
|
81 |
buttons grow:nOptions.
|
|
82 |
actions grow:nOptions
|
|
83 |
!
|
|
84 |
|
|
85 |
title:aString
|
16
|
86 |
"set the boxes title"
|
0
|
87 |
|
16
|
88 |
aString ~= textLabel label ifTrue:[
|
59
|
89 |
textLabel label:aString withoutSeparators.
|
|
90 |
textLabel resize.
|
|
91 |
self resize
|
16
|
92 |
]
|
0
|
93 |
!
|
|
94 |
|
|
95 |
numberOfOptions:nOptions
|
|
96 |
"set the number of options"
|
|
97 |
|
|
98 |
buttons := Array new:nOptions.
|
|
99 |
actions := Array new:nOptions
|
|
100 |
!
|
|
101 |
|
7
|
102 |
numberOfOptions
|
|
103 |
"return the number of options"
|
|
104 |
|
|
105 |
^ buttons size
|
|
106 |
!
|
|
107 |
|
21
|
108 |
buttons
|
|
109 |
"return the buttons collection"
|
|
110 |
|
|
111 |
^ buttons
|
|
112 |
!
|
|
113 |
|
0
|
114 |
buttonTitles:titles
|
7
|
115 |
"set the button titles"
|
|
116 |
|
0
|
117 |
|index|
|
|
118 |
|
|
119 |
index := 1.
|
|
120 |
titles do:[:aString |
|
59
|
121 |
(buttons at:index) label:aString.
|
|
122 |
(buttons at:index) resize.
|
|
123 |
index := index + 1
|
0
|
124 |
].
|
|
125 |
self resize
|
|
126 |
!
|
|
127 |
|
|
128 |
actions:actionBlocks
|
7
|
129 |
"define the actions"
|
|
130 |
|
0
|
131 |
actions := actionBlocks
|
|
132 |
!
|
|
133 |
|
|
134 |
buttonTitles:titles actions:actionBlocks
|
7
|
135 |
"define both button titles and actions"
|
0
|
136 |
|
7
|
137 |
self buttonTitles:titles.
|
0
|
138 |
actions := actionBlocks.
|
|
139 |
self resize
|
|
140 |
! !
|
|
141 |
|
|
142 |
!OptionBox methodsFor:'initializing'!
|
|
143 |
|
|
144 |
initialize
|
|
145 |
|nButt|
|
|
146 |
|
|
147 |
super initialize.
|
|
148 |
|
38
|
149 |
formLabel := Label in:self.
|
|
150 |
self initFormBitmap.
|
0
|
151 |
formLabel borderWidth:0.
|
|
152 |
formLabel origin:(ViewSpacing @ ViewSpacing).
|
|
153 |
|
|
154 |
textLabel := Label label:'Warning' in:self.
|
|
155 |
textLabel borderWidth:0.
|
|
156 |
textLabel origin:((ViewSpacing + formLabel width + ViewSpacing) @ ViewSpacing).
|
|
157 |
|
59
|
158 |
"
|
|
159 |
buttonPanel := HorizontalPanelView in:self.
|
|
160 |
buttonPanel origin:(0.0 @ 1.0)
|
|
161 |
corner:(1.0 @ 1.0).
|
|
162 |
buttonPanel leftInset:mm;
|
|
163 |
rightInset:mm;
|
|
164 |
topInset:(font height * 2 + mm + mm) negated;
|
|
165 |
bottomInset:mm.
|
|
166 |
"
|
|
167 |
|
0
|
168 |
nButt := buttons size.
|
|
169 |
|
7
|
170 |
1 to:nButt do:[:index |
|
59
|
171 |
|button|
|
7
|
172 |
|
59
|
173 |
button := Button label:'press'
|
|
174 |
action:[
|
|
175 |
|action|
|
7
|
176 |
|
59
|
177 |
(buttons at:index) turnOffWithoutRedraw.
|
|
178 |
self hide.
|
|
179 |
action := actions at:index.
|
|
180 |
action notNil ifTrue:[
|
|
181 |
action value
|
|
182 |
]
|
|
183 |
]
|
|
184 |
in:self.
|
|
185 |
buttons at:index put:button.
|
|
186 |
button origin:[( (index-1) * ((width-ViewSpacing) // nButt) + (ViewSpacing) )
|
|
187 |
@
|
|
188 |
(height - ViewSpacing - (buttons at:index) heightIncludingBorder)].
|
|
189 |
button extent:[(width-ViewSpacing-ViewSpacing // nButt - ViewSpacing)
|
|
190 |
@
|
|
191 |
(buttons at:index) height
|
|
192 |
]
|
0
|
193 |
]
|
38
|
194 |
!
|
|
195 |
|
|
196 |
initFormBitmap
|
|
197 |
WarnBitmap isNil ifTrue:[
|
59
|
198 |
WarnBitmap := Form fromFile:'Warning.xbm' resolution:100 on:Display
|
38
|
199 |
].
|
|
200 |
formLabel form:WarnBitmap
|
0
|
201 |
! !
|
|
202 |
|
63
|
203 |
!OptionBox methodsFor:'queries'!
|
0
|
204 |
|
16
|
205 |
positionOffset
|
|
206 |
"return the delta, by which the box should be displayed
|
|
207 |
from the mouse pointer. Value returned here makes
|
|
208 |
okButton appear under the cursor"
|
|
209 |
|
|
210 |
^ (buttons last originRelativeTo:self) + (buttons last extent // 2)
|
|
211 |
!
|
|
212 |
|
59
|
213 |
preferedExtent
|
|
214 |
"return a size to make everything fit into myself"
|
|
215 |
|
38
|
216 |
|w w1 w2 h maxH|
|
0
|
217 |
|
|
218 |
w1 := ViewSpacing + formLabel width + ViewSpacing + textLabel width + ViewSpacing.
|
59
|
219 |
w2 := buttons inject:ViewSpacing into:[:sum :butt | sum + butt widthIncludingBorder + ViewSpacing].
|
38
|
220 |
w := w1 max:w2.
|
|
221 |
|
|
222 |
maxH := 0.
|
|
223 |
buttons do:[:button |
|
59
|
224 |
maxH := maxH max:(button heightIncludingBorder)
|
0
|
225 |
].
|
|
226 |
|
|
227 |
h := ViewSpacing
|
59
|
228 |
+ ((formLabel height) max:(textLabel height))
|
|
229 |
+ ViewSpacing + ViewSpacing
|
|
230 |
+ maxH
|
|
231 |
+ ViewSpacing.
|
0
|
232 |
|
59
|
233 |
^ w @ h
|
0
|
234 |
! !
|