author | Claus Gittinger <cg@exept.de> |
Thu, 24 Aug 2006 11:24:48 +0200 | |
changeset 3356 | 4a1ab6d0be69 |
parent 3121 | 8e4d21e008c9 |
child 3616 | d77444e898db |
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 |
" |
|
2467
82d16b9ea94d
confirmBox icon (windows only)
Claus Gittinger <cg@exept.de>
parents:
2428
diff
changeset
|
93 |
Notice, the preferred use is via the DialogBox class messages, |
82d16b9ea94d
confirmBox icon (windows only)
Claus Gittinger <cg@exept.de>
parents:
2428
diff
changeset
|
94 |
such as |
82d16b9ea94d
confirmBox icon (windows only)
Claus Gittinger <cg@exept.de>
parents:
2428
diff
changeset
|
95 |
[exBegin] |
82d16b9ea94d
confirmBox icon (windows only)
Claus Gittinger <cg@exept.de>
parents:
2428
diff
changeset
|
96 |
Dialog confirm:'Coffee ?' |
82d16b9ea94d
confirmBox icon (windows only)
Claus Gittinger <cg@exept.de>
parents:
2428
diff
changeset
|
97 |
Dialog confirmWithCancel:'Coffee ?' |
82d16b9ea94d
confirmBox icon (windows only)
Claus Gittinger <cg@exept.de>
parents:
2428
diff
changeset
|
98 |
[exEnd] |
82d16b9ea94d
confirmBox icon (windows only)
Claus Gittinger <cg@exept.de>
parents:
2428
diff
changeset
|
99 |
these (DialogBox) mesages are compatible with VW and should therefore |
82d16b9ea94d
confirmBox icon (windows only)
Claus Gittinger <cg@exept.de>
parents:
2428
diff
changeset
|
100 |
be used for portability. |
82d16b9ea94d
confirmBox icon (windows only)
Claus Gittinger <cg@exept.de>
parents:
2428
diff
changeset
|
101 |
|
82d16b9ea94d
confirmBox icon (windows only)
Claus Gittinger <cg@exept.de>
parents:
2428
diff
changeset
|
102 |
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
|
103 |
|
82d16b9ea94d
confirmBox icon (windows only)
Claus Gittinger <cg@exept.de>
parents:
2428
diff
changeset
|
104 |
|
38 | 105 |
Examples: |
593 | 106 |
[exBegin] |
107 |
|aBox| |
|
38 | 108 |
|
593 | 109 |
aBox := YesNoBox title:'Coffee or tee ?'. |
110 |
aBox noText:'tee'. |
|
111 |
aBox yesText:'coffee'. |
|
655 | 112 |
aBox yesAction:[Transcript showCR:'make coffee']. |
113 |
aBox noAction:[Transcript showCR:'make tee']. |
|
593 | 114 |
aBox showAtPointer. |
115 |
[exEnd] |
|
38 | 116 |
or, shorter: |
593 | 117 |
[exBegin] |
118 |
|aBox| |
|
38 | 119 |
|
593 | 120 |
aBox := YesNoBox new. |
121 |
aBox title:'Coffee or Tee ?' |
|
655 | 122 |
yesAction:[Transcript showCR:'make coffee'] |
123 |
noAction:[Transcript showCR:'make tee']. |
|
593 | 124 |
aBox yesText:'Coffee' noText:'Tee'. |
125 |
aBox showAtPointer |
|
126 |
[exEnd] |
|
38 | 127 |
|
128 |
Also, have a look at the inherited protocol; for example, this allows changing |
|
129 |
the bitmap (default: a question mark) and other properties. |
|
59 | 130 |
|
131 |
If the box is needed to ask for a simple boolean, you can also use the |
|
132 |
#confirm method, to bring up a box, let it ask for something and return |
|
133 |
true or false. |
|
134 |
Example: |
|
593 | 135 |
[exBegin] |
136 |
|box value| |
|
59 | 137 |
|
593 | 138 |
box := YesNoBox new. |
139 |
value := box confirm:'yes or no:'. |
|
140 |
value ifTrue:[ |
|
655 | 141 |
Transcript showCR:'yes' |
593 | 142 |
] ifFalse:[ |
655 | 143 |
Transcript showCR:'no' |
593 | 144 |
] |
145 |
[exEnd] |
|
59 | 146 |
|
147 |
of course, this can also be written shorter as: |
|
593 | 148 |
[exBegin] |
149 |
(YesNoBox new confirm:'yes or no:') ifTrue:[ |
|
655 | 150 |
Transcript showCR:'yes' |
593 | 151 |
] ifFalse:[ |
655 | 152 |
Transcript showCR:'no' |
593 | 153 |
] |
154 |
[exEnd] |
|
125 | 155 |
or: |
593 | 156 |
[exBegin] |
157 |
(Dialog confirm:'yes or no:') ifTrue:[ |
|
655 | 158 |
Transcript showCR:'yes' |
593 | 159 |
] ifFalse:[ |
655 | 160 |
Transcript showCR:'no' |
593 | 161 |
] |
162 |
[exEnd] |
|
38 | 163 |
" |
164 |
! ! |
|
0 | 165 |
|
856 | 166 |
!YesNoBox class methodsFor:'instance creation'! |
59 | 167 |
|
1187 | 168 |
title:titleString yesText:yesString noText:noString |
572 | 169 |
"return a new YesNoBox with title, and buttonLabels yesString/noString" |
170 |
||
1187 | 171 |
^ (self new) title:titleString yesText:yesString noText:noString |
572 | 172 |
|
1187 | 173 |
"Modified: 11.4.1997 / 21:11:45 / cg" |
59 | 174 |
! ! |
175 |
||
856 | 176 |
!YesNoBox class methodsFor:'icon bitmap'! |
59 | 177 |
|
178 |
iconBitmap |
|
1173
86440dfaca06
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
949
diff
changeset
|
179 |
"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
|
180 |
This is the default image; you can overwrite this in a concrete |
1187 | 181 |
instance with the #image: message." |
59 | 182 |
|
1365 | 183 |
<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
|
184 |
|
59 | 185 |
RequestBitmap isNil ifTrue:[ |
2786 | 186 |
RequestBitmap := self iconBitmapFromStyle:'requestBox.icon' orStyleFile:'requestBox.iconFile' orFilename:'bitmaps/Request.xbm'. |
59 | 187 |
]. |
188 |
^ RequestBitmap |
|
943 | 189 |
|
1365 | 190 |
"Created: / 17.11.1995 / 18:16:47 / cg" |
191 |
"Modified: / 26.10.1997 / 17:06:19 / cg" |
|
59 | 192 |
! ! |
193 |
||
856 | 194 |
!YesNoBox class methodsFor:'styles'! |
197 | 195 |
|
196 |
updateStyleCache |
|
1173
86440dfaca06
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
949
diff
changeset
|
197 |
"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
|
198 |
Here, the cached infoBitmap is simply flushed." |
197 | 199 |
|
1173
86440dfaca06
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
949
diff
changeset
|
200 |
RequestBitmap := nil |
444
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
373
diff
changeset
|
201 |
|
1173
86440dfaca06
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
949
diff
changeset
|
202 |
"Modified: 1.4.1997 / 14:51:30 / cg" |
197 | 203 |
! ! |
204 |
||
0 | 205 |
!YesNoBox methodsFor:'initialization'! |
206 |
||
207 |
initialize |
|
208 |
super initialize. |
|
209 |
||
150 | 210 |
label := resources string:'Choose'. |
79 | 211 |
|
130 | 212 |
buttonPanel horizontalLayout:#fitSpace. "/ looks better; should it come from the StyleSheet ? |
63 | 213 |
|
2428 | 214 |
textLabel label:(resources string:'Please confirm'). |
215 |
okButton label:(resources string:'Yes'). |
|
0 | 216 |
|
162 | 217 |
abortButton := Button abortButton. |
2304
c96b6b899023
button-roder reversal is now done exclusively in the buttonPanel
Claus Gittinger <cg@exept.de>
parents:
2074
diff
changeset
|
218 |
|
c96b6b899023
button-roder reversal is now done exclusively in the buttonPanel
Claus Gittinger <cg@exept.de>
parents:
2074
diff
changeset
|
219 |
"/ changed: |
c96b6b899023
button-roder reversal is now done exclusively in the buttonPanel
Claus Gittinger <cg@exept.de>
parents:
2074
diff
changeset
|
220 |
"/ 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
|
221 |
|
2698 | 222 |
"/ (Dialog defaultOKButtonAtLeft) ifTrue:[ |
2304
c96b6b899023
button-roder reversal is now done exclusively in the buttonPanel
Claus Gittinger <cg@exept.de>
parents:
2074
diff
changeset
|
223 |
"/ 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
|
224 |
"/ ] ifFalse:[ |
c96b6b899023
button-roder reversal is now done exclusively in the buttonPanel
Claus Gittinger <cg@exept.de>
parents:
2074
diff
changeset
|
225 |
"/ 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
|
226 |
"/ ]. |
c96b6b899023
button-roder reversal is now done exclusively in the buttonPanel
Claus Gittinger <cg@exept.de>
parents:
2074
diff
changeset
|
227 |
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
|
228 |
|
2428 | 229 |
abortButton label:(resources string:'No'). |
162 | 230 |
abortButton height:(okButton height). |
231 |
abortButton model:self; change:#noPressed |
|
856 | 232 |
|
946 | 233 |
"Modified: 15.1.1997 / 23:32:21 / cg" |
197 | 234 |
! ! |
235 |
||
236 |
!YesNoBox methodsFor:'queries'! |
|
237 |
||
3121 | 238 |
beepWhenOpening |
239 |
^ false |
|
240 |
! |
|
241 |
||
197 | 242 |
preferredExtent |
572 | 243 |
"compute the boxes preferredExtent from the components' sizes" |
244 |
||
373 | 245 |
|w h max mm| |
246 |
||
796 | 247 |
"/ If I have an explicit preferredExtent .. |
248 |
||
713
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
249 |
preferredExtent notNil ifTrue:[ |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
250 |
^ preferredExtent |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
251 |
]. |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
252 |
|
373 | 253 |
mm := ViewSpacing. |
79 | 254 |
|
197 | 255 |
" |
256 |
make the two buttons of equal size |
|
257 |
" |
|
258 |
max := okButton preferredExtent x max:abortButton preferredExtent x. |
|
259 |
okButton width:max. |
|
260 |
abortButton width:max. |
|
373 | 261 |
|
197 | 262 |
w := (formLabel width + textLabel width) max:max * 2. |
373 | 263 |
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
|
264 |
w := w max:self maxPreferredWidthOfAddedComponents. |
2800
25f261040a9a
allow adding a (single) checkBox
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
265 |
|
373 | 266 |
h := (mm * 5) |
267 |
+ ((formLabel height) max:(textLabel height)) |
|
2800
25f261040a9a
allow adding a (single) checkBox
Claus Gittinger <cg@exept.de>
parents:
2786
diff
changeset
|
268 |
+ ((addedComponents ? #()) inject:0 into:[:sum :thisComponent | sum + thisComponent preferredExtent y]) |
373 | 269 |
+ okButton heightIncludingBorder. |
197 | 270 |
|
271 |
^ (w @ h). |
|
373 | 272 |
|
796 | 273 |
"Modified: 19.7.1996 / 20:45:53 / cg" |
59 | 274 |
! ! |
38 | 275 |
|
59 | 276 |
!YesNoBox methodsFor:'startup'! |
277 |
||
278 |
confirm |
|
279 |
"open the receiver and return true for yes, false for no. |
|
280 |
This is an easier interface to use, since no action blocks |
|
281 |
have to be defined. The title is used as previously defined." |
|
38 | 282 |
|
59 | 283 |
self yesAction:[^ true] noAction:[^ false]. |
63 | 284 |
self showAtPointer. |
285 |
self yesAction:nil noAction:nil. "/ clear actions for earlier release of context |
|
38 | 286 |
|
59 | 287 |
" |
288 |
YesNoBox new confirm |
|
289 |
" |
|
0 | 290 |
! |
291 |
||
59 | 292 |
confirm:aString |
3356 | 293 |
"open a modal yes-no dialog. |
294 |
Return true for yes, false for no. |
|
295 |
This is an easier interface to use, since no action blocks have to be defined." |
|
38 | 296 |
|
59 | 297 |
self title:aString. |
298 |
^ self confirm |
|
299 |
||
300 |
" |
|
301 |
YesNoBox new confirm:'really ?' |
|
253
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
302 |
YesNoBox confirm:'really ?' |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
303 |
self confirm:'really ?' |
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 |
for ST-80 compatibility, you should use Dialogs confirm |
f071ff350cd5
added confirm with button-labels
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
306 |
(which simply forwards the request to the YesNoBox anyway): |
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 |
Dialog confirm:'really ?' |
59 | 309 |
" |
253
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 |
"Modified: 13.12.1995 / 16:20:01 / cg" |
0 | 312 |
! ! |
313 |
||
314 |
!YesNoBox methodsFor:'user interaction'! |
|
315 |
||
316 |
noPressed |
|
317 |
"user pressed the no-button; |
|
318 |
hide myself and evaluate the action" |
|
319 |
||
162 | 320 |
abortButton turnOffWithoutRedraw. |
321 |
self hideAndEvaluate:abortAction |
|
0 | 322 |
! ! |
323 |
||
856 | 324 |
!YesNoBox class methodsFor:'documentation'! |
243 | 325 |
|
326 |
version |
|
3356 | 327 |
^ '$Header: /cvs/stx/stx/libwidg/YesNoBox.st,v 1.56 2006-08-24 09:24:48 cg Exp $' |
243 | 328 |
! ! |