Button.st
author claus
Wed, 24 Aug 1994 01:38:59 +0200
changeset 51 e895ac4cc7c8
parent 42 2904f8679ede
child 59 450ce95a72a4
permissions -rw-r--r--
support non-string entries

"
 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:'pressActionBlock releaseActionBlock
                              enabled pressed active entered
                              autoRepeat repeatBlock
                              onLevel offLevel
                              initialDelay repeatDelay
                              disabledFgColor
                              activeFgColor activeBgColor
                              enteredFgColor enteredBgColor
                              isReturnButton
                              shadowForm lightForm
                              formColor formShadowColor formLightColor'
       classVariableNames:'ReturnForm ReturnLightForm ReturnShadowForm'
       poolDictionaries:''
       category:'Views-Interactors'
!

Button comment:'
COPYRIGHT (c) 1989 by Claus Gittinger
              All Rights Reserved

$Header: /cvs/stx/stx/libwidg/Button.st,v 1.9 1994-08-11 23:46:08 claus Exp $
'!

!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.9 1994-08-11 23:46:08 claus Exp $
"
!

documentation
"
    Buttons are Labels which do something when pressed/released.

    Instance variables:

      pressActionBlock        <Block>         block to evaluate when pressed (default: noop)
      releaseActionBlock      <Block>         block to evaluate when released (default: noop)
      enabled                 <Boolean>       pressing is allowed (default: true)
      active                  <Boolean>       true during action evaluation (internal)
      pressed                 <Boolean>       true if currently pressed (read-only)
      entered                 <Boolean>       true if the cursor is currently in this view
      autoRepeat              <Boolean>       auto-repeats when pressed long enough (default: false)
      repeatBlock             <Block>         block evaluated for auto-repeat (internal)
      onLevel                 <Integer>       level when pressed (3D only) (default: depends on style)
      offLevel                <Integer>       level when released (3D only) (default: depends on style)
      initialDelay            <Number>        seconds till first auto-repeat (default: 0.2)
      repeatDelay             <Number>        seconds of repeat intervall (default: 0.025)
      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 (default: false)
      shadowForm              <Form>          form to display in addition to buttons label
      lightForm               <Form>          light part of shadowForm

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


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

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

    see doc/coding-examples for more variations.
"
! !

!Button class methodsFor:'defaults'!

defaultInitialDelay
    "when autorepeat is enabled, and button is not released,
     start repeating after initialDelay seconds"

    ^ 0.2
!

defaultRepeatDelay
    "when autorepeat is enabled, and button is not released,
     repeat every repeatDelay seconds"

    ^ 0.025
!

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 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."

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

!Button methodsFor:'initialization'!

initialize
    super initialize.

    enabled := true.
    active := false.
    pressed := false.
    entered := false.
    autoRepeat := false.
    initialDelay := self class defaultInitialDelay.
    repeatDelay := self class defaultRepeatDelay.
    isReturnButton := false.

"/    self initStyle
!

initStyle
    |hasGreyscales|

    super initStyle.

    onLevel := -1.
    offLevel := 1.
    softEdge := false.

    disabledFgColor := Color grey.
    enteredFgColor := fgColor.
    enteredBgColor := bgColor.
    activeFgColor := activeBgColor := nil.
    enteredFgColor := enteredBgColor := nil.
    halfShadowColor := shadowColor := nil.

    shadowColor := Black.

    hasGreyscales := device hasGreyscales.

    (style == #next) ifTrue:[
        softEdge := true.
        onLevel := 1.
        offLevel := 2.
        hasGreyscales ifTrue:[
            activeFgColor := Black.
            activeBgColor := White.
            enteredFgColor := fgColor.
            enteredBgColor := Color lightGrey.
            halfShadowColor := Color darkGrey.
        ]
    ] ifFalse:[
        (style == #openwin) ifTrue:[
            hasGreyscales ifTrue:[
                activeFgColor := Black.
                activeBgColor := Color grey
            ]
        ] ifFalse:[
            (style == #mswindows) ifTrue:[
                disabledFgColor := Color darkGrey.
                hasGreyscales ifTrue:[
                    offLevel := 3.
                    onLevel := -1.
                    softEdge := true.
                    fgColor := Black.
                    bgColor := Color lightGrey "Grey".
                    halfShadowColor := Color darkGrey.
                    activeFgColor := fgColor.
                    activeBgColor := bgColor
                ]
            ] ifFalse:[
                (style == #iris) ifTrue:[
                    offLevel := 3.
                    onLevel := -1.
                    softEdge := true.
                    halfShadowColor := Color darkGrey.
                    disabledFgColor := Color darkGrey.
                    enteredFgColor := fgColor.
                    hasGreyscales ifTrue:[
                        enteredBgColor := bgColor lightened "Color lightGrey".
                        activeBgColor := enteredBgColor.
                        activeFgColor := enteredFgColor.
                    ] ifFalse:[
                        enteredBgColor := Color veryLightGrey.
                        activeBgColor := Black.
                        activeFgColor := White.
                    ].
                ] ifFalse:[
                    style == #motif ifTrue:[
                        offLevel := 2.
                        onLevel := -2.
                        hasGreyscales ifTrue:[
                            activeFgColor := fgColor.
                            activeBgColor := bgColor.
                            lightColor := Color lightGrey
                        ]
                    ] ifFalse:[
                        style == #st80 ifTrue:[
                            hasGreyscales ifTrue:[
                                activeFgColor := fgColor.
                                activeBgColor := bgColor darkened.
                            ] ifFalse:[
                                activeFgColor := White.
                                activeBgColor := Black
                            ]
                        ] ifFalse:[
                            device hasColors ifTrue:[
                                activeFgColor := Color red:100 green:100 blue:0 "yellow"
                            ] ifFalse:[
                                activeFgColor := White
                            ].
                            hasGreyscales ifTrue:[
                                activeBgColor := bgColor
                            ] ifFalse:[
                                activeBgColor := Black
                            ]
                        ]
                    ]
                ]
            ]
        ]
    ].

    "default for mono-displays and non-3D"
    activeFgColor isNil ifTrue:[
        activeFgColor := bgColor.
        activeBgColor := fgColor
    ].
"/    enteredFgColor isNil ifTrue:[
"/        enteredFgColor := fgColor.
"/    ].
"/    enteredBgColor isNil ifTrue:[
"/        enteredBgColor := bgColor.
"/    ].

    self level:offLevel.
    margin := (onLevel abs) max:(offLevel abs).

    ((style ~~ #normal) 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 enableButtonEvents.
    self enableEnterLeaveEvents
!

realize
    super realize.
    active := false.
    entered := false.

    fgColor := fgColor on:device.
    bgColor := bgColor on:device.
    activeFgColor notNil ifTrue:[
        activeFgColor := activeFgColor on:device.
    ].
    activeBgColor notNil ifTrue:[
        activeBgColor := activeBgColor on:device.
    ].
    enteredFgColor notNil ifTrue:[
        enteredFgColor := enteredFgColor on:device.
    ].
    enteredBgColor notNil ifTrue:[
        enteredBgColor := enteredBgColor on:device.
    ].
    formColor notNil ifTrue:[
        formColor := formColor on:device.
    ].
!

reinitialize
    super reinitialize.
    active := false
! !

!Button methodsFor:'accessing'!

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

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

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

    ^ isReturnButton
!

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

    isReturnButton ~~ aBoolean ifTrue:[
        ((style == #mswindows) or:[style == #motif]) ifTrue:[
            self borderWidth:(aBoolean ifTrue:[1] ifFalse:[0])
        ].
        isReturnButton := aBoolean.
        self newLayout
    ]
!
    
disable
    "disable the button"

    enabled ifTrue:[
        enabled := false.
        self redraw
    ]
!

enable
    "enable the button"

    enabled ifFalse:[
        enabled := true.
        self redraw
    ]
!

turnOffWithoutRedraw
    "turn the button off - no redraw"

    pressed := false.
    active := false.
    (style ~~ #normal) ifTrue:[
        "do not use super level:offLevel
         - that one redraws the edges.
         Sure, this is no good coding style"
        level := offLevel.
        margin := level abs
    ]
!

turnOff
    "turn the button off (if not already off)"

    pressed ifTrue:[
        active := false.
        pressed := false.
        self level:offLevel.
        self redraw
    ]
!

turnOn
    "turn the button on (if not already on)"

    pressed ifFalse:[
        pressed := true.
        self level:onLevel.
        self redraw
    ]
!

pressAction
    ^ pressActionBlock
!

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

    pressActionBlock := aBlock
!

releaseAction
    ^ releaseActionBlock
!

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

    releaseActionBlock := aBlock
!

action:aBlock
    "convenient method: define the press-action clear any release-action"

    releaseActionBlock := nil.
    pressActionBlock := aBlock
!

autoRepeat
    "turn on autorepeat"

    autoRepeat := true.
    repeatBlock := [self repeat]
!

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

    ^ pressed
!

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

    onLevel := aNumber.
    pressed ifTrue:[
        self level:onLevel.
        margin := onLevel abs max:offLevel abs.
        self redraw
    ]
!

onLevel
    "return the level of the button when pressed"

    ^ onLevel
!

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

    offLevel := aNumber.
    pressed ifFalse:[
        self level:offLevel.
        margin := onLevel abs max:offLevel abs.
        self redraw
    ]
!

offLevel
    "return the level of the button when released"

    ^ offLevel
!

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

    ^ activeFgColor
!

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

    activeFgColor := aColor.
    pressed ifTrue:[
        self redraw
    ]
!

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

    ^ activeBgColor
!

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

    activeBgColor := aColor.
    pressed ifTrue:[
        self redraw
    ]
!

activeForegroundColor:fgColor backgroundColor:bgColor
    "set the colors to be used when pressed"

    activeFgColor := fgColor.
    activeBgColor := bgColor.
    pressed ifTrue:[
        self redraw
    ]
!

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
! !

!Button methodsFor:'queries'!

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

    |extra|

    logo notNil ifTrue:[
        extra := (onLevel abs max:offLevel abs) * 2.
        style == #normal ifTrue:[
            (logo isKindOf:Form) ifFalse:[
                "add space for a frame around"
                extra := extra + 2
            ]
        ].
        ^ (labelWidth + extra) @ (labelHeight + extra)
    ].

    ^ super preferredExtent
! !

!Button methodsFor:'private'!

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

    super computeLabelSize.
    (isReturnButton and:[style ~~ #mswindows]) ifTrue:[
        labelWidth := labelWidth + hSpace + shadowForm width.
        labelHeight := labelHeight max: (shadowForm height + vSpace)
    ]
!

resize
    "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.
            style == #normal ifTrue:[
                (logo isKindOf:Form) ifFalse:[
                    "add space for a frame around"
                    extra := extra + 2
                ]
            ].
            self extent:(labelWidth + extra) @ (labelHeight + extra)
        ]
    ]
! !

!Button methodsFor:'redrawing'!

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

    |x y sColor lColor|

    super drawWith:fg and:bg.   "this draws the text"

    (isReturnButton and:[style ~~ #mswindows]) ifTrue:[
        y := (height - shadowForm height) // 2.
        x := width - shadowForm width - (hSpace // 2).

        formShadowColor isNil ifTrue:[ "self is3D ifFalse:[      "
            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.
        ].
        shadowForm notNil ifTrue:[
            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 on:bg.
        self function:#copy.
        "/ self foreground:fg background:bg function:#copy
    ]
!

redraw
    "like redrawing a label, but hilight when pressed
     (lolight when disabled)"

    |fg bg|

" OLD:
    shown ifTrue:[
        fg := fgColor.
        bg := bgColor.
        active ifFalse:[
            (style ~~ #normal) ifTrue:[
                enabled ifFalse:[
                    fg := disabledFgColor
                ] ifTrue:[
                    pressed ifTrue:[
                        fg := activeFgColor.
                        bg := activeBgColor
                    ]
                ].
                self drawWith:fg and:bg
            ] ifFalse:[
                enabled ifFalse:[
                    fg := disabledFgColor.
                    self drawWith:fg and:bg
                ] ifTrue:[
                    pressed ifTrue:[
                        self drawWith:bgColor and:fgColor.
                        (logo isKindOf:Form) ifFalse:[
                            self paint:bg.
                            self displayRectangleX:0 y:0 width:width height:height
                        ]
                    ] ifFalse:[     
                        super redraw
                    ]
                ]
            ]
        ]
    ]
"

    shown ifTrue:[
        active ifFalse:[
            fg := fgColor.
            bg := bgColor.
            enabled ifFalse:[
                fg := disabledFgColor
            ] ifTrue:[
                entered ifTrue:[
                    enteredFgColor notNil ifTrue:[fg := enteredFgColor].
                    enteredBgColor notNil ifTrue:[bg := enteredBgColor]
                ].
                pressed ifTrue:[
                    (style == #normal) ifTrue:[
                        self drawWith:bgColor and:fgColor.
                        (logo isKindOf:Form) ifFalse:[
                            self paint:bg.
                            self displayRectangleX:0 y:0 width:width height:height
                        ].
                        ^ self
                    ].
                    fg := activeFgColor.
                    bg := activeBgColor
                ].
            ].
            self drawWith:fg and:bg
        ]
    ]
! !

!Button methodsFor:'event handling'!

buttonPress:button x:x y:y
    "button was pressed - if enabled, perform pressaction"

    (button == 1 or:[button == #select]) ifFalse:[
        ^ super buttonPress:button x:x y:y
    ].
    pressed ifFalse:[
        enabled ifTrue:[
            pressed := true.
            self level:onLevel.
            self redraw.
            active := true.

            "
             force output - so that button is draw correctly in case
             of any long-computation (at high priority)
            "
            device synchronizeOutput.
            pressActionBlock notNil ifTrue:[
                pressActionBlock value
            ].

            "the ST-80 way of doing things"
            (model notNil and:[changeSymbol notNil]) ifTrue:[
                model perform:changeSymbol
            ].
            active := false.
"/            device synchronizeOutput.

            autoRepeat ifTrue:[
                Processor addTimedBlock:repeatBlock afterSeconds:initialDelay
            ]
        ]
    ]
!

buttonMultiPress:button x:x y:y
    ^ self buttonPress:button x:x y:y
!

buttonRelease:button x:x y:y
    "button was released - if enabled, perform releaseaction"

    (button == 1 or:[button == #select]) ifFalse:[
        ^ super buttonRelease:button x:x y:y
    ].
    pressed ifTrue:[
        autoRepeat ifTrue:[
            Processor removeTimedBlock:repeatBlock
        ].
        pressed := false.
        self level:offLevel.
        self redraw.
        enabled ifTrue:[
            active := true.
            releaseActionBlock notNil ifTrue:[device synchronizeOutput.
                                              releaseActionBlock value].
            active := false.
            enteredFgColor notNil ifTrue:[
                self drawWith:enteredFgColor and:enteredBgColor
            ]
        ]
    ]
!

pointerLeave:state
    "redraw with normal colors if they differ from enteredColors"

    pressed ifTrue:[
        "
         leave with mouse-button down;
         stop autorepeating
        "
        autoRepeat ifTrue:[
            Processor removeTimedBlock:repeatBlock
        ]
    ] ifFalse:[
        enabled ifTrue:[
            entered := false.
            ((enteredFgColor notNil and:[enteredFgColor ~~ fgColor])
            or:[enteredBgColor notNil and:[enteredBgColor ~~ bgColor]]) ifTrue:[
"/                self drawWith:fgColor and:bgColor
                self redraw
            ]
        ]
    ]
!

pointerEnter:state x:x y:y
    "redraw with enteredColors if they differ from the normal colors"

    pressed ifTrue:[
        "
         reentered after a leave with mouse-button down;
         restart autorepeating
        "
        enabled ifTrue:[
            autoRepeat ifTrue:[
                Processor addTimedBlock:repeatBlock afterSeconds:initialDelay
            ]
        ]
    ] ifFalse:[
        enabled ifTrue:[
            entered := true.
            ((enteredFgColor notNil and:[enteredFgColor ~~ fgColor])
            or:[enteredBgColor notNil and:[enteredBgColor ~~ bgColor]]) ifTrue:[
"/                self drawWith:enteredFgColor and:enteredBgColor
                self redraw
            ]
        ]
    ]
!

repeat
    "this is sent from the autorepeat-block, when the button has been pressed long
     enough; it simulates a release-press, thereby retriggering action."

    pressed ifTrue:[
        enabled ifTrue:[
            active ifFalse:[
                active := true.
                releaseActionBlock notNil ifTrue:[releaseActionBlock value].
                pressActionBlock notNil ifTrue:[pressActionBlock value].
                active := false.
"/                device synchronizeOutput.

                autoRepeat ifTrue:[
                    Processor addTimedBlock:repeatBlock afterSeconds:repeatDelay
                ]
            ]
        ]
    ]
! !