HScroller.st
author claus
Thu, 13 Jan 1994 01:18:51 +0100
changeset 24 966098a893f8
parent 5 7b4fb1b170e5
child 38 4b9b70b2cc87
permissions -rw-r--r--
*** empty log message ***

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

Scroller subclass:#HorizontalScroller
       instanceVariableNames:''
       classVariableNames:''
       poolDictionaries:''
       category:'Views-Interactors'
!

HorizontalScroller comment:'

COPYRIGHT (c) 1989 by Claus Gittinger
              All Rights Reserved

the scroller part of a horizontal scrollbar

$Header: /cvs/stx/stx/libwidg/Attic/HScroller.st,v 1.4 1994-01-13 00:16:13 claus Exp $
written spring/summer 89 by claus
'!

!HorizontalScroller methodsFor:'initialization'!

initialize
    super initialize.
    moveDirection := #x
! !

!HorizontalScroller methodsFor:'accessing'!

thumbOrigin:newOrigin
    "set the thumbs origin (in percent)"

    |realNewOrigin oldFrame oldLeft oldRight thumbLeft thumbRight
     tH tW delta top|

    ((newOrigin + thumbHeight) > 100) ifTrue:[
        realNewOrigin := 100 - thumbHeight
    ] ifFalse: [
        realNewOrigin := newOrigin
    ].
    (realNewOrigin > 100) ifTrue:[
        realNewOrigin := 100
    ] ifFalse: [
        (realNewOrigin < 0) ifTrue:[
            realNewOrigin := 0
        ]
    ].
    (realNewOrigin = thumbOrigin) ifFalse:[
        oldFrame := thumbFrame.
        thumbOrigin := realNewOrigin.
        self computeThumbFrame.
        (thumbHeight = 100) ifTrue:[^ self].

        shown ifTrue:[
            (thumbFrame ~~ oldFrame) ifTrue:[
                tH := thumbFrame height.
                tW := thumbFrame width.
                oldLeft := oldFrame left.
                oldRight := oldLeft + tW.

                thumbLeft := thumbFrame left.
                thumbRight := thumbLeft + tW.

                top := thumbFrame top.

                (oldRight >= width) ifTrue:[
                    "cannot copy - thumb was behind end"
                    self drawThumbBackgroundInX:oldLeft y:top
                                          width:(width - oldLeft" - 1") height:tH.
                    self drawThumb.
                    ^ self
                ].

                self copyFrom:self x:oldLeft y:top
                                 toX:thumbLeft y:top
                               width:tW height:tH.

                self catchExpose.

                oldLeft > thumbLeft ifTrue:[
                    delta := oldLeft - thumbLeft.
                    oldLeft > thumbRight ifTrue:[
                        self drawThumbBackgroundInX:oldLeft y:top
                                              width:(tW + 1) height:tH
                    ] ifFalse:[
                        self drawThumbBackgroundInX:thumbRight y:top
                                              width:delta height:tH
                    ]
                ] ifFalse:[
                    delta := thumbLeft - oldLeft.
                    oldRight < thumbLeft ifTrue:[
                        self drawThumbBackgroundInX:oldLeft y:top
                                              width:tW + 1 height:tH
                    ] ifFalse:[
                        self drawThumbBackgroundInX:oldLeft y:top 
                                              width:delta height:tH
                    ]
                ].
                self waitForExpose
            ]
        ]
    ]
!

setThumbFor:aView
    "get contents and size info from aView and adjust thumb"

    |percentHeight percentOrigin totalWidth|

    aView isNil ifTrue:[
        totalWidth := 0
    ] ifFalse:[
        totalWidth := aView widthOfContents
    ].
    (totalWidth = 0) ifTrue:[
        percentHeight := 100.
        percentOrigin := 100
    ] ifFalse:[
        percentHeight := (aView innerWidth) * 100 // totalWidth.
        percentOrigin := (aView xOriginOfContents) * 100 // totalWidth
    ].
    (percentHeight = thumbHeight) ifTrue:[
        self thumbOrigin:percentOrigin
    ] ifFalse:[
        (percentOrigin = thumbOrigin) ifTrue:[
            self thumbHeight:percentHeight
        ] ifFalse:[
            self thumbOrigin:percentOrigin thumbHeight:percentHeight
        ]
    ]
!

setThumbHeightFor:aView
    "get contents and size info from aView and adjust thumb height"

    |percent totalWidth|

    totalWidth := aView widthOfContents.
    (totalWidth = 0) ifTrue:[
        percent := 100
    ] ifFalse:[
        percent := (aView innerWidth) * 100 // totalWidth
    ].
    self thumbHeight:percent
!

setThumbOriginFor:aView
    "get contents and size info from aView and adjust thumb origin"

    |percent totalWidth|

    totalWidth := aView widthOfContents.
    (totalWidth = 0) ifTrue:[
        percent := 100
    ] ifFalse:[
        percent := (aView xOriginOfContents) * 100 // totalWidth
    ].
    self thumbOrigin:percent
! !