Button.st
author Claus Gittinger <cg@exept.de>
Thu, 23 Nov 1995 15:37:40 +0100
changeset 202 01f3cbb8e20e
parent 178 5c28593c2a3b
child 205 6814c0bf8df8
permissions -rw-r--r--
checkin from browser

"
 COPYRIGHT (c) 1989 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.
"

Label subclass:#Button
       instanceVariableNames:'activeLogo passiveLogo disabledLogo focusLogo
			      onLevel offLevel
			      disabledFgColor
			      activeFgColor activeBgColor
			      enteredFgColor enteredBgColor
			      isReturnButton
			      shadowForm lightForm
			      formColor formShadowColor formLightColor
			      edgeStyle halfShadowColor halfLightColor'

      classVariableNames:'ReturnForm ReturnLightForm ReturnShadowForm 
		DefaultFont DefaultActiveLevel
		DefaultPassiveLevel DefaultEdgeStyle DefaultBorderWidth
		DefaultForegroundColor DefaultBackgroundColor
		DefaultDisabledForegroundColor DefaultDisabledBackgroundColor
		DefaultEnteredForegroundColor DefaultEnteredBackgroundColor
		DefaultActiveForegroundColor DefaultActiveBackgroundColor
		DefaultReturnButtonHasImage DefaultReturnButtonHasBorder
		DefaultShadowColor DefaultLightColor
		DefaultHalfShadowColor DefaultHalfLightColor'
       poolDictionaries:''
       category:'Views-Interactors'
!

!Button class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1989 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.
"
!

version
    ^ '$Header: /cvs/stx/stx/libwidg/Button.st,v 1.36 1995-11-15 16:20:26 cg Exp $'
!

documentation
"
    Buttons are Labels which do something when pressed/released.
    Since they inherit from Label, read the documentation on Labels to 
    see how color, layout, font, image or labelString are changed.

    Buttons (and also instances of subclasses, such as toggles, checkToggles
    and radioButtons) perform some action when pressed, and optionally when
    released. Due to historic reasons, ST/X buttons support two mechanisms:

    Actionblock operation:
      the button has an actionBlock (actually, it has two: a pressAction and
      a releaseAction) which is evaluated, when the button is pressed.
      The user of a button can set these action blocks via the #action:,
      #pressAction: or #releaseAction: messages.

    Model-View interaction:
      buttons with a model will send change-messages to the model and also react 
      to changes in the model.
      You have to define the buttons labelMessage and an aspectSymbol.
      When changed, the model should send 'self changed:<aspect>' if it wants the
      label to change and return a string from the labelSymbol-message.
      By default, the labelMsg is nil, therefore no update of the label is done.
      (this behavior is inherited from label, see documentation there)

      When pressed, the button sends a changeMessage to the model.
      If the changeMsg is for a one-argument message, the current
      press-state is passed as argument (i.e. true if pressed, false if released).
      By default, the change-Message is #value: (for ST-80 compatibility).

	button model:aModel.
	button aspect:aspectSymbol.
	button change:changeSymbol.
	button labelMessage:labelSymbol.

	model sends #changed:aspectSymbol
	---> button will redraw its label from value returned by model>>labelSymbol

	button changes state:
	---> button sends changeSymbol / changeSymbol:state to the model

      By default (as inherited), the labelMsg is nil; therefore, buttons
      do not try to aquire a new labelString from the model.
      If you want this behavior, you must set labelMsg and aspectMsg
      as appropriate.

    See examples.


    Instance variables:

      activeLogo              <StringOrImage> logo to show when active (pressed)
      passiveLogo             <StringOrImage> logo to show when passive (released)
					      default is nil for both, so the normal logo is used
					      (see superclass: Label)
      onLevel                 <Integer>       level when pressed (3D only) (default: depends on style)
      offLevel                <Integer>       level when released (3D only) (default: depends on style)
      disabledFgColor         <Color>         color used to draw logo when disabled (default: depends on style)
      activeFgColor           <Color>         color to draw logo when pressed (default: depends on style)
      activeBgColor           <Color>         bg color when pressed (default: depends on style)
      enteredFgColor          <Color>         fg color to draw logo when cursor entered (default: depends on style)
      enteredBgColor          <Color>         bg color when cursor entered (default: depends on style)

      isReturnButton          <Boolean>       true if this button is also activated by the
					      return key - if true, it will draw a return-bitmap 
					      in addition to the logo (default: false)

      shadowForm              <Form>          form to display in addition to buttons label (returnbutton only)
      lightForm               <Form>          light part of shadowForm (returnbutton only)

      formColor               <Color>         color to draw form with (returnbutton only)
      formShadowColor         <Color>         color for shadowing the form (3D only & return)
      formLightColor          <Color>         color for lighting the form (3D only)


    styleSheet parameters:

      buttonActiveLevel       <Integer>       level when on (ignored in 2D styles)
      buttonPassiveLevel      <Integer>       level when off (ignored in 2D styles)
      buttonBorderWidth       <Integer>       default borderwidth
      buttonEdgeStyle         <Symbol>        style of edges (currently #soft or nil)
      buttonFont              <Font>          font to use for textual labels
      buttonForegroundColor   <Color>         color to draw foreground pixels (i.e. the string)
      buttonBackgroundColor   <Color>         color to draw background pixels
      buttonDisabledForegroundColor <Color>   same when disabled
      buttonDisabledBackgroundColor <Color>   same when disabled
      buttonEnteredForegroundColor  <Color>   same when mouse pointer is in
      buttonEnteredBackgroundColor  <Color>   same when mouse pointer is in
      buttonActiveForegroundColor   <Color>   same when button is active
      buttonActiveBackgroundColor   <Color>   same when button is active
      buttonShadowColor             <Color>   shadow color for edgaes (ignored in 2D styles)
      buttonLightColor              <Color>   light color for edgaes (ignored in 2D styles)
      buttonHalfShadowColor         <Color>   half shadow color; for soft edges only
      buttonHalfLightColor          <Color>   half light color; for soft edges only

      buttonReturnButtonHasImage    <Boolean> if true, return-buttons draw a return-key image
      buttonReturnButtonHasBorder   <Boolean> if true, return-buttons show a border

    See also: Toggle  CheckToggle  CheckBox
"
!

actionBlocksVersusModelChanges 
"
    You may ask yourself, why ST/X supports two different ways
    to trigger a buttons action (also true for sliders, selectionInListViews,
    toggles etc.) and when to use which mechanism.

    There are two reasons:
	1) history - historically, ST/X used only actionBlocks
	   Basically, these provide the most general functionality
	   (you can of course send change-messages from those blocks)

	   Change-message notification was added later, to make porting
	   of existing applications easier.

	2) for many (simple) applications, it is often easier, to simply
	   define an action block. This is especially true, if the button
	   triggers some action (such as ok-/abort-buttons) and does NOT
	   change some models internal value.
	   (other smalltalks provide extra adapter-models for this,
	    in which you can set actionBlocks in much the same way).

    In general:
	use model-change-messages, iff multiple views are possibly open
	on the same domain model, and changes can occur from multiple
	places. Or if a change has to be forwarded to multiple other objects
	(possible not foreseen).

	For simplicity, better use actionBlocks for trigger-like actions
	(such as closing a view, ok/abort etc.) iff there is only a single
	entity which is interrested in that button press.
"
!

examples 
"
    You dont have to normally care for all the internals 
    (they allow many variations though). The typical use is:

	b := Button label:'some logo' in:aView.
	b action:[ .. things to do, when pressed ... ]

    for buttons with a string-label,
    and:

	b := Button label:someImage in:aView.
	b action:[ .. things to do, when pressed ... ]

    for buttons with a bitmap label.

    Of course, you can also setup things the ST-80 way, in first
    creating the button and later add it to some superview:

	b := Button new.
	b label:someImage.
	b action:[ .. things to do, when pressed ... ]
	...
	aSuperView add:b in:<frameRectangle>.

    Although you can specify a lot in a button,
    you should use the defaults in most applications.
    As you specify more things in your program, 
    the styleSheet settings are more and more ignored.
    Also, even though it might look fancy, colorful
    button panels are usually not a good GUI design;
    they will attract the users attention - possibly to things
    which are not worth it.
    Finally, if you use fancy colors, always thing of those poor users
    without color displays - the styleSheet allows those people to adjust things,
    while hard-coded colors cannot be fixed without changing the code.

    a button with default settings 
    (you may want to try it with different viewStyle settings in effect):

      |top b|

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

      b := Button in:top.
      b label:'hello'.
      b action:[Transcript flash].
      top open.


    there is also a combined instance creation message:

      |top b|

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

      b := Button label:'hello' action:[Transcript flash] in:top.
      top open.


    a return button
    (in dialogs, you should setup things to have the return-key perform
     the ok action, and mark the corresponding button as being a returnButton):

      |top b|

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

      b := Button label:'hello' action:[Transcript flash] in:top.
      b isReturnButton:true.
      top open.


    enabling/disabling buttons via explicit messages:

      |top panel b1 b2 b3|

      top := StandardSystemView new.
      top extent:300@100.
      panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.

      b1 := Button label:'enable'  action:[b3 enable] in:panel.
      b2 := Button label:'disable' action:[b3 disable] in:panel.
      b3 := Button label:'flash'   action:[Transcript flash] in:panel.
      top open.


    enabling/disabling buttons via implicit value change of a valueHolder:

      |top panel ena t b1 b2 b3 check|

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

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

      ena := false asValue.

      t := Toggle label:'enable' in:panel.
      t model:ena.

      b1 := Button label:'button1' in:panel.
      b1 controller enableChannel:ena.

      b2 := Button label:'button2' in:panel.
      b2 controller enableChannel:ena.

      b3 := Button label:'button3' in:panel.
      b3 controller enableChannel:ena.

      top open.

      check := CheckBox model:ena.
      check label:'also enable'.
      check extent:(check preferredExtent + (5@5)).
      check open



    changing colors:

      |top b|

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

      b := Button label:'hello' in:top.
      b action:[Transcript flash].
      b activeForegroundColor:(Color white).
      b activeBackgroundColor:(Color red).
      top open.


    changing more colors:

      |top b|

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

      b := Button label:'hello' in:top.
      b action:[Transcript flash].
      b enteredForegroundColor:(Color red).
      b enteredBackgroundColor:(b backgroundColor).
      b activeForegroundColor:(Color white).
      b activeBackgroundColor:(Color red).
      top open.


    button with an image and different colors:

      |top b|

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

      b := Button in:top.
      b label:(Image fromFile:'bitmaps/SBrowser.xbm').
      b action:[Transcript flash].
      b enteredForegroundColor:(Color green darkened).
      b enteredBackgroundColor:(b backgroundColor).
      b activeForegroundColor:(Color white).
      b activeBackgroundColor:(Color red).
      top open.


    changing the image when pressed:

      |top b|

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

      b := Button in:top.
      b passiveLogo:(Image fromFile:'bitmaps/SBrowser.xbm').
      b activeLogo:(Image fromFile:'bitmaps/CBrowser.xbm').
      b action:[Transcript flash].
      b enteredForegroundColor:(Color red).
      b enteredBackgroundColor:(b backgroundColor).
      b activeForegroundColor:(Color white).
      b activeBackgroundColor:(Color red).
      top open.


    well, even that is possible (but you should NEVER do it):
    (notice the changing size and the resulting problem when
     pressed near the bottom, since the button thinks the pointer
     leaves the view and changes back and forth ...)

      |top b|

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

      b := Button in:top.
      b passiveLogo:(Image fromFile:'bitmaps/SmalltalkX.xbm').
      b activeLogo:#('start') asStringCollection.
      b action:[Transcript flash].
      b enteredForegroundColor:(Color red).
      b enteredBackgroundColor:(b backgroundColor).
      b activeForegroundColor:(Color white).
      b activeBackgroundColor:(Color red).
      top open.


    same as above, with frozen size to avoid the problem. 
    (make certain, that the size is ok for all possible logos):

      |top b|

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

      b := Button in:top.
      b passiveLogo:(Image fromFile:'bitmaps/SmalltalkX.xbm').
      b activeLogo:#('go') asStringCollection.
      b action:[Transcript flash].
      b enteredForegroundColor:(Color red).
      b enteredBackgroundColor:(b backgroundColor).
      b activeForegroundColor:(Color white).
      b activeBackgroundColor:(Color red).
      b sizeFixed:true.
      top open.


    more playing with colors:

      |top b|

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

      b := Button in:top.
      b logo:(Image fromFile:'bitmaps/SmalltalkX.xbm').
      b action:[Transcript flash].
      b foregroundColor:(Color red:0 green:80 blue:20) darkened.
      b backgroundColor:(Color grey:10).
      b enteredForegroundColor:(Color red).
      b activeForegroundColor:(Color red).
      b activeBackgroundColor:(Color grey:10).
      top open.


    more playing with colors:

      |top b|

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

      b := Button in:top.
      b logo:(Image fromFile:'bitmaps/SmalltalkX.xbm').
      b action:[Transcript flash].
      b foregroundColor:(Color red:0 green:80 blue:20) darkened.
      b backgroundColor:(Color grey:10).
      b enteredBackgroundColor:(Color grey:20).
      b activeForegroundColor:(Color red).
      b activeBackgroundColor:(Color grey:20).
      top open.


    fire on press (buttons in scrollbars do this, while normal buttons
    fire on release).
    To give the user a chance to change her mind
    and leave the button without action, you should not change the default 
    behavior and NOT use triggerOnDown-buttons in most applications:

      |top b|

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

      b := Button label:'hello' in:top.
      b controller beTriggerOnDown.
      b action:[Transcript flash].
      top open.


    To implement fun buttons (for games, show-demos etc.), you can
    access all internal parameters (and not take the viewStyle defaults)
    as in:

	|b granite light shadow|

	b := Button label:'a nice one ?'.
	granite := Image fromFile:'bitmaps/granite_small.tiff'.
	light := granite lightened.
	shadow := granite darkened darkened.
	b backgroundColor:granite.
	b foregroundColor:Color white.
	b shadowColor:shadow.
	b lightColor:light.
	b enteredBackgroundColor:light.
	b enteredForegroundColor:Color black.
	b activeLevel:-3; passiveLevel:5.
	b extent:(200 @ 50).
	b open

    However, in your application, you may want to read those bitmaps only once
    during startup and cache them for later reuse in some class variable
    (reading, lightning & darkening of images is a bit slow)


    ST/X Buttons allow simulation of the ST-80 MVC way of interacting.
    To do so, instead (or in addition) to defining actionBlocks, set the
    buttons model to have this be informed (in addition):

    Model-View interaction (ST-80 style):
    (have a look at the models values in the inspector, as the toggles change)

      |bool1 bool2 b panel top|

      bool1 := ValueHolder newBoolean.
      bool2 := ValueHolder newBoolean value:true.

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

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

      b := Toggle label:'eat me' in:panel.
      b model:bool1.

      b := Toggle label:'drink me' in:panel.
      b model:bool2.

      top open.
      bool1 inspect.
      bool2 inspect.


    Using a PluggableAdaptor (ST-80 style):
    (notice, that this is almost what ST/X buttons did originally,
     therefore, you may want use actionBlocks right away ...)

      |adaptor1 adaptor2 b panel top|

      adaptor1 := PluggableAdaptor new 
			getBlock:[:m | false] 
			putBlock:[:m :v | Transcript showCr:'eat']
			updateBlock:nil.
      adaptor2 := PluggableAdaptor new 
			getBlock:[:m | false] 
			putBlock:[:m :v | Transcript showCr:'drink']
			updateBlock:nil.

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

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

      b := Button label:'eat me' in:panel.
      b model:adaptor1.

      b := Button label:'drink me' in:panel.
      b model:adaptor2.

      top open.


    as a reminder, the corresponding ST/X setup is:

      |b panel top|

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

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

      b := Button label:'eat me' in:panel.
      b action:[Transcript showCr:'eat'].

      b := Button label:'drink me' in:panel.
      b action:[Transcript showCr:'drink'].

      top open.


    accessing multiple aspects of a complex model
    (using a plug here to simulate that model ...)
    (Notice, the next example shall demonstrate multiple aspects;
     for this kind of functionality, you'd better use actionBlocks in
     real applications)

      |myModel b panel top|

      myModel := Plug new.
      myModel respondTo:#grow with:[top extent:200@300].
      myModel respondTo:#shrink with:[top extent:200@100].

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

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

      b := Button label:'eat me' in:panel.
      b model:myModel; change:#grow.

      b := Button label:'drink me' in:panel.
      b model:myModel; change:#shrink.

      top open.


    aquiring the label from the model
    (this functionality is inherited from Label)

      |myModel b panel top currentLabel|

      currentLabel := 'foo'.

      myModel := Plug new.
      myModel respondTo:#getLabel with:[currentLabel].
      myModel respondTo:#b0Pressed with:[].
      myModel respondTo:#b1Pressed with:[currentLabel := 'bar'.
					 myModel changed:#labelAspect].
      myModel respondTo:#b2Pressed with:[currentLabel := 'foo'.
					 myModel changed:#labelAspect].

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

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

      b := Button label:'press me' in:panel.
      b model:myModel; change:#b0Pressed; 
	labelMessage:#getLabel; aspect:#labelAspect.

      b := Button label:'press for bar' in:panel.
      b model:myModel; change:#b1Pressed.

      b := Button label:'press for foo' in:panel.
      b model:myModel; change:#b2Pressed.

      top open.


    the same, using actionBlocks:
      |myModel b panel top currentLabel|

      currentLabel := 'foo'.

      myModel := Plug new.
      myModel respondTo:#getLabel with:[currentLabel].

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

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

      b := Button label:'press me' in:panel.
      b model:myModel; action:[Transcript showCr:'pressed']; 
	labelMessage:#getLabel; aspect:#labelAspect.

      b := Button label:'press for bar' in:panel.
      b action:[currentLabel := 'bar'. myModel changed:#labelAspect].

      b := Button label:'press for foo' in:panel.
      b action:[currentLabel := 'foo'. myModel changed:#labelAspect].

      top open.

    see 'doc/coding-examples' and 'doc/misc/quick_view_intro.doc' 
    for more variations on this theme.
"
! !

!Button class methodsFor:'defaults'!

updateStyleCache
    |defaultLevel|

    StyleSheet is3D ifTrue:[
	defaultLevel := 1.
    ] ifFalse:[
	defaultLevel := 0
    ].
    DefaultActiveLevel := StyleSheet at:'buttonActiveLevel' default:(defaultLevel negated).
    DefaultPassiveLevel := StyleSheet at:'buttonPassiveLevel' default:defaultLevel.

    DefaultEdgeStyle := StyleSheet at:'buttonEdgeStyle'.
    DefaultFont := StyleSheet fontAt:'buttonFont'.
    DefaultBorderWidth := StyleSheet at:'buttonBorderWidth'.
    DefaultForegroundColor := StyleSheet colorAt:'buttonForegroundColor'.
    DefaultBackgroundColor := StyleSheet colorAt:'buttonBackgroundColor'.
    DefaultDisabledForegroundColor := StyleSheet colorAt:'buttonDisabledForegroundColor' default:Color grey.
    DefaultDisabledBackgroundColor := StyleSheet colorAt:'buttonDisabledBackgroundColor'.
    DefaultEnteredForegroundColor := StyleSheet colorAt:'buttonEnteredForegroundColor'.
    DefaultEnteredBackgroundColor := StyleSheet colorAt:'buttonEnteredBackgroundColor'.
    DefaultActiveForegroundColor := StyleSheet colorAt:'buttonActiveForegroundColor'.
    DefaultActiveBackgroundColor := StyleSheet colorAt:'buttonActiveBackgroundColor'.
    DefaultReturnButtonHasImage := StyleSheet at:'buttonReturnButtonHasImage' default:true.
    DefaultReturnButtonHasBorder := StyleSheet at:'buttonReturnButtonHasBorder' default:false.
    DefaultShadowColor := StyleSheet colorAt:'buttonShadowColor'.
    DefaultLightColor := StyleSheet colorAt:'buttonLightColor'.
    DefaultHalfShadowColor := StyleSheet colorAt:'buttonHalfShadowColor'.
    DefaultHalfLightColor := StyleSheet colorAt:'buttonHalfLightColor'.
!

returnFormOn:aDevice
    "return the form used for the return arrow in non-3D;
     cache the one for Display for the next round."

    |f|

    (ReturnForm notNil and:[aDevice == ReturnForm device]) ifTrue:[
	^ ReturnForm
    ].
    f := Form fromFile:'Return.xbm' resolution:100 on:aDevice.
    f isNil ifTrue:[
	f := Form width:24 height:16 fromArray:#[2r00000000 2r00000000 2r00000000
						 2r00000000 2r00000000 2r00000000
						 2r00000000 2r00000000 2r00000000
						 2r00000000 2r00000011 2r11100000
						 2r00000001 2r10000011 2r11100000
						 2r00000011 2r10000011 2r11100000
						 2r00000111 2r11111111 2r11100000
						 2r00001111 2r11111111 2r11100000
						 2r00011111 2r11111111 2r11100000
						 2r00001111 2r11111111 2r11100000
						 2r00000111 2r11111111 2r11100000
						 2r00000011 2r10000000 2r00000000
						 2r00000001 2r10000000 2r00000000
						 2r00000000 2r00000000 2r00000000
						 2r00000000 2r00000000 2r00000000
						 2r00000000 2r00000000 2r00000000]
					      on:aDevice
    ].
    ReturnForm := f.
    ^ f
!

returnShadowFormOn:aDevice
    "return the form used for the return arrow shadow pixels (3D only);
     cache the one for Display for the next round."

    |f|

    (ReturnShadowForm notNil and:[aDevice == ReturnShadowForm device]) ifTrue:[
	^ ReturnShadowForm
    ].
    f := Form fromFile:'ReturnShadow.xbm' resolution:100 on:aDevice.
    f isNil ifTrue:[
	f := Form width:24 height:16 fromArray:#[2r00000000 2r00000000 2r00000000
						 2r00000000 2r00000000 2r00000000
						 2r00000000 2r00000000 2r00000000
						 2r00000000 2r00000011 2r11100000
						 2r00000001 2r10000010 2r00000000
						 2r00000010 2r10000010 2r00000000
						 2r00000100 2r11111110 2r00000000
						 2r00001000 2r00000000 2r00000000
						 2r00010000 2r00000000 2r00000000
						 2r00001000 2r00000000 2r00000000
						 2r00000100 2r00000000 2r00000000
						 2r00000010 2r00000000 2r00000000
						 2r00000001 2r00000000 2r00000000
						 2r00000000 2r00000000 2r00000000
						 2r00000000 2r00000000 2r00000000
						 2r00000000 2r00000000 2r00000000]
					      on:aDevice
    ].
    ReturnShadowForm := f.
    ^ f
!

returnLightFormOn:aDevice
    "return the form used for the return arrow light pixels (3D only);
     cache the one for Display for the next round"

    |f|

    (ReturnLightForm notNil and:[aDevice == ReturnLightForm device]) ifTrue:[
	^ ReturnLightForm
    ].
    f := Form fromFile:'ReturnLight.xbm' resolution:100 on:aDevice.
    f isNil ifTrue:[
	f := Form width:24 height:16 fromArray:#[2r00000000 2r00000000 2r00000000
						 2r00000000 2r00000000 2r00000000
						 2r00000000 2r00000000 2r00000000
						 2r00000000 2r00000000 2r00000000
						 2r00000000 2r00000000 2r00100000
						 2r00000000 2r00000000 2r00100000
						 2r00000000 2r00000000 2r00100000
						 2r00000000 2r00000000 2r00100000
						 2r00000000 2r00000000 2r00100000
						 2r00000000 2r00000000 2r00100000
						 2r00000000 2r11111111 2r11100000
						 2r00000000 2r10000000 2r00000000
						 2r00000000 2r10000000 2r00000000
						 2r00000000 2r00000000 2r00000000
						 2r00000000 2r00000000 2r00000000
						 2r00000000 2r00000000 2r00000000]
					      on:aDevice
    ].
    ReturnLightForm := f.
    ^ f
! !

!Button class methodsFor:'instance creation'!

label:aLabel action:aBlock
    "create and return a new Button with text-label, aString
     and pressAction, aBlock."

    ^ (self label:aLabel) action:aBlock
!

label:aLabel action:aBlock in:aView
    "create and return a new Button with text-label, aString
     and pressAction, aBlock.  Button is placed into aView."

    ^ ((self in:aView) label:aLabel) action:aBlock
!

form:aForm action:aBlock in:aView
    "create and return a new Button with icon-label, aForm
     and pressAction, aBlock.  Button is placed into aView.
     OBSOLETE: this is for backward compatibility; 
     you can now pass an image or form in the #label:action:in: message."

    ^ ((self in:aView) form:aForm) action:aBlock
!

okButton
    "since ok-buttons are very common, here is a convenient
     method to create one ..."

    |aButton|

    aButton := Button label:(self classResources at:'ok').
    aButton cursor:(Cursor thumbsUp).
    aButton isReturnButton:true.
    ^ aButton
!

abortButton
    "since abort-buttons are very common, here is a convenient
     method to create one ..."

    |aButton|

    aButton := Button label:(self classResources at:'abort').
    aButton cursor:(Cursor thumbsDown).
    ^ aButton
!

okButtonIn:aView
    "since ok-buttons are very common, here is a convenient
     method to create one ..."

    |b|

    aView addSubView:(b := self okButton).
    ^ b
!

abortButtonIn:aView
    "since abort-buttons are very common, here is a convenient
     method to create one ..."

    |b|

    aView addSubView:(b := self abortButton). 
    ^ b
!

toggle
    "ST-80 compatibility: create & return a new toggle."

    ^ Toggle new

    "
     Button toggle label:'press me';
		   model:((PluggableAdaptor on:(Point new))
			    getSelector:#x putSelector:#x:)
    "
    "this is the same as"
    "
     Toggle new label:'press me';
		model:((PluggableAdaptor on:(Point new))
			    getSelector:#x putSelector:#x:)
    "
! !

!Button methodsFor:'initialization'!

initialize
    super initialize.

    isReturnButton := false.
!

initStyle
    |hasGreyscales nm|

    super initStyle.

    DefaultFont notNil ifTrue:[font := DefaultFont on:device].
    DefaultBorderWidth notNil ifTrue:[borderWidth := DefaultBorderWidth].
    DefaultForegroundColor notNil ifTrue:[fgColor := DefaultForegroundColor on:device].
    DefaultBackgroundColor notNil ifTrue:[bgColor := DefaultBackgroundColor on:device].

    edgeStyle := DefaultEdgeStyle.
    onLevel := DefaultActiveLevel.
    offLevel := DefaultPassiveLevel.

    DefaultDisabledForegroundColor notNil ifTrue:[
	disabledFgColor := DefaultDisabledForegroundColor on:device
    ] ifFalse:[
	disabledFgColor := fgColor
    ].

    DefaultEnteredForegroundColor notNil ifTrue:[enteredFgColor := DefaultEnteredForegroundColor on:device].
    DefaultEnteredBackgroundColor notNil ifTrue:[enteredBgColor := DefaultEnteredBackgroundColor on:device].
    DefaultActiveForegroundColor notNil ifTrue:[activeFgColor := DefaultActiveForegroundColor on:device].
    DefaultActiveBackgroundColor notNil ifTrue:[activeBgColor := DefaultActiveBackgroundColor on:device].

    DefaultShadowColor notNil ifTrue:[shadowColor := DefaultShadowColor on:device].
    DefaultLightColor notNil ifTrue:[lightColor := DefaultLightColor on:device].

    shadowColor isNil ifTrue:[
	shadowColor := Black.
    ].
    lightColor isNil ifTrue:[
	lightColor := White.
    ].

    hasGreyscales := device hasGreyscales.
    (edgeStyle == #soft) ifTrue:[
	DefaultHalfShadowColor notNil ifTrue:[halfShadowColor := DefaultHalfShadowColor on:device].
	DefaultHalfLightColor notNil ifTrue:[halfLightColor := DefaultHalfLightColor on:device].

	halfShadowColor isNil ifTrue:[
"/            hasGreyscales ifTrue:[
"/                halfShadowColor := Color darkGrey
"/            ] ifFalse:[
"/                halfShadowColor := shadowColor
"/            ]
	    halfShadowColor := shadowColor lightened
	]
    ].

    "
     actually, the stuf below should not be needed
     - the styleSheet should provide values for nonGreyscale displays too
    "
    nm := styleSheet name.
    (nm == #iris) ifTrue:[
	hasGreyscales ifTrue:[
	    DefaultEnteredBackgroundColor isNil ifTrue:[
		enteredBgColor := bgColor lightened "Color lightGrey".
	    ].
	    DefaultActiveBackgroundColor isNil ifTrue:[
		activeBgColor := enteredBgColor.
	    ].
	    DefaultActiveForegroundColor isNil ifTrue:[
		activeFgColor := enteredFgColor.
	    ].
	] ifFalse:[
	    DefaultEnteredBackgroundColor isNil ifTrue:[
		enteredBgColor := Color veryLightGrey.
	    ].
	    DefaultActiveBackgroundColor isNil ifTrue:[
		activeBgColor := Black.
	    ].
	    DefaultActiveForegroundColor isNil ifTrue:[
		activeFgColor := White.
	    ].
	].
    ] ifFalse:[
	nm == #motif ifTrue:[
	    lightColor isNil ifTrue:[
		lightColor := bgColor lightened
	    ].
"/            hasGreyscales ifTrue:[
"/                lightColor := Color lightGrey
"/            ]
	] ifFalse:[
	    nm == #st80 ifTrue:[
		hasGreyscales ifTrue:[
		    DefaultActiveForegroundColor isNil ifTrue:[
			activeFgColor := fgColor.
		    ].
		    DefaultActiveBackgroundColor isNil ifTrue:[
			activeBgColor := bgColor darkened.
		    ].
		] ifFalse:[
		    DefaultActiveForegroundColor isNil ifTrue:[
			activeFgColor := White.
		    ].
		    DefaultActiveBackgroundColor isNil ifTrue:[
			activeBgColor := Black
		    ]
		]
	    ]
	]
    ].

    offLevel ~~ level ifTrue:[
	self level:offLevel.
	margin := (onLevel abs) max:(offLevel abs).
    ].

    DefaultReturnButtonHasImage ifTrue:[
	(styleSheet is3D and:[hasGreyscales]) ifTrue:[
	    shadowForm := self class returnShadowFormOn:device.
	    lightForm := self class returnLightFormOn:device.
	    formColor := viewBackground.
	    formShadowColor := shadowColor.
	    formLightColor := lightColor
	] ifFalse:[
	    shadowForm := self class returnFormOn:device.
	    formColor := Black
	].
    ].
!

initCursor
    "set up a hand cursor"

    cursor := Cursor hand
!

initEvents
    super initEvents.
    self enableEnterLeaveEvents
!

realize
    super realize.

    controller active:false.
    controller entered:false.

    fgColor := fgColor on:device.
    bgColor := bgColor on:device.
    formColor notNil ifTrue:[
	formColor := formColor on:device.
    ].
!

reinitialize
    super reinitialize.
    controller notNil ifTrue:[
	controller active:false.
	controller entered:false.
    ]
!

defaultControllerClass
    ^ ButtonController
! !

!Button methodsFor:'queries'!

is3D
    "return true, if the receiver is a 3D style view"

    styleSheet name == #mswindows ifTrue:[^ true].
    ^ super is3D
!

isReturnButton
    "return true, if this is a return button"

    ^ isReturnButton
!

isOn
    "return true, if this button is currently pressed"

    ^ controller pressed
!

specClass
    self class == Button ifTrue:[^ ActionButtonSpec].
    ^ nil
! !

!Button methodsFor:'accessing-look'!

isReturnButton:aBoolean
    "show/dont show a return-key image after the label"

    isReturnButton ~~ aBoolean ifTrue:[
	DefaultReturnButtonHasBorder ifTrue:[
	    self borderWidth:(aBoolean ifTrue:[1] ifFalse:[0])
	].
	isReturnButton := aBoolean.
	self newLayout
    ]
!

beImageButton
    "make mySelf an image button - that is turn off all levelChanges
     and logo spacing. This should be sent for buttons which use both
     passive and active logos, and the 3D effect comes from the bitmaps
     (i.e. windows buttons)."

    self 
	extent:(labelWidth @ labelHeight);
	sizeFixed:true; 
	borderWidth:0;
	onLevel:0; 
	offLevel:0; 
	horizontalSpace:0; 
	verticalSpace:0;
	newLayout.

    "Created: 17.9.1995 / 20:41:47 / claus"
    "Modified: 19.9.1995 / 16:34:08 / claus"
!

beRoundRadioButton
    "setup myself for a round radioButton look.
     this is a private method; do not use it. It is going to move into the
     RadioButton class."

    self activeLogo:(Icon constantNamed:'RadioOn').
    self passiveLogo:(Icon constantNamed:'RadioOff').
    self activeLevel:0; 
	 passiveLevel:0; 
	 activeBackgroundColor:bgColor;
	 activeForegroundColor:fgColor;
	 borderWidth:0;
	 enteredBackgroundColor:bgColor.
    self computeLabelSize.
    self beImageButton.

    "Created: 22.9.1995 / 15:48:05 / claus"
    "Modified: 22.9.1995 / 17:07:46 / claus"
!

onLevel:aNumber
    "set the level of the button when pressed (i.e. how deep).
     Historic leftover; use #activeLevel:."

    ^ self activeLevel:aNumber
!

onLevel
    "return the level of the button when pressed.
     Historic leftover; use #activeLevel."

    ^ onLevel
!

offLevel:aNumber
    "set the level of the button when released (i.e. how deep).
     Historic leftover; use #passiveLevel:."

    ^ self passiveLevel:aNumber
!

offLevel
    "return the level of the button when released.
     Historic leftover; use #passiveLevel."

    ^ offLevel
!

activeLevel:aNumber
    "set the level of the button when pressed (i.e. how deep)"

    onLevel := aNumber.
    (controller notNil
    and:[controller pressed]) ifTrue:[
	self level:onLevel.
	margin := onLevel abs max:offLevel abs.
	self redraw
    ]
!

activeLevel
    "return the level of the button when pressed"

    ^ onLevel
!

passiveLevel:aNumber
    "set the level of the button when not pressed (i.e. how high)"

    offLevel := aNumber.
    (controller notNil
    and:[controller pressed not]) ifTrue:[
	self level:offLevel.
	margin := onLevel abs max:offLevel abs.
	self redraw
    ]
!

passiveLevel
    "return the level of the button when released"

    ^ offLevel
!

edgeStyle:aSymbol
    "set the edgestyle - currently only #soft or nil"

    edgeStyle := aSymbol
!

activeLogo:anImageOrString
    "define the logo to be displayed while active -
     this is optional; the default is to display the same
     (logo) in both pressed and released states."

    activeLogo := anImageOrString.
    controller pressed ifTrue:[
	self logo:anImageOrString
    ]
!

passiveLogo:anImageOrString
    "define the logo to be displayed while inactive -
     this is optional; the default is to display the same
     (logo) in both pressed and released states."

    passiveLogo := anImageOrString.
    controller pressed ifFalse:[
	self logo:anImageOrString
    ]
!

disabledLogo:anImageOrString
    "define the logo to be displayed while active -
     this is optional; the default is to display the same
     (logo) in both pressed and released states."

    disabledLogo := anImageOrString.
    controller enabled ifFalse:[
	self logo:anImageOrString
    ]

    "Created: 17.9.1995 / 19:50:17 / claus"
    "Modified: 17.9.1995 / 19:50:34 / claus"
!

focusLogo:anImageOrString
    "define the logo to be displayed while active -
     this is optional; the default is to display the same
     (logo) in both pressed and released states."

    focusLogo := anImageOrString.

    "Created: 17.9.1995 / 19:50:17 / claus"
    "Modified: 17.9.1995 / 20:00:43 / claus"
!

activeForegroundColor
    "return the foreground color to be used when pressed"

    ^ activeFgColor
!

activeForegroundColor:aColor
    "set the foreground color to be used when pressed"

    activeFgColor := aColor.
    self redrawIfPressed
!

activeBackgroundColor
    "return the background color to be used when pressed"

    ^ activeBgColor
!

activeBackgroundColor:aColor
    "set the background color to be used when pressed"

    activeBgColor := aColor.
    self redrawIfPressed
!

activeForegroundColor:fgColor backgroundColor:bgColor
    "set both fg and bg colors to be used when pressed"

    activeFgColor := fgColor.
    activeBgColor := bgColor.
    self redrawIfPressed
!

enteredForegroundColor
    "return the foreground color to be used when the mouse
     pointer enters the button area"

    ^ enteredFgColor
!

enteredForegroundColor:aColor
    "set the foreground color to be used when the mouse
     pointer enters the button area"

    enteredFgColor := aColor
!

enteredBackgroundColor
    "return the background color to be used when the mouse
     pointer enters the button area"

    ^ enteredBgColor
!

enteredBackgroundColor:aColor
    "set the background color to be used when the mouse
     pointer enters the button area"

    enteredBgColor := aColor
!

disabledForegroundColor
    "return the foreground color used when the button is disabled"

    ^ disabledFgColor
! !
    
!Button methodsFor:'accessing-behavior'!

pressAction
    "return the pressAction; thats the block which gets evaluated
     when the button is pressed (if non-nil)"

    ^ controller pressAction
!

pressAction:aBlock
    "define the action to be performed on press"

    controller pressAction:aBlock
!

releaseAction
    "return the releaseAction; thats the block which gets evaluated
     when the button is relreased (if non-nil)"

    ^ controller releaseAction
!

releaseAction:aBlock
    "define the action to be performed on release"

    controller releaseAction:aBlock
!

action:aBlock
    "convenient method: depending on the setting of controllers triggerOnDown flag,
     either set the press-action and clear any release-action or
     vice versa, set the release-action and clear the press-action."

    controller action:aBlock
!

autoRepeat
    "turn on autorepeat OBSOLETE"

    controller autoRepeat
!

autoRepeat:aBoolean
    "turn on/off autorepeat"

    controller autoRepeat:aBoolean

    "Modified: 5.9.1995 / 22:06:13 / claus"
!

disable
    "disable the button"

    controller disable.
!

enable
    "enable the button"

    controller enable
!

enableChannel
    "return the valueHolder used for enable/disable"

    ^ controller enableChannel
!

enableChannel:aValueHolderForBoolean
    "set the valueHolder used for enable/disable"

    controller enableChannel:aValueHolderForBoolean
!

pressChannel:aBlock
    "set the pressChannel"

    controller pressChannel:aBlock

    "Modified: 7.9.1995 / 18:05:14 / claus"
!

releaseChannel:aBlock
    "set the releaseChannel"

    controller releaseChannel:aBlock

    "Modified: 7.9.1995 / 18:05:21 / claus"
!

releaseChannel
    "return the releaseChannel"

    ^ controller releaseChannel

    "Modified: 7.9.1995 / 18:15:24 / claus"
!

pressChannel
    "return the pressChannel"

    ^ controller pressChannel

    "Modified: 7.9.1995 / 18:16:20 / claus"
! !

!Button methodsFor:'changing state'!

turnOffWithAction
    "turn the button off (if not already off) and perform any action/change notification"

    controller pressed ifTrue:[
	offLevel ~~ level ifTrue:[
	    self level:offLevel.
	].
	(passiveLogo notNil and:[passiveLogo ~~ logo]) ifTrue:[
	    self logo:passiveLogo
	].
	self turnOffWithoutRedraw.
	self redraw
    ]

    "Created: 15.11.1995 / 16:55:37 / cg"
!

turnOffWithoutRedraw
    "turn the button off - no redraw but perform any action/change notification"

    controller pressed:false.
    controller active:false.

    "do not use super level:offLevel
     - because that one does redraw the edges.
     Sure, this is no good coding style"

    level := offLevel.
    margin := level abs
!

turnOff
    "turn the button off (if not already off) do NOT perform actions/change notifications"

    controller pressed ifTrue:[
	offLevel ~~ level ifTrue:[
	    self level:offLevel.
	].
	(passiveLogo notNil and:[passiveLogo ~~ logo]) ifTrue:[
	    self logo:passiveLogo
	].
	controller setPressed:false.
	controller active:false.
	level := offLevel.
	margin := level abs.
	self redraw
    ]
!

turnOnWithAction
    "turn the button on (if not already on) and perform any change actions/notifications"

    controller pressed ifFalse:[
	onLevel ~~ level ifTrue:[
	    self level:onLevel.
	].
	(activeLogo notNil and:[activeLogo ~~ logo]) ifTrue:[
	    self logo:activeLogo
	].
	self turnOnWithoutRedraw.
	self redraw
    ]

    "Created: 15.11.1995 / 16:55:56 / cg"
!

turnOn
    "turn the button on (if not already on) - do NOT perform any action/notification"

    controller pressed ifFalse:[
	onLevel ~~ level ifTrue:[
	    self level:onLevel.
	].
	(activeLogo notNil and:[activeLogo ~~ logo]) ifTrue:[
	    self logo:activeLogo
	].
	controller setPressed:true.
	level := onLevel.
	margin := level abs.

	self redraw
    ]

    "Created: 14.11.1995 / 22:00:45 / cg"
    "Modified: 14.11.1995 / 22:01:02 / cg"
!

turnOnWithoutRedraw
    "turn the button on - no redraw but perform any change actions/notifications"

    controller pressed:true.

    "do not use super level:offLevel
     - because that one does redraw the edges.
     Sure, this is no good coding style"

    level := onLevel.
    margin := level abs
!

toggleNoAction
    "toggle, but do NOT perform any action - can be used to change a toggle
     under program control (i.e. turn one toggle off from another one)"

    controller toggleNoAction
!

toggle
    "toggle and perform the action"

    controller toggle
! !

!Button methodsFor:'queries'!

preferredExtent
    "return my preferred extent - this is the minimum size I would like to have"

    |extraH extraV|

    logo notNil ifTrue:[
"
	extraH := extraV := (onLevel abs max:offLevel abs) + ViewSpacing * 2.
"
	extraH := extraV := (onLevel abs max:offLevel abs).
	extraH := (extraH + hSpace * 2).
	extraV := (extraV + vSpace * 2).

	self is3D ifFalse:[
	    "add space for a frame around"
	    extraH := extraH + 2. extraV := extraV + 2.
	].
	^ (labelWidth + extraH) @ (labelHeight + extraV)
    ].

    ^ super preferredExtent
! !

!Button methodsFor:'private'!

computeLabelOrigin
    "compute the origin of the text - if  I am a returnButton,
     shift it somwehat to the right (we have already allocated the
     real estate, since computeLabelSize returned some extra space
     before)."

    super computeLabelOrigin.
    (isReturnButton and:[shadowForm notNil]) ifTrue:[
	labelOriginX := labelOriginX + hSpace + hSpace.
    ]
!

computeLabelSize
    "compute the extent needed to hold the label plus the return form"

    super computeLabelSize.
    (isReturnButton and:[shadowForm notNil]) ifTrue:[
	labelWidth := labelWidth + (hSpace * 2) + shadowForm width.
	labelHeight := labelHeight max: (shadowForm height + vSpace)
    ]
!

XXresize
    "resize myself to make logo fit into myself.
     Redefined, since we add space for a frame around text when non-3D"

    |extra|

    logo isNil ifFalse:[
	self computeLabelOrigin.
	(relativeExtent isNil and:[extentRule isNil]) ifTrue:[
	    extra := (onLevel abs max:offLevel abs) * 2.
	    styleSheet is3D ifFalse:[
"/                (logo isKindOf:Form) ifFalse:[
		    "add space for a rectangle around"
		    extra := extra + 2
"/                ]
	    ].
	    self extent:(labelWidth + extra) @ (labelHeight + extra)
	]
    ]
! !

!Button methodsFor:'focus change'!

showFocus
    focusLogo notNil ifTrue:[
	controller enabled ifTrue:[
	    logo := focusLogo.  
	    ^ self redisplay
	]
    ].
    super showFocus

    "Created: 17.9.1995 / 19:58:50 / claus"
!

showNoFocus
    focusLogo notNil ifTrue:[
	disabledLogo notNil ifTrue:[
	    controller enabled ifTrue:[
		logo := passiveLogo.  
	    ] ifFalse:[
		logo := disabledLogo.  
	    ].
	] ifFalse:[
	    logo := passiveLogo
	].
	^ self redisplay
    ].
    super showNoFocus

    "Created: 17.9.1995 / 20:00:06 / claus"
    "Modified: 17.9.1995 / 20:26:32 / claus"
! !

!Button methodsFor:'redrawing'!

redrawX:x y:y width:w height:h 
    self redisplay.
!

drawEdges
    "draw all of my 3D edges"

    self drawEdgesForX:0 y:0 width:width height:height level:level 
		shadow:shadowColor 
		light:lightColor
		halfShadow:halfShadowColor 
		halfLight:halfLightColor
		style:edgeStyle 
!

drawLeftEdge
    "draw left 3D edge into window frame"

    self drawLeftEdgeLevel:level
		    shadow:shadowColor 
		     light:lightColor
		     halfShadow:halfShadowColor 
		     halfLight:halfLightColor
		     style:edgeStyle.
!

drawRightEdge
    "draw right 3D edge into window frame"

    self drawRightEdgeLevel:level
		     shadow:shadowColor 
		      light:lightColor
		      halfShadow:halfShadowColor 
		      halfLight:halfLightColor
		      style:edgeStyle.
!

drawTopEdge
    "draw top 3D edge into window frame"

    self drawTopEdgeLevel:level
		   shadow:shadowColor 
		   light:lightColor
		   halfShadow:halfShadowColor 
		   halfLight:halfLightColor
		   style:edgeStyle.
!

drawBottomEdge
    "draw bottom 3D edge into window frame"

    self drawBottomEdgeLevel:level
		      shadow:shadowColor 
		      light:lightColor
		      halfShadow:halfShadowColor 
		      halfLight:halfLightColor
		      style:edgeStyle.
!

drawWith:fg and:bg
    "redraw myself with fg/bg. Use super to draw the label, add
     the return-arrow here."

    |x y sColor lColor|

    shown ifFalse:[^ self].
    super drawWith:fg and:bg.   "this draws the text"

    (isReturnButton and:[shadowForm notNil]) ifTrue:[
	y := (height - shadowForm height) // 2.
	x := width - shadowForm width - (hSpace // 2).

	formShadowColor isNil ifTrue:[
	    self paint:fg on:bg.
"/            self background:bg.
	    self displayOpaqueForm:shadowForm x:x y:y.
	    ^ self
	].

	"
	 drawing form in 3d-style (i.e. with shadow and light)
	"
	(formShadowColor isColor and:[formShadowColor colorId notNil
	 and:[formLightColor isColor and:[formLightColor colorId notNil
	 and:[formColor isColor and:[formColor colorId notNil]]]]])
	ifTrue:[
	    sColor := formShadowColor.
	    lColor := formLightColor.
	] ifFalse:[
	    sColor := Black.
	    lColor := White.
	].
	self foreground:sColor.
	self displayForm:shadowForm x:x y:y.

	lightForm notNil ifTrue:[
	    self foreground:lColor.
	    self displayForm:lightForm x:x y:y.
	].
	self paint:fg.
    ]
!

showPassive
    "redraw myself as passive"

    offLevel ~~ level ifTrue:[
	self level:offLevel.
    ].
    (passiveLogo notNil and:[passiveLogo ~~ logo]) ifTrue:[
	self logo:passiveLogo
    ].
    self redraw.
!

showActive
    "redraw myself as active (i.e. busy)"

    onLevel ~~ level ifTrue:[
	self level:onLevel.
    ].
    (activeLogo notNil and:[activeLogo ~~ logo]) ifTrue:[
	self logo:activeLogo
    ].
    self redraw.
!

redrawIfPressed
    "redraw the button, but only if visible and currently being pressed"

    shown ifTrue:[
	controller pressed ifTrue:[
	    self redisplay
	]
    ]
!

redraw
    "redraw the button. but not if currently active"

    shown ifFalse:[^ self].
"/    controller active ifTrue:[^ self].  - disabled; otherwise, we do not redreaw if changed from within action procedure
    self redisplay.
!

redisplay
    "redraw the button. 
     Thats like redrawing a label, but use different colors when pressed
     or entered."

    |fg bg entered|

    shown ifFalse:[^ self].

    fg := fgColor.
    bg := bgColor.
    controller enabled ifFalse:[
	fg := disabledFgColor
    ] ifTrue:[
	entered := controller entered.
	entered ifTrue:[
	    enteredFgColor notNil ifTrue:[fg := enteredFgColor].
	    enteredBgColor notNil ifTrue:[bg := enteredBgColor]
	].
	(controller pressed and:[entered or:[controller isTriggerOnDown]]) ifTrue:[
	    activeFgColor isNil ifTrue:[
		onLevel == offLevel ifTrue:[
		    fg := bgColor
		]
	    ] ifFalse:[
		fg := activeFgColor.
	    ].
	    activeBgColor isNil ifTrue:[
		onLevel == offLevel ifTrue:[
		    bg := fgColor
		]
	    ] ifFalse:[
		bg := activeBgColor
	    ].
	    self is3D ifFalse:[
		self drawWith:fg and:bg .
		"
		 draw a rectangle around
		"
		self paint:fg.
		self displayRectangleX:0 y:0 width:width height:height.

		^ self
	    ].
	].
    ].
    self drawWith:fg and:bg
!

enableStateChangeRedraw
    "redraw the button after an enable state change"

    disabledLogo notNil ifTrue:[
	controller enabled ifFalse:[
	    logo := disabledLogo.
	] ifTrue:[
	    controller active ifTrue:[
		logo := activeLogo
	    ] ifFalse:[
		logo := passiveLogo
	    ].
	].
    ].
    shown ifFalse:[^ self].
    self redisplay.

    "Created: 17.9.1995 / 19:46:14 / claus"
    "Modified: 17.9.1995 / 19:56:24 / claus"
! !