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