author | Claus Gittinger <cg@exept.de> |
Mon, 18 Aug 2003 19:13:54 +0200 | |
changeset 2785 | ac6eb18aa58e |
parent 2474 | c297943dc3d7 |
child 2786 | 06de7ca4b263 |
permissions | -rw-r--r-- |
0 | 1 |
" |
2 |
COPYRIGHT (c) 1993 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 |
||
2362
f6ace7307e4d
examples fixed (bitmaps access)
Claus Gittinger <cg@exept.de>
parents:
2073
diff
changeset
|
13 |
"{ Package: 'stx:libwidg' }" |
f6ace7307e4d
examples fixed (bitmaps access)
Claus Gittinger <cg@exept.de>
parents:
2073
diff
changeset
|
14 |
|
0 | 15 |
InfoBox subclass:#WarningBox |
355 | 16 |
instanceVariableNames:'' |
2474 | 17 |
classVariableNames:'WarnBitmap ErrorBitmap' |
355 | 18 |
poolDictionaries:'' |
19 |
category:'Views-DialogBoxes' |
|
0 | 20 |
! |
21 |
||
38 | 22 |
!WarningBox class methodsFor:'documentation'! |
23 |
||
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1993 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 |
||
2468 | 46 |
In the future, those existing subclasses' functionality might |
47 |
be moved fully into Dialog, and the subclasses be replaced by dummy |
|
355 | 48 |
delegators. (They will be kept for backward compatibility, though). |
49 |
||
50 |
||
51 |
||
38 | 52 |
this class implements a pop-up box to show an information message. |
53 |
WarningBoxes are basically InfoBoxes with a different bitmap-image. |
|
54 |
(also, they add a beep when popping up) |
|
55 |
||
56 |
They are created with: |
|
57 |
||
355 | 58 |
aBox := WarningBox title:'some title'. |
38 | 59 |
|
60 |
and shown with: |
|
61 |
||
355 | 62 |
aBox showAtPointer |
38 | 63 |
|
64 |
The default box shows 'yes' in its button; this can be changed with: |
|
65 |
||
355 | 66 |
aBox okText:'some string'. |
38 | 67 |
|
79 | 68 |
Since showing warnings is a common action, a convenient method has been |
69 |
added to Object; thus you can use: |
|
70 |
||
355 | 71 |
self warn:'oops - headcrash' |
79 | 72 |
|
73 |
everywhere in your code. |
|
585 | 74 |
|
75 |
[see also:] |
|
76 |
DialogBox InfoBox YesNoBox |
|
77 |
( introduction to view programming :html: programming/viewintro.html ) |
|
78 |
||
79 |
[author:] |
|
80 |
Claus Gittinger |
|
63 | 81 |
" |
82 |
! |
|
38 | 83 |
|
63 | 84 |
examples |
85 |
" |
|
2468 | 86 |
Notice, the preferred use is via the DialogBox class messages, |
87 |
such as |
|
88 |
[exBegin] |
|
2469 | 89 |
Dialog warn:'Attention !!' |
2468 | 90 |
[exEnd] |
91 |
these (DialogBox) mesages are compatible with VW and should therefore |
|
92 |
be used for portability. |
|
93 |
||
94 |
Direct reference to WarnBox is only required for highly specialized boxes. |
|
95 |
||
96 |
||
644 | 97 |
standard warning dialogs |
98 |
(recommended, since these are ST-80 compatible interfaces) |
|
99 |
[exBegin] |
|
100 |
Dialog warn:'you should not do this' |
|
101 |
[exEnd] |
|
102 |
since all objects support the #warn message, |
|
103 |
you can also simply use (for any self): |
|
104 |
[exBegin] |
|
105 |
self warn:'you should not do this' |
|
106 |
[exEnd] |
|
107 |
||
108 |
with attributed text: |
|
109 |
[exBegin] |
|
110 |
Dialog warn:(Text string:'you should not do this' |
|
111 |
emphasis:#color->Color red) |
|
112 |
[exEnd] |
|
113 |
||
114 |
specifying more details of the warnBox (low level entries). |
|
115 |
label of OK-button: |
|
593 | 116 |
[exBegin] |
117 |
|aBox| |
|
38 | 118 |
|
593 | 119 |
aBox := WarningBox title:'Press ''OK'' to continue'. |
120 |
aBox okText:'OK'. |
|
121 |
aBox showAtPointer. |
|
122 |
[exEnd] |
|
644 | 123 |
|
124 |
accessing the ok-Button component and changing its color: |
|
125 |
[exBegin] |
|
126 |
|aBox| |
|
127 |
||
128 |
aBox := WarningBox title:'Do you really want to do this ?'. |
|
129 |
aBox okText:'yes, go on'. |
|
130 |
aBox okButton foregroundColor:Color red. |
|
131 |
aBox showAtPointer. |
|
132 |
[exEnd] |
|
79 | 133 |
since warnboxes are much like infoBoxes, all of look can be changed |
134 |
like described there: |
|
593 | 135 |
[exBegin] |
644 | 136 |
|image aBox| |
79 | 137 |
|
593 | 138 |
aBox := WarningBox title:'Press ''OK'' to continue'. |
139 |
aBox okText:'yes, continue'. |
|
2362
f6ace7307e4d
examples fixed (bitmaps access)
Claus Gittinger <cg@exept.de>
parents:
2073
diff
changeset
|
140 |
image := Image fromFile:'bitmaps/SmalltalkX.xbm' inPackage:'stx:libtool'. |
644 | 141 |
aBox form:image. |
593 | 142 |
aBox showAtPointer. |
143 |
[exEnd] |
|
38 | 144 |
" |
59 | 145 |
! ! |
146 |
||
147 |
!WarningBox class methodsFor:'icon bitmap'! |
|
148 |
||
2474 | 149 |
errorIconBitmap |
150 |
"return the bitmap shown as icon in my instances. |
|
151 |
This is the default image; you can overwrite this in a concrete |
|
152 |
instance with the image: message" |
|
153 |
||
154 |
<resource: #style (#'errorBox.icon' #'errorBox.iconFile')> |
|
155 |
||
156 |
|img imgFileName| |
|
157 |
||
158 |
ErrorBitmap isNil ifTrue:[ |
|
2785 | 159 |
img := self styleSheet at:'errorBox.icon'. |
2474 | 160 |
img isNil ifTrue:[ |
161 |
imgFileName := StyleSheet at:'errorBox.iconFile' default:'bitmaps/Error.xbm'. |
|
162 |
img := Smalltalk imageFromFileNamed:imgFileName forClass:self. |
|
163 |
]. |
|
164 |
img notNil ifTrue:[ |
|
165 |
img := img onDevice:Display |
|
166 |
]. |
|
167 |
img isNil ifTrue:[ |
|
168 |
img := self warnIconBitmap. |
|
169 |
]. |
|
170 |
ErrorBitmap := img |
|
171 |
]. |
|
172 |
^ ErrorBitmap |
|
173 |
||
174 |
" |
|
175 |
|box| |
|
176 |
||
177 |
box := WarningBox title:'foo bar'. |
|
178 |
box image:(WarningBox errorIconBitmap). |
|
179 |
box showAtPointer. |
|
180 |
" |
|
181 |
||
182 |
"Created: / 17.11.1995 / 18:16:47 / cg" |
|
183 |
"Modified: / 16.11.2001 / 15:02:54 / cg" |
|
184 |
! |
|
185 |
||
59 | 186 |
iconBitmap |
184 | 187 |
"return the bitmap shown as icon in my instances. |
188 |
This is the default image; you can overwrite this in a concrete |
|
189 |
instance with the image: message" |
|
59 | 190 |
|
2474 | 191 |
^ self warnIconBitmap |
192 |
||
193 |
" |
|
194 |
self warn:'foo bar'. |
|
195 |
||
196 |
|box| |
|
197 |
box := WarningBox title:'foo bar'. |
|
198 |
box showAtPointer. |
|
199 |
||
200 |
|box| |
|
201 |
box := WarningBox title:'foo bar'. |
|
202 |
box image:(Image fromFile:'QUESTION.xpm' inPackage:'stx:goodies/bitmaps/xpmBitmaps'). |
|
203 |
box showAtPointer. |
|
204 |
" |
|
205 |
||
206 |
"Created: / 17.11.1995 / 18:16:47 / cg" |
|
207 |
"Modified: / 16.11.2001 / 15:02:38 / cg" |
|
208 |
! |
|
209 |
||
210 |
warnIconBitmap |
|
211 |
"return the bitmap shown as icon in my instances. |
|
212 |
This is the default image; you can overwrite this in a concrete |
|
213 |
instance with the image: message" |
|
214 |
||
1365 | 215 |
<resource: #style (#'warningBox.icon' #'warningBox.iconFile')> |
1173
86440dfaca06
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
216 |
|
86440dfaca06
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
217 |
|img imgFileName| |
86440dfaca06
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
218 |
|
0 | 219 |
WarnBitmap isNil ifTrue:[ |
2785 | 220 |
img := self styleSheet at:'warningBox.icon'. |
1743 | 221 |
img isNil ifTrue:[ |
1365 | 222 |
imgFileName := StyleSheet at:'warningBox.iconFile' default:'bitmaps/Warning.xbm'. |
2073 | 223 |
img := Smalltalk imageFromFileNamed:imgFileName forClass:self. |
1173
86440dfaca06
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
224 |
]. |
1743 | 225 |
img notNil ifTrue:[ |
1987 | 226 |
img := img onDevice:Display |
1743 | 227 |
]. |
228 |
WarnBitmap := img |
|
0 | 229 |
]. |
59 | 230 |
^ WarnBitmap |
184 | 231 |
|
232 |
" |
|
233 |
self warn:'foo bar'. |
|
234 |
||
235 |
|box| |
|
236 |
box := WarningBox title:'foo bar'. |
|
237 |
box showAtPointer. |
|
238 |
||
239 |
|box| |
|
240 |
box := WarningBox title:'foo bar'. |
|
2362
f6ace7307e4d
examples fixed (bitmaps access)
Claus Gittinger <cg@exept.de>
parents:
2073
diff
changeset
|
241 |
box image:(Image fromFile:'QUESTION.xpm' inPackage:'stx:goodies/bitmaps/xpmBitmaps'). |
184 | 242 |
box showAtPointer. |
243 |
" |
|
244 |
||
1915 | 245 |
"Modified: / 25.5.1999 / 15:22:25 / cg" |
2474 | 246 |
"Created: / 16.11.2001 / 15:02:24 / cg" |
0 | 247 |
! ! |
248 |
||
197 | 249 |
!WarningBox class methodsFor:'styles'! |
250 |
||
251 |
updateStyleCache |
|
1173
86440dfaca06
allow either image or imageFileName to be specified
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
252 |
"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:
693
diff
changeset
|
253 |
Here, the cached infoBitmap is simply flushed." |
443
555bb9c7e1be
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
355
diff
changeset
|
254 |
|
2474 | 255 |
WarnBitmap := nil. |
256 |
ErrorBitmap := nil. |
|
197 | 257 |
|
2474 | 258 |
"Modified: / 16.11.2001 / 15:00:43 / cg" |
197 | 259 |
! ! |
260 |
||
79 | 261 |
!WarningBox methodsFor:'initialization'! |
262 |
||
263 |
initialize |
|
264 |
super initialize. |
|
265 |
label := 'Warning' |
|
266 |
! ! |
|
267 |
||
0 | 268 |
!WarningBox methodsFor:'realization'! |
269 |
||
493 | 270 |
openModal |
0 | 271 |
"added bell to wake up user" |
272 |
||
693 | 273 |
self beep. |
493 | 274 |
super openModal |
26 | 275 |
|
493 | 276 |
" |
277 |
self warn:'hello' |
|
278 |
" |
|
26 | 279 |
|
693 | 280 |
"Modified: 28.5.1996 / 16:59:01 / cg" |
0 | 281 |
! ! |
197 | 282 |
|
243 | 283 |
!WarningBox class methodsFor:'documentation'! |
284 |
||
285 |
version |
|
2785 | 286 |
^ '$Header: /cvs/stx/stx/libwidg/WarningBox.st,v 1.32 2003-08-18 17:13:54 cg Exp $' |
243 | 287 |
! ! |