0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 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 |
WarningBox subclass:#YesNoBox
|
|
14 |
instanceVariableNames:'noButton noAction'
|
|
15 |
classVariableNames:'RequestBitmap'
|
|
16 |
poolDictionaries:''
|
38
|
17 |
category:'Views-DialogBoxes'
|
0
|
18 |
!
|
|
19 |
|
|
20 |
YesNoBox comment:'
|
5
|
21 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
22 |
All Rights Reserved
|
0
|
23 |
|
79
|
24 |
$Header: /cvs/stx/stx/libwidg/YesNoBox.st,v 1.9 1995-02-06 00:55:04 claus Exp $
|
38
|
25 |
'!
|
|
26 |
|
|
27 |
!YesNoBox class methodsFor:'documentation'!
|
|
28 |
|
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1989 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 |
"
|
79
|
45 |
$Header: /cvs/stx/stx/libwidg/YesNoBox.st,v 1.9 1995-02-06 00:55:04 claus Exp $
|
38
|
46 |
"
|
|
47 |
!
|
|
48 |
|
|
49 |
documentation
|
|
50 |
"
|
|
51 |
this class implements yes-no boxes by adding another (no-) Button to the WarnBox-View.
|
|
52 |
They are created with:
|
|
53 |
|
59
|
54 |
aBox := YesNoBox title:'some title'.
|
|
55 |
aBox okAction:[ .. some action to be performed when ok is pressed ].
|
38
|
56 |
|
|
57 |
and finally shown with:
|
0
|
58 |
|
59
|
59 |
aBox showAtPointer
|
38
|
60 |
|
|
61 |
The default box shows 'yes' and 'no' in its buttons; this can be changed with:
|
|
62 |
|
59
|
63 |
aBox yesText:'some string'.
|
|
64 |
aBox noText:'some string'.
|
38
|
65 |
|
|
66 |
There is also protocol to set both button titles in one message.
|
|
67 |
Also, the action associated to the noButton can be changed.
|
|
68 |
|
63
|
69 |
For very simple yes/no queries, you can also use the much simpler confirm:.
|
|
70 |
Since implemented in Object, everyone understands confirm. You can pass
|
|
71 |
a question message (but not change the buttons labels).
|
|
72 |
Use is:
|
|
73 |
self confirm:'some question'
|
|
74 |
and will return true or false.
|
|
75 |
"
|
|
76 |
!
|
|
77 |
|
|
78 |
examples
|
|
79 |
"
|
38
|
80 |
Examples:
|
|
81 |
|
59
|
82 |
|aBox|
|
38
|
83 |
|
59
|
84 |
aBox := YesNoBox title:'Coffee or tee ?'.
|
|
85 |
aBox noText:'tee'.
|
|
86 |
aBox yesText:'coffee'.
|
|
87 |
aBox yesAction:[Transcript showCr:'make coffee'].
|
|
88 |
aBox noAction:[Transcript showCr:'make tee'].
|
|
89 |
aBox showAtPointer.
|
38
|
90 |
|
|
91 |
or, shorter:
|
|
92 |
|
59
|
93 |
|aBox|
|
38
|
94 |
|
59
|
95 |
aBox := YesNoBox new.
|
|
96 |
aBox title:'Coffee or Tee ?'
|
|
97 |
yesAction:[Transcript showCr:'make coffee']
|
|
98 |
noAction:[Transcript showCr:'make tee'].
|
|
99 |
aBox yesText:'Coffee' noText:'Tee'.
|
|
100 |
aBox showAtPointer
|
38
|
101 |
|
|
102 |
Also, have a look at the inherited protocol; for example, this allows changing
|
|
103 |
the bitmap (default: a question mark) and other properties.
|
59
|
104 |
|
|
105 |
If the box is needed to ask for a simple boolean, you can also use the
|
|
106 |
#confirm method, to bring up a box, let it ask for something and return
|
|
107 |
true or false.
|
|
108 |
Example:
|
|
109 |
|
|
110 |
|box value|
|
|
111 |
|
|
112 |
box := YesNoBox new.
|
|
113 |
value := box confirm:'yes or no:'.
|
|
114 |
value ifTrue:[
|
|
115 |
Transcript showCr:'yes'
|
|
116 |
] ifFalse:[
|
|
117 |
Transcript showCr:'no'
|
|
118 |
]
|
|
119 |
|
|
120 |
of course, this can also be written shorter as:
|
|
121 |
|
|
122 |
(YesNoBox new confirm:'yes or no:') ifTrue:[
|
|
123 |
Transcript showCr:'yes'
|
|
124 |
] ifFalse:[
|
|
125 |
Transcript showCr:'no'
|
|
126 |
]
|
38
|
127 |
"
|
|
128 |
! !
|
0
|
129 |
|
59
|
130 |
!YesNoBox class methodsFor:'styles'!
|
|
131 |
|
|
132 |
updateStyleCache
|
|
133 |
|img|
|
|
134 |
|
|
135 |
img := StyleSheet at:'requestBoxIcon'.
|
79
|
136 |
img notNil ifTrue:[RequestBitmap := img on:Display].
|
59
|
137 |
! !
|
|
138 |
|
|
139 |
!YesNoBox class methodsFor:'icon bitmap'!
|
|
140 |
|
|
141 |
iconBitmap
|
|
142 |
"return the bitmap shown as icon in my instances"
|
|
143 |
|
|
144 |
RequestBitmap isNil ifTrue:[
|
79
|
145 |
RequestBitmap := (Image fromFile:'bitmaps/Request.xbm') on:Display
|
59
|
146 |
].
|
|
147 |
^ RequestBitmap
|
|
148 |
! !
|
|
149 |
|
|
150 |
!YesNoBox class methodsFor:'instance creation'!
|
|
151 |
|
|
152 |
title:t yesText:yesString noText:noString
|
|
153 |
^ (self new) title:t yesText:yesString noText:noString
|
|
154 |
! !
|
|
155 |
|
0
|
156 |
!YesNoBox methodsFor:'initialization'!
|
|
157 |
|
|
158 |
initialize
|
|
159 |
super initialize.
|
|
160 |
|
79
|
161 |
label := 'Choose'.
|
|
162 |
|
|
163 |
buttonPanel layout:#fitSpace. "/ looks better; should it come from the StyleSheet ?
|
63
|
164 |
|
59
|
165 |
textLabel label:'please Confirm'.
|
3
|
166 |
okButton label:(resources at:'yes').
|
0
|
167 |
|
59
|
168 |
noButton := Button new.
|
|
169 |
buttonPanel addSubView:noButton before:okButton.
|
|
170 |
noButton label:(resources at:'no').
|
|
171 |
noButton height:(okButton height).
|
|
172 |
noButton action:[
|
|
173 |
noButton turnOffWithoutRedraw.
|
|
174 |
self noPressed
|
|
175 |
].
|
|
176 |
self resize.
|
79
|
177 |
!
|
|
178 |
|
|
179 |
focusSequence
|
|
180 |
^ Array with:noButton with:okButton
|
59
|
181 |
! !
|
38
|
182 |
|
59
|
183 |
!YesNoBox methodsFor:'startup'!
|
|
184 |
|
|
185 |
confirm
|
|
186 |
"open the receiver and return true for yes, false for no.
|
|
187 |
This is an easier interface to use, since no action blocks
|
|
188 |
have to be defined. The title is used as previously defined."
|
38
|
189 |
|
59
|
190 |
self yesAction:[^ true] noAction:[^ false].
|
63
|
191 |
self showAtPointer.
|
|
192 |
self yesAction:nil noAction:nil. "/ clear actions for earlier release of context
|
38
|
193 |
|
59
|
194 |
"
|
|
195 |
YesNoBox new confirm
|
|
196 |
"
|
0
|
197 |
!
|
|
198 |
|
59
|
199 |
confirm:aString
|
|
200 |
"open the receiver and return true for yes, false for no.
|
|
201 |
This is an easier interface to use, since no action blocks
|
|
202 |
have to be defined."
|
38
|
203 |
|
59
|
204 |
self title:aString.
|
|
205 |
^ self confirm
|
|
206 |
|
|
207 |
"
|
|
208 |
YesNoBox new confirm:'really ?'
|
|
209 |
"
|
0
|
210 |
! !
|
|
211 |
|
|
212 |
!YesNoBox methodsFor:'accessing'!
|
|
213 |
|
|
214 |
yesButton
|
|
215 |
"return the yes-button"
|
|
216 |
|
|
217 |
^ okButton
|
|
218 |
!
|
|
219 |
|
|
220 |
noButton
|
|
221 |
"return the no-button"
|
|
222 |
|
|
223 |
^ noButton
|
|
224 |
!
|
|
225 |
|
|
226 |
yesAction:aBlock
|
|
227 |
"define the action to be performed when yes is pressed"
|
|
228 |
|
|
229 |
okAction := aBlock
|
|
230 |
!
|
|
231 |
|
|
232 |
noAction:aBlock
|
|
233 |
"define the action to be performed when no is pressed"
|
|
234 |
|
|
235 |
noAction := aBlock
|
|
236 |
!
|
|
237 |
|
|
238 |
yesAction:yesBlock noAction:noBlock
|
|
239 |
"define both actions"
|
|
240 |
|
|
241 |
okAction := yesBlock.
|
|
242 |
noAction := noBlock
|
|
243 |
!
|
|
244 |
|
|
245 |
yesText:aString
|
|
246 |
"define the label of the yes-button"
|
|
247 |
|
9
|
248 |
self okText:aString
|
0
|
249 |
!
|
|
250 |
|
|
251 |
noText:aString
|
|
252 |
"define the label of the no-button"
|
|
253 |
|
9
|
254 |
aString ~= noButton label ifTrue:[
|
59
|
255 |
noButton label:aString.
|
|
256 |
noButton resize.
|
|
257 |
self resize
|
9
|
258 |
]
|
0
|
259 |
!
|
|
260 |
|
59
|
261 |
okText:yesString noText:noString
|
|
262 |
"define the labels of both buttons - same as yesText:noText"
|
|
263 |
|
|
264 |
^ self yesText:yesString noText:noString
|
|
265 |
!
|
|
266 |
|
0
|
267 |
yesText:yesString noText:noString
|
|
268 |
"define the labels of both buttons"
|
|
269 |
|
9
|
270 |
((yesString ~= okButton label) or:[noString ~= noButton label]) ifTrue:[
|
59
|
271 |
okButton label:yesString.
|
|
272 |
noButton label:noString.
|
|
273 |
okButton resize.
|
|
274 |
noButton resize.
|
|
275 |
self resize
|
9
|
276 |
]
|
0
|
277 |
!
|
|
278 |
|
59
|
279 |
title:aString yesText:yesString noText:noString
|
|
280 |
"define title and button labels"
|
|
281 |
|
|
282 |
self title:aString.
|
|
283 |
self yesText:yesString noText:noString
|
|
284 |
!
|
|
285 |
|
0
|
286 |
title:aString yesAction:yesBlock noAction:noBlock
|
|
287 |
"define title and actions"
|
|
288 |
|
|
289 |
self title:aString.
|
|
290 |
okAction := yesBlock.
|
|
291 |
noAction := noBlock
|
|
292 |
! !
|
|
293 |
|
|
294 |
!YesNoBox methodsFor:'user interaction'!
|
|
295 |
|
|
296 |
noPressed
|
|
297 |
"user pressed the no-button;
|
|
298 |
hide myself and evaluate the action"
|
|
299 |
|
|
300 |
self hideAndEvaluate:noAction
|
|
301 |
! !
|
|
302 |
|
59
|
303 |
!YesNoBox methodsFor:'queries'!
|
0
|
304 |
|
59
|
305 |
preferedExtent
|
|
306 |
|w h max|
|
0
|
307 |
|
59
|
308 |
"
|
|
309 |
make the two buttons of equal size
|
|
310 |
"
|
|
311 |
max := okButton preferedExtent x max:noButton preferedExtent x.
|
|
312 |
okButton width:max; fixSize.
|
|
313 |
noButton width:max; fixSize.
|
|
314 |
w := (formLabel width + textLabel width) max:max * 2.
|
|
315 |
w := w + (3 * ViewSpacing) + (okButton borderWidth + noButton borderWidth * 2).
|
63
|
316 |
h := ViewSpacing
|
59
|
317 |
+ ((formLabel height) max:(textLabel height))
|
63
|
318 |
+ (ViewSpacing * 3)
|
|
319 |
+ okButton heightIncludingBorder
|
|
320 |
+ ViewSpacing.
|
0
|
321 |
|
59
|
322 |
^ (w @ h).
|
0
|
323 |
! !
|