author | Claus Gittinger <cg@exept.de> |
Thu, 04 Oct 2001 19:26:48 +0200 | |
changeset 2428 | f800d9ec09a8 |
parent 2361 | 227ff51a7e7b |
child 2467 | 82d16b9ea94d |
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 |
||
2304
c96b6b899023
button-roder reversal is now done exclusively in the buttonPanel
Claus Gittinger <cg@exept.de>
parents:
2074
diff
changeset
|
13 |
"{ Package: 'stx:libwidg' }" |
c96b6b899023
button-roder reversal is now done exclusively in the buttonPanel
Claus Gittinger <cg@exept.de>
parents:
2074
diff
changeset
|
14 |
|
0 | 15 |
WarningBox subclass:#YesNoBox |
253
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
16 |
instanceVariableNames:'' |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
17 |
classVariableNames:'RequestBitmap' |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
18 |
poolDictionaries:'' |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
19 |
category:'Views-DialogBoxes' |
0 | 20 |
! |
21 |
||
856 | 22 |
!YesNoBox class methodsFor:'documentation'! |
38 | 23 |
|
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
59 | 27 |
All Rights Reserved |
38 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
38 |
documentation |
|
39 |
" |
|
355 | 40 |
Historic note: |
41 |
originally, ST/X had separate classes for the various entry methods; |
|
42 |
there were YesNoBox, EnterBox, InfoBox and so on. |
|
43 |
In the meantime, the DialogBox class (and therefore its alias: Dialog) |
|
44 |
is going to duplicate most funcionality found in these classes. |
|
45 |
||
46 |
In the future, those existing subclasses' functionality is going to |
|
47 |
be moved fully into Dialog, and the subclasses will be replaced by dummy |
|
48 |
delegators. (They will be kept for backward compatibility, though). |
|
49 |
||
949 | 50 |
New applications should use corresponding confirmation |
51 |
methods from DialogBox. |
|
355 | 52 |
|
38 | 53 |
this class implements yes-no boxes by adding another (no-) Button to the WarnBox-View. |
54 |
They are created with: |
|
55 |
||
355 | 56 |
aBox := YesNoBox title:'some title'. |
57 |
aBox okAction:[ .. some action to be performed when ok is pressed ]. |
|
38 | 58 |
|
59 |
and finally shown with: |
|
0 | 60 |
|
355 | 61 |
aBox showAtPointer |
38 | 62 |
|
63 |
The default box shows 'yes' and 'no' in its buttons; this can be changed with: |
|
64 |
||
355 | 65 |
aBox yesText:'some string'. |
66 |
aBox noText:'some string'. |
|
38 | 67 |
|
68 |
There is also protocol to set both button titles in one message. |
|
69 |
Also, the action associated to the noButton can be changed. |
|
70 |
||
63 | 71 |
For very simple yes/no queries, you can also use the much simpler confirm:. |
72 |
Since implemented in Object, everyone understands confirm. You can pass |
|
73 |
a question message (but not change the buttons labels). |
|
74 |
Use is: |
|
355 | 75 |
self confirm:'some question' |
63 | 76 |
and will return true or false. |
125 | 77 |
|
78 |
For compatibility with ST-80, use: |
|
355 | 79 |
Dialog confirm:'hello' |
585 | 80 |
|
81 |
[see also:] |
|
82 |
DialogBox |
|
83 |
EnterBox |
|
84 |
||
85 |
[author:] |
|
86 |
Claus Gittinger |
|
87 |
||
63 | 88 |
" |
89 |
! |
|
90 |
||
91 |
examples |
|
92 |
" |
|
38 | 93 |
Examples: |
593 | 94 |
[exBegin] |
95 |
|aBox| |
|
38 | 96 |
|
593 | 97 |
aBox := YesNoBox title:'Coffee or tee ?'. |
98 |
aBox noText:'tee'. |
|
99 |
aBox yesText:'coffee'. |
|
655 | 100 |
aBox yesAction:[Transcript showCR:'make coffee']. |
101 |
aBox noAction:[Transcript showCR:'make tee']. |
|
593 | 102 |
aBox showAtPointer. |
103 |
[exEnd] |
|
38 | 104 |
or, shorter: |
593 | 105 |
[exBegin] |
106 |
|aBox| |
|
38 | 107 |
|
593 | 108 |
aBox := YesNoBox new. |
109 |
aBox title:'Coffee or Tee ?' |
|
655 | 110 |
yesAction:[Transcript showCR:'make coffee'] |
111 |
noAction:[Transcript showCR:'make tee']. |
|
593 | 112 |
aBox yesText:'Coffee' noText:'Tee'. |
113 |
aBox showAtPointer |
|
114 |
[exEnd] |
|
38 | 115 |
|
116 |
Also, have a look at the inherited protocol; for example, this allows changing |
|
117 |
the bitmap (default: a question mark) and other properties. |
|
59 | 118 |
|
119 |
If the box is needed to ask for a simple boolean, you can also use the |
|
120 |
#confirm method, to bring up a box, let it ask for something and return |
|
121 |
true or false. |
|
122 |
Example: |
|
593 | 123 |
[exBegin] |
124 |
|box value| |
|
59 | 125 |
|
593 | 126 |
box := YesNoBox new. |
127 |
value := box confirm:'yes or no:'. |
|
128 |
value ifTrue:[ |
|
655 | 129 |
Transcript showCR:'yes' |
593 | 130 |
] ifFalse:[ |
655 | 131 |
Transcript showCR:'no' |
593 | 132 |
] |
133 |
[exEnd] |
|
59 | 134 |
|
135 |
of course, this can also be written shorter as: |
|
593 | 136 |
[exBegin] |
137 |
(YesNoBox new confirm:'yes or no:') ifTrue:[ |
|
655 | 138 |
Transcript showCR:'yes' |
593 | 139 |
] ifFalse:[ |
655 | 140 |
Transcript showCR:'no' |
593 | 141 |
] |
142 |
[exEnd] |
|
125 | 143 |
or: |
593 | 144 |
[exBegin] |
145 |
(Dialog confirm:'yes or no:') ifTrue:[ |
|
655 | 146 |
Transcript showCR:'yes' |
593 | 147 |
] ifFalse:[ |
655 | 148 |
Transcript showCR:'no' |
593 | 149 |
] |
150 |
[exEnd] |
|
38 | 151 |
" |
152 |
! ! |
|
0 | 153 |
|
856 | 154 |
!YesNoBox class methodsFor:'instance creation'! |
59 | 155 |
|
1187 | 156 |
title:titleString yesText:yesString noText:noString |
572 | 157 |
"return a new YesNoBox with title, and buttonLabels yesString/noString" |
158 |
||
1187 | 159 |
^ (self new) title:titleString yesText:yesString noText:noString |
572 | 160 |
|
1187 | 161 |
"Modified: 11.4.1997 / 21:11:45 / cg" |
59 | 162 |
! ! |
163 |
||
856 | 164 |
!YesNoBox class methodsFor:'icon bitmap'! |
59 | 165 |
|
166 |
iconBitmap |
|
1173
86440dfaca06
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
949
diff
changeset
|
167 |
"return the bitmap shown as icon in my instances. |
86440dfaca06
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
949
diff
changeset
|
168 |
This is the default image; you can overwrite this in a concrete |
1187 | 169 |
instance with the #image: message." |
59 | 170 |
|
1365 | 171 |
<resource: #style (#'requestBox.icon' #'requestBox.iconFile')> |
1173
86440dfaca06
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
949
diff
changeset
|
172 |
|
86440dfaca06
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
949
diff
changeset
|
173 |
|img imgFileName| |
943 | 174 |
|
59 | 175 |
RequestBitmap isNil ifTrue:[ |
1365 | 176 |
img := StyleSheet at:'requestBox.icon'. |
943 | 177 |
img notNil ifTrue:[ |
1173
86440dfaca06
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
949
diff
changeset
|
178 |
RequestBitmap := img |
86440dfaca06
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
949
diff
changeset
|
179 |
] ifFalse:[ |
1365 | 180 |
imgFileName := StyleSheet at:'requestBox.iconFile' default:'bitmaps/Request.xbm'. |
2074 | 181 |
RequestBitmap := Smalltalk imageFromFileNamed:imgFileName forClass:self. |
943 | 182 |
]. |
1173
86440dfaca06
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
949
diff
changeset
|
183 |
RequestBitmap notNil ifTrue:[ |
1987 | 184 |
RequestBitmap := RequestBitmap onDevice:Display |
1173
86440dfaca06
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
949
diff
changeset
|
185 |
] |
59 | 186 |
]. |
187 |
^ RequestBitmap |
|
943 | 188 |
|
1365 | 189 |
"Created: / 17.11.1995 / 18:16:47 / cg" |
190 |
"Modified: / 26.10.1997 / 17:06:19 / cg" |
|
59 | 191 |
! ! |
192 |
||
856 | 193 |
!YesNoBox class methodsFor:'styles'! |
197 | 194 |
|
195 |
updateStyleCache |
|
1173
86440dfaca06
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
949
diff
changeset
|
196 |
"extract values from the styleSheet and cache them in class variables. |
86440dfaca06
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
949
diff
changeset
|
197 |
Here, the cached infoBitmap is simply flushed." |
197 | 198 |
|
1173
86440dfaca06
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
949
diff
changeset
|
199 |
RequestBitmap := nil |
444
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
373
diff
changeset
|
200 |
|
1173
86440dfaca06
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
949
diff
changeset
|
201 |
"Modified: 1.4.1997 / 14:51:30 / cg" |
197 | 202 |
! ! |
203 |
||
0 | 204 |
!YesNoBox methodsFor:'initialization'! |
205 |
||
206 |
initialize |
|
1760
631f902aaabe
care for styleSheets right-to-left button order.
Claus Gittinger <cg@exept.de>
parents:
1365
diff
changeset
|
207 |
<resource: #style (#'dialogBox.okAtLeft')> |
631f902aaabe
care for styleSheets right-to-left button order.
Claus Gittinger <cg@exept.de>
parents:
1365
diff
changeset
|
208 |
|
0 | 209 |
super initialize. |
210 |
||
150 | 211 |
label := resources string:'Choose'. |
79 | 212 |
|
130 | 213 |
buttonPanel horizontalLayout:#fitSpace. "/ looks better; should it come from the StyleSheet ? |
63 | 214 |
|
2428 | 215 |
textLabel label:(resources string:'Please confirm'). |
216 |
okButton label:(resources string:'Yes'). |
|
0 | 217 |
|
162 | 218 |
abortButton := Button abortButton. |
2304
c96b6b899023
button-roder reversal is now done exclusively in the buttonPanel
Claus Gittinger <cg@exept.de>
parents:
2074
diff
changeset
|
219 |
|
c96b6b899023
button-roder reversal is now done exclusively in the buttonPanel
Claus Gittinger <cg@exept.de>
parents:
2074
diff
changeset
|
220 |
"/ changed: |
c96b6b899023
button-roder reversal is now done exclusively in the buttonPanel
Claus Gittinger <cg@exept.de>
parents:
2074
diff
changeset
|
221 |
"/ now exclusively done by the buttonPanel itself |
c96b6b899023
button-roder reversal is now done exclusively in the buttonPanel
Claus Gittinger <cg@exept.de>
parents:
2074
diff
changeset
|
222 |
|
c96b6b899023
button-roder reversal is now done exclusively in the buttonPanel
Claus Gittinger <cg@exept.de>
parents:
2074
diff
changeset
|
223 |
"/ (styleSheet at:'dialogBox.okAtLeft' default:false) ifTrue:[ |
c96b6b899023
button-roder reversal is now done exclusively in the buttonPanel
Claus Gittinger <cg@exept.de>
parents:
2074
diff
changeset
|
224 |
"/ buttonPanel addSubView:abortButton after:okButton. |
c96b6b899023
button-roder reversal is now done exclusively in the buttonPanel
Claus Gittinger <cg@exept.de>
parents:
2074
diff
changeset
|
225 |
"/ ] ifFalse:[ |
c96b6b899023
button-roder reversal is now done exclusively in the buttonPanel
Claus Gittinger <cg@exept.de>
parents:
2074
diff
changeset
|
226 |
"/ buttonPanel addSubView:abortButton before:okButton. |
c96b6b899023
button-roder reversal is now done exclusively in the buttonPanel
Claus Gittinger <cg@exept.de>
parents:
2074
diff
changeset
|
227 |
"/ ]. |
c96b6b899023
button-roder reversal is now done exclusively in the buttonPanel
Claus Gittinger <cg@exept.de>
parents:
2074
diff
changeset
|
228 |
buttonPanel addSubView:abortButton before:okButton. |
c96b6b899023
button-roder reversal is now done exclusively in the buttonPanel
Claus Gittinger <cg@exept.de>
parents:
2074
diff
changeset
|
229 |
|
2428 | 230 |
abortButton label:(resources string:'No'). |
162 | 231 |
abortButton height:(okButton height). |
232 |
abortButton model:self; change:#noPressed |
|
856 | 233 |
|
946 | 234 |
"Modified: 15.1.1997 / 23:32:21 / cg" |
197 | 235 |
! ! |
236 |
||
237 |
!YesNoBox methodsFor:'queries'! |
|
238 |
||
239 |
preferredExtent |
|
572 | 240 |
"compute the boxes preferredExtent from the components' sizes" |
241 |
||
373 | 242 |
|w h max mm| |
243 |
||
796 | 244 |
"/ If I have an explicit preferredExtent .. |
245 |
||
713
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
246 |
preferredExtent notNil ifTrue:[ |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
247 |
^ preferredExtent |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
248 |
]. |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
249 |
|
373 | 250 |
mm := ViewSpacing. |
79 | 251 |
|
197 | 252 |
" |
253 |
make the two buttons of equal size |
|
254 |
" |
|
255 |
max := okButton preferredExtent x max:abortButton preferredExtent x. |
|
256 |
okButton width:max. |
|
257 |
abortButton width:max. |
|
373 | 258 |
|
197 | 259 |
w := (formLabel width + textLabel width) max:max * 2. |
373 | 260 |
w := w + (3 * mm) + (okButton borderWidth + abortButton borderWidth * 2). |
261 |
h := (mm * 5) |
|
262 |
+ ((formLabel height) max:(textLabel height)) |
|
263 |
+ okButton heightIncludingBorder. |
|
197 | 264 |
|
265 |
^ (w @ h). |
|
373 | 266 |
|
796 | 267 |
"Modified: 19.7.1996 / 20:45:53 / cg" |
59 | 268 |
! ! |
38 | 269 |
|
59 | 270 |
!YesNoBox methodsFor:'startup'! |
271 |
||
272 |
confirm |
|
273 |
"open the receiver and return true for yes, false for no. |
|
274 |
This is an easier interface to use, since no action blocks |
|
275 |
have to be defined. The title is used as previously defined." |
|
38 | 276 |
|
59 | 277 |
self yesAction:[^ true] noAction:[^ false]. |
63 | 278 |
self showAtPointer. |
279 |
self yesAction:nil noAction:nil. "/ clear actions for earlier release of context |
|
38 | 280 |
|
59 | 281 |
" |
282 |
YesNoBox new confirm |
|
283 |
" |
|
0 | 284 |
! |
285 |
||
59 | 286 |
confirm:aString |
287 |
"open the receiver and return true for yes, false for no. |
|
288 |
This is an easier interface to use, since no action blocks |
|
289 |
have to be defined." |
|
38 | 290 |
|
59 | 291 |
self title:aString. |
292 |
^ self confirm |
|
293 |
||
294 |
" |
|
295 |
YesNoBox new confirm:'really ?' |
|
253
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
296 |
YesNoBox confirm:'really ?' |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
297 |
self confirm:'really ?' |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
298 |
|
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
299 |
for ST-80 compatibility, you should use Dialogs confirm |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
300 |
(which simply forwards the request to the YesNoBox anyway): |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
301 |
|
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
302 |
Dialog confirm:'really ?' |
59 | 303 |
" |
253
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
304 |
|
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
305 |
"Modified: 13.12.1995 / 16:20:01 / cg" |
0 | 306 |
! ! |
307 |
||
308 |
!YesNoBox methodsFor:'user interaction'! |
|
309 |
||
310 |
noPressed |
|
311 |
"user pressed the no-button; |
|
312 |
hide myself and evaluate the action" |
|
313 |
||
162 | 314 |
abortButton turnOffWithoutRedraw. |
315 |
self hideAndEvaluate:abortAction |
|
0 | 316 |
! ! |
317 |
||
856 | 318 |
!YesNoBox class methodsFor:'documentation'! |
243 | 319 |
|
320 |
version |
|
2428 | 321 |
^ '$Header: /cvs/stx/stx/libwidg/YesNoBox.st,v 1.47 2001-10-04 17:26:48 cg Exp $' |
243 | 322 |
! ! |