About Scrolling
Volume Number: 5
Issue Number: 4
Column Tag: C Workshop
Related Info: Quickdraw
All About Scrolling Windows
By John A. Nairn, Salt Lake City, UT
A Scrolling Manager: Why and How to Scroll
The Macintosh user interface is based on windows. Windows provide a solution to
the problem of keeping track of much information on a single computer screen. Each
window can be structured to contain a single document. By document, I mean a logically
connected set of text, graphics, or text and graphics that provides the working
environment for a particular application. By the process of activating a window which
brings that window to the foreground, the user can work on the document in that
window. While working in one window, the contents of deactivated windows are within
easy reach - a mouse click away.
Because the physical size of a window is limited to the physical size of the
computer screen, a common occurrence will be that the document is larger than the
window. In this situation, the window will only be able to display a portion of the
document. The window based interface would fail if it were not possible to relocate the
window and to display different portions of the document. The task of relocating
windows or rather of repositioning documents behind windows is accomplished by
scroll bars. Two scroll bars are required - a vertical scroll bar for scrolling the
window contents up or down and a horizontal scroll bar and for scrolling the window
contents left or right.
Figure 1. Scrollbars and Toolbars
While scroll bars are an important user interface feature, like many other
Macintosh features, their implementation is less than trivial. My first attempt at
using scroll bars was a time consuming process. Aided by an excellent book (C
Programming Techniques for the Macintosh™ by Z. R. Mednieks and T. M. Schilke) and
after much trial and error, I was able to work out the kinks of window scrolling. My
second attempt was much easier and remarkable similar to the first attempt. After a
few more attempts, I decided it was time to generalize the scrolling routines to elevate
inclusion of scrolling in applications to the trivial matter that it ought to be.
My efforts aimed at generalizing window scrolling have been developed into a
scrolling manager. Using the scrolling manager and relatively few lines of code any
window can be converted into a scrolling window. The window can have both vertical
and horizontal scroll bars. The contents of the window can be graphic (i.e. application
defined) or can contain a Text Edit record. Using the scrolling interface described in
the next section, the scrolling manager supports tool bars and rulers. Additional
features include automatic scrolling while selecting, drag scrolling, joy-stick
scrolling, and automatic tracking of the selection point. This article will describe the
development and use of the scrolling manager and illustrate its capabilities with a
demonstration application.
A Scrolling Interface
The document window in the figure illustrates the important objects for the
scrolling interface supported by the scrolling manager. The objects include vertical
and horizontal scroll bars, tool bars, and rulers. The functions and the placement of
each of these objects will be discussed in this section.
In virtually all applications, the horizontal scroll bar is along the bottom of the
window with the right edge touching the size box in the lower right-hand corner of the
window. Typically, the horizontal scroll bar extends the full width of the window with
the left edge of the scroll bar touching the left edge of the window. Some applications
stop the horizontal scroll bar before the left edge and leave a scroll bar margin which
is used for some application-defined purpose (See figure). The scrolling interface
defined by the scrolling manager supports horizontal scroll bars with one end touching
the size box and the other end stopping an application-defined margin from the left
edge of the window.
Vertical scroll bars are universally along the right edge of the window. In analogy
with horizontal scroll bars, the scrolling manager supports vertical scroll bars whose
bottom touches the size box and whose top stops at an application-defined margin from
the top of the window.
The function of the scroll bars should be second nature to all experienced
Macintosh users and will not be discussed at length here. In brief, the arrows scroll
one line at a time, the gray regions between the arrows and the scroll box scroll one
“page” (i.e. one window full) at a time and by dragging the scroll box, you can scroll
to any position in the document.
Some applications (e.g. MacDraw™) incorporate tool bars along the edge of their
windows. The tool bar areas are static areas that do not scroll as the contents of the
rest of the window scrolls. While the most common use of tool bars will be to provide
tools for the user, they can be used to display any static information that is meaningful
to a particular application.
The scrolling manager supports vertical and/or horizontal tool bars. The vertical
tool bar is a static area of application-defined width along the left edge of the window
extending from the top of the window to the top of the horizontal scroll bar. The
horizontal tool bar of application-defined height is along the top of the window and
extends from the left edge of the window to the left edge of the vertical scroll bar.
Another common feature of in windows is rulers. Rulers are typically used in
graphics applications to mark and measure position within a drawing. When scrolling
occurs, the rulers should sometimes scroll and sometimes remain stationary. Consider
for example a vertical ruler. As the window is scrolled in the vertical direction, the
ruler should scroll along with the window contents. But, when horizontal scrolling
occurs, the ruler should remain stationary otherwise it might scroll out of view.
Likewise, horizontal rulers should scroll in the horizontal direction but remain
stationary during vertical scrolling.
The scrolling manager supports vertical and/or horizontal rulers. The vertical
ruler is of application-defined width and is just to the right of the vertical tool bar.
The horizontal ruler is of application-defined height and is just below the horizontal
tool bar.
The contents of rulers are not restricted to ruler markings. The ruler area, for
example, might also include row and column labels in spreadsheet software. In terms
of scrolling, row and column labels are logically equivalent to vertical and horizontal
rulers. During vertical or row scrolling, row labels, just as vertical rulers, should
scroll along with the window contents. During horizontal or column scrolling, the row
labels, again just as vertical rulers, should remain stationary.
The last scrolling object is the content region which is the area of the window left
for the document after removing the areas occupied by the size box, the scroll bars,
the tool bars, and the rulers. In any scrolling window, the content region will be
rectangular.
The scrolling objects defined in this section comprise a workable user-interface
for scrolling windows. We note that the windows in virtually all Macintosh
applications can be described by using some subset of these scrolling objects. The
scrolling in all these applications could therefore be handled using the scrolling
manager.
Scrolling in some applications could not be handled with the scrolling manager
because those applications select “unusual” locations for scrolling objects. In Adobe™
Illustrator, for example, the rulers appear adjacent to the scroll bars rather than
adjacent to the tool bars. Rulers in the position I described, however, would be equally
functional to rulers located elsewhere. I therefore see no compelling reason for
choosing a variety of ruler locations in a variety of different applications. It can be
argued instead, that the user should be provided with a consistent scrolling interface.
By providing specific locations for scroll bars, tool bars, and rulers, the scrolling
manager attempts to provide a consistent scrolling interface.
The scrolling manager was developed to be stable with respect to all subsets of
scrolling objects. Although this stability includes subsets lacking one or even both
scroll bars, I view the use of less then the full complement of scroll bars a violation
(albeit a mild one) of the Macintosh user interface. When an application does not
provide scroll bars, the user is limited in his options as to the size of the document
window. If the window is made too small, the user will not be able to view the entire
document without the inconvenience of resizing the window. In short the user’s desktop
ceases to be efficiently customizable to fit all user’s needs. Before MultiFinder,
limitations on window sizes were not very severe. But under MultiFinder, with the
possibility of many open windows, the user may have valid reasons for resizing
windows in ways not envisioned be developers of specific applications. I therefore
suggest that all document windows, no matter what their contents, should include both
vertical and horizontal scroll bars.
ScrollInfo Record
To operate window scrolling, the scrolling manager needs to know which scroll
bars to include, the size and whether or not to include tool bars and rulers, and some
other information related to scrolling. This information is contained in a data
structure of type ScrollInfo which is defined as follows:
/* 1 */
typedef struct {
ControlHandle hScrollHdl;
int horizLines;
int horizLinesVis;
Rect horizScrollRect;
Point hRectTopLeft;
int hScrollMarg;
ControlHandle vScrollHdl;
int vertLines;
int vertLinesVis;
Rect vertScrollRect;
Point vRectTopLeft;
int vScrollMarg;
TEHandle hTE;
long refCon;
} ScrollInfo,*ScrollPtr;
The hScrollHdl and vScrollHdl fields are handles for the scroll bars. Although as
discussed in the introduction, it is recommended that all windows use both scroll bars,
the scrolling manager will support windows with one or even with no scroll bars.
When a scroll bar is absent, its handle field is set to NIL.
The horizLines and vertLines fields specify the total number of lines in the
document. This information is needed to set the range of the scroll bars.