author | Claus Gittinger <cg@exept.de> |
Wed, 29 May 1996 12:20:58 +0200 | |
changeset 713 | 0c38ad51016d |
parent 655 | acad3ef3a46c |
child 740 | 2d5cb01c7e11 |
permissions | -rw-r--r-- |
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 |
|
253
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
14 |
instanceVariableNames:'' |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
15 |
classVariableNames:'RequestBitmap' |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
16 |
poolDictionaries:'' |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
17 |
category:'Views-DialogBoxes' |
0 | 18 |
! |
19 |
||
38 | 20 |
!YesNoBox class methodsFor:'documentation'! |
21 |
||
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1989 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 |
||
36 |
documentation |
|
37 |
" |
|
355 | 38 |
Historic note: |
39 |
originally, ST/X had separate classes for the various entry methods; |
|
40 |
there were YesNoBox, EnterBox, InfoBox and so on. |
|
41 |
In the meantime, the DialogBox class (and therefore its alias: Dialog) |
|
42 |
is going to duplicate most funcionality found in these classes. |
|
43 |
||
44 |
In the future, those existing subclasses' functionality is going to |
|
45 |
be moved fully into Dialog, and the subclasses will be replaced by dummy |
|
46 |
delegators. (They will be kept for backward compatibility, though). |
|
47 |
||
48 |
||
49 |
||
38 | 50 |
this class implements yes-no boxes by adding another (no-) Button to the WarnBox-View. |
51 |
They are created with: |
|
52 |
||
355 | 53 |
aBox := YesNoBox title:'some title'. |
54 |
aBox okAction:[ .. some action to be performed when ok is pressed ]. |
|
38 | 55 |
|
56 |
and finally shown with: |
|
0 | 57 |
|
355 | 58 |
aBox showAtPointer |
38 | 59 |
|
60 |
The default box shows 'yes' and 'no' in its buttons; this can be changed with: |
|
61 |
||
355 | 62 |
aBox yesText:'some string'. |
63 |
aBox noText:'some string'. |
|
38 | 64 |
|
65 |
There is also protocol to set both button titles in one message. |
|
66 |
Also, the action associated to the noButton can be changed. |
|
67 |
||
63 | 68 |
For very simple yes/no queries, you can also use the much simpler confirm:. |
69 |
Since implemented in Object, everyone understands confirm. You can pass |
|
70 |
a question message (but not change the buttons labels). |
|
71 |
Use is: |
|
355 | 72 |
self confirm:'some question' |
63 | 73 |
and will return true or false. |
125 | 74 |
|
75 |
For compatibility with ST-80, use: |
|
355 | 76 |
Dialog confirm:'hello' |
585 | 77 |
|
78 |
[see also:] |
|
79 |
DialogBox |
|
80 |
EnterBox |
|
81 |
||
82 |
[author:] |
|
83 |
Claus Gittinger |
|
84 |
||
63 | 85 |
" |
86 |
! |
|
87 |
||
88 |
examples |
|
89 |
" |
|
38 | 90 |
Examples: |
593 | 91 |
[exBegin] |
92 |
|aBox| |
|
38 | 93 |
|
593 | 94 |
aBox := YesNoBox title:'Coffee or tee ?'. |
95 |
aBox noText:'tee'. |
|
96 |
aBox yesText:'coffee'. |
|
655 | 97 |
aBox yesAction:[Transcript showCR:'make coffee']. |
98 |
aBox noAction:[Transcript showCR:'make tee']. |
|
593 | 99 |
aBox showAtPointer. |
100 |
[exEnd] |
|
38 | 101 |
or, shorter: |
593 | 102 |
[exBegin] |
103 |
|aBox| |
|
38 | 104 |
|
593 | 105 |
aBox := YesNoBox new. |
106 |
aBox title:'Coffee or Tee ?' |
|
655 | 107 |
yesAction:[Transcript showCR:'make coffee'] |
108 |
noAction:[Transcript showCR:'make tee']. |
|
593 | 109 |
aBox yesText:'Coffee' noText:'Tee'. |
110 |
aBox showAtPointer |
|
111 |
[exEnd] |
|
38 | 112 |
|
113 |
Also, have a look at the inherited protocol; for example, this allows changing |
|
114 |
the bitmap (default: a question mark) and other properties. |
|
59 | 115 |
|
116 |
If the box is needed to ask for a simple boolean, you can also use the |
|
117 |
#confirm method, to bring up a box, let it ask for something and return |
|
118 |
true or false. |
|
119 |
Example: |
|
593 | 120 |
[exBegin] |
121 |
|box value| |
|
59 | 122 |
|
593 | 123 |
box := YesNoBox new. |
124 |
value := box confirm:'yes or no:'. |
|
125 |
value ifTrue:[ |
|
655 | 126 |
Transcript showCR:'yes' |
593 | 127 |
] ifFalse:[ |
655 | 128 |
Transcript showCR:'no' |
593 | 129 |
] |
130 |
[exEnd] |
|
59 | 131 |
|
132 |
of course, this can also be written shorter as: |
|
593 | 133 |
[exBegin] |
134 |
(YesNoBox new confirm:'yes or no:') ifTrue:[ |
|
655 | 135 |
Transcript showCR:'yes' |
593 | 136 |
] ifFalse:[ |
655 | 137 |
Transcript showCR:'no' |
593 | 138 |
] |
139 |
[exEnd] |
|
125 | 140 |
or: |
593 | 141 |
[exBegin] |
142 |
(Dialog confirm:'yes or no:') ifTrue:[ |
|
655 | 143 |
Transcript showCR:'yes' |
593 | 144 |
] ifFalse:[ |
655 | 145 |
Transcript showCR:'no' |
593 | 146 |
] |
147 |
[exEnd] |
|
38 | 148 |
" |
149 |
! ! |
|
0 | 150 |
|
197 | 151 |
!YesNoBox class methodsFor:'instance creation'! |
59 | 152 |
|
197 | 153 |
title:t yesText:yesString noText:noString |
572 | 154 |
"return a new YesNoBox with title, and buttonLabels yesString/noString" |
155 |
||
197 | 156 |
^ (self new) title:t yesText:yesString noText:noString |
572 | 157 |
|
158 |
"Modified: 23.4.1996 / 00:12:48 / cg" |
|
59 | 159 |
! ! |
160 |
||
161 |
!YesNoBox class methodsFor:'icon bitmap'! |
|
162 |
||
163 |
iconBitmap |
|
164 |
"return the bitmap shown as icon in my instances" |
|
165 |
||
166 |
RequestBitmap isNil ifTrue:[ |
|
109 | 167 |
RequestBitmap := Image fromFile:'bitmaps/Request.xbm'. |
168 |
RequestBitmap notNil ifTrue:[ |
|
169 |
RequestBitmap := RequestBitmap on:Display |
|
170 |
]. |
|
59 | 171 |
]. |
172 |
^ RequestBitmap |
|
173 |
! ! |
|
174 |
||
197 | 175 |
!YesNoBox class methodsFor:'styles'! |
176 |
||
177 |
updateStyleCache |
|
444
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
373
diff
changeset
|
178 |
"extract values from the styleSheet and cache them in class variables" |
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
373
diff
changeset
|
179 |
|
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
373
diff
changeset
|
180 |
<resource: #style (#requestBoxIcon)> |
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
373
diff
changeset
|
181 |
|
197 | 182 |
|img| |
183 |
||
184 |
img := StyleSheet at:'requestBoxIcon'. |
|
185 |
img notNil ifTrue:[RequestBitmap := img on:Display]. |
|
444
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
373
diff
changeset
|
186 |
|
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
373
diff
changeset
|
187 |
"Modified: 1.3.1996 / 13:52:18 / cg" |
197 | 188 |
! ! |
189 |
||
190 |
!YesNoBox methodsFor:'accessing'! |
|
191 |
||
192 |
noAction:aBlock |
|
193 |
"define the action to be performed when no is pressed" |
|
194 |
||
195 |
abortAction := aBlock |
|
196 |
! |
|
197 |
||
198 |
noButton |
|
199 |
"return the no-button" |
|
200 |
||
201 |
^ abortButton |
|
202 |
! |
|
203 |
||
253
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
204 |
noLabel:aString |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
205 |
"define the label of the no-button" |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
206 |
|
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
207 |
self noText:aString. |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
208 |
|
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
209 |
"Created: 13.12.1995 / 16:21:57 / cg" |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
210 |
! |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
211 |
|
197 | 212 |
noText:aString |
213 |
"define the label of the no-button" |
|
214 |
||
215 |
aString ~= abortButton label ifTrue:[ |
|
216 |
abortButton label:aString. |
|
217 |
abortButton resize. |
|
218 |
shown ifTrue:[self resize] |
|
219 |
] |
|
220 |
! |
|
221 |
||
222 |
okText:yesString noText:noString |
|
223 |
"define the labels of both buttons - same as yesText:noText" |
|
224 |
||
225 |
^ self yesText:yesString noText:noString |
|
226 |
! |
|
227 |
||
228 |
title:aString yesAction:yesBlock noAction:noBlock |
|
229 |
"define title and actions" |
|
59 | 230 |
|
197 | 231 |
self title:aString. |
232 |
okAction := yesBlock. |
|
233 |
abortAction := noBlock |
|
234 |
! |
|
235 |
||
236 |
title:aString yesText:yesString noText:noString |
|
237 |
"define title and button labels" |
|
238 |
||
239 |
self title:aString. |
|
240 |
self yesText:yesString noText:noString |
|
241 |
! |
|
242 |
||
243 |
yesAction:aBlock |
|
244 |
"define the action to be performed when yes is pressed" |
|
245 |
||
246 |
okAction := aBlock |
|
247 |
! |
|
248 |
||
249 |
yesAction:yesBlock noAction:noBlock |
|
250 |
"define both actions" |
|
251 |
||
252 |
okAction := yesBlock. |
|
253 |
abortAction := noBlock |
|
254 |
! |
|
255 |
||
256 |
yesButton |
|
257 |
"return the yes-button" |
|
258 |
||
259 |
^ okButton |
|
260 |
! |
|
261 |
||
253
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
262 |
yesLabel:aString |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
263 |
"define the label of the yes-button" |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
264 |
|
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
265 |
self yesText:aString. |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
266 |
|
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
267 |
"Created: 13.12.1995 / 16:22:05 / cg" |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
268 |
! |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
269 |
|
197 | 270 |
yesText:aString |
271 |
"define the label of the yes-button" |
|
272 |
||
273 |
self okText:aString |
|
274 |
! |
|
275 |
||
276 |
yesText:yesString noText:noString |
|
277 |
"define the labels of both buttons" |
|
278 |
||
279 |
((yesString ~= okButton label) or:[noString ~= abortButton label]) ifTrue:[ |
|
373 | 280 |
okButton label:yesString. |
281 |
abortButton label:noString. |
|
282 |
okButton resize. |
|
283 |
abortButton resize. |
|
284 |
shown ifTrue:[self resize] |
|
197 | 285 |
] |
373 | 286 |
|
287 |
"Modified: 21.2.1996 / 00:58:38 / cg" |
|
59 | 288 |
! ! |
289 |
||
0 | 290 |
!YesNoBox methodsFor:'initialization'! |
291 |
||
292 |
initialize |
|
293 |
super initialize. |
|
294 |
||
150 | 295 |
label := resources string:'Choose'. |
79 | 296 |
|
130 | 297 |
buttonPanel horizontalLayout:#fitSpace. "/ looks better; should it come from the StyleSheet ? |
63 | 298 |
|
59 | 299 |
textLabel label:'please Confirm'. |
162 | 300 |
okButton logo:(resources at:'yes'). |
0 | 301 |
|
162 | 302 |
abortButton := Button abortButton. |
303 |
buttonPanel addSubView:abortButton before:okButton. |
|
304 |
abortButton logo:(resources at:'no'). |
|
305 |
abortButton height:(okButton height). |
|
306 |
abortButton model:self; change:#noPressed |
|
197 | 307 |
! ! |
308 |
||
309 |
!YesNoBox methodsFor:'queries'! |
|
310 |
||
572 | 311 |
focusSequence |
312 |
"return the focusSequence through the box" |
|
313 |
||
314 |
^ Array with:abortButton with:okButton |
|
315 |
||
316 |
"Modified: 23.4.1996 / 00:13:12 / cg" |
|
317 |
! |
|
318 |
||
197 | 319 |
preferredExtent |
572 | 320 |
"compute the boxes preferredExtent from the components' sizes" |
321 |
||
373 | 322 |
|w h max mm| |
323 |
||
713
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
324 |
preferredExtent notNil ifTrue:[ |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
325 |
^ preferredExtent |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
326 |
]. |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
327 |
|
373 | 328 |
mm := ViewSpacing. |
79 | 329 |
|
197 | 330 |
" |
331 |
make the two buttons of equal size |
|
332 |
" |
|
333 |
max := okButton preferredExtent x max:abortButton preferredExtent x. |
|
334 |
okButton width:max. |
|
335 |
abortButton width:max. |
|
373 | 336 |
|
197 | 337 |
w := (formLabel width + textLabel width) max:max * 2. |
373 | 338 |
w := w + (3 * mm) + (okButton borderWidth + abortButton borderWidth * 2). |
339 |
h := (mm * 5) |
|
340 |
+ ((formLabel height) max:(textLabel height)) |
|
341 |
+ okButton heightIncludingBorder. |
|
197 | 342 |
|
343 |
^ (w @ h). |
|
373 | 344 |
|
713
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
345 |
"Modified: 29.5.1996 / 12:10:11 / cg" |
59 | 346 |
! ! |
38 | 347 |
|
59 | 348 |
!YesNoBox methodsFor:'startup'! |
349 |
||
350 |
confirm |
|
351 |
"open the receiver and return true for yes, false for no. |
|
352 |
This is an easier interface to use, since no action blocks |
|
353 |
have to be defined. The title is used as previously defined." |
|
38 | 354 |
|
59 | 355 |
self yesAction:[^ true] noAction:[^ false]. |
63 | 356 |
self showAtPointer. |
357 |
self yesAction:nil noAction:nil. "/ clear actions for earlier release of context |
|
38 | 358 |
|
59 | 359 |
" |
360 |
YesNoBox new confirm |
|
361 |
" |
|
0 | 362 |
! |
363 |
||
59 | 364 |
confirm:aString |
365 |
"open the receiver and return true for yes, false for no. |
|
366 |
This is an easier interface to use, since no action blocks |
|
367 |
have to be defined." |
|
38 | 368 |
|
59 | 369 |
self title:aString. |
370 |
^ self confirm |
|
371 |
||
372 |
" |
|
373 |
YesNoBox new confirm:'really ?' |
|
253
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
374 |
YesNoBox confirm:'really ?' |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
375 |
self confirm:'really ?' |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
376 |
|
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
377 |
for ST-80 compatibility, you should use Dialogs confirm |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
378 |
(which simply forwards the request to the YesNoBox anyway): |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
379 |
|
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
380 |
Dialog confirm:'really ?' |
59 | 381 |
" |
253
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
382 |
|
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
383 |
"Modified: 13.12.1995 / 16:20:01 / cg" |
0 | 384 |
! ! |
385 |
||
386 |
!YesNoBox methodsFor:'user interaction'! |
|
387 |
||
388 |
noPressed |
|
389 |
"user pressed the no-button; |
|
390 |
hide myself and evaluate the action" |
|
391 |
||
162 | 392 |
abortButton turnOffWithoutRedraw. |
393 |
self hideAndEvaluate:abortAction |
|
0 | 394 |
! ! |
395 |
||
243 | 396 |
!YesNoBox class methodsFor:'documentation'! |
397 |
||
398 |
version |
|
713
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
399 |
^ '$Header: /cvs/stx/stx/libwidg/YesNoBox.st,v 1.30 1996-05-29 10:15:05 cg Exp $' |
243 | 400 |
! ! |