|
Class: ViewScroller
Object
|
+--GraphicsMedium
|
+--DisplaySurface
|
+--SimpleView
|
+--ViewScroller
- Package:
- stx:libwidg2
- Category:
- Views-Basic
- Version:
- rev:
1.60
date: 2023/07/06 14:36:52
- user: cg
- file: ViewScroller.st directory: libwidg2
- module: stx stc-classLibrary: libwidg2
This wrapper view allows scrolling of views (in contrast to scrolling
of contents which can be done by any view).
Normally, scrolling is done by putting a view into a ScrollableView (which
simply wraps the scrollbars around) and have the scrollbars send scrollUp:/
scrollDown: etc. send to the scrolledView.
The default implementation of scrolling (in View) modifies the transformation,
and does a bit-copy of the contents with redraw of the exposed area.
However, there are situations, where you want to scroll a view itself.
For example, if you need many buttons in a panel, which do not fit.
This class provides the basic mechanism to implement this.
It is a wrapper, which implements scrolling by modifying the origin of its
single subview when asked to scroll. Thus, it can be put into a ScrollableView
like any other, but will move its subview when asked to scroll instead.
(i.e. reimplement all scroll messages by manipulating its subviews origin
instead of its contents' transformation offset)
The subview should have a constant extent, which will be taken for the
scrollbar position/height computation.
Since the subview is represented directly by the underlying window systems view
implementation, there may be a limit on the maximum size of that view. For
example, in X, dimensions may not be larger than 32767 pixels.
[Instance variables:]
model <ValueHolder> the model which keeps the current scrolledView.
keepViewsChannel <ValueHolder> boolean holder; if the value is false (the default),
the previous scrolled view is destroyed, whenever a
new scrolled view is set. If true, it is unmapped and
kept.
Set this flag, if the application changes the scrolled
view but wants them to be kept for fast switching.
horizontalScrollStep <SmallInteger> amount to scroll when stepping left/right in pixels
verticalScrollStep <SmallInteger> amount to scroll when stepping up/down in pixels
frame <SimpleView> the one and only container of the visible scrolledView
and all invisible scrolledViews if existent.
scrolledView <SimpleView | nil> the current scrolled view or nil
copyrightCOPYRIGHT (c) 1994 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.
accessing
-
destroyAllClientViews
-
destroy all client views
-
keepViews
-
returns the value of the boolean channel: keepViewsChannel.
for more information see: #keepViewsChannel
-
keepViews: aBool
-
set the value of the boolean channel: keepViewsChannel.
for more information see: #keepViewsChannel:
-
resizeScrolledViewHorizontal
-
-
resizeScrolledViewHorizontal: aBoolean
-
if true, the scrolled view is actually NOT scrolled horizontally,
but instead always resized to fit.
Set this, if only vertical scrollability is wanted (i.e. the view
itself does adjust its size horizontally (for example, in a settings dialog,
the subcanvas to be enbedded has a horizontal panel, taking all of the space)
-
resizeScrolledViewVertical
-
-
resizeScrolledViewVertical: aBoolean
-
if true, the scrolled view is actually NOT scrolled vertically,
but instead always resized to fit.
Set this, if only horizontal scrollability is wanted (i.e. the view
itself does adjust its size vertically (for example, in a settings dialog,
the subcanvas to be enbedded has a vertical panel, taking all of the space)
-
scrolledView
-
return the view which is scrolled
-
scrolledView: aView
-
set a new scolled view; dependent on the #keepViewsChannel
the old scolled view will be destroyed or unmapped.
-
scrolledViews
-
Returns the collection of all scrolled views including the current scrolled view
and all unmapped scrolled views.
accessing-channels
-
keepViewsChannel
-
boolean holder; if the value is false (the default), the previous scrolled view is
destroyed, whenever a new scrolled view is set. if true, it is unmapped and kept.
Set this flag, if the application changes the scrolled view but wants
them to be kept for fast switching.
-
keepViewsChannel: aHolder
-
boolean holder; if the value is false (the default), the previous scrolled view is
destroyed, whenever a new scrolled view is set. if true, it is unmapped and kept.
Set this flag, if the application changes the scrolled view but wants
them to be kept for fast switching.
-
model
-
value holder, which keeps the current scrolledView or nil
-
model: aHolder
-
value holder, which keeps the current scrolledView or nil
accessing-look
-
horizontalScrollStep: something
-
set the value of the instance variable 'horizontalScrollStep' (automatically generated)
-
verticalScrollStep: something
-
set the value of the instance variable 'verticalScrollStep' (automatically generated)
change & update
-
resizeScrolledView
-
forces a recomputation of the scrolled view's size
-
update: something with: aParameter from: changedObject
-
update possible scrollers
delegation
-
viewBackground: aColor
-
(comment from inherited method)
set the viewBackground to something, a color, image or form.
If it's a color and we run on a color display, also set shadow and light
colors - this means, that a red view will get light-red and dark-red
edges.
event handling
-
processEvent: anEvent
-
Intercept mouseWheel events in the scrolled view.
Return true, if the event was eaten.
-
repositionScrolledView
-
Reposition the scrolledView, if required
-
sizeChanged: how from: oldExtentOrNil
-
my view has changed the size;
Reposition the scrolledView, if required
focus handling
-
canTab
-
initialization & release
-
destroy
-
(comment from inherited method)
unmap & destroy - make me invisible, destroy subviews then
make me unknown to the device
-
initialize
-
initialize all models of the view
-
realize
-
(comment from inherited method)
realize - make visible;
realizing is done very late (after layout is fixed) to avoid
visible rearranging of windows on the screen
-
release
-
release all dependencies
queries-contents
-
heightOfContents
-
return my contents' height; this is the scrolledViews height
-
viewOrigin
-
the viewOrigin (for scrollBars) is based upon the scrolledView's origin
-
widthOfContents
-
return my contents' width; this is the scrolledViews width
scrolling
-
horizontalScrollStep
-
return the amount by which to step-scroll horizontally
-
scrollTo: aPoint redraw: doRedraw
-
change origin of scrolledView to scroll to aPoint
-
verticalScrollStep
-
return the amount by which to step-scroll vertically
scroll a panel of buttons:
|top frame vscroller v panel|
top := StandardSystemView new.
top extent:100@400.
frame := ScrollableView for:ViewScroller in:top.
frame origin:0.0 @ 0.0 corner:1.0 @ 1.0.
vscroller := frame scrolledView.
panel := VerticalPanelView new.
panel horizontalLayout:#fit.
1 to:100 do:[:i |
Button label:(i printString) in:panel
].
vscroller scrolledView:panel.
top open.
|
same, defining what a scroll step is:
|top frame vscroller v panel|
top := StandardSystemView new.
top extent:100@400.
frame := ScrollableView for:ViewScroller in:top.
frame origin:0.0 @ 0.0 corner:1.0 @ 1.0.
vscroller := frame scrolledView.
vscroller verticalScrollStep:20.
panel := VerticalPanelView new.
panel horizontalLayout:#fit.
1 to:100 do:[:i |
Button label:(i printString) in:panel
].
vscroller scrolledView:panel.
top open.
|
same, horizontally. Also change layout in panel for nicer look
and make panel adjust its height:
(since the buttons are defined to fill vertically, the vertical
scrollbar is useless here - its here as example; not for its function)
|top frame vscroller v panel|
top := StandardSystemView new.
top extent:300@100.
frame := HVScrollableView for:ViewScroller in:top.
frame origin:0.0 @ 0.0 corner:1.0 @ 1.0.
vscroller := frame scrolledView.
panel := HorizontalPanelView new.
panel verticalLayout:#fit.
panel horizontalLayout:#fit.
1 to:100 do:[:i |
Button label:(i printString) in:panel
].
vscroller scrolledView:panel.
panel height:1.0.
top open.
|
scroll a panel of buttons and other views:
(not good looking, but a demo that it can be done ...)
|top frame vscroller v panel textView1 textView2|
top := StandardSystemView new.
frame := HVScrollableView for:ViewScroller in:top.
frame origin:0.0 @ 0.0 corner:1.0 @ 1.0.
vscroller := frame scrolledView.
panel := VerticalPanelView new.
panel horizontalLayout:#leftSpace.
panel extent:1.0@1.0.
textView1 := ScrollableView for:EditTextView in:panel.
textView1 extent:1.0 @ 300.
textView1 scrolledView contents:('keyboard.rc' asFilename readStream contents).
textView2 := ScrollableView for:EditTextView in:panel.
textView2 extent:500 @ 300.
textView2 scrolledView contents:('Make.proto' asFilename readStream contents).
1 to:100 do:[:i |
Button label:(i printString) in:panel
].
vscroller resizeScrolledViewHorizontal:true.
vscroller scrolledView:panel.
top open.
|
|