ChckTggle.st
author Claus Gittinger <cg@exept.de>
Tue, 16 Jan 1996 03:04:32 +0100
changeset 289 82d20a3e2fe8
parent 265 76336839475b
child 375 6656f7e8ae20
permissions -rw-r--r--
dont grab if no menu pulled

"
 COPYRIGHT (c) 1991 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"

Toggle subclass:#CheckToggle
	 instanceVariableNames:''
	 classVariableNames:'DefaultCheckForm DefaultCheckColor DefaultActiveFGColor
		DefaultActiveBGColor DefaultFGColor DefaultBGColor
		DefaultActiveLevel DefaultPassiveLevel DefaultBorderWidth'
	 poolDictionaries:''
	 category:'Views-Interactors'
!

!CheckToggle class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1991 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

documentation
"
    CheckButtons are like Toggles in toggling their state when pressed.
    However, they show an ok-marker if on; nothing if off.
    CheckButtons are mostly used as part of a checkBox (since normally,
    you want to have some label along the check) and often grouped for
    many-in-many or one-in-many setups.

    StyleSheet values:

	checkToggleCheckColor   <Color>         color to draw check-image with.
						defaults to value of #buttonActiveForegroundColor.

	checkToggleActiveBackgroundColor        background color to draw active checki-image with
	checkToggleForegroundColor              foreground color to use if off
	checkToggleBackgroundColor              background color to use if off

	checkToggleBitmapFile   <String>        name of bitmap file for check-image

	checkToggleStyle        <Symbol>        default checkForm style.
						used if above is nil or file not readable
						can be #cross or #check; defaults to #check 

	checkToggleAvtiveLevel  <Number>        active level - defaults to value of #buttonPassiveLevel
	checkTogglePassiveLevel <Number>        active level - defaults to value of #buttonPassiveLevel
	checkToggleBorderWidth  <Number>        borderWidth - defaults buttons default

    (if not set in the styleSheet, Toggle values are taken)

    See examples.

    See also: CheckBox  RadioButton  RadioButtonGroup Toggle Button
"
!

examples 
"
    checkToggle alone:

	|top check|

	top := StandardSystemView new.
	top extent:100@100.

	check := CheckToggle in:top.
	check origin:10@10.

	top open

    give it an action:

	|top check|

	top := StandardSystemView new.
	top extent:100@100.

	check := CheckToggle in:top.
	check origin:10@10.
	check action:[:value | Transcript showCr:'changed to: ' , value printString].

	top open

    give it a model:

	|top check model|

	model := false asValue.

	top := StandardSystemView new.
	top extent:100@100.

	check := CheckToggle in:top.
	check origin:10@10.
	check model:model.

	top openModal.

	Transcript showCr:'value after closing box: ' , model value printString

    multiple checks on a single model (with different change selectors):
    (using a checkBox here, for the demonstration ...)
    (this is a typical many-in-many setup)

	|top model panel ext1 ext2
	 readFlag writeFlag executeFlag|

	readFlag := writeFlag := true.
	executeFlag := false.

	model := Plug new.
	model respondTo:#read with:[readFlag].
	model respondTo:#write with:[writeFlag].
	model respondTo:#execute with:[executeFlag].
	model respondTo:#read: with:[:val | readFlag := val].
	model respondTo:#write: with:[:val | writeFlag := val].
	model respondTo:#execute: with:[:val | executeFlag := val].

	top := StandardSystemView new.
	top extent:200@200.
	top label:'File permissions:'.

	panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.

	#(read write execute) do:[:sym |
	    |check|

	    check := CheckBox in:panel.
	    check label:sym.
	    check model:model; aspect:sym; changeMessage:(sym , ':') asSymbol.
	].

	top openModal.

	Transcript showCr:'settings after closing box:'.
	Transcript showCr:'  read -> ' , readFlag printString.
	Transcript showCr:'  write -> ' , writeFlag printString.
	Transcript showCr:'  execute -> ' , executeFlag printString.


    checkToggles in a group
    (this is a typical one-in-many setup)

	|top panel check1 check2 check3 grp|

	top := StandardSystemView new.
	top extent:200@300.

	panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.

	check1 := CheckToggle in:panel.
	check2 := CheckToggle in:panel.
	check3 := CheckToggle in:panel.

	grp := RadioButtonGroup new.
	grp add:check1.
	grp add:check2.
	grp add:check3.

	top open


     Channel operation 
     -----------------

       enabling other toggles via a toggle

	|top panel t enableChannel|

	top := StandardSystemView new.
	top extent:(400 @ 200).

	panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.

	enableChannel := false asValue.

	1 to:10 do:[:i |
	    t := CheckToggle in:panel.
	    t enableChannel:enableChannel.
	].

	t := Toggle in:panel.
	t activeLogo:'enabled'; passiveLogo:'disabled'.
	t controller pressChannel:enableChannel.

	top open
"
! !

!CheckToggle class methodsFor:'defaults'!

checkFormOn:aDevice
    "return the form used when checkToggle is turned on.
     Provided as public entry, to allow other views
     to share the same check-image."

    ^ DefaultCheckForm on:aDevice.
!

updateStyleCache
    |checkFileName bits|

    DefaultCheckColor := StyleSheet colorAt:'checkToggleCheckColor'.
    DefaultFGColor := StyleSheet colorAt:'checkToggleForegroundColor'.
    DefaultBGColor := StyleSheet colorAt:'checkToggleBackgroundColor'.
    DefaultActiveFGColor := StyleSheet colorAt:'checkToggleActiveForegroundColor'.
    DefaultActiveBGColor := StyleSheet colorAt:'checkToggleActiveBackgroundColor'.
    DefaultActiveLevel := StyleSheet at:'checkToggleActiveLevel'.
    DefaultPassiveLevel := StyleSheet at:'checkTogglePassiveLevel'.
    DefaultBorderWidth := StyleSheet at:'checkToggleBorderWidth'.

    DefaultCheckForm := nil.
    checkFileName := StyleSheet at:'checkToggleBitmapFile' default:'CheckOn.xbm'.
    checkFileName notNil ifTrue:[
	DefaultCheckForm := Form fromFile:checkFileName 
			       resolution:100
				       on:Display.
    ].
    DefaultCheckForm isNil ifTrue:[
	(StyleSheet at:'checkToggleStyle' default:#check) == #cross ifTrue:[
	    bits := #[2r10000000 2r00000001
		      2r01000000 2r00000010
		      2r00100000 2r00000100
		      2r00010000 2r00001000
		      2r00001000 2r00010000
		      2r00000100 2r00100000
		      2r00000010 2r01000000
		      2r00000001 2r10000000
		      2r00000001 2r10000000
		      2r00000010 2r01000000
		      2r00000100 2r00100000
		      2r00001000 2r00010000
		      2r00010000 2r00001000
		      2r00100000 2r00000100
		      2r01000000 2r00000010
		      2r10000000 2r00000001]

	] ifFalse:[
	    bits := #[2r00000000 2r00000000
		      2r00000000 2r00000010
		      2r00000000 2r00000010
		      2r00000000 2r00000100
		      2r00000000 2r00000100
		      2r00000000 2r00001000
		      2r00000000 2r00001000
		      2r00000000 2r00010000
		      2r01000000 2r00110000
		      2r00100000 2r01100000
		      2r00011000 2r01100000
		      2r00001110 2r11000000
		      2r00000111 2r11000000
		      2r00000011 2r10000000
		      2r00000001 2r10000000
		      2r00000000 2r00000000]
	].
	DefaultCheckForm := Form width:16 height:16 fromArray:bits on:Display                                           
    ]
! !

!CheckToggle methodsFor:'initialization'!

initStyle
    super initStyle.

    onLevel := offLevel.
    DefaultActiveLevel notNil ifTrue:[onLevel := DefaultActiveLevel].
    DefaultPassiveLevel notNil ifTrue:[offLevel := DefaultPassiveLevel].

    activeLogo := DefaultCheckForm on:device.
    passiveLogo := nil.

    DefaultActiveFGColor notNil ifTrue:[self activeForegroundColor:DefaultActiveFGColor].
    DefaultCheckColor notNil ifTrue:[self activeForegroundColor:DefaultCheckColor].
    DefaultActiveBGColor notNil ifTrue:[self activeBackgroundColor:DefaultActiveBGColor].
    DefaultFGColor notNil ifTrue:[self foregroundColor:DefaultFGColor].
    DefaultBGColor notNil ifTrue:[self backgroundColor:DefaultBGColor].

    showLamp := false.

    DefaultBorderWidth notNil ifTrue:[self borderWidth:DefaultBorderWidth].

    offLevel ~~ level ifTrue:[self level:offLevel].
!

initialize
    super initialize.
    passiveLogo := nil.
    self form:activeLogo "/ to let me compute some defaultExtent
! !

!CheckToggle methodsFor:'redrawing'!

drawWith:fg and:bg
    controller pressed ifTrue:[
	logo := activeLogo.
    ] ifFalse:[
	logo := passiveLogo.
    ].
    super drawWith:fg and:bg

    "Modified: 22.9.1995 / 15:45:02 / claus"
! !

!CheckToggle class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libwidg/Attic/ChckTggle.st,v 1.21 1995-12-17 16:35:38 cg Exp $'
! !