ScrollBar.st
changeset 128 06a050529335
parent 119 59758ff5b841
child 130 338e856bddc9
--- a/ScrollBar.st	Fri May 12 20:25:18 1995 +0200
+++ b/ScrollBar.st	Wed May 17 14:26:27 1995 +0200
@@ -15,7 +15,7 @@
 SimpleView subclass:#ScrollBar
 	 instanceVariableNames:'thumb button1 button2 layout elementSpacing'
 	 classVariableNames:'DefaultButtonPositions DefaultLevel DefaultElementSpacing
-                DefaultScrollerBordered'
+		DefaultScrollerBordered'
 	 poolDictionaries:''
 	 category:'Views-Interactors'
 !
@@ -24,7 +24,7 @@
 COPYRIGHT (c) 1989 by Claus Gittinger
 	      All Rights Reserved
 
-$Header: /cvs/stx/stx/libwidg/ScrollBar.st,v 1.12 1995-05-03 00:37:35 claus Exp $
+$Header: /cvs/stx/stx/libwidg/ScrollBar.st,v 1.13 1995-05-17 12:25:59 claus Exp $
 '!
 
 !ScrollBar class methodsFor:'documentation'!
@@ -45,7 +45,7 @@
 
 version
 "
-$Header: /cvs/stx/stx/libwidg/ScrollBar.st,v 1.12 1995-05-03 00:37:35 claus Exp $
+$Header: /cvs/stx/stx/libwidg/ScrollBar.st,v 1.13 1995-05-17 12:25:59 claus Exp $
 "
 !
 
@@ -72,6 +72,9 @@
 
     Most often scrollbars are used hidden with ScrollableView or HVScrollableView (i.e. you
     dont have to care for all the details).
+
+    The scrollBars and scrollers protocols have been made similar enough to
+    allow transparent use of either a scroller or a scrollBar in applications.
 "
 ! !
 
@@ -153,29 +156,29 @@
      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).
+	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
-        ].
+	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
+	].
     ].
 
     self extent:w @ h.
@@ -190,6 +193,10 @@
 
     self createElements.
 
+    (StyleSheet at:'scrollBarDisableButtons' default:false) ifTrue:[
+	thumb addDependent:self
+    ].
+
     button1 autoRepeat.
     button2 autoRepeat.
 
@@ -197,42 +204,42 @@
 
     button1 borderWidth:borderWidth.
     DefaultScrollerBordered ifFalse:[
-        thumb borderWidth:borderWidth.
+	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.
+	"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 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.
-        ]
+	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.
+	]
     ]
 !
 
@@ -241,44 +248,109 @@
     self setElementPositions.
 ! !
 
-!ScrollBar methodsFor:'accessing'!
+!ScrollBar methodsFor:'change & update'!
 
-setThumbFor:aView
-    "adjust thumb for aView"
+update:something with:aParameter from:changedObject
+    changedObject == thumb ifTrue:[
+	self enableDisableButtons
+    ]
+! !
 
-    thumb setThumbFor:aView
-!
+!ScrollBar methodsFor:'private'!
+
+enableDisableButtons
+    |e1 e2|
+
+    (StyleSheet at:'scrollBarDisableButtons' default:false) ifFalse:[^ self].
 
-setThumbOriginFor:aView
-    "adjust thumbs origin for aView"
-
-    thumb setThumbOriginFor:aView
-!
+    e1 := e2 := true.
+    thumb thumbHeight >= 99.99999 ifTrue:[
+	e1 := false.
+	e2 := false
+    ] ifFalse:[
+	thumb thumbOrigin <= 0.00001 ifTrue:[
+	    e1 := false
+	] ifFalse:[
+	    (thumb thumbOrigin + thumb thumbHeight) >= 99.99999 ifTrue:[
+		e2 := false
+	    ]
+	]
+    ].
+    e1 ifTrue:[button1 enable] ifFalse:[button1 disable].
+    e2 ifTrue:[button2 enable] ifFalse:[button2 disable].
+! !
 
-thumbOrigin:newOrigin thumbHeight:newHeight
-    "set origin and height of thumb in percent"
-
-    ^ thumb thumbOrigin:newOrigin thumbHeight:newHeight
-!
+!ScrollBar methodsFor:'accessing-behavior'!
 
 scrollAction:aBlock
-    "set the action, aBlock to be performed when the scroller is moved"
- 
+    "set the action, aBlock to be performed when the scroller is moved.
+     This is forwarded to the scroller here."
+
     thumb scrollAction:aBlock
 !
 
 scrollUpAction:aBlock
-    "set the action, aBlock to be performed when the up-button is pressed"
- 
+    "set the action, aBlock to be performed when the up-button is pressed."
+
     button1 action:aBlock
 !
 
 scrollDownAction:aBlock
-    "set the action, aBlock to be performed when the down-button is pressed"
- 
+    "set the action, aBlock to be performed when the down-button is pressed."
+
     button2 action:aBlock
 !
 
+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 asynchronousOperation
+!
+
+synchronousOperation
+    "set synchronous-mode - scroll action is performed for every movement
+     of scroller.
+     This is forwarded to the scroller here."
+
+    thumb synchronousOperation
+! !
+
+!ScrollBar methodsFor:'accessing'!
+
+setThumbFor:aView
+    "adjust thumb for aView 
+     (i.e. adjust thumbs origin & size for views size & views contents).
+     This is forwarded to the scroller here."
+
+    thumb setThumbFor:aView.
+    self enableDisableButtons
+!
+
+setThumbOriginFor:aView
+    "adjust thumbs origin for aViews size & contents.
+     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
+!
+
+thumbOrigin:newOrigin thumbHeight:newHeight
+    "set origin and height of thumb (both in percent)"
+
+    thumb thumbOrigin:newOrigin thumbHeight:newHeight.
+    self enableDisableButtons
+!
+
 thumbColor:aColor
     "set the thumbs color"
 
@@ -294,7 +366,8 @@
 thumbOrigin:newOrigin
     "set position of (top of) thumb in percent"
 
-    ^ thumb thumbOrigin:newOrigin
+    thumb thumbOrigin:newOrigin.
+    self enableDisableButtons
 !
 
 thumbHeight
@@ -306,41 +379,25 @@
 thumbHeight:newHeight
     "set height of thumb in percent"
 
-    ^ thumb thumbHeight:newHeight
-!
-
-setThumbHeightFor:aView
-    "adjust thumbs height for aView"
-
-    thumb setThumbHeightFor:aView
-!
-
-asynchronousOperation
-    "set asynchronous-mode - scroll action is performed after movement
-     of scroller (i.e. when mouse-button is finally released)"
-
-    thumb asynchronousOperation
-!
-
-synchronousOperation
-    "set synchronous-mode - scroll action is performed for every movement
-     of scroller"
-
-    thumb synchronousOperation
+    thumb thumbHeight:newHeight.
+    self enableDisableButtons
 ! !
 
 !ScrollBar methodsFor:'events'!
 
 sizeChanged:how
-    "when my size changes, I have to resize/reposition the subviews"
+    "when my size changes, I have to resize/reposition the subviews.
+     Also, if I became too small, hide thumb/buttons."
 
     |upHeight downHeight thumbHeight upAndDownHeight bwn sep2
-     thumbWidth w|
+     thumbWidth w style|
 
     button1 isNil ifTrue:[^ self].
     thumb isNil ifTrue:[^ self].
     button2 isNil ifTrue:[^ self].
 
+    style := StyleSheet name.
+
     upHeight := button1 height + borderWidth.
     downHeight := button2 height + borderWidth.
     upAndDownHeight := upHeight + downHeight.
@@ -395,11 +452,11 @@
     ].
 
     thumbWidth := w.
-    StyleSheet name == #next ifTrue:[
+    style == #next ifTrue:[
 	thumbWidth := thumbWidth - (thumb borderWidth * 2).
 	thumbHeight := thumbHeight - 1
     ].
-    StyleSheet name == #motif ifTrue:[
+    style == #motif ifTrue:[
 	thumbHeight := thumbHeight - margin
     ].
 
@@ -434,13 +491,20 @@
     ].
     "buttons around thumb"
 
-StyleSheet name == #motif ifTrue:[
-    sep2 := sep2 + 1
-].
+    style == #motif ifTrue:[
+	sep2 := sep2 + 1
+    ].
     button1 origin:(bwn @ bwn).
-    button2 origin:(bwn @ (upHeight + thumbHeight + sep2 - (margin // 2) "+ borderWidth")).
-    thumb extent:(thumbWidth @ (thumbHeight + margin - (margin // 2))).
-    thumb origin:(bwn @ (upHeight - borderWidth + elementSpacing))
+
+    style == #os2 ifTrue:[
+	button2 origin:(bwn @ (upHeight + thumbHeight + sep2 - margin "+ borderWidth")).
+	thumb extent:(thumbWidth @ (thumbHeight - margin - margin "+ margin - (margin // 2)")).
+	thumb origin:(bwn @ (upHeight - borderWidth + elementSpacing + margin))
+    ] ifFalse:[
+	button2 origin:(bwn @ (upHeight + thumbHeight + sep2 - (margin // 2) "+ borderWidth")).
+	thumb extent:(thumbWidth @ (thumbHeight + margin - (margin // 2))).
+	thumb origin:(bwn @ (upHeight - borderWidth + elementSpacing))
+    ].
 ! !
 
 !ScrollBar methodsFor:'forced scroll'!