ScrollBar.st
changeset 448 e23465aad9e8
parent 446 98f38de97099
child 453 dc035dd8b9eb
--- a/ScrollBar.st	Fri Mar 01 19:44:55 1996 +0100
+++ b/ScrollBar.st	Fri Mar 01 19:48:00 1996 +0100
@@ -82,43 +82,123 @@
 
 !ScrollBar methodsFor:'accessing'!
 
-thumbColor:aColor
-    "set the thumbs color"
+v := ScrollableView for:EditTextView.
+     v scrolledView contents:('/etc/passwd' asFilename contentsOfEntireFile).
+     v scrollBar upButtonLabel:'+' downButtonLabel:'-'.
+     v open
+    "
+
+    "also possible :
+     |v|
 
-    thumb thumbColor:aColor
+     v := ScrollableView for:EditTextView.
+     v scrolledView contents:('/etc/passwd' asFilename contentsOfEntireFile).
+     v scrollBar upButtonLabel:'u' downButtonLabel:'d'.
+     v open
+    "
+
+    "BAD example:
+     |v|
+
+     v := ScrollableView for:EditTextView.
+     v scrolledView contents:('/etc/passwd' asFilename contentsOfEntireFile).
+     v scrollBar upButtonLabel:'up' downButtonLabel:'down'.
+     v open
+    "
+
+    "Modified: 1.3.1996 / 19:06:50 / cg"
 !
 
-thumbHeight
-    "return height of thumb in percent"
+c/passwd' asFilename contentsOfEntireFile).
+     v scrollBar upButtonLabel:'+' downButtonLabel:'-'.
+     v open
+    "
 
-    ^ thumb thumbHeight
-!
+    "also possible :
+     |v|
 
-thumbHeight:newHeight
-    "set height of thumb in percent"
+     v := ScrollableView for:EditTextView.
+     v scrolledView contents:('/etc/passwd' asFilename contentsOfEntireFile).
+     v scrollBar upButtonLabel:'u' downButtonLabel:'d'.
+     v open
+    "
 
-    thumb thumbHeight:newHeight.
-    self enableDisableButtons
+    "BAD example:
+     |v|
+
+     v := ScrollableView for:EditTextView.
+     v scrolledView contents:('/etc/passwd' asFilename contentsOfEntireFile).
+     v scrollBar upButtonLabel:'up' downButtonLabel:'down'.
+     v open
+    "
+
+    "Modified: 1.3.1996 / 19:06:50 / cg"
 !
 
-thumbOrigin
-    "return position of (top of) thumb in percent"
+ownButtonLabel:'-'.
+     v open
+    "
+
+    "also possible :
+     |v|
 
-    ^ thumb thumbOrigin
+     v := ScrollableView for:EditTextView.
+     v scrolledView contents:('/etc/passwd' asFilename contentsOfEntireFile).
+     v scrollBar upButtonLabel:'u' downButtonLabel:'d'.
+     v open
+    "
+
+    "BAD example:
+     |v|
+
+     v := ScrollableView for:EditTextView.
+     v scrolledView contents:('/etc/passwd' asFilename contentsOfEntireFile).
+     v scrollBar upButtonLabel:'up' downButtonLabel:'down'.
+     v open
+    "
+
+    "Modified: 1.3.1996 / 19:06:50 / cg"
 !
 
-thumbOrigin:newOrigin
-    "set position of (top of) thumb in percent"
+edView contents:('/etc/passwd' asFilename contentsOfEntireFile).
+     v scrollBar upButtonLabel:'u' downButtonLabel:'d'.
+     v open
+    "
+
+    "BAD example:
+     |v|
 
-    thumb thumbOrigin:newOrigin.
-    self enableDisableButtons
+     v := ScrollableView for:EditTextView.
+     v scrolledView contents:('/etc/passwd' asFilename contentsOfEntireFile).
+     v scrollBar upButtonLabel:'up' downButtonLabel:'down'.
+     v open
+    "
+
+    "Modified: 1.3.1996 / 19:06:50 / cg"
 !
 
-thumbOrigin:newOrigin thumbHeight:newHeight
-    "set origin and height of thumb (both in percent)"
+abel:'u' downButtonLabel:'d'.
+     v open
+    "
+
+    "BAD example:
+     |v|
 
-    thumb thumbOrigin:newOrigin thumbHeight:newHeight.
-    self enableDisableButtons
+     v := ScrollableView for:EditTextView.
+     v scrolledView contents:('/etc/passwd' asFilename contentsOfEntireFile).
+     v scrollBar upButtonLabel:'up' downButtonLabel:'down'.
+     v open
+    "
+
+    "Modified: 1.3.1996 / 19:06:50 / cg"
+!
+
+ew contents:('/etc/passwd' asFilename contentsOfEntireFile).
+     v scrollBar upButtonLabel:'up' downButtonLabel:'down'.
+     v open
+    "
+
+    "Modified: 1.3.1996 / 19:06:50 / cg"
 !
 
 upButtonLabel:label1 downButtonLabel:label2
@@ -162,39 +242,58 @@
 
 !ScrollBar methodsFor:'accessing-behavior'!
 
-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."
+"return the down-button
+     (Please: only use this direct access for special applications)"
+
+    ^ button2
+
+    "
+     |v|
 
-    thumb asynchronousOperation
-!
+     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
+    "
 
-scrollAction:aBlock
-    "set the action, aBlock to be performed when the scroller is moved.
-     This is forwarded to the scroller here."
-
-    thumb scrollAction:aBlock
+    "Modified: 1.3.1996 / 19:04:43 / cg"
 !
 
-scrollDownAction:aBlock
-    "set the action, aBlock to be performed when the down-button is pressed."
+EntireFile).
+     v scrollBar upButton activeForegroundColor:Color red.
+     v scrollBar downButton activeForegroundColor:Color red.
+     v open
+    "
 
-    button2 action:aBlock
+    "Modified: 1.3.1996 / 19:04:43 / cg"
+!
+
+996 / 19:04:43 / cg"
 !
 
-scrollUpAction:aBlock
-    "set the action, aBlock to be performed when the up-button is pressed."
+al applications)"
+
+    ^ thumb
+
+    "
+     |v|
 
-    button1 action:aBlock
+     v := ScrollableView for:EditTextView.
+     v scrolledView contents:('/etc/passwd' asFilename contentsOfEntireFile).
+     v scrollBar thumb thumbColor:(Color red).
+     v open
+    "
+
+    "Modified: 1.3.1996 / 19:15:50 / cg"
 !
 
-synchronousOperation
-    "set synchronous-mode - scroll action is performed for every movement
-     of scroller.
-     This is forwarded to the scroller here."
+asswd' asFilename contentsOfEntireFile).
+     v scrollBar thumb thumbColor:(Color red).
+     v open
+    "
 
-    thumb synchronousOperation
+    "Modified: 1.3.1996 / 19:15:50 / cg"
 ! !
 
 !ScrollBar methodsFor:'accessing-components'!
@@ -259,145 +358,52 @@
 
 !ScrollBar methodsFor:'change & update'!
 
-update:something with:aParameter from:changedObject
-    changedObject == thumb ifTrue:[
-	self enableDisableButtons
-    ]
+l applications)"
+
+    ^ button1
+
+    "
+     |v|
+
+     v := ScrollableView for:EditTextView.
+     v scrolledView contents:('/etc/passwd' asFilename contentsOfEntireFile).
+     v scrollBar upButton foregroundColor:(Color red).
+     v scrollBar upButton enteredForegroundColor:(Color red lightened).
+     v scrollBar downButton foregroundColor:(Color green).
+     v scrollBar downButton enteredForegroundColor:(Color green lightened).
+     v open
+    "
+
+    "Modified: 1.3.1996 / 19:04:48 / cg"
 ! !
 
 !ScrollBar methodsFor:'events'!
 
-sizeChanged:how
-    "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 style b1Hidden b2Hidden thumbHidden bY|
-
-    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.
-    bwn := borderWidth negated + margin.
-
-    thumbHeight := height - upAndDownHeight - borderWidth - (elementSpacing * 3).
-"
-    ((buttonLayout ~~ #top) and:[buttonLayout ~~ #bottom]) ifTrue:[
-	thumbHeight := thumbHeight - borderWidth
-    ].
-"
-    buttonLayout == #around ifTrue:[
-	thumbHeight := thumbHeight + borderWidth
-    ].
-
-    "if I become too small, hide buttons and thumb"
+tireFile).
+     v scrollBar upButton foregroundColor:(Color red).
+     v scrollBar upButton enteredForegroundColor:(Color red lightened).
+     v scrollBar downButton foregroundColor:(Color green).
+     v scrollBar downButton enteredForegroundColor:(Color green lightened).
+     v open
+    "
 
-    height < upAndDownHeight ifTrue:[
-	b1Hidden := b2Hidden := thumbHidden := true.
-    ] ifFalse:[
-	b1Hidden := b2Hidden := thumbHidden := false.
-    ].
-
-    (thumbHeight < 10) ifTrue:[
-	thumbHidden := true.
-    ] ifFalse:[
-	thumbHidden := false.
-    ].
+    "Modified: 1.3.1996 / 19:04:48 / cg"
+! !
 
-    button1 hiddenOnRealize:b1Hidden.
-    b1Hidden ifTrue:[
-	button1 unrealize
-    ] ifFalse:[
-	shown ifTrue:[button1 realize]
-    ].
-    button2 hiddenOnRealize:b1Hidden.
-    b2Hidden ifTrue:[
-	button2 unrealize
-    ] ifFalse:[
-	shown ifTrue:[button2 realize]
-    ].
-    thumb hiddenOnRealize:thumbHidden.
-    thumbHidden ifTrue:[
-	thumb unrealize
-    ] ifFalse:[
-	shown ifTrue:[thumb realize]
-    ].
-
-    "width of buttons is always my width"
+!ScrollBar methodsFor:'forced scroll'!
 
-    w := width - (margin * 2).
-    (w ~~ button1 width) ifTrue:[
-	button1 width:w.
-	button2 width:w
-    ].
-
-    thumbWidth := w.
-    style == #next ifTrue:[
-	thumbWidth := thumbWidth - (thumb borderWidth * 2).
-	thumbHeight := thumbHeight - 1
-    ].
-    style == #motif ifTrue:[
-	thumbHeight := thumbHeight - margin
+ue:[
+	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))
     ].
-
-    "
-     a kludge: views with width or height of 0 are illegal
-     avoid error from view-creation (it will be hidden anyway)
-    "
-    thumbHeight <= 0 ifTrue:[
-	thumbHeight := 1
-    ].
-
-    (buttonLayout == #top) ifTrue:[
-	"buttons at top"
-	thumb extent:(thumbWidth @ thumbHeight).
-	^ self
-    ].
+!
 
-    sep2 := elementSpacing * 2.
-    (buttonLayout == #bottom) ifTrue:[
-	"buttons at bottom"
-"/
-"/ XX: I thought, that viewGravity shuld fix things automatically
-"/ XX: it seems not to do it (or I misused it ;-)
-"/ XX: anyway, viewGravity is an X special feature which is probably
-"/ XX: not available with other windowing systems. Therefore,
-"/ XX: the viewGravity depending code below is disabled.
-"/ XX: resize is somewhat slower, though.
-
-	thumbHeight := thumbHeight + borderWidth.
-"/ XX        thumbHidden ifTrue:[
-"/ XX           bY := elementSpacing
-"/ XX       ] ifFalse:[
-	    bY := thumbHeight + sep2.
-"/ XX       ].
-"XX"            button1 viewGravity:#North. 
-"XX"            button2 viewGravity:#North. 
-	(how == #smaller) ifTrue:[
-	    thumb extent:(thumbWidth @ thumbHeight).
-"XX"            button1 origin:(bwn @ (thumbHeight + sep2)).
-"XX"            button2 origin:(bwn @ (thumbHeight + sep2 + upHeight))
-	] ifFalse:[
-	    button1 origin:(bwn @ bY).
-	    button2 origin:(bwn @ (bY + upHeight)).
-	    thumb extent:(thumbWidth @ thumbHeight)
-	].
-	^ self
-    ].
-    "buttons around thumb"
-
-    style == #motif ifTrue:[
-	sep2 := sep2 + 1
-    ].
-    button1 origin:(bwn @ bwn).
-
-    style == #os2 ifTrue:[
-	button2 origin:(bwn @ (upHeight + thumbHeight + sep2 - margin "+ borderWidth")).
+sep2 - margin "+ borderWidth")).
 	thumb extent:(thumbWidth @ (thumbHeight - margin - margin "+ margin - (margin // 2)")).
 	thumb origin:(bwn @ (upHeight - borderWidth + elementSpacing + margin))
     ] ifFalse:[
@@ -407,42 +413,26 @@
     ].
 ! !
 
-!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).
+] ifFalse:[
+	button2 origin:(bwn @ (upHeight + thumbHeight + sep2 - (margin // 2) "+ borderWidth")).
+	thumb extent:(thumbWidth @ (thumbHeight + margin - (margin // 2))).
+	thumb origin:(bwn @ (upHeight - borderWidth + elementSpacing))
+    ].
 !
 
-createElements
-    button1 := ArrowButton upIn:self.
-    button2 := ArrowButton downIn:self.
-    thumb := Scroller in:self.
+defaultExtent
+    "compute my extent from sub-components"
+
+    ^ self preferredExtent
+
+    "Created: 1.3.1996 / 19:22:11 / cg"
 !
 
-initStyle
-    super initStyle.
-
-    buttonLayout := DefaultButtonPositions.
-    DefaultLevel notNil ifTrue:[
-	self level:DefaultLevel
+@ (thumbHeight + margin - (margin // 2))).
+	thumb origin:(bwn @ (upHeight - borderWidth + elementSpacing))
     ].
-    elementSpacing := DefaultElementSpacing
 !
 
 initialize
@@ -461,8 +451,6 @@
     button1 autoRepeat:true.
     button2 autoRepeat:true.
 
-    self computeInitialExtent.
-
     button1 borderWidth:borderWidth.
     DefaultScrollerBordered ifFalse:[
         thumb borderWidth:borderWidth.
@@ -503,31 +491,47 @@
         ]
     ]
 
+    "Modified: 1.3.1996 / 19:22:47 / cg"
+!
+
+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.
+        ]
+    ]
+
     "Modified: 9.2.1996 / 22:42:16 / cg"
 !
 
-reinitialize
-    super reinitialize.
-    self setElementPositions.
-!
-
-setElementPositions
-    "position sub-components"
-
-    |bwn|
+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.
+        ]
+    ]
 
-    bwn := borderWidth negated + margin.
+    "Modified: 9.2.1996 / 22:42:16 / cg"
+! !
 
-    (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)).
+!ScrollBar methodsFor:'private'!
+
+elementSpacing)).
 	thumb viewGravity:#North.
 	^ self
     ].
@@ -547,18 +551,60 @@
 "/    button2 viewGravity:#North.
     thumb origin:(bwn @ (button1 height + elementSpacing)).
     thumb viewGravity:#North
+!
+
+mbOrigin:newOrigin thumbHeight:newHeight.
+    self enableDisableButtons
 ! !
 
-!ScrollBar methodsFor:'private'!
+!ScrollBar methodsFor:'private scrollView interface'!
+
+"set position of (top of) thumb in percent"
+
+    thumb thumbOrigin:newOrigin.
+    self enableDisableButtons
+!
+
+sizes, this only makes sense with 
+     single-character strings or small bitmaps."
+
+    button1 label:label1.
+    button2 label:label2.
+    self setElementPositions.
+
+    "not bad:
+     |v|
+
+     v := ScrollableView for:EditTextView.
+     v scrolledView contents:('/etc/passwd' asFilename contentsOfEntireFile).
+     v scrollBar upButtonLabel:'+' downButtonLabel:'-'.
+     v open
+    "
 
-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."
+    "also possible :
+     |v|
+
+     v := ScrollableView for:EditTextView.
+     v scrolledView contents:('/etc/passwd' asFilename contentsOfEntireFile).
+     v scrollBar upButtonLabel:'u' downButtonLabel:'d'.
+     v open
+    "
+
+    "BAD example:
+     |v|
 
-    |e1 e2 th to|
+     v := ScrollableView for:EditTextView.
+     v scrolledView contents:('/etc/passwd' asFilename contentsOfEntireFile).
+     v scrollBar upButtonLabel:'up' downButtonLabel:'down'.
+     v open
+    "
 
-    (styleSheet at:'scrollBarDisableButtons' default:false) ifFalse:[^ self].
+    "Modified: 1.3.1996 / 19:06:50 / cg"
+! !
+
+!ScrollBar methodsFor:'queries'!
+
+et at:'scrollBarDisableButtons' default:false) ifFalse:[^ self].
 
     e1 := e2 := true.
     (th := thumb thumbHeight) notNil ifTrue:[
@@ -577,81 +623,10 @@
     ].
     e1 ifTrue:[button1 enable] ifFalse:[button1 disable].
     e2 ifTrue:[button2 enable] ifFalse:[button2 disable].
-!
-
-setThumbHeightFor:aView
-    "adjust thumbs height for aViews size & contents.
-     This is forwarded to the scroller here."
-
-    thumb setThumbHeightFor:aView.
-    self enableDisableButtons
-! !
-
-!ScrollBar methodsFor:'private scrollView interface'!
-
-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
-! !
-
-!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.23 1996-03-01 18:16:26 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/ScrollBar.st,v 1.24 1996-03-01 18:47:36 cg Exp $'
 ! !