FIX: Proportioned Morphic Scrollbar enhancement, plus arrow fix

Doug Way dway at mat.net
Sat Feb 13 09:33:54 UTC 1999


Here's the final version of the proportional-sized Morphic scrollbar
enhancement.  I spent some time cleaning up a couple of minor things, so
it seems pretty solid now.  (I even avoided adding an instance variable to
ScrollBar, which I had in there originally.)  All of the tools in Morphic
which use PluggableListMorphs and PluggableTextMorphs will use the
enhanced scrollbars (browsers, filelists, change sorters, etc.)

Please give it a test run if you're curious, and let me know if there are
any problems.  If it's solid enough, I'd hope it could be added as an
official update... (I'm assuming no one actually prefers the fixed-size
scrollbars, especially since the MVC ones are proportional.  I realize
that Mac scrollbars are fixed size, but I use a Mac at home and I can say
with certainty that the fixed size scrollbars are nothing special. :) )

In addition to the proportioned scrollbars, I made a fix to the arrow
buttons on the Morphic scrollbar, which I only recently noticed.
Basically, whenever you clicked on the up arrow, it scrolled up two lines,
and the down arrow scrolled down one line.  (Very interesting.)  This is
now fixed so that they both scroll one line at a time.

- Doug Way
  EAI/Transom Technologies, Ann Arbor, MI
  http://www.transom.com
  dway at transom.com, dway at mat.net

  Smalltalk: Guaranteed Y10K Compliant


'From Squeak 2.3 of January 14, 1999 on 13 February 1999 at 3:41:03 am'!

!PluggableListMorph methodsFor: 'initialization' stamp: 'dew 2/13/1999
02:05'!
setScrollDeltas
	| range |
	scroller hasSubmorphs ifFalse: [scrollBar interval: 1.0.  ^ self].
	range _ self totalScrollRange.
	range = 0 ifTrue: [^ scrollBar scrollDelta: 0.02 pageDelta: 0.2;
interval: 1.0].
	"Set up for one line, or a full pane less one line"
	scrollBar scrollDelta: (scroller firstSubmorph height / range)
asFloat 
			pageDelta: (self innerBounds height - scroller
firstSubmorph height / range) asFloat.
	"('range' really equals the leftover range, not the total range,
so adjust accordingly)"
	scrollBar interval: (self innerBounds height - scroller
firstSubmorph height / (range + (self innerBounds height * 3 // 4)))
asFloat.
! !


!PluggableTextMorph methodsFor: 'initialization' stamp: 'dew 2/10/1999
01:08'!
extent: newExtent
	super extent: (newExtent max: 36 at 16).
	textMorph ifNotNil:
		[textMorph extent: (self innerBounds width-6)@self
height].
	self setScrollDeltas! !

!PluggableTextMorph methodsFor: 'initialization' stamp: 'dew 2/13/1999
02:08'!
setScrollDeltas
	| range |
	scroller hasSubmorphs ifFalse: [^ self].
	range _ self totalScrollRange.
	range = 0 ifTrue: [^ scrollBar scrollDelta: 0.02 pageDelta: 0.2;
interval: 1.0].
	scrollBar scrollDelta: (scroller firstSubmorph defaultLineHeight /
range) asFloat 
			pageDelta: (self innerBounds height - scroller
firstSubmorph defaultLineHeight / range) asFloat.
	"('range' really equals the leftover range, not the total range,
so adjust accordingly)"
	scrollBar interval: (self innerBounds height - scroller
firstSubmorph defaultLineHeight / (range + (self innerBounds height * 3 //
4))) asFloat.
! !


!Slider methodsFor: 'geometry' stamp: 'dew 2/13/1999 02:33'!
extent: newExtent
	newExtent = bounds extent ifTrue: [^ self].
	bounds isWide
		ifTrue: [super extent: (newExtent x max: self
sliderThickness * 2) @ newExtent y]
		ifFalse: [super extent: newExtent x @ (newExtent y max:
self sliderThickness * 2)].
	self removeAllMorphs; initializeSlider! !

!Slider methodsFor: 'scrolling' stamp: 'dew 2/9/1999 23:26'!
scrollAbsolute: event
	| r p |
	r _ self roomToMove.
	bounds isWide
		ifTrue: [r width = 0 ifTrue: [^self]]
		ifFalse: [r height = 0 ifTrue: [^self]].
	p _ event targetPoint adhereTo: r.
	self setValue: (bounds isWide 
		ifTrue: [(p x - r left) asFloat / r width]
		ifFalse: [(p y - r top) asFloat / r height])! !


!ScrollBar methodsFor: 'access' stamp: 'dew 2/13/1999 01:28'!
interval: d
	"Supply an optional floating fraction so slider can expand to
indicate range"
	interval _ d min: 1.0.
	self expandSlider.
	self computeSlider.
! !

!ScrollBar methodsFor: 'geometry' stamp: 'dew 2/13/1999 00:59'!
computeSlider
	"interval ifNotNil: [self expandSlider]."
	super computeSlider.
! !

!ScrollBar methodsFor: 'geometry' stamp: 'dew 2/13/1999 03:21'!
expandSlider
	"Compute the new size of the slider."
	| r |
	r _ self totalSliderArea.
	slider extent: (bounds isWide
		ifTrue: [((r width * interval) asInteger max: 5) @ slider
height]
		ifFalse: [slider width @ ((r height * interval) asInteger
max: 5)])! !

!ScrollBar methodsFor: 'geometry' stamp: 'dew 2/13/1999 03:31'!
sliderExtent
	"The sliderExtent is now stored in the slider itself, not
hardcoded as it is in the superclass."
	^slider extent! !

!ScrollBar methodsFor: 'scrolling' stamp: 'dew 2/13/1999 02:28'!
setValue: newValue
	"Using roundTo: instead of truncateTo: ensures that scrollUp will
scroll the same distance as scrollDown."
	^ super setValue: (newValue roundTo: scrollDelta)! !


!TextMorphForEditView methodsFor: 'private' stamp: 'dew 2/13/1999 00:59'!
updateFromParagraph  
	super updateFromParagraph.
	editView setScrollDeltas.! !





More information about the Squeak-dev mailing list