HVScrollableView.st
author claus
Sat, 08 Jan 1994 18:27:56 +0100
changeset 21 9ef599238fea
parent 7 15a9291b9bd0
child 38 4b9b70b2cc87
permissions -rw-r--r--
*** empty log message ***

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

ScrollableView subclass:#HVScrollableView
       instanceVariableNames:'hScrollBar'
       classVariableNames:''
       poolDictionaries:''
       category:'Views-Basic'
!

HVScrollableView comment:'

COPYRIGHT (c) 1991 by Claus Gittinger
              All Rights Reserved

a view containing both horizontal and vertical scrollbars
and some other (slave-)view

$Header: /cvs/stx/stx/libwidg/HVScrollableView.st,v 1.5 1994-01-08 17:27:21 claus Exp $
written jan 91 by claus
'!

!HVScrollableView methodsFor:'initialization'!

initializeFor:aViewClass
    |negativeOffset halfMargin|

    hScrollBar := HorizontalScrollBar in:self.

    super initializeFor:aViewClass.

    negativeOffset := borderWidth negated.
    halfMargin := innerMargin // 2.

    "change vertical scrollbars size"

    self is3D ifTrue:[
        scrollBar extent:[scrollBar width
                          @
                          (height - hScrollBar height - innerMargin)
                         ]
    ] ifFalse:[
"
        aViewClass isNil ifTrue:[
"
            scrollBar extent:[scrollBar width
                              @
                              (height - hScrollBar height
                                      - (1 * hScrollBar borderWidth))
                             ]
"
        ] ifFalse:[
            scrollBar extent:[scrollBar width
                              @
                              (height - hScrollBar height
                                      - hScrollBar borderWidth
                                      - scrolledView borderWidth)
                             ]
        ]
"
    ].

    hScrollBar thumbOrigin:0 thumbHeight:100.
    self is3D ifTrue:[
        hScrollBar origin:[(scrollBar origin x + scrollBar width + innerMargin)
                           @
                           (height - hScrollBar height - halfMargin)
                          ]
                   extent:[(width - scrollBar width - (innerMargin * 2))
                           @
                           hScrollBar height
                          ]
    ] ifFalse:[
        hScrollBar origin:[(scrollBar origin x + scrollBar width + scrollBar borderWidth)
                           @
                           (height - hScrollBar height - (hScrollBar borderWidth "* 2"))
                          ]
                   extent:[(width - scrollBar width) @ hScrollBar height
                          ]
    ].

    "redefine subviews size"
    self is3D ifTrue:[
        helpView extent:[(width - scrollBar width - (innerMargin * 2))
                         @
                         (height - hScrollBar height - (innerMargin * 2))
                        ]
    ] ifFalse:[
        scrolledView notNil ifTrue:[
            scrolledView
                extent:[(width
                         - scrollBar width
                         - scrollBar borderWidth
                         "- scrolledView borderWidth") 
                        @ 
                        (height
                         - hScrollBar height
                         - hScrollBar borderWidth
                         "- scrolledView borderWidth")
                       ]
        ].
    ].

    scrolledView notNil ifTrue:[
        self setScrollActions
    ]
!

realize
    super realize.
    hScrollBar setThumbFor:scrolledView
! !

!HVScrollableView methodsFor:'private'!

setScrollActions
    |lock|

    lock := false.

    scrollBar scrollAction:[:position |
        lock := true.
        scrolledView scrollVerticalToPercent:position.
        lock := false
    ].
    scrollBar scrollUpAction:[scrolledView scrollUp].
    scrollBar scrollDownAction:[scrolledView scrollDown].

    hScrollBar scrollAction:[:position |
        lock := true.
        scrolledView scrollHorizontalToPercent:position.
        lock := false
    ].
    hScrollBar scrollLeftAction:[scrolledView scrollLeft].
    hScrollBar scrollRightAction:[scrolledView scrollRight].

    scrolledView originChangeAction:[:aView |
        lock ifFalse:[
            scrollBar setThumbOriginFor:aView.
            hScrollBar setThumbOriginFor:aView
        ]
    ].
    scrolledView contentsChangeAction:[:aView | 
        scrollBar setThumbFor:aView.
        hScrollBar setThumbFor:aView
    ]
! !

!HVScrollableView methodsFor:'accessing'!

horizontalScrollBar
    "return the horizontal scrollbar"

    ^ hScrollBar
!

scrolledView:aView
    "set the scrolled view"

    super scrolledView:aView.

    "redefine subviews size"
    self is3D ifFalse:[
        scrolledView
            extent:[(width
                     - scrollBar width
                     - scrollBar borderWidth
                     "- scrolledView borderWidth") 
                    @ 
                    (height
                     - hScrollBar height
                     - hScrollBar borderWidth
                     "- scrolledView borderWidth")
                   ]
    ].

    self setScrollActions
! !

!HVScrollableView methodsFor:'event processing'!

sizeChanged:how
    super sizeChanged:how.
    hScrollBar setThumbFor:scrolledView
! !