Scrollbars XCMD
Volume Number: 5
Issue Number: 3
Column Tag: HyperChat™
Related Info: Control Manager Quickdraw
XCMD Corner: Window Scrollbars
By Joe Zuffoletto, Apple Computer, Inc.
Note: Source code files accompanying article are located on MacTech CD-ROM or
source code disks.
In Last Month’s Episode...
Last month I showed you how to write an event-driven XCMD that displays a
normal Macintosh window on top of HyperCard. I discussed some interesting human
interface issues that come up when you do this, and I demonstrated how to communicate
with HyperCard from an XCMD in order to do window updates and other “human
interface maintenance” tasks. I also used the XCMD as a springboard for illustrating
more general techniques, including how to be MultiFinder aware, how to do cursor
tracking under MultiFinder, and how to cope elegantly with multiple-screen
environments. Finally, I gave the window scroll bars that didn’t work, and I promised
to “breathe life into them” this month, which I will do by adding code to the XCMD that
takes a “snapshot” of the current card and displays it in the window. We can then
scroll around and admire the snapshot until we either get bored, learn about scrolling,
or both!
Scroll Bars!
The scroll bars are here!
The scroll bars are here!
Why should I care?
People have been scrolling for years....
Yes, but few people have taken the time and effort to explain scrolling to neophyte
Mac programmers, who must either figure it out themselves, copy code from someone
else, or avoid it completely. Why is this? I have a simple theory: People are ashamed
of their scrolling code. In fact, some people might be afraid of their scrolling code.
Scrolling code is ugly. It consists of gobs of source riddled with special cases and
questionable algorithms. Nobody has found an elegant way to do it, so nobody wants to
show their version of it to anybody else.
On top of all this, scrolling is implemented differently depending on the type of
document being scrolled, be it bitmapped graphics, object-oriented graphics, text,
icon lists, etc. While the basic rules stay the same, the special cases change and often
multiply. Therefore, learning everything there is to know about scrolling is a daunting
task indeed.
I certainly don’t know everything about scrolling, but I know enough to get you
started if you’ve never done it before, and I can touch on a few fundamentals that may
help you improve your scrolling code if you’ve written some already. In this article I
will show how to scroll bitmapped graphics documents, including how to set up and
manage an offscreen bitmap for fast, flicker-free scrolling. I will assume we have a
static document that cannot be edited or moved around inside its window. I leave these
more challenging cases as proverbial exercises for the reader.
If you haven’t done so already, read the Control Manager chapter of Inside
Macintosh, Volume I so I don’t have to explain the Toolbox software behind controls. I
will repeat some of the general material in that chapter, but I will not go into the data