SteppingSlider.st
author claus
Sun, 23 Jul 1995 05:13:10 +0200
changeset 65 40e27e2606b5
parent 57 126745871373
child 71 9f9243f5813b
permissions -rw-r--r--
.

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

'From Smalltalk/X, Version:2.10.3 on 27-sep-1994 at 12:56:30'!

ScrollBar subclass:#SteppingSlider
	 instanceVariableNames:'stepIncrement'
	 classVariableNames:''
	 poolDictionaries:''
	 category:'Views-Interactors'
!

SteppingSlider comment:'
COPYRIGHT (c) 1994 by Claus Gittinger
	      All Rights Reserved

$Header: /cvs/stx/stx/libwidg2/SteppingSlider.st,v 1.4 1995-07-23 03:12:59 claus Exp $
'!

!SteppingSlider class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1994 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/libwidg2/SteppingSlider.st,v 1.4 1995-07-23 03:12:59 claus Exp $
"
!

documentation
"
    SteppingSliders are like Sliders, but add step-up and step-down
    buttons (which increment/decrement the value).
    (you can also think of them as a ScrollBar with a slider instead of
     a scroller as component)
"
!

examples 
"
    non model operation:

      |top sl|

      top := StandardSystemView extent:200@200.
      sl := SteppingSlider in:top.
      sl origin:(0.0@0.0) corner:(sl width@1.0).
      sl scrollAction:[:pos | Transcript showCr:pos].    
      top open


    change the step:

      |top sl|

      top := StandardSystemView extent:200@200.
      sl := SteppingSlider in:top.
      sl origin:(0.0@0.0) corner:(sl width@1.0).
      sl scrollAction:[:pos | Transcript showCr:pos].    
      sl stepIncrement:10.
      top open


    model operation (look at value in model):

      |model top sl fld|

      model := 0 asValue.

      top := StandardSystemView extent:200@200.
      top label:'slider on model'.
      sl := SteppingSlider in:top.
      sl origin:(0.0@0.0) corner:(sl width@1.0).
      sl model:model.
      top open.

      top := StandardSystemView extent:200@200.
      top label:'inputField on model'.
      fld := EditField in:top.
      fld origin:(0.0@0.0) corner:(1.0 @ fld height).
      fld model:model; converter:(PrintConverter new initForNumber).
      top open
"
! !

!SteppingSlider methodsFor:'initialization'!

createElements
    button1 := ArrowButton upIn:self.
    button1 name:'UpButton'.
    button2 := ArrowButton downIn:self.
    button2 name:'DownButton'.
    thumb := Slider in:self.
!

initialize
    super initialize.
    stepIncrement := 1.
    self scrollDownAction:[self scrollStepUp].
    self scrollUpAction:[self scrollStepDown].
! !

!SteppingSlider methodsFor:'accessing'!

model:aModel
    thumb model:aModel
!

stepIncrement:aNumber 
    "set the value used for stepping (defaults to 1)"

    stepIncrement := aNumber
!

step:aNumber
    "same as stepIncrement;
     set the value used for stepping (defaults to 1)"

    stepIncrement := aNumber
!

step
    ^ stepIncrement
!

start:start stop:stop step:step
    thumb start:start stop:stop.
    stepIncrement := step
! !

!SteppingSlider methodsFor:'events'!

keyPress:key x:x y:y
    key == #CursorRight ifTrue:[
	self scrollStepUp.
	^ self
    ].
    key == #CursorLeft ifTrue:[
	self scrollStepDown.
	^ self
    ].
    super keyPress:key x:x y:y
! !

!SteppingSlider methodsFor:'private'!

scrollStepUp
    |nO|

    nO := (thumb thumbOrigin + stepIncrement) min:thumb stop.         
    thumb thumbOrigin:nO.
    thumb tellOthers.
!

scrollStepDown
    |nO|

    nO := (thumb thumbOrigin - stepIncrement) max:thumb start.
    thumb thumbOrigin:nO.
    thumb tellOthers.
! !

!SteppingSlider methodsFor:'misc'!

doesNotUnderstand:aMessage
    ^ aMessage sendTo:thumb 
! !