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