author | Claus Gittinger <cg@exept.de> |
Sat, 24 Feb 1996 17:35:36 +0100 | |
changeset 392 | 81343306d796 |
parent 366 | 27bf7d05650b |
child 420 | e57314f0ceb7 |
permissions | -rw-r--r-- |
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 |
|
264 | 14 |
instanceVariableNames:'activeLogo passiveLogo disabledLogo focusLogo onLevel offLevel |
15 |
disabledFgColor activeFgColor activeBgColor enteredFgColor |
|
16 |
enteredBgColor isReturnButton shadowForm lightForm formColor |
|
17 |
formShadowColor formLightColor edgeStyle halfShadowColor |
|
18 |
halfLightColor' |
|
392
81343306d796
eliminated all DefaultFont classVars (are now classINSTvars)
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
19 |
classVariableNames:'ReturnForm ReturnLightForm ReturnShadowForm |
264 | 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' |
|
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 |
|
258
ae4b8f1a6738
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
244
diff
changeset
|
63 |
entity which is interested in that button press. |
205 | 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 |
|
366
27bf7d05650b
renamed abort-button to cancel
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
670 |
aButton := Button label:(self classResources at:'cancel'). |
205 | 671 |
aButton cursor:(Cursor thumbsDown). |
672 |
^ aButton |
|
366
27bf7d05650b
renamed abort-button to cancel
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
673 |
|
27bf7d05650b
renamed abort-button to cancel
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
674 |
"Modified: 20.2.1996 / 20:20:16 / cg" |
205 | 675 |
! |
676 |
||
677 |
abortButtonIn:aView |
|
678 |
"since abort-buttons are very common, here is a convenient |
|
679 |
method to create one ..." |
|
680 |
||
681 |
|b| |
|
60 | 682 |
|
205 | 683 |
aView addSubView:(b := self abortButton). |
684 |
^ b |
|
685 |
! |
|
686 |
||
687 |
form:aForm action:aBlock in:aView |
|
688 |
"create and return a new Button with icon-label, aForm |
|
689 |
and pressAction, aBlock. Button is placed into aView. |
|
690 |
OBSOLETE: this is for backward compatibility; |
|
691 |
you can now pass an image or form in the #label:action:in: message." |
|
692 |
||
693 |
^ ((self in:aView) form:aForm) action:aBlock |
|
694 |
! |
|
695 |
||
696 |
label:aLabel action:aBlock |
|
697 |
"create and return a new Button with text-label, aString |
|
698 |
and pressAction, aBlock." |
|
699 |
||
700 |
^ (self label:aLabel) action:aBlock |
|
701 |
! |
|
702 |
||
703 |
label:aLabel action:aBlock in:aView |
|
704 |
"create and return a new Button with text-label, aString |
|
705 |
and pressAction, aBlock. Button is placed into aView." |
|
60 | 706 |
|
205 | 707 |
^ ((self in:aView) label:aLabel) action:aBlock |
708 |
! |
|
709 |
||
710 |
okButton |
|
711 |
"since ok-buttons are very common, here is a convenient |
|
712 |
method to create one ..." |
|
713 |
||
714 |
|aButton| |
|
715 |
||
716 |
aButton := Button label:(self classResources at:'ok'). |
|
717 |
aButton cursor:(Cursor thumbsUp). |
|
219 | 718 |
aButton beReturnButton. |
205 | 719 |
^ aButton |
59 | 720 |
! |
721 |
||
205 | 722 |
okButtonIn:aView |
723 |
"since ok-buttons are very common, here is a convenient |
|
724 |
method to create one ..." |
|
725 |
||
726 |
|b| |
|
727 |
||
728 |
aView addSubView:(b := self okButton). |
|
729 |
^ b |
|
730 |
! |
|
731 |
||
732 |
toggle |
|
733 |
"ST-80 compatibility: create & return a new toggle." |
|
734 |
||
735 |
^ Toggle new |
|
736 |
||
737 |
" |
|
738 |
Button toggle label:'press me'; |
|
739 |
model:((PluggableAdaptor on:(Point new)) |
|
740 |
getSelector:#x putSelector:#x:) |
|
741 |
" |
|
742 |
"this is the same as" |
|
743 |
" |
|
744 |
Toggle new label:'press me'; |
|
745 |
model:((PluggableAdaptor on:(Point new)) |
|
746 |
getSelector:#x putSelector:#x:) |
|
747 |
" |
|
748 |
! ! |
|
749 |
||
750 |
!Button class methodsFor:'defaults'! |
|
751 |
||
0 | 752 |
returnFormOn:aDevice |
753 |
"return the form used for the return arrow in non-3D; |
|
754 |
cache the one for Display for the next round." |
|
755 |
||
756 |
|f| |
|
757 |
||
35 | 758 |
(ReturnForm notNil and:[aDevice == ReturnForm device]) ifTrue:[ |
59 | 759 |
^ ReturnForm |
0 | 760 |
]. |
761 |
f := Form fromFile:'Return.xbm' resolution:100 on:aDevice. |
|
762 |
f isNil ifTrue:[ |
|
59 | 763 |
f := Form width:24 height:16 fromArray:#[2r00000000 2r00000000 2r00000000 |
764 |
2r00000000 2r00000000 2r00000000 |
|
765 |
2r00000000 2r00000000 2r00000000 |
|
766 |
2r00000000 2r00000011 2r11100000 |
|
767 |
2r00000001 2r10000011 2r11100000 |
|
768 |
2r00000011 2r10000011 2r11100000 |
|
769 |
2r00000111 2r11111111 2r11100000 |
|
770 |
2r00001111 2r11111111 2r11100000 |
|
771 |
2r00011111 2r11111111 2r11100000 |
|
772 |
2r00001111 2r11111111 2r11100000 |
|
773 |
2r00000111 2r11111111 2r11100000 |
|
774 |
2r00000011 2r10000000 2r00000000 |
|
775 |
2r00000001 2r10000000 2r00000000 |
|
776 |
2r00000000 2r00000000 2r00000000 |
|
777 |
2r00000000 2r00000000 2r00000000 |
|
778 |
2r00000000 2r00000000 2r00000000] |
|
779 |
on:aDevice |
|
0 | 780 |
]. |
35 | 781 |
ReturnForm := f. |
0 | 782 |
^ f |
783 |
! |
|
784 |
||
205 | 785 |
returnLightFormOn:aDevice |
786 |
"return the form used for the return arrow light pixels (3D only); |
|
787 |
cache the one for Display for the next round" |
|
788 |
||
789 |
|f| |
|
790 |
||
791 |
(ReturnLightForm notNil and:[aDevice == ReturnLightForm device]) ifTrue:[ |
|
792 |
^ ReturnLightForm |
|
793 |
]. |
|
794 |
f := Form fromFile:'ReturnLight.xbm' resolution:100 on:aDevice. |
|
795 |
f isNil ifTrue:[ |
|
796 |
f := Form width:24 height:16 fromArray:#[2r00000000 2r00000000 2r00000000 |
|
797 |
2r00000000 2r00000000 2r00000000 |
|
798 |
2r00000000 2r00000000 2r00000000 |
|
799 |
2r00000000 2r00000000 2r00000000 |
|
800 |
2r00000000 2r00000000 2r00100000 |
|
801 |
2r00000000 2r00000000 2r00100000 |
|
802 |
2r00000000 2r00000000 2r00100000 |
|
803 |
2r00000000 2r00000000 2r00100000 |
|
804 |
2r00000000 2r00000000 2r00100000 |
|
805 |
2r00000000 2r00000000 2r00100000 |
|
806 |
2r00000000 2r11111111 2r11100000 |
|
807 |
2r00000000 2r10000000 2r00000000 |
|
808 |
2r00000000 2r10000000 2r00000000 |
|
809 |
2r00000000 2r00000000 2r00000000 |
|
810 |
2r00000000 2r00000000 2r00000000 |
|
811 |
2r00000000 2r00000000 2r00000000] |
|
812 |
on:aDevice |
|
813 |
]. |
|
814 |
ReturnLightForm := f. |
|
815 |
^ f |
|
816 |
! |
|
817 |
||
0 | 818 |
returnShadowFormOn:aDevice |
819 |
"return the form used for the return arrow shadow pixels (3D only); |
|
820 |
cache the one for Display for the next round." |
|
821 |
||
822 |
|f| |
|
823 |
||
35 | 824 |
(ReturnShadowForm notNil and:[aDevice == ReturnShadowForm device]) ifTrue:[ |
59 | 825 |
^ ReturnShadowForm |
0 | 826 |
]. |
827 |
f := Form fromFile:'ReturnShadow.xbm' resolution:100 on:aDevice. |
|
828 |
f isNil ifTrue:[ |
|
59 | 829 |
f := Form width:24 height:16 fromArray:#[2r00000000 2r00000000 2r00000000 |
830 |
2r00000000 2r00000000 2r00000000 |
|
831 |
2r00000000 2r00000000 2r00000000 |
|
832 |
2r00000000 2r00000011 2r11100000 |
|
833 |
2r00000001 2r10000010 2r00000000 |
|
834 |
2r00000010 2r10000010 2r00000000 |
|
835 |
2r00000100 2r11111110 2r00000000 |
|
836 |
2r00001000 2r00000000 2r00000000 |
|
837 |
2r00010000 2r00000000 2r00000000 |
|
838 |
2r00001000 2r00000000 2r00000000 |
|
839 |
2r00000100 2r00000000 2r00000000 |
|
840 |
2r00000010 2r00000000 2r00000000 |
|
841 |
2r00000001 2r00000000 2r00000000 |
|
842 |
2r00000000 2r00000000 2r00000000 |
|
843 |
2r00000000 2r00000000 2r00000000 |
|
844 |
2r00000000 2r00000000 2r00000000] |
|
845 |
on:aDevice |
|
0 | 846 |
]. |
35 | 847 |
ReturnShadowForm := f. |
0 | 848 |
^ f |
849 |
! |
|
850 |
||
205 | 851 |
updateStyleCache |
852 |
|defaultLevel| |
|
0 | 853 |
|
205 | 854 |
StyleSheet is3D ifTrue:[ |
855 |
defaultLevel := 1. |
|
856 |
] ifFalse:[ |
|
857 |
defaultLevel := 0 |
|
0 | 858 |
]. |
205 | 859 |
DefaultActiveLevel := StyleSheet at:'buttonActiveLevel' default:(defaultLevel negated). |
860 |
DefaultPassiveLevel := StyleSheet at:'buttonPassiveLevel' default:defaultLevel. |
|
861 |
||
862 |
DefaultEdgeStyle := StyleSheet at:'buttonEdgeStyle'. |
|
863 |
DefaultFont := StyleSheet fontAt:'buttonFont'. |
|
864 |
DefaultBorderWidth := StyleSheet at:'buttonBorderWidth'. |
|
865 |
DefaultForegroundColor := StyleSheet colorAt:'buttonForegroundColor'. |
|
866 |
DefaultBackgroundColor := StyleSheet colorAt:'buttonBackgroundColor'. |
|
867 |
DefaultDisabledForegroundColor := StyleSheet colorAt:'buttonDisabledForegroundColor' default:Color grey. |
|
868 |
DefaultDisabledBackgroundColor := StyleSheet colorAt:'buttonDisabledBackgroundColor'. |
|
869 |
DefaultEnteredForegroundColor := StyleSheet colorAt:'buttonEnteredForegroundColor'. |
|
870 |
DefaultEnteredBackgroundColor := StyleSheet colorAt:'buttonEnteredBackgroundColor'. |
|
871 |
DefaultActiveForegroundColor := StyleSheet colorAt:'buttonActiveForegroundColor'. |
|
872 |
DefaultActiveBackgroundColor := StyleSheet colorAt:'buttonActiveBackgroundColor'. |
|
873 |
DefaultReturnButtonHasImage := StyleSheet at:'buttonReturnButtonHasImage' default:true. |
|
874 |
DefaultReturnButtonHasBorder := StyleSheet at:'buttonReturnButtonHasBorder' default:false. |
|
875 |
DefaultShadowColor := StyleSheet colorAt:'buttonShadowColor'. |
|
876 |
DefaultLightColor := StyleSheet colorAt:'buttonLightColor'. |
|
877 |
DefaultHalfShadowColor := StyleSheet colorAt:'buttonHalfShadowColor'. |
|
878 |
DefaultHalfLightColor := StyleSheet colorAt:'buttonHalfLightColor'. |
|
0 | 879 |
! ! |
880 |
||
205 | 881 |
!Button methodsFor:'accessing-behavior'! |
882 |
||
883 |
action:aBlock |
|
884 |
"convenient method: depending on the setting of controllers triggerOnDown flag, |
|
885 |
either set the press-action and clear any release-action or |
|
886 |
vice versa, set the release-action and clear the press-action." |
|
887 |
||
315
dbfd0ae75b57
check for nil-controller (dont die if fBrowser is closed while command is being executed)
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
888 |
controller notNil ifTrue:[controller action:aBlock] |
205 | 889 |
! |
890 |
||
891 |
autoRepeat |
|
346 | 892 |
"turn on autorepeat OBSOLETE; use #autoRepeat:" |
205 | 893 |
|
894 |
controller autoRepeat |
|
346 | 895 |
|
896 |
"Modified: 9.2.1996 / 22:42:37 / cg" |
|
205 | 897 |
! |
898 |
||
899 |
autoRepeat:aBoolean |
|
900 |
"turn on/off autorepeat" |
|
901 |
||
902 |
controller autoRepeat:aBoolean |
|
903 |
||
904 |
"Modified: 5.9.1995 / 22:06:13 / claus" |
|
905 |
! |
|
906 |
||
907 |
disable |
|
908 |
"disable the button" |
|
909 |
||
910 |
controller disable. |
|
911 |
! |
|
912 |
||
913 |
enable |
|
914 |
"enable the button" |
|
915 |
||
916 |
controller enable |
|
917 |
! |
|
918 |
||
919 |
enableChannel |
|
920 |
"return the valueHolder used for enable/disable" |
|
921 |
||
922 |
^ controller enableChannel |
|
923 |
! |
|
924 |
||
925 |
enableChannel:aValueHolderForBoolean |
|
926 |
"set the valueHolder used for enable/disable" |
|
927 |
||
928 |
controller enableChannel:aValueHolderForBoolean |
|
929 |
! |
|
930 |
||
264 | 931 |
enabled |
932 |
"return true if the button is enabled" |
|
933 |
||
934 |
^ controller enabled |
|
935 |
||
936 |
"Created: 17.12.1995 / 16:12:26 / cg" |
|
937 |
! |
|
938 |
||
205 | 939 |
pressAction |
940 |
"return the pressAction; thats the block which gets evaluated |
|
941 |
when the button is pressed (if non-nil)" |
|
942 |
||
943 |
^ controller pressAction |
|
944 |
! |
|
0 | 945 |
|
205 | 946 |
pressAction:aBlock |
947 |
"define the action to be performed on press" |
|
948 |
||
949 |
controller pressAction:aBlock |
|
950 |
! |
|
951 |
||
952 |
pressChannel |
|
953 |
"return the pressChannel" |
|
954 |
||
955 |
^ controller pressChannel |
|
956 |
||
957 |
"Modified: 7.9.1995 / 18:16:20 / claus" |
|
958 |
! |
|
959 |
||
960 |
pressChannel:aBlock |
|
961 |
"set the pressChannel" |
|
962 |
||
963 |
controller pressChannel:aBlock |
|
964 |
||
965 |
"Modified: 7.9.1995 / 18:05:14 / claus" |
|
966 |
! |
|
967 |
||
968 |
releaseAction |
|
969 |
"return the releaseAction; thats the block which gets evaluated |
|
970 |
when the button is relreased (if non-nil)" |
|
971 |
||
972 |
^ controller releaseAction |
|
973 |
! |
|
164 | 974 |
|
205 | 975 |
releaseAction:aBlock |
976 |
"define the action to be performed on release" |
|
977 |
||
978 |
controller releaseAction:aBlock |
|
979 |
! |
|
980 |
||
981 |
releaseChannel |
|
982 |
"return the releaseChannel" |
|
983 |
||
984 |
^ controller releaseChannel |
|
985 |
||
986 |
"Modified: 7.9.1995 / 18:15:24 / claus" |
|
987 |
! |
|
988 |
||
989 |
releaseChannel:aBlock |
|
990 |
"set the releaseChannel" |
|
991 |
||
992 |
controller releaseChannel:aBlock |
|
993 |
||
994 |
"Modified: 7.9.1995 / 18:05:21 / claus" |
|
995 |
! ! |
|
996 |
||
997 |
!Button methodsFor:'accessing-look'! |
|
998 |
||
999 |
activeBackgroundColor |
|
1000 |
"return the background color to be used when pressed" |
|
1001 |
||
1002 |
^ activeBgColor |
|
164 | 1003 |
! |
1004 |
||
205 | 1005 |
activeBackgroundColor:aColor |
1006 |
"set the background color to be used when pressed" |
|
1007 |
||
1008 |
activeBgColor := aColor. |
|
1009 |
self redrawIfPressed |
|
1010 |
! |
|
1011 |
||
1012 |
activeForegroundColor |
|
1013 |
"return the foreground color to be used when pressed" |
|
1014 |
||
1015 |
^ activeFgColor |
|
1016 |
! |
|
1017 |
||
1018 |
activeForegroundColor:aColor |
|
1019 |
"set the foreground color to be used when pressed" |
|
1020 |
||
1021 |
activeFgColor := aColor. |
|
1022 |
self redrawIfPressed |
|
1023 |
! |
|
1024 |
||
1025 |
activeForegroundColor:fgColor backgroundColor:bgColor |
|
1026 |
"set both fg and bg colors to be used when pressed" |
|
1027 |
||
1028 |
activeFgColor := fgColor. |
|
1029 |
activeBgColor := bgColor. |
|
1030 |
self redrawIfPressed |
|
1031 |
! |
|
0 | 1032 |
|
205 | 1033 |
activeLevel |
1034 |
"return the level of the button when pressed" |
|
1035 |
||
1036 |
^ onLevel |
|
1037 |
! |
|
1038 |
||
1039 |
activeLevel:aNumber |
|
1040 |
"set the level of the button when pressed (i.e. how deep)" |
|
1041 |
||
1042 |
onLevel := aNumber. |
|
1043 |
(controller notNil |
|
1044 |
and:[controller pressed]) ifTrue:[ |
|
1045 |
self level:onLevel. |
|
1046 |
margin := onLevel abs max:offLevel abs. |
|
1047 |
self redraw |
|
1048 |
] |
|
1049 |
! |
|
1050 |
||
1051 |
activeLogo:anImageOrString |
|
1052 |
"define the logo to be displayed while active - |
|
1053 |
this is optional; the default is to display the same |
|
1054 |
(logo) in both pressed and released states." |
|
1055 |
||
1056 |
activeLogo := anImageOrString. |
|
1057 |
controller pressed ifTrue:[ |
|
1058 |
self logo:anImageOrString |
|
1059 |
] |
|
0 | 1060 |
! |
1061 |
||
205 | 1062 |
beImageButton |
1063 |
"make mySelf an image button - that is turn off all levelChanges |
|
1064 |
and logo spacing. This should be sent for buttons which use both |
|
1065 |
passive and active logos, and the 3D effect comes from the bitmaps |
|
1066 |
(i.e. windows buttons)." |
|
1067 |
||
1068 |
self |
|
1069 |
extent:(labelWidth @ labelHeight); |
|
1070 |
sizeFixed:true; |
|
1071 |
borderWidth:0; |
|
1072 |
onLevel:0; |
|
1073 |
offLevel:0; |
|
1074 |
horizontalSpace:0; |
|
1075 |
verticalSpace:0; |
|
1076 |
newLayout. |
|
1077 |
||
1078 |
"Created: 17.9.1995 / 20:41:47 / claus" |
|
1079 |
"Modified: 19.9.1995 / 16:34:08 / claus" |
|
1080 |
! |
|
1081 |
||
244 | 1082 |
beReturnButton |
1083 |
"show show a return-key image after the label" |
|
1084 |
||
1085 |
self isReturnButton:true |
|
1086 |
! |
|
1087 |
||
205 | 1088 |
beRoundRadioButton |
1089 |
"setup myself for a round radioButton look. |
|
1090 |
this is a private method; do not use it. It is going to move into the |
|
1091 |
RadioButton class." |
|
0 | 1092 |
|
205 | 1093 |
self activeLogo:(Icon constantNamed:'RadioOn'). |
1094 |
self passiveLogo:(Icon constantNamed:'RadioOff'). |
|
1095 |
self activeLevel:0; |
|
1096 |
passiveLevel:0; |
|
1097 |
activeBackgroundColor:bgColor; |
|
1098 |
activeForegroundColor:fgColor; |
|
1099 |
borderWidth:0; |
|
1100 |
enteredBackgroundColor:bgColor. |
|
1101 |
self computeLabelSize. |
|
1102 |
self beImageButton. |
|
1103 |
||
1104 |
"Created: 22.9.1995 / 15:48:05 / claus" |
|
1105 |
"Modified: 22.9.1995 / 17:07:46 / claus" |
|
1106 |
! |
|
1107 |
||
1108 |
disabledForegroundColor |
|
1109 |
"return the foreground color used when the button is disabled" |
|
1110 |
||
1111 |
^ disabledFgColor |
|
1112 |
! |
|
1113 |
||
1114 |
disabledLogo:anImageOrString |
|
1115 |
"define the logo to be displayed while active - |
|
1116 |
this is optional; the default is to display the same |
|
1117 |
(logo) in both pressed and released states." |
|
1118 |
||
1119 |
disabledLogo := anImageOrString. |
|
1120 |
controller enabled ifFalse:[ |
|
1121 |
self logo:anImageOrString |
|
1122 |
] |
|
1123 |
||
1124 |
"Created: 17.9.1995 / 19:50:17 / claus" |
|
1125 |
"Modified: 17.9.1995 / 19:50:34 / claus" |
|
59 | 1126 |
! |
1127 |
||
205 | 1128 |
edgeStyle:aSymbol |
1129 |
"set the edgestyle - currently only #soft or nil" |
|
1130 |
||
1131 |
edgeStyle := aSymbol |
|
1132 |
! |
|
1133 |
||
1134 |
enteredBackgroundColor |
|
1135 |
"return the background color to be used when the mouse |
|
1136 |
pointer enters the button area" |
|
1137 |
||
1138 |
^ enteredBgColor |
|
1139 |
! |
|
1140 |
||
1141 |
enteredBackgroundColor:aColor |
|
1142 |
"set the background color to be used when the mouse |
|
1143 |
pointer enters the button area" |
|
1144 |
||
1145 |
enteredBgColor := aColor |
|
1146 |
! |
|
1147 |
||
1148 |
enteredForegroundColor |
|
1149 |
"return the foreground color to be used when the mouse |
|
1150 |
pointer enters the button area" |
|
1151 |
||
1152 |
^ enteredFgColor |
|
1153 |
! |
|
1154 |
||
1155 |
enteredForegroundColor:aColor |
|
1156 |
"set the foreground color to be used when the mouse |
|
1157 |
pointer enters the button area" |
|
59 | 1158 |
|
205 | 1159 |
enteredFgColor := aColor |
1160 |
! |
|
1161 |
||
1162 |
focusLogo:anImageOrString |
|
1163 |
"define the logo to be displayed while active - |
|
1164 |
this is optional; the default is to display the same |
|
1165 |
(logo) in both pressed and released states." |
|
1166 |
||
1167 |
focusLogo := anImageOrString. |
|
1168 |
||
1169 |
"Created: 17.9.1995 / 19:50:17 / claus" |
|
1170 |
"Modified: 17.9.1995 / 20:00:43 / claus" |
|
1171 |
! |
|
59 | 1172 |
|
205 | 1173 |
isReturnButton:aBoolean |
1174 |
"show/dont show a return-key image after the label" |
|
1175 |
||
1176 |
isReturnButton ~~ aBoolean ifTrue:[ |
|
1177 |
DefaultReturnButtonHasBorder ifTrue:[ |
|
1178 |
self borderWidth:(aBoolean ifTrue:[1] ifFalse:[0]) |
|
1179 |
]. |
|
1180 |
isReturnButton := aBoolean. |
|
1181 |
self newLayout |
|
1182 |
] |
|
1183 |
! |
|
1184 |
||
1185 |
offLevel |
|
1186 |
"return the level of the button when released. |
|
1187 |
Historic leftover; use #passiveLevel." |
|
1188 |
||
1189 |
^ offLevel |
|
59 | 1190 |
! |
1191 |
||
205 | 1192 |
offLevel:aNumber |
1193 |
"set the level of the button when released (i.e. how deep). |
|
1194 |
Historic leftover; use #passiveLevel:." |
|
1195 |
||
1196 |
^ self passiveLevel:aNumber |
|
1197 |
! |
|
1198 |
||
1199 |
onLevel |
|
1200 |
"return the level of the button when pressed. |
|
1201 |
Historic leftover; use #activeLevel." |
|
1202 |
||
1203 |
^ onLevel |
|
1204 |
! |
|
1205 |
||
1206 |
onLevel:aNumber |
|
1207 |
"set the level of the button when pressed (i.e. how deep). |
|
1208 |
Historic leftover; use #activeLevel:." |
|
1209 |
||
1210 |
^ self activeLevel:aNumber |
|
1211 |
! |
|
1212 |
||
1213 |
passiveLevel |
|
1214 |
"return the level of the button when released" |
|
1215 |
||
1216 |
^ offLevel |
|
1217 |
! |
|
1218 |
||
1219 |
passiveLevel:aNumber |
|
1220 |
"set the level of the button when not pressed (i.e. how high)" |
|
118 | 1221 |
|
205 | 1222 |
offLevel := aNumber. |
1223 |
(controller notNil |
|
1224 |
and:[controller pressed not]) ifTrue:[ |
|
1225 |
self level:offLevel. |
|
1226 |
margin := onLevel abs max:offLevel abs. |
|
1227 |
self redraw |
|
1228 |
] |
|
1229 |
! |
|
1230 |
||
1231 |
passiveLogo:anImageOrString |
|
1232 |
"define the logo to be displayed while inactive - |
|
1233 |
this is optional; the default is to display the same |
|
1234 |
(logo) in both pressed and released states." |
|
118 | 1235 |
|
205 | 1236 |
passiveLogo := anImageOrString. |
1237 |
controller pressed ifFalse:[ |
|
1238 |
self logo:anImageOrString |
|
1239 |
] |
|
1240 |
! ! |
|
1241 |
||
1242 |
!Button methodsFor:'changing state'! |
|
1243 |
||
1244 |
toggle |
|
1245 |
"toggle and perform the action" |
|
1246 |
||
1247 |
controller toggle |
|
1248 |
! |
|
1249 |
||
1250 |
toggleNoAction |
|
1251 |
"toggle, but do NOT perform any action - can be used to change a toggle |
|
1252 |
under program control (i.e. turn one toggle off from another one)" |
|
1253 |
||
1254 |
controller toggleNoAction |
|
118 | 1255 |
! |
1256 |
||
205 | 1257 |
turnOff |
1258 |
"turn the button off (if not already off) do NOT perform actions/change notifications" |
|
1259 |
||
328
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1260 |
(controller notNil and:[controller pressed]) ifTrue:[ |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1261 |
offLevel ~~ level ifTrue:[ |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1262 |
self level:offLevel. |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1263 |
]. |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1264 |
(passiveLogo notNil and:[passiveLogo ~~ logo]) ifTrue:[ |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1265 |
self logo:passiveLogo |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1266 |
]. |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1267 |
controller setPressed:false. |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1268 |
controller active:false. |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1269 |
level := offLevel. |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1270 |
margin := level abs. |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1271 |
self redraw |
205 | 1272 |
] |
328
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1273 |
|
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1274 |
"Modified: 8.2.1996 / 15:28:06 / cg" |
205 | 1275 |
! |
1276 |
||
1277 |
turnOffWithAction |
|
1278 |
"turn the button off (if not already off) and perform any action/change notification" |
|
118 | 1279 |
|
328
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1280 |
(controller notNil and:[controller pressed]) ifTrue:[ |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1281 |
offLevel ~~ level ifTrue:[ |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1282 |
self level:offLevel. |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1283 |
]. |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1284 |
(passiveLogo notNil and:[passiveLogo ~~ logo]) ifTrue:[ |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1285 |
self logo:passiveLogo |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1286 |
]. |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1287 |
self turnOffWithoutRedraw. |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1288 |
self redraw |
205 | 1289 |
] |
118 | 1290 |
|
205 | 1291 |
"Created: 15.11.1995 / 16:55:37 / cg" |
328
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1292 |
"Modified: 8.2.1996 / 15:28:36 / cg" |
205 | 1293 |
! |
1294 |
||
1295 |
turnOffWithoutRedraw |
|
1296 |
"turn the button off - no redraw but perform any action/change notification" |
|
1297 |
||
328
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1298 |
controller notNil ifTrue:[ |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1299 |
controller pressed:false. |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1300 |
controller active:false. |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1301 |
]. |
205 | 1302 |
|
1303 |
"do not use super level:offLevel |
|
1304 |
- because that one does redraw the edges. |
|
1305 |
Sure, this is no good coding style" |
|
1306 |
||
1307 |
level := offLevel. |
|
1308 |
margin := level abs |
|
328
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1309 |
|
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1310 |
"Modified: 8.2.1996 / 15:28:53 / cg" |
118 | 1311 |
! |
1312 |
||
205 | 1313 |
turnOn |
1314 |
"turn the button on (if not already on) - do NOT perform any action/notification" |
|
1315 |
||
328
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1316 |
(controller notNil and:[controller pressed not]) ifTrue:[ |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1317 |
onLevel ~~ level ifTrue:[ |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1318 |
self level:onLevel. |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1319 |
]. |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1320 |
(activeLogo notNil and:[activeLogo ~~ logo]) ifTrue:[ |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1321 |
self logo:activeLogo |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1322 |
]. |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1323 |
controller setPressed:true. |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1324 |
level := onLevel. |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1325 |
margin := level abs. |
205 | 1326 |
|
328
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1327 |
self redraw |
205 | 1328 |
] |
59 | 1329 |
|
205 | 1330 |
"Created: 14.11.1995 / 22:00:45 / cg" |
328
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1331 |
"Modified: 8.2.1996 / 15:28:24 / cg" |
205 | 1332 |
! |
1333 |
||
1334 |
turnOnWithAction |
|
1335 |
"turn the button on (if not already on) and perform any change actions/notifications" |
|
118 | 1336 |
|
328
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1337 |
(controller notNil and:[controller pressed not]) ifTrue:[ |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1338 |
onLevel ~~ level ifTrue:[ |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1339 |
self level:onLevel. |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1340 |
]. |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1341 |
(activeLogo notNil and:[activeLogo ~~ logo]) ifTrue:[ |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1342 |
self logo:activeLogo |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1343 |
]. |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1344 |
self turnOnWithoutRedraw. |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1345 |
self redraw |
205 | 1346 |
] |
1347 |
||
1348 |
"Created: 15.11.1995 / 16:55:56 / cg" |
|
328
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1349 |
"Modified: 8.2.1996 / 15:29:07 / cg" |
118 | 1350 |
! |
1351 |
||
205 | 1352 |
turnOnWithoutRedraw |
1353 |
"turn the button on - no redraw but perform any change actions/notifications" |
|
1354 |
||
328
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1355 |
controller notNil ifTrue:[ |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1356 |
controller pressed:true. |
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1357 |
]. |
118 | 1358 |
|
205 | 1359 |
"do not use super level:offLevel |
1360 |
- because that one does redraw the edges. |
|
1361 |
Sure, this is no good coding style" |
|
1362 |
||
1363 |
level := onLevel. |
|
1364 |
margin := level abs |
|
328
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1365 |
|
6c4daccc6fb5
check for nil controller (turnOn/Off might be called after destroy)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
1366 |
"Modified: 8.2.1996 / 15:29:23 / cg" |
205 | 1367 |
! ! |
1368 |
||
1369 |
!Button methodsFor:'focus change'! |
|
59 | 1370 |
|
309
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
265
diff
changeset
|
1371 |
showFocus:explicit |
205 | 1372 |
focusLogo notNil ifTrue:[ |
1373 |
controller enabled ifTrue:[ |
|
1374 |
logo := focusLogo. |
|
1375 |
^ self redisplay |
|
1376 |
] |
|
1377 |
]. |
|
309
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
265
diff
changeset
|
1378 |
super showFocus:explicit |
205 | 1379 |
|
1380 |
"Created: 17.9.1995 / 19:58:50 / claus" |
|
1381 |
! |
|
1382 |
||
309
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
265
diff
changeset
|
1383 |
showNoFocus:explicit |
205 | 1384 |
focusLogo notNil ifTrue:[ |
1385 |
disabledLogo notNil ifTrue:[ |
|
1386 |
controller enabled ifTrue:[ |
|
1387 |
logo := passiveLogo. |
|
1388 |
] ifFalse:[ |
|
1389 |
logo := disabledLogo. |
|
1390 |
]. |
|
1391 |
] ifFalse:[ |
|
1392 |
logo := passiveLogo |
|
1393 |
]. |
|
1394 |
^ self redisplay |
|
1395 |
]. |
|
309
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
265
diff
changeset
|
1396 |
super showNoFocus:explicit |
205 | 1397 |
|
1398 |
"Created: 17.9.1995 / 20:00:06 / claus" |
|
1399 |
"Modified: 17.9.1995 / 20:26:32 / claus" |
|
0 | 1400 |
! ! |
1401 |
||
1402 |
!Button methodsFor:'initialization'! |
|
1403 |
||
205 | 1404 |
defaultControllerClass |
1405 |
^ ButtonController |
|
1406 |
! |
|
1407 |
||
1408 |
initCursor |
|
1409 |
"set up a hand cursor" |
|
0 | 1410 |
|
205 | 1411 |
cursor := Cursor hand |
1412 |
! |
|
1413 |
||
1414 |
initEvents |
|
1415 |
super initEvents. |
|
1416 |
self enableEnterLeaveEvents |
|
0 | 1417 |
! |
1418 |
||
1419 |
initStyle |
|
59 | 1420 |
|hasGreyscales nm| |
1421 |
||
1422 |
super initStyle. |
|
1423 |
||
392
81343306d796
eliminated all DefaultFont classVars (are now classINSTvars)
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
1424 |
"/ DefaultFont notNil ifTrue:[font := DefaultFont on:device]. |
81343306d796
eliminated all DefaultFont classVars (are now classINSTvars)
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
1425 |
|
74 | 1426 |
DefaultBorderWidth notNil ifTrue:[borderWidth := DefaultBorderWidth]. |
59 | 1427 |
DefaultForegroundColor notNil ifTrue:[fgColor := DefaultForegroundColor on:device]. |
1428 |
DefaultBackgroundColor notNil ifTrue:[bgColor := DefaultBackgroundColor on:device]. |
|
1429 |
||
62 | 1430 |
edgeStyle := DefaultEdgeStyle. |
59 | 1431 |
onLevel := DefaultActiveLevel. |
1432 |
offLevel := DefaultPassiveLevel. |
|
1433 |
||
1434 |
DefaultDisabledForegroundColor notNil ifTrue:[ |
|
1435 |
disabledFgColor := DefaultDisabledForegroundColor on:device |
|
1436 |
] ifFalse:[ |
|
1437 |
disabledFgColor := fgColor |
|
1438 |
]. |
|
1439 |
||
1440 |
DefaultEnteredForegroundColor notNil ifTrue:[enteredFgColor := DefaultEnteredForegroundColor on:device]. |
|
1441 |
DefaultEnteredBackgroundColor notNil ifTrue:[enteredBgColor := DefaultEnteredBackgroundColor on:device]. |
|
1442 |
DefaultActiveForegroundColor notNil ifTrue:[activeFgColor := DefaultActiveForegroundColor on:device]. |
|
1443 |
DefaultActiveBackgroundColor notNil ifTrue:[activeBgColor := DefaultActiveBackgroundColor on:device]. |
|
1444 |
||
62 | 1445 |
DefaultShadowColor notNil ifTrue:[shadowColor := DefaultShadowColor on:device]. |
1446 |
DefaultLightColor notNil ifTrue:[lightColor := DefaultLightColor on:device]. |
|
59 | 1447 |
|
62 | 1448 |
shadowColor isNil ifTrue:[ |
1449 |
shadowColor := Black. |
|
1450 |
]. |
|
1451 |
lightColor isNil ifTrue:[ |
|
1452 |
lightColor := White. |
|
1453 |
]. |
|
59 | 1454 |
|
1455 |
hasGreyscales := device hasGreyscales. |
|
62 | 1456 |
(edgeStyle == #soft) ifTrue:[ |
1457 |
DefaultHalfShadowColor notNil ifTrue:[halfShadowColor := DefaultHalfShadowColor on:device]. |
|
1458 |
DefaultHalfLightColor notNil ifTrue:[halfLightColor := DefaultHalfLightColor on:device]. |
|
1459 |
||
1460 |
halfShadowColor isNil ifTrue:[ |
|
1461 |
"/ hasGreyscales ifTrue:[ |
|
1462 |
"/ halfShadowColor := Color darkGrey |
|
1463 |
"/ ] ifFalse:[ |
|
1464 |
"/ halfShadowColor := shadowColor |
|
1465 |
"/ ] |
|
1466 |
halfShadowColor := shadowColor lightened |
|
59 | 1467 |
] |
1468 |
]. |
|
1469 |
||
62 | 1470 |
" |
1471 |
actually, the stuf below should not be needed |
|
1472 |
- the styleSheet should provide values for nonGreyscale displays too |
|
1473 |
" |
|
130 | 1474 |
nm := styleSheet name. |
62 | 1475 |
(nm == #iris) ifTrue:[ |
1476 |
hasGreyscales ifTrue:[ |
|
1477 |
DefaultEnteredBackgroundColor isNil ifTrue:[ |
|
1478 |
enteredBgColor := bgColor lightened "Color lightGrey". |
|
1479 |
]. |
|
1480 |
DefaultActiveBackgroundColor isNil ifTrue:[ |
|
1481 |
activeBgColor := enteredBgColor. |
|
1482 |
]. |
|
1483 |
DefaultActiveForegroundColor isNil ifTrue:[ |
|
1484 |
activeFgColor := enteredFgColor. |
|
59 | 1485 |
]. |
1486 |
] ifFalse:[ |
|
62 | 1487 |
DefaultEnteredBackgroundColor isNil ifTrue:[ |
1488 |
enteredBgColor := Color veryLightGrey. |
|
1489 |
]. |
|
1490 |
DefaultActiveBackgroundColor isNil ifTrue:[ |
|
1491 |
activeBgColor := Black. |
|
1492 |
]. |
|
1493 |
DefaultActiveForegroundColor isNil ifTrue:[ |
|
1494 |
activeFgColor := White. |
|
1495 |
]. |
|
1496 |
]. |
|
1497 |
] ifFalse:[ |
|
1498 |
nm == #motif ifTrue:[ |
|
1499 |
lightColor isNil ifTrue:[ |
|
1500 |
lightColor := bgColor lightened |
|
1501 |
]. |
|
1502 |
"/ hasGreyscales ifTrue:[ |
|
1503 |
"/ lightColor := Color lightGrey |
|
1504 |
"/ ] |
|
1505 |
] ifFalse:[ |
|
1506 |
nm == #st80 ifTrue:[ |
|
59 | 1507 |
hasGreyscales ifTrue:[ |
62 | 1508 |
DefaultActiveForegroundColor isNil ifTrue:[ |
1509 |
activeFgColor := fgColor. |
|
1510 |
]. |
|
1511 |
DefaultActiveBackgroundColor isNil ifTrue:[ |
|
1512 |
activeBgColor := bgColor darkened. |
|
1513 |
]. |
|
1514 |
] ifFalse:[ |
|
1515 |
DefaultActiveForegroundColor isNil ifTrue:[ |
|
1516 |
activeFgColor := White. |
|
1517 |
]. |
|
1518 |
DefaultActiveBackgroundColor isNil ifTrue:[ |
|
1519 |
activeBgColor := Black |
|
59 | 1520 |
] |
1521 |
] |
|
1522 |
] |
|
1523 |
] |
|
1524 |
]. |
|
1525 |
||
1526 |
offLevel ~~ level ifTrue:[ |
|
1527 |
self level:offLevel. |
|
1528 |
margin := (onLevel abs) max:(offLevel abs). |
|
1529 |
]. |
|
1530 |
||
1531 |
DefaultReturnButtonHasImage ifTrue:[ |
|
130 | 1532 |
(styleSheet is3D and:[hasGreyscales]) ifTrue:[ |
59 | 1533 |
shadowForm := self class returnShadowFormOn:device. |
1534 |
lightForm := self class returnLightFormOn:device. |
|
1535 |
formColor := viewBackground. |
|
1536 |
formShadowColor := shadowColor. |
|
1537 |
formLightColor := lightColor |
|
1538 |
] ifFalse:[ |
|
1539 |
shadowForm := self class returnFormOn:device. |
|
1540 |
formColor := Black |
|
1541 |
]. |
|
1542 |
]. |
|
1543 |
! |
|
1544 |
||
205 | 1545 |
initialize |
1546 |
super initialize. |
|
0 | 1547 |
|
205 | 1548 |
isReturnButton := false. |
0 | 1549 |
! |
1550 |
||
1551 |
realize |
|
1552 |
super realize. |
|
118 | 1553 |
|
77 | 1554 |
controller active:false. |
1555 |
controller entered:false. |
|
0 | 1556 |
|
1557 |
fgColor := fgColor on:device. |
|
1558 |
bgColor := bgColor on:device. |
|
18 | 1559 |
formColor notNil ifTrue:[ |
59 | 1560 |
formColor := formColor on:device. |
18 | 1561 |
]. |
0 | 1562 |
! |
1563 |
||
1564 |
reinitialize |
|
1565 |
super reinitialize. |
|
77 | 1566 |
controller notNil ifTrue:[ |
1567 |
controller active:false. |
|
1568 |
controller entered:false. |
|
1569 |
] |
|
205 | 1570 |
! ! |
1571 |
||
1572 |
!Button methodsFor:'private'! |
|
1573 |
||
1574 |
XXresize |
|
1575 |
"resize myself to make logo fit into myself. |
|
1576 |
Redefined, since we add space for a frame around text when non-3D" |
|
1577 |
||
1578 |
|extra| |
|
1579 |
||
1580 |
logo isNil ifFalse:[ |
|
1581 |
self computeLabelOrigin. |
|
1582 |
(relativeExtent isNil and:[extentRule isNil]) ifTrue:[ |
|
1583 |
extra := (onLevel abs max:offLevel abs) * 2. |
|
1584 |
styleSheet is3D ifFalse:[ |
|
1585 |
"/ (logo isKindOf:Form) ifFalse:[ |
|
1586 |
"add space for a rectangle around" |
|
1587 |
extra := extra + 2 |
|
1588 |
"/ ] |
|
1589 |
]. |
|
1590 |
self extent:(labelWidth + extra) @ (labelHeight + extra) |
|
1591 |
] |
|
1592 |
] |
|
77 | 1593 |
! |
1594 |
||
205 | 1595 |
computeLabelOrigin |
1596 |
"compute the origin of the text - if I am a returnButton, |
|
1597 |
shift it somwehat to the right (we have already allocated the |
|
1598 |
real estate, since computeLabelSize returned some extra space |
|
1599 |
before)." |
|
1600 |
||
1601 |
super computeLabelOrigin. |
|
1602 |
(isReturnButton and:[shadowForm notNil]) ifTrue:[ |
|
1603 |
labelOriginX := labelOriginX + hSpace + hSpace. |
|
1604 |
] |
|
1605 |
! |
|
1606 |
||
1607 |
computeLabelSize |
|
1608 |
"compute the extent needed to hold the label plus the return form" |
|
1609 |
||
1610 |
super computeLabelSize. |
|
1611 |
(isReturnButton and:[shadowForm notNil]) ifTrue:[ |
|
1612 |
labelWidth := labelWidth + (hSpace * 2) + shadowForm width. |
|
1613 |
labelHeight := labelHeight max: (shadowForm height + vSpace) |
|
1614 |
] |
|
0 | 1615 |
! ! |
1616 |
||
62 | 1617 |
!Button methodsFor:'queries'! |
0 | 1618 |
|
1619 |
is3D |
|
1620 |
"return true, if the receiver is a 3D style view" |
|
1621 |
||
130 | 1622 |
styleSheet name == #mswindows ifTrue:[^ true]. |
0 | 1623 |
^ super is3D |
1624 |
! |
|
1625 |
||
127 | 1626 |
isOn |
1627 |
"return true, if this button is currently pressed" |
|
1628 |
||
1629 |
^ controller pressed |
|
155 | 1630 |
! |
1631 |
||
205 | 1632 |
isReturnButton |
1633 |
"return true, if this is a return button" |
|
0 | 1634 |
|
205 | 1635 |
^ isReturnButton |
156 | 1636 |
! |
1637 |
||
130 | 1638 |
preferredExtent |
1639 |
"return my preferred extent - this is the minimum size I would like to have" |
|
35 | 1640 |
|
131 | 1641 |
|extraH extraV| |
35 | 1642 |
|
1643 |
logo notNil ifTrue:[ |
|
131 | 1644 |
" |
1645 |
extraH := extraV := (onLevel abs max:offLevel abs) + ViewSpacing * 2. |
|
1646 |
" |
|
1647 |
extraH := extraV := (onLevel abs max:offLevel abs). |
|
1648 |
extraH := (extraH + hSpace * 2). |
|
1649 |
extraV := (extraV + vSpace * 2). |
|
1650 |
||
59 | 1651 |
self is3D ifFalse:[ |
97 | 1652 |
"add space for a frame around" |
131 | 1653 |
extraH := extraH + 2. extraV := extraV + 2. |
59 | 1654 |
]. |
131 | 1655 |
^ (labelWidth + extraH) @ (labelHeight + extraV) |
35 | 1656 |
]. |
1657 |
||
130 | 1658 |
^ super preferredExtent |
0 | 1659 |
! |
1660 |
||
205 | 1661 |
specClass |
1662 |
self class == Button ifTrue:[^ ActionButtonSpec]. |
|
1663 |
^ nil |
|
162 | 1664 |
! ! |
1665 |
||
0 | 1666 |
!Button methodsFor:'redrawing'! |
1667 |
||
205 | 1668 |
drawBottomEdge |
1669 |
"draw bottom 3D edge into window frame" |
|
1670 |
||
1671 |
self drawBottomEdgeLevel:level |
|
1672 |
shadow:shadowColor |
|
1673 |
light:lightColor |
|
1674 |
halfShadow:halfShadowColor |
|
1675 |
halfLight:halfLightColor |
|
1676 |
style:edgeStyle. |
|
133 | 1677 |
! |
1678 |
||
62 | 1679 |
drawEdges |
1680 |
"draw all of my 3D edges" |
|
1681 |
||
1682 |
self drawEdgesForX:0 y:0 width:width height:height level:level |
|
1683 |
shadow:shadowColor |
|
1684 |
light:lightColor |
|
1685 |
halfShadow:halfShadowColor |
|
1686 |
halfLight:halfLightColor |
|
1687 |
style:edgeStyle |
|
1688 |
! |
|
1689 |
||
1690 |
drawLeftEdge |
|
1691 |
"draw left 3D edge into window frame" |
|
1692 |
||
1693 |
self drawLeftEdgeLevel:level |
|
1694 |
shadow:shadowColor |
|
1695 |
light:lightColor |
|
1696 |
halfShadow:halfShadowColor |
|
1697 |
halfLight:halfLightColor |
|
1698 |
style:edgeStyle. |
|
1699 |
! |
|
1700 |
||
1701 |
drawRightEdge |
|
1702 |
"draw right 3D edge into window frame" |
|
1703 |
||
1704 |
self drawRightEdgeLevel:level |
|
1705 |
shadow:shadowColor |
|
1706 |
light:lightColor |
|
1707 |
halfShadow:halfShadowColor |
|
1708 |
halfLight:halfLightColor |
|
1709 |
style:edgeStyle. |
|
1710 |
! |
|
1711 |
||
1712 |
drawTopEdge |
|
1713 |
"draw top 3D edge into window frame" |
|
1714 |
||
1715 |
self drawTopEdgeLevel:level |
|
1716 |
shadow:shadowColor |
|
1717 |
light:lightColor |
|
1718 |
halfShadow:halfShadowColor |
|
1719 |
halfLight:halfLightColor |
|
1720 |
style:edgeStyle. |
|
1721 |
! |
|
1722 |
||
0 | 1723 |
drawWith:fg and:bg |
1724 |
"redraw myself with fg/bg. Use super to draw the label, add |
|
1725 |
the return-arrow here." |
|
1726 |
||
18 | 1727 |
|x y sColor lColor| |
0 | 1728 |
|
59 | 1729 |
shown ifFalse:[^ self]. |
0 | 1730 |
super drawWith:fg and:bg. "this draws the text" |
1731 |
||
59 | 1732 |
(isReturnButton and:[shadowForm notNil]) ifTrue:[ |
1733 |
y := (height - shadowForm height) // 2. |
|
1734 |
x := width - shadowForm width - (hSpace // 2). |
|
1735 |
||
1736 |
formShadowColor isNil ifTrue:[ |
|
1737 |
self paint:fg on:bg. |
|
130 | 1738 |
"/ self background:bg. |
59 | 1739 |
self displayOpaqueForm:shadowForm x:x y:y. |
1740 |
^ self |
|
1741 |
]. |
|
0 | 1742 |
|
59 | 1743 |
" |
1744 |
drawing form in 3d-style (i.e. with shadow and light) |
|
1745 |
" |
|
1746 |
(formShadowColor isColor and:[formShadowColor colorId notNil |
|
1747 |
and:[formLightColor isColor and:[formLightColor colorId notNil |
|
1748 |
and:[formColor isColor and:[formColor colorId notNil]]]]]) |
|
1749 |
ifTrue:[ |
|
1750 |
sColor := formShadowColor. |
|
1751 |
lColor := formLightColor. |
|
1752 |
] ifFalse:[ |
|
1753 |
sColor := Black. |
|
1754 |
lColor := White. |
|
1755 |
]. |
|
1756 |
self foreground:sColor. |
|
1757 |
self displayForm:shadowForm x:x y:y. |
|
35 | 1758 |
|
59 | 1759 |
lightForm notNil ifTrue:[ |
1760 |
self foreground:lColor. |
|
1761 |
self displayForm:lightForm x:x y:y. |
|
1762 |
]. |
|
1763 |
self paint:fg. |
|
0 | 1764 |
] |
1765 |
! |
|
1766 |
||
205 | 1767 |
enableStateChangeRedraw |
1768 |
"redraw the button after an enable state change" |
|
59 | 1769 |
|
205 | 1770 |
disabledLogo notNil ifTrue:[ |
1771 |
controller enabled ifFalse:[ |
|
1772 |
logo := disabledLogo. |
|
1773 |
] ifTrue:[ |
|
1774 |
controller active ifTrue:[ |
|
1775 |
logo := activeLogo |
|
1776 |
] ifFalse:[ |
|
1777 |
logo := passiveLogo |
|
1778 |
]. |
|
1779 |
]. |
|
59 | 1780 |
]. |
205 | 1781 |
shown ifFalse:[^ self]. |
1782 |
self redisplay. |
|
82 | 1783 |
|
205 | 1784 |
"Created: 17.9.1995 / 19:46:14 / claus" |
1785 |
"Modified: 17.9.1995 / 19:56:24 / claus" |
|
133 | 1786 |
! |
1787 |
||
1788 |
redisplay |
|
82 | 1789 |
"redraw the button. |
1790 |
Thats like redrawing a label, but use different colors when pressed |
|
1791 |
or entered." |
|
0 | 1792 |
|
229 | 1793 |
|fg bg entered noFrame| |
0 | 1794 |
|
62 | 1795 |
shown ifFalse:[^ self]. |
35 | 1796 |
|
265 | 1797 |
noFrame := true. |
62 | 1798 |
fg := fgColor. |
1799 |
bg := bgColor. |
|
77 | 1800 |
controller enabled ifFalse:[ |
62 | 1801 |
fg := disabledFgColor |
1802 |
] ifTrue:[ |
|
77 | 1803 |
entered := controller entered. |
62 | 1804 |
entered ifTrue:[ |
1805 |
enteredFgColor notNil ifTrue:[fg := enteredFgColor]. |
|
1806 |
enteredBgColor notNil ifTrue:[bg := enteredBgColor] |
|
1807 |
]. |
|
77 | 1808 |
(controller pressed and:[entered or:[controller isTriggerOnDown]]) ifTrue:[ |
229 | 1809 |
noFrame := false. |
62 | 1810 |
activeFgColor isNil ifTrue:[ |
1811 |
onLevel == offLevel ifTrue:[ |
|
1812 |
fg := bgColor |
|
1813 |
] |
|
1814 |
] ifFalse:[ |
|
1815 |
fg := activeFgColor. |
|
59 | 1816 |
]. |
62 | 1817 |
activeBgColor isNil ifTrue:[ |
1818 |
onLevel == offLevel ifTrue:[ |
|
1819 |
bg := fgColor |
|
1820 |
] |
|
1821 |
] ifFalse:[ |
|
1822 |
bg := activeBgColor |
|
1823 |
]. |
|
232 | 1824 |
|
62 | 1825 |
self is3D ifFalse:[ |
232 | 1826 |
noFrame := (fgColor = fg) and:[bgColor = bg]. |
62 | 1827 |
]. |
1828 |
]. |
|
1829 |
]. |
|
265 | 1830 |
self drawWith:fg and:bg. |
1831 |
noFrame ifFalse:[ |
|
1832 |
" |
|
1833 |
draw a rectangle around (2D styles only) |
|
1834 |
" |
|
1835 |
self paint:fg. |
|
1836 |
self displayRectangleX:0 y:0 width:width height:height. |
|
1837 |
^ self |
|
1838 |
]. |
|
1839 |
||
1840 |
"Modified: 17.12.1995 / 17:03:46 / cg" |
|
162 | 1841 |
! |
1842 |
||
205 | 1843 |
redraw |
1844 |
"redraw the button. but not if currently active" |
|
1845 |
||
1846 |
shown ifFalse:[^ self]. |
|
1847 |
"/ controller active ifTrue:[^ self]. - disabled; otherwise, we do not redreaw if changed from within action procedure |
|
1848 |
self redisplay. |
|
1849 |
! |
|
1850 |
||
1851 |
redrawIfPressed |
|
1852 |
"redraw the button, but only if visible and currently being pressed" |
|
1853 |
||
1854 |
shown ifTrue:[ |
|
1855 |
controller pressed ifTrue:[ |
|
1856 |
self redisplay |
|
1857 |
] |
|
1858 |
] |
|
1859 |
! |
|
1860 |
||
1861 |
redrawX:x y:y width:w height:h |
|
1862 |
self redisplay. |
|
1863 |
! |
|
1864 |
||
1865 |
showActive |
|
1866 |
"redraw myself as active (i.e. busy)" |
|
162 | 1867 |
|
205 | 1868 |
onLevel ~~ level ifTrue:[ |
1869 |
self level:onLevel. |
|
1870 |
]. |
|
1871 |
(activeLogo notNil and:[activeLogo ~~ logo]) ifTrue:[ |
|
1872 |
self logo:activeLogo |
|
162 | 1873 |
]. |
205 | 1874 |
self redraw. |
1875 |
! |
|
1876 |
||
1877 |
showPassive |
|
1878 |
"redraw myself as passive" |
|
162 | 1879 |
|
205 | 1880 |
offLevel ~~ level ifTrue:[ |
1881 |
self level:offLevel. |
|
1882 |
]. |
|
1883 |
(passiveLogo notNil and:[passiveLogo ~~ logo]) ifTrue:[ |
|
1884 |
self logo:passiveLogo |
|
1885 |
]. |
|
1886 |
self redraw. |
|
0 | 1887 |
! ! |
205 | 1888 |
|
1889 |
!Button class methodsFor:'documentation'! |
|
1890 |
||
1891 |
version |
|
392
81343306d796
eliminated all DefaultFont classVars (are now classINSTvars)
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
1892 |
^ '$Header: /cvs/stx/stx/libwidg/Button.st,v 1.51 1996-02-24 16:33:36 cg Exp $' |
205 | 1893 |
! ! |