Scrolling Windows PP
Volume Number: 11
Issue Number: 12
Column Tag: Getting Started
PowerPlant and Scrolling Windows 
By Dave Mark, MacTech Magazine Regular Contributing Author
Note: Source code files accompanying article are located on MacTech CD-ROM orsource code disks.
Due to popular demand, this month’s column returns to the land of CodeWarrior and
PowerPlant. Assuming it’s okay with all of you, I’d like to spend the next few months
really getting to know PowerPlant, instead of hopping back and forth between
PowerPlant, TCL, and Sprocket. Any dissenting opinions? Let me know! As always,
look on page 2 of the magazine to find out how to get in touch with us.
I want to take a moment and thank Greg Dow, the creator of PowerPlant, for all
his help. Greg has never been too busy to answer my questions, and spent a lot of time
making sure I got it right. If you see Greg at MacWorld or at WWDC, thank him and
buy him an Espresso!
Create the PictScroller Project
This month’s program will create windows that look like the one shown in Figure 1.
Notice that the window is divided into two areas. The top area contains two buttons.
The left button beeps when you click on it. The right button is disabled (we’ll change
that in next month’s column). The lower portion of the window contains a PICT, and
the scroll bars allow you to scroll the PICT up and down, left and right. The close box,
zoom box, and size box each work as expected. The PICT is not scaled, and “sticks” to
the upper left corner of the scrolling region. Perhaps the coolest thing about this
program is that dragging the thumb forces the window to update dynamically. In other
words, the window is constantly redrawn as you drag the thumb, unlike a normal
Macintosh window which updates only after the scrollbar’s thumb is released.
Figure 1: A PictScroller window
Let’s get to work.
• Create a folder named PictScroller on your hard drive, anywhere outside of
the CW7 folder.
• Lauch CodeWarrior IDE 1.3. You’ll find it inside the CodeWarrior 7 folder,
inside the Metrowerks CodeWarrior subfolder.
• Create a new project file named PictScroller.µ - be sure you use one of the
two PowerPlant stationery files when you create the project. Select either
PowerPlant 68K.µ or PowerPlant PPC.µ from the Project Stationery
popup menu.
• In the project window that appears, double-click on the file name Source>.cp.
This file is located in the stationery folder. Since we’ll eventually modify this
file and we don’t want our changes reflected in the project stationery, we’ll save a copy
of this file in our working folder.
• Select Save As... from the File menu and save the file as PictScroller.cp in your PictScroller folder.
Notice that the file name actually changed in the project window, showing that
your copy of the file has replaced the stationery file in the project. Our next step is to
change the name of the include file associated with this .cp file.
• Towards the top of the file PictScroller.cp, you’ll find an include file named
.h. Open this file by selecting the file name and typing AppleD.
• Once the file .h opens, select Save As... from the File menu and save it in your PictScroller folder under the name
PictScroller.h.
• Close the file PictScroller.h.
• Back in PictScroller.cp, change the reference .h in the #include to say PictScroller.h instead.
At this point, all of our source code is disconnected from the stationery files.
There is one more stationery dependency left, however, and that is the file Starter Resource>, the default constructor file.
• Back in the project window, double-click on the file named Resource>.rsrc. Though the file contains regular old resources, its creator is
MWC2, the creator type associated with Constructor 2.0.
• In Constructor, select Save As... from the File menu, navigate back over to your PictScroller folder and save the file as PictScroller.rsrc.
• Go back to CodeWarrior and select the file .rsrc in the project window.
• Select Add Files... from the Project menu and add the file PictScroller.rsrc to the project.
• Once again, select .rsrc in the project window. This time, select Remove Files from the Project menu to remove the last stationery file from the project.
We have now made our own copy of the three files we’ll be modifying:
PictScroller.rsrc, PictScroller.cp, and PictScroller.h. Before we make our
changes, let’s take the default project for a spin.
• Select Run from the Project menu. PowerPlant will now compile all of the source code files (the entire PowerPlant
framework) in your project. This took about one minute and 15 seconds on a
PowerMac 8100/100. Your mileage may vary.
It is interesting to note that the completely compiled project file takes up about
1.1 meg of hard drive space, as compared with the more than 10 meg consumed by last
month’s TCL project. Obviously, Symantec stores a lot more project information than
CodeWarrior. Still, a size factor of 10 to 1 is pretty significant. Hey, Rich Parker, do
you know why this is?
• Once the project compiles and runs, select Quit from the File menu. We are now ready to use Constructor to design our custom two-button scrolling
window.
• Go back to Constructor. The file PictScroller.rsrc should still be open.
Figure 2 shows the PictScroller.rsrc Constructor window before we start
messing with it. Constructor handles three different resource types. Views, by far the
most popular type, are what we’ll be working with. Views are Constructor interface
elements designed to act as containers for other Constructor elements. You’ll
frequently encounter the terms view and pane. All visual Constructor elements are
panes. Views are panes that can contain other panes. Don’t get too hung up on the
terminology. It really isn’t important.
Figure 2: The PictScroller.rsrc window, before we make our changes
Text traits allow you to embed TextEdit style information inside a resource,
rather than specifying it programmatically using QuickDraw calls. Think of text
traits as a poor person’s style sheet.
Custom types allow you to create your own custom views, as opposed to the views
that are built into Constructor.
The project stationery came with a single view, an LWindow with a resource ID
of 1 and a name of . This View resource will act as the template for our
two-button scrolling window. Let’s start changing it.
• Make sure the LWindow view is selected, then select Resource Info from the