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