76
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
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 |
|
|
13 |
|
|
14 |
'From Smalltalk/X, Version:2.10.4 on 28-dec-1994 at 1:38:02 pm'!
|
|
15 |
|
|
16 |
ModalBox subclass:#DialogBox
|
|
17 |
instanceVariableNames:'buttonPanel okButton okAction abortButton abortAction
|
|
18 |
acceptReturnAsOK'
|
|
19 |
classVariableNames:''
|
|
20 |
poolDictionaries:''
|
|
21 |
category:'Views-DialogBoxes'
|
|
22 |
!
|
|
23 |
|
|
24 |
!DialogBox class methodsFor:'documentation'!
|
|
25 |
|
|
26 |
version
|
|
27 |
"
|
|
28 |
$Header: /cvs/stx/stx/libwidg/DialogBox.st,v 1.1 1995-02-06 00:52:01 claus Exp $
|
|
29 |
"
|
|
30 |
!
|
|
31 |
|
|
32 |
documentation
|
|
33 |
"
|
|
34 |
this class implements the common behavior of dialogboxes.
|
|
35 |
|
|
36 |
DialogBox is an (abstract) superclass of many other boxes - see InfoBox,
|
|
37 |
WarningBox, YesNoBox etc. for concrete examples.
|
|
38 |
Most of them simply add buttons or other elements.
|
|
39 |
|
|
40 |
instance variables:
|
|
41 |
|
|
42 |
buttonPanel <PanelView> contains the button(s)
|
|
43 |
|
|
44 |
okButton <Button> the ok-Button
|
|
45 |
|
|
46 |
okAction <Block> the action to be performed when ok is pressed,
|
|
47 |
or return is pressed.
|
|
48 |
|
|
49 |
acceptReturnAsOK <Boolean> if true, pressing the return-key counts
|
|
50 |
as if ok was pressed. Default is true.
|
|
51 |
|
|
52 |
abortButton <Button> the cancel-Button
|
|
53 |
|
|
54 |
abortAction <Block> the action to be performed when cancel is
|
|
55 |
pressed.
|
|
56 |
"
|
|
57 |
!
|
|
58 |
|
|
59 |
examples
|
|
60 |
"
|
|
61 |
DialogBox new open
|
|
62 |
|
|
63 |
|
|
64 |
DialogBox new addOkButton; open
|
|
65 |
DialogBox new addAbortButton; addOkButton; open
|
|
66 |
"
|
|
67 |
!
|
|
68 |
|
|
69 |
copyright
|
|
70 |
"
|
|
71 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
|
72 |
All Rights Reserved
|
|
73 |
|
|
74 |
This software is furnished under a license and may be used
|
|
75 |
only in accordance with the terms of that license and with the
|
|
76 |
inclusion of the above copyright notice. This software may not
|
|
77 |
be provided or otherwise made available to, or used by, any
|
|
78 |
other person. No title to or ownership of the software is
|
|
79 |
hereby transferred.
|
|
80 |
"
|
|
81 |
! !
|
|
82 |
|
|
83 |
!DialogBox methodsFor:'user actions'!
|
|
84 |
|
|
85 |
okPressed
|
|
86 |
"user pressed ok-button; make myself invisible and if an action was
|
|
87 |
specified do it"
|
|
88 |
|
|
89 |
self hideAndEvaluate:okAction
|
|
90 |
!
|
|
91 |
|
|
92 |
abortPressed
|
|
93 |
"user pressed abort button - hide myself and evaluate okAction"
|
|
94 |
|
|
95 |
self hideAndEvaluate:abortAction
|
|
96 |
!
|
|
97 |
|
|
98 |
keyPress:aKey x:x y:y
|
|
99 |
"return-key dublicates ok-function if acceptReturnAsOK is true"
|
|
100 |
|
|
101 |
acceptReturnAsOK ifTrue:[
|
|
102 |
(aKey == #Return) ifTrue:[^ self okPressed]
|
|
103 |
].
|
|
104 |
super keyPress:aKey x:x y:y
|
|
105 |
! !
|
|
106 |
|
|
107 |
!DialogBox methodsFor:'queries'!
|
|
108 |
|
|
109 |
positionOffset
|
|
110 |
"return the delta, by which the box should be displayed
|
|
111 |
from the mouse pointer. Value returned here makes center of
|
|
112 |
okButton appear under the cursor"
|
|
113 |
|
|
114 |
okButton isNil ifTrue:[
|
|
115 |
^ self extent // 2
|
|
116 |
].
|
|
117 |
buttonPanel setChildPositionsIfChanged.
|
|
118 |
^ (okButton originRelativeTo:self) + (okButton extent // 2)
|
|
119 |
!
|
|
120 |
|
|
121 |
preferedExtent
|
|
122 |
"return my prefered extent"
|
|
123 |
|
|
124 |
|w h|
|
|
125 |
|
|
126 |
okButton isNil ifTrue:[
|
|
127 |
^ super preferedExtent
|
|
128 |
].
|
|
129 |
w := okButton preferedExtent x + (ViewSpacing * 2).
|
|
130 |
h := ViewSpacing
|
|
131 |
+ okButton preferedExtent y
|
|
132 |
+ ViewSpacing.
|
|
133 |
|
|
134 |
^ w @ h
|
|
135 |
! !
|
|
136 |
|
|
137 |
!DialogBox methodsFor:'initialization'!
|
|
138 |
|
|
139 |
initialize
|
|
140 |
|mm|
|
|
141 |
|
|
142 |
super initialize.
|
|
143 |
|
|
144 |
label := 'Dialog'.
|
|
145 |
|
|
146 |
mm := ViewSpacing.
|
|
147 |
|
|
148 |
acceptReturnAsOK := true.
|
|
149 |
|
|
150 |
buttonPanel := HorizontalPanelView in:self.
|
|
151 |
buttonPanel origin:(0.0 @ 1.0) corner:(1.0 @ 1.0).
|
|
152 |
buttonPanel bottomInset:mm;
|
|
153 |
topInset:(font height + mm * 2) negated.
|
|
154 |
buttonPanel borderWidth:0.
|
|
155 |
|
|
156 |
buttonPanel layout:#spread.
|
|
157 |
|
|
158 |
"
|
|
159 |
|b|
|
|
160 |
b := DialogBox new.
|
|
161 |
b addAbortButton; addOkButton; showAtPointer
|
|
162 |
"
|
|
163 |
"
|
|
164 |
|b|
|
|
165 |
b := DialogBox new.
|
|
166 |
b addOkButton; showAtPointer
|
|
167 |
"
|
|
168 |
!
|
|
169 |
|
|
170 |
addOkButton
|
|
171 |
"create an okButton - to be sent from redefined initialize
|
|
172 |
methods in subclasses."
|
|
173 |
|
|
174 |
buttonPanel subViews size == 1 ifTrue:[
|
|
175 |
buttonPanel layout:#fitSpace.
|
|
176 |
].
|
|
177 |
okButton := Button okButtonIn:buttonPanel.
|
|
178 |
okButton action:[
|
|
179 |
okButton turnOffWithoutRedraw.
|
|
180 |
self okPressed
|
|
181 |
].
|
|
182 |
okButton isReturnButton:acceptReturnAsOK.
|
|
183 |
!
|
|
184 |
|
|
185 |
addAbortButton
|
|
186 |
"create an abortButton - to be sent from redefined initialize
|
|
187 |
methods in subclasses."
|
|
188 |
|
|
189 |
buttonPanel subViews size == 1 ifTrue:[
|
|
190 |
buttonPanel layout:#fitSpace.
|
|
191 |
].
|
|
192 |
abortButton := Button abortButtonIn:buttonPanel.
|
|
193 |
abortButton action:[
|
|
194 |
abortButton turnOffWithoutRedraw.
|
|
195 |
self abortPressed
|
|
196 |
].
|
|
197 |
!
|
|
198 |
|
|
199 |
reAdjustGeometry
|
|
200 |
"sent late in snapin processing - gives me a chance
|
|
201 |
to resize for changed font dimensions."
|
|
202 |
|
|
203 |
super reAdjustGeometry.
|
|
204 |
okButton notNil ifTrue:[okButton resize].
|
|
205 |
abortButton notNil ifTrue:[abortButton resize].
|
|
206 |
self resize
|
|
207 |
! !
|
|
208 |
|
|
209 |
!DialogBox methodsFor:'private'!
|
|
210 |
|
|
211 |
hideAndEvaluate:aBlock
|
|
212 |
"make myself invisible and evaluate aBlock"
|
|
213 |
|
|
214 |
self hide.
|
|
215 |
aBlock notNil ifTrue:[aBlock value]
|
|
216 |
! !
|
|
217 |
|
|
218 |
!DialogBox methodsFor:'accessing'!
|
|
219 |
|
|
220 |
acceptReturnAsOK:aBoolean
|
|
221 |
"turn on/off interpretation of return-key as ok.
|
|
222 |
Default is on"
|
|
223 |
|
|
224 |
acceptReturnAsOK := aBoolean.
|
|
225 |
okButton notNil ifTrue:[
|
|
226 |
okButton isReturnButton:aBoolean.
|
|
227 |
]
|
|
228 |
!
|
|
229 |
|
|
230 |
okAction:aBlock
|
|
231 |
"define the action to be performed when ok is pressed"
|
|
232 |
|
|
233 |
okAction := aBlock
|
|
234 |
!
|
|
235 |
|
|
236 |
action:aBlock
|
|
237 |
"set the action to be performed when user presses ok-button;
|
|
238 |
aBlock must be nil or a block. This method simply
|
|
239 |
reuses okAction: and has been added for a consistent action-setting
|
|
240 |
protocol."
|
|
241 |
|
|
242 |
self okAction:aBlock
|
|
243 |
!
|
|
244 |
|
|
245 |
okButton
|
|
246 |
"return the okButton"
|
|
247 |
|
|
248 |
^ okButton
|
|
249 |
!
|
|
250 |
|
|
251 |
okText:aString
|
|
252 |
"define the text in the ok-button"
|
|
253 |
|
|
254 |
|oldSize|
|
|
255 |
|
|
256 |
aString ~= okButton label ifTrue:[
|
|
257 |
oldSize := okButton extent.
|
|
258 |
okButton label:aString.
|
|
259 |
okButton resize.
|
|
260 |
okButton extent ~= oldSize ifTrue:[
|
|
261 |
self resize
|
|
262 |
]
|
|
263 |
]
|
|
264 |
!
|
|
265 |
|
|
266 |
abortAction:aBlock
|
|
267 |
"define the action to be performed when abort is pressed"
|
|
268 |
|
|
269 |
abortAction := aBlock
|
|
270 |
!
|
|
271 |
|
|
272 |
abortButton
|
|
273 |
"return the abortButton"
|
|
274 |
|
|
275 |
^ abortButton
|
|
276 |
!
|
|
277 |
|
|
278 |
abortText:aString
|
|
279 |
"define the label in the abort-button"
|
|
280 |
|
|
281 |
|oldSize|
|
|
282 |
|
|
283 |
aString ~= abortButton label ifTrue:[
|
|
284 |
oldSize := abortButton extent.
|
|
285 |
abortButton label:aString.
|
|
286 |
abortButton resize.
|
|
287 |
abortButton extent ~= oldSize ifTrue:[
|
|
288 |
self resize
|
|
289 |
]
|
|
290 |
]
|
|
291 |
!
|
|
292 |
|
|
293 |
okText:okString abortText:abortString
|
|
294 |
"set both texts displayed in the buttons"
|
|
295 |
|
|
296 |
(abortString ~= abortButton label
|
|
297 |
or:[okString ~= okButton label]) ifTrue:[
|
|
298 |
okButton label:okString.
|
|
299 |
abortButton label:abortString.
|
|
300 |
okButton resize.
|
|
301 |
abortButton resize.
|
|
302 |
self resize
|
|
303 |
]
|
|
304 |
! !
|
|
305 |
|