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