--- a/ScrollBar.st Thu Nov 23 18:48:50 1995 +0100
+++ b/ScrollBar.st Thu Nov 23 19:19:24 1995 +0100
@@ -10,12 +10,10 @@
hereby transferred.
"
-'From Smalltalk/X, Version:2.10.5 on 25-mar-1995 at 1:10:33 am'!
-
SimpleView subclass:#ScrollBar
instanceVariableNames:'thumb button1 button2 buttonLayout elementSpacing'
classVariableNames:'DefaultButtonPositions DefaultLevel DefaultElementSpacing
- DefaultScrollerBordered'
+ DefaultScrollerBordered'
poolDictionaries:''
category:'Views-Interactors'
!
@@ -36,10 +34,6 @@
"
!
-version
- ^ '$Header: /cvs/stx/stx/libwidg/ScrollBar.st,v 1.19 1995-11-11 16:22:32 cg Exp $'
-!
-
documentation
"
this class implements vertical scrollbars with scroller and
@@ -79,252 +73,88 @@
default:(StyleSheet is3D ifTrue:[1] ifFalse:[0]).
! !
-!ScrollBar methodsFor:'initialization'!
+!ScrollBar methodsFor:'accessing'!
-setElementPositions
- "position sub-components"
+downButton
+ "return the down-button
+ (Please: only use direct access for special applications)"
- |bwn|
-
- bwn := borderWidth negated + margin.
+ ^ button2
- (buttonLayout == #top) ifTrue:[
- button1 origin:(bwn @ bwn).
- button1 viewGravity:#North.
- button2 origin:(bwn @ (button1 height)).
- button2 viewGravity:#North.
- thumb origin:(bwn @ (button1 height
- + borderWidth
- + button2 height
- + elementSpacing
- + elementSpacing)).
- thumb viewGravity:#North.
- ^ self
- ].
- (buttonLayout == #bottom) ifTrue:[
- device supportsViewGravity ifTrue:[
- button1 viewGravity:#South.
- button2 viewGravity:#South.
- thumb viewGravity:#North.
- ].
- thumb origin:(bwn @ bwn).
- ^ self
- ].
+ "
+ |v|
- "buttonLayout == #around"
- button1 origin:(bwn @ bwn).
- button1 viewGravity:#North.
-"/ button2 viewGravity:#North.
- thumb origin:(bwn @ (button1 height + elementSpacing)).
- thumb viewGravity:#North
-!
-
-createElements
- button1 := ArrowButton upIn:self.
- button2 := ArrowButton downIn:self.
- thumb := Scroller in:self.
-!
-
-initStyle
- super initStyle.
-
- buttonLayout := DefaultButtonPositions.
- DefaultLevel notNil ifTrue:[
- self level:DefaultLevel
- ].
- elementSpacing := DefaultElementSpacing
+ v := ScrollableView for:EditTextView.
+ v scrolledView contents:('/etc/passwd' asFilename contentsOfEntireFile).
+ v scrollBar upButton activeForegroundColor:Color red.
+ v scrollBar downButton activeForegroundColor:Color red.
+ v open
+ "
!
-computeInitialExtent
- "compute my extent from sub-components"
+setThumbFor:aView
+ "adjust thumb for aView
+ (i.e. adjust thumbs origin & size for views size & views contents).
+ This is forwarded to the scroller here."
- self extent:(self preferredExtent).
+ thumb setThumbFor:aView.
+ self enableDisableButtons
!
-initialize
- "setup; create the 2 buttons and a scroller"
-
- |clr style|
-
- super initialize.
-
- self createElements.
-
- (styleSheet at:'scrollBarDisableButtons' default:false) ifTrue:[
- thumb addDependent:self
- ].
-
- button1 autoRepeat.
- button2 autoRepeat.
-
- self computeInitialExtent.
-
- button1 borderWidth:borderWidth.
- DefaultScrollerBordered ifFalse:[
- thumb borderWidth:borderWidth.
- ].
- button2 borderWidth:borderWidth.
+setThumbHeightFor:aView
+ "adjust thumbs height for aViews size & contents.
+ This is forwarded to the scroller here."
- style := styleSheet name.
- ((style = #iris) and:[Display hasGreyscales]) ifTrue:[
- "have to change some of Buttons defaults"
- clr := (Color grey:25) on:device.
- button1 offLevel:2.
- button2 offLevel:2.
- button1 foregroundColor:clr.
- button1 activeForegroundColor:clr.
- button1 enteredForegroundColor:clr.
- button2 foregroundColor:clr.
- button2 activeForegroundColor:clr.
- button2 enteredForegroundColor:clr.
- ].
-
- self setElementPositions.
-
- style = #motif ifTrue:[
- clr := thumb thumbColor.
- button1 foregroundColor:clr.
- button2 foregroundColor:clr.
-
- clr := thumb viewBackground.
- button1 viewBackground:clr.
- button2 viewBackground:clr.
- button1 backgroundColor:clr.
- button2 backgroundColor:clr.
- button1 activeBackgroundColor:clr.
- button2 activeBackgroundColor:clr.
- device hasGreyscales ifFalse:[
- button1 activeForegroundColor:Black.
- button2 activeForegroundColor:Black.
- ]
- ]
+ thumb setThumbHeightFor:aView.
+ self enableDisableButtons
!
-reinitialize
- super reinitialize.
- self setElementPositions.
-! !
-
-!ScrollBar methodsFor:'change & update'!
-
-update:something with:aParameter from:changedObject
- changedObject == thumb ifTrue:[
- self enableDisableButtons
- ]
-! !
-
-!ScrollBar methodsFor:'queries'!
-
-preferredExtent
- "compute my extent from sub-components"
-
- |w h upForm downForm
- upHeight "{ Class: SmallInteger }"
- downHeight "{ Class: SmallInteger }"
- upWidth downWidth style|
-
- "
- need fix - this is a kludge;
- the if should not be needed ...
- "
- style := styleSheet name.
- style == #mswindows ifTrue:[
- w := button1 width max:button2 width.
- h := button1 height + button2 height + (Scroller defaultExtent y).
- ] ifFalse:[
- upForm := ArrowButton upArrowButtonForm:style on:device.
- downForm := ArrowButton downArrowButtonForm:style on:device.
- upForm isNil ifTrue:[
- upHeight := upWidth := 16.
- ] ifFalse:[
- upHeight := upForm height.
- upWidth := upForm width
- ].
- downForm isNil ifTrue:[
- downHeight := downWidth := 16
- ] ifFalse:[
- downHeight := downForm height.
- downWidth := downForm width
- ].
- h := upHeight + downHeight + (1 * 2) + (Scroller defaultExtent y).
- w := upWidth max:downWidth.
- style ~~ #normal ifTrue:[
- h := h + 4.
- w := w + 4
- ].
- ].
-
- ^ w @ h.
-! !
-
-!ScrollBar methodsFor:'private'!
-
-enableDisableButtons
- "only used with styles which disable their buttons if the
- thumb is at either end. Check where the thumb is and enable/disable
- as appropriate."
-
- |e1 e2 th to|
-
- (styleSheet at:'scrollBarDisableButtons' default:false) ifFalse:[^ self].
-
- e1 := e2 := true.
- (th := thumb thumbHeight) notNil ifTrue:[
- (th >= (thumb stop)) ifTrue:[
- e1 := false.
- e2 := false
- ]
- ].
- ((to := thumb thumbOrigin) <= thumb start) ifTrue:[
- e1 := false
- ] ifFalse:[
- th isNil ifTrue:[th := 0].
- (to + th) >= thumb stop ifTrue:[
- e2 := false
- ]
- ].
- e1 ifTrue:[button1 enable] ifFalse:[button1 disable].
- e2 ifTrue:[button2 enable] ifFalse:[button2 disable].
-! !
-
-!ScrollBar methodsFor:'accessing-behavior'!
-
-scrollAction:aBlock
- "set the action, aBlock to be performed when the scroller is moved.
+setThumbOriginFor:aView
+ "adjust thumbs origin for aViews size & contents.
This is forwarded to the scroller here."
- thumb scrollAction:aBlock
+ thumb setThumbOriginFor:aView.
+ self enableDisableButtons
!
-scrollUpAction:aBlock
- "set the action, aBlock to be performed when the up-button is pressed."
+thumbColor:aColor
+ "set the thumbs color"
- button1 action:aBlock
+ thumb thumbColor:aColor
!
-scrollDownAction:aBlock
- "set the action, aBlock to be performed when the down-button is pressed."
+thumbHeight
+ "return height of thumb in percent"
- button2 action:aBlock
+ ^ thumb thumbHeight
!
-asynchronousOperation
- "set asynchronous-mode - scroll action is performed after movement
- of scroller (i.e. when mouse-button is finally released).
- This is forwarded to the scroller here."
+thumbHeight:newHeight
+ "set height of thumb in percent"
- thumb asynchronousOperation
+ thumb thumbHeight:newHeight.
+ self enableDisableButtons
+!
+
+thumbOrigin
+ "return position of (top of) thumb in percent"
+
+ ^ thumb thumbOrigin
!
-synchronousOperation
- "set synchronous-mode - scroll action is performed for every movement
- of scroller.
- This is forwarded to the scroller here."
+thumbOrigin:newOrigin
+ "set position of (top of) thumb in percent"
+
+ thumb thumbOrigin:newOrigin.
+ self enableDisableButtons
+!
- thumb synchronousOperation
-! !
+thumbOrigin:newOrigin thumbHeight:newHeight
+ "set origin and height of thumb (both in percent)"
-!ScrollBar methodsFor:'accessing'!
+ thumb thumbOrigin:newOrigin thumbHeight:newHeight.
+ self enableDisableButtons
+!
upButton
"return the up-button
@@ -345,23 +175,6 @@
"
!
-downButton
- "return the down-button
- (Please: only use direct access for special applications)"
-
- ^ button2
-
- "
- |v|
-
- v := ScrollableView for:EditTextView.
- v scrolledView contents:('/etc/passwd' asFilename contentsOfEntireFile).
- v scrollBar upButton activeForegroundColor:Color red.
- v scrollBar downButton activeForegroundColor:Color red.
- v open
- "
-!
-
upButtonLabel:label1 downButtonLabel:label2
"set the labels shown in the buttons"
@@ -377,70 +190,51 @@
v scrollBar upButtonLabel:'+' downButtonLabel:'-'.
v open
"
-!
+! !
+
+!ScrollBar methodsFor:'accessing-behavior'!
-setThumbFor:aView
- "adjust thumb for aView
- (i.e. adjust thumbs origin & size for views size & views contents).
+asynchronousOperation
+ "set asynchronous-mode - scroll action is performed after movement
+ of scroller (i.e. when mouse-button is finally released).
This is forwarded to the scroller here."
- thumb setThumbFor:aView.
- self enableDisableButtons
+ thumb asynchronousOperation
!
-setThumbOriginFor:aView
- "adjust thumbs origin for aViews size & contents.
+scrollAction:aBlock
+ "set the action, aBlock to be performed when the scroller is moved.
This is forwarded to the scroller here."
- thumb setThumbOriginFor:aView.
- self enableDisableButtons
-!
-
-setThumbHeightFor:aView
- "adjust thumbs height for aViews size & contents.
- This is forwarded to the scroller here."
-
- thumb setThumbHeightFor:aView.
- self enableDisableButtons
+ thumb scrollAction:aBlock
!
-thumbOrigin:newOrigin thumbHeight:newHeight
- "set origin and height of thumb (both in percent)"
+scrollDownAction:aBlock
+ "set the action, aBlock to be performed when the down-button is pressed."
- thumb thumbOrigin:newOrigin thumbHeight:newHeight.
- self enableDisableButtons
+ button2 action:aBlock
!
-thumbColor:aColor
- "set the thumbs color"
+scrollUpAction:aBlock
+ "set the action, aBlock to be performed when the up-button is pressed."
- thumb thumbColor:aColor
-!
-
-thumbOrigin
- "return position of (top of) thumb in percent"
-
- ^ thumb thumbOrigin
+ button1 action:aBlock
!
-thumbOrigin:newOrigin
- "set position of (top of) thumb in percent"
-
- thumb thumbOrigin:newOrigin.
- self enableDisableButtons
-!
+synchronousOperation
+ "set synchronous-mode - scroll action is performed for every movement
+ of scroller.
+ This is forwarded to the scroller here."
-thumbHeight
- "return height of thumb in percent"
+ thumb synchronousOperation
+! !
- ^ thumb thumbHeight
-!
+!ScrollBar methodsFor:'change & update'!
-thumbHeight:newHeight
- "set height of thumb in percent"
-
- thumb thumbHeight:newHeight.
- self enableDisableButtons
+update:something with:aParameter from:changedObject
+ changedObject == thumb ifTrue:[
+ self enableDisableButtons
+ ]
! !
!ScrollBar methodsFor:'events'!
@@ -587,14 +381,220 @@
!ScrollBar methodsFor:'forced scroll'!
+pageDown
+ "page down/right"
+
+ thumb pageDown
+!
+
pageUp
"page up/left"
thumb pageUp
+! !
+
+!ScrollBar methodsFor:'initialization'!
+
+computeInitialExtent
+ "compute my extent from sub-components"
+
+ self extent:(self preferredExtent).
+!
+
+createElements
+ button1 := ArrowButton upIn:self.
+ button2 := ArrowButton downIn:self.
+ thumb := Scroller in:self.
+!
+
+initStyle
+ super initStyle.
+
+ buttonLayout := DefaultButtonPositions.
+ DefaultLevel notNil ifTrue:[
+ self level:DefaultLevel
+ ].
+ elementSpacing := DefaultElementSpacing
+!
+
+initialize
+ "setup; create the 2 buttons and a scroller"
+
+ |clr style|
+
+ super initialize.
+
+ self createElements.
+
+ (styleSheet at:'scrollBarDisableButtons' default:false) ifTrue:[
+ thumb addDependent:self
+ ].
+
+ button1 autoRepeat.
+ button2 autoRepeat.
+
+ self computeInitialExtent.
+
+ button1 borderWidth:borderWidth.
+ DefaultScrollerBordered ifFalse:[
+ thumb borderWidth:borderWidth.
+ ].
+ button2 borderWidth:borderWidth.
+
+ style := styleSheet name.
+ ((style = #iris) and:[Display hasGreyscales]) ifTrue:[
+ "have to change some of Buttons defaults"
+ clr := (Color grey:25) on:device.
+ button1 offLevel:2.
+ button2 offLevel:2.
+ button1 foregroundColor:clr.
+ button1 activeForegroundColor:clr.
+ button1 enteredForegroundColor:clr.
+ button2 foregroundColor:clr.
+ button2 activeForegroundColor:clr.
+ button2 enteredForegroundColor:clr.
+ ].
+
+ self setElementPositions.
+
+ style = #motif ifTrue:[
+ clr := thumb thumbColor.
+ button1 foregroundColor:clr.
+ button2 foregroundColor:clr.
+
+ clr := thumb viewBackground.
+ button1 viewBackground:clr.
+ button2 viewBackground:clr.
+ button1 backgroundColor:clr.
+ button2 backgroundColor:clr.
+ button1 activeBackgroundColor:clr.
+ button2 activeBackgroundColor:clr.
+ device hasGreyscales ifFalse:[
+ button1 activeForegroundColor:Black.
+ button2 activeForegroundColor:Black.
+ ]
+ ]
+!
+
+reinitialize
+ super reinitialize.
+ self setElementPositions.
!
-pageDown
- "page down/right"
+setElementPositions
+ "position sub-components"
+
+ |bwn|
+
+ bwn := borderWidth negated + margin.
+
+ (buttonLayout == #top) ifTrue:[
+ button1 origin:(bwn @ bwn).
+ button1 viewGravity:#North.
+ button2 origin:(bwn @ (button1 height)).
+ button2 viewGravity:#North.
+ thumb origin:(bwn @ (button1 height
+ + borderWidth
+ + button2 height
+ + elementSpacing
+ + elementSpacing)).
+ thumb viewGravity:#North.
+ ^ self
+ ].
+ (buttonLayout == #bottom) ifTrue:[
+ device supportsViewGravity ifTrue:[
+ button1 viewGravity:#South.
+ button2 viewGravity:#South.
+ thumb viewGravity:#North.
+ ].
+ thumb origin:(bwn @ bwn).
+ ^ self
+ ].
+
+ "buttonLayout == #around"
+ button1 origin:(bwn @ bwn).
+ button1 viewGravity:#North.
+"/ button2 viewGravity:#North.
+ thumb origin:(bwn @ (button1 height + elementSpacing)).
+ thumb viewGravity:#North
+! !
+
+!ScrollBar methodsFor:'private'!
+
+enableDisableButtons
+ "only used with styles which disable their buttons if the
+ thumb is at either end. Check where the thumb is and enable/disable
+ as appropriate."
+
+ |e1 e2 th to|
+
+ (styleSheet at:'scrollBarDisableButtons' default:false) ifFalse:[^ self].
- thumb pageDown
+ e1 := e2 := true.
+ (th := thumb thumbHeight) notNil ifTrue:[
+ (th >= (thumb stop)) ifTrue:[
+ e1 := false.
+ e2 := false
+ ]
+ ].
+ ((to := thumb thumbOrigin) <= thumb start) ifTrue:[
+ e1 := false
+ ] ifFalse:[
+ th isNil ifTrue:[th := 0].
+ (to + th) >= thumb stop ifTrue:[
+ e2 := false
+ ]
+ ].
+ e1 ifTrue:[button1 enable] ifFalse:[button1 disable].
+ e2 ifTrue:[button2 enable] ifFalse:[button2 disable].
! !
+
+!ScrollBar methodsFor:'queries'!
+
+preferredExtent
+ "compute my extent from sub-components"
+
+ |w h upForm downForm
+ upHeight "{ Class: SmallInteger }"
+ downHeight "{ Class: SmallInteger }"
+ upWidth downWidth style|
+
+ "
+ need fix - this is a kludge;
+ the if should not be needed ...
+ "
+ style := styleSheet name.
+ style == #mswindows ifTrue:[
+ w := button1 width max:button2 width.
+ h := button1 height + button2 height + (Scroller defaultExtent y).
+ ] ifFalse:[
+ upForm := ArrowButton upArrowButtonForm:style on:device.
+ downForm := ArrowButton downArrowButtonForm:style on:device.
+ upForm isNil ifTrue:[
+ upHeight := upWidth := 16.
+ ] ifFalse:[
+ upHeight := upForm height.
+ upWidth := upForm width
+ ].
+ downForm isNil ifTrue:[
+ downHeight := downWidth := 16
+ ] ifFalse:[
+ downHeight := downForm height.
+ downWidth := downForm width
+ ].
+ h := upHeight + downHeight + (1 * 2) + (Scroller defaultExtent y).
+ w := upWidth max:downWidth.
+ style ~~ #normal ifTrue:[
+ h := h + 4.
+ w := w + 4
+ ].
+ ].
+
+ ^ w @ h.
+! !
+
+!ScrollBar class methodsFor:'documentation'!
+
+version
+ ^ '$Header: /cvs/stx/stx/libwidg/ScrollBar.st,v 1.20 1995-11-23 18:18:24 cg Exp $'
+! !