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 |
onLevel offLevel
|
|
16 |
disabledFgColor
|
|
17 |
activeFgColor activeBgColor
|
|
18 |
enteredFgColor enteredBgColor
|
|
19 |
isReturnButton
|
|
20 |
shadowForm lightForm
|
62
|
21 |
formColor formShadowColor formLightColor
|
|
22 |
edgeStyle halfShadowColor halfLightColor'
|
|
23 |
|
59
|
24 |
classVariableNames:'ReturnForm ReturnLightForm ReturnShadowForm
|
|
25 |
DefaultFont DefaultActiveLevel
|
95
|
26 |
DefaultPassiveLevel DefaultEdgeStyle DefaultBorderWidth
|
59
|
27 |
DefaultForegroundColor DefaultBackgroundColor
|
|
28 |
DefaultDisabledForegroundColor DefaultDisabledBackgroundColor
|
|
29 |
DefaultEnteredForegroundColor DefaultEnteredBackgroundColor
|
|
30 |
DefaultActiveForegroundColor DefaultActiveBackgroundColor
|
62
|
31 |
DefaultReturnButtonHasImage DefaultReturnButtonHasBorder
|
|
32 |
DefaultShadowColor DefaultLightColor
|
|
33 |
DefaultHalfShadowColor DefaultHalfLightColor'
|
0
|
34 |
poolDictionaries:''
|
|
35 |
category:'Views-Interactors'
|
|
36 |
!
|
|
37 |
|
|
38 |
Button comment:'
|
4
|
39 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
40 |
All Rights Reserved
|
0
|
41 |
|
131
|
42 |
$Header: /cvs/stx/stx/libwidg/Button.st,v 1.25 1995-06-27 02:22:17 claus Exp $
|
0
|
43 |
'!
|
|
44 |
|
|
45 |
!Button class methodsFor:'documentation'!
|
|
46 |
|
35
|
47 |
copyright
|
|
48 |
"
|
|
49 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
50 |
All Rights Reserved
|
35
|
51 |
|
|
52 |
This software is furnished under a license and may be used
|
|
53 |
only in accordance with the terms of that license and with the
|
|
54 |
inclusion of the above copyright notice. This software may not
|
|
55 |
be provided or otherwise made available to, or used by, any
|
|
56 |
other person. No title to or ownership of the software is
|
|
57 |
hereby transferred.
|
|
58 |
"
|
|
59 |
!
|
|
60 |
|
|
61 |
version
|
|
62 |
"
|
131
|
63 |
$Header: /cvs/stx/stx/libwidg/Button.st,v 1.25 1995-06-27 02:22:17 claus Exp $
|
35
|
64 |
"
|
|
65 |
!
|
|
66 |
|
0
|
67 |
documentation
|
|
68 |
"
|
|
69 |
Buttons are Labels which do something when pressed/released.
|
113
|
70 |
Since they inherit from Label, read the documentation on Labels to
|
|
71 |
see how color, layout, font, image or labelString are changed.
|
|
72 |
|
|
73 |
Actionblock operation:
|
|
74 |
button has an actionBlock (actually, it has two: a pressAction and
|
|
75 |
a releaseAction) which are evaluated.
|
|
76 |
The user of a button can define these actions via the #action,
|
|
77 |
#pressAction or #releaseAction messages.
|
|
78 |
|
|
79 |
Model-View interaction:
|
118
|
80 |
buttons with a model and a labelMsg react to changes of the aspect
|
|
81 |
and perform a labelMsg-message on the model to aquire a new labelString.
|
113
|
82 |
The model is should send 'self changed:<aspect>' if it wants the label to
|
118
|
83 |
change and return a string from the labelSymbol-message.
|
|
84 |
By default, the labelMsg is nil, therefore no update of the label is done.
|
|
85 |
(this behavior is inherited from label, see documentation there)
|
|
86 |
|
|
87 |
When pressed, the button sends a <change> message to the model.
|
|
88 |
If the changeMsg is for a one-argument message, the current
|
113
|
89 |
press-state is passed as argument (i.e. true if pressed, false if released).
|
118
|
90 |
By default, the change-Message is #value: (for ST-80 compatibility).
|
113
|
91 |
|
|
92 |
button model:aModel.
|
|
93 |
button aspect:aspectSymbol.
|
|
94 |
button change:changeSymbol.
|
|
95 |
|
|
96 |
model sends #changed:aspectSymbol
|
|
97 |
---> button will redraw its label from value of model>>aspectSymbol
|
|
98 |
|
|
99 |
button changes state:
|
|
100 |
---> button sends changeSymbolSymbol / changeSymbol:state
|
|
101 |
|
118
|
102 |
By default (as inherited), the labelMsg is nil; therefore, buttons
|
|
103 |
do not try to aquire a new labelString from the model.
|
|
104 |
If you want this behavior, you must set labelMsg and aspectMsg
|
|
105 |
as appropriate.
|
0
|
106 |
|
|
107 |
Instance variables:
|
|
108 |
|
59
|
109 |
activeLogo <StringOrImage> logo to show when active (pressed)
|
|
110 |
passiveLogo <StringOrImage> logo to show when passive (released)
|
|
111 |
default is nil for both, so the normal logo is used
|
|
112 |
(see superclass: Label)
|
35
|
113 |
onLevel <Integer> level when pressed (3D only) (default: depends on style)
|
|
114 |
offLevel <Integer> level when released (3D only) (default: depends on style)
|
|
115 |
disabledFgColor <Color> color used to draw logo when disabled (default: depends on style)
|
|
116 |
activeFgColor <Color> color to draw logo when pressed (default: depends on style)
|
|
117 |
activeBgColor <Color> bg color when pressed (default: depends on style)
|
|
118 |
enteredFgColor <Color> fg color to draw logo when cursor entered (default: depends on style)
|
|
119 |
enteredBgColor <Color> bg color when cursor entered (default: depends on style)
|
0
|
120 |
|
35
|
121 |
isReturnButton <Boolean> true if this button is also activated by the
|
59
|
122 |
return key - if true, it will draw a return-bitmap
|
|
123 |
in addition to the logo (default: false)
|
35
|
124 |
|
59
|
125 |
shadowForm <Form> form to display in addition to buttons label (returnbutton only)
|
|
126 |
lightForm <Form> light part of shadowForm (returnbutton only)
|
|
127 |
|
|
128 |
formColor <Color> color to draw form with (returnbutton only)
|
|
129 |
formShadowColor <Color> color for shadowing the form (3D only & return)
|
35
|
130 |
formLightColor <Color> color for lighting the form (3D only)
|
|
131 |
|
62
|
132 |
|
|
133 |
styleSheet parameters:
|
|
134 |
|
|
135 |
buttonActiveLevel <Integer> level when on (ignored in 2D styles)
|
|
136 |
buttonPassiveLevel <Integer> level when off (ignored in 2D styles)
|
74
|
137 |
buttonBorderWidth <Integer> default borderwidth
|
62
|
138 |
buttonEdgeStyle <Symbol> style of edges (currently #soft or nil)
|
|
139 |
buttonFont <Font> font to use for textual labels
|
|
140 |
buttonForegroundColor <Color> color to draw foreground pixels (i.e. the string)
|
|
141 |
buttonBackgroundColor <Color> color to draw background pixels
|
|
142 |
buttonDisabledForegroundColor <Color> same when disabled
|
|
143 |
buttonDisabledBackgroundColor <Color> same when disabled
|
|
144 |
buttonEnteredForegroundColor <Color> same when mouse pointer is in
|
|
145 |
buttonEnteredBackgroundColor <Color> same when mouse pointer is in
|
|
146 |
buttonActiveForegroundColor <Color> same when button is active
|
|
147 |
buttonActiveBackgroundColor <Color> same when button is active
|
|
148 |
buttonShadowColor <Color> shadow color for edgaes (ignored in 2D styles)
|
|
149 |
buttonLightColor <Color> light color for edgaes (ignored in 2D styles)
|
|
150 |
buttonHalfShadowColor <Color> half shadow color; for soft edges only
|
|
151 |
buttonHalfLightColor <Color> half light color; for soft edges only
|
|
152 |
|
|
153 |
buttonReturnButtonHasImage <Boolean> if true, return-buttons draw a return-key image
|
|
154 |
buttonReturnButtonHasBorder <Boolean> if true, return-buttons show a border
|
130
|
155 |
|
|
156 |
See examples.
|
|
157 |
|
|
158 |
See also: Toggle CheckToggle CheckBox
|
62
|
159 |
"
|
|
160 |
!
|
|
161 |
|
|
162 |
examples
|
|
163 |
"
|
|
164 |
You dont have to normally care for all the internals
|
35
|
165 |
(they allow many variations though). The typical use is:
|
|
166 |
|
59
|
167 |
b := Button label:'some logo' in:aView.
|
|
168 |
b action:[ .. things to do, when pressed ... ]
|
35
|
169 |
|
62
|
170 |
for buttons with a string-label,
|
|
171 |
and:
|
|
172 |
|
118
|
173 |
b := Button label:someImage in:aView.
|
62
|
174 |
b action:[ .. things to do, when pressed ... ]
|
|
175 |
|
|
176 |
for buttons with a bitmap label.
|
|
177 |
|
118
|
178 |
|
88
|
179 |
Although you can specify a lot in a button,
|
|
180 |
use the default in most applications.
|
|
181 |
As you specify more things in your program,
|
|
182 |
the styleSheet settings are more and more ignored.
|
|
183 |
Also, even though it might look fancy, colorful
|
|
184 |
button panels are usually not a good GUI design;
|
|
185 |
they will attract the users attention - possibly to things
|
|
186 |
which are not worth it.
|
130
|
187 |
Finally, if you use fancy colors, always thing of those without
|
|
188 |
color displays - the styleSheet allows those people to adjust things,
|
|
189 |
while hard-coded colors cannot be fixed without changing the code.
|
88
|
190 |
|
|
191 |
default settings:
|
|
192 |
|
|
193 |
|top b|
|
|
194 |
|
|
195 |
top := StandardSystemView new.
|
|
196 |
top extent:100@100.
|
|
197 |
|
118
|
198 |
b := Button in:top.
|
113
|
199 |
b label:'hello'.
|
88
|
200 |
b action:[Transcript flash].
|
|
201 |
top open.
|
|
202 |
|
|
203 |
|
113
|
204 |
there is also a combined instance creation message:
|
|
205 |
|
|
206 |
|top b|
|
|
207 |
|
|
208 |
top := StandardSystemView new.
|
|
209 |
top extent:100@100.
|
|
210 |
|
|
211 |
b := Button label:'hello' action:[Transcript flash] in:top.
|
|
212 |
top open.
|
|
213 |
|
|
214 |
|
88
|
215 |
changing colors:
|
|
216 |
|
|
217 |
|top b|
|
|
218 |
|
|
219 |
top := StandardSystemView new.
|
|
220 |
top extent:100@100.
|
|
221 |
|
|
222 |
b := Button label:'hello' in:top.
|
|
223 |
b action:[Transcript flash].
|
|
224 |
b activeForegroundColor:(Color white).
|
|
225 |
b activeBackgroundColor:(Color red).
|
|
226 |
top open.
|
|
227 |
|
|
228 |
|
|
229 |
changing more colors:
|
|
230 |
|
|
231 |
|top b|
|
|
232 |
|
|
233 |
top := StandardSystemView new.
|
|
234 |
top extent:100@100.
|
|
235 |
|
|
236 |
b := Button label:'hello' in:top.
|
|
237 |
b action:[Transcript flash].
|
|
238 |
b enteredForegroundColor:(Color red).
|
|
239 |
b enteredBackgroundColor:(b backgroundColor).
|
|
240 |
b activeForegroundColor:(Color white).
|
|
241 |
b activeBackgroundColor:(Color red).
|
|
242 |
top open.
|
|
243 |
|
|
244 |
|
113
|
245 |
button with an image and different colors:
|
88
|
246 |
|
|
247 |
|top b|
|
|
248 |
|
|
249 |
top := StandardSystemView new.
|
|
250 |
top extent:100@100.
|
|
251 |
|
|
252 |
b := Button in:top.
|
118
|
253 |
b label:(Image fromFile:'bitmaps/SBrowser.xbm').
|
88
|
254 |
b action:[Transcript flash].
|
|
255 |
b enteredForegroundColor:(Color green darkened).
|
|
256 |
b enteredBackgroundColor:(b backgroundColor).
|
|
257 |
b activeForegroundColor:(Color white).
|
|
258 |
b activeBackgroundColor:(Color red).
|
|
259 |
top open.
|
|
260 |
|
|
261 |
|
118
|
262 |
changing the image when pressed:
|
88
|
263 |
|
|
264 |
|top b|
|
|
265 |
|
|
266 |
top := StandardSystemView new.
|
|
267 |
top extent:100@100.
|
62
|
268 |
|
88
|
269 |
b := Button in:top.
|
|
270 |
b passiveLogo:(Image fromFile:'bitmaps/SBrowser.xbm').
|
|
271 |
b activeLogo:(Image fromFile:'bitmaps/CBrowser.xbm').
|
|
272 |
b action:[Transcript flash].
|
|
273 |
b enteredForegroundColor:(Color red).
|
|
274 |
b enteredBackgroundColor:(b backgroundColor).
|
|
275 |
b activeForegroundColor:(Color white).
|
|
276 |
b activeBackgroundColor:(Color red).
|
|
277 |
top open.
|
|
278 |
|
|
279 |
|
113
|
280 |
well, even that is possible (but you should NEVER do it):
|
88
|
281 |
(notice the changing size and the resulting problem when
|
113
|
282 |
pressed near the bottom, since the button thinks the pointer
|
118
|
283 |
leaves the view and changes back and forth ...)
|
88
|
284 |
|
|
285 |
|top b|
|
|
286 |
|
|
287 |
top := StandardSystemView new.
|
|
288 |
top extent:100@100.
|
|
289 |
|
|
290 |
b := Button in:top.
|
|
291 |
b passiveLogo:(Image fromFile:'bitmaps/SmalltalkX.xbm').
|
|
292 |
b activeLogo:#('start') asStringCollection.
|
|
293 |
b action:[Transcript flash].
|
|
294 |
b enteredForegroundColor:(Color red).
|
|
295 |
b enteredBackgroundColor:(b backgroundColor).
|
|
296 |
b activeForegroundColor:(Color white).
|
|
297 |
b activeBackgroundColor:(Color red).
|
|
298 |
top open.
|
|
299 |
|
|
300 |
|
113
|
301 |
same as above, with frozen size to avoid the problem.
|
88
|
302 |
(make certain, that the size is ok for all possible logos):
|
|
303 |
|
|
304 |
|top b|
|
|
305 |
|
|
306 |
top := StandardSystemView new.
|
|
307 |
top extent:100@100.
|
|
308 |
|
|
309 |
b := Button in:top.
|
|
310 |
b passiveLogo:(Image fromFile:'bitmaps/SmalltalkX.xbm').
|
|
311 |
b activeLogo:#('go') asStringCollection.
|
|
312 |
b action:[Transcript flash].
|
|
313 |
b enteredForegroundColor:(Color red).
|
|
314 |
b enteredBackgroundColor:(b backgroundColor).
|
|
315 |
b activeForegroundColor:(Color white).
|
|
316 |
b activeBackgroundColor:(Color red).
|
|
317 |
b sizeFixed:true.
|
|
318 |
top open.
|
|
319 |
|
|
320 |
|
|
321 |
more playing with colors:
|
|
322 |
|
|
323 |
|top b|
|
|
324 |
|
|
325 |
top := StandardSystemView new.
|
|
326 |
top extent:100@100.
|
|
327 |
|
|
328 |
b := Button in:top.
|
130
|
329 |
b logo:(Image fromFile:'bitmaps/SmalltalkX.xbm').
|
|
330 |
b action:[Transcript flash].
|
|
331 |
b foregroundColor:(Color red:0 green:80 blue:20) darkened.
|
|
332 |
b backgroundColor:(Color grey:10).
|
|
333 |
b enteredForegroundColor:(Color red).
|
|
334 |
b activeForegroundColor:(Color red).
|
|
335 |
b activeBackgroundColor:(Color grey:10).
|
|
336 |
top open.
|
|
337 |
|
|
338 |
|
|
339 |
more playing with colors:
|
|
340 |
|
|
341 |
|top b|
|
|
342 |
|
|
343 |
top := StandardSystemView new.
|
|
344 |
top extent:100@100.
|
|
345 |
|
|
346 |
b := Button in:top.
|
|
347 |
b logo:(Image fromFile:'bitmaps/SmalltalkX.xbm').
|
88
|
348 |
b action:[Transcript flash].
|
|
349 |
b foregroundColor:(Color red:0 green:80 blue:20) darkened.
|
|
350 |
b backgroundColor:(Color grey:10).
|
|
351 |
b enteredBackgroundColor:(Color grey:20).
|
|
352 |
b activeForegroundColor:(Color red).
|
|
353 |
b activeBackgroundColor:(Color grey:20).
|
|
354 |
top open.
|
|
355 |
|
|
356 |
|
113
|
357 |
fire on press (buttons in scrollbars do this, while normal buttons
|
130
|
358 |
fire on release.
|
|
359 |
(to give the user a chance to change her mind
|
|
360 |
and leave the button, you should not change the default behavior):
|
88
|
361 |
|
|
362 |
|top b|
|
|
363 |
|
|
364 |
top := StandardSystemView new.
|
|
365 |
top extent:100@100.
|
|
366 |
|
|
367 |
b := Button label:'hello' in:top.
|
|
368 |
b controller beTriggerOnDown.
|
|
369 |
b action:[Transcript flash].
|
|
370 |
top open.
|
62
|
371 |
|
|
372 |
|
|
373 |
To implement fun buttons (for games, show-demos etc.), you can
|
|
374 |
access all internal parameters (and not take the viewStyle defaults)
|
|
375 |
as in:
|
|
376 |
|
|
377 |
|b granite light shadow|
|
|
378 |
|
88
|
379 |
b := Button label:'a nice one ?'.
|
62
|
380 |
granite := Image fromFile:'bitmaps/granite_small.tiff'.
|
|
381 |
light := granite lightened.
|
|
382 |
shadow := granite darkened.
|
|
383 |
b backgroundColor:granite.
|
|
384 |
b foregroundColor:Color white.
|
|
385 |
b shadowColor:shadow.
|
|
386 |
b lightColor:light.
|
88
|
387 |
b enteredBackgroundColor:light.
|
113
|
388 |
b enteredForegroundColor:Color black.
|
62
|
389 |
b onLevel:-3; offLevel:5.
|
|
390 |
b extent:(200 @ 50).
|
|
391 |
b open
|
|
392 |
|
|
393 |
However, in your application, you may want to read those bitmaps only once
|
|
394 |
during startup and cache them for later reuse in some class variable
|
|
395 |
(reading, lightning & darkening of images is a bit slow)
|
88
|
396 |
|
113
|
397 |
|
118
|
398 |
ST/X Buttons allow simulation of the ST-80 MVC way of interacting.
|
|
399 |
To do so, instead (or in addition) to defining actionBlocks, set the
|
127
|
400 |
buttons model to have this be informed (in addition):
|
118
|
401 |
|
|
402 |
Model-View interaction (ST-80 style):
|
|
403 |
(have a look at the models values in the inspector, as the toggles change)
|
|
404 |
|
|
405 |
|bool1 bool2 b panel top|
|
|
406 |
|
|
407 |
bool1 := ValueHolder newBoolean.
|
|
408 |
bool2 := ValueHolder newBoolean value:true.
|
|
409 |
|
|
410 |
top := StandardSystemView new.
|
|
411 |
top extent:200@100.
|
|
412 |
|
|
413 |
panel := HorizontalPanelView
|
|
414 |
origin:0.0 @ 0.0 corner:1.0 @ 50 in:top.
|
|
415 |
|
|
416 |
b := Toggle label:'eat me' in:panel.
|
|
417 |
b model:bool1.
|
|
418 |
|
|
419 |
b := Toggle label:'drink me' in:panel.
|
|
420 |
b model:bool2.
|
|
421 |
|
|
422 |
top open.
|
|
423 |
bool1 inspect.
|
|
424 |
bool2 inspect.
|
|
425 |
|
|
426 |
Using a PluggableAdaptor (ST-80 style):
|
|
427 |
(notice, that this is almost what ST/X buttons did originally,
|
127
|
428 |
therefore, you may want use actionBlocks right away ...)
|
118
|
429 |
|
|
430 |
|adaptor1 adaptor2 b panel top|
|
|
431 |
|
|
432 |
adaptor1 := PluggableAdaptor new
|
130
|
433 |
getBlock:[:m | false]
|
131
|
434 |
putBlock:[:m :v | Transcript showCr:'eat']
|
118
|
435 |
updateBlock:nil.
|
|
436 |
adaptor2 := PluggableAdaptor new
|
130
|
437 |
getBlock:[:m | false]
|
131
|
438 |
putBlock:[:m :v | Transcript showCr:'drink']
|
118
|
439 |
updateBlock:nil.
|
|
440 |
|
|
441 |
top := StandardSystemView new.
|
|
442 |
top extent:200@100.
|
|
443 |
|
|
444 |
panel := HorizontalPanelView
|
|
445 |
origin:0.0 @ 0.0 corner:1.0 @ 50 in:top.
|
|
446 |
|
130
|
447 |
b := Button label:'eat me' in:panel.
|
118
|
448 |
b model:adaptor1.
|
|
449 |
|
130
|
450 |
b := Button label:'drink me' in:panel.
|
118
|
451 |
b model:adaptor2.
|
|
452 |
|
|
453 |
top open.
|
|
454 |
|
|
455 |
|
|
456 |
as a reminder, the corresponding ST/X setup is:
|
|
457 |
|
|
458 |
|b panel top|
|
|
459 |
|
|
460 |
top := StandardSystemView new.
|
|
461 |
top extent:200@100.
|
|
462 |
|
|
463 |
panel := HorizontalPanelView
|
|
464 |
origin:0.0 @ 0.0 corner:1.0 @ 50 in:top.
|
|
465 |
|
130
|
466 |
b := Button label:'eat me' in:panel.
|
131
|
467 |
b action:[Transcript showCr:'eat'].
|
118
|
468 |
|
130
|
469 |
b := Button label:'drink me' in:panel.
|
131
|
470 |
b action:[Transcript showCr:'drink'].
|
118
|
471 |
|
|
472 |
top open.
|
|
473 |
|
|
474 |
|
130
|
475 |
accessing multiple aspects of a complex model
|
|
476 |
(using a plug here to simulate that model ...)
|
113
|
477 |
|
|
478 |
|myModel b panel top|
|
|
479 |
|
|
480 |
myModel := Plug new.
|
|
481 |
myModel respondTo:#grow with:[top extent:200@300].
|
|
482 |
myModel respondTo:#shrink with:[top extent:200@100].
|
|
483 |
|
|
484 |
top := StandardSystemView new.
|
|
485 |
top extent:200@100.
|
|
486 |
|
|
487 |
panel := HorizontalPanelView
|
|
488 |
origin:0.0 @ 0.0
|
|
489 |
corner:1.0 @ 50
|
|
490 |
in:top.
|
|
491 |
|
|
492 |
b := Button label:'eat me' in:panel.
|
|
493 |
b model:myModel; change:#grow.
|
|
494 |
|
|
495 |
b := Button label:'drink me' in:panel.
|
|
496 |
b model:myModel; change:#shrink.
|
|
497 |
|
|
498 |
top open.
|
118
|
499 |
|
113
|
500 |
|
130
|
501 |
aquiring the label from the model
|
|
502 |
(this functionality is inherited from Label)
|
|
503 |
|
|
504 |
|myModel b panel top currentLabel|
|
|
505 |
|
|
506 |
currentLabel := 'foo'.
|
|
507 |
|
|
508 |
myModel := Plug new.
|
|
509 |
myModel respondTo:#getLabel with:[currentLabel].
|
|
510 |
myModel respondTo:#b0Pressed with:[].
|
|
511 |
myModel respondTo:#b1Pressed with:[currentLabel := 'bar'.
|
|
512 |
myModel changed:#labelAspect].
|
|
513 |
myModel respondTo:#b2Pressed with:[currentLabel := 'foo'.
|
|
514 |
myModel changed:#labelAspect].
|
|
515 |
|
|
516 |
top := StandardSystemView new.
|
|
517 |
top extent:300@100.
|
|
518 |
|
|
519 |
panel := HorizontalPanelView
|
|
520 |
origin:0.0 @ 0.0
|
|
521 |
corner:1.0 @ 50
|
|
522 |
in:top.
|
|
523 |
|
|
524 |
b := Button label:'press me' in:panel.
|
|
525 |
b model:myModel; change:#b0Pressed;
|
|
526 |
labelMessage:#getLabel; aspect:#labelAspect.
|
|
527 |
|
|
528 |
b := Button label:'press for bar' in:panel.
|
|
529 |
b model:myModel; change:#b1Pressed.
|
|
530 |
|
|
531 |
b := Button label:'press for foo' in:panel.
|
|
532 |
b model:myModel; change:#b2Pressed.
|
|
533 |
|
|
534 |
top open.
|
|
535 |
|
88
|
536 |
see 'doc/coding-examples' and 'doc/misc/quick_view_intro.doc'
|
|
537 |
for more variations on this theme.
|
0
|
538 |
"
|
|
539 |
! !
|
|
540 |
|
|
541 |
!Button class methodsFor:'defaults'!
|
|
542 |
|
59
|
543 |
updateStyleCache
|
60
|
544 |
|defaultLevel|
|
|
545 |
|
59
|
546 |
StyleSheet is3D ifTrue:[
|
60
|
547 |
defaultLevel := 1.
|
59
|
548 |
] ifFalse:[
|
60
|
549 |
defaultLevel := 0
|
59
|
550 |
].
|
60
|
551 |
DefaultActiveLevel := StyleSheet at:'buttonActiveLevel' default:(defaultLevel negated).
|
|
552 |
DefaultPassiveLevel := StyleSheet at:'buttonPassiveLevel' default:defaultLevel.
|
|
553 |
|
62
|
554 |
DefaultEdgeStyle := StyleSheet at:'buttonEdgeStyle'.
|
60
|
555 |
DefaultFont := StyleSheet fontAt:'buttonFont'.
|
74
|
556 |
DefaultBorderWidth := StyleSheet at:'buttonBorderWidth'.
|
60
|
557 |
DefaultForegroundColor := StyleSheet colorAt:'buttonForegroundColor'.
|
|
558 |
DefaultBackgroundColor := StyleSheet colorAt:'buttonBackgroundColor'.
|
|
559 |
DefaultDisabledForegroundColor := StyleSheet colorAt:'buttonDisabledForegroundColor' default:Color grey.
|
|
560 |
DefaultDisabledBackgroundColor := StyleSheet colorAt:'buttonDisabledBackgroundColor'.
|
|
561 |
DefaultEnteredForegroundColor := StyleSheet colorAt:'buttonEnteredForegroundColor'.
|
|
562 |
DefaultEnteredBackgroundColor := StyleSheet colorAt:'buttonEnteredBackgroundColor'.
|
|
563 |
DefaultActiveForegroundColor := StyleSheet colorAt:'buttonActiveForegroundColor'.
|
|
564 |
DefaultActiveBackgroundColor := StyleSheet colorAt:'buttonActiveBackgroundColor'.
|
59
|
565 |
DefaultReturnButtonHasImage := StyleSheet at:'buttonReturnButtonHasImage' default:true.
|
|
566 |
DefaultReturnButtonHasBorder := StyleSheet at:'buttonReturnButtonHasBorder' default:false.
|
62
|
567 |
DefaultShadowColor := StyleSheet colorAt:'buttonShadowColor'.
|
|
568 |
DefaultLightColor := StyleSheet colorAt:'buttonLightColor'.
|
|
569 |
DefaultHalfShadowColor := StyleSheet colorAt:'buttonHalfShadowColor'.
|
|
570 |
DefaultHalfLightColor := StyleSheet colorAt:'buttonHalfLightColor'.
|
59
|
571 |
!
|
|
572 |
|
0
|
573 |
returnFormOn:aDevice
|
|
574 |
"return the form used for the return arrow in non-3D;
|
|
575 |
cache the one for Display for the next round."
|
|
576 |
|
|
577 |
|f|
|
|
578 |
|
35
|
579 |
(ReturnForm notNil and:[aDevice == ReturnForm device]) ifTrue:[
|
59
|
580 |
^ ReturnForm
|
0
|
581 |
].
|
|
582 |
f := Form fromFile:'Return.xbm' resolution:100 on:aDevice.
|
|
583 |
f isNil ifTrue:[
|
59
|
584 |
f := Form width:24 height:16 fromArray:#[2r00000000 2r00000000 2r00000000
|
|
585 |
2r00000000 2r00000000 2r00000000
|
|
586 |
2r00000000 2r00000000 2r00000000
|
|
587 |
2r00000000 2r00000011 2r11100000
|
|
588 |
2r00000001 2r10000011 2r11100000
|
|
589 |
2r00000011 2r10000011 2r11100000
|
|
590 |
2r00000111 2r11111111 2r11100000
|
|
591 |
2r00001111 2r11111111 2r11100000
|
|
592 |
2r00011111 2r11111111 2r11100000
|
|
593 |
2r00001111 2r11111111 2r11100000
|
|
594 |
2r00000111 2r11111111 2r11100000
|
|
595 |
2r00000011 2r10000000 2r00000000
|
|
596 |
2r00000001 2r10000000 2r00000000
|
|
597 |
2r00000000 2r00000000 2r00000000
|
|
598 |
2r00000000 2r00000000 2r00000000
|
|
599 |
2r00000000 2r00000000 2r00000000]
|
|
600 |
on:aDevice
|
0
|
601 |
].
|
35
|
602 |
ReturnForm := f.
|
0
|
603 |
^ f
|
|
604 |
!
|
|
605 |
|
|
606 |
returnShadowFormOn:aDevice
|
|
607 |
"return the form used for the return arrow shadow pixels (3D only);
|
|
608 |
cache the one for Display for the next round."
|
|
609 |
|
|
610 |
|f|
|
|
611 |
|
35
|
612 |
(ReturnShadowForm notNil and:[aDevice == ReturnShadowForm device]) ifTrue:[
|
59
|
613 |
^ ReturnShadowForm
|
0
|
614 |
].
|
|
615 |
f := Form fromFile:'ReturnShadow.xbm' resolution:100 on:aDevice.
|
|
616 |
f isNil ifTrue:[
|
59
|
617 |
f := Form width:24 height:16 fromArray:#[2r00000000 2r00000000 2r00000000
|
|
618 |
2r00000000 2r00000000 2r00000000
|
|
619 |
2r00000000 2r00000000 2r00000000
|
|
620 |
2r00000000 2r00000011 2r11100000
|
|
621 |
2r00000001 2r10000010 2r00000000
|
|
622 |
2r00000010 2r10000010 2r00000000
|
|
623 |
2r00000100 2r11111110 2r00000000
|
|
624 |
2r00001000 2r00000000 2r00000000
|
|
625 |
2r00010000 2r00000000 2r00000000
|
|
626 |
2r00001000 2r00000000 2r00000000
|
|
627 |
2r00000100 2r00000000 2r00000000
|
|
628 |
2r00000010 2r00000000 2r00000000
|
|
629 |
2r00000001 2r00000000 2r00000000
|
|
630 |
2r00000000 2r00000000 2r00000000
|
|
631 |
2r00000000 2r00000000 2r00000000
|
|
632 |
2r00000000 2r00000000 2r00000000]
|
|
633 |
on:aDevice
|
0
|
634 |
].
|
35
|
635 |
ReturnShadowForm := f.
|
0
|
636 |
^ f
|
|
637 |
!
|
|
638 |
|
|
639 |
returnLightFormOn:aDevice
|
|
640 |
"return the form used for the return arrow light pixels (3D only);
|
|
641 |
cache the one for Display for the next round"
|
|
642 |
|
|
643 |
|f|
|
|
644 |
|
35
|
645 |
(ReturnLightForm notNil and:[aDevice == ReturnLightForm device]) ifTrue:[
|
59
|
646 |
^ ReturnLightForm
|
0
|
647 |
].
|
|
648 |
f := Form fromFile:'ReturnLight.xbm' resolution:100 on:aDevice.
|
|
649 |
f isNil ifTrue:[
|
59
|
650 |
f := Form width:24 height:16 fromArray:#[2r00000000 2r00000000 2r00000000
|
|
651 |
2r00000000 2r00000000 2r00000000
|
|
652 |
2r00000000 2r00000000 2r00000000
|
|
653 |
2r00000000 2r00000000 2r00000000
|
|
654 |
2r00000000 2r00000000 2r00100000
|
|
655 |
2r00000000 2r00000000 2r00100000
|
|
656 |
2r00000000 2r00000000 2r00100000
|
|
657 |
2r00000000 2r00000000 2r00100000
|
|
658 |
2r00000000 2r00000000 2r00100000
|
|
659 |
2r00000000 2r00000000 2r00100000
|
|
660 |
2r00000000 2r11111111 2r11100000
|
|
661 |
2r00000000 2r10000000 2r00000000
|
|
662 |
2r00000000 2r10000000 2r00000000
|
|
663 |
2r00000000 2r00000000 2r00000000
|
|
664 |
2r00000000 2r00000000 2r00000000
|
|
665 |
2r00000000 2r00000000 2r00000000]
|
|
666 |
on:aDevice
|
0
|
667 |
].
|
35
|
668 |
ReturnLightForm := f.
|
0
|
669 |
^ f
|
|
670 |
! !
|
|
671 |
|
|
672 |
!Button class methodsFor:'instance creation'!
|
|
673 |
|
|
674 |
label:aLabel action:aBlock in:aView
|
|
675 |
"create and return a new Button with text-label, aString
|
|
676 |
and pressAction, aBlock. Button is placed into aView."
|
|
677 |
|
|
678 |
^ ((self in:aView) label:aLabel) action:aBlock
|
|
679 |
!
|
|
680 |
|
|
681 |
form:aForm action:aBlock in:aView
|
|
682 |
"create and return a new Button with icon-label, aForm
|
|
683 |
and pressAction, aBlock. Button is placed into aView."
|
|
684 |
|
|
685 |
^ ((self in:aView) form:aForm) action:aBlock
|
59
|
686 |
!
|
|
687 |
|
118
|
688 |
okButton
|
59
|
689 |
"since ok-buttons are very common, here is a convenient
|
|
690 |
method to create one ..."
|
|
691 |
|
|
692 |
|aButton|
|
|
693 |
|
118
|
694 |
aButton := Button label:(self classResources at:'ok').
|
59
|
695 |
aButton cursor:(Cursor thumbsUp).
|
|
696 |
aButton isReturnButton:true.
|
|
697 |
^ aButton
|
|
698 |
!
|
|
699 |
|
118
|
700 |
abortButton
|
|
701 |
"since abort-buttons are very common, here is a convenient
|
|
702 |
method to create one ..."
|
|
703 |
|
|
704 |
|aButton|
|
|
705 |
|
|
706 |
aButton := Button label:(self classResources at:'abort').
|
|
707 |
aButton cursor:(Cursor thumbsDown).
|
|
708 |
^ aButton
|
|
709 |
!
|
|
710 |
|
|
711 |
okButtonIn:aView
|
|
712 |
"since ok-buttons are very common, here is a convenient
|
|
713 |
method to create one ..."
|
|
714 |
|
|
715 |
|b|
|
|
716 |
|
|
717 |
aView addSubView:(b := self okButton).
|
|
718 |
^ b
|
|
719 |
!
|
|
720 |
|
59
|
721 |
abortButtonIn:aView
|
|
722 |
"since abort-buttons are very common, here is a convenient
|
|
723 |
method to create one ..."
|
|
724 |
|
118
|
725 |
|b|
|
|
726 |
|
|
727 |
aView addSubView:(b := self abortButton).
|
|
728 |
^ b
|
|
729 |
!
|
|
730 |
|
|
731 |
toggle
|
|
732 |
"ST-80 compatibility: create & return a new toggle."
|
|
733 |
|
|
734 |
^ Toggle new
|
59
|
735 |
|
118
|
736 |
"
|
|
737 |
Button toggle label:'press me';
|
|
738 |
model:((PluggableAdaptor on:(Point new))
|
|
739 |
getSelector:#x putSelector:#x:)
|
|
740 |
"
|
|
741 |
"this is the same as"
|
|
742 |
"
|
|
743 |
Toggle new label:'press me';
|
|
744 |
model:((PluggableAdaptor on:(Point new))
|
|
745 |
getSelector:#x putSelector:#x:)
|
|
746 |
"
|
0
|
747 |
! !
|
|
748 |
|
|
749 |
!Button methodsFor:'initialization'!
|
|
750 |
|
|
751 |
initialize
|
|
752 |
super initialize.
|
|
753 |
|
|
754 |
isReturnButton := false.
|
|
755 |
!
|
|
756 |
|
|
757 |
initStyle
|
59
|
758 |
|hasGreyscales nm|
|
|
759 |
|
|
760 |
super initStyle.
|
|
761 |
|
|
762 |
DefaultFont notNil ifTrue:[font := DefaultFont on:device].
|
74
|
763 |
DefaultBorderWidth notNil ifTrue:[borderWidth := DefaultBorderWidth].
|
59
|
764 |
DefaultForegroundColor notNil ifTrue:[fgColor := DefaultForegroundColor on:device].
|
|
765 |
DefaultBackgroundColor notNil ifTrue:[bgColor := DefaultBackgroundColor on:device].
|
|
766 |
|
62
|
767 |
edgeStyle := DefaultEdgeStyle.
|
59
|
768 |
onLevel := DefaultActiveLevel.
|
|
769 |
offLevel := DefaultPassiveLevel.
|
|
770 |
|
|
771 |
DefaultDisabledForegroundColor notNil ifTrue:[
|
|
772 |
disabledFgColor := DefaultDisabledForegroundColor on:device
|
|
773 |
] ifFalse:[
|
|
774 |
disabledFgColor := fgColor
|
|
775 |
].
|
|
776 |
|
|
777 |
DefaultEnteredForegroundColor notNil ifTrue:[enteredFgColor := DefaultEnteredForegroundColor on:device].
|
|
778 |
DefaultEnteredBackgroundColor notNil ifTrue:[enteredBgColor := DefaultEnteredBackgroundColor on:device].
|
|
779 |
DefaultActiveForegroundColor notNil ifTrue:[activeFgColor := DefaultActiveForegroundColor on:device].
|
|
780 |
DefaultActiveBackgroundColor notNil ifTrue:[activeBgColor := DefaultActiveBackgroundColor on:device].
|
|
781 |
|
62
|
782 |
DefaultShadowColor notNil ifTrue:[shadowColor := DefaultShadowColor on:device].
|
|
783 |
DefaultLightColor notNil ifTrue:[lightColor := DefaultLightColor on:device].
|
59
|
784 |
|
62
|
785 |
shadowColor isNil ifTrue:[
|
|
786 |
shadowColor := Black.
|
|
787 |
].
|
|
788 |
lightColor isNil ifTrue:[
|
|
789 |
lightColor := White.
|
|
790 |
].
|
59
|
791 |
|
|
792 |
hasGreyscales := device hasGreyscales.
|
62
|
793 |
(edgeStyle == #soft) ifTrue:[
|
|
794 |
DefaultHalfShadowColor notNil ifTrue:[halfShadowColor := DefaultHalfShadowColor on:device].
|
|
795 |
DefaultHalfLightColor notNil ifTrue:[halfLightColor := DefaultHalfLightColor on:device].
|
|
796 |
|
|
797 |
halfShadowColor isNil ifTrue:[
|
|
798 |
"/ hasGreyscales ifTrue:[
|
|
799 |
"/ halfShadowColor := Color darkGrey
|
|
800 |
"/ ] ifFalse:[
|
|
801 |
"/ halfShadowColor := shadowColor
|
|
802 |
"/ ]
|
|
803 |
halfShadowColor := shadowColor lightened
|
59
|
804 |
]
|
|
805 |
].
|
|
806 |
|
62
|
807 |
"
|
|
808 |
actually, the stuf below should not be needed
|
|
809 |
- the styleSheet should provide values for nonGreyscale displays too
|
|
810 |
"
|
130
|
811 |
nm := styleSheet name.
|
62
|
812 |
(nm == #iris) ifTrue:[
|
|
813 |
hasGreyscales ifTrue:[
|
|
814 |
DefaultEnteredBackgroundColor isNil ifTrue:[
|
|
815 |
enteredBgColor := bgColor lightened "Color lightGrey".
|
|
816 |
].
|
|
817 |
DefaultActiveBackgroundColor isNil ifTrue:[
|
|
818 |
activeBgColor := enteredBgColor.
|
|
819 |
].
|
|
820 |
DefaultActiveForegroundColor isNil ifTrue:[
|
|
821 |
activeFgColor := enteredFgColor.
|
59
|
822 |
].
|
|
823 |
] ifFalse:[
|
62
|
824 |
DefaultEnteredBackgroundColor isNil ifTrue:[
|
|
825 |
enteredBgColor := Color veryLightGrey.
|
|
826 |
].
|
|
827 |
DefaultActiveBackgroundColor isNil ifTrue:[
|
|
828 |
activeBgColor := Black.
|
|
829 |
].
|
|
830 |
DefaultActiveForegroundColor isNil ifTrue:[
|
|
831 |
activeFgColor := White.
|
|
832 |
].
|
|
833 |
].
|
|
834 |
] ifFalse:[
|
|
835 |
nm == #motif ifTrue:[
|
|
836 |
lightColor isNil ifTrue:[
|
|
837 |
lightColor := bgColor lightened
|
|
838 |
].
|
|
839 |
"/ hasGreyscales ifTrue:[
|
|
840 |
"/ lightColor := Color lightGrey
|
|
841 |
"/ ]
|
|
842 |
] ifFalse:[
|
|
843 |
nm == #st80 ifTrue:[
|
59
|
844 |
hasGreyscales ifTrue:[
|
62
|
845 |
DefaultActiveForegroundColor isNil ifTrue:[
|
|
846 |
activeFgColor := fgColor.
|
|
847 |
].
|
|
848 |
DefaultActiveBackgroundColor isNil ifTrue:[
|
|
849 |
activeBgColor := bgColor darkened.
|
|
850 |
].
|
|
851 |
] ifFalse:[
|
|
852 |
DefaultActiveForegroundColor isNil ifTrue:[
|
|
853 |
activeFgColor := White.
|
|
854 |
].
|
|
855 |
DefaultActiveBackgroundColor isNil ifTrue:[
|
|
856 |
activeBgColor := Black
|
59
|
857 |
]
|
|
858 |
]
|
|
859 |
]
|
|
860 |
]
|
|
861 |
].
|
|
862 |
|
|
863 |
offLevel ~~ level ifTrue:[
|
|
864 |
self level:offLevel.
|
|
865 |
margin := (onLevel abs) max:(offLevel abs).
|
|
866 |
].
|
|
867 |
|
|
868 |
DefaultReturnButtonHasImage ifTrue:[
|
130
|
869 |
(styleSheet is3D and:[hasGreyscales]) ifTrue:[
|
59
|
870 |
shadowForm := self class returnShadowFormOn:device.
|
|
871 |
lightForm := self class returnLightFormOn:device.
|
|
872 |
formColor := viewBackground.
|
|
873 |
formShadowColor := shadowColor.
|
|
874 |
formLightColor := lightColor
|
|
875 |
] ifFalse:[
|
|
876 |
shadowForm := self class returnFormOn:device.
|
|
877 |
formColor := Black
|
|
878 |
].
|
|
879 |
].
|
|
880 |
!
|
|
881 |
|
0
|
882 |
initCursor
|
|
883 |
"set up a hand cursor"
|
|
884 |
|
|
885 |
cursor := Cursor hand
|
|
886 |
!
|
|
887 |
|
|
888 |
initEvents
|
|
889 |
super initEvents.
|
|
890 |
self enableEnterLeaveEvents
|
|
891 |
!
|
|
892 |
|
|
893 |
realize
|
|
894 |
super realize.
|
118
|
895 |
|
77
|
896 |
controller active:false.
|
|
897 |
controller entered:false.
|
0
|
898 |
|
|
899 |
fgColor := fgColor on:device.
|
|
900 |
bgColor := bgColor on:device.
|
18
|
901 |
formColor notNil ifTrue:[
|
59
|
902 |
formColor := formColor on:device.
|
18
|
903 |
].
|
0
|
904 |
!
|
|
905 |
|
|
906 |
reinitialize
|
|
907 |
super reinitialize.
|
77
|
908 |
controller notNil ifTrue:[
|
|
909 |
controller active:false.
|
|
910 |
controller entered:false.
|
|
911 |
]
|
|
912 |
!
|
|
913 |
|
95
|
914 |
defaultControllerClass
|
77
|
915 |
^ ButtonController
|
0
|
916 |
! !
|
|
917 |
|
62
|
918 |
!Button methodsFor:'queries'!
|
0
|
919 |
|
|
920 |
is3D
|
|
921 |
"return true, if the receiver is a 3D style view"
|
|
922 |
|
130
|
923 |
styleSheet name == #mswindows ifTrue:[^ true].
|
0
|
924 |
^ super is3D
|
|
925 |
!
|
|
926 |
|
35
|
927 |
isReturnButton
|
|
928 |
"return true, if this is a return button"
|
|
929 |
|
|
930 |
^ isReturnButton
|
127
|
931 |
!
|
|
932 |
|
|
933 |
isOn
|
|
934 |
"return true, if this button is currently pressed"
|
|
935 |
|
|
936 |
^ controller pressed
|
62
|
937 |
! !
|
|
938 |
|
127
|
939 |
!Button methodsFor:'accessing-look'!
|
35
|
940 |
|
0
|
941 |
isReturnButton:aBoolean
|
|
942 |
"show/dont show a return-key image after the label"
|
|
943 |
|
|
944 |
isReturnButton ~~ aBoolean ifTrue:[
|
59
|
945 |
DefaultReturnButtonHasBorder ifTrue:[
|
|
946 |
self borderWidth:(aBoolean ifTrue:[1] ifFalse:[0])
|
|
947 |
].
|
|
948 |
isReturnButton := aBoolean.
|
|
949 |
self newLayout
|
0
|
950 |
]
|
|
951 |
!
|
|
952 |
|
|
953 |
onLevel:aNumber
|
|
954 |
"set the level of the button when pressed (i.e. how deep)"
|
|
955 |
|
|
956 |
onLevel := aNumber.
|
128
|
957 |
(controller notNil
|
|
958 |
and:[controller pressed]) ifTrue:[
|
59
|
959 |
self level:onLevel.
|
|
960 |
margin := onLevel abs max:offLevel abs.
|
|
961 |
self redraw
|
0
|
962 |
]
|
|
963 |
!
|
|
964 |
|
|
965 |
onLevel
|
|
966 |
"return the level of the button when pressed"
|
|
967 |
|
|
968 |
^ onLevel
|
|
969 |
!
|
|
970 |
|
|
971 |
offLevel:aNumber
|
|
972 |
"set the level of the button when not pressed (i.e. how high)"
|
|
973 |
|
|
974 |
offLevel := aNumber.
|
128
|
975 |
(controller notNil
|
|
976 |
and:[controller pressed not]) ifTrue:[
|
59
|
977 |
self level:offLevel.
|
|
978 |
margin := onLevel abs max:offLevel abs.
|
|
979 |
self redraw
|
0
|
980 |
]
|
|
981 |
!
|
|
982 |
|
|
983 |
offLevel
|
|
984 |
"return the level of the button when released"
|
|
985 |
|
|
986 |
^ offLevel
|
|
987 |
!
|
|
988 |
|
74
|
989 |
edgeStyle:aSymbol
|
|
990 |
"set the edgestyle - currently only #soft or nil"
|
|
991 |
|
|
992 |
edgeStyle := aSymbol
|
|
993 |
!
|
|
994 |
|
59
|
995 |
activeLogo:anImageOrString
|
|
996 |
"define the logo to be displayed while active -
|
|
997 |
this is optional; the default is to display the same
|
|
998 |
(logo) in both pressed and released states."
|
|
999 |
|
|
1000 |
activeLogo := anImageOrString.
|
77
|
1001 |
controller pressed ifTrue:[
|
59
|
1002 |
self logo:anImageOrString
|
|
1003 |
]
|
|
1004 |
!
|
|
1005 |
|
|
1006 |
passiveLogo:anImageOrString
|
|
1007 |
"define the logo to be displayed while inactive -
|
|
1008 |
this is optional; the default is to display the same
|
|
1009 |
(logo) in both pressed and released states."
|
|
1010 |
|
|
1011 |
passiveLogo := anImageOrString.
|
77
|
1012 |
controller pressed ifFalse:[
|
59
|
1013 |
self logo:anImageOrString
|
|
1014 |
]
|
|
1015 |
!
|
|
1016 |
|
0
|
1017 |
activeForegroundColor
|
|
1018 |
"return the foreground color to be used when pressed"
|
|
1019 |
|
|
1020 |
^ activeFgColor
|
|
1021 |
!
|
|
1022 |
|
|
1023 |
activeForegroundColor:aColor
|
|
1024 |
"set the foreground color to be used when pressed"
|
|
1025 |
|
|
1026 |
activeFgColor := aColor.
|
77
|
1027 |
self redrawIfPressed
|
0
|
1028 |
!
|
|
1029 |
|
|
1030 |
activeBackgroundColor
|
|
1031 |
"return the background color to be used when pressed"
|
|
1032 |
|
|
1033 |
^ activeBgColor
|
|
1034 |
!
|
|
1035 |
|
|
1036 |
activeBackgroundColor:aColor
|
|
1037 |
"set the background color to be used when pressed"
|
|
1038 |
|
|
1039 |
activeBgColor := aColor.
|
77
|
1040 |
self redrawIfPressed
|
0
|
1041 |
!
|
|
1042 |
|
|
1043 |
activeForegroundColor:fgColor backgroundColor:bgColor
|
77
|
1044 |
"set both fg and bg colors to be used when pressed"
|
0
|
1045 |
|
|
1046 |
activeFgColor := fgColor.
|
|
1047 |
activeBgColor := bgColor.
|
77
|
1048 |
self redrawIfPressed
|
0
|
1049 |
!
|
|
1050 |
|
|
1051 |
enteredForegroundColor
|
|
1052 |
"return the foreground color to be used when the mouse
|
|
1053 |
pointer enters the button area"
|
|
1054 |
|
|
1055 |
^ enteredFgColor
|
|
1056 |
!
|
|
1057 |
|
|
1058 |
enteredForegroundColor:aColor
|
|
1059 |
"set the foreground color to be used when the mouse
|
|
1060 |
pointer enters the button area"
|
|
1061 |
|
|
1062 |
enteredFgColor := aColor
|
|
1063 |
!
|
|
1064 |
|
|
1065 |
enteredBackgroundColor
|
|
1066 |
"return the background color to be used when the mouse
|
|
1067 |
pointer enters the button area"
|
|
1068 |
|
|
1069 |
^ enteredBgColor
|
|
1070 |
!
|
|
1071 |
|
|
1072 |
enteredBackgroundColor:aColor
|
|
1073 |
"set the background color to be used when the mouse
|
|
1074 |
pointer enters the button area"
|
|
1075 |
|
|
1076 |
enteredBgColor := aColor
|
127
|
1077 |
!
|
|
1078 |
|
|
1079 |
disabledForegroundColor
|
|
1080 |
"return the foreground color used when the button is disabled"
|
|
1081 |
|
|
1082 |
^ disabledFgColor
|
0
|
1083 |
! !
|
127
|
1084 |
|
|
1085 |
!Button methodsFor:'accessing-behavior'!
|
|
1086 |
|
|
1087 |
pressAction
|
|
1088 |
"return the pressAction; thats the block which gets evaluated
|
|
1089 |
when the button is pressed (if non-nil)"
|
|
1090 |
|
|
1091 |
^ controller pressAction
|
|
1092 |
!
|
|
1093 |
|
|
1094 |
pressAction:aBlock
|
|
1095 |
"define the action to be performed on press"
|
|
1096 |
|
|
1097 |
controller pressAction:aBlock
|
|
1098 |
!
|
0
|
1099 |
|
127
|
1100 |
releaseAction
|
|
1101 |
"return the releaseAction; thats the block which gets evaluated
|
|
1102 |
when the button is relreased (if non-nil)"
|
|
1103 |
|
|
1104 |
^ controller releaseAction
|
|
1105 |
!
|
|
1106 |
|
|
1107 |
releaseAction:aBlock
|
|
1108 |
"define the action to be performed on release"
|
|
1109 |
|
|
1110 |
controller releaseAction:aBlock
|
|
1111 |
!
|
|
1112 |
|
|
1113 |
action:aBlock
|
|
1114 |
"convenient method: depending on the setting of controllers triggerOnDown flag,
|
|
1115 |
either set the press-action and clear any release-action or
|
|
1116 |
vice versa, set the release-action and clear the press-action."
|
|
1117 |
|
|
1118 |
controller action:aBlock
|
|
1119 |
!
|
|
1120 |
|
|
1121 |
autoRepeat
|
|
1122 |
"turn on autorepeat"
|
|
1123 |
|
|
1124 |
controller autoRepeat
|
|
1125 |
!
|
118
|
1126 |
|
|
1127 |
disable
|
|
1128 |
"disable the button"
|
|
1129 |
|
|
1130 |
controller disable.
|
|
1131 |
!
|
|
1132 |
|
|
1133 |
enable
|
|
1134 |
"enable the button"
|
|
1135 |
|
|
1136 |
controller enable
|
127
|
1137 |
! !
|
|
1138 |
|
|
1139 |
!Button methodsFor:'changing state'!
|
118
|
1140 |
|
|
1141 |
turnOffWithoutRedraw
|
|
1142 |
"turn the button off - no redraw"
|
|
1143 |
|
|
1144 |
controller pressed:false.
|
|
1145 |
controller active:false.
|
|
1146 |
|
|
1147 |
"do not use super level:offLevel
|
|
1148 |
- because that one does redraw the edges.
|
|
1149 |
Sure, this is no good coding style"
|
|
1150 |
level := offLevel.
|
|
1151 |
margin := level abs
|
|
1152 |
!
|
|
1153 |
|
|
1154 |
turnOff
|
|
1155 |
"turn the button off (if not already off)"
|
|
1156 |
|
|
1157 |
controller pressed ifTrue:[
|
128
|
1158 |
self level:offLevel.
|
118
|
1159 |
self turnOffWithoutRedraw.
|
|
1160 |
self redraw
|
|
1161 |
]
|
|
1162 |
!
|
|
1163 |
|
|
1164 |
turnOnWithoutRedraw
|
|
1165 |
"turn the button on - no redraw"
|
|
1166 |
|
|
1167 |
controller pressed:true.
|
|
1168 |
|
|
1169 |
"do not use super level:offLevel
|
|
1170 |
- because that one does redraw the edges.
|
|
1171 |
Sure, this is no good coding style"
|
|
1172 |
level := onLevel.
|
|
1173 |
margin := level abs
|
|
1174 |
!
|
|
1175 |
|
|
1176 |
turnOn
|
|
1177 |
"turn the button on (if not already on)"
|
|
1178 |
|
|
1179 |
controller pressed ifFalse:[
|
128
|
1180 |
self level:onLevel.
|
118
|
1181 |
self turnOnWithoutRedraw.
|
|
1182 |
self redraw
|
|
1183 |
]
|
|
1184 |
!
|
|
1185 |
|
|
1186 |
toggleNoAction
|
|
1187 |
"toggle, but do NOT perform any action - can be used to change a toggle
|
|
1188 |
under program control (i.e. turn one toggle off from another one)"
|
|
1189 |
|
|
1190 |
controller toggleNoAction
|
|
1191 |
!
|
|
1192 |
|
|
1193 |
toggle
|
|
1194 |
"toggle and perform the action"
|
|
1195 |
|
|
1196 |
controller toggle
|
|
1197 |
! !
|
|
1198 |
|
35
|
1199 |
!Button methodsFor:'queries'!
|
|
1200 |
|
130
|
1201 |
preferredExtent
|
|
1202 |
"return my preferred extent - this is the minimum size I would like to have"
|
35
|
1203 |
|
131
|
1204 |
|extraH extraV|
|
35
|
1205 |
|
|
1206 |
logo notNil ifTrue:[
|
131
|
1207 |
"
|
|
1208 |
extraH := extraV := (onLevel abs max:offLevel abs) + ViewSpacing * 2.
|
|
1209 |
"
|
|
1210 |
extraH := extraV := (onLevel abs max:offLevel abs).
|
|
1211 |
extraH := (extraH + hSpace * 2).
|
|
1212 |
extraV := (extraV + vSpace * 2).
|
|
1213 |
|
59
|
1214 |
self is3D ifFalse:[
|
97
|
1215 |
"add space for a frame around"
|
131
|
1216 |
extraH := extraH + 2. extraV := extraV + 2.
|
59
|
1217 |
].
|
131
|
1218 |
^ (labelWidth + extraH) @ (labelHeight + extraV)
|
35
|
1219 |
].
|
|
1220 |
|
130
|
1221 |
^ super preferredExtent
|
35
|
1222 |
! !
|
|
1223 |
|
0
|
1224 |
!Button methodsFor:'private'!
|
|
1225 |
|
62
|
1226 |
computeLabelOrigin
|
|
1227 |
"compute the origin of the text - if I am a returnButton,
|
|
1228 |
shift it somwehat to the right (we have already allocated the
|
|
1229 |
real estate, since computeLabelSize returned some extra space
|
|
1230 |
before)."
|
|
1231 |
|
|
1232 |
super computeLabelOrigin.
|
|
1233 |
(isReturnButton and:[shadowForm notNil]) ifTrue:[
|
|
1234 |
labelOriginX := labelOriginX + hSpace + hSpace.
|
|
1235 |
]
|
|
1236 |
!
|
|
1237 |
|
0
|
1238 |
computeLabelSize
|
|
1239 |
"compute the extent needed to hold the label plus the return form"
|
|
1240 |
|
|
1241 |
super computeLabelSize.
|
59
|
1242 |
(isReturnButton and:[shadowForm notNil]) ifTrue:[
|
62
|
1243 |
labelWidth := labelWidth + (hSpace * 2) + shadowForm width.
|
59
|
1244 |
labelHeight := labelHeight max: (shadowForm height + vSpace)
|
0
|
1245 |
]
|
|
1246 |
!
|
|
1247 |
|
131
|
1248 |
XXresize
|
0
|
1249 |
"resize myself to make logo fit into myself.
|
|
1250 |
Redefined, since we add space for a frame around text when non-3D"
|
|
1251 |
|
|
1252 |
|extra|
|
|
1253 |
|
|
1254 |
logo isNil ifFalse:[
|
59
|
1255 |
self computeLabelOrigin.
|
|
1256 |
(relativeExtent isNil and:[extentRule isNil]) ifTrue:[
|
|
1257 |
extra := (onLevel abs max:offLevel abs) * 2.
|
130
|
1258 |
styleSheet is3D ifFalse:[
|
59
|
1259 |
"/ (logo isKindOf:Form) ifFalse:[
|
|
1260 |
"add space for a rectangle around"
|
|
1261 |
extra := extra + 2
|
|
1262 |
"/ ]
|
|
1263 |
].
|
|
1264 |
self extent:(labelWidth + extra) @ (labelHeight + extra)
|
|
1265 |
]
|
0
|
1266 |
]
|
|
1267 |
! !
|
|
1268 |
|
|
1269 |
!Button methodsFor:'redrawing'!
|
|
1270 |
|
62
|
1271 |
drawEdges
|
|
1272 |
"draw all of my 3D edges"
|
|
1273 |
|
|
1274 |
self drawEdgesForX:0 y:0 width:width height:height level:level
|
|
1275 |
shadow:shadowColor
|
|
1276 |
light:lightColor
|
|
1277 |
halfShadow:halfShadowColor
|
|
1278 |
halfLight:halfLightColor
|
|
1279 |
style:edgeStyle
|
|
1280 |
!
|
|
1281 |
|
|
1282 |
drawLeftEdge
|
|
1283 |
"draw left 3D edge into window frame"
|
|
1284 |
|
|
1285 |
self drawLeftEdgeLevel:level
|
|
1286 |
shadow:shadowColor
|
|
1287 |
light:lightColor
|
|
1288 |
halfShadow:halfShadowColor
|
|
1289 |
halfLight:halfLightColor
|
|
1290 |
style:edgeStyle.
|
|
1291 |
!
|
|
1292 |
|
|
1293 |
drawRightEdge
|
|
1294 |
"draw right 3D edge into window frame"
|
|
1295 |
|
|
1296 |
self drawRightEdgeLevel:level
|
|
1297 |
shadow:shadowColor
|
|
1298 |
light:lightColor
|
|
1299 |
halfShadow:halfShadowColor
|
|
1300 |
halfLight:halfLightColor
|
|
1301 |
style:edgeStyle.
|
|
1302 |
!
|
|
1303 |
|
|
1304 |
drawTopEdge
|
|
1305 |
"draw top 3D edge into window frame"
|
|
1306 |
|
|
1307 |
self drawTopEdgeLevel:level
|
|
1308 |
shadow:shadowColor
|
|
1309 |
light:lightColor
|
|
1310 |
halfShadow:halfShadowColor
|
|
1311 |
halfLight:halfLightColor
|
|
1312 |
style:edgeStyle.
|
|
1313 |
!
|
|
1314 |
|
|
1315 |
drawBottomEdge
|
|
1316 |
"draw bottom 3D edge into window frame"
|
|
1317 |
|
|
1318 |
self drawBottomEdgeLevel:level
|
|
1319 |
shadow:shadowColor
|
|
1320 |
light:lightColor
|
|
1321 |
halfShadow:halfShadowColor
|
|
1322 |
halfLight:halfLightColor
|
|
1323 |
style:edgeStyle.
|
|
1324 |
!
|
|
1325 |
|
0
|
1326 |
drawWith:fg and:bg
|
|
1327 |
"redraw myself with fg/bg. Use super to draw the label, add
|
|
1328 |
the return-arrow here."
|
|
1329 |
|
18
|
1330 |
|x y sColor lColor|
|
0
|
1331 |
|
59
|
1332 |
shown ifFalse:[^ self].
|
0
|
1333 |
super drawWith:fg and:bg. "this draws the text"
|
|
1334 |
|
59
|
1335 |
(isReturnButton and:[shadowForm notNil]) ifTrue:[
|
|
1336 |
y := (height - shadowForm height) // 2.
|
|
1337 |
x := width - shadowForm width - (hSpace // 2).
|
|
1338 |
|
|
1339 |
formShadowColor isNil ifTrue:[
|
|
1340 |
self paint:fg on:bg.
|
130
|
1341 |
"/ self background:bg.
|
59
|
1342 |
self displayOpaqueForm:shadowForm x:x y:y.
|
|
1343 |
^ self
|
|
1344 |
].
|
0
|
1345 |
|
59
|
1346 |
"
|
|
1347 |
drawing form in 3d-style (i.e. with shadow and light)
|
|
1348 |
"
|
|
1349 |
(formShadowColor isColor and:[formShadowColor colorId notNil
|
|
1350 |
and:[formLightColor isColor and:[formLightColor colorId notNil
|
|
1351 |
and:[formColor isColor and:[formColor colorId notNil]]]]])
|
|
1352 |
ifTrue:[
|
|
1353 |
sColor := formShadowColor.
|
|
1354 |
lColor := formLightColor.
|
|
1355 |
] ifFalse:[
|
|
1356 |
sColor := Black.
|
|
1357 |
lColor := White.
|
|
1358 |
].
|
|
1359 |
self foreground:sColor.
|
|
1360 |
self displayForm:shadowForm x:x y:y.
|
35
|
1361 |
|
59
|
1362 |
lightForm notNil ifTrue:[
|
|
1363 |
self foreground:lColor.
|
|
1364 |
self displayForm:lightForm x:x y:y.
|
|
1365 |
].
|
|
1366 |
self paint:fg.
|
0
|
1367 |
]
|
|
1368 |
!
|
|
1369 |
|
59
|
1370 |
showPassive
|
82
|
1371 |
"redraw myself as passive"
|
59
|
1372 |
|
|
1373 |
offLevel ~~ level ifTrue:[
|
|
1374 |
self level:offLevel.
|
|
1375 |
].
|
|
1376 |
(passiveLogo notNil and:[passiveLogo ~~ logo]) ifTrue:[
|
|
1377 |
self logo:passiveLogo
|
|
1378 |
].
|
|
1379 |
self redraw.
|
|
1380 |
!
|
|
1381 |
|
|
1382 |
showActive
|
118
|
1383 |
"redraw myself as active (i.e. busy)"
|
59
|
1384 |
|
|
1385 |
onLevel ~~ level ifTrue:[
|
|
1386 |
self level:onLevel.
|
|
1387 |
].
|
|
1388 |
(activeLogo notNil and:[activeLogo ~~ logo]) ifTrue:[
|
|
1389 |
self logo:activeLogo
|
|
1390 |
].
|
|
1391 |
self redraw.
|
|
1392 |
!
|
|
1393 |
|
77
|
1394 |
redrawIfPressed
|
82
|
1395 |
"redraw the button, but only if visible and currently being pressed"
|
|
1396 |
|
|
1397 |
shown ifTrue:[
|
|
1398 |
controller pressed ifTrue:[
|
|
1399 |
self redraw
|
|
1400 |
]
|
77
|
1401 |
]
|
|
1402 |
!
|
|
1403 |
|
0
|
1404 |
redraw
|
82
|
1405 |
"redraw the button.
|
|
1406 |
Thats like redrawing a label, but use different colors when pressed
|
|
1407 |
or entered."
|
0
|
1408 |
|
77
|
1409 |
|fg bg entered|
|
0
|
1410 |
|
62
|
1411 |
shown ifFalse:[^ self].
|
77
|
1412 |
controller active ifTrue:[^ self].
|
35
|
1413 |
|
62
|
1414 |
fg := fgColor.
|
|
1415 |
bg := bgColor.
|
77
|
1416 |
controller enabled ifFalse:[
|
62
|
1417 |
fg := disabledFgColor
|
|
1418 |
] ifTrue:[
|
77
|
1419 |
entered := controller entered.
|
62
|
1420 |
entered ifTrue:[
|
|
1421 |
enteredFgColor notNil ifTrue:[fg := enteredFgColor].
|
|
1422 |
enteredBgColor notNil ifTrue:[bg := enteredBgColor]
|
|
1423 |
].
|
77
|
1424 |
(controller pressed and:[entered or:[controller isTriggerOnDown]]) ifTrue:[
|
62
|
1425 |
activeFgColor isNil ifTrue:[
|
|
1426 |
onLevel == offLevel ifTrue:[
|
|
1427 |
fg := bgColor
|
|
1428 |
]
|
|
1429 |
] ifFalse:[
|
|
1430 |
fg := activeFgColor.
|
59
|
1431 |
].
|
62
|
1432 |
activeBgColor isNil ifTrue:[
|
|
1433 |
onLevel == offLevel ifTrue:[
|
|
1434 |
bg := fgColor
|
|
1435 |
]
|
|
1436 |
] ifFalse:[
|
|
1437 |
bg := activeBgColor
|
|
1438 |
].
|
|
1439 |
self is3D ifFalse:[
|
|
1440 |
self drawWith:fg and:bg .
|
|
1441 |
"
|
|
1442 |
draw a rectangle around
|
|
1443 |
"
|
|
1444 |
self paint:fg.
|
|
1445 |
self displayRectangleX:0 y:0 width:width height:height.
|
|
1446 |
|
|
1447 |
^ self
|
|
1448 |
].
|
|
1449 |
].
|
|
1450 |
].
|
|
1451 |
self drawWith:fg and:bg
|
0
|
1452 |
! !
|