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