0
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1990-93 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 |
ModalBox subclass:#EnterBox
|
|
14 |
instanceVariableNames:'labelField enterField buttonPanel
|
|
15 |
okButton abortButton
|
|
16 |
okAction abortAction'
|
|
17 |
classVariableNames:''
|
|
18 |
poolDictionaries:''
|
|
19 |
category:'Views-Interactors'
|
|
20 |
!
|
|
21 |
|
|
22 |
EnterBox comment:'
|
|
23 |
|
|
24 |
COPYRIGHT (c) 1990-93 by Claus Gittinger
|
|
25 |
All Rights Reserved
|
|
26 |
|
3
|
27 |
$Header: /cvs/stx/stx/libwidg/EnterBox.st,v 1.2 1993-10-13 01:01:55 claus Exp $
|
0
|
28 |
|
|
29 |
written Feb 90 by claus
|
|
30 |
'!
|
|
31 |
|
3
|
32 |
!EnterBox class methodsFor:'documentation'!
|
|
33 |
|
|
34 |
documentation
|
|
35 |
"
|
|
36 |
this class implements a pop-up box to enter some string
|
|
37 |
with 2 buttons; one to cancel, another to start some action.
|
|
38 |
The boxes title can be changed using:
|
|
39 |
|
|
40 |
aBox title:'some string'
|
|
41 |
|
|
42 |
The two button-labels default to 'abort' and 'ok'; they can be changed
|
|
43 |
using:
|
|
44 |
|
|
45 |
aBox okText:'someString'
|
|
46 |
aBox abortText:'someString'
|
|
47 |
|
|
48 |
The initial text in the enterfield can be set using:
|
|
49 |
|
|
50 |
aBox initialText:'someString'
|
|
51 |
|
|
52 |
when the ok-button is pressed, an eaction is performed, which is
|
|
53 |
set using:
|
|
54 |
|
|
55 |
aBox action:[ ... ]
|
|
56 |
|
|
57 |
the abort-action defaults to no-action, but can also be set.
|
|
58 |
"
|
|
59 |
! !
|
|
60 |
|
0
|
61 |
!EnterBox class methodsFor:'defaults'!
|
|
62 |
|
|
63 |
defaultExtent
|
|
64 |
^ (Display pixelPerMillimeter * (60 @ 30)) rounded
|
|
65 |
! !
|
|
66 |
|
|
67 |
!EnterBox class methodsFor:'instance creation'!
|
|
68 |
|
|
69 |
action:aBlock
|
|
70 |
"create and return a new EnterBox
|
|
71 |
which will evaluate aBlock when 'ok' is pressed"
|
|
72 |
|
|
73 |
^ (self new) action:aBlock
|
|
74 |
|
|
75 |
"(EnterBox action:[:string | Transcript showCr:string]) showAtPointer"
|
|
76 |
!
|
|
77 |
|
|
78 |
title:titleString action:aBlock
|
|
79 |
"create and return a new EnterBox with title aString,
|
|
80 |
which will evaluate aBlock when 'ok' is pressed"
|
|
81 |
|
|
82 |
^ ((self new) title:titleString) action:aBlock
|
|
83 |
!
|
|
84 |
|
|
85 |
title:titleString okText:okText abortText:abortText action:aBlock
|
|
86 |
"create and return a new EnterBox with title aString, and buttons showing
|
|
87 |
okText and abortText; it will evaluate aBlock when 'ok' is pressed"
|
|
88 |
|
|
89 |
^ ((self new) title:titleString
|
|
90 |
okText:okText
|
|
91 |
abortText:abortText) action:aBlock
|
|
92 |
! !
|
|
93 |
|
|
94 |
!EnterBox methodsFor:'initialization'!
|
|
95 |
|
|
96 |
initialize
|
|
97 |
|space2 innerWidth|
|
|
98 |
|
|
99 |
super initialize.
|
|
100 |
|
|
101 |
space2 := 2 * ViewSpacing.
|
|
102 |
|
|
103 |
labelField := Label in:self.
|
|
104 |
labelField label:''.
|
|
105 |
labelField borderWidth:0.
|
|
106 |
labelField adjust:#center.
|
|
107 |
|
|
108 |
"kludge: preset extent to something useful since other subviews
|
|
109 |
depend on it (extent blocks are not evaluated until view is realized)
|
|
110 |
- avoid visible resizing when realized the first time"
|
|
111 |
|
|
112 |
innerWidth := width - space2.
|
|
113 |
|
|
114 |
labelField origin:(ViewSpacing @ ViewSpacing)
|
|
115 |
extent:(innerWidth @ labelField height).
|
|
116 |
|
|
117 |
enterField := EditField in:self.
|
|
118 |
enterField origin:(ViewSpacing @ (space2 + labelField height))
|
|
119 |
extent:((width - space2 - (enterField borderWidth * 2)) @ enterField height).
|
|
120 |
enterField origin:[ViewSpacing @ (space2 + labelField height)]
|
|
121 |
extent:[(width - space2 - (enterField borderWidth * 2)) @ enterField height].
|
|
122 |
enterField leaveAction:[:key | self okPressed].
|
|
123 |
|
|
124 |
buttonPanel := HorizontalPanelView in:self.
|
|
125 |
buttonPanel origin:(ViewSpacing @ (height - (font height * 2) - ViewSpacing - (borderWidth * 2)))
|
|
126 |
extent:((width - space2 - (buttonPanel borderWidth * 2))
|
|
127 |
@ ((font height * 2) + (borderWidth * 2))).
|
|
128 |
buttonPanel origin:[ViewSpacing @ (height - (font height * 2) - ViewSpacing - (borderWidth * 2))]
|
|
129 |
extent:[(width - space2 - (buttonPanel borderWidth * 2))
|
|
130 |
@ ((font height * 2) + (borderWidth * 2))].
|
|
131 |
|
|
132 |
buttonPanel layout:"#spread2" #right.
|
|
133 |
buttonPanel borderWidth:0.
|
|
134 |
|
3
|
135 |
abortButton := Button label:(resources at:'abort')
|
0
|
136 |
action:[
|
|
137 |
abortButton turnOffWithoutRedraw.
|
|
138 |
self abortPressed
|
|
139 |
]
|
|
140 |
in:buttonPanel.
|
|
141 |
|
3
|
142 |
okButton := Button label:(resources at:'ok')
|
0
|
143 |
action:[
|
|
144 |
okButton turnOffWithoutRedraw.
|
|
145 |
self okPressed
|
|
146 |
]
|
|
147 |
in:buttonPanel.
|
|
148 |
okButton isReturnButton:true.
|
|
149 |
|
|
150 |
self keyboardHandler:enterField
|
|
151 |
|
|
152 |
!
|
|
153 |
|
|
154 |
initEvents
|
|
155 |
super initEvents.
|
|
156 |
self enableKeyEvents
|
|
157 |
!
|
|
158 |
|
|
159 |
reAdjustGeometry
|
|
160 |
"sent late in snapin processing - gives me a chance
|
|
161 |
to resize for new font dimensions"
|
|
162 |
|
|
163 |
super reAdjustGeometry.
|
|
164 |
labelField resize.
|
|
165 |
okButton resize.
|
|
166 |
abortButton resize.
|
|
167 |
self resize
|
|
168 |
! !
|
|
169 |
|
|
170 |
!EnterBox methodsFor:'private'!
|
|
171 |
|
|
172 |
resize
|
|
173 |
"resize myself to make everything visible"
|
|
174 |
|
|
175 |
|wWanted hWanted wPanel|
|
|
176 |
|
|
177 |
wWanted := labelField widthIncludingBorder + ViewSpacing + ViewSpacing.
|
3
|
178 |
"
|
0
|
179 |
(wWanted > width) ifFalse:[
|
|
180 |
wWanted := width
|
|
181 |
].
|
3
|
182 |
"
|
0
|
183 |
wPanel := buttonPanel preferedExtent x + ViewSpacing + ViewSpacing.
|
|
184 |
wPanel > wWanted ifTrue:[
|
|
185 |
wWanted := wPanel
|
|
186 |
].
|
|
187 |
hWanted := ViewSpacing + labelField height +
|
|
188 |
ViewSpacing + enterField height +
|
|
189 |
(ViewSpacing * 6) + buttonPanel height +
|
|
190 |
ViewSpacing.
|
3
|
191 |
((wWanted ~= width) or:[hWanted ~= height]) ifTrue:[
|
|
192 |
self extent:(wWanted @ hWanted)
|
|
193 |
]
|
0
|
194 |
! !
|
|
195 |
|
|
196 |
!EnterBox methodsFor:'accessing'!
|
|
197 |
|
|
198 |
title:aString
|
|
199 |
"set the title to be displayed at top of enterBox"
|
|
200 |
|
3
|
201 |
|oldSize|
|
|
202 |
|
|
203 |
oldSize := labelField extent.
|
0
|
204 |
labelField label:aString.
|
|
205 |
labelField resize.
|
3
|
206 |
|
|
207 |
labelField extent ~= oldSize ifTrue:[
|
|
208 |
self resize
|
|
209 |
]
|
0
|
210 |
!
|
|
211 |
|
|
212 |
title:titleString okText:okString abortText:abortString
|
|
213 |
"set title and texts in the buttons"
|
|
214 |
|
|
215 |
self title:titleString.
|
|
216 |
okButton label:okString.
|
|
217 |
abortButton label:abortString
|
|
218 |
!
|
|
219 |
|
|
220 |
title:titleString okText:okString
|
|
221 |
"set title and text in okbutton"
|
|
222 |
|
|
223 |
self title:titleString.
|
|
224 |
okButton label:okString
|
|
225 |
!
|
|
226 |
|
|
227 |
okText:aString
|
|
228 |
"set the text to be displayed in the ok-button"
|
|
229 |
|
3
|
230 |
|oldSize|
|
|
231 |
|
|
232 |
oldSize := okButton extent.
|
0
|
233 |
okButton label:aString.
|
|
234 |
okButton resize.
|
3
|
235 |
okButton extent ~= oldSize ifTrue:[
|
|
236 |
self resize
|
|
237 |
]
|
0
|
238 |
!
|
|
239 |
|
|
240 |
abortText:aString
|
|
241 |
"set the text to be displayed in the abort-button"
|
|
242 |
|
3
|
243 |
|oldSize|
|
|
244 |
|
|
245 |
oldSize := abortButton extent.
|
0
|
246 |
abortButton label:aString.
|
|
247 |
abortButton resize.
|
3
|
248 |
abortButton extent ~= oldSize ifTrue:[
|
|
249 |
self resize
|
|
250 |
]
|
0
|
251 |
!
|
|
252 |
|
|
253 |
okText:okString abortText:abortString
|
|
254 |
"set both texts displayed in the buttons"
|
|
255 |
|
|
256 |
okButton label:okString.
|
|
257 |
abortButton label:abortString.
|
|
258 |
okButton resize.
|
|
259 |
abortButton resize.
|
|
260 |
self resize
|
|
261 |
!
|
|
262 |
|
|
263 |
contents
|
|
264 |
"return my contents"
|
|
265 |
|
|
266 |
^ enterField contents
|
|
267 |
!
|
|
268 |
|
|
269 |
initialText:aString
|
|
270 |
"define the initial text in the enterfield. all will be selected initially"
|
|
271 |
|
|
272 |
enterField initialText:aString
|
|
273 |
!
|
|
274 |
|
|
275 |
initialText:aString selectFrom:start to:stop
|
|
276 |
"define the initial text in the enterfield, and the part to be selected"
|
|
277 |
|
|
278 |
enterField initialText:aString.
|
|
279 |
enterField selectFromLine:1 col:start toLine:1 col:stop
|
|
280 |
!
|
|
281 |
|
|
282 |
action:aBlock
|
|
283 |
"set the action to be performed when user presses ok-button;
|
|
284 |
aBlock must be nil or a block with one argument "
|
|
285 |
|
|
286 |
okAction := aBlock
|
|
287 |
!
|
|
288 |
|
|
289 |
abortAction:aBlock
|
|
290 |
"set the action to be performed when user presses abort-button;
|
|
291 |
aBlock must be nil or a block with no arguments"
|
|
292 |
|
|
293 |
abortAction := aBlock
|
|
294 |
! !
|
|
295 |
|
|
296 |
!EnterBox methodsFor:'user interaction'!
|
|
297 |
|
|
298 |
hideAndEvaluate:aBlock
|
|
299 |
"common processing for all ok-actions (see subclasses);
|
|
300 |
shut down box, fetch entered string and evaluate the action with it"
|
|
301 |
|
|
302 |
|string|
|
|
303 |
|
|
304 |
self hide.
|
|
305 |
aBlock notNil ifTrue:[
|
|
306 |
string := self contents.
|
|
307 |
string isNil ifTrue:[
|
|
308 |
string := ''
|
|
309 |
] ifFalse:[
|
|
310 |
string := string withoutSeparators
|
|
311 |
].
|
|
312 |
aBlock value:string
|
|
313 |
]
|
|
314 |
!
|
|
315 |
|
|
316 |
okPressed
|
|
317 |
"user pressed ok button - hide myself and evaluate okAction"
|
|
318 |
|
|
319 |
self hideAndEvaluate:okAction
|
|
320 |
!
|
|
321 |
|
|
322 |
abortPressed
|
|
323 |
"user pressed abort button - hide myself and evaluate okAction"
|
|
324 |
|
|
325 |
self hideAndEvaluate:abortAction
|
|
326 |
! !
|