HVScrollableView.st
author claus
Wed, 13 Oct 1993 03:49:56 +0100
changeset 5 7b4fb1b170e5
parent 3 9d7eefb5e69f
child 7 15a9291b9bd0
permissions -rw-r--r--
(none)

"
 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.3 1993-10-13 02:48:04 claus Exp $
written jan 91 by claus
'!

!HVScrollableView methodsFor:'initialization'!

initializeFor:aViewClass
    |negativeOffset halfMargin|

    super initializeFor:aViewClass.

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

    "create the horizontal scrollbar and change vertical scrollbars size"

    hScrollBar := HorizontalScrollBar in:self.

    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.
    hScrollBar scrollAction:[:position | 
                                scrolledView scrollHorizontalToPercent:position].
    hScrollBar scrollLeftAction:[scrolledView scrollLeft].
    hScrollBar scrollRightAction:[scrolledView scrollRight].
    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:[
        scrolledView
            originChangeAction:[:aView | scrollBar setThumbOriginFor:aView.
                                         hScrollBar setThumbOriginFor:aView].
        scrolledView
            contentsChangeAction:[:aView | scrollBar setThumbFor:aView.
                                           hScrollBar setThumbFor:aView]
    ]
!

realize
    super realize.
    hScrollBar setThumbFor:scrolledView
! !

!HVScrollableView methodsFor:'accessing'!

scrolledView:aView
    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")
                   ]
    ].

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

!HVScrollableView methodsFor:'event processing'!

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