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
|
205
|
14 |
instanceVariableNames:'activeLogo passiveLogo disabledLogo focusLogo onLevel offLevel
|
219
|
15 |
disabledFgColor activeFgColor activeBgColor enteredFgColor
|
|
16 |
enteredBgColor isReturnButton shadowForm lightForm formColor
|
|
17 |
formShadowColor formLightColor edgeStyle halfShadowColor
|
|
18 |
halfLightColor'
|
205
|
19 |
classVariableNames:'ReturnForm ReturnLightForm ReturnShadowForm DefaultFont
|
219
|
20 |
DefaultActiveLevel DefaultPassiveLevel DefaultEdgeStyle
|
|
21 |
DefaultBorderWidth DefaultForegroundColor DefaultBackgroundColor
|
|
22 |
DefaultDisabledForegroundColor DefaultDisabledBackgroundColor
|
|
23 |
DefaultEnteredForegroundColor DefaultEnteredBackgroundColor
|
|
24 |
DefaultActiveForegroundColor DefaultActiveBackgroundColor
|
|
25 |
DefaultReturnButtonHasImage DefaultReturnButtonHasBorder
|
|
26 |
DefaultShadowColor DefaultLightColor DefaultHalfShadowColor
|
|
27 |
DefaultHalfLightColor'
|
205
|
28 |
poolDictionaries:''
|
|
29 |
category:'Views-Interactors'
|
0
|
30 |
!
|
|
31 |
|
|
32 |
!Button class methodsFor:'documentation'!
|
|
33 |
|
205
|
34 |
actionBlocksVersusModelChanges
|
|
35 |
"
|
|
36 |
You may ask yourself, why ST/X supports two different ways
|
|
37 |
to trigger a buttons action (also true for sliders, selectionInListViews,
|
|
38 |
toggles etc.) and when to use which mechanism.
|
|
39 |
|
|
40 |
There are two reasons:
|
|
41 |
1) history - historically, ST/X used only actionBlocks
|
|
42 |
Basically, these provide the most general functionality
|
|
43 |
(you can of course send change-messages from those blocks)
|
|
44 |
|
|
45 |
Change-message notification was added later, to make porting
|
|
46 |
of existing applications easier.
|
|
47 |
|
|
48 |
2) for many (simple) applications, it is often easier, to simply
|
|
49 |
define an action block. This is especially true, if the button
|
|
50 |
triggers some action (such as ok-/abort-buttons) and does NOT
|
|
51 |
change some models internal value.
|
|
52 |
(other smalltalks provide extra adapter-models for this,
|
|
53 |
in which you can set actionBlocks in much the same way).
|
|
54 |
|
|
55 |
In general:
|
|
56 |
use model-change-messages, iff multiple views are possibly open
|
|
57 |
on the same domain model, and changes can occur from multiple
|
|
58 |
places. Or if a change has to be forwarded to multiple other objects
|
|
59 |
(possible not foreseen).
|
|
60 |
|
|
61 |
For simplicity, better use actionBlocks for trigger-like actions
|
|
62 |
(such as closing a view, ok/abort etc.) iff there is only a single
|
|
63 |
entity which is interrested in that button press.
|
|
64 |
"
|
|
65 |
!
|
|
66 |
|
35
|
67 |
copyright
|
|
68 |
"
|
|
69 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
70 |
All Rights Reserved
|
35
|
71 |
|
|
72 |
This software is furnished under a license and may be used
|
|
73 |
only in accordance with the terms of that license and with the
|
|
74 |
inclusion of the above copyright notice. This software may not
|
|
75 |
be provided or otherwise made available to, or used by, any
|
|
76 |
other person. No title to or ownership of the software is
|
|
77 |
hereby transferred.
|
|
78 |
"
|
|
79 |
!
|
|
80 |
|
0
|
81 |
documentation
|
|
82 |
"
|
|
83 |
Buttons are Labels which do something when pressed/released.
|
113
|
84 |
Since they inherit from Label, read the documentation on Labels to
|
|
85 |
see how color, layout, font, image or labelString are changed.
|
|
86 |
|
133
|
87 |
Buttons (and also instances of subclasses, such as toggles, checkToggles
|
|
88 |
and radioButtons) perform some action when pressed, and optionally when
|
|
89 |
released. Due to historic reasons, ST/X buttons support two mechanisms:
|
|
90 |
|
113
|
91 |
Actionblock operation:
|
133
|
92 |
the button has an actionBlock (actually, it has two: a pressAction and
|
|
93 |
a releaseAction) which is evaluated, when the button is pressed.
|
|
94 |
The user of a button can set these action blocks via the #action:,
|
|
95 |
#pressAction: or #releaseAction: messages.
|
113
|
96 |
|
|
97 |
Model-View interaction:
|
133
|
98 |
buttons with a model will send change-messages to the model and also react
|
|
99 |
to changes in the model.
|
|
100 |
You have to define the buttons labelMessage and an aspectSymbol.
|
|
101 |
When changed, the model should send 'self changed:<aspect>' if it wants the
|
|
102 |
label to change and return a string from the labelSymbol-message.
|
118
|
103 |
By default, the labelMsg is nil, therefore no update of the label is done.
|
|
104 |
(this behavior is inherited from label, see documentation there)
|
|
105 |
|
133
|
106 |
When pressed, the button sends a changeMessage to the model.
|
118
|
107 |
If the changeMsg is for a one-argument message, the current
|
113
|
108 |
press-state is passed as argument (i.e. true if pressed, false if released).
|
118
|
109 |
By default, the change-Message is #value: (for ST-80 compatibility).
|
113
|
110 |
|
|
111 |
button model:aModel.
|
|
112 |
button aspect:aspectSymbol.
|
|
113 |
button change:changeSymbol.
|
133
|
114 |
button labelMessage:labelSymbol.
|
113
|
115 |
|
|
116 |
model sends #changed:aspectSymbol
|
133
|
117 |
---> button will redraw its label from value returned by model>>labelSymbol
|
113
|
118 |
|
|
119 |
button changes state:
|
133
|
120 |
---> button sends changeSymbol / changeSymbol:state to the model
|
113
|
121 |
|
118
|
122 |
By default (as inherited), the labelMsg is nil; therefore, buttons
|
|
123 |
do not try to aquire a new labelString from the model.
|
|
124 |
If you want this behavior, you must set labelMsg and aspectMsg
|
|
125 |
as appropriate.
|
0
|
126 |
|
133
|
127 |
See examples.
|
|
128 |
|
|
129 |
|
0
|
130 |
Instance variables:
|
|
131 |
|
59
|
132 |
activeLogo <StringOrImage> logo to show when active (pressed)
|
|
133 |
passiveLogo <StringOrImage> logo to show when passive (released)
|
|
134 |
default is nil for both, so the normal logo is used
|
|
135 |
(see superclass: Label)
|
35
|
136 |
onLevel <Integer> level when pressed (3D only) (default: depends on style)
|
|
137 |
offLevel <Integer> level when released (3D only) (default: depends on style)
|
|
138 |
disabledFgColor <Color> color used to draw logo when disabled (default: depends on style)
|
|
139 |
activeFgColor <Color> color to draw logo when pressed (default: depends on style)
|
|
140 |
activeBgColor <Color> bg color when pressed (default: depends on style)
|
|
141 |
enteredFgColor <Color> fg color to draw logo when cursor entered (default: depends on style)
|
|
142 |
enteredBgColor <Color> bg color when cursor entered (default: depends on style)
|
0
|
143 |
|
35
|
144 |
isReturnButton <Boolean> true if this button is also activated by the
|
59
|
145 |
return key - if true, it will draw a return-bitmap
|
|
146 |
in addition to the logo (default: false)
|
35
|
147 |
|
59
|
148 |
shadowForm <Form> form to display in addition to buttons label (returnbutton only)
|
|
149 |
lightForm <Form> light part of shadowForm (returnbutton only)
|
|
150 |
|
|
151 |
formColor <Color> color to draw form with (returnbutton only)
|
|
152 |
formShadowColor <Color> color for shadowing the form (3D only & return)
|
35
|
153 |
formLightColor <Color> color for lighting the form (3D only)
|
|
154 |
|
62
|
155 |
|
|
156 |
styleSheet parameters:
|
|
157 |
|
|
158 |
buttonActiveLevel <Integer> level when on (ignored in 2D styles)
|
|
159 |
buttonPassiveLevel <Integer> level when off (ignored in 2D styles)
|
74
|
160 |
buttonBorderWidth <Integer> default borderwidth
|
62
|
161 |
buttonEdgeStyle <Symbol> style of edges (currently #soft or nil)
|
|
162 |
buttonFont <Font> font to use for textual labels
|
|
163 |
buttonForegroundColor <Color> color to draw foreground pixels (i.e. the string)
|
|
164 |
buttonBackgroundColor <Color> color to draw background pixels
|
|
165 |
buttonDisabledForegroundColor <Color> same when disabled
|
|
166 |
buttonDisabledBackgroundColor <Color> same when disabled
|
|
167 |
buttonEnteredForegroundColor <Color> same when mouse pointer is in
|
|
168 |
buttonEnteredBackgroundColor <Color> same when mouse pointer is in
|
|
169 |
buttonActiveForegroundColor <Color> same when button is active
|
|
170 |
buttonActiveBackgroundColor <Color> same when button is active
|
|
171 |
buttonShadowColor <Color> shadow color for edgaes (ignored in 2D styles)
|
|
172 |
buttonLightColor <Color> light color for edgaes (ignored in 2D styles)
|
|
173 |
buttonHalfShadowColor <Color> half shadow color; for soft edges only
|
|
174 |
buttonHalfLightColor <Color> half light color; for soft edges only
|
|
175 |
|
|
176 |
buttonReturnButtonHasImage <Boolean> if true, return-buttons draw a return-key image
|
|
177 |
buttonReturnButtonHasBorder <Boolean> if true, return-buttons show a border
|
130
|
178 |
|
133
|
179 |
See also: Toggle CheckToggle CheckBox
|
|
180 |
"
|
|
181 |
!
|
|
182 |
|
62
|
183 |
examples
|
|
184 |
"
|
|
185 |
You dont have to normally care for all the internals
|
35
|
186 |
(they allow many variations though). The typical use is:
|
|
187 |
|
59
|
188 |
b := Button label:'some logo' in:aView.
|
|
189 |
b action:[ .. things to do, when pressed ... ]
|
35
|
190 |
|
62
|
191 |
for buttons with a string-label,
|
|
192 |
and:
|
|
193 |
|
118
|
194 |
b := Button label:someImage in:aView.
|
62
|
195 |
b action:[ .. things to do, when pressed ... ]
|
|
196 |
|
|
197 |
for buttons with a bitmap label.
|
|
198 |
|
133
|
199 |
Of course, you can also setup things the ST-80 way, in first
|
|
200 |
creating the button and later add it to some superview:
|
|
201 |
|
|
202 |
b := Button new.
|
|
203 |
b label:someImage.
|
|
204 |
b action:[ .. things to do, when pressed ... ]
|
|
205 |
...
|
|
206 |
aSuperView add:b in:<frameRectangle>.
|
118
|
207 |
|
88
|
208 |
Although you can specify a lot in a button,
|
133
|
209 |
you should use the defaults in most applications.
|
88
|
210 |
As you specify more things in your program,
|
|
211 |
the styleSheet settings are more and more ignored.
|
|
212 |
Also, even though it might look fancy, colorful
|
|
213 |
button panels are usually not a good GUI design;
|
|
214 |
they will attract the users attention - possibly to things
|
|
215 |
which are not worth it.
|
133
|
216 |
Finally, if you use fancy colors, always thing of those poor users
|
|
217 |
without color displays - the styleSheet allows those people to adjust things,
|
130
|
218 |
while hard-coded colors cannot be fixed without changing the code.
|
88
|
219 |
|
133
|
220 |
a button with default settings
|
|
221 |
(you may want to try it with different viewStyle settings in effect):
|
88
|
222 |
|
|
223 |
|top b|
|
|
224 |
|
|
225 |
top := StandardSystemView new.
|
|
226 |
top extent:100@100.
|
|
227 |
|
118
|
228 |
b := Button in:top.
|
113
|
229 |
b label:'hello'.
|
88
|
230 |
b action:[Transcript flash].
|
|
231 |
top open.
|
|
232 |
|
|
233 |
|
113
|
234 |
there is also a combined instance creation message:
|
|
235 |
|
|
236 |
|top b|
|
|
237 |
|
|
238 |
top := StandardSystemView new.
|
|
239 |
top extent:100@100.
|
|
240 |
|
|
241 |
b := Button label:'hello' action:[Transcript flash] in:top.
|
|
242 |
top open.
|
|
243 |
|
|
244 |
|
133
|
245 |
a return button
|
|
246 |
(in dialogs, you should setup things to have the return-key perform
|
|
247 |
the ok action, and mark the corresponding button as being a returnButton):
|
|
248 |
|
|
249 |
|top b|
|
|
250 |
|
|
251 |
top := StandardSystemView new.
|
|
252 |
top extent:100@100.
|
|
253 |
|
|
254 |
b := Button label:'hello' action:[Transcript flash] in:top.
|
219
|
255 |
b beReturnButton.
|
133
|
256 |
top open.
|
|
257 |
|
|
258 |
|
|
259 |
enabling/disabling buttons via explicit messages:
|
|
260 |
|
|
261 |
|top panel b1 b2 b3|
|
|
262 |
|
|
263 |
top := StandardSystemView new.
|
|
264 |
top extent:300@100.
|
|
265 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
|
|
266 |
|
|
267 |
b1 := Button label:'enable' action:[b3 enable] in:panel.
|
|
268 |
b2 := Button label:'disable' action:[b3 disable] in:panel.
|
|
269 |
b3 := Button label:'flash' action:[Transcript flash] in:panel.
|
|
270 |
top open.
|
|
271 |
|
|
272 |
|
|
273 |
enabling/disabling buttons via implicit value change of a valueHolder:
|
|
274 |
|
|
275 |
|top panel ena t b1 b2 b3 check|
|
|
276 |
|
|
277 |
top := StandardSystemView new.
|
|
278 |
top extent:300@100.
|
|
279 |
|
|
280 |
panel := HorizontalPanelView origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top.
|
|
281 |
|
|
282 |
ena := false asValue.
|
|
283 |
|
|
284 |
t := Toggle label:'enable' in:panel.
|
|
285 |
t model:ena.
|
|
286 |
|
|
287 |
b1 := Button label:'button1' in:panel.
|
|
288 |
b1 controller enableChannel:ena.
|
|
289 |
|
|
290 |
b2 := Button label:'button2' in:panel.
|
|
291 |
b2 controller enableChannel:ena.
|
|
292 |
|
|
293 |
b3 := Button label:'button3' in:panel.
|
|
294 |
b3 controller enableChannel:ena.
|
|
295 |
|
|
296 |
top open.
|
|
297 |
|
|
298 |
check := CheckBox model:ena.
|
|
299 |
check label:'also enable'.
|
|
300 |
check extent:(check preferredExtent + (5@5)).
|
|
301 |
check open
|
|
302 |
|
|
303 |
|
|
304 |
|
88
|
305 |
changing colors:
|
|
306 |
|
|
307 |
|top b|
|
|
308 |
|
|
309 |
top := StandardSystemView new.
|
|
310 |
top extent:100@100.
|
|
311 |
|
|
312 |
b := Button label:'hello' in:top.
|
|
313 |
b action:[Transcript flash].
|
|
314 |
b activeForegroundColor:(Color white).
|
|
315 |
b activeBackgroundColor:(Color red).
|
|
316 |
top open.
|
|
317 |
|
|
318 |
|
|
319 |
changing more colors:
|
|
320 |
|
|
321 |
|top b|
|
|
322 |
|
|
323 |
top := StandardSystemView new.
|
|
324 |
top extent:100@100.
|
|
325 |
|
|
326 |
b := Button label:'hello' in:top.
|
|
327 |
b action:[Transcript flash].
|
|
328 |
b enteredForegroundColor:(Color red).
|
|
329 |
b enteredBackgroundColor:(b backgroundColor).
|
|
330 |
b activeForegroundColor:(Color white).
|
|
331 |
b activeBackgroundColor:(Color red).
|
|
332 |
top open.
|
|
333 |
|
|
334 |
|
113
|
335 |
button with an image and different colors:
|
88
|
336 |
|
|
337 |
|top b|
|
|
338 |
|
|
339 |
top := StandardSystemView new.
|
|
340 |
top extent:100@100.
|
|
341 |
|
|
342 |
b := Button in:top.
|
118
|
343 |
b label:(Image fromFile:'bitmaps/SBrowser.xbm').
|
88
|
344 |
b action:[Transcript flash].
|
|
345 |
b enteredForegroundColor:(Color green darkened).
|
|
346 |
b enteredBackgroundColor:(b backgroundColor).
|
|
347 |
b activeForegroundColor:(Color white).
|
|
348 |
b activeBackgroundColor:(Color red).
|
|
349 |
top open.
|
|
350 |
|
|
351 |
|
118
|
352 |
changing the image when pressed:
|
88
|
353 |
|
|
354 |
|top b|
|
|
355 |
|
|
356 |
top := StandardSystemView new.
|
|
357 |
top extent:100@100.
|
62
|
358 |
|
88
|
359 |
b := Button in:top.
|
|
360 |
b passiveLogo:(Image fromFile:'bitmaps/SBrowser.xbm').
|
|
361 |
b activeLogo:(Image fromFile:'bitmaps/CBrowser.xbm').
|
|
362 |
b action:[Transcript flash].
|
|
363 |
b enteredForegroundColor:(Color red).
|
|
364 |
b enteredBackgroundColor:(b backgroundColor).
|
|
365 |
b activeForegroundColor:(Color white).
|
|
366 |
b activeBackgroundColor:(Color red).
|
|
367 |
top open.
|
|
368 |
|
|
369 |
|
113
|
370 |
well, even that is possible (but you should NEVER do it):
|
88
|
371 |
(notice the changing size and the resulting problem when
|
113
|
372 |
pressed near the bottom, since the button thinks the pointer
|
118
|
373 |
leaves the view and changes back and forth ...)
|
88
|
374 |
|
|
375 |
|top b|
|
|
376 |
|
|
377 |
top := StandardSystemView new.
|
|
378 |
top extent:100@100.
|
|
379 |
|
|
380 |
b := Button in:top.
|
|
381 |
b passiveLogo:(Image fromFile:'bitmaps/SmalltalkX.xbm').
|
|
382 |
b activeLogo:#('start') asStringCollection.
|
|
383 |
b action:[Transcript flash].
|
|
384 |
b enteredForegroundColor:(Color red).
|
|
385 |
b enteredBackgroundColor:(b backgroundColor).
|
|
386 |
b activeForegroundColor:(Color white).
|
|
387 |
b activeBackgroundColor:(Color red).
|
|
388 |
top open.
|
|
389 |
|
|
390 |
|
113
|
391 |
same as above, with frozen size to avoid the problem.
|
88
|
392 |
(make certain, that the size is ok for all possible logos):
|
|
393 |
|
|
394 |
|top b|
|
|
395 |
|
|
396 |
top := StandardSystemView new.
|
|
397 |
top extent:100@100.
|
|
398 |
|
|
399 |
b := Button in:top.
|
|
400 |
b passiveLogo:(Image fromFile:'bitmaps/SmalltalkX.xbm').
|
|
401 |
b activeLogo:#('go') asStringCollection.
|
|
402 |
b action:[Transcript flash].
|
|
403 |
b enteredForegroundColor:(Color red).
|
|
404 |
b enteredBackgroundColor:(b backgroundColor).
|
|
405 |
b activeForegroundColor:(Color white).
|
|
406 |
b activeBackgroundColor:(Color red).
|
|
407 |
b sizeFixed:true.
|
|
408 |
top open.
|
|
409 |
|
|
410 |
|
|
411 |
more playing with colors:
|
|
412 |
|
|
413 |
|top b|
|
|
414 |
|
|
415 |
top := StandardSystemView new.
|
|
416 |
top extent:100@100.
|
|
417 |
|
|
418 |
b := Button in:top.
|
130
|
419 |
b logo:(Image fromFile:'bitmaps/SmalltalkX.xbm').
|
|
420 |
b action:[Transcript flash].
|
|
421 |
b foregroundColor:(Color red:0 green:80 blue:20) darkened.
|
|
422 |
b backgroundColor:(Color grey:10).
|
|
423 |
b enteredForegroundColor:(Color red).
|
|
424 |
b activeForegroundColor:(Color red).
|
|
425 |
b activeBackgroundColor:(Color grey:10).
|
|
426 |
top open.
|
|
427 |
|
|
428 |
|
|
429 |
more playing with colors:
|
|
430 |
|
|
431 |
|top b|
|
|
432 |
|
|
433 |
top := StandardSystemView new.
|
|
434 |
top extent:100@100.
|
|
435 |
|
|
436 |
b := Button in:top.
|
|
437 |
b logo:(Image fromFile:'bitmaps/SmalltalkX.xbm').
|
88
|
438 |
b action:[Transcript flash].
|
|
439 |
b foregroundColor:(Color red:0 green:80 blue:20) darkened.
|
|
440 |
b backgroundColor:(Color grey:10).
|
|
441 |
b enteredBackgroundColor:(Color grey:20).
|
|
442 |
b activeForegroundColor:(Color red).
|
|
443 |
b activeBackgroundColor:(Color grey:20).
|
|
444 |
top open.
|
|
445 |
|
|
446 |
|
113
|
447 |
fire on press (buttons in scrollbars do this, while normal buttons
|
133
|
448 |
fire on release).
|
|
449 |
To give the user a chance to change her mind
|
|
450 |
and leave the button without action, you should not change the default
|
|
451 |
behavior and NOT use triggerOnDown-buttons in most applications:
|
88
|
452 |
|
|
453 |
|top b|
|
|
454 |
|
|
455 |
top := StandardSystemView new.
|
|
456 |
top extent:100@100.
|
|
457 |
|
|
458 |
b := Button label:'hello' in:top.
|
|
459 |
b controller beTriggerOnDown.
|
|
460 |
b action:[Transcript flash].
|
|
461 |
top open.
|
62
|
462 |
|
|
463 |
|
|
464 |
To implement fun buttons (for games, show-demos etc.), you can
|
|
465 |
access all internal parameters (and not take the viewStyle defaults)
|
|
466 |
as in:
|
|
467 |
|
|
468 |
|b granite light shadow|
|
|
469 |
|
88
|
470 |
b := Button label:'a nice one ?'.
|
62
|
471 |
granite := Image fromFile:'bitmaps/granite_small.tiff'.
|
|
472 |
light := granite lightened.
|
133
|
473 |
shadow := granite darkened darkened.
|
62
|
474 |
b backgroundColor:granite.
|
|
475 |
b foregroundColor:Color white.
|
|
476 |
b shadowColor:shadow.
|
|
477 |
b lightColor:light.
|
88
|
478 |
b enteredBackgroundColor:light.
|
113
|
479 |
b enteredForegroundColor:Color black.
|
164
|
480 |
b activeLevel:-3; passiveLevel:5.
|
62
|
481 |
b extent:(200 @ 50).
|
|
482 |
b open
|
|
483 |
|
|
484 |
However, in your application, you may want to read those bitmaps only once
|
|
485 |
during startup and cache them for later reuse in some class variable
|
|
486 |
(reading, lightning & darkening of images is a bit slow)
|
88
|
487 |
|
113
|
488 |
|
118
|
489 |
ST/X Buttons allow simulation of the ST-80 MVC way of interacting.
|
|
490 |
To do so, instead (or in addition) to defining actionBlocks, set the
|
127
|
491 |
buttons model to have this be informed (in addition):
|
118
|
492 |
|
|
493 |
Model-View interaction (ST-80 style):
|
|
494 |
(have a look at the models values in the inspector, as the toggles change)
|
|
495 |
|
|
496 |
|bool1 bool2 b panel top|
|
|
497 |
|
|
498 |
bool1 := ValueHolder newBoolean.
|
|
499 |
bool2 := ValueHolder newBoolean value:true.
|
|
500 |
|
|
501 |
top := StandardSystemView new.
|
|
502 |
top extent:200@100.
|
|
503 |
|
|
504 |
panel := HorizontalPanelView
|
|
505 |
origin:0.0 @ 0.0 corner:1.0 @ 50 in:top.
|
|
506 |
|
|
507 |
b := Toggle label:'eat me' in:panel.
|
|
508 |
b model:bool1.
|
|
509 |
|
|
510 |
b := Toggle label:'drink me' in:panel.
|
|
511 |
b model:bool2.
|
|
512 |
|
|
513 |
top open.
|
|
514 |
bool1 inspect.
|
|
515 |
bool2 inspect.
|
|
516 |
|
133
|
517 |
|
118
|
518 |
Using a PluggableAdaptor (ST-80 style):
|
|
519 |
(notice, that this is almost what ST/X buttons did originally,
|
127
|
520 |
therefore, you may want use actionBlocks right away ...)
|
118
|
521 |
|
|
522 |
|adaptor1 adaptor2 b panel top|
|
|
523 |
|
|
524 |
adaptor1 := PluggableAdaptor new
|
130
|
525 |
getBlock:[:m | false]
|
131
|
526 |
putBlock:[:m :v | Transcript showCr:'eat']
|
118
|
527 |
updateBlock:nil.
|
|
528 |
adaptor2 := PluggableAdaptor new
|
130
|
529 |
getBlock:[:m | false]
|
131
|
530 |
putBlock:[:m :v | Transcript showCr:'drink']
|
118
|
531 |
updateBlock:nil.
|
|
532 |
|
|
533 |
top := StandardSystemView new.
|
|
534 |
top extent:200@100.
|
|
535 |
|
|
536 |
panel := HorizontalPanelView
|
|
537 |
origin:0.0 @ 0.0 corner:1.0 @ 50 in:top.
|
|
538 |
|
130
|
539 |
b := Button label:'eat me' in:panel.
|
118
|
540 |
b model:adaptor1.
|
|
541 |
|
130
|
542 |
b := Button label:'drink me' in:panel.
|
118
|
543 |
b model:adaptor2.
|
|
544 |
|
|
545 |
top open.
|
|
546 |
|
|
547 |
|
|
548 |
as a reminder, the corresponding ST/X setup is:
|
|
549 |
|
|
550 |
|b panel top|
|
|
551 |
|
|
552 |
top := StandardSystemView new.
|
|
553 |
top extent:200@100.
|
|
554 |
|
|
555 |
panel := HorizontalPanelView
|
|
556 |
origin:0.0 @ 0.0 corner:1.0 @ 50 in:top.
|
|
557 |
|
130
|
558 |
b := Button label:'eat me' in:panel.
|
131
|
559 |
b action:[Transcript showCr:'eat'].
|
118
|
560 |
|
130
|
561 |
b := Button label:'drink me' in:panel.
|
131
|
562 |
b action:[Transcript showCr:'drink'].
|
118
|
563 |
|
|
564 |
top open.
|
|
565 |
|
|
566 |
|
130
|
567 |
accessing multiple aspects of a complex model
|
|
568 |
(using a plug here to simulate that model ...)
|
133
|
569 |
(Notice, the next example shall demonstrate multiple aspects;
|
|
570 |
for this kind of functionality, you'd better use actionBlocks in
|
|
571 |
real applications)
|
113
|
572 |
|
|
573 |
|myModel b panel top|
|
|
574 |
|
|
575 |
myModel := Plug new.
|
|
576 |
myModel respondTo:#grow with:[top extent:200@300].
|
|
577 |
myModel respondTo:#shrink with:[top extent:200@100].
|
|
578 |
|
|
579 |
top := StandardSystemView new.
|
|
580 |
top extent:200@100.
|
|
581 |
|
|
582 |
panel := HorizontalPanelView
|
|
583 |
origin:0.0 @ 0.0
|
|
584 |
corner:1.0 @ 50
|
|
585 |
in:top.
|
|
586 |
|
|
587 |
b := Button label:'eat me' in:panel.
|
|
588 |
b model:myModel; change:#grow.
|
|
589 |
|
|
590 |
b := Button label:'drink me' in:panel.
|
|
591 |
b model:myModel; change:#shrink.
|
|
592 |
|
|
593 |
top open.
|
118
|
594 |
|
113
|
595 |
|
130
|
596 |
aquiring the label from the model
|
|
597 |
(this functionality is inherited from Label)
|
|
598 |
|
|
599 |
|myModel b panel top currentLabel|
|
|
600 |
|
|
601 |
currentLabel := 'foo'.
|
|
602 |
|
|
603 |
myModel := Plug new.
|
|
604 |
myModel respondTo:#getLabel with:[currentLabel].
|
|
605 |
myModel respondTo:#b0Pressed with:[].
|
|
606 |
myModel respondTo:#b1Pressed with:[currentLabel := 'bar'.
|
|
607 |
myModel changed:#labelAspect].
|
|
608 |
myModel respondTo:#b2Pressed with:[currentLabel := 'foo'.
|
|
609 |
myModel changed:#labelAspect].
|
|
610 |
|
|
611 |
top := StandardSystemView new.
|
|
612 |
top extent:300@100.
|
|
613 |
|
|
614 |
panel := HorizontalPanelView
|
|
615 |
origin:0.0 @ 0.0
|
|
616 |
corner:1.0 @ 50
|
|
617 |
in:top.
|
|
618 |
|
|
619 |
b := Button label:'press me' in:panel.
|
|
620 |
b model:myModel; change:#b0Pressed;
|
|
621 |
labelMessage:#getLabel; aspect:#labelAspect.
|
|
622 |
|
|
623 |
b := Button label:'press for bar' in:panel.
|
|
624 |
b model:myModel; change:#b1Pressed.
|
|
625 |
|
|
626 |
b := Button label:'press for foo' in:panel.
|
|
627 |
b model:myModel; change:#b2Pressed.
|
|
628 |
|
|
629 |
top open.
|
|
630 |
|
133
|
631 |
|
|
632 |
the same, using actionBlocks:
|
|
633 |
|myModel b panel top currentLabel|
|
|
634 |
|
|
635 |
currentLabel := 'foo'.
|
|
636 |
|
|
637 |
myModel := Plug new.
|
|
638 |
myModel respondTo:#getLabel with:[currentLabel].
|
|
639 |
|
|
640 |
top := StandardSystemView new.
|
|
641 |
top extent:300@100.
|
|
642 |
|
|
643 |
panel := HorizontalPanelView origin:0.0 @ 0.0 corner:1.0 @ 50 in:top.
|
|
644 |
|
|
645 |
b := Button label:'press me' in:panel.
|
|
646 |
b model:myModel; action:[Transcript showCr:'pressed'];
|
|
647 |
labelMessage:#getLabel; aspect:#labelAspect.
|
|
648 |
|
|
649 |
b := Button label:'press for bar' in:panel.
|
|
650 |
b action:[currentLabel := 'bar'. myModel changed:#labelAspect].
|
|
651 |
|
|
652 |
b := Button label:'press for foo' in:panel.
|
|
653 |
b action:[currentLabel := 'foo'. myModel changed:#labelAspect].
|
|
654 |
|
|
655 |
top open.
|
|
656 |
|
88
|
657 |
see 'doc/coding-examples' and 'doc/misc/quick_view_intro.doc'
|
|
658 |
for more variations on this theme.
|
0
|
659 |
"
|
|
660 |
! !
|
|
661 |
|
205
|
662 |
!Button class methodsFor:'instance creation'!
|
|
663 |
|
|
664 |
abortButton
|
|
665 |
"since abort-buttons are very common, here is a convenient
|
|
666 |
method to create one ..."
|
|
667 |
|
|
668 |
|aButton|
|
0
|
669 |
|
205
|
670 |
aButton := Button label:(self classResources at:'abort').
|
|
671 |
aButton cursor:(Cursor thumbsDown).
|
|
672 |
^ aButton
|
|
673 |
!
|
|
674 |
|
|
675 |
abortButtonIn:aView
|
|
676 |
"since abort-buttons are very common, here is a convenient
|
|
677 |
method to create one ..."
|
|
678 |
|
|
679 |
|b|
|
60
|
680 |
|
205
|
681 |
aView addSubView:(b := self abortButton).
|
|
682 |
^ b
|
|
683 |
!
|
|
684 |
|
|
685 |
form:aForm action:aBlock in:aView
|
|
686 |
"create and return a new Button with icon-label, aForm
|
|
687 |
and pressAction, aBlock. Button is placed into aView.
|
|
688 |
OBSOLETE: this is for backward compatibility;
|
|
689 |
you can now pass an image or form in the #label:action:in: message."
|
|
690 |
|
|
691 |
^ ((self in:aView) form:aForm) action:aBlock
|
|
692 |
!
|
|
693 |
|
|
694 |
label:aLabel action:aBlock
|
|
695 |
"create and return a new Button with text-label, aString
|
|
696 |
and pressAction, aBlock."
|
|
697 |
|
|
698 |
^ (self label:aLabel) action:aBlock
|
|
699 |
!
|
|
700 |
|
|
701 |
label:aLabel action:aBlock in:aView
|
|
702 |
"create and return a new Button with text-label, aString
|
|
703 |
and pressAction, aBlock. Button is placed into aView."
|
60
|
704 |
|
205
|
705 |
^ ((self in:aView) label:aLabel) action:aBlock
|
|
706 |
!
|
|
707 |
|
|
708 |
okButton
|
|
709 |
"since ok-buttons are very common, here is a convenient
|
|
710 |
method to create one ..."
|
|
711 |
|
|
712 |
|aButton|
|
|
713 |
|
|
714 |
aButton := Button label:(self classResources at:'ok').
|
|
715 |
aButton cursor:(Cursor thumbsUp).
|
219
|
716 |
aButton beReturnButton.
|
205
|
717 |
^ aButton
|
59
|
718 |
!
|
|
719 |
|
205
|
720 |
okButtonIn:aView
|
|
721 |
"since ok-buttons are very common, here is a convenient
|
|
722 |
method to create one ..."
|
|
723 |
|
|
724 |
|b|
|
|
725 |
|
|
726 |
aView addSubView:(b := self okButton).
|
|
727 |
^ b
|
|
728 |
!
|
|
729 |
|
|
730 |
toggle
|
|
731 |
"ST-80 compatibility: create & return a new toggle."
|
|
732 |
|
|
733 |
^ Toggle new
|
|
734 |
|
|
735 |
"
|
|
736 |
Button toggle label:'press me';
|
|
737 |
model:((PluggableAdaptor on:(Point new))
|
|
738 |
getSelector:#x putSelector:#x:)
|
|
739 |
"
|
|
740 |
"this is the same as"
|
|
741 |
"
|
|
742 |
Toggle new label:'press me';
|
|
743 |
model:((PluggableAdaptor on:(Point new))
|
|
744 |
getSelector:#x putSelector:#x:)
|
|
745 |
"
|
|
746 |
! !
|
|
747 |
|
|
748 |
!Button class methodsFor:'defaults'!
|
|
749 |
|
0
|
750 |
returnFormOn:aDevice
|
|
751 |
"return the form used for the return arrow in non-3D;
|
|
752 |
cache the one for Display for the next round."
|
|
753 |
|
|
754 |
|f|
|
|
755 |
|
35
|
756 |
(ReturnForm notNil and:[aDevice == ReturnForm device]) ifTrue:[
|
59
|
757 |
^ ReturnForm
|
0
|
758 |
].
|
|
759 |
f := Form fromFile:'Return.xbm' resolution:100 on:aDevice.
|
|
760 |
f isNil ifTrue:[
|
59
|
761 |
f := Form width:24 height:16 fromArray:#[2r00000000 2r00000000 2r00000000
|
|
762 |
2r00000000 2r00000000 2r00000000
|
|
763 |
2r00000000 2r00000000 2r00000000
|
|
764 |
2r00000000 2r00000011 2r11100000
|
|
765 |
2r00000001 2r10000011 2r11100000
|
|
766 |
2r00000011 2r10000011 2r11100000
|
|
767 |
2r00000111 2r11111111 2r11100000
|
|
768 |
2r00001111 2r11111111 2r11100000
|
|
769 |
2r00011111 2r11111111 2r11100000
|
|
770 |
2r00001111 2r11111111 2r11100000
|
|
771 |
2r00000111 2r11111111 2r11100000
|
|
772 |
2r00000011 2r10000000 2r00000000
|
|
773 |
2r00000001 2r10000000 2r00000000
|
|
774 |
2r00000000 2r00000000 2r00000000
|
|
775 |
2r00000000 2r00000000 2r00000000
|
|
776 |
2r00000000 2r00000000 2r00000000]
|
|
777 |
on:aDevice
|
0
|
778 |
].
|
35
|
779 |
ReturnForm := f.
|
0
|
780 |
^ f
|
|
781 |
!
|
|
782 |
|
205
|
783 |
returnLightFormOn:aDevice
|
|
784 |
"return the form used for the return arrow light pixels (3D only);
|
|
785 |
cache the one for Display for the next round"
|
|
786 |
|
|
787 |
|f|
|
|
788 |
|
|
789 |
(ReturnLightForm notNil and:[aDevice == ReturnLightForm device]) ifTrue:[
|
|
790 |
^ ReturnLightForm
|
|
791 |
].
|
|
792 |
f := Form fromFile:'ReturnLight.xbm' resolution:100 on:aDevice.
|
|
793 |
f isNil ifTrue:[
|
|
794 |
f := Form width:24 height:16 fromArray:#[2r00000000 2r00000000 2r00000000
|
|
795 |
2r00000000 2r00000000 2r00000000
|
|
796 |
2r00000000 2r00000000 2r00000000
|
|
797 |
2r00000000 2r00000000 2r00000000
|
|
798 |
2r00000000 2r00000000 2r00100000
|
|
799 |
2r00000000 2r00000000 2r00100000
|
|
800 |
2r00000000 2r00000000 2r00100000
|
|
801 |
2r00000000 2r00000000 2r00100000
|
|
802 |
2r00000000 2r00000000 2r00100000
|
|
803 |
2r00000000 2r00000000 2r00100000
|
|
804 |
2r00000000 2r11111111 2r11100000
|
|
805 |
2r00000000 2r10000000 2r00000000
|
|
806 |
2r00000000 2r10000000 2r00000000
|
|
807 |
2r00000000 2r00000000 2r00000000
|
|
808 |
2r00000000 2r00000000 2r00000000
|
|
809 |
2r00000000 2r00000000 2r00000000]
|
|
810 |
on:aDevice
|
|
811 |
].
|
|
812 |
ReturnLightForm := f.
|
|
813 |
^ f
|
|
814 |
!
|
|
815 |
|
0
|
816 |
returnShadowFormOn:aDevice
|
|
817 |
"return the form used for the return arrow shadow pixels (3D only);
|
|
818 |
cache the one for Display for the next round."
|
|
819 |
|
|
820 |
|f|
|
|
821 |
|
35
|
822 |
(ReturnShadowForm notNil and:[aDevice == ReturnShadowForm device]) ifTrue:[
|
59
|
823 |
^ ReturnShadowForm
|
0
|
824 |
].
|
|
825 |
f := Form fromFile:'ReturnShadow.xbm' resolution:100 on:aDevice.
|
|
826 |
f isNil ifTrue:[
|
59
|
827 |
f := Form width:24 height:16 fromArray:#[2r00000000 2r00000000 2r00000000
|
|
828 |
2r00000000 2r00000000 2r00000000
|
|
829 |
2r00000000 2r00000000 2r00000000
|
|
830 |
2r00000000 2r00000011 2r11100000
|
|
831 |
2r00000001 2r10000010 2r00000000
|
|
832 |
2r00000010 2r10000010 2r00000000
|
|
833 |
2r00000100 2r11111110 2r00000000
|
|
834 |
2r00001000 2r00000000 2r00000000
|
|
835 |
2r00010000 2r00000000 2r00000000
|
|
836 |
2r00001000 2r00000000 2r00000000
|
|
837 |
2r00000100 2r00000000 2r00000000
|
|
838 |
2r00000010 2r00000000 2r00000000
|
|
839 |
2r00000001 2r00000000 2r00000000
|
|
840 |
2r00000000 2r00000000 2r00000000
|
|
841 |
2r00000000 2r00000000 2r00000000
|
|
842 |
2r00000000 2r00000000 2r00000000]
|
|
843 |
on:aDevice
|
0
|
844 |
].
|
35
|
845 |
ReturnShadowForm := f.
|
0
|
846 |
^ f
|
|
847 |
!
|
|
848 |
|
205
|
849 |
updateStyleCache
|
|
850 |
|defaultLevel|
|
0
|
851 |
|
205
|
852 |
StyleSheet is3D ifTrue:[
|
|
853 |
defaultLevel := 1.
|
|
854 |
] ifFalse:[
|
|
855 |
defaultLevel := 0
|
0
|
856 |
].
|
205
|
857 |
DefaultActiveLevel := StyleSheet at:'buttonActiveLevel' default:(defaultLevel negated).
|
|
858 |
DefaultPassiveLevel := StyleSheet at:'buttonPassiveLevel' default:defaultLevel.
|
|
859 |
|
|
860 |
DefaultEdgeStyle := StyleSheet at:'buttonEdgeStyle'.
|
|
861 |
DefaultFont := StyleSheet fontAt:'buttonFont'.
|
|
862 |
DefaultBorderWidth := StyleSheet at:'buttonBorderWidth'.
|
|
863 |
DefaultForegroundColor := StyleSheet colorAt:'buttonForegroundColor'.
|
|
864 |
DefaultBackgroundColor := StyleSheet colorAt:'buttonBackgroundColor'.
|
|
865 |
DefaultDisabledForegroundColor := StyleSheet colorAt:'buttonDisabledForegroundColor' default:Color grey.
|
|
866 |
DefaultDisabledBackgroundColor := StyleSheet colorAt:'buttonDisabledBackgroundColor'.
|
|
867 |
DefaultEnteredForegroundColor := StyleSheet colorAt:'buttonEnteredForegroundColor'.
|
|
868 |
DefaultEnteredBackgroundColor := StyleSheet colorAt:'buttonEnteredBackgroundColor'.
|
|
869 |
DefaultActiveForegroundColor := StyleSheet colorAt:'buttonActiveForegroundColor'.
|
|
870 |
DefaultActiveBackgroundColor := StyleSheet colorAt:'buttonActiveBackgroundColor'.
|
|
871 |
DefaultReturnButtonHasImage := StyleSheet at:'buttonReturnButtonHasImage' default:true.
|
|
872 |
DefaultReturnButtonHasBorder := StyleSheet at:'buttonReturnButtonHasBorder' default:false.
|
|
873 |
DefaultShadowColor := StyleSheet colorAt:'buttonShadowColor'.
|
|
874 |
DefaultLightColor := StyleSheet colorAt:'buttonLightColor'.
|
|
875 |
DefaultHalfShadowColor := StyleSheet colorAt:'buttonHalfShadowColor'.
|
|
876 |
DefaultHalfLightColor := StyleSheet colorAt:'buttonHalfLightColor'.
|
0
|
877 |
! !
|
|
878 |
|
205
|
879 |
!Button methodsFor:'accessing-behavior'!
|
|
880 |
|
|
881 |
action:aBlock
|
|
882 |
"convenient method: depending on the setting of controllers triggerOnDown flag,
|
|
883 |
either set the press-action and clear any release-action or
|
|
884 |
vice versa, set the release-action and clear the press-action."
|
|
885 |
|
|
886 |
controller action:aBlock
|
|
887 |
!
|
|
888 |
|
|
889 |
autoRepeat
|
|
890 |
"turn on autorepeat OBSOLETE"
|
|
891 |
|
|
892 |
controller autoRepeat
|
|
893 |
!
|
|
894 |
|
|
895 |
autoRepeat:aBoolean
|
|
896 |
"turn on/off autorepeat"
|
|
897 |
|
|
898 |
controller autoRepeat:aBoolean
|
|
899 |
|
|
900 |
"Modified: 5.9.1995 / 22:06:13 / claus"
|
|
901 |
!
|
|
902 |
|
|
903 |
disable
|
|
904 |
"disable the button"
|
|
905 |
|
|
906 |
controller disable.
|
|
907 |
!
|
|
908 |
|
|
909 |
enable
|
|
910 |
"enable the button"
|
|
911 |
|
|
912 |
controller enable
|
|
913 |
!
|
|
914 |
|
|
915 |
enableChannel
|
|
916 |
"return the valueHolder used for enable/disable"
|
|
917 |
|
|
918 |
^ controller enableChannel
|
|
919 |
!
|
|
920 |
|
|
921 |
enableChannel:aValueHolderForBoolean
|
|
922 |
"set the valueHolder used for enable/disable"
|
|
923 |
|
|
924 |
controller enableChannel:aValueHolderForBoolean
|
|
925 |
!
|
|
926 |
|
|
927 |
pressAction
|
|
928 |
"return the pressAction; thats the block which gets evaluated
|
|
929 |
when the button is pressed (if non-nil)"
|
|
930 |
|
|
931 |
^ controller pressAction
|
|
932 |
!
|
0
|
933 |
|
205
|
934 |
pressAction:aBlock
|
|
935 |
"define the action to be performed on press"
|
|
936 |
|
|
937 |
controller pressAction:aBlock
|
|
938 |
!
|
|
939 |
|
|
940 |
pressChannel
|
|
941 |
"return the pressChannel"
|
|
942 |
|
|
943 |
^ controller pressChannel
|
|
944 |
|
|
945 |
"Modified: 7.9.1995 / 18:16:20 / claus"
|
|
946 |
!
|
|
947 |
|
|
948 |
pressChannel:aBlock
|
|
949 |
"set the pressChannel"
|
|
950 |
|
|
951 |
controller pressChannel:aBlock
|
|
952 |
|
|
953 |
"Modified: 7.9.1995 / 18:05:14 / claus"
|
|
954 |
!
|
|
955 |
|
|
956 |
releaseAction
|
|
957 |
"return the releaseAction; thats the block which gets evaluated
|
|
958 |
when the button is relreased (if non-nil)"
|
|
959 |
|
|
960 |
^ controller releaseAction
|
|
961 |
!
|
164
|
962 |
|
205
|
963 |
releaseAction:aBlock
|
|
964 |
"define the action to be performed on release"
|
|
965 |
|
|
966 |
controller releaseAction:aBlock
|
|
967 |
!
|
|
968 |
|
|
969 |
releaseChannel
|
|
970 |
"return the releaseChannel"
|
|
971 |
|
|
972 |
^ controller releaseChannel
|
|
973 |
|
|
974 |
"Modified: 7.9.1995 / 18:15:24 / claus"
|
|
975 |
!
|
|
976 |
|
|
977 |
releaseChannel:aBlock
|
|
978 |
"set the releaseChannel"
|
|
979 |
|
|
980 |
controller releaseChannel:aBlock
|
|
981 |
|
|
982 |
"Modified: 7.9.1995 / 18:05:21 / claus"
|
|
983 |
! !
|
|
984 |
|
|
985 |
!Button methodsFor:'accessing-look'!
|
|
986 |
|
|
987 |
activeBackgroundColor
|
|
988 |
"return the background color to be used when pressed"
|
|
989 |
|
|
990 |
^ activeBgColor
|
164
|
991 |
!
|
|
992 |
|
205
|
993 |
activeBackgroundColor:aColor
|
|
994 |
"set the background color to be used when pressed"
|
|
995 |
|
|
996 |
activeBgColor := aColor.
|
|
997 |
self redrawIfPressed
|
|
998 |
!
|
|
999 |
|
|
1000 |
activeForegroundColor
|
|
1001 |
"return the foreground color to be used when pressed"
|
|
1002 |
|
|
1003 |
^ activeFgColor
|
|
1004 |
!
|
|
1005 |
|
|
1006 |
activeForegroundColor:aColor
|
|
1007 |
"set the foreground color to be used when pressed"
|
|
1008 |
|
|
1009 |
activeFgColor := aColor.
|
|
1010 |
self redrawIfPressed
|
|
1011 |
!
|
|
1012 |
|
|
1013 |
activeForegroundColor:fgColor backgroundColor:bgColor
|
|
1014 |
"set both fg and bg colors to be used when pressed"
|
|
1015 |
|
|
1016 |
activeFgColor := fgColor.
|
|
1017 |
activeBgColor := bgColor.
|
|
1018 |
self redrawIfPressed
|
|
1019 |
!
|
0
|
1020 |
|
205
|
1021 |
activeLevel
|
|
1022 |
"return the level of the button when pressed"
|
|
1023 |
|
|
1024 |
^ onLevel
|
|
1025 |
!
|
|
1026 |
|
|
1027 |
activeLevel:aNumber
|
|
1028 |
"set the level of the button when pressed (i.e. how deep)"
|
|
1029 |
|
|
1030 |
onLevel := aNumber.
|
|
1031 |
(controller notNil
|
|
1032 |
and:[controller pressed]) ifTrue:[
|
|
1033 |
self level:onLevel.
|
|
1034 |
margin := onLevel abs max:offLevel abs.
|
|
1035 |
self redraw
|
|
1036 |
]
|
|
1037 |
!
|
|
1038 |
|
|
1039 |
activeLogo:anImageOrString
|
|
1040 |
"define the logo to be displayed while active -
|
|
1041 |
this is optional; the default is to display the same
|
|
1042 |
(logo) in both pressed and released states."
|
|
1043 |
|
|
1044 |
activeLogo := anImageOrString.
|
|
1045 |
controller pressed ifTrue:[
|
|
1046 |
self logo:anImageOrString
|
|
1047 |
]
|
0
|
1048 |
!
|
|
1049 |
|
205
|
1050 |
beImageButton
|
|
1051 |
"make mySelf an image button - that is turn off all levelChanges
|
|
1052 |
and logo spacing. This should be sent for buttons which use both
|
|
1053 |
passive and active logos, and the 3D effect comes from the bitmaps
|
|
1054 |
(i.e. windows buttons)."
|
|
1055 |
|
|
1056 |
self
|
|
1057 |
extent:(labelWidth @ labelHeight);
|
|
1058 |
sizeFixed:true;
|
|
1059 |
borderWidth:0;
|
|
1060 |
onLevel:0;
|
|
1061 |
offLevel:0;
|
|
1062 |
horizontalSpace:0;
|
|
1063 |
verticalSpace:0;
|
|
1064 |
newLayout.
|
|
1065 |
|
|
1066 |
"Created: 17.9.1995 / 20:41:47 / claus"
|
|
1067 |
"Modified: 19.9.1995 / 16:34:08 / claus"
|
|
1068 |
!
|
|
1069 |
|
|
1070 |
beRoundRadioButton
|
|
1071 |
"setup myself for a round radioButton look.
|
|
1072 |
this is a private method; do not use it. It is going to move into the
|
|
1073 |
RadioButton class."
|
0
|
1074 |
|
205
|
1075 |
self activeLogo:(Icon constantNamed:'RadioOn').
|
|
1076 |
self passiveLogo:(Icon constantNamed:'RadioOff').
|
|
1077 |
self activeLevel:0;
|
|
1078 |
passiveLevel:0;
|
|
1079 |
activeBackgroundColor:bgColor;
|
|
1080 |
activeForegroundColor:fgColor;
|
|
1081 |
borderWidth:0;
|
|
1082 |
enteredBackgroundColor:bgColor.
|
|
1083 |
self computeLabelSize.
|
|
1084 |
self beImageButton.
|
|
1085 |
|
|
1086 |
"Created: 22.9.1995 / 15:48:05 / claus"
|
|
1087 |
"Modified: 22.9.1995 / 17:07:46 / claus"
|
|
1088 |
!
|
|
1089 |
|
|
1090 |
disabledForegroundColor
|
|
1091 |
"return the foreground color used when the button is disabled"
|
|
1092 |
|
|
1093 |
^ disabledFgColor
|
|
1094 |
!
|
|
1095 |
|
|
1096 |
disabledLogo:anImageOrString
|
|
1097 |
"define the logo to be displayed while active -
|
|
1098 |
this is optional; the default is to display the same
|
|
1099 |
(logo) in both pressed and released states."
|
|
1100 |
|
|
1101 |
disabledLogo := anImageOrString.
|
|
1102 |
controller enabled ifFalse:[
|
|
1103 |
self logo:anImageOrString
|
|
1104 |
]
|
|
1105 |
|
|
1106 |
"Created: 17.9.1995 / 19:50:17 / claus"
|
|
1107 |
"Modified: 17.9.1995 / 19:50:34 / claus"
|
59
|
1108 |
!
|
|
1109 |
|
205
|
1110 |
edgeStyle:aSymbol
|
|
1111 |
"set the edgestyle - currently only #soft or nil"
|
|
1112 |
|
|
1113 |
edgeStyle := aSymbol
|
|
1114 |
!
|
|
1115 |
|
|
1116 |
enteredBackgroundColor
|
|
1117 |
"return the background color to be used when the mouse
|
|
1118 |
pointer enters the button area"
|
|
1119 |
|
|
1120 |
^ enteredBgColor
|
|
1121 |
!
|
|
1122 |
|
|
1123 |
enteredBackgroundColor:aColor
|
|
1124 |
"set the background color to be used when the mouse
|
|
1125 |
pointer enters the button area"
|
|
1126 |
|
|
1127 |
enteredBgColor := aColor
|
|
1128 |
!
|
|
1129 |
|
|
1130 |
enteredForegroundColor
|
|
1131 |
"return the foreground color to be used when the mouse
|
|
1132 |
pointer enters the button area"
|
|
1133 |
|
|
1134 |
^ enteredFgColor
|
|
1135 |
!
|
|
1136 |
|
|
1137 |
enteredForegroundColor:aColor
|
|
1138 |
"set the foreground color to be used when the mouse
|
|
1139 |
pointer enters the button area"
|
59
|
1140 |
|
205
|
1141 |
enteredFgColor := aColor
|
|
1142 |
!
|
|
1143 |
|
|
1144 |
focusLogo:anImageOrString
|
|
1145 |
"define the logo to be displayed while active -
|
|
1146 |
this is optional; the default is to display the same
|
|
1147 |
(logo) in both pressed and released states."
|
|
1148 |
|
|
1149 |
focusLogo := anImageOrString.
|
|
1150 |
|
|
1151 |
"Created: 17.9.1995 / 19:50:17 / claus"
|
|
1152 |
"Modified: 17.9.1995 / 20:00:43 / claus"
|
|
1153 |
!
|
59
|
1154 |
|
219
|
1155 |
beReturnButton
|
|
1156 |
"show show a return-key image after the label"
|
|
1157 |
|
|
1158 |
self isReturnButton:true
|
|
1159 |
!
|
|
1160 |
|
205
|
1161 |
isReturnButton:aBoolean
|
|
1162 |
"show/dont show a return-key image after the label"
|
|
1163 |
|
|
1164 |
isReturnButton ~~ aBoolean ifTrue:[
|
|
1165 |
DefaultReturnButtonHasBorder ifTrue:[
|
|
1166 |
self borderWidth:(aBoolean ifTrue:[1] ifFalse:[0])
|
|
1167 |
].
|
|
1168 |
isReturnButton := aBoolean.
|
|
1169 |
self newLayout
|
|
1170 |
]
|
|
1171 |
!
|
|
1172 |
|
|
1173 |
offLevel
|
|
1174 |
"return the level of the button when released.
|
|
1175 |
Historic leftover; use #passiveLevel."
|
|
1176 |
|
|
1177 |
^ offLevel
|
59
|
1178 |
!
|
|
1179 |
|
205
|
1180 |
offLevel:aNumber
|
|
1181 |
"set the level of the button when released (i.e. how deep).
|
|
1182 |
Historic leftover; use #passiveLevel:."
|
|
1183 |
|
|
1184 |
^ self passiveLevel:aNumber
|
|
1185 |
!
|
|
1186 |
|
|
1187 |
onLevel
|
|
1188 |
"return the level of the button when pressed.
|
|
1189 |
Historic leftover; use #activeLevel."
|
|
1190 |
|
|
1191 |
^ onLevel
|
|
1192 |
!
|
|
1193 |
|
|
1194 |
onLevel:aNumber
|
|
1195 |
"set the level of the button when pressed (i.e. how deep).
|
|
1196 |
Historic leftover; use #activeLevel:."
|
|
1197 |
|
|
1198 |
^ self activeLevel:aNumber
|
|
1199 |
!
|
|
1200 |
|
|
1201 |
passiveLevel
|
|
1202 |
"return the level of the button when released"
|
|
1203 |
|
|
1204 |
^ offLevel
|
|
1205 |
!
|
|
1206 |
|
|
1207 |
passiveLevel:aNumber
|
|
1208 |
"set the level of the button when not pressed (i.e. how high)"
|
118
|
1209 |
|
205
|
1210 |
offLevel := aNumber.
|
|
1211 |
(controller notNil
|
|
1212 |
and:[controller pressed not]) ifTrue:[
|
|
1213 |
self level:offLevel.
|
|
1214 |
margin := onLevel abs max:offLevel abs.
|
|
1215 |
self redraw
|
|
1216 |
]
|
|
1217 |
!
|
|
1218 |
|
|
1219 |
passiveLogo:anImageOrString
|
|
1220 |
"define the logo to be displayed while inactive -
|
|
1221 |
this is optional; the default is to display the same
|
|
1222 |
(logo) in both pressed and released states."
|
118
|
1223 |
|
205
|
1224 |
passiveLogo := anImageOrString.
|
|
1225 |
controller pressed ifFalse:[
|
|
1226 |
self logo:anImageOrString
|
|
1227 |
]
|
|
1228 |
! !
|
|
1229 |
|
|
1230 |
!Button methodsFor:'changing state'!
|
|
1231 |
|
|
1232 |
toggle
|
|
1233 |
"toggle and perform the action"
|
|
1234 |
|
|
1235 |
controller toggle
|
|
1236 |
!
|
|
1237 |
|
|
1238 |
toggleNoAction
|
|
1239 |
"toggle, but do NOT perform any action - can be used to change a toggle
|
|
1240 |
under program control (i.e. turn one toggle off from another one)"
|
|
1241 |
|
|
1242 |
controller toggleNoAction
|
118
|
1243 |
!
|
|
1244 |
|
205
|
1245 |
turnOff
|
|
1246 |
"turn the button off (if not already off) do NOT perform actions/change notifications"
|
|
1247 |
|
|
1248 |
controller pressed ifTrue:[
|
|
1249 |
offLevel ~~ level ifTrue:[
|
|
1250 |
self level:offLevel.
|
|
1251 |
].
|
|
1252 |
(passiveLogo notNil and:[passiveLogo ~~ logo]) ifTrue:[
|
|
1253 |
self logo:passiveLogo
|
|
1254 |
].
|
|
1255 |
controller setPressed:false.
|
|
1256 |
controller active:false.
|
|
1257 |
level := offLevel.
|
|
1258 |
margin := level abs.
|
|
1259 |
self redraw
|
|
1260 |
]
|
|
1261 |
!
|
|
1262 |
|
|
1263 |
turnOffWithAction
|
|
1264 |
"turn the button off (if not already off) and perform any action/change notification"
|
118
|
1265 |
|
205
|
1266 |
controller pressed ifTrue:[
|
|
1267 |
offLevel ~~ level ifTrue:[
|
|
1268 |
self level:offLevel.
|
|
1269 |
].
|
|
1270 |
(passiveLogo notNil and:[passiveLogo ~~ logo]) ifTrue:[
|
|
1271 |
self logo:passiveLogo
|
|
1272 |
].
|
|
1273 |
self turnOffWithoutRedraw.
|
|
1274 |
self redraw
|
|
1275 |
]
|
118
|
1276 |
|
205
|
1277 |
"Created: 15.11.1995 / 16:55:37 / cg"
|
|
1278 |
!
|
|
1279 |
|
|
1280 |
turnOffWithoutRedraw
|
|
1281 |
"turn the button off - no redraw but perform any action/change notification"
|
|
1282 |
|
|
1283 |
controller pressed:false.
|
|
1284 |
controller active:false.
|
|
1285 |
|
|
1286 |
"do not use super level:offLevel
|
|
1287 |
- because that one does redraw the edges.
|
|
1288 |
Sure, this is no good coding style"
|
|
1289 |
|
|
1290 |
level := offLevel.
|
|
1291 |
margin := level abs
|
118
|
1292 |
!
|
|
1293 |
|
205
|
1294 |
turnOn
|
|
1295 |
"turn the button on (if not already on) - do NOT perform any action/notification"
|
|
1296 |
|
|
1297 |
controller pressed ifFalse:[
|
|
1298 |
onLevel ~~ level ifTrue:[
|
|
1299 |
self level:onLevel.
|
|
1300 |
].
|
|
1301 |
(activeLogo notNil and:[activeLogo ~~ logo]) ifTrue:[
|
|
1302 |
self logo:activeLogo
|
|
1303 |
].
|
|
1304 |
controller setPressed:true.
|
|
1305 |
level := onLevel.
|
|
1306 |
margin := level abs.
|
|
1307 |
|
|
1308 |
self redraw
|
|
1309 |
]
|
59
|
1310 |
|
205
|
1311 |
"Created: 14.11.1995 / 22:00:45 / cg"
|
|
1312 |
"Modified: 14.11.1995 / 22:01:02 / cg"
|
|
1313 |
!
|
|
1314 |
|
|
1315 |
turnOnWithAction
|
|
1316 |
"turn the button on (if not already on) and perform any change actions/notifications"
|
118
|
1317 |
|
205
|
1318 |
controller pressed ifFalse:[
|
|
1319 |
onLevel ~~ level ifTrue:[
|
|
1320 |
self level:onLevel.
|
|
1321 |
].
|
|
1322 |
(activeLogo notNil and:[activeLogo ~~ logo]) ifTrue:[
|
|
1323 |
self logo:activeLogo
|
|
1324 |
].
|
|
1325 |
self turnOnWithoutRedraw.
|
|
1326 |
self redraw
|
|
1327 |
]
|
|
1328 |
|
|
1329 |
"Created: 15.11.1995 / 16:55:56 / cg"
|
118
|
1330 |
!
|
|
1331 |
|
205
|
1332 |
turnOnWithoutRedraw
|
|
1333 |
"turn the button on - no redraw but perform any change actions/notifications"
|
|
1334 |
|
|
1335 |
controller pressed:true.
|
118
|
1336 |
|
205
|
1337 |
"do not use super level:offLevel
|
|
1338 |
- because that one does redraw the edges.
|
|
1339 |
Sure, this is no good coding style"
|
|
1340 |
|
|
1341 |
level := onLevel.
|
|
1342 |
margin := level abs
|
|
1343 |
! !
|
|
1344 |
|
|
1345 |
!Button methodsFor:'focus change'!
|
59
|
1346 |
|
205
|
1347 |
showFocus
|
|
1348 |
focusLogo notNil ifTrue:[
|
|
1349 |
controller enabled ifTrue:[
|
|
1350 |
logo := focusLogo.
|
|
1351 |
^ self redisplay
|
|
1352 |
]
|
|
1353 |
].
|
|
1354 |
super showFocus
|
|
1355 |
|
|
1356 |
"Created: 17.9.1995 / 19:58:50 / claus"
|
|
1357 |
!
|
|
1358 |
|
|
1359 |
showNoFocus
|
|
1360 |
focusLogo notNil ifTrue:[
|
|
1361 |
disabledLogo notNil ifTrue:[
|
|
1362 |
controller enabled ifTrue:[
|
|
1363 |
logo := passiveLogo.
|
|
1364 |
] ifFalse:[
|
|
1365 |
logo := disabledLogo.
|
|
1366 |
].
|
|
1367 |
] ifFalse:[
|
|
1368 |
logo := passiveLogo
|
|
1369 |
].
|
|
1370 |
^ self redisplay
|
|
1371 |
].
|
|
1372 |
super showNoFocus
|
|
1373 |
|
|
1374 |
"Created: 17.9.1995 / 20:00:06 / claus"
|
|
1375 |
"Modified: 17.9.1995 / 20:26:32 / claus"
|
0
|
1376 |
! !
|
|
1377 |
|
|
1378 |
!Button methodsFor:'initialization'!
|
|
1379 |
|
205
|
1380 |
defaultControllerClass
|
|
1381 |
^ ButtonController
|
|
1382 |
!
|
|
1383 |
|
|
1384 |
initCursor
|
|
1385 |
"set up a hand cursor"
|
0
|
1386 |
|
205
|
1387 |
cursor := Cursor hand
|
|
1388 |
!
|
|
1389 |
|
|
1390 |
initEvents
|
|
1391 |
super initEvents.
|
|
1392 |
self enableEnterLeaveEvents
|
0
|
1393 |
!
|
|
1394 |
|
|
1395 |
initStyle
|
59
|
1396 |
|hasGreyscales nm|
|
|
1397 |
|
|
1398 |
super initStyle.
|
|
1399 |
|
|
1400 |
DefaultFont notNil ifTrue:[font := DefaultFont on:device].
|
74
|
1401 |
DefaultBorderWidth notNil ifTrue:[borderWidth := DefaultBorderWidth].
|
59
|
1402 |
DefaultForegroundColor notNil ifTrue:[fgColor := DefaultForegroundColor on:device].
|
|
1403 |
DefaultBackgroundColor notNil ifTrue:[bgColor := DefaultBackgroundColor on:device].
|
|
1404 |
|
62
|
1405 |
edgeStyle := DefaultEdgeStyle.
|
59
|
1406 |
onLevel := DefaultActiveLevel.
|
|
1407 |
offLevel := DefaultPassiveLevel.
|
|
1408 |
|
|
1409 |
DefaultDisabledForegroundColor notNil ifTrue:[
|
|
1410 |
disabledFgColor := DefaultDisabledForegroundColor on:device
|
|
1411 |
] ifFalse:[
|
|
1412 |
disabledFgColor := fgColor
|
|
1413 |
].
|
|
1414 |
|
|
1415 |
DefaultEnteredForegroundColor notNil ifTrue:[enteredFgColor := DefaultEnteredForegroundColor on:device].
|
|
1416 |
DefaultEnteredBackgroundColor notNil ifTrue:[enteredBgColor := DefaultEnteredBackgroundColor on:device].
|
|
1417 |
DefaultActiveForegroundColor notNil ifTrue:[activeFgColor := DefaultActiveForegroundColor on:device].
|
|
1418 |
DefaultActiveBackgroundColor notNil ifTrue:[activeBgColor := DefaultActiveBackgroundColor on:device].
|
|
1419 |
|
62
|
1420 |
DefaultShadowColor notNil ifTrue:[shadowColor := DefaultShadowColor on:device].
|
|
1421 |
DefaultLightColor notNil ifTrue:[lightColor := DefaultLightColor on:device].
|
59
|
1422 |
|
62
|
1423 |
shadowColor isNil ifTrue:[
|
|
1424 |
shadowColor := Black.
|
|
1425 |
].
|
|
1426 |
lightColor isNil ifTrue:[
|
|
1427 |
lightColor := White.
|
|
1428 |
].
|
59
|
1429 |
|
|
1430 |
hasGreyscales := device hasGreyscales.
|
62
|
1431 |
(edgeStyle == #soft) ifTrue:[
|
|
1432 |
DefaultHalfShadowColor notNil ifTrue:[halfShadowColor := DefaultHalfShadowColor on:device].
|
|
1433 |
DefaultHalfLightColor notNil ifTrue:[halfLightColor := DefaultHalfLightColor on:device].
|
|
1434 |
|
|
1435 |
halfShadowColor isNil ifTrue:[
|
|
1436 |
"/ hasGreyscales ifTrue:[
|
|
1437 |
"/ halfShadowColor := Color darkGrey
|
|
1438 |
"/ ] ifFalse:[
|
|
1439 |
"/ halfShadowColor := shadowColor
|
|
1440 |
"/ ]
|
|
1441 |
halfShadowColor := shadowColor lightened
|
59
|
1442 |
]
|
|
1443 |
].
|
|
1444 |
|
62
|
1445 |
"
|
|
1446 |
actually, the stuf below should not be needed
|
|
1447 |
- the styleSheet should provide values for nonGreyscale displays too
|
|
1448 |
"
|
130
|
1449 |
nm := styleSheet name.
|
62
|
1450 |
(nm == #iris) ifTrue:[
|
|
1451 |
hasGreyscales ifTrue:[
|
|
1452 |
DefaultEnteredBackgroundColor isNil ifTrue:[
|
|
1453 |
enteredBgColor := bgColor lightened "Color lightGrey".
|
|
1454 |
].
|
|
1455 |
DefaultActiveBackgroundColor isNil ifTrue:[
|
|
1456 |
activeBgColor := enteredBgColor.
|
|
1457 |
].
|
|
1458 |
DefaultActiveForegroundColor isNil ifTrue:[
|
|
1459 |
activeFgColor := enteredFgColor.
|
59
|
1460 |
].
|
|
1461 |
] ifFalse:[
|
62
|
1462 |
DefaultEnteredBackgroundColor isNil ifTrue:[
|
|
1463 |
enteredBgColor := Color veryLightGrey.
|
|
1464 |
].
|
|
1465 |
DefaultActiveBackgroundColor isNil ifTrue:[
|
|
1466 |
activeBgColor := Black.
|
|
1467 |
].
|
|
1468 |
DefaultActiveForegroundColor isNil ifTrue:[
|
|
1469 |
activeFgColor := White.
|
|
1470 |
].
|
|
1471 |
].
|
|
1472 |
] ifFalse:[
|
|
1473 |
nm == #motif ifTrue:[
|
|
1474 |
lightColor isNil ifTrue:[
|
|
1475 |
lightColor := bgColor lightened
|
|
1476 |
].
|
|
1477 |
"/ hasGreyscales ifTrue:[
|
|
1478 |
"/ lightColor := Color lightGrey
|
|
1479 |
"/ ]
|
|
1480 |
] ifFalse:[
|
|
1481 |
nm == #st80 ifTrue:[
|
59
|
1482 |
hasGreyscales ifTrue:[
|
62
|
1483 |
DefaultActiveForegroundColor isNil ifTrue:[
|
|
1484 |
activeFgColor := fgColor.
|
|
1485 |
].
|
|
1486 |
DefaultActiveBackgroundColor isNil ifTrue:[
|
|
1487 |
activeBgColor := bgColor darkened.
|
|
1488 |
].
|
|
1489 |
] ifFalse:[
|
|
1490 |
DefaultActiveForegroundColor isNil ifTrue:[
|
|
1491 |
activeFgColor := White.
|
|
1492 |
].
|
|
1493 |
DefaultActiveBackgroundColor isNil ifTrue:[
|
|
1494 |
activeBgColor := Black
|
59
|
1495 |
]
|
|
1496 |
]
|
|
1497 |
]
|
|
1498 |
]
|
|
1499 |
].
|
|
1500 |
|
|
1501 |
offLevel ~~ level ifTrue:[
|
|
1502 |
self level:offLevel.
|
|
1503 |
margin := (onLevel abs) max:(offLevel abs).
|
|
1504 |
].
|
|
1505 |
|
|
1506 |
DefaultReturnButtonHasImage ifTrue:[
|
130
|
1507 |
(styleSheet is3D and:[hasGreyscales]) ifTrue:[
|
59
|
1508 |
shadowForm := self class returnShadowFormOn:device.
|
|
1509 |
lightForm := self class returnLightFormOn:device.
|
|
1510 |
formColor := viewBackground.
|
|
1511 |
formShadowColor := shadowColor.
|
|
1512 |
formLightColor := lightColor
|
|
1513 |
] ifFalse:[
|
|
1514 |
shadowForm := self class returnFormOn:device.
|
|
1515 |
formColor := Black
|
|
1516 |
].
|
|
1517 |
].
|
|
1518 |
!
|
|
1519 |
|
205
|
1520 |
initialize
|
|
1521 |
super initialize.
|
0
|
1522 |
|
205
|
1523 |
isReturnButton := false.
|
0
|
1524 |
!
|
|
1525 |
|
|
1526 |
realize
|
|
1527 |
super realize.
|
118
|
1528 |
|
77
|
1529 |
controller active:false.
|
|
1530 |
controller entered:false.
|
0
|
1531 |
|
|
1532 |
fgColor := fgColor on:device.
|
|
1533 |
bgColor := bgColor on:device.
|
18
|
1534 |
formColor notNil ifTrue:[
|
59
|
1535 |
formColor := formColor on:device.
|
18
|
1536 |
].
|
0
|
1537 |
!
|
|
1538 |
|
|
1539 |
reinitialize
|
|
1540 |
super reinitialize.
|
77
|
1541 |
controller notNil ifTrue:[
|
|
1542 |
controller active:false.
|
|
1543 |
controller entered:false.
|
|
1544 |
]
|
205
|
1545 |
! !
|
|
1546 |
|
|
1547 |
!Button methodsFor:'private'!
|
|
1548 |
|
|
1549 |
XXresize
|
|
1550 |
"resize myself to make logo fit into myself.
|
|
1551 |
Redefined, since we add space for a frame around text when non-3D"
|
|
1552 |
|
|
1553 |
|extra|
|
|
1554 |
|
|
1555 |
logo isNil ifFalse:[
|
|
1556 |
self computeLabelOrigin.
|
|
1557 |
(relativeExtent isNil and:[extentRule isNil]) ifTrue:[
|
|
1558 |
extra := (onLevel abs max:offLevel abs) * 2.
|
|
1559 |
styleSheet is3D ifFalse:[
|
|
1560 |
"/ (logo isKindOf:Form) ifFalse:[
|
|
1561 |
"add space for a rectangle around"
|
|
1562 |
extra := extra + 2
|
|
1563 |
"/ ]
|
|
1564 |
].
|
|
1565 |
self extent:(labelWidth + extra) @ (labelHeight + extra)
|
|
1566 |
]
|
|
1567 |
]
|
77
|
1568 |
!
|
|
1569 |
|
205
|
1570 |
computeLabelOrigin
|
|
1571 |
"compute the origin of the text - if I am a returnButton,
|
|
1572 |
shift it somwehat to the right (we have already allocated the
|
|
1573 |
real estate, since computeLabelSize returned some extra space
|
|
1574 |
before)."
|
|
1575 |
|
|
1576 |
super computeLabelOrigin.
|
|
1577 |
(isReturnButton and:[shadowForm notNil]) ifTrue:[
|
|
1578 |
labelOriginX := labelOriginX + hSpace + hSpace.
|
|
1579 |
]
|
|
1580 |
!
|
|
1581 |
|
|
1582 |
computeLabelSize
|
|
1583 |
"compute the extent needed to hold the label plus the return form"
|
|
1584 |
|
|
1585 |
super computeLabelSize.
|
|
1586 |
(isReturnButton and:[shadowForm notNil]) ifTrue:[
|
|
1587 |
labelWidth := labelWidth + (hSpace * 2) + shadowForm width.
|
|
1588 |
labelHeight := labelHeight max: (shadowForm height + vSpace)
|
|
1589 |
]
|
0
|
1590 |
! !
|
|
1591 |
|
62
|
1592 |
!Button methodsFor:'queries'!
|
0
|
1593 |
|
|
1594 |
is3D
|
|
1595 |
"return true, if the receiver is a 3D style view"
|
|
1596 |
|
130
|
1597 |
styleSheet name == #mswindows ifTrue:[^ true].
|
0
|
1598 |
^ super is3D
|
|
1599 |
!
|
|
1600 |
|
127
|
1601 |
isOn
|
|
1602 |
"return true, if this button is currently pressed"
|
|
1603 |
|
|
1604 |
^ controller pressed
|
155
|
1605 |
!
|
|
1606 |
|
205
|
1607 |
isReturnButton
|
|
1608 |
"return true, if this is a return button"
|
0
|
1609 |
|
205
|
1610 |
^ isReturnButton
|
156
|
1611 |
!
|
|
1612 |
|
130
|
1613 |
preferredExtent
|
|
1614 |
"return my preferred extent - this is the minimum size I would like to have"
|
35
|
1615 |
|
131
|
1616 |
|extraH extraV|
|
35
|
1617 |
|
|
1618 |
logo notNil ifTrue:[
|
131
|
1619 |
"
|
|
1620 |
extraH := extraV := (onLevel abs max:offLevel abs) + ViewSpacing * 2.
|
|
1621 |
"
|
|
1622 |
extraH := extraV := (onLevel abs max:offLevel abs).
|
|
1623 |
extraH := (extraH + hSpace * 2).
|
|
1624 |
extraV := (extraV + vSpace * 2).
|
|
1625 |
|
59
|
1626 |
self is3D ifFalse:[
|
97
|
1627 |
"add space for a frame around"
|
131
|
1628 |
extraH := extraH + 2. extraV := extraV + 2.
|
59
|
1629 |
].
|
131
|
1630 |
^ (labelWidth + extraH) @ (labelHeight + extraV)
|
35
|
1631 |
].
|
|
1632 |
|
130
|
1633 |
^ super preferredExtent
|
0
|
1634 |
!
|
|
1635 |
|
205
|
1636 |
specClass
|
|
1637 |
self class == Button ifTrue:[^ ActionButtonSpec].
|
|
1638 |
^ nil
|
162
|
1639 |
! !
|
|
1640 |
|
0
|
1641 |
!Button methodsFor:'redrawing'!
|
|
1642 |
|
205
|
1643 |
drawBottomEdge
|
|
1644 |
"draw bottom 3D edge into window frame"
|
|
1645 |
|
|
1646 |
self drawBottomEdgeLevel:level
|
|
1647 |
shadow:shadowColor
|
|
1648 |
light:lightColor
|
|
1649 |
halfShadow:halfShadowColor
|
|
1650 |
halfLight:halfLightColor
|
|
1651 |
style:edgeStyle.
|
133
|
1652 |
!
|
|
1653 |
|
62
|
1654 |
drawEdges
|
|
1655 |
"draw all of my 3D edges"
|
|
1656 |
|
|
1657 |
self drawEdgesForX:0 y:0 width:width height:height level:level
|
|
1658 |
shadow:shadowColor
|
|
1659 |
light:lightColor
|
|
1660 |
halfShadow:halfShadowColor
|
|
1661 |
halfLight:halfLightColor
|
|
1662 |
style:edgeStyle
|
|
1663 |
!
|
|
1664 |
|
|
1665 |
drawLeftEdge
|
|
1666 |
"draw left 3D edge into window frame"
|
|
1667 |
|
|
1668 |
self drawLeftEdgeLevel:level
|
|
1669 |
shadow:shadowColor
|
|
1670 |
light:lightColor
|
|
1671 |
halfShadow:halfShadowColor
|
|
1672 |
halfLight:halfLightColor
|
|
1673 |
style:edgeStyle.
|
|
1674 |
!
|
|
1675 |
|
|
1676 |
drawRightEdge
|
|
1677 |
"draw right 3D edge into window frame"
|
|
1678 |
|
|
1679 |
self drawRightEdgeLevel:level
|
|
1680 |
shadow:shadowColor
|
|
1681 |
light:lightColor
|
|
1682 |
halfShadow:halfShadowColor
|
|
1683 |
halfLight:halfLightColor
|
|
1684 |
style:edgeStyle.
|
|
1685 |
!
|
|
1686 |
|
|
1687 |
drawTopEdge
|
|
1688 |
"draw top 3D edge into window frame"
|
|
1689 |
|
|
1690 |
self drawTopEdgeLevel:level
|
|
1691 |
shadow:shadowColor
|
|
1692 |
light:lightColor
|
|
1693 |
halfShadow:halfShadowColor
|
|
1694 |
halfLight:halfLightColor
|
|
1695 |
style:edgeStyle.
|
|
1696 |
!
|
|
1697 |
|
0
|
1698 |
drawWith:fg and:bg
|
|
1699 |
"redraw myself with fg/bg. Use super to draw the label, add
|
|
1700 |
the return-arrow here."
|
|
1701 |
|
18
|
1702 |
|x y sColor lColor|
|
0
|
1703 |
|
59
|
1704 |
shown ifFalse:[^ self].
|
0
|
1705 |
super drawWith:fg and:bg. "this draws the text"
|
|
1706 |
|
59
|
1707 |
(isReturnButton and:[shadowForm notNil]) ifTrue:[
|
|
1708 |
y := (height - shadowForm height) // 2.
|
|
1709 |
x := width - shadowForm width - (hSpace // 2).
|
|
1710 |
|
|
1711 |
formShadowColor isNil ifTrue:[
|
|
1712 |
self paint:fg on:bg.
|
130
|
1713 |
"/ self background:bg.
|
59
|
1714 |
self displayOpaqueForm:shadowForm x:x y:y.
|
|
1715 |
^ self
|
|
1716 |
].
|
0
|
1717 |
|
59
|
1718 |
"
|
|
1719 |
drawing form in 3d-style (i.e. with shadow and light)
|
|
1720 |
"
|
|
1721 |
(formShadowColor isColor and:[formShadowColor colorId notNil
|
|
1722 |
and:[formLightColor isColor and:[formLightColor colorId notNil
|
|
1723 |
and:[formColor isColor and:[formColor colorId notNil]]]]])
|
|
1724 |
ifTrue:[
|
|
1725 |
sColor := formShadowColor.
|
|
1726 |
lColor := formLightColor.
|
|
1727 |
] ifFalse:[
|
|
1728 |
sColor := Black.
|
|
1729 |
lColor := White.
|
|
1730 |
].
|
|
1731 |
self foreground:sColor.
|
|
1732 |
self displayForm:shadowForm x:x y:y.
|
35
|
1733 |
|
59
|
1734 |
lightForm notNil ifTrue:[
|
|
1735 |
self foreground:lColor.
|
|
1736 |
self displayForm:lightForm x:x y:y.
|
|
1737 |
].
|
|
1738 |
self paint:fg.
|
0
|
1739 |
]
|
|
1740 |
!
|
|
1741 |
|
205
|
1742 |
enableStateChangeRedraw
|
|
1743 |
"redraw the button after an enable state change"
|
59
|
1744 |
|
205
|
1745 |
disabledLogo notNil ifTrue:[
|
|
1746 |
controller enabled ifFalse:[
|
|
1747 |
logo := disabledLogo.
|
|
1748 |
] ifTrue:[
|
|
1749 |
controller active ifTrue:[
|
|
1750 |
logo := activeLogo
|
|
1751 |
] ifFalse:[
|
|
1752 |
logo := passiveLogo
|
|
1753 |
].
|
|
1754 |
].
|
59
|
1755 |
].
|
205
|
1756 |
shown ifFalse:[^ self].
|
|
1757 |
self redisplay.
|
82
|
1758 |
|
205
|
1759 |
"Created: 17.9.1995 / 19:46:14 / claus"
|
|
1760 |
"Modified: 17.9.1995 / 19:56:24 / claus"
|
133
|
1761 |
!
|
|
1762 |
|
|
1763 |
redisplay
|
82
|
1764 |
"redraw the button.
|
|
1765 |
Thats like redrawing a label, but use different colors when pressed
|
|
1766 |
or entered."
|
0
|
1767 |
|
229
|
1768 |
|fg bg entered noFrame|
|
0
|
1769 |
|
62
|
1770 |
shown ifFalse:[^ self].
|
35
|
1771 |
|
62
|
1772 |
fg := fgColor.
|
|
1773 |
bg := bgColor.
|
77
|
1774 |
controller enabled ifFalse:[
|
62
|
1775 |
fg := disabledFgColor
|
|
1776 |
] ifTrue:[
|
77
|
1777 |
entered := controller entered.
|
62
|
1778 |
entered ifTrue:[
|
|
1779 |
enteredFgColor notNil ifTrue:[fg := enteredFgColor].
|
|
1780 |
enteredBgColor notNil ifTrue:[bg := enteredBgColor]
|
|
1781 |
].
|
77
|
1782 |
(controller pressed and:[entered or:[controller isTriggerOnDown]]) ifTrue:[
|
229
|
1783 |
noFrame := false.
|
62
|
1784 |
activeFgColor isNil ifTrue:[
|
|
1785 |
onLevel == offLevel ifTrue:[
|
|
1786 |
fg := bgColor
|
|
1787 |
]
|
|
1788 |
] ifFalse:[
|
|
1789 |
fg := activeFgColor.
|
59
|
1790 |
].
|
62
|
1791 |
activeBgColor isNil ifTrue:[
|
|
1792 |
onLevel == offLevel ifTrue:[
|
|
1793 |
bg := fgColor
|
|
1794 |
]
|
|
1795 |
] ifFalse:[
|
|
1796 |
bg := activeBgColor
|
|
1797 |
].
|
232
|
1798 |
|
62
|
1799 |
self is3D ifFalse:[
|
232
|
1800 |
noFrame := (fgColor = fg) and:[bgColor = bg].
|
229
|
1801 |
noFrame ifFalse:[
|
232
|
1802 |
"
|
|
1803 |
draw a rectangle around
|
|
1804 |
"
|
|
1805 |
self drawWith:fg and:bg .
|
229
|
1806 |
self paint:fg.
|
|
1807 |
self displayRectangleX:0 y:0 width:width height:height.
|
232
|
1808 |
^ self
|
229
|
1809 |
].
|
62
|
1810 |
].
|
|
1811 |
].
|
|
1812 |
].
|
|
1813 |
self drawWith:fg and:bg
|
162
|
1814 |
!
|
|
1815 |
|
205
|
1816 |
redraw
|
|
1817 |
"redraw the button. but not if currently active"
|
|
1818 |
|
|
1819 |
shown ifFalse:[^ self].
|
|
1820 |
"/ controller active ifTrue:[^ self]. - disabled; otherwise, we do not redreaw if changed from within action procedure
|
|
1821 |
self redisplay.
|
|
1822 |
!
|
|
1823 |
|
|
1824 |
redrawIfPressed
|
|
1825 |
"redraw the button, but only if visible and currently being pressed"
|
|
1826 |
|
|
1827 |
shown ifTrue:[
|
|
1828 |
controller pressed ifTrue:[
|
|
1829 |
self redisplay
|
|
1830 |
]
|
|
1831 |
]
|
|
1832 |
!
|
|
1833 |
|
|
1834 |
redrawX:x y:y width:w height:h
|
|
1835 |
self redisplay.
|
|
1836 |
!
|
|
1837 |
|
|
1838 |
showActive
|
|
1839 |
"redraw myself as active (i.e. busy)"
|
162
|
1840 |
|
205
|
1841 |
onLevel ~~ level ifTrue:[
|
|
1842 |
self level:onLevel.
|
|
1843 |
].
|
|
1844 |
(activeLogo notNil and:[activeLogo ~~ logo]) ifTrue:[
|
|
1845 |
self logo:activeLogo
|
162
|
1846 |
].
|
205
|
1847 |
self redraw.
|
|
1848 |
!
|
|
1849 |
|
|
1850 |
showPassive
|
|
1851 |
"redraw myself as passive"
|
162
|
1852 |
|
205
|
1853 |
offLevel ~~ level ifTrue:[
|
|
1854 |
self level:offLevel.
|
|
1855 |
].
|
|
1856 |
(passiveLogo notNil and:[passiveLogo ~~ logo]) ifTrue:[
|
|
1857 |
self logo:passiveLogo
|
|
1858 |
].
|
|
1859 |
self redraw.
|
0
|
1860 |
! !
|
205
|
1861 |
|
|
1862 |
!Button class methodsFor:'documentation'!
|
|
1863 |
|
|
1864 |
version
|
232
|
1865 |
^ '$Header: /cvs/stx/stx/libwidg/Button.st,v 1.41 1995-12-04 00:32:25 cg Exp $'
|
205
|
1866 |
! !
|