Fix prev fix from cg. Send setupDimensions only if scrolledView
is set.
"
COPYRIGHT (c) 1989 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.
"
SimpleView subclass:#ScrollableView
instanceVariableNames:'scrolledView vScrollBar hScrollBar scrollBarPosition lockUpdates
hideScrollBars hasHorizontalScrollBar hasVerticalScrollBar
horizontalMini verticalMini vScrollBarHidden hScrollBarHidden'
classVariableNames:'DefaultScrolledViewLevel DefaultScrolledViewMargin
DefaultScrollBarSpacing DefaultScrolledViewBorderWidth
DefaultLevel DefaultScrollBarLevel MyDefaultViewBackgroundColor'
poolDictionaries:''
category:'Views-Basic'
!
!ScrollableView class methodsFor:'documentation'!
copyright
"
COPYRIGHT (c) 1989 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.
"
!
documentation
"
a view containing a scrollbar and some other (slave-)view.
This view wraps scrollbar(s) around the view to be scrolled.
The scrollbars are setup to send scrollUp/scrollDown/scrollVerticalTo
and scrollLeft/scrollRight/scrollHorizontalTo- messages whenever moved.
The view itself has to implement these (there is a default implementation
in the common View class for this.
For the scrollbars to know about the full (maximum) size, the view
must implement #heightOfContents and/or #widthOfContents.
The values returned by these methods are used to compute the fraction
which is visible (i.e. the scrollers thumb heights).
There are two ways to create a ScrollableView:
if the type of the view to be scrolled is known in advance,
use:
v := ScrollableView for:<ViewClass>
or:
v := ScrollableView for:<ViewClass> in:someSuperView
otherwise, create the scrollableView empty with:
v := ScrollableView new
or:
v := ScrollableView in:someSuperView
and define the view later with:
v scrolledView:aViewToBeScrolled
Finally, if the view to be scrolled has been already created,
use:
v := ScrollableView forView:aViewToBeScrolled
or:
v := ScrollableView forView:aViewToBeScrolled in:someSuperView
It is also possible to change the scrolledView later (even multiple times).
This may be useful, if different views are needed to display different types
of data (see example2) and at creation time, it is not known what type
of view is required (multimedia applications).
If you want to scroll views (instead of a views contents), you need a
companion class (ViewScroller). See the documentation there.
If you need horizontal scrolling too, use an instance of HVScrollableView.
By default, scrollbars are full size scrollbars - for horizontal scrolling
(which is less often used), scrollableViews can optionally be created with
miniscrollers which take up less screen space.
TODO:
this is pretty old and needs a rewrite. There are quite some
historic leftovers found here and things can be done better
(especially in initializeFor...)
Also, it should be rewritten into one class which supports both
Vertical-only, Horizontal-only and HV scrolling.
Currently, horizontal-only scrolling is not available.
(you have to write your own class ...)
Finally, some means to hide scrollbars should be added - this would
give more screenspace to the view when all is visible
(and therefore, the scrollbars are not needed, anyway)
Expect the above things to be fixed in an upcoming version.
[author:]
Claus Gittinger
[see also:]
ScrollBar Scroller
HVScrollableView
"
!
examples
"
example1 (simple scrolled text):
[exBegin]
|top scr txt|
top := StandardSystemView label:'scroll example1'.
top extent:200@100.
scr := NewScrollableView for:EditTextView in:top.
scr origin:0.0@0.0 corner:1.0@1.0.
txt := scr scrolledView.
txt list:#('line1'
'line2'
'line3'
'line4'
'line5'
'line7'
'line8'
'line9'
'line10'
).
top open
[exEnd]
example2 (changing the scrolledView later):
[exBegin]
|top scr txtView1 txtView2 browserView|
top := StandardSystemView label:'scroll example2'.
top extent:300@100.
scr := ScrollableView in:top.
scr origin:0.0@0.0 corner:1.0@1.0.
top open.
(Delay forSeconds:5) wait.
txtView1 := EditTextView new.
txtView1 list:#(
'wait 5 seconds to see the other text'
'line2'
'line3'
'line4'
'line5'
'line7'
'line8'
'line9'
'line10'
).
scr scrolledView:txtView1.
(Delay forSeconds:5) wait.
txtView2 := EditTextView new.
txtView2 list:#('this is the other views text'
'alternative line2'
'alternative line3'
'alternative line4'
'alternative line5'
'alternative line6').
scr scrolledView:txtView2.
[exEnd]
example3 (using a miniscroller):
[exBegin]
|top scr txt|
top := StandardSystemView label:'scroll example3'.
top extent:200@100.
scr := ScrollableView for:EditTextView miniScroller:true in:top.
scr origin:0.0@0.0 corner:1.0@1.0.
txt := scr scrolledView.
txt list:#('line1'
'line2'
'line3'
'line4'
'line5'
'line7'
'line8'
'line9'
'line10'
).
top open
[exEnd]
example4 (scrolling in both directions):
[exBegin]
|top scr txt|
top := StandardSystemView label:'scroll example4'.
top extent:200@100.
scr := HVScrollableView for:EditTextView in:top.
scr origin:0.0@0.0 corner:1.0@1.0.
txt := scr scrolledView.
txt list:#('line1'
'line2'
'line3'
'line4'
'line5'
'line7'
'line8'
'line9'
'line10'
).
top open
[exEnd]
example5 (using a full scroller vertically, miniscroller horizontally):
[exBegin]
|top scr txt|
top := StandardSystemView label:'scroll example5'.
top extent:200@100.
scr := HVScrollableView for:EditTextView miniScrollerH:true in:top.
scr origin:0.0@0.0 corner:1.0@1.0.
txt := scr scrolledView.
txt list:#('line1'
'line2'
'line3'
'line4'
'line5'
'line7'
'line8'
'line9'
'line10'
).
top open
[exEnd]
example6 (using miniscrollers for both directions ):
[exBegin]
|top scr txt|
top := StandardSystemView label:'scroll example6'.
top extent:200@100.
scr := HVScrollableView for:EditTextView miniScroller:true in:top.
scr origin:0.0@0.0 corner:1.0@1.0.
txt := scr scrolledView.
txt list:#('line1'
'line2'
'line3'
'line4'
'line5'
'line7'
'line8'
'line9'
'line10'
).
top open
[exEnd]
"
! !
!ScrollableView class methodsFor:'instance creation'!
for:aViewClass
"return a new scrolling view scrolling an instance of aViewClass.
The subview is created here.
The view will have full scrollbars."
^ self
for:aViewClass
hasHorizontalScrollBar:(self == HVScrollableView)
hasVerticalScrollBar:true
miniScrollerH:false
miniScrollerV:false
origin:nil
corner:nil
in:nil
"Created: 6.3.1997 / 18:06:22 / cg"
"Modified: 6.3.1997 / 23:18:32 / cg"
!
for:aViewClass hasHorizontalScrollBar:hasH hasVerticalScrollBar:hasV miniScrollerH:miniH miniScrollerV:miniV origin:org corner:corn in:aView
"return a new scrolling view scrolling an instance of aViewClass.
The subview is created here.
The view will have full scrollbars if the corresponding miniH/miniV
is false, miniscrollers if true."
|newView|
aViewClass notNil ifTrue:[
newView := aViewClass new.
].
^ self
forView:newView
hasHorizontalScrollBar:hasH
hasVerticalScrollBar:hasV
miniScrollerH:miniH
miniScrollerV:miniV
origin:org
corner:corn
in:aView
"
|top scr|
top := StandardSystemView extent:200@200.
scr := NewScrollableView for:nil
hasHorizontalScrollBar:true
hasVerticalScrollBar:true
miniScrollerH:false
miniScrollerV:false
origin:0.0@0.0
corner:1.0@1.0
in:top.
top open
"
"Modified: 6.3.1997 / 18:36:01 / cg"
!
for:aViewClass in:aView
"return a new scrolling view scrolling an instance of aViewClass.
The subview is created here.
The view will have full scrollbars."
^ self
for:aViewClass
hasHorizontalScrollBar:(self == HVScrollableView)
hasVerticalScrollBar:true
miniScrollerH:false
miniScrollerV:false
origin:nil
corner:nil
in:aView
"Modified: 6.3.1997 / 23:18:41 / cg"
!
for:aViewClass miniScroller:mini
"return a new scrolling view scrolling an instance of aViewClass.
The subview is created here.
The view will have full scrollbars if mini is false, miniscrollers
if true."
^ self
for:aViewClass
hasHorizontalScrollBar:(self == HVScrollableView)
hasVerticalScrollBar:true
miniScrollerH:mini
miniScrollerV:mini
origin:nil
corner:nil
in:nil
"Modified: 6.3.1997 / 23:18:45 / cg"
!
for:aViewClass miniScroller:mini in:aView
"return a new scrolling view scrolling an instance of aViewClass.
The subview is created here.
The view will have full scrollbars if mini is false, miniscrollers
if true."
^ self
for:aViewClass
hasHorizontalScrollBar:(self == HVScrollableView)
hasVerticalScrollBar:true
miniScrollerH:mini
miniScrollerV:mini
origin:nil
corner:nil
in:aView
"Modified: 6.3.1997 / 23:18:50 / cg"
!
for:aViewClass miniScroller:mini origin:org corner:corn in:aView
"return a new scrolling view scrolling an instance of aViewClass.
The subview is created here.
The view will have full scrollbars if mini is false, miniscrollers
if true."
^ self
for:aViewClass
hasHorizontalScrollBar:(self == HVScrollableView)
hasVerticalScrollBar:true
miniScrollerH:mini
miniScrollerV:mini
origin:org
corner:corn
in:aView
"Modified: 6.3.1997 / 23:18:53 / cg"
!
for:aViewClass miniScrollerH:miniH
"return a new scrolling view scrolling an instance of aViewClass.
The subview is created here.
The view will have full scrollbars if miniH is false,
and a horizontal miniscroller if true."
^ self
for:aViewClass
hasHorizontalScrollBar:true
hasVerticalScrollBar:true
miniScrollerH:miniH
miniScrollerV:false
origin:nil
corner:nil
in:nil
"Modified: 6.3.1997 / 18:30:15 / cg"
!
for:aViewClass miniScrollerH:miniH in:aView
"return a new scrolling view scrolling an instance of aViewClass.
The subview is created here.
The view will have full scrollbars if the corresponding miniH/miniV
is false, miniscrollers if true."
^ self
for:aViewClass
hasHorizontalScrollBar:true
hasVerticalScrollBar:true
miniScrollerH:miniH
miniScrollerV:false
origin:nil
corner:nil
in:aView
"Modified: 6.3.1997 / 18:30:31 / cg"
!
for:aViewClass miniScrollerH:miniH miniScrollerV:miniV
"return a new scrolling view scrolling an instance of aViewClass.
The subview is created here.
The view will have full scrollbars if the corresponding miniH/miniV
is false, miniscrollers if true."
^ self
for:aViewClass
hasHorizontalScrollBar:true
hasVerticalScrollBar:true
miniScrollerH:miniH
miniScrollerV:miniV
origin:nil
corner:nil
in:nil
"Modified: 6.3.1997 / 18:30:47 / cg"
!
for:aViewClass miniScrollerH:miniH miniScrollerV:miniV in:aView
"return a new scrolling view scrolling an instance of aViewClass.
The subview is created here.
The view will have full scrollbars if the corresponding miniH/miniV
is false, miniscrollers if true."
^ self
for:aViewClass
hasHorizontalScrollBar:true
hasVerticalScrollBar:true
miniScrollerH:miniH
miniScrollerV:miniV
origin:nil
corner:nil
in:aView
"Modified: 6.3.1997 / 18:31:02 / cg"
!
for:aViewClass miniScrollerH:miniH miniScrollerV:miniV origin:org corner:corn in:aView
"return a new scrolling view scrolling an instance of aViewClass.
The subview is created here.
The view will have full scrollbars if the corresponding miniH/miniV
is false, miniscrollers if true."
^ self
for:aViewClass
hasHorizontalScrollBar:true
hasVerticalScrollBar:true
miniScrollerH:miniH
miniScrollerV:miniV
origin:org
corner:corn
in:aView
"Modified: 6.3.1997 / 18:31:17 / cg"
!
for:aViewClass miniScrollerH:miniH origin:org corner:corn in:aView
"return a new scrolling view scrolling an instance of aViewClass.
The subview is created here.
The view will have a full horizontal scrollbar if miniH is false,
a miniscroller if true."
^ self
for:aViewClass
hasHorizontalScrollBar:true
hasVerticalScrollBar:true
miniScrollerH:miniH
miniScrollerV:false
origin:org
corner:corn
in:aView
"Modified: 6.3.1997 / 18:31:28 / cg"
!
for:aViewClass miniScrollerV:miniV origin:org corner:corn in:aView
"return a new scrolling view scrolling an instance of aViewClass.
The subview is created here.
The view will have a full vertical scrollbar if miniV is false,
a miniscroller if true."
^ self
for:aViewClass
hasHorizontalScrollBar:true
hasVerticalScrollBar:true
miniScrollerH:false
miniScrollerV:miniV
origin:org
corner:corn
in:aView
"Modified: 6.3.1997 / 18:31:41 / cg"
!
for:aViewClass origin:org corner:corner in:aView
"return a new scrolling view scrolling an instance of aViewClass.
The subview is created here.
The view will have full scrollbars."
^ self
for:aViewClass
hasHorizontalScrollBar:(self == HVScrollableView)
hasVerticalScrollBar:true
miniScrollerH:false
miniScrollerV:false
origin:org
corner:corner
in:aView
"Modified: 6.3.1997 / 23:19:05 / cg"
!
forView:aView
"return a new scrolling view scrolling aView.
The view will have full scrollbars."
^ self
forView:aView
hasHorizontalScrollBar:(self == HVScrollableView)
hasVerticalScrollBar:true
miniScrollerH:false
miniScrollerV:false
origin:nil
corner:nil
in:nil
"Modified: 6.3.1997 / 23:19:08 / cg"
!
forView:aScrolledView hasHorizontalScrollBar:hasH hasVerticalScrollBar:hasV miniScrollerH:miniH miniScrollerV:miniV origin:org corner:corn in:aView
"return a new scrolling view scrolling an instance of aViewClass.
The subview is created here.
The view will have full scrollbars if the corresponding miniH/miniV
is false, miniscrollers if true."
|newView dev|
aView notNil ifTrue:[
dev := aView graphicsDevice
] ifFalse:[
dev := Screen current
].
newView := self basicNew device:dev.
newView initialize.
newView setupVertical:hasV mini:miniV horizontal:hasH mini:miniH.
aScrolledView notNil ifTrue:[
newView scrolledView:aScrolledView.
].
<<<<<<< ScrView.st
=======
"/ newView setupDimensions.
>>>>>>> 1.53
org notNil ifTrue:[
newView origin:org
].
corn notNil ifTrue:[
newView corner:corn
].
aView notNil ifTrue:[
aView addSubView:newView
].
^ newView
"
|top scr|
top := StandardSystemView extent:200@200.
scr := NewScrollableView
forView:(TextView new)
hasHorizontalScrollBar:true
hasVerticalScrollBar:true
miniScrollerH:false
miniScrollerV:false
origin:0.0@0.0
corner:1.0@1.0
in:top.
top open
"
<<<<<<< ScrView.st
"Modified: 6.3.1997 / 18:42:40 / cg"
"Modified: 19.3.1997 / 15:32:51 / stefan"
=======
"Modified: 19.3.1997 / 15:16:37 / cg"
>>>>>>> 1.53
!
forView:aView in:aSuperView
"return a new scrolling view scrolling aView.
The view will have full scrollbars."
^ self
forView:aView
hasHorizontalScrollBar:(self == HVScrollableView)
hasVerticalScrollBar:true
miniScrollerH:false
miniScrollerV:false
origin:nil
corner:nil
in:aSuperView
"Modified: 6.3.1997 / 23:19:12 / cg"
!
forView:aView miniScrollerH:mini
"return a new scrolling view scrolling aView.
The view will have a full vertical scrollbar and a horizontal
miniScroller if mini is true."
^ self
forView:aView
hasHorizontalScrollBar:true
hasVerticalScrollBar:true
miniScrollerH:mini
miniScrollerV:false
origin:nil
corner:nil
in:nil
"Modified: 6.3.1997 / 18:32:58 / cg"
!
forView:scrolledView miniScrollerH:miniH miniScrollerV:miniV in:aView
"return a new scrolling view, scrolling aView.
The view will have full scrollbars if the corresponding miniH/miniV
is false, miniscrollers if true."
^ self
forView:scrolledView
hasHorizontalScrollBar:true
hasVerticalScrollBar:true
miniScrollerH:miniH
miniScrollerV:miniV
origin:nil
corner:nil
in:aView
"Modified: 6.3.1997 / 18:33:20 / cg"
!
in:aView
"return a new scrolling view to be contained in aView.
There is no slave view now - this has to be set later via
the scrolledView: method.
The view will have full scrollbars."
^ self
forView:nil
hasHorizontalScrollBar:(self == HVScrollableView)
hasVerticalScrollBar:true
miniScrollerH:false
miniScrollerV:false
origin:nil
corner:nil
in:aView
"Modified: 6.3.1997 / 23:19:19 / cg"
!
miniScroller:mini
"return a new scrolling view. The subview will be created later.
The view will have full scrollbars if mini is false,
miniscrollers if true."
^ self
forView:nil
hasHorizontalScrollBar:(self == HVScrollableView)
hasVerticalScrollBar:true
miniScrollerH:mini
miniScrollerV:mini
origin:nil
corner:nil
in:nil
"Modified: 6.3.1997 / 23:19:21 / cg"
!
miniScrollerH:miniH
"return a new scrolling view. The subview will be created later.
The view will have full scrollbars if miniH is false,
and a horizontal miniscroller if true."
^ self
forView:nil
hasHorizontalScrollBar:true
hasVerticalScrollBar:true
miniScrollerH:miniH
miniScrollerV:false
origin:nil
corner:nil
in:nil
"Modified: 6.3.1997 / 18:34:06 / cg"
!
miniScrollerH:miniH miniScrollerV:miniV
"return a new scrolling view. The subview will be created later.
The view will have full scrollbars if the corresponding miniH/miniV
is false, miniscrollers if true."
^ self
forView:nil
hasHorizontalScrollBar:true
hasVerticalScrollBar:true
miniScrollerH:miniH
miniScrollerV:miniV
origin:nil
corner:nil
in:nil
"Modified: 6.3.1997 / 18:34:16 / cg"
! !
!ScrollableView class methodsFor:'defaults'!
updateStyleCache
"extract values from the styleSheet and cache them in class variables"
<resource: #style (#scrolledViewLevel #scrolledViewMargin)>
|defLevel defMargin defSpacing|
StyleSheet is3D ifTrue:[
defLevel := -1.
defMargin := ViewSpacing // 2.
defSpacing := defMargin.
] ifFalse:[
defLevel := 0.
defMargin := 0.
defSpacing := 0
].
DefaultScrolledViewLevel := StyleSheet at:'scrolledViewLevel' default:defLevel.
DefaultScrolledViewBorderWidth := StyleSheet at:'scrolledViewBorderWidth' default:nil.
DefaultScrolledViewMargin := StyleSheet at:'scrolledViewMargin' default:defMargin.
DefaultScrollBarSpacing := StyleSheet at:'scrollBarSpacing' default:defSpacing.
DefaultLevel := StyleSheet at:'scrollableViewLevel' default:nil.
DefaultScrollBarLevel := StyleSheet at:'scrollBarLevel' default:nil.
MyDefaultViewBackgroundColor := StyleSheet at:'scrollableViewBackgroundColor' default:DefaultViewBackgroundColor.
"
self updateStyleCache
"
"Modified: 7.3.1997 / 15:03:37 / cg"
! !
!ScrollableView methodsFor:'accessing - components'!
horizontalScrollBar
"return the horizontal scrollbar (or nil, if there is none)"
^ hScrollBar
"Modified: 6.3.1997 / 16:59:24 / cg"
"Created: 6.3.1997 / 18:06:23 / cg"
!
scrollBar
"return the vertical scrollbar (or nil, if there is none)"
^ vScrollBar
"Modified: 6.3.1997 / 16:59:29 / cg"
"Created: 6.3.1997 / 18:06:23 / cg"
!
scrolledView
"return the scrolled view (or nil, if there is none)"
^ scrolledView
"Modified: 6.3.1997 / 16:48:09 / cg"
"Created: 6.3.1997 / 18:06:23 / cg"
!
scrolledView:aView
"set the view to scroll"
scrolledView notNil ifTrue:[
scrolledView removeDependent:self.
scrolledView destroy.
scrolledView := nil.
].
scrolledView := aView.
super addSubViewFirst:aView.
scrolledView notNil ifTrue:[
self setScrollActions.
realized ifTrue:[
self setupDimensions.
self sizeChanged:nil.
scrolledView realize
].
]
<<<<<<< ScrView.st
"Modified: 7.3.1997 / 22:24:43 / cg"
"Modified: 19.3.1997 / 15:32:37 / stefan"
=======
"Modified: 19.3.1997 / 15:08:18 / cg"
>>>>>>> 1.53
!
verticalScrollBar
"return the vertical scrollbar (or nil, if there is none)"
^ vScrollBar
"Modified: 6.3.1997 / 16:59:24 / cg"
"Created: 6.3.1997 / 18:06:23 / cg"
! !
!ScrollableView methodsFor:'accessing-look'!
hideScrollBars:aBoolean
hideScrollBars := aBoolean.
"Created: 7.3.1997 / 21:57:23 / cg"
!
horizontalMini:aBoolean
horizontalMini ~~ aBoolean ifTrue:[
horizontalMini := aBoolean.
self setupViews
].
"Created: 7.3.1997 / 21:57:02 / cg"
"Modified: 7.3.1997 / 22:09:46 / cg"
!
horizontalScrollable:aBoolean
hasHorizontalScrollBar ~~ aBoolean ifTrue:[
hasHorizontalScrollBar := aBoolean.
hScrollBarHidden := false.
self setupViews
].
"Created: 7.3.1997 / 21:56:28 / cg"
"Modified: 7.3.1997 / 22:10:21 / cg"
!
verticalMini:aBoolean
verticalMini ~~ aBoolean ifTrue:[
verticalMini := aBoolean.
self setupViews
]
"Created: 7.3.1997 / 21:56:57 / cg"
"Modified: 7.3.1997 / 22:09:57 / cg"
!
verticalScrollable:aBoolean
hasVerticalScrollBar ~~ aBoolean ifTrue:[
hasVerticalScrollBar := aBoolean.
vScrollBarHidden := false.
self setupViews
]
"Created: 7.3.1997 / 21:56:39 / cg"
"Modified: 7.3.1997 / 22:10:39 / cg"
! !
!ScrollableView methodsFor:'changes '!
update:something with:argument from:changedObject
"whenever the scrolledView changes its contents, the scroller(s) must
be updated as well"
changedObject == scrolledView ifTrue:[
something == #sizeOfContents ifTrue:[
vScrollBar notNil ifTrue:[
vScrollBar setThumbFor:scrolledView.
].
hScrollBar notNil ifTrue:[
hScrollBar setThumbFor:scrolledView.
].
].
something == #originOfContents ifTrue:[
lockUpdates ifFalse:[
vScrollBar notNil ifTrue:[
vScrollBar setThumbOriginFor:scrolledView.
].
hScrollBar notNil ifTrue:[
hScrollBar setThumbOriginFor:scrolledView.
].
].
].
self updateScrollBarVisibility
].
"Modified: 7.3.1997 / 22:22:15 / cg"
!
updateScrollBarVisibility
"check if any scrollbar needs to be hidden or shown"
|anyChange|
hideScrollBars ifFalse:[^ self].
anyChange := false.
vScrollBar notNil ifTrue:[
vScrollBar thumbHeight >= 100 ifTrue:[
vScrollBarHidden ifFalse:[
vScrollBarHidden := true.
vScrollBar beInvisible.
anyChange := true.
]
] ifFalse:[
vScrollBarHidden ifTrue:[
vScrollBarHidden := false.
vScrollBar beVisible.
anyChange := true.
]
]
].
hScrollBar notNil ifTrue:[
hScrollBar thumbHeight >= 100 ifTrue:[
hScrollBarHidden ifFalse:[
hScrollBarHidden := true.
hScrollBar beInvisible.
anyChange := true.
]
] ifFalse:[
hScrollBarHidden ifTrue:[
hScrollBarHidden := false.
hScrollBar beVisible.
anyChange := true.
]
]
].
anyChange ifTrue:[
realized ifTrue:[
self setupDimensions.
].
"/ force him to recompute its dimension ...
scrolledView notNil ifTrue:[
vScrollBar notNil ifTrue:[
vScrollBar setThumbFor:scrolledView.
].
hScrollBar notNil ifTrue:[
hScrollBar setThumbFor:scrolledView.
].
].
"/ stupid - showing one may need the other ...
"/ and vice versa; do it again.
anyChange := false.
vScrollBar notNil ifTrue:[
vScrollBar thumbHeight >= 100 ifTrue:[
vScrollBarHidden ifFalse:[
vScrollBarHidden := true.
vScrollBar beInvisible.
anyChange := true.
]
] ifFalse:[
vScrollBarHidden ifTrue:[
vScrollBarHidden := false.
vScrollBar beVisible.
anyChange := true.
]
]
].
hScrollBar notNil ifTrue:[
hScrollBar thumbHeight >= 100 ifTrue:[
hScrollBarHidden ifFalse:[
hScrollBarHidden := true.
hScrollBar beInvisible.
anyChange := true.
]
] ifFalse:[
hScrollBarHidden ifTrue:[
hScrollBarHidden := false.
hScrollBar beVisible.
anyChange := true.
]
]
].
anyChange ifTrue:[
<<<<<<< ScrView.st
realized ifTrue:[
self setupDimensions.
].
].
=======
realized ifTrue:[
self setupDimensions.
]
]
>>>>>>> 1.53
].
<<<<<<< ScrView.st
"Modified: 7.3.1997 / 22:58:56 / cg"
"Modified: 19.3.1997 / 15:33:36 / stefan"
=======
"Modified: 19.3.1997 / 15:09:23 / cg"
>>>>>>> 1.53
! !
!ScrollableView methodsFor:'event processing'!
keyPress:key x:x y:y
"a key was pressed - handle page-keys here"
<resource: #keyboard ( #Prior #Next ) >
(key == #Prior) ifTrue: [^ self pageUp].
(key == #Next) ifTrue: [^ self pageDown].
super keyPress:key x:x y:y
"Created: 6.3.1997 / 18:06:23 / cg"
!
sizeChanged:how
|orgX orgY scroll|
"/ resize components manually, in an order which is optimal
how == #smaller ifTrue:[
"/ first resize the horizontalScrollBar,
scrolledView notNil ifTrue:[
scrolledView containerChangedSize
].
hScrollBar notNil ifTrue:[
hScrollBar containerChangedSize
].
vScrollBar notNil ifTrue:[
vScrollBar containerChangedSize
].
] ifFalse:[
hScrollBar notNil ifTrue:[
hScrollBar containerChangedSize
].
vScrollBar notNil ifTrue:[
vScrollBar containerChangedSize
].
scrolledView notNil ifTrue:[
scrolledView containerChangedSize
].
].
"/ The following action will be done in a atomic operation
"/ in HVScrollableView
scrolledView isNil ifTrue:[^ self].
(hScrollBar isNil and:[vScrollBar isNil]) ifTrue:[^ self].
vScrollBar notNil ifTrue:[
vScrollBar setThumbFor:scrolledView.
].
hScrollBar notNil ifTrue:[
hScrollBar setThumbFor:scrolledView.
].
"/ splitted, since there are optimized scrollProcedures for each case ...
hScrollBar isNil ifTrue:[
"/ only care for vertical ...
vScrollBar thumbOrigin + vScrollBar thumbHeight >= 100 ifTrue:[
vScrollBar thumbOrigin:(100 - vScrollBar thumbHeight).
scrolledView scrollVerticalToPercent:vScrollBar thumbOrigin.
].
] ifFalse:[
vScrollBar isNil ifTrue:[
"/ only care for horizontal ...
hScrollBar thumbOrigin + hScrollBar thumbHeight >= 100 ifTrue:[
hScrollBar thumbOrigin:(100 - hScrollBar thumbHeight).
scrolledView scrollVerticalToPercent:hScrollBar thumbOrigin.
].
] ifFalse:[
"/ care for both ...
orgY := vScrollBar thumbOrigin.
orgX := hScrollBar thumbOrigin.
scroll := false.
orgY + vScrollBar thumbHeight >= 100 ifTrue:[
vScrollBar thumbOrigin:(100 - vScrollBar thumbHeight).
orgY := vScrollBar thumbOrigin.
scroll := true.
].
orgX + hScrollBar thumbHeight >= 100 ifTrue:[
hScrollBar thumbOrigin:(100 - hScrollBar thumbHeight).
orgX := hScrollBar thumbOrigin.
scroll := true.
].
scroll ifTrue:[
scrolledView scrollToPercent:(orgX@orgY).
].
]
].
self updateScrollBarVisibility.
"Modified: 7.3.1997 / 22:18:23 / cg"
! !
!ScrollableView methodsFor:'forced scroll'!
pageDown
"page down"
vScrollBar notNil ifTrue:[
vScrollBar pageDown
]
"Modified: 6.3.1997 / 17:01:51 / cg"
"Created: 6.3.1997 / 18:06:23 / cg"
!
pageUp
"page up"
vScrollBar notNil ifTrue:[
vScrollBar pageUp
]
"Modified: 6.3.1997 / 17:01:58 / cg"
"Created: 6.3.1997 / 18:06:23 / cg"
! !
!ScrollableView methodsFor:'initialization'!
initStyle
"initialize style specifics"
<resource: #style (#scrollBarPosition)>
super initStyle.
viewBackground := MyDefaultViewBackgroundColor.
scrollBarPosition := styleSheet at:'scrollBarPosition' default:#left.
hideScrollBars := styleSheet at:'scrollBarHiding' default:false.
"Created: 6.3.1997 / 18:06:23 / cg"
"Modified: 7.3.1997 / 21:47:32 / cg"
!
realize
super realize.
self setupDimensions.
"since scrolledview may have done something to its contents
during init-time we had no chance yet to catch contents-
changes; do it now
"
scrolledView notNil ifTrue:[
self setupDimensions.
vScrollBar notNil ifTrue:[
vScrollBar setThumbFor:scrolledView
].
hScrollBar notNil ifTrue:[
hScrollBar setThumbFor:scrolledView
].
].
self updateScrollBarVisibility
<<<<<<< ScrView.st
"Modified: 7.3.1997 / 22:22:33 / cg"
"Modified: 19.3.1997 / 15:32:20 / stefan"
=======
"Modified: 19.3.1997 / 15:07:56 / cg"
>>>>>>> 1.53
!
releaseHorizontalScrollBar
"destroy any horizontal scrollBar"
hScrollBar notNil ifTrue:[
hScrollBar destroy.
hScrollBar := nil
].
"Modified: 6.3.1997 / 17:43:20 / cg"
"Created: 6.3.1997 / 18:06:23 / cg"
!
releaseVerticalScrollBar
"destroy any vertical scrollBar"
vScrollBar notNil ifTrue:[
vScrollBar destroy.
vScrollBar := nil
].
"Created: 6.3.1997 / 18:06:23 / cg"
!
setScrollActions
"lock prevents repositioning the scroller to the
actual (often rounded) position while scrolling,
and keeps it instead at the pointer position.
(this avoids run-away scroller when scrolling
textviews, when the text is aligned line-wise).
Consider this as a kludge."
lockUpdates := false.
vScrollBar notNil ifTrue:[
vScrollBar scrollAction:[:position |
lockUpdates := true.
scrolledView scrollVerticalToPercent:position.
lockUpdates := false
].
vScrollBar scrollUpAction:[scrolledView scrollUp].
vScrollBar scrollDownAction:[scrolledView scrollDown].
].
hScrollBar notNil ifTrue:[
hScrollBar scrollAction:[:position |
lockUpdates := true.
scrolledView scrollHorizontalToPercent:position.
lockUpdates := false
].
hScrollBar scrollUpAction:[scrolledView scrollLeft].
hScrollBar scrollDownAction:[scrolledView scrollRight].
].
scrolledView addDependent:self.
"
pass my keyboard input (and other subviews input)
to the scrolled view ...
"
self delegate:(KeyboardForwarder toView:scrolledView).
"Modified: 6.3.1997 / 17:03:43 / cg"
"Created: 6.3.1997 / 18:06:23 / cg"
!
setupDimensions
|scrolledViewMargin scrollBarSpacing
scrolledViewLayout hScrollBarLayout vScrollBarLayout
vBd "{ Class: SmallInteger }"
hBd "{ Class: SmallInteger }"
sBd "{ Class: SmallInteger }"
wVScroll "{ Class: SmallInteger }"
hHScroll "{ Class: SmallInteger }"
hLeftOffs "{ Class: SmallInteger }"
hRightOffs "{ Class: SmallInteger }"
hTopOffs "{ Class: SmallInteger }"
hBottomOffs "{ Class: SmallInteger }"
sLeftOffs "{ Class: SmallInteger }"
sRightOffs "{ Class: SmallInteger }"
sTopOffs "{ Class: SmallInteger }"
sBottomOffs "{ Class: SmallInteger }"
vLeftOffs "{ Class: SmallInteger }"
vRightOffs "{ Class: SmallInteger }"
vTopOffs "{ Class: SmallInteger }"
vBottomOffs "{ Class: SmallInteger }"
addMargin "{ Class: SmallInteger }"|
DefaultLevel notNil ifTrue:[self level:DefaultLevel].
sBd := 0.
DefaultScrolledViewBorderWidth notNil ifTrue:[
sBd := DefaultScrolledViewBorderWidth.
scrolledView notNil ifTrue:[
scrolledView borderWidth:DefaultScrolledViewBorderWidth.
]
] ifFalse:[
scrolledView notNil ifTrue:[
sBd := scrolledView borderWidth
]
].
(vScrollBar notNil and:[vScrollBarHidden not]) ifTrue:[
vBd := vScrollBar borderWidth.
wVScroll := vScrollBar widthIncludingBorder.
] ifFalse:[
vBd := wVScroll := 0.
].
(hScrollBar notNil and:[hScrollBarHidden not]) ifTrue:[
hBd := hScrollBar borderWidth.
hHScroll := hScrollBar heightIncludingBorder.
] ifFalse:[
hBd := hHScroll := 0.
].
"/ the raw layout ...
scrolledViewLayout := ((0.0 @ 0.0) corner:(1.0@1.0)) asLayout.
hScrollBarLayout := ((0.0 @ 1.0) corner:(1.0@1.0)) asLayout.
"/ the painful details; mostly complicated for 2D styles,
"/ where the positions are setUp to overlay borders ...
"/ (well, with 3D styles, a single pixel error will not be noticed;
"/ but 2D styles are very sensitive to those;
"/ the code below may not work correctly with different borderWidths).
scrolledViewMargin := DefaultScrolledViewMargin.
scrollBarSpacing := DefaultScrollBarSpacing.
vTopOffs := 0 - vBd + scrolledViewMargin + margin.
scrolledViewMargin == 0 ifTrue:[
vBottomOffs := 0 + vBd - scrolledViewMargin - sBd.
] ifFalse:[
vBottomOffs := 0 + vBd - scrolledViewMargin + sBd.
].
hLeftOffs := 0 - hBd + scrolledViewMargin + margin.
hRightOffs := 0 + hBd - scrolledViewMargin - sBd.
sLeftOffs := 0 - hBd + scrolledViewMargin + margin.
sRightOffs := 0 + hBd - scrolledViewMargin - sBd - sBd - sBd.
scrolledViewMargin == 0 ifTrue:[
sTopOffs := 0 - sBd + margin.
sBottomOffs := 0 + sBd - sBd.
] ifFalse:[
sTopOffs := 0 + scrolledViewMargin + margin.
sBottomOffs := 0 + sBd - scrolledViewMargin - sBd - sBd - sBd.
].
addMargin := 0.
"/ DefaultScrollBarLevel == DefaultScrolledViewLevel
"/ addMargin := 1.
"/ ].
(vScrollBar notNil and:[vScrollBarHidden not]) ifTrue:[
scrollBarPosition == #right ifTrue:[
"/ right/bottom
vScrollBarLayout := ((1.0 @ 0.0) corner:(1.0@1.0)) asLayout.
vRightOffs := 0 - scrolledViewMargin + margin "???".
vLeftOffs := vRightOffs - wVScroll.
sRightOffs := sRightOffs - scrollBarSpacing - wVScroll + sBd.
hRightOffs := hRightOffs - wVScroll - scrollBarSpacing - sBd.
sRightOffs := sRightOffs - addMargin
] ifFalse:[
"/ left/bottom
vScrollBarLayout := ((0.0 @ 0.0) corner:(0.0@1.0)) asLayout.
vLeftOffs := 0 - vBd + scrolledViewMargin + margin.
vRightOffs := vLeftOffs + wVScroll + margin.
sLeftOffs := wVScroll + scrolledViewMargin + scrollBarSpacing + margin.
sRightOffs := 0 - scrolledViewMargin - margin.
hLeftOffs := hLeftOffs + wVScroll + vBd + scrollBarSpacing.
sLeftOffs := sLeftOffs + addMargin
].
].
(hScrollBar notNil and:[hScrollBarHidden not]) ifTrue:[
hBottomOffs := 0 - scrolledViewMargin - hBd + margin "???".
hTopOffs := hBottomOffs - hHScroll.
scrolledViewMargin == 0 ifTrue:[
hTopOffs := hTopOffs + sBd + sBd
].
sBottomOffs := sBottomOffs - scrollBarSpacing - hHScroll.
(vScrollBar notNil and:[vScrollBarHidden not]) ifTrue:[
vBottomOffs := vBottomOffs - scrollBarSpacing - hHScroll.
].
sBottomOffs := sBottomOffs - addMargin.
hRightOffs := hRightOffs - addMargin.
].
scrolledView notNil ifTrue:[
scrolledViewLayout leftOffset:sLeftOffs.
scrolledViewLayout rightOffset:sRightOffs.
scrolledViewLayout topOffset:sTopOffs.
scrolledViewLayout bottomOffset:sBottomOffs.
scrolledView level:DefaultScrolledViewLevel.
scrolledView layout:scrolledViewLayout.
].
(hScrollBar notNil and:[hScrollBarHidden not]) ifTrue:[
hScrollBarLayout leftOffset:hLeftOffs.
hScrollBarLayout rightOffset:hRightOffs.
hScrollBarLayout topOffset:hTopOffs.
hScrollBarLayout bottomOffset:hBottomOffs.
hScrollBar level:DefaultScrollBarLevel.
hScrollBar layout:hScrollBarLayout
].
(vScrollBar notNil and:[vScrollBarHidden not]) ifTrue:[
vScrollBarLayout leftOffset:vLeftOffs.
vScrollBarLayout rightOffset:vRightOffs.
vScrollBarLayout topOffset:vTopOffs.
vScrollBarLayout bottomOffset:vBottomOffs.
vScrollBar level:DefaultScrollBarLevel.
vScrollBar layout:vScrollBarLayout
].
"Created: 6.3.1997 / 18:06:23 / cg"
"Modified: 7.3.1997 / 22:41:14 / cg"
!
setupVertical:isVertical mini:miniV horizontal:isHorizontal mini:miniH
"setup scrollbars as specified in the arguments"
|noMiniScrollers|
vScrollBarHidden := hScrollBarHidden := false.
hasVerticalScrollBar := isVertical.
hasHorizontalScrollBar := isHorizontal.
noMiniScrollers := styleSheet at:'scrollBarNeverMini' default:false.
verticalMini := miniV.
verticalMini ifTrue:[
noMiniScrollers ifTrue:[
verticalMini := false
]
].
horizontalMini := miniH.
horizontalMini ifTrue:[
noMiniScrollers ifTrue:[
horizontalMini := false
]
].
self setupViews.
"Modified: 7.3.1997 / 22:09:12 / cg"
!
setupViews
"setup scrollbars as specified in the arguments"
|cls|
hasVerticalScrollBar ifTrue:[
cls := ScrollBar.
verticalMini ifTrue:[
cls := MiniScroller
].
(vScrollBar notNil
and:[vScrollBar class ~~ cls]) ifTrue:[
self releaseVerticalScrollBar
].
vScrollBar isNil ifTrue:[
vScrollBar := cls in:self.
].
vScrollBar thumbOrigin:0 thumbHeight:100.
] ifFalse:[
vScrollBar notNil ifTrue:[
self releaseVerticalScrollBar
]
].
hasHorizontalScrollBar ifTrue:[
cls := HorizontalScrollBar.
horizontalMini ifTrue:[
cls := HorizontalMiniScroller
].
(hScrollBar notNil
and:[hScrollBar class ~~ cls]) ifTrue:[
self releaseHorizontalScrollBar
].
hScrollBar isNil ifTrue:[
hScrollBar := cls in:self.
].
hScrollBar thumbOrigin:0 thumbHeight:100.
] ifFalse:[
hScrollBar notNil ifTrue:[
self releaseHorizontalScrollBar
]
].
scrolledView notNil ifTrue:[
self setScrollActions.
]
"Created: 6.3.1997 / 18:06:23 / cg"
"Modified: 7.3.1997 / 21:54:34 / cg"
! !
!ScrollableView methodsFor:'queries'!
isHorizontalScrollable
"return true if I am horizontally scrollable"
^ hScrollBar notNil
"Modified: 6.3.1997 / 17:03:49 / cg"
"Created: 6.3.1997 / 18:06:23 / cg"
!
isVerticalScrollable
"return true if I am vertically scrollable"
^ vScrollBar notNil
"Modified: 6.3.1997 / 17:03:52 / cg"
"Created: 6.3.1997 / 18:06:23 / cg"
!
preferredExtent
"return my preferredExtent from the scrolledViews prefExtent
plus the size of the scrollBar"
|slavesPref prefX prefY|
"/ If I have an explicit preferredExtent ..
preferredExtent notNil ifTrue:[
^ preferredExtent
].
scrolledView notNil ifTrue:[
slavesPref := scrolledView preferredExtent.
prefX := slavesPref x.
prefY := slavesPref y.
vScrollBar notNil ifTrue:[
prefX := prefX + vScrollBar width + (DefaultScrolledViewMargin * 2) + DefaultScrollBarSpacing.
].
hScrollBar notNil ifTrue:[
prefY := prefY + hScrollBar height + (DefaultScrolledViewMargin * 2) + DefaultScrollBarSpacing.
].
^ prefX @ prefY.
].
^ super preferredExtent.
"Created: 6.3.1997 / 18:06:24 / cg"
"Modified: 6.3.1997 / 22:34:09 / cg"
!
preferredExtentForLines:numLines cols:numCols
"return my preferredExtent from the scrolledViews prefExtent
plus the size of the scrollBar"
|slavesPref prefX prefY|
"/ If I have an explicit preferredExtent ..
preferredExtent notNil ifTrue:[
^ preferredExtent
].
scrolledView notNil ifTrue:[
slavesPref := scrolledView preferredExtentForLines:numLines cols:numCols.
prefX := slavesPref x.
prefY := slavesPref y.
vScrollBar notNil ifTrue:[
prefX := prefX + vScrollBar width + (DefaultScrolledViewMargin * 2) + DefaultScrollBarSpacing.
].
hScrollBar notNil ifTrue:[
prefY := prefY + hScrollBar height + (DefaultScrolledViewMargin * 2) + DefaultScrollBarSpacing.
].
^ prefX @ prefY.
].
^ super preferredExtent.
"Created: 6.3.1997 / 18:06:24 / cg"
"Modified: 6.3.1997 / 22:34:30 / cg"
! !
!ScrollableView methodsFor:'slave-view messages'!
clear
scrolledView notNil ifTrue:[scrolledView clear]
"Created: 6.3.1997 / 18:06:24 / cg"
!
doesNotUnderstand:aMessage
"this is funny: all message we do not understand, are passed
on to the scrolledView - so we do not have to care for all
possible messages ...(thanks to the Message class)"
scrolledView isNil ifFalse:[
^ scrolledView perform:(aMessage selector)
withArguments:(aMessage arguments)
].
^ super doesNotUnderstand:aMessage
"Created: 6.3.1997 / 18:06:24 / cg"
"Modified: 6.3.1997 / 18:38:54 / cg"
!
leftButtonMenu
"return scrolledViews leftbuttonmenu"
scrolledView isNil ifTrue:[^ nil].
^ scrolledView leftButtonMenu
"Created: 6.3.1997 / 18:06:24 / cg"
!
leftButtonMenu:aMenu
"pass on leftbuttonmenu to scrolledView"
scrolledView leftButtonMenu:aMenu
"Created: 6.3.1997 / 18:06:24 / cg"
!
middleButtonMenu
"return scrolledViews middlebuttonmenu"
scrolledView isNil ifTrue:[^ nil].
^ scrolledView middleButtonMenu
"Created: 6.3.1997 / 18:06:24 / cg"
!
middleButtonMenu:aMenu
"pass on middlebuttonmenu to scrolledView"
scrolledView middleButtonMenu:aMenu
"Created: 6.3.1997 / 18:06:24 / cg"
!
model
"return my scrolledViews model"
scrolledView isNil ifTrue:[^ nil].
^ scrolledView model
"Modified: 1.3.1997 / 01:38:07 / cg"
"Created: 6.3.1997 / 18:06:24 / cg"
!
model:aModel
"forward model change to my scrolledViews"
^ scrolledView model:aModel
"Modified: 5.6.1996 / 17:09:50 / cg"
"Created: 6.3.1997 / 18:06:24 / cg"
!
rightButtonMenu
"return scrolledViews rightbuttonmenu"
scrolledView isNil ifTrue:[^ nil].
^ scrolledView rightButtonMenu
"Created: 6.3.1997 / 18:06:24 / cg"
!
rightButtonMenu:aMenu
"pass on rightbuttonmenu to scrolledView"
scrolledView rightButtonMenu:aMenu
"Created: 6.3.1997 / 18:06:24 / cg"
! !
!ScrollableView class methodsFor:'documentation'!
version
^ '$Header: /cvs/stx/stx/libwidg/Attic/ScrView.st,v 1.54 1997-03-19 15:43:47 stefan Exp $'
! !