Contents

Class ScrollController


Inheritance:

Object  »
  Controller  »
    MouseMenuController  »
      ScrollController

This controller implements control for vertical scrolling using a scrollBar. It is a MouseMenuController that creates a scrollBar, rather than menus. The subclasses add the button menus. This controller keeps control as long as the cursor is inside the view or the scrollBar area.

Squeak follows the tradition of Smalltalk-80 to display a scrollbar only for as long as the view is active. The vertical scrollbar of an active window is placed to the left of the window - where most of the text is. In virtually all currently used windowing systems the scrollbars are permanently displayed. The advantage of the display-on-activation policy is that it is not necessary to keep a possibly great number of scrollbars up-to-date.

A Workspace with a Scrollbar on the Left

A scrollBar is a rectangular area representing the length of the information being viewed. It contains an inner rectangle - the marker - whose top y-coordinate represents the relative position of the information visible on the screen with respect to all of the information, and whose size represents the relative amount of that information visible on the screen. The user controls which part of the information is visible by pressing the red (left-most) button. If the cursor is to the right of the inner rectangle (in the 'scroll up' area), the window onto the visible information moves upward, if the cursor is to the left (in the 'scroll down' area), the window moves downward, and if the cursor is inside, the inner rectangle is grabbed and moved to a desired position.

The subclass ListController modifies scrolling for list views; the subclass ParagraphEditor modifies scrolling for text views.

Instance Variables:

The Mathematics of Scrolling

The following diagram shows a scrollbar with its marker and the document with its currently visible part:

The Scrollbar and the Scrolled Document

The useable height of the scrollbar is scrollbar inside height, the height of the marker is marker height. The marker is always entirely visible in the scrollbar, its possible offsets from the origin of the scrollbar are in the range

0 to: scrollbar inside height - marker height

The height of the entire document is view  boundingBox height, the height of the display field is view window height. The possible offsets of the visible part of the document from the origin of the document are in the range

0 to: view boundingBox height - view window height

The Computation of the Marker Height

By convention, the marker height represents the relative amount of information that is visible display field of the window. This is expressed by the following equation:

     marker height             view window height
 -----------------------  =  -----------------------
 scrollbar inside height     view boundingBox height

For the height of the marker we obtain (in method computeMarkerRegion):

((view window height asFloat /
      view boundingBox height *
        scrollBar inside height
 )
      rounded min: scrollBar inside height)

For efficiency reasons, the computation is performed with floats. The result is rounded because an integer height is needed. The final

<...> min: scrollBar inside height

limits the maximal height of the marker to the useable height of the scrollbar.


These are obtained by:
alfa :=
  (marker top - scrollbar top /(scrollbar height - marker height)) rounded

The Scroll Algorithm

Scrolling is implemented with the support of class WindowingTransformation. WindowingTransformation>>scrollBy:

Mandatory Protocol of Views that use Scrolling

To use scrolling, a view has to use a subclass of ScrollController as its controller. Such views have to implement these instance methods:

Important Instance Methods:


Contents