author | Claus Gittinger <cg@exept.de> |
Thu, 18 Jan 2018 17:03:53 +0100 | |
changeset 6266 | 7feb5a4f8bf1 |
parent 6060 | fcd81f4fe76c |
permissions | -rw-r--r-- |
0 | 1 |
" |
5 | 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 |
" |
|
2504
f12dab112227
use new #valueWithOptionalArg
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
12 |
"{ Package: 'stx:libwidg' }" |
f12dab112227
use new #valueWithOptionalArg
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
13 |
|
5241 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
0 | 16 |
Button subclass:#Toggle |
377 | 17 |
instanceVariableNames:'showLamp lampColor lampWidth lampHeight' |
1385
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
18 |
classVariableNames:'DefaultShowLamp DefaultLampColor LampInset' |
377 | 19 |
poolDictionaries:'' |
20 |
category:'Views-Interactors' |
|
0 | 21 |
! |
22 |
||
22 | 23 |
!Toggle class methodsFor:'documentation'! |
24 |
||
38 | 25 |
copyright |
26 |
" |
|
27 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
59 | 28 |
All Rights Reserved |
38 | 29 |
|
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
22 | 39 |
documentation |
40 |
" |
|
128 | 41 |
this button changes state whenever clicked upon and stays down (pressed) |
42 |
until clicked again. All the main action is in Button and the controller |
|
43 |
(ToggleController). |
|
38 | 44 |
|
45 |
The toggle may optionally display a little kind-of-lamp (or LED), which |
|
46 |
is turned on when the toggle is pressed. (i.e. as in the Interviews toolkit). |
|
47 |
||
48 |
whenever the Toggle changes its change, it will evaluate one of |
|
49 |
pressAction or releaseAction. |
|
50 |
||
51 |
For ST-80 compatibility, if the model is nonNil, this one gets a new |
|
128 | 52 |
value and is sent a changed message. Also, the toggle will follow changes |
53 |
in the model and update its display as appropriate. |
|
38 | 54 |
If nonNil, the model is supposed to be a ValueHolder holding true or false. |
55 |
||
56 |
||
585 | 57 |
[instance variables:] |
58 |
showLamp <Boolean> true if a lamp should be displayed |
|
59 |
lampColor <Color> color of the lamp |
|
60 |
lampWidth <Integer> width of the lamp in pixel |
|
61 |
lampHeight <Integer> height of the lamp in pixel |
|
119 | 62 |
|
585 | 63 |
[styleSheet values:] |
64 |
toggleShowLamp <Boolean> if true, a lamp is shown; default:false. |
|
65 |
toggleLampColor <Color> lamps color; default:yellow. |
|
66 |
||
67 |
[author:] |
|
68 |
Claus Gittinger |
|
609 | 69 |
|
70 |
[see also:] |
|
71 |
Button RadioButton |
|
72 |
( introduction to view programming :html: programming/viewintro.html#INTER_TOGGLES ) |
|
73 |
||
74 |
||
63 | 75 |
" |
76 |
! |
|
38 | 77 |
|
63 | 78 |
examples |
79 |
" |
|
38 | 80 |
Examples: |
128 | 81 |
Try all, to see what is possible. |
377 | 82 |
(notice, that these examples are meant to show what can be done; |
83 |
usually, all style-related stuff is preinitialized - you should not |
|
84 |
normally play around with onLevel, offLevel, showLamp: etc) |
|
38 | 85 |
|
128 | 86 |
|
38 | 87 |
simple: |
593 | 88 |
[exBegin] |
377 | 89 |
|v t| |
38 | 90 |
|
377 | 91 |
v := StandardSystemView new extent:200@200. |
92 |
t := Toggle label:'press here' in:v. |
|
93 |
t origin:10 @ 10. |
|
655 | 94 |
t action:[:value | Transcript show:'toggle state: '; showCR:value.]. |
377 | 95 |
v open |
593 | 96 |
[exEnd] |
119 | 97 |
|
128 | 98 |
|
119 | 99 |
separate press/release actions: |
593 | 100 |
[exBegin] |
377 | 101 |
|v t| |
119 | 102 |
|
377 | 103 |
v := StandardSystemView new extent:200@200. |
104 |
t := Toggle label:'press here' in:v. |
|
105 |
t origin:10 @ 10. |
|
655 | 106 |
t pressAction:[Transcript showCR:'toggle pressed'.]. |
107 |
t releaseAction:[Transcript showCR:'toggle released'.]. |
|
377 | 108 |
v open |
593 | 109 |
[exEnd] |
38 | 110 |
|
128 | 111 |
|
38 | 112 |
changing logo: |
593 | 113 |
[exBegin] |
377 | 114 |
|v t| |
115 |
||
116 |
v := StandardSystemView new extent:200@200. |
|
117 |
t := Toggle label:'eat me' in:v. |
|
118 |
t origin:10 @ 10. |
|
655 | 119 |
t pressAction:[Transcript showCR:'smaller'. t label:'drink me']. |
120 |
t releaseAction:[Transcript showCR:'larger'. t label:'eat me']. |
|
377 | 121 |
v open |
593 | 122 |
[exEnd] |
377 | 123 |
|
124 |
||
378 | 125 |
changing logo: |
593 | 126 |
[exBegin] |
378 | 127 |
|v t| |
128 |
||
129 |
v := StandardSystemView new extent:200@200. |
|
130 |
t := Toggle in:v. |
|
131 |
t logo:(Form width:16 height:14 fromArray:#( |
|
132 |
2r00000000 2r00000000 |
|
133 |
2r00000000 2r00000000 |
|
134 |
2r00000000 2r00000000 |
|
135 |
2r00000111 2r11100000 |
|
136 |
2r00001100 2r00000000 |
|
137 |
2r00011000 2r00000000 |
|
138 |
2r00011000 2r00000000 |
|
139 |
2r00011000 2r00000000 |
|
140 |
2r00011000 2r00000000 |
|
141 |
2r00001100 2r00000000 |
|
142 |
2r00000111 2r11100000 |
|
143 |
2r00000000 2r00000000 |
|
144 |
2r00000000 2r00000000 |
|
145 |
2r00000000 2r00000000)). |
|
146 |
t origin:10 @ 10. |
|
147 |
v open |
|
593 | 148 |
[exEnd] |
378 | 149 |
|
150 |
||
377 | 151 |
uhh - changing logos and getting bg-colors from the image: |
593 | 152 |
[exBegin] |
377 | 153 |
|v t i| |
154 |
||
155 |
v := StandardSystemView new extent:200@200. |
|
156 |
t := Toggle in:v. |
|
157 |
t origin:10 @ 10. |
|
158 |
t showLamp:false. |
|
159 |
t activeLogo:(i := Image fromFile:'red-ball.gif'). |
|
160 |
t passiveLogo:(Image fromFile:'green-ball.gif'). |
|
161 |
t backgroundColor:(i at:0@0). |
|
162 |
t enteredBackgroundColor:(t backgroundColor). |
|
163 |
t activeBackgroundColor:(t backgroundColor). |
|
164 |
v open |
|
593 | 165 |
[exEnd] |
38 | 166 |
|
128 | 167 |
|
38 | 168 |
changing logo and freezing size (looks better): |
593 | 169 |
[exBegin] |
377 | 170 |
|v t| |
38 | 171 |
|
377 | 172 |
v := StandardSystemView new extent:200@200. |
173 |
'create with large logo; freeze; change to small logo'. |
|
174 |
t := Toggle label:'drink me' in:v. |
|
175 |
t sizeFixed:true. |
|
176 |
t label:'eat me'. |
|
38 | 177 |
|
377 | 178 |
t origin:10 @ 10. |
655 | 179 |
t pressAction:[Transcript showCR:'smaller'. t label:'drink me']. |
180 |
t releaseAction:[Transcript showCR:'larger'. t label:'eat me']. |
|
377 | 181 |
v open |
593 | 182 |
[exEnd] |
38 | 183 |
|
128 | 184 |
|
119 | 185 |
adding a lamp (in some view styles, this is the default anyway): |
593 | 186 |
[exBegin] |
377 | 187 |
|v t| |
38 | 188 |
|
377 | 189 |
v := StandardSystemView new extent:200@200. |
190 |
t := Toggle label:'off' in:v. |
|
191 |
t showLamp:true. |
|
192 |
t origin:10 @ 10. |
|
655 | 193 |
t pressAction:[Transcript showCR:'on'. t label:'on']. |
194 |
t releaseAction:[Transcript showCR:'off'. t label:'off']. |
|
377 | 195 |
v open |
593 | 196 |
[exEnd] |
38 | 197 |
|
128 | 198 |
|
119 | 199 |
changing lamps color: |
593 | 200 |
[exBegin] |
377 | 201 |
|v t| |
38 | 202 |
|
377 | 203 |
v := StandardSystemView new extent:200@200. |
204 |
t := Toggle label:'off' in:v. |
|
205 |
t showLamp:true. |
|
206 |
t lampColor:Color red. |
|
207 |
t origin:10 @ 10. |
|
655 | 208 |
t pressAction:[Transcript showCR:'on'. t label:'on'.]. |
209 |
t releaseAction:[Transcript showCR:'off'. t label:'off'.]. |
|
377 | 210 |
v open |
593 | 211 |
[exEnd] |
119 | 212 |
|
128 | 213 |
|
119 | 214 |
lamp only - no '3D going-in' (this is the default with IRIS style) |
593 | 215 |
[exBegin] |
377 | 216 |
|v t| |
119 | 217 |
|
377 | 218 |
v := StandardSystemView new extent:200@200. |
219 |
t := Toggle label:'off' in:v. |
|
220 |
t showLamp:true. |
|
221 |
t onLevel:(t offLevel). |
|
222 |
t origin:10 @ 10. |
|
655 | 223 |
t pressAction:[Transcript showCR:'on'. t label:'on']. |
224 |
t releaseAction:[Transcript showCR:'off'. t label:'off']. |
|
377 | 225 |
v open |
593 | 226 |
[exEnd] |
38 | 227 |
|
128 | 228 |
|
38 | 229 |
lamp and freezing size of the label (looks better): |
593 | 230 |
[exBegin] |
377 | 231 |
|v t| |
38 | 232 |
|
377 | 233 |
v := StandardSystemView new extent:200@200. |
234 |
t := Toggle label:'off' in:v. |
|
235 |
t showLamp:true. |
|
236 |
t sizeFixed:true. |
|
237 |
t origin:10 @ 10. |
|
655 | 238 |
t pressAction:[Transcript showCR:'on'. t label:'on']. |
239 |
t releaseAction:[Transcript showCR:'off'. t label:'off']. |
|
377 | 240 |
v open |
593 | 241 |
[exEnd] |
38 | 242 |
|
128 | 243 |
|
38 | 244 |
another variation: |
593 | 245 |
[exBegin] |
377 | 246 |
|v t| |
38 | 247 |
|
377 | 248 |
v := StandardSystemView new extent:200@200. |
249 |
t := Toggle label:'off' in:v. |
|
250 |
t showLamp:true. |
|
251 |
t sizeFixed:true. |
|
252 |
t onLevel:(t offLevel). |
|
253 |
t origin:10 @ 10. |
|
655 | 254 |
t pressAction:[Transcript showCR:'on'. t label:'on']. |
255 |
t releaseAction:[Transcript showCR:'off'. t label:'off']. |
|
377 | 256 |
v open |
593 | 257 |
[exEnd] |
38 | 258 |
|
128 | 259 |
|
38 | 260 |
and another one: |
593 | 261 |
[exBegin] |
377 | 262 |
|v t| |
38 | 263 |
|
377 | 264 |
v := StandardSystemView new extent:200@200. |
265 |
t := Toggle label:'off' in:v. |
|
266 |
t showLamp:true. |
|
267 |
t sizeFixed:true. |
|
38 | 268 |
|
377 | 269 |
t showLamp:false. |
270 |
t offLevel:3. |
|
271 |
t onLevel:3. |
|
272 |
t origin:10 @ 10. |
|
655 | 273 |
t pressAction:[Transcript showCR:'on'. t showLamp:true. t label:'on']. |
274 |
t releaseAction:[Transcript showCR:'off'. t showLamp:false. t label:'off']. |
|
377 | 275 |
v open |
593 | 276 |
[exEnd] |
38 | 277 |
|
128 | 278 |
|
38 | 279 |
another font: |
593 | 280 |
[exBegin] |
377 | 281 |
|v t| |
38 | 282 |
|
377 | 283 |
v := StandardSystemView new extent:200@200. |
284 |
t := Toggle label:'off' in:v. |
|
285 |
t font:(Font family:'times' face:'bold' style:'roman' size:24). |
|
286 |
t label:'hello'. |
|
287 |
t origin:10 @ 10. |
|
655 | 288 |
t pressAction:[Transcript showCR:'on'.]. |
289 |
t releaseAction:[Transcript showCR:'off'.]. |
|
377 | 290 |
v open |
593 | 291 |
[exEnd] |
38 | 292 |
|
128 | 293 |
|
5953 | 294 |
another font (no, I don't know what it means :-): |
593 | 295 |
[exBegin] |
377 | 296 |
|v t| |
38 | 297 |
|
377 | 298 |
v := StandardSystemView new extent:200@200. |
299 |
t := Toggle label:'off' in:v. |
|
300 |
t font:(Font family:'k14' face:nil style:nil size:nil). |
|
301 |
t label:(TwoByteString with:(Character value:16r3021)). |
|
38 | 302 |
|
377 | 303 |
t origin:10 @ 10. |
655 | 304 |
t pressAction:[Transcript showCR:'on'.]. |
305 |
t releaseAction:[Transcript showCR:'off'.]. |
|
377 | 306 |
v open |
593 | 307 |
[exEnd] |
119 | 308 |
|
128 | 309 |
|
310 |
using a model (look at 'value' in the inspector): |
|
593 | 311 |
[exBegin] |
377 | 312 |
|m v t| |
119 | 313 |
|
377 | 314 |
m := ValueHolder newBoolean. |
315 |
m inspect. |
|
119 | 316 |
|
377 | 317 |
v := StandardSystemView new extent:200@200. |
318 |
t := Toggle label:'press here to change value' in:v. |
|
319 |
t origin:10 @ 10. |
|
320 |
t model:m. |
|
321 |
v open |
|
593 | 322 |
[exEnd] |
119 | 323 |
|
128 | 324 |
|
119 | 325 |
using a model with different changeSelector: |
593 | 326 |
[exBegin] |
377 | 327 |
|m v t| |
119 | 328 |
|
377 | 329 |
m := Plug new. |
655 | 330 |
m respondTo:#setValue1: with:[:value | Transcript show:'value 1 changed to: '; showCR:value]. |
331 |
m respondTo:#setValue2: with:[:value | Transcript show:'value 2 changed to: '; showCR:value]. |
|
119 | 332 |
|
377 | 333 |
v := StandardSystemView new extent:200@200. |
334 |
t := Toggle label:'press here for value1' in:v. |
|
335 |
t origin:10 @ 10. |
|
336 |
t model:m; change:#setValue1:. |
|
337 |
t := Toggle label:'press here for value2' in:v. |
|
338 |
t origin:10 @ 50. |
|
339 |
t model:m; change:#setValue2:. |
|
340 |
v open |
|
593 | 341 |
[exEnd] |
128 | 342 |
|
343 |
||
344 |
two toggles on the same model: |
|
593 | 345 |
[exBegin] |
377 | 346 |
|m v t| |
128 | 347 |
|
377 | 348 |
m := true asValue. |
128 | 349 |
|
377 | 350 |
v := StandardSystemView new extent:200@200. |
351 |
t := Toggle label:'press here' in:v. |
|
352 |
t origin:10 @ 10. |
|
353 |
t model:m. |
|
128 | 354 |
|
377 | 355 |
t := Toggle label:'or here' in:v. |
356 |
t origin:10 @ 50. |
|
357 |
t model:m. |
|
358 |
v open |
|
593 | 359 |
[exEnd] |
22 | 360 |
" |
361 |
! ! |
|
362 |
||
119 | 363 |
!Toggle class methodsFor:'defaults'! |
364 |
||
365 |
updateStyleCache |
|
441
e170bca66a78
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
378
diff
changeset
|
366 |
"extract values from the styleSheet and cache them in class variables" |
e170bca66a78
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
378
diff
changeset
|
367 |
|
1353 | 368 |
<resource: #style (#'toggle.showLamp' |
369 |
#'toggle.lampColor')> |
|
441
e170bca66a78
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
378
diff
changeset
|
370 |
|
1873 | 371 |
DefaultShowLamp := StyleSheet at:#'toggle.showLamp' default:false. |
372 |
DefaultLampColor := StyleSheet colorAt:#'toggle.lampColor' default:Color yellow. |
|
1385
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
373 |
LampInset := 1 "2". |
441
e170bca66a78
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
378
diff
changeset
|
374 |
|
1385
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
375 |
"Modified: / 3.11.1997 / 11:42:19 / cg" |
119 | 376 |
! ! |
377 |
||
593 | 378 |
!Toggle methodsFor:'accessing-look'! |
205 | 379 |
|
1044 | 380 |
lampColor |
381 |
"returns the color of the toggle-lamp" |
|
382 |
||
383 |
^ lampColor |
|
384 |
! |
|
385 |
||
205 | 386 |
lampColor:aColor |
387 |
"change the color of the toggle-lamp" |
|
388 |
||
389 |
lampColor := aColor. |
|
993 | 390 |
shown ifTrue:[ |
391 |
(showLamp and:[controller pressed]) ifTrue:[ |
|
1553
a89b36bd0fd7
redrawNow, when lampColor changes.
Claus Gittinger <cg@exept.de>
parents:
1470
diff
changeset
|
392 |
self invalidateRepairNow:true |
993 | 393 |
] |
205 | 394 |
] |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
655
diff
changeset
|
395 |
|
1553
a89b36bd0fd7
redrawNow, when lampColor changes.
Claus Gittinger <cg@exept.de>
parents:
1470
diff
changeset
|
396 |
"Modified: / 6.6.1998 / 19:32:50 / cg" |
205 | 397 |
! |
398 |
||
5241 | 399 |
lampHeight |
400 |
^ lampHeight |
|
401 |
! |
|
402 |
||
2957 | 403 |
lampHeight:something |
404 |
lampHeight := something. |
|
405 |
! |
|
406 |
||
5241 | 407 |
lampWidth |
408 |
^ lampWidth |
|
409 |
! |
|
410 |
||
2957 | 411 |
lampWidth: something |
412 |
lampWidth := something |
|
413 |
! |
|
414 |
||
205 | 415 |
showLamp |
416 |
"return true, if I show a lamp" |
|
417 |
||
418 |
^ showLamp |
|
419 |
! |
|
420 |
||
421 |
showLamp:aBoolean |
|
422 |
"enable/disable drawing of the lamp" |
|
423 |
||
424 |
showLamp ~~ aBoolean ifTrue:[ |
|
425 |
showLamp := aBoolean. |
|
426 |
self computeLabelSize. |
|
427 |
fixSize ifFalse:[ |
|
428 |
self resize |
|
429 |
] |
|
430 |
] |
|
431 |
! ! |
|
432 |
||
1044 | 433 |
!Toggle methodsFor:'accessing-mvc'! |
434 |
||
435 |
model:aModel |
|
436 |
super model:aModel. |
|
1083
13e64cc1c493
fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
437 |
self getValueFromModel. |
1044 | 438 |
|
1083
13e64cc1c493
fetch models value when a model is assigned;
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
439 |
"Modified: 28.2.1997 / 19:09:58 / cg" |
1044 | 440 |
! ! |
441 |
||
205 | 442 |
!Toggle methodsFor:'change & update'! |
443 |
||
444 |
update:something with:parameter from:changedObject |
|
445 |
something == aspectMsg ifTrue:[ |
|
1470 | 446 |
self getValueFromModel. |
205 | 447 |
]. |
448 |
super update:something with:parameter from:changedObject |
|
449 |
! ! |
|
450 |
||
22 | 451 |
!Toggle methodsFor:'initialization'! |
452 |
||
105 | 453 |
defaultControllerClass |
454 |
^ ToggleController |
|
455 |
! |
|
456 |
||
936 | 457 |
fetchDeviceResources |
458 |
"fetch device colors, to avoid reallocation at redraw time" |
|
459 |
||
460 |
super fetchDeviceResources. |
|
461 |
||
5630 | 462 |
lampColor notNil ifTrue:[lampColor := lampColor onDevice:device]. |
936 | 463 |
|
464 |
"Created: 13.1.1997 / 23:46:31 / cg" |
|
465 |
! |
|
466 |
||
22 | 467 |
initStyle |
966 | 468 |
"setup viewStyle specifics" |
469 |
||
3262 | 470 |
<resource: #style (#'toggle.lampWidthMM' |
471 |
#'toggle.lampHeightMM' |
|
472 |
#'toggle.activeLevel' |
|
473 |
#'toggle.passiveLevel' |
|
474 |
#'toggle.activeForegroundColor' |
|
475 |
#'toggle.activeBackgroundColor' |
|
476 |
#'toggle.foregroundColor' |
|
477 |
#'toggle.backgroundColor' |
|
478 |
)> |
|
479 |
||
1874
6ff31b38d752
added extra toggle.foreground and toggle.background styles
Claus Gittinger <cg@exept.de>
parents:
1873
diff
changeset
|
480 |
|mm fg bg| |
1385
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
481 |
|
22 | 482 |
super initStyle. |
483 |
||
119 | 484 |
showLamp := DefaultShowLamp. |
22 | 485 |
showLamp ifTrue:[ |
936 | 486 |
onLevel := offLevel. |
22 | 487 |
|
5954 | 488 |
"don't know, if I like this ..." |
936 | 489 |
" |
490 |
activeBgColor := bgColor |
|
491 |
" |
|
22 | 492 |
]. |
38 | 493 |
|
936 | 494 |
lampColor := DefaultLampColor. |
3262 | 495 |
mm := styleSheet at:#'toggle.lampWidthMM' default:1.5. |
5630 | 496 |
lampWidth := (device horizontalPixelPerMillimeter * mm) rounded. |
3262 | 497 |
mm := styleSheet at:#'toggle.lampHeightMM' default:3.0. |
5630 | 498 |
lampHeight := (device verticalPixelPerMillimeter * mm) rounded. |
936 | 499 |
|
1876 | 500 |
onLevel := styleSheet at:#'toggle.activeLevel' default:onLevel. |
501 |
offLevel := styleSheet at:#'toggle.passiveLevel' default:offLevel. |
|
502 |
||
503 |
fg := styleSheet colorAt:#'toggle.activeForegroundColor'. |
|
1874
6ff31b38d752
added extra toggle.foreground and toggle.background styles
Claus Gittinger <cg@exept.de>
parents:
1873
diff
changeset
|
504 |
fg notNil ifTrue:[ |
1876 | 505 |
activeFgColor := fg. |
506 |
]. |
|
507 |
bg := styleSheet colorAt:#'toggle.activeBackgroundColor'. |
|
508 |
bg notNil ifTrue:[ |
|
509 |
activeBgColor := bg. |
|
1874
6ff31b38d752
added extra toggle.foreground and toggle.background styles
Claus Gittinger <cg@exept.de>
parents:
1873
diff
changeset
|
510 |
]. |
6ff31b38d752
added extra toggle.foreground and toggle.background styles
Claus Gittinger <cg@exept.de>
parents:
1873
diff
changeset
|
511 |
|
1876 | 512 |
fg := styleSheet colorAt:#'toggle.foregroundColor'. |
513 |
fg notNil ifTrue:[ |
|
514 |
self foregroundColor:fg. |
|
515 |
]. |
|
516 |
||
517 |
bg := styleSheet colorAt:#'toggle.backgroundColor'. |
|
1873 | 518 |
bg notNil ifTrue:[ |
1876 | 519 |
self backgroundColor:bg. |
5630 | 520 |
shadowColor := (bg averageColorIn:(0@0 corner:7@7)) darkened onDevice:device. |
521 |
lightColor := (bg averageColorIn:(0@0 corner:7@7)) lightened onDevice:device. |
|
1873 | 522 |
]. |
523 |
||
1385
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
524 |
"Modified: / 3.11.1997 / 02:22:02 / cg" |
22 | 525 |
! ! |
526 |
||
527 |
!Toggle methodsFor:'private'! |
|
528 |
||
529 |
computeLabelOrigin |
|
530 |
"compute the origin of the form/text. |
|
531 |
redefined to move label to the right if there is a lamp." |
|
532 |
||
533 |
super computeLabelOrigin. |
|
534 |
showLamp ifTrue:[ |
|
1385
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
535 |
labelOriginX := labelOriginX + hSpace + (self lampImageWidth) + hSpace. |
22 | 536 |
] |
1385
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
537 |
|
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
538 |
"Modified: / 3.11.1997 / 14:27:03 / cg" |
22 | 539 |
! |
540 |
||
205 | 541 |
getValueFromModel |
1464 | 542 |
"fetch my boolean value from the model (if there is a model around) |
543 |
by sending it the aspectMessage, and update my look as required" |
|
544 |
||
205 | 545 |
|val| |
121 | 546 |
|
205 | 547 |
(model notNil and:[aspectMsg notNil]) ifTrue:[ |
2963 | 548 |
aspectMsg == #value ifTrue:[ |
549 |
val := model value "/ faster call |
|
550 |
] ifFalse:[ |
|
551 |
val := model perform:aspectMsg withOptionalArgument:self. |
|
552 |
]. |
|
3571 | 553 |
(val ? false) ifTrue:[ "allowing nil - treat as false" |
1464 | 554 |
self turnOn |
555 |
] ifFalse:[ |
|
556 |
self turnOff |
|
557 |
]. |
|
121 | 558 |
]. |
205 | 559 |
|
1464 | 560 |
"Created: / 14.11.1995 / 21:08:43 / cg" |
2167 | 561 |
"Modified: / 1.3.2000 / 15:14:49 / cg" |
1385
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
562 |
! |
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
563 |
|
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
564 |
lampImageHeight |
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
565 |
^ lampHeight |
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
566 |
|
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
567 |
"Created: / 3.11.1997 / 14:24:47 / cg" |
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
568 |
! |
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
569 |
|
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
570 |
lampImageWidth |
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
571 |
^ lampWidth |
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
572 |
|
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
573 |
"Created: / 3.11.1997 / 14:25:35 / cg" |
4001
12dc99eb1717
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3761
diff
changeset
|
574 |
! |
12dc99eb1717
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3761
diff
changeset
|
575 |
|
12dc99eb1717
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3761
diff
changeset
|
576 |
rawLabelSizeOf:aLogo |
12dc99eb1717
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3761
diff
changeset
|
577 |
"compute the extent needed to hold the label plus the lamp" |
12dc99eb1717
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3761
diff
changeset
|
578 |
|
12dc99eb1717
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3761
diff
changeset
|
579 |
|ext| |
12dc99eb1717
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3761
diff
changeset
|
580 |
|
12dc99eb1717
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3761
diff
changeset
|
581 |
ext := super rawLabelSizeOf:aLogo. |
12dc99eb1717
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3761
diff
changeset
|
582 |
showLamp ifTrue:[ |
12dc99eb1717
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3761
diff
changeset
|
583 |
^ (ext x + hSpace + (self lampImageWidth) + hSpace) |
12dc99eb1717
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3761
diff
changeset
|
584 |
@ |
12dc99eb1717
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3761
diff
changeset
|
585 |
(ext y max: self lampImageHeight) |
12dc99eb1717
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3761
diff
changeset
|
586 |
]. |
12dc99eb1717
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3761
diff
changeset
|
587 |
^ ext |
12dc99eb1717
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3761
diff
changeset
|
588 |
|
12dc99eb1717
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3761
diff
changeset
|
589 |
"Modified: / 3.11.1997 / 14:26:54 / cg" |
121 | 590 |
! ! |
591 |
||
105 | 592 |
!Toggle methodsFor:'redrawing'! |
593 |
||
1385
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
594 |
drawToggleImage |
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
595 |
"drawing of the lamp is done here." |
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
596 |
|
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
597 |
|x y clr l2| |
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
598 |
|
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
599 |
showLamp ifTrue:[ |
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
600 |
x := hSpace + margin. |
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
601 |
y := (height - self lampImageHeight) // 2. |
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
602 |
self |
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
603 |
drawEdgesForX:x y:y |
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
604 |
width:(self lampImageWidth) |
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
605 |
height:(self lampImageHeight) |
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
606 |
level:-1. |
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
607 |
controller pressed ifTrue:[ |
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
608 |
clr := lampColor. |
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
609 |
] ifFalse:[ |
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
610 |
clr := bgColor. |
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
611 |
]. |
6060 | 612 |
gc paint:clr. |
1385
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
613 |
l2 := LampInset*2. |
6060 | 614 |
gc |
1385
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
615 |
fillRectangleX:x+LampInset y:y+LampInset |
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
616 |
width:(self lampImageWidth) - l2 |
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
617 |
height:(self lampImageHeight) - l2 |
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
618 |
] |
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
619 |
|
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
620 |
"Created: / 3.11.1997 / 12:12:07 / cg" |
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
621 |
"Modified: / 3.11.1997 / 14:26:33 / cg" |
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
622 |
! |
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
623 |
|
105 | 624 |
drawWith:fg and:bg |
625 |
"redraw myself with fg/bg. Use super to draw the label, |
|
626 |
drawing of the lamp is done here." |
|
627 |
||
1385
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
628 |
shown ifFalse:[^ self]. |
6060 | 629 |
|
105 | 630 |
super drawWith:fg and:bg. "this draws the text" |
631 |
||
1385
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
632 |
self drawToggleImage. |
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
633 |
|
691d891fa440
flixiblized for better radioButton
Claus Gittinger <cg@exept.de>
parents:
1353
diff
changeset
|
634 |
"Modified: / 3.11.1997 / 13:19:32 / cg" |
105 | 635 |
! ! |
205 | 636 |
|
637 |
!Toggle class methodsFor:'documentation'! |
|
638 |
||
639 |
version |
|
5630 | 640 |
^ '$Header$' |
4001
12dc99eb1717
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3761
diff
changeset
|
641 |
! |
12dc99eb1717
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3761
diff
changeset
|
642 |
|
12dc99eb1717
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3761
diff
changeset
|
643 |
version_CVS |
5630 | 644 |
^ '$Header$' |
205 | 645 |
! ! |
4919 | 646 |