0
|
1 |
"
|
4
|
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 |
|
|
13 |
Label subclass:#Button
|
59
|
14 |
instanceVariableNames:'activeLogo passiveLogo
|
|
15 |
pressActionBlock releaseActionBlock
|
|
16 |
actionWhenPressed
|
|
17 |
enabled pressed active entered
|
|
18 |
autoRepeat repeatBlock
|
|
19 |
onLevel offLevel
|
|
20 |
initialDelay repeatDelay
|
|
21 |
disabledFgColor
|
|
22 |
activeFgColor activeBgColor
|
|
23 |
enteredFgColor enteredBgColor
|
|
24 |
isReturnButton
|
|
25 |
shadowForm lightForm
|
62
|
26 |
formColor formShadowColor formLightColor
|
|
27 |
edgeStyle halfShadowColor halfLightColor'
|
|
28 |
|
59
|
29 |
classVariableNames:'ReturnForm ReturnLightForm ReturnShadowForm
|
|
30 |
DefaultFont DefaultActiveLevel
|
74
|
31 |
DefaultPassiveLevel DefaultEdgeStyle DefaultFont DefaultBorderWidth
|
59
|
32 |
DefaultForegroundColor DefaultBackgroundColor
|
|
33 |
DefaultDisabledForegroundColor DefaultDisabledBackgroundColor
|
|
34 |
DefaultEnteredForegroundColor DefaultEnteredBackgroundColor
|
|
35 |
DefaultActiveForegroundColor DefaultActiveBackgroundColor
|
62
|
36 |
DefaultReturnButtonHasImage DefaultReturnButtonHasBorder
|
|
37 |
DefaultShadowColor DefaultLightColor
|
|
38 |
DefaultHalfShadowColor DefaultHalfLightColor'
|
0
|
39 |
poolDictionaries:''
|
|
40 |
category:'Views-Interactors'
|
|
41 |
!
|
|
42 |
|
|
43 |
Button comment:'
|
4
|
44 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
45 |
All Rights Reserved
|
0
|
46 |
|
74
|
47 |
$Header: /cvs/stx/stx/libwidg/Button.st,v 1.13 1995-01-26 16:04:47 claus Exp $
|
0
|
48 |
'!
|
|
49 |
|
|
50 |
!Button class methodsFor:'documentation'!
|
|
51 |
|
35
|
52 |
copyright
|
|
53 |
"
|
|
54 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
55 |
All Rights Reserved
|
35
|
56 |
|
|
57 |
This software is furnished under a license and may be used
|
|
58 |
only in accordance with the terms of that license and with the
|
|
59 |
inclusion of the above copyright notice. This software may not
|
|
60 |
be provided or otherwise made available to, or used by, any
|
|
61 |
other person. No title to or ownership of the software is
|
|
62 |
hereby transferred.
|
|
63 |
"
|
|
64 |
!
|
|
65 |
|
|
66 |
version
|
|
67 |
"
|
74
|
68 |
$Header: /cvs/stx/stx/libwidg/Button.st,v 1.13 1995-01-26 16:04:47 claus Exp $
|
35
|
69 |
"
|
|
70 |
!
|
|
71 |
|
0
|
72 |
documentation
|
|
73 |
"
|
|
74 |
Buttons are Labels which do something when pressed/released.
|
|
75 |
|
|
76 |
Instance variables:
|
|
77 |
|
59
|
78 |
activeLogo <StringOrImage> logo to show when active (pressed)
|
|
79 |
passiveLogo <StringOrImage> logo to show when passive (released)
|
|
80 |
default is nil for both, so the normal logo is used
|
|
81 |
(see superclass: Label)
|
35
|
82 |
pressActionBlock <Block> block to evaluate when pressed (default: noop)
|
|
83 |
releaseActionBlock <Block> block to evaluate when released (default: noop)
|
59
|
84 |
actionWhenPressed <Boolean> controls if the action should be executed on
|
|
85 |
press or on release (default: on release).
|
35
|
86 |
enabled <Boolean> pressing is allowed (default: true)
|
|
87 |
pressed <Boolean> true if currently pressed (read-only)
|
|
88 |
entered <Boolean> true if the cursor is currently in this view
|
|
89 |
autoRepeat <Boolean> auto-repeats when pressed long enough (default: false)
|
|
90 |
onLevel <Integer> level when pressed (3D only) (default: depends on style)
|
|
91 |
offLevel <Integer> level when released (3D only) (default: depends on style)
|
|
92 |
initialDelay <Number> seconds till first auto-repeat (default: 0.2)
|
|
93 |
repeatDelay <Number> seconds of repeat intervall (default: 0.025)
|
|
94 |
disabledFgColor <Color> color used to draw logo when disabled (default: depends on style)
|
|
95 |
activeFgColor <Color> color to draw logo when pressed (default: depends on style)
|
|
96 |
activeBgColor <Color> bg color when pressed (default: depends on style)
|
|
97 |
enteredFgColor <Color> fg color to draw logo when cursor entered (default: depends on style)
|
|
98 |
enteredBgColor <Color> bg color when cursor entered (default: depends on style)
|
0
|
99 |
|
35
|
100 |
isReturnButton <Boolean> true if this button is also activated by the
|
59
|
101 |
return key - if true, it will draw a return-bitmap
|
|
102 |
in addition to the logo (default: false)
|
35
|
103 |
|
59
|
104 |
shadowForm <Form> form to display in addition to buttons label (returnbutton only)
|
|
105 |
lightForm <Form> light part of shadowForm (returnbutton only)
|
|
106 |
|
|
107 |
formColor <Color> color to draw form with (returnbutton only)
|
|
108 |
formShadowColor <Color> color for shadowing the form (3D only & return)
|
35
|
109 |
formLightColor <Color> color for lighting the form (3D only)
|
|
110 |
|
59
|
111 |
repeatBlock <Block> block evaluated for auto-repeat (internal)
|
|
112 |
active <Boolean> true during action evaluation (internal)
|
35
|
113 |
|
62
|
114 |
|
|
115 |
styleSheet parameters:
|
|
116 |
|
|
117 |
buttonActiveLevel <Integer> level when on (ignored in 2D styles)
|
|
118 |
buttonPassiveLevel <Integer> level when off (ignored in 2D styles)
|
74
|
119 |
buttonBorderWidth <Integer> default borderwidth
|
62
|
120 |
buttonEdgeStyle <Symbol> style of edges (currently #soft or nil)
|
|
121 |
buttonFont <Font> font to use for textual labels
|
|
122 |
buttonForegroundColor <Color> color to draw foreground pixels (i.e. the string)
|
|
123 |
buttonBackgroundColor <Color> color to draw background pixels
|
|
124 |
buttonDisabledForegroundColor <Color> same when disabled
|
|
125 |
buttonDisabledBackgroundColor <Color> same when disabled
|
|
126 |
buttonEnteredForegroundColor <Color> same when mouse pointer is in
|
|
127 |
buttonEnteredBackgroundColor <Color> same when mouse pointer is in
|
|
128 |
buttonActiveForegroundColor <Color> same when button is active
|
|
129 |
buttonActiveBackgroundColor <Color> same when button is active
|
|
130 |
buttonShadowColor <Color> shadow color for edgaes (ignored in 2D styles)
|
|
131 |
buttonLightColor <Color> light color for edgaes (ignored in 2D styles)
|
|
132 |
buttonHalfShadowColor <Color> half shadow color; for soft edges only
|
|
133 |
buttonHalfLightColor <Color> half light color; for soft edges only
|
|
134 |
|
|
135 |
buttonReturnButtonHasImage <Boolean> if true, return-buttons draw a return-key image
|
|
136 |
buttonReturnButtonHasBorder <Boolean> if true, return-buttons show a border
|
|
137 |
"
|
|
138 |
!
|
|
139 |
|
|
140 |
examples
|
|
141 |
"
|
|
142 |
You dont have to normally care for all the internals
|
35
|
143 |
(they allow many variations though). The typical use is:
|
|
144 |
|
59
|
145 |
b := Button label:'some logo' in:aView.
|
|
146 |
b action:[ .. things to do, when pressed ... ]
|
35
|
147 |
|
62
|
148 |
for buttons with a string-label,
|
|
149 |
and:
|
|
150 |
|
|
151 |
b := Button form:someImage in:aView.
|
|
152 |
b action:[ .. things to do, when pressed ... ]
|
|
153 |
|
|
154 |
for buttons with a bitmap label.
|
|
155 |
|
|
156 |
There are many things whaich can be configured in addition;
|
|
157 |
for example,
|
|
158 |
|
59
|
159 |
see 'doc/coding-examples' and 'doc/misc/quick_view_intro.doc' for more variations.
|
62
|
160 |
|
|
161 |
|
|
162 |
To implement fun buttons (for games, show-demos etc.), you can
|
|
163 |
access all internal parameters (and not take the viewStyle defaults)
|
|
164 |
as in:
|
|
165 |
|
|
166 |
|b granite light shadow|
|
|
167 |
|
|
168 |
b := Button label:'isn''t that a nice one ?'.
|
|
169 |
granite := Image fromFile:'bitmaps/granite_small.tiff'.
|
|
170 |
light := granite lightened.
|
|
171 |
shadow := granite darkened.
|
|
172 |
b backgroundColor:granite.
|
|
173 |
b foregroundColor:Color white.
|
|
174 |
b shadowColor:shadow.
|
|
175 |
b lightColor:light.
|
|
176 |
b onLevel:-3; offLevel:5.
|
|
177 |
b extent:(200 @ 50).
|
|
178 |
b open
|
|
179 |
|
|
180 |
However, in your application, you may want to read those bitmaps only once
|
|
181 |
during startup and cache them for later reuse in some class variable
|
|
182 |
(reading, lightning & darkening of images is a bit slow)
|
0
|
183 |
"
|
|
184 |
! !
|
|
185 |
|
|
186 |
!Button class methodsFor:'defaults'!
|
|
187 |
|
|
188 |
defaultInitialDelay
|
|
189 |
"when autorepeat is enabled, and button is not released,
|
|
190 |
start repeating after initialDelay seconds"
|
|
191 |
|
|
192 |
^ 0.2
|
|
193 |
!
|
|
194 |
|
|
195 |
defaultRepeatDelay
|
|
196 |
"when autorepeat is enabled, and button is not released,
|
|
197 |
repeat every repeatDelay seconds"
|
|
198 |
|
|
199 |
^ 0.025
|
|
200 |
!
|
|
201 |
|
59
|
202 |
updateStyleCache
|
60
|
203 |
|defaultLevel|
|
|
204 |
|
59
|
205 |
StyleSheet is3D ifTrue:[
|
60
|
206 |
defaultLevel := 1.
|
59
|
207 |
] ifFalse:[
|
60
|
208 |
defaultLevel := 0
|
59
|
209 |
].
|
60
|
210 |
DefaultActiveLevel := StyleSheet at:'buttonActiveLevel' default:(defaultLevel negated).
|
|
211 |
DefaultPassiveLevel := StyleSheet at:'buttonPassiveLevel' default:defaultLevel.
|
|
212 |
|
62
|
213 |
DefaultEdgeStyle := StyleSheet at:'buttonEdgeStyle'.
|
60
|
214 |
DefaultFont := StyleSheet fontAt:'buttonFont'.
|
74
|
215 |
DefaultBorderWidth := StyleSheet at:'buttonBorderWidth'.
|
60
|
216 |
DefaultForegroundColor := StyleSheet colorAt:'buttonForegroundColor'.
|
|
217 |
DefaultBackgroundColor := StyleSheet colorAt:'buttonBackgroundColor'.
|
|
218 |
DefaultDisabledForegroundColor := StyleSheet colorAt:'buttonDisabledForegroundColor' default:Color grey.
|
|
219 |
DefaultDisabledBackgroundColor := StyleSheet colorAt:'buttonDisabledBackgroundColor'.
|
|
220 |
DefaultEnteredForegroundColor := StyleSheet colorAt:'buttonEnteredForegroundColor'.
|
|
221 |
DefaultEnteredBackgroundColor := StyleSheet colorAt:'buttonEnteredBackgroundColor'.
|
|
222 |
DefaultActiveForegroundColor := StyleSheet colorAt:'buttonActiveForegroundColor'.
|
|
223 |
DefaultActiveBackgroundColor := StyleSheet colorAt:'buttonActiveBackgroundColor'.
|
59
|
224 |
DefaultReturnButtonHasImage := StyleSheet at:'buttonReturnButtonHasImage' default:true.
|
|
225 |
DefaultReturnButtonHasBorder := StyleSheet at:'buttonReturnButtonHasBorder' default:false.
|
62
|
226 |
DefaultShadowColor := StyleSheet colorAt:'buttonShadowColor'.
|
|
227 |
DefaultLightColor := StyleSheet colorAt:'buttonLightColor'.
|
|
228 |
DefaultHalfShadowColor := StyleSheet colorAt:'buttonHalfShadowColor'.
|
|
229 |
DefaultHalfLightColor := StyleSheet colorAt:'buttonHalfLightColor'.
|
59
|
230 |
!
|
|
231 |
|
0
|
232 |
returnFormOn:aDevice
|
|
233 |
"return the form used for the return arrow in non-3D;
|
|
234 |
cache the one for Display for the next round."
|
|
235 |
|
|
236 |
|f|
|
|
237 |
|
35
|
238 |
(ReturnForm notNil and:[aDevice == ReturnForm device]) ifTrue:[
|
59
|
239 |
^ ReturnForm
|
0
|
240 |
].
|
|
241 |
f := Form fromFile:'Return.xbm' resolution:100 on:aDevice.
|
|
242 |
f isNil ifTrue:[
|
59
|
243 |
f := Form width:24 height:16 fromArray:#[2r00000000 2r00000000 2r00000000
|
|
244 |
2r00000000 2r00000000 2r00000000
|
|
245 |
2r00000000 2r00000000 2r00000000
|
|
246 |
2r00000000 2r00000011 2r11100000
|
|
247 |
2r00000001 2r10000011 2r11100000
|
|
248 |
2r00000011 2r10000011 2r11100000
|
|
249 |
2r00000111 2r11111111 2r11100000
|
|
250 |
2r00001111 2r11111111 2r11100000
|
|
251 |
2r00011111 2r11111111 2r11100000
|
|
252 |
2r00001111 2r11111111 2r11100000
|
|
253 |
2r00000111 2r11111111 2r11100000
|
|
254 |
2r00000011 2r10000000 2r00000000
|
|
255 |
2r00000001 2r10000000 2r00000000
|
|
256 |
2r00000000 2r00000000 2r00000000
|
|
257 |
2r00000000 2r00000000 2r00000000
|
|
258 |
2r00000000 2r00000000 2r00000000]
|
|
259 |
on:aDevice
|
0
|
260 |
].
|
35
|
261 |
ReturnForm := f.
|
0
|
262 |
^ f
|
|
263 |
!
|
|
264 |
|
|
265 |
returnShadowFormOn:aDevice
|
|
266 |
"return the form used for the return arrow shadow pixels (3D only);
|
|
267 |
cache the one for Display for the next round."
|
|
268 |
|
|
269 |
|f|
|
|
270 |
|
35
|
271 |
(ReturnShadowForm notNil and:[aDevice == ReturnShadowForm device]) ifTrue:[
|
59
|
272 |
^ ReturnShadowForm
|
0
|
273 |
].
|
|
274 |
f := Form fromFile:'ReturnShadow.xbm' resolution:100 on:aDevice.
|
|
275 |
f isNil ifTrue:[
|
59
|
276 |
f := Form width:24 height:16 fromArray:#[2r00000000 2r00000000 2r00000000
|
|
277 |
2r00000000 2r00000000 2r00000000
|
|
278 |
2r00000000 2r00000000 2r00000000
|
|
279 |
2r00000000 2r00000011 2r11100000
|
|
280 |
2r00000001 2r10000010 2r00000000
|
|
281 |
2r00000010 2r10000010 2r00000000
|
|
282 |
2r00000100 2r11111110 2r00000000
|
|
283 |
2r00001000 2r00000000 2r00000000
|
|
284 |
2r00010000 2r00000000 2r00000000
|
|
285 |
2r00001000 2r00000000 2r00000000
|
|
286 |
2r00000100 2r00000000 2r00000000
|
|
287 |
2r00000010 2r00000000 2r00000000
|
|
288 |
2r00000001 2r00000000 2r00000000
|
|
289 |
2r00000000 2r00000000 2r00000000
|
|
290 |
2r00000000 2r00000000 2r00000000
|
|
291 |
2r00000000 2r00000000 2r00000000]
|
|
292 |
on:aDevice
|
0
|
293 |
].
|
35
|
294 |
ReturnShadowForm := f.
|
0
|
295 |
^ f
|
|
296 |
!
|
|
297 |
|
|
298 |
returnLightFormOn:aDevice
|
|
299 |
"return the form used for the return arrow light pixels (3D only);
|
|
300 |
cache the one for Display for the next round"
|
|
301 |
|
|
302 |
|f|
|
|
303 |
|
35
|
304 |
(ReturnLightForm notNil and:[aDevice == ReturnLightForm device]) ifTrue:[
|
59
|
305 |
^ ReturnLightForm
|
0
|
306 |
].
|
|
307 |
f := Form fromFile:'ReturnLight.xbm' resolution:100 on:aDevice.
|
|
308 |
f isNil ifTrue:[
|
59
|
309 |
f := Form width:24 height:16 fromArray:#[2r00000000 2r00000000 2r00000000
|
|
310 |
2r00000000 2r00000000 2r00000000
|
|
311 |
2r00000000 2r00000000 2r00000000
|
|
312 |
2r00000000 2r00000000 2r00000000
|
|
313 |
2r00000000 2r00000000 2r00100000
|
|
314 |
2r00000000 2r00000000 2r00100000
|
|
315 |
2r00000000 2r00000000 2r00100000
|
|
316 |
2r00000000 2r00000000 2r00100000
|
|
317 |
2r00000000 2r00000000 2r00100000
|
|
318 |
2r00000000 2r00000000 2r00100000
|
|
319 |
2r00000000 2r11111111 2r11100000
|
|
320 |
2r00000000 2r10000000 2r00000000
|
|
321 |
2r00000000 2r10000000 2r00000000
|
|
322 |
2r00000000 2r00000000 2r00000000
|
|
323 |
2r00000000 2r00000000 2r00000000
|
|
324 |
2r00000000 2r00000000 2r00000000]
|
|
325 |
on:aDevice
|
0
|
326 |
].
|
35
|
327 |
ReturnLightForm := f.
|
0
|
328 |
^ f
|
|
329 |
! !
|
|
330 |
|
|
331 |
!Button class methodsFor:'instance creation'!
|
|
332 |
|
|
333 |
label:aLabel action:aBlock in:aView
|
|
334 |
"create and return a new Button with text-label, aString
|
|
335 |
and pressAction, aBlock. Button is placed into aView."
|
|
336 |
|
|
337 |
^ ((self in:aView) label:aLabel) action:aBlock
|
|
338 |
!
|
|
339 |
|
|
340 |
form:aForm action:aBlock in:aView
|
|
341 |
"create and return a new Button with icon-label, aForm
|
|
342 |
and pressAction, aBlock. Button is placed into aView."
|
|
343 |
|
|
344 |
^ ((self in:aView) form:aForm) action:aBlock
|
59
|
345 |
!
|
|
346 |
|
|
347 |
okButtonIn:aView
|
|
348 |
"since ok-buttons are very common, here is a convenient
|
|
349 |
method to create one ..."
|
|
350 |
|
|
351 |
|aButton|
|
|
352 |
|
|
353 |
aButton := Button
|
|
354 |
label:(self classResources at:'ok')
|
|
355 |
in:aView.
|
|
356 |
aButton cursor:(Cursor thumbsUp).
|
|
357 |
aButton isReturnButton:true.
|
|
358 |
^ aButton
|
|
359 |
!
|
|
360 |
|
|
361 |
abortButtonIn:aView
|
|
362 |
"since abort-buttons are very common, here is a convenient
|
|
363 |
method to create one ..."
|
|
364 |
|
|
365 |
|aButton|
|
|
366 |
|
|
367 |
aButton := Button
|
|
368 |
label:(self classResources at:'abort')
|
|
369 |
in:aView.
|
|
370 |
aButton cursor:(Cursor thumbsDown).
|
|
371 |
^ aButton
|
0
|
372 |
! !
|
|
373 |
|
|
374 |
!Button methodsFor:'initialization'!
|
|
375 |
|
|
376 |
initialize
|
|
377 |
super initialize.
|
|
378 |
|
59
|
379 |
actionWhenPressed := false.
|
0
|
380 |
enabled := true.
|
|
381 |
active := false.
|
35
|
382 |
pressed := false.
|
|
383 |
entered := false.
|
0
|
384 |
autoRepeat := false.
|
|
385 |
initialDelay := self class defaultInitialDelay.
|
|
386 |
repeatDelay := self class defaultRepeatDelay.
|
|
387 |
isReturnButton := false.
|
|
388 |
!
|
|
389 |
|
|
390 |
initStyle
|
59
|
391 |
|hasGreyscales nm|
|
|
392 |
|
|
393 |
super initStyle.
|
|
394 |
|
|
395 |
DefaultFont notNil ifTrue:[
|
|
396 |
font := DefaultFont on:device
|
|
397 |
].
|
|
398 |
|
|
399 |
DefaultFont notNil ifTrue:[font := DefaultFont on:device].
|
74
|
400 |
DefaultBorderWidth notNil ifTrue:[borderWidth := DefaultBorderWidth].
|
59
|
401 |
DefaultForegroundColor notNil ifTrue:[fgColor := DefaultForegroundColor on:device].
|
|
402 |
DefaultBackgroundColor notNil ifTrue:[bgColor := DefaultBackgroundColor on:device].
|
|
403 |
|
62
|
404 |
edgeStyle := DefaultEdgeStyle.
|
59
|
405 |
onLevel := DefaultActiveLevel.
|
|
406 |
offLevel := DefaultPassiveLevel.
|
|
407 |
|
|
408 |
DefaultDisabledForegroundColor notNil ifTrue:[
|
|
409 |
disabledFgColor := DefaultDisabledForegroundColor on:device
|
|
410 |
] ifFalse:[
|
|
411 |
disabledFgColor := fgColor
|
|
412 |
].
|
|
413 |
|
|
414 |
DefaultEnteredForegroundColor notNil ifTrue:[enteredFgColor := DefaultEnteredForegroundColor on:device].
|
|
415 |
DefaultEnteredBackgroundColor notNil ifTrue:[enteredBgColor := DefaultEnteredBackgroundColor on:device].
|
|
416 |
DefaultActiveForegroundColor notNil ifTrue:[activeFgColor := DefaultActiveForegroundColor on:device].
|
|
417 |
DefaultActiveBackgroundColor notNil ifTrue:[activeBgColor := DefaultActiveBackgroundColor on:device].
|
|
418 |
|
62
|
419 |
DefaultShadowColor notNil ifTrue:[shadowColor := DefaultShadowColor on:device].
|
|
420 |
DefaultLightColor notNil ifTrue:[lightColor := DefaultLightColor on:device].
|
59
|
421 |
|
62
|
422 |
shadowColor isNil ifTrue:[
|
|
423 |
shadowColor := Black.
|
|
424 |
].
|
|
425 |
lightColor isNil ifTrue:[
|
|
426 |
lightColor := White.
|
|
427 |
].
|
59
|
428 |
|
|
429 |
hasGreyscales := device hasGreyscales.
|
62
|
430 |
(edgeStyle == #soft) ifTrue:[
|
|
431 |
DefaultHalfShadowColor notNil ifTrue:[halfShadowColor := DefaultHalfShadowColor on:device].
|
|
432 |
DefaultHalfLightColor notNil ifTrue:[halfLightColor := DefaultHalfLightColor on:device].
|
|
433 |
|
|
434 |
halfShadowColor isNil ifTrue:[
|
|
435 |
"/ hasGreyscales ifTrue:[
|
|
436 |
"/ halfShadowColor := Color darkGrey
|
|
437 |
"/ ] ifFalse:[
|
|
438 |
"/ halfShadowColor := shadowColor
|
|
439 |
"/ ]
|
|
440 |
halfShadowColor := shadowColor lightened
|
59
|
441 |
]
|
|
442 |
].
|
|
443 |
|
62
|
444 |
"
|
|
445 |
actually, the stuf below should not be needed
|
|
446 |
- the styleSheet should provide values for nonGreyscale displays too
|
|
447 |
"
|
59
|
448 |
nm := StyleSheet name asSymbol.
|
62
|
449 |
(nm == #iris) ifTrue:[
|
|
450 |
hasGreyscales ifTrue:[
|
|
451 |
DefaultEnteredBackgroundColor isNil ifTrue:[
|
|
452 |
enteredBgColor := bgColor lightened "Color lightGrey".
|
|
453 |
].
|
|
454 |
DefaultActiveBackgroundColor isNil ifTrue:[
|
|
455 |
activeBgColor := enteredBgColor.
|
|
456 |
].
|
|
457 |
DefaultActiveForegroundColor isNil ifTrue:[
|
|
458 |
activeFgColor := enteredFgColor.
|
59
|
459 |
].
|
|
460 |
] ifFalse:[
|
62
|
461 |
DefaultEnteredBackgroundColor isNil ifTrue:[
|
|
462 |
enteredBgColor := Color veryLightGrey.
|
|
463 |
].
|
|
464 |
DefaultActiveBackgroundColor isNil ifTrue:[
|
|
465 |
activeBgColor := Black.
|
|
466 |
].
|
|
467 |
DefaultActiveForegroundColor isNil ifTrue:[
|
|
468 |
activeFgColor := White.
|
|
469 |
].
|
|
470 |
].
|
|
471 |
] ifFalse:[
|
|
472 |
nm == #motif ifTrue:[
|
|
473 |
lightColor isNil ifTrue:[
|
|
474 |
lightColor := bgColor lightened
|
|
475 |
].
|
|
476 |
"/ hasGreyscales ifTrue:[
|
|
477 |
"/ lightColor := Color lightGrey
|
|
478 |
"/ ]
|
|
479 |
] ifFalse:[
|
|
480 |
nm == #st80 ifTrue:[
|
59
|
481 |
hasGreyscales ifTrue:[
|
62
|
482 |
DefaultActiveForegroundColor isNil ifTrue:[
|
|
483 |
activeFgColor := fgColor.
|
|
484 |
].
|
|
485 |
DefaultActiveBackgroundColor isNil ifTrue:[
|
|
486 |
activeBgColor := bgColor darkened.
|
|
487 |
].
|
|
488 |
] ifFalse:[
|
|
489 |
DefaultActiveForegroundColor isNil ifTrue:[
|
|
490 |
activeFgColor := White.
|
|
491 |
].
|
|
492 |
DefaultActiveBackgroundColor isNil ifTrue:[
|
|
493 |
activeBgColor := Black
|
59
|
494 |
]
|
|
495 |
]
|
|
496 |
]
|
|
497 |
]
|
|
498 |
].
|
|
499 |
|
|
500 |
offLevel ~~ level ifTrue:[
|
|
501 |
self level:offLevel.
|
|
502 |
margin := (onLevel abs) max:(offLevel abs).
|
|
503 |
].
|
|
504 |
|
|
505 |
DefaultReturnButtonHasImage ifTrue:[
|
|
506 |
(StyleSheet is3D and:[hasGreyscales]) ifTrue:[
|
|
507 |
shadowForm := self class returnShadowFormOn:device.
|
|
508 |
lightForm := self class returnLightFormOn:device.
|
|
509 |
formColor := viewBackground.
|
|
510 |
formShadowColor := shadowColor.
|
|
511 |
formLightColor := lightColor
|
|
512 |
] ifFalse:[
|
|
513 |
shadowForm := self class returnFormOn:device.
|
|
514 |
formColor := Black
|
|
515 |
].
|
|
516 |
].
|
|
517 |
!
|
|
518 |
|
0
|
519 |
initCursor
|
|
520 |
"set up a hand cursor"
|
|
521 |
|
|
522 |
cursor := Cursor hand
|
|
523 |
!
|
|
524 |
|
|
525 |
initEvents
|
|
526 |
super initEvents.
|
|
527 |
self enableButtonEvents.
|
|
528 |
self enableEnterLeaveEvents
|
|
529 |
!
|
|
530 |
|
|
531 |
realize
|
|
532 |
super realize.
|
|
533 |
active := false.
|
35
|
534 |
entered := false.
|
0
|
535 |
|
|
536 |
fgColor := fgColor on:device.
|
|
537 |
bgColor := bgColor on:device.
|
18
|
538 |
formColor notNil ifTrue:[
|
59
|
539 |
formColor := formColor on:device.
|
18
|
540 |
].
|
0
|
541 |
!
|
|
542 |
|
|
543 |
reinitialize
|
|
544 |
super reinitialize.
|
59
|
545 |
active := false.
|
|
546 |
entered := false
|
0
|
547 |
! !
|
|
548 |
|
62
|
549 |
!Button methodsFor:'queries'!
|
0
|
550 |
|
|
551 |
is3D
|
|
552 |
"return true, if the receiver is a 3D style view"
|
|
553 |
|
74
|
554 |
StyleSheet name == #mswindows ifTrue:[^ true].
|
0
|
555 |
^ super is3D
|
|
556 |
!
|
|
557 |
|
35
|
558 |
isReturnButton
|
|
559 |
"return true, if this is a return button"
|
|
560 |
|
|
561 |
^ isReturnButton
|
62
|
562 |
! !
|
|
563 |
|
|
564 |
!Button methodsFor:'accessing'!
|
35
|
565 |
|
0
|
566 |
isReturnButton:aBoolean
|
|
567 |
"show/dont show a return-key image after the label"
|
|
568 |
|
|
569 |
isReturnButton ~~ aBoolean ifTrue:[
|
59
|
570 |
DefaultReturnButtonHasBorder ifTrue:[
|
|
571 |
self borderWidth:(aBoolean ifTrue:[1] ifFalse:[0])
|
|
572 |
].
|
|
573 |
isReturnButton := aBoolean.
|
|
574 |
self newLayout
|
0
|
575 |
]
|
|
576 |
!
|
|
577 |
|
|
578 |
disable
|
|
579 |
"disable the button"
|
|
580 |
|
|
581 |
enabled ifTrue:[
|
59
|
582 |
enabled := false.
|
|
583 |
self redraw
|
0
|
584 |
]
|
|
585 |
!
|
|
586 |
|
|
587 |
enable
|
|
588 |
"enable the button"
|
|
589 |
|
|
590 |
enabled ifFalse:[
|
59
|
591 |
enabled := true.
|
|
592 |
self redraw
|
0
|
593 |
]
|
|
594 |
!
|
|
595 |
|
|
596 |
turnOffWithoutRedraw
|
|
597 |
"turn the button off - no redraw"
|
|
598 |
|
|
599 |
pressed := false.
|
|
600 |
active := false.
|
59
|
601 |
|
|
602 |
"do not use super level:offLevel
|
|
603 |
- because that one does redraw the edges.
|
|
604 |
Sure, this is no good coding style"
|
|
605 |
level := offLevel.
|
|
606 |
margin := level abs
|
0
|
607 |
!
|
|
608 |
|
|
609 |
turnOff
|
|
610 |
"turn the button off (if not already off)"
|
|
611 |
|
|
612 |
pressed ifTrue:[
|
59
|
613 |
active := false.
|
|
614 |
pressed := false.
|
|
615 |
self level:offLevel.
|
|
616 |
self redraw
|
0
|
617 |
]
|
|
618 |
!
|
|
619 |
|
|
620 |
turnOn
|
|
621 |
"turn the button on (if not already on)"
|
|
622 |
|
|
623 |
pressed ifFalse:[
|
59
|
624 |
pressed := true.
|
|
625 |
self level:onLevel.
|
|
626 |
self redraw
|
0
|
627 |
]
|
|
628 |
!
|
|
629 |
|
35
|
630 |
pressAction
|
62
|
631 |
"return the pressAction; thats the block which gets evaluated
|
|
632 |
when the button is pressed (if non-nil)"
|
|
633 |
|
35
|
634 |
^ pressActionBlock
|
|
635 |
!
|
|
636 |
|
0
|
637 |
pressAction:aBlock
|
|
638 |
"define the action to be performed on press"
|
|
639 |
|
|
640 |
pressActionBlock := aBlock
|
|
641 |
!
|
|
642 |
|
35
|
643 |
releaseAction
|
62
|
644 |
"return the releaseAction; thats the block which gets evaluated
|
|
645 |
when the button is relreased (if non-nil)"
|
|
646 |
|
35
|
647 |
^ releaseActionBlock
|
|
648 |
!
|
|
649 |
|
0
|
650 |
releaseAction:aBlock
|
|
651 |
"define the action to be performed on release"
|
|
652 |
|
|
653 |
releaseActionBlock := aBlock
|
|
654 |
!
|
|
655 |
|
|
656 |
action:aBlock
|
59
|
657 |
"convenient method: depending on the setting of actionWhenPressed,
|
|
658 |
either set the press-action clear any release-action or
|
|
659 |
vice versa, set the release-action and clear the press-action."
|
0
|
660 |
|
59
|
661 |
actionWhenPressed ifTrue:[
|
|
662 |
releaseActionBlock := nil.
|
|
663 |
pressActionBlock := aBlock
|
|
664 |
] ifFalse:[
|
|
665 |
releaseActionBlock := aBlock.
|
|
666 |
pressActionBlock := nil
|
|
667 |
]
|
0
|
668 |
!
|
|
669 |
|
|
670 |
autoRepeat
|
|
671 |
"turn on autorepeat"
|
|
672 |
|
|
673 |
autoRepeat := true.
|
|
674 |
repeatBlock := [self repeat]
|
|
675 |
!
|
|
676 |
|
|
677 |
isOn
|
|
678 |
"return true, if this button is currently pressed"
|
|
679 |
|
|
680 |
^ pressed
|
|
681 |
!
|
|
682 |
|
|
683 |
onLevel:aNumber
|
|
684 |
"set the level of the button when pressed (i.e. how deep)"
|
|
685 |
|
|
686 |
onLevel := aNumber.
|
|
687 |
pressed ifTrue:[
|
59
|
688 |
self level:onLevel.
|
|
689 |
margin := onLevel abs max:offLevel abs.
|
|
690 |
self redraw
|
0
|
691 |
]
|
|
692 |
!
|
|
693 |
|
|
694 |
onLevel
|
|
695 |
"return the level of the button when pressed"
|
|
696 |
|
|
697 |
^ onLevel
|
|
698 |
!
|
|
699 |
|
|
700 |
offLevel:aNumber
|
|
701 |
"set the level of the button when not pressed (i.e. how high)"
|
|
702 |
|
|
703 |
offLevel := aNumber.
|
|
704 |
pressed ifFalse:[
|
59
|
705 |
self level:offLevel.
|
|
706 |
margin := onLevel abs max:offLevel abs.
|
|
707 |
self redraw
|
0
|
708 |
]
|
|
709 |
!
|
|
710 |
|
|
711 |
offLevel
|
|
712 |
"return the level of the button when released"
|
|
713 |
|
|
714 |
^ offLevel
|
|
715 |
!
|
|
716 |
|
74
|
717 |
edgeStyle:aSymbol
|
|
718 |
"set the edgestyle - currently only #soft or nil"
|
|
719 |
|
|
720 |
edgeStyle := aSymbol
|
|
721 |
!
|
|
722 |
|
59
|
723 |
activeLogo:anImageOrString
|
|
724 |
"define the logo to be displayed while active -
|
|
725 |
this is optional; the default is to display the same
|
|
726 |
(logo) in both pressed and released states."
|
|
727 |
|
|
728 |
activeLogo := anImageOrString.
|
|
729 |
pressed ifTrue:[
|
|
730 |
self logo:anImageOrString
|
|
731 |
]
|
|
732 |
!
|
|
733 |
|
|
734 |
passiveLogo:anImageOrString
|
|
735 |
"define the logo to be displayed while inactive -
|
|
736 |
this is optional; the default is to display the same
|
|
737 |
(logo) in both pressed and released states."
|
|
738 |
|
|
739 |
passiveLogo := anImageOrString.
|
|
740 |
pressed ifFalse:[
|
|
741 |
self logo:anImageOrString
|
|
742 |
]
|
|
743 |
!
|
|
744 |
|
0
|
745 |
activeForegroundColor
|
|
746 |
"return the foreground color to be used when pressed"
|
|
747 |
|
|
748 |
^ activeFgColor
|
|
749 |
!
|
|
750 |
|
|
751 |
activeForegroundColor:aColor
|
|
752 |
"set the foreground color to be used when pressed"
|
|
753 |
|
|
754 |
activeFgColor := aColor.
|
|
755 |
pressed ifTrue:[
|
59
|
756 |
self redraw
|
0
|
757 |
]
|
|
758 |
!
|
|
759 |
|
|
760 |
activeBackgroundColor
|
|
761 |
"return the background color to be used when pressed"
|
|
762 |
|
|
763 |
^ activeBgColor
|
|
764 |
!
|
|
765 |
|
|
766 |
activeBackgroundColor:aColor
|
|
767 |
"set the background color to be used when pressed"
|
|
768 |
|
|
769 |
activeBgColor := aColor.
|
|
770 |
pressed ifTrue:[
|
59
|
771 |
self redraw
|
0
|
772 |
]
|
|
773 |
!
|
|
774 |
|
|
775 |
activeForegroundColor:fgColor backgroundColor:bgColor
|
|
776 |
"set the colors to be used when pressed"
|
|
777 |
|
|
778 |
activeFgColor := fgColor.
|
|
779 |
activeBgColor := bgColor.
|
|
780 |
pressed ifTrue:[
|
59
|
781 |
self redraw
|
0
|
782 |
]
|
|
783 |
!
|
|
784 |
|
|
785 |
enteredForegroundColor
|
|
786 |
"return the foreground color to be used when the mouse
|
|
787 |
pointer enters the button area"
|
|
788 |
|
|
789 |
^ enteredFgColor
|
|
790 |
!
|
|
791 |
|
|
792 |
enteredForegroundColor:aColor
|
|
793 |
"set the foreground color to be used when the mouse
|
|
794 |
pointer enters the button area"
|
|
795 |
|
|
796 |
enteredFgColor := aColor
|
|
797 |
!
|
|
798 |
|
|
799 |
enteredBackgroundColor
|
|
800 |
"return the background color to be used when the mouse
|
|
801 |
pointer enters the button area"
|
|
802 |
|
|
803 |
^ enteredBgColor
|
|
804 |
!
|
|
805 |
|
|
806 |
enteredBackgroundColor:aColor
|
|
807 |
"set the background color to be used when the mouse
|
|
808 |
pointer enters the button area"
|
|
809 |
|
|
810 |
enteredBgColor := aColor
|
|
811 |
! !
|
|
812 |
|
35
|
813 |
!Button methodsFor:'queries'!
|
|
814 |
|
59
|
815 |
preferedExtent
|
|
816 |
"return my prefered extent - this is the minimum size I would like to have"
|
35
|
817 |
|
|
818 |
|extra|
|
|
819 |
|
|
820 |
logo notNil ifTrue:[
|
59
|
821 |
extra := (onLevel abs max:offLevel abs) * 2.
|
|
822 |
self is3D ifFalse:[
|
|
823 |
"/ (logo isKindOf:Form) ifFalse:[
|
|
824 |
"add space for a frame around"
|
|
825 |
extra := extra + 2.
|
|
826 |
"/ ]
|
|
827 |
].
|
|
828 |
^ (labelWidth + extra) @ (labelHeight + extra)
|
35
|
829 |
].
|
|
830 |
|
59
|
831 |
^ super preferedExtent
|
35
|
832 |
! !
|
|
833 |
|
0
|
834 |
!Button methodsFor:'private'!
|
|
835 |
|
62
|
836 |
computeLabelOrigin
|
|
837 |
"compute the origin of the text - if I am a returnButton,
|
|
838 |
shift it somwehat to the right (we have already allocated the
|
|
839 |
real estate, since computeLabelSize returned some extra space
|
|
840 |
before)."
|
|
841 |
|
|
842 |
super computeLabelOrigin.
|
|
843 |
(isReturnButton and:[shadowForm notNil]) ifTrue:[
|
|
844 |
labelOriginX := labelOriginX + hSpace + hSpace.
|
|
845 |
]
|
|
846 |
!
|
|
847 |
|
0
|
848 |
computeLabelSize
|
|
849 |
"compute the extent needed to hold the label plus the return form"
|
|
850 |
|
|
851 |
super computeLabelSize.
|
59
|
852 |
(isReturnButton and:[shadowForm notNil]) ifTrue:[
|
62
|
853 |
labelWidth := labelWidth + (hSpace * 2) + shadowForm width.
|
59
|
854 |
labelHeight := labelHeight max: (shadowForm height + vSpace)
|
0
|
855 |
]
|
|
856 |
!
|
|
857 |
|
|
858 |
resize
|
|
859 |
"resize myself to make logo fit into myself.
|
|
860 |
Redefined, since we add space for a frame around text when non-3D"
|
|
861 |
|
|
862 |
|extra|
|
|
863 |
|
|
864 |
logo isNil ifFalse:[
|
59
|
865 |
self computeLabelOrigin.
|
|
866 |
(relativeExtent isNil and:[extentRule isNil]) ifTrue:[
|
|
867 |
extra := (onLevel abs max:offLevel abs) * 2.
|
|
868 |
StyleSheet is3D ifFalse:[
|
|
869 |
"/ (logo isKindOf:Form) ifFalse:[
|
|
870 |
"add space for a rectangle around"
|
|
871 |
extra := extra + 2
|
|
872 |
"/ ]
|
|
873 |
].
|
|
874 |
self extent:(labelWidth + extra) @ (labelHeight + extra)
|
|
875 |
]
|
0
|
876 |
]
|
|
877 |
! !
|
|
878 |
|
|
879 |
!Button methodsFor:'redrawing'!
|
|
880 |
|
62
|
881 |
drawEdges
|
|
882 |
"draw all of my 3D edges"
|
|
883 |
|
|
884 |
self drawEdgesForX:0 y:0 width:width height:height level:level
|
|
885 |
shadow:shadowColor
|
|
886 |
light:lightColor
|
|
887 |
halfShadow:halfShadowColor
|
|
888 |
halfLight:halfLightColor
|
|
889 |
style:edgeStyle
|
|
890 |
!
|
|
891 |
|
|
892 |
drawLeftEdge
|
|
893 |
"draw left 3D edge into window frame"
|
|
894 |
|
|
895 |
self drawLeftEdgeLevel:level
|
|
896 |
shadow:shadowColor
|
|
897 |
light:lightColor
|
|
898 |
halfShadow:halfShadowColor
|
|
899 |
halfLight:halfLightColor
|
|
900 |
style:edgeStyle.
|
|
901 |
!
|
|
902 |
|
|
903 |
drawRightEdge
|
|
904 |
"draw right 3D edge into window frame"
|
|
905 |
|
|
906 |
self drawRightEdgeLevel:level
|
|
907 |
shadow:shadowColor
|
|
908 |
light:lightColor
|
|
909 |
halfShadow:halfShadowColor
|
|
910 |
halfLight:halfLightColor
|
|
911 |
style:edgeStyle.
|
|
912 |
!
|
|
913 |
|
|
914 |
drawTopEdge
|
|
915 |
"draw top 3D edge into window frame"
|
|
916 |
|
|
917 |
self drawTopEdgeLevel:level
|
|
918 |
shadow:shadowColor
|
|
919 |
light:lightColor
|
|
920 |
halfShadow:halfShadowColor
|
|
921 |
halfLight:halfLightColor
|
|
922 |
style:edgeStyle.
|
|
923 |
!
|
|
924 |
|
|
925 |
drawBottomEdge
|
|
926 |
"draw bottom 3D edge into window frame"
|
|
927 |
|
|
928 |
self drawBottomEdgeLevel:level
|
|
929 |
shadow:shadowColor
|
|
930 |
light:lightColor
|
|
931 |
halfShadow:halfShadowColor
|
|
932 |
halfLight:halfLightColor
|
|
933 |
style:edgeStyle.
|
|
934 |
!
|
|
935 |
|
0
|
936 |
drawWith:fg and:bg
|
|
937 |
"redraw myself with fg/bg. Use super to draw the label, add
|
|
938 |
the return-arrow here."
|
|
939 |
|
18
|
940 |
|x y sColor lColor|
|
0
|
941 |
|
59
|
942 |
shown ifFalse:[^ self].
|
0
|
943 |
super drawWith:fg and:bg. "this draws the text"
|
|
944 |
|
59
|
945 |
(isReturnButton and:[shadowForm notNil]) ifTrue:[
|
|
946 |
y := (height - shadowForm height) // 2.
|
|
947 |
x := width - shadowForm width - (hSpace // 2).
|
|
948 |
|
|
949 |
formShadowColor isNil ifTrue:[
|
|
950 |
self paint:fg on:bg.
|
|
951 |
self background:bg.
|
|
952 |
self displayOpaqueForm:shadowForm x:x y:y.
|
|
953 |
^ self
|
|
954 |
].
|
0
|
955 |
|
59
|
956 |
"
|
|
957 |
drawing form in 3d-style (i.e. with shadow and light)
|
|
958 |
"
|
|
959 |
(formShadowColor isColor and:[formShadowColor colorId notNil
|
|
960 |
and:[formLightColor isColor and:[formLightColor colorId notNil
|
|
961 |
and:[formColor isColor and:[formColor colorId notNil]]]]])
|
|
962 |
ifTrue:[
|
|
963 |
sColor := formShadowColor.
|
|
964 |
lColor := formLightColor.
|
|
965 |
] ifFalse:[
|
|
966 |
sColor := Black.
|
|
967 |
lColor := White.
|
|
968 |
].
|
|
969 |
self foreground:sColor.
|
|
970 |
self displayForm:shadowForm x:x y:y.
|
35
|
971 |
|
59
|
972 |
lightForm notNil ifTrue:[
|
|
973 |
self foreground:lColor.
|
|
974 |
self displayForm:lightForm x:x y:y.
|
|
975 |
].
|
|
976 |
self paint:fg.
|
0
|
977 |
]
|
|
978 |
!
|
|
979 |
|
59
|
980 |
showPassive
|
|
981 |
"redraw myself passive"
|
|
982 |
|
|
983 |
offLevel ~~ level ifTrue:[
|
|
984 |
self level:offLevel.
|
|
985 |
].
|
|
986 |
(passiveLogo notNil and:[passiveLogo ~~ logo]) ifTrue:[
|
|
987 |
self logo:passiveLogo
|
|
988 |
].
|
|
989 |
self redraw.
|
|
990 |
!
|
|
991 |
|
|
992 |
showActive
|
|
993 |
"redraw myself active"
|
|
994 |
|
|
995 |
onLevel ~~ level ifTrue:[
|
|
996 |
self level:onLevel.
|
|
997 |
].
|
|
998 |
(activeLogo notNil and:[activeLogo ~~ logo]) ifTrue:[
|
|
999 |
self logo:activeLogo
|
|
1000 |
].
|
|
1001 |
self redraw.
|
|
1002 |
!
|
|
1003 |
|
0
|
1004 |
redraw
|
|
1005 |
"like redrawing a label, but hilight when pressed
|
|
1006 |
(lolight when disabled)"
|
|
1007 |
|
|
1008 |
|fg bg|
|
|
1009 |
|
62
|
1010 |
shown ifFalse:[^ self].
|
|
1011 |
active ifTrue:[^ self].
|
35
|
1012 |
|
62
|
1013 |
fg := fgColor.
|
|
1014 |
bg := bgColor.
|
|
1015 |
enabled ifFalse:[
|
|
1016 |
fg := disabledFgColor
|
|
1017 |
] ifTrue:[
|
|
1018 |
entered ifTrue:[
|
|
1019 |
enteredFgColor notNil ifTrue:[fg := enteredFgColor].
|
|
1020 |
enteredBgColor notNil ifTrue:[bg := enteredBgColor]
|
|
1021 |
].
|
|
1022 |
(pressed and:[entered or:[actionWhenPressed]]) ifTrue:[
|
|
1023 |
activeFgColor isNil ifTrue:[
|
|
1024 |
onLevel == offLevel ifTrue:[
|
|
1025 |
fg := bgColor
|
|
1026 |
]
|
|
1027 |
] ifFalse:[
|
|
1028 |
fg := activeFgColor.
|
59
|
1029 |
].
|
62
|
1030 |
activeBgColor isNil ifTrue:[
|
|
1031 |
onLevel == offLevel ifTrue:[
|
|
1032 |
bg := fgColor
|
|
1033 |
]
|
|
1034 |
] ifFalse:[
|
|
1035 |
bg := activeBgColor
|
|
1036 |
].
|
|
1037 |
self is3D ifFalse:[
|
|
1038 |
self drawWith:fg and:bg .
|
|
1039 |
"
|
|
1040 |
draw a rectangle around
|
|
1041 |
"
|
|
1042 |
self paint:fg.
|
|
1043 |
self displayRectangleX:0 y:0 width:width height:height.
|
|
1044 |
|
|
1045 |
^ self
|
|
1046 |
].
|
|
1047 |
].
|
|
1048 |
].
|
|
1049 |
self drawWith:fg and:bg
|
0
|
1050 |
! !
|
|
1051 |
|
|
1052 |
!Button methodsFor:'event handling'!
|
|
1053 |
|
|
1054 |
buttonPress:button x:x y:y
|
|
1055 |
"button was pressed - if enabled, perform pressaction"
|
|
1056 |
|
35
|
1057 |
(button == 1 or:[button == #select]) ifFalse:[
|
59
|
1058 |
^ super buttonPress:button x:x y:y
|
0
|
1059 |
].
|
|
1060 |
pressed ifFalse:[
|
59
|
1061 |
enabled ifTrue:[
|
|
1062 |
pressed := true.
|
|
1063 |
self showActive.
|
|
1064 |
|
|
1065 |
(pressActionBlock notNil or:[model notNil]) ifTrue:[
|
|
1066 |
"
|
|
1067 |
force output - so that button is drawn correctly in case
|
|
1068 |
of any long-computation (at high priority)
|
|
1069 |
"
|
|
1070 |
device synchronizeOutput.
|
|
1071 |
].
|
|
1072 |
|
|
1073 |
active := true.
|
35
|
1074 |
|
59
|
1075 |
pressActionBlock notNil ifTrue:[
|
|
1076 |
pressActionBlock value
|
|
1077 |
].
|
35
|
1078 |
|
59
|
1079 |
actionWhenPressed ifTrue:[
|
|
1080 |
"the ST-80 way of doing things"
|
|
1081 |
(model notNil and:[changeSymbol notNil]) ifTrue:[
|
|
1082 |
model perform:changeSymbol
|
|
1083 |
].
|
|
1084 |
].
|
0
|
1085 |
|
59
|
1086 |
active := false.
|
|
1087 |
|
|
1088 |
autoRepeat ifTrue:[
|
|
1089 |
Processor addTimedBlock:repeatBlock afterSeconds:initialDelay
|
|
1090 |
]
|
|
1091 |
]
|
0
|
1092 |
]
|
|
1093 |
!
|
|
1094 |
|
|
1095 |
buttonMultiPress:button x:x y:y
|
|
1096 |
^ self buttonPress:button x:x y:y
|
|
1097 |
!
|
|
1098 |
|
|
1099 |
buttonRelease:button x:x y:y
|
|
1100 |
"button was released - if enabled, perform releaseaction"
|
|
1101 |
|
35
|
1102 |
(button == 1 or:[button == #select]) ifFalse:[
|
59
|
1103 |
^ super buttonRelease:button x:x y:y
|
0
|
1104 |
].
|
|
1105 |
pressed ifTrue:[
|
59
|
1106 |
autoRepeat ifTrue:[
|
|
1107 |
Processor removeTimedBlock:repeatBlock
|
|
1108 |
].
|
|
1109 |
pressed := false.
|
|
1110 |
self showPassive.
|
|
1111 |
enabled ifTrue:[
|
|
1112 |
"
|
|
1113 |
only perform action if released within myself
|
|
1114 |
"
|
|
1115 |
((x >= 0)
|
|
1116 |
and:[x <= width
|
|
1117 |
and:[y >= 0
|
|
1118 |
and:[y <= height]]]) ifTrue:[
|
|
1119 |
|
|
1120 |
(releaseActionBlock notNil or:[model notNil]) ifTrue:[
|
|
1121 |
"
|
|
1122 |
force output - so that button is drawn correctly in case
|
|
1123 |
of any long-computation (at high priority)
|
|
1124 |
"
|
|
1125 |
device synchronizeOutput.
|
|
1126 |
].
|
|
1127 |
|
|
1128 |
active := true.
|
|
1129 |
|
|
1130 |
releaseActionBlock notNil ifTrue:[
|
|
1131 |
releaseActionBlock value
|
|
1132 |
].
|
|
1133 |
actionWhenPressed ifFalse:[
|
|
1134 |
"the ST-80 way of doing things"
|
|
1135 |
(model notNil and:[changeSymbol notNil]) ifTrue:[
|
|
1136 |
model perform:changeSymbol
|
|
1137 |
].
|
|
1138 |
].
|
|
1139 |
|
|
1140 |
active := false.
|
|
1141 |
|
|
1142 |
enteredFgColor notNil ifTrue:[
|
|
1143 |
self drawWith:enteredFgColor and:enteredBgColor
|
|
1144 |
]
|
|
1145 |
]
|
|
1146 |
]
|
0
|
1147 |
]
|
|
1148 |
!
|
|
1149 |
|
74
|
1150 |
keyPress:key x:x y:y
|
|
1151 |
"only trigger, if I am the focusView of my group"
|
|
1152 |
|
|
1153 |
(windowGroup notNil and:[windowGroup focusView == self]) ifTrue:[
|
|
1154 |
(key == #Return or:[key == Character space]) ifTrue:[
|
|
1155 |
"just simulate a buttonPress/release here."
|
|
1156 |
self buttonPress:1 x:0 y:0.
|
|
1157 |
self buttonRelease:1 x:0 y:0.
|
|
1158 |
^ self.
|
|
1159 |
]
|
|
1160 |
].
|
|
1161 |
super keyPress:key x:x y:y
|
|
1162 |
!
|
|
1163 |
|
0
|
1164 |
pointerLeave:state
|
|
1165 |
"redraw with normal colors if they differ from enteredColors"
|
|
1166 |
|
59
|
1167 |
entered := false.
|
0
|
1168 |
pressed ifTrue:[
|
59
|
1169 |
"
|
|
1170 |
leave with mouse-button down;
|
|
1171 |
stop autorepeating and/or if I am a button with
|
|
1172 |
action on release, show passive
|
|
1173 |
"
|
|
1174 |
autoRepeat ifTrue:[
|
|
1175 |
Processor removeTimedBlock:repeatBlock
|
|
1176 |
].
|
|
1177 |
actionWhenPressed ifFalse:[
|
|
1178 |
self showPassive.
|
|
1179 |
]
|
0
|
1180 |
] ifFalse:[
|
59
|
1181 |
enabled ifTrue:[
|
|
1182 |
((enteredFgColor notNil and:[enteredFgColor ~~ fgColor])
|
|
1183 |
or:[enteredBgColor notNil and:[enteredBgColor ~~ bgColor]]) ifTrue:[
|
|
1184 |
self redraw
|
|
1185 |
]
|
|
1186 |
]
|
0
|
1187 |
]
|
|
1188 |
!
|
|
1189 |
|
|
1190 |
pointerEnter:state x:x y:y
|
|
1191 |
"redraw with enteredColors if they differ from the normal colors"
|
|
1192 |
|
59
|
1193 |
entered := true.
|
0
|
1194 |
pressed ifTrue:[
|
59
|
1195 |
"
|
|
1196 |
reentered after a leave with mouse-button down;
|
|
1197 |
restart autorepeating and/or if I am a button with
|
|
1198 |
actionWhenReleased, show active again.
|
|
1199 |
"
|
|
1200 |
enabled ifTrue:[
|
|
1201 |
autoRepeat ifTrue:[
|
|
1202 |
Processor addTimedBlock:repeatBlock afterSeconds:initialDelay
|
|
1203 |
].
|
|
1204 |
actionWhenPressed ifFalse:[
|
|
1205 |
self showActive.
|
|
1206 |
]
|
|
1207 |
]
|
0
|
1208 |
] ifFalse:[
|
59
|
1209 |
enabled ifTrue:[
|
|
1210 |
((enteredFgColor notNil and:[enteredFgColor ~~ fgColor])
|
|
1211 |
or:[enteredBgColor notNil and:[enteredBgColor ~~ bgColor]]) ifTrue:[
|
|
1212 |
self redraw
|
|
1213 |
]
|
|
1214 |
]
|
0
|
1215 |
]
|
|
1216 |
!
|
|
1217 |
|
|
1218 |
repeat
|
|
1219 |
"this is sent from the autorepeat-block, when the button has been pressed long
|
59
|
1220 |
enough; it simulates a release-press, by evaluating both release
|
|
1221 |
and press actions."
|
0
|
1222 |
|
|
1223 |
pressed ifTrue:[
|
59
|
1224 |
enabled ifTrue:[
|
|
1225 |
active ifFalse:[
|
|
1226 |
active := true.
|
|
1227 |
releaseActionBlock notNil ifTrue:[releaseActionBlock value].
|
|
1228 |
pressActionBlock notNil ifTrue:[pressActionBlock value].
|
|
1229 |
active := false.
|
35
|
1230 |
"/ device synchronizeOutput.
|
0
|
1231 |
|
59
|
1232 |
autoRepeat ifTrue:[
|
|
1233 |
Processor addTimedBlock:repeatBlock afterSeconds:repeatDelay
|
|
1234 |
]
|
|
1235 |
]
|
|
1236 |
]
|
0
|
1237 |
]
|
|
1238 |
! !
|