author | Claus Gittinger <cg@exept.de> |
Thu, 09 Nov 2017 20:09:30 +0100 | |
changeset 6225 | 0122e4e6c587 |
parent 6182 | 46362930b07b |
child 6331 | 08ac4c72de00 |
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 |
" |
|
2304
c96b6b899023
button-roder reversal is now done exclusively in the buttonPanel
Claus Gittinger <cg@exept.de>
parents:
2074
diff
changeset
|
12 |
"{ Package: 'stx:libwidg' }" |
c96b6b899023
button-roder reversal is now done exclusively in the buttonPanel
Claus Gittinger <cg@exept.de>
parents:
2074
diff
changeset
|
13 |
|
5895 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
0 | 16 |
WarningBox subclass:#YesNoBox |
253
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
17 |
instanceVariableNames:'' |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
18 |
classVariableNames:'RequestBitmap' |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
19 |
poolDictionaries:'' |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
20 |
category:'Views-DialogBoxes' |
0 | 21 |
! |
22 |
||
856 | 23 |
!YesNoBox class methodsFor:'documentation'! |
38 | 24 |
|
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
59 | 28 |
All Rights Reserved |
38 | 29 |
|
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
39 |
documentation |
|
40 |
" |
|
355 | 41 |
Historic note: |
42 |
originally, ST/X had separate classes for the various entry methods; |
|
43 |
there were YesNoBox, EnterBox, InfoBox and so on. |
|
44 |
In the meantime, the DialogBox class (and therefore its alias: Dialog) |
|
5895 | 45 |
is going to duplicate most functionality found in these classes. |
355 | 46 |
|
47 |
In the future, those existing subclasses' functionality is going to |
|
48 |
be moved fully into Dialog, and the subclasses will be replaced by dummy |
|
49 |
delegators. (They will be kept for backward compatibility, though). |
|
50 |
||
949 | 51 |
New applications should use corresponding confirmation |
52 |
methods from DialogBox. |
|
355 | 53 |
|
38 | 54 |
this class implements yes-no boxes by adding another (no-) Button to the WarnBox-View. |
55 |
They are created with: |
|
56 |
||
355 | 57 |
aBox := YesNoBox title:'some title'. |
58 |
aBox okAction:[ .. some action to be performed when ok is pressed ]. |
|
38 | 59 |
|
60 |
and finally shown with: |
|
0 | 61 |
|
355 | 62 |
aBox showAtPointer |
38 | 63 |
|
64 |
The default box shows 'yes' and 'no' in its buttons; this can be changed with: |
|
65 |
||
355 | 66 |
aBox yesText:'some string'. |
67 |
aBox noText:'some string'. |
|
38 | 68 |
|
69 |
There is also protocol to set both button titles in one message. |
|
70 |
Also, the action associated to the noButton can be changed. |
|
71 |
||
63 | 72 |
For very simple yes/no queries, you can also use the much simpler confirm:. |
73 |
Since implemented in Object, everyone understands confirm. You can pass |
|
74 |
a question message (but not change the buttons labels). |
|
75 |
Use is: |
|
5895 | 76 |
self confirm:'some question' |
63 | 77 |
and will return true or false. |
125 | 78 |
|
79 |
For compatibility with ST-80, use: |
|
355 | 80 |
Dialog confirm:'hello' |
585 | 81 |
|
82 |
[see also:] |
|
83 |
DialogBox |
|
84 |
EnterBox |
|
85 |
||
86 |
[author:] |
|
87 |
Claus Gittinger |
|
88 |
||
63 | 89 |
" |
90 |
! |
|
91 |
||
92 |
examples |
|
93 |
" |
|
2467
82d16b9ea94d
confirmBox icon (windows only)
Claus Gittinger <cg@exept.de>
parents:
2428
diff
changeset
|
94 |
Notice, the preferred use is via the DialogBox class messages, |
5895 | 95 |
such as |
2467
82d16b9ea94d
confirmBox icon (windows only)
Claus Gittinger <cg@exept.de>
parents:
2428
diff
changeset
|
96 |
[exBegin] |
82d16b9ea94d
confirmBox icon (windows only)
Claus Gittinger <cg@exept.de>
parents:
2428
diff
changeset
|
97 |
Dialog confirm:'Coffee ?' |
82d16b9ea94d
confirmBox icon (windows only)
Claus Gittinger <cg@exept.de>
parents:
2428
diff
changeset
|
98 |
Dialog confirmWithCancel:'Coffee ?' |
82d16b9ea94d
confirmBox icon (windows only)
Claus Gittinger <cg@exept.de>
parents:
2428
diff
changeset
|
99 |
[exEnd] |
82d16b9ea94d
confirmBox icon (windows only)
Claus Gittinger <cg@exept.de>
parents:
2428
diff
changeset
|
100 |
these (DialogBox) mesages are compatible with VW and should therefore |
82d16b9ea94d
confirmBox icon (windows only)
Claus Gittinger <cg@exept.de>
parents:
2428
diff
changeset
|
101 |
be used for portability. |
82d16b9ea94d
confirmBox icon (windows only)
Claus Gittinger <cg@exept.de>
parents:
2428
diff
changeset
|
102 |
|
82d16b9ea94d
confirmBox icon (windows only)
Claus Gittinger <cg@exept.de>
parents:
2428
diff
changeset
|
103 |
Direct reference to YesNoBox is only required for highly specialized boxes. |
82d16b9ea94d
confirmBox icon (windows only)
Claus Gittinger <cg@exept.de>
parents:
2428
diff
changeset
|
104 |
|
82d16b9ea94d
confirmBox icon (windows only)
Claus Gittinger <cg@exept.de>
parents:
2428
diff
changeset
|
105 |
|
38 | 106 |
Examples: |
593 | 107 |
[exBegin] |
108 |
|aBox| |
|
38 | 109 |
|
593 | 110 |
aBox := YesNoBox title:'Coffee or tee ?'. |
111 |
aBox noText:'tee'. |
|
112 |
aBox yesText:'coffee'. |
|
655 | 113 |
aBox yesAction:[Transcript showCR:'make coffee']. |
114 |
aBox noAction:[Transcript showCR:'make tee']. |
|
593 | 115 |
aBox showAtPointer. |
116 |
[exEnd] |
|
38 | 117 |
or, shorter: |
593 | 118 |
[exBegin] |
119 |
|aBox| |
|
38 | 120 |
|
593 | 121 |
aBox := YesNoBox new. |
5895 | 122 |
aBox title:'Coffee or Tee?' |
655 | 123 |
yesAction:[Transcript showCR:'make coffee'] |
124 |
noAction:[Transcript showCR:'make tee']. |
|
593 | 125 |
aBox yesText:'Coffee' noText:'Tee'. |
126 |
aBox showAtPointer |
|
127 |
[exEnd] |
|
38 | 128 |
|
129 |
Also, have a look at the inherited protocol; for example, this allows changing |
|
130 |
the bitmap (default: a question mark) and other properties. |
|
59 | 131 |
|
132 |
If the box is needed to ask for a simple boolean, you can also use the |
|
133 |
#confirm method, to bring up a box, let it ask for something and return |
|
5895 | 134 |
true or false. |
59 | 135 |
Example: |
593 | 136 |
[exBegin] |
137 |
|box value| |
|
59 | 138 |
|
593 | 139 |
box := YesNoBox new. |
140 |
value := box confirm:'yes or no:'. |
|
141 |
value ifTrue:[ |
|
655 | 142 |
Transcript showCR:'yes' |
593 | 143 |
] ifFalse:[ |
655 | 144 |
Transcript showCR:'no' |
593 | 145 |
] |
146 |
[exEnd] |
|
59 | 147 |
|
148 |
of course, this can also be written shorter as: |
|
593 | 149 |
[exBegin] |
150 |
(YesNoBox new confirm:'yes or no:') ifTrue:[ |
|
655 | 151 |
Transcript showCR:'yes' |
593 | 152 |
] ifFalse:[ |
655 | 153 |
Transcript showCR:'no' |
593 | 154 |
] |
155 |
[exEnd] |
|
125 | 156 |
or: |
593 | 157 |
[exBegin] |
158 |
(Dialog confirm:'yes or no:') ifTrue:[ |
|
655 | 159 |
Transcript showCR:'yes' |
593 | 160 |
] ifFalse:[ |
655 | 161 |
Transcript showCR:'no' |
593 | 162 |
] |
163 |
[exEnd] |
|
38 | 164 |
" |
165 |
! ! |
|
0 | 166 |
|
856 | 167 |
!YesNoBox class methodsFor:'instance creation'! |
59 | 168 |
|
1187 | 169 |
title:titleString yesText:yesString noText:noString |
572 | 170 |
"return a new YesNoBox with title, and buttonLabels yesString/noString" |
171 |
||
1187 | 172 |
^ (self new) title:titleString yesText:yesString noText:noString |
572 | 173 |
|
1187 | 174 |
"Modified: 11.4.1997 / 21:11:45 / cg" |
59 | 175 |
! ! |
176 |
||
856 | 177 |
!YesNoBox class methodsFor:'icon bitmap'! |
59 | 178 |
|
179 |
iconBitmap |
|
1173
86440dfaca06
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
949
diff
changeset
|
180 |
"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
|
181 |
This is the default image; you can overwrite this in a concrete |
1187 | 182 |
instance with the #image: message." |
59 | 183 |
|
1365 | 184 |
<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
|
185 |
|
59 | 186 |
RequestBitmap isNil ifTrue:[ |
2786 | 187 |
RequestBitmap := self iconBitmapFromStyle:'requestBox.icon' orStyleFile:'requestBox.iconFile' orFilename:'bitmaps/Request.xbm'. |
59 | 188 |
]. |
189 |
^ RequestBitmap |
|
943 | 190 |
|
1365 | 191 |
"Created: / 17.11.1995 / 18:16:47 / cg" |
192 |
"Modified: / 26.10.1997 / 17:06:19 / cg" |
|
59 | 193 |
! ! |
194 |
||
856 | 195 |
!YesNoBox class methodsFor:'styles'! |
197 | 196 |
|
197 |
updateStyleCache |
|
1173
86440dfaca06
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
949
diff
changeset
|
198 |
"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
|
199 |
Here, the cached infoBitmap is simply flushed." |
197 | 200 |
|
1173
86440dfaca06
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
949
diff
changeset
|
201 |
RequestBitmap := nil |
444
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
373
diff
changeset
|
202 |
|
1173
86440dfaca06
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
949
diff
changeset
|
203 |
"Modified: 1.4.1997 / 14:51:30 / cg" |
197 | 204 |
! ! |
205 |
||
0 | 206 |
!YesNoBox methodsFor:'initialization'! |
207 |
||
208 |
initialize |
|
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 |
|
2698 | 223 |
"/ (Dialog defaultOKButtonAtLeft) ifTrue:[ |
2304
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 |
||
3121 | 239 |
beepWhenOpening |
240 |
^ false |
|
241 |
! |
|
242 |
||
5895 | 243 |
preferredExtent |
572 | 244 |
"compute the boxes preferredExtent from the components' sizes" |
245 |
||
373 | 246 |
|w h max mm| |
247 |
||
3766
4f421cb433d6
changed #preferredExtent - use explicitExtent instvar
Stefan Vogel <sv@exept.de>
parents:
3616
diff
changeset
|
248 |
"/ If I have an explicit preferredExtent.. |
4f421cb433d6
changed #preferredExtent - use explicitExtent instvar
Stefan Vogel <sv@exept.de>
parents:
3616
diff
changeset
|
249 |
explicitExtent notNil ifTrue:[ |
4f421cb433d6
changed #preferredExtent - use explicitExtent instvar
Stefan Vogel <sv@exept.de>
parents:
3616
diff
changeset
|
250 |
^ explicitExtent |
4f421cb433d6
changed #preferredExtent - use explicitExtent instvar
Stefan Vogel <sv@exept.de>
parents:
3616
diff
changeset
|
251 |
]. |
796 | 252 |
|
3766
4f421cb433d6
changed #preferredExtent - use explicitExtent instvar
Stefan Vogel <sv@exept.de>
parents:
3616
diff
changeset
|
253 |
"/ If I have a cached preferredExtent value.. |
713
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
254 |
preferredExtent notNil ifTrue:[ |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
255 |
^ preferredExtent |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
256 |
]. |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
257 |
|
373 | 258 |
mm := ViewSpacing. |
79 | 259 |
|
197 | 260 |
" |
261 |
make the two buttons of equal size |
|
262 |
" |
|
3616
d77444e898db
added preferredWidth & preferredHeight
Claus Gittinger <cg@exept.de>
parents:
3356
diff
changeset
|
263 |
max := okButton preferredWidth max:abortButton preferredWidth. |
197 | 264 |
okButton width:max. |
265 |
abortButton width:max. |
|
373 | 266 |
|
6174 | 267 |
w := (formLabel width + textLabel width) max:(max * 2). |
5967 | 268 |
w := w + (3 * mm) + ((okButton borderWidth + abortButton borderWidth) * 2). |
2802
19b141dd52b9
fixed preferredWidth when components were added
Claus Gittinger <cg@exept.de>
parents:
2800
diff
changeset
|
269 |
w := w max:self maxPreferredWidthOfAddedComponents. |
2800
25f261040a9a
allow adding a (single) checkBox
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
270 |
|
373 | 271 |
h := (mm * 5) |
272 |
+ ((formLabel height) max:(textLabel height)) |
|
3616
d77444e898db
added preferredWidth & preferredHeight
Claus Gittinger <cg@exept.de>
parents:
3356
diff
changeset
|
273 |
+ ((addedComponents ? #()) inject:0 into:[:sum :thisComponent | sum + thisComponent preferredHeight]) |
373 | 274 |
+ okButton heightIncludingBorder. |
197 | 275 |
|
276 |
^ (w @ h). |
|
373 | 277 |
|
5967 | 278 |
"Modified: / 19-07-1996 / 20:45:53 / cg" |
6174 | 279 |
"Modified (format): / 20-06-2017 / 10:37:44 / cg" |
59 | 280 |
! ! |
38 | 281 |
|
59 | 282 |
!YesNoBox methodsFor:'startup'! |
283 |
||
284 |
confirm |
|
285 |
"open the receiver and return true for yes, false for no. |
|
286 |
This is an easier interface to use, since no action blocks |
|
287 |
have to be defined. The title is used as previously defined." |
|
38 | 288 |
|
59 | 289 |
self yesAction:[^ true] noAction:[^ false]. |
63 | 290 |
self showAtPointer. |
291 |
self yesAction:nil noAction:nil. "/ clear actions for earlier release of context |
|
6182 | 292 |
"/ not reached |
293 |
^ false |
|
294 |
||
59 | 295 |
" |
296 |
YesNoBox new confirm |
|
297 |
" |
|
6182 | 298 |
|
299 |
"Modified (comment): / 16-07-2017 / 14:03:23 / cg" |
|
0 | 300 |
! |
301 |
||
59 | 302 |
confirm:aString |
3356 | 303 |
"open a modal yes-no dialog. |
304 |
Return true for yes, false for no. |
|
305 |
This is an easier interface to use, since no action blocks have to be defined." |
|
38 | 306 |
|
59 | 307 |
self title:aString. |
308 |
^ self confirm |
|
309 |
||
310 |
" |
|
5895 | 311 |
YesNoBox new confirm:'really?' |
312 |
YesNoBox confirm:'really?' |
|
313 |
self confirm:'really?' |
|
253
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
314 |
|
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
315 |
for ST-80 compatibility, you should use Dialogs confirm |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
316 |
(which simply forwards the request to the YesNoBox anyway): |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
317 |
|
5895 | 318 |
Dialog confirm:'really?' |
59 | 319 |
" |
253
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
320 |
|
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
321 |
"Modified: 13.12.1995 / 16:20:01 / cg" |
0 | 322 |
! ! |
323 |
||
324 |
!YesNoBox methodsFor:'user interaction'! |
|
325 |
||
326 |
noPressed |
|
327 |
"user pressed the no-button; |
|
328 |
hide myself and evaluate the action" |
|
329 |
||
162 | 330 |
abortButton turnOffWithoutRedraw. |
331 |
self hideAndEvaluate:abortAction |
|
0 | 332 |
! ! |
333 |
||
856 | 334 |
!YesNoBox class methodsFor:'documentation'! |
243 | 335 |
|
336 |
version |
|
5895 | 337 |
^ '$Header$' |
243 | 338 |
! ! |
5895 | 339 |