Print Dialog
Volume Number: 2
Issue Number: 12
Column Tag: Basic School
Introduction to Print Dialogs
By Dave Kelly, MacTutor Editorial Board
Exploring the Printing Manager
This month we'll explore the Macintosh Printing Manager. The Printing
Manager is a set of RAM-based routines that allow you to use standard Quickdraw
routines to print text or graphics on a printer. Take a look at Inside Macintosh for
details on the Printing Manager (starting on page II-147). Then when you're
thoroughly confused, come back here and I'll try to clarify some points by example.
The examples that I've prepared here are written in ZBasic and Lightspeed
Pascal. The pascal example is included to help clarify how the Printing Manager is
actually used. ZBasic routines call parts of the Printing Manager to enable you to have
some control over your graphics or text output. However, ZBasic does not give you full
support even though it does support the Printing Manager in more specific ways than
does MS Basic as of this writing. ZBasic Toolbox calls DO NOT support the Printing
Manager routines (i.e., they are not available). Also, we've found that the ZBasic
example here does not work as cleanly as the Pascal example, so we invite our readers
to compare the two and try some alternative Basic approaches to improve its
performance.
In ZBasic there is a short list of commands available to us which pertain to the
Printing Manager (Found on page D-58 thru D-63 in the ZBasic manual). They are:
DEF LPRINT: this command calls up the job dialog box so the user may select the
page range, print quality, etc.
DEF PAGE: this command calls up the page setup dialog box. The user selects the
paper size and orientation via this dialog.
PRCANCEL: this function returns a true when the user has pressed the cancel
button in the job dialog box (called with DEF LPRINT.
PRHANDLE: this function returns a pointer to the print record created by the
Printing Manager. By using PEEK WORD (two byte peek) the records may be examined
and important information can be read (see ZBasic manual page D-62).
ROUTE X: this statement routes the output of all printing to a specified device X.
ROUTE 0 sends output to the screen; ROUTE 128 sends output to the printer driver.
(Note Route 0 does not seem to effect the Printing Manager).
CLEAR LPRINT: abruptly closes the printer driver. If you haven't printed
anything, a single sheet of paper (blank) is fed out of the printer.
Fig. 1 Our sample shows print record info
The whole idea of the Printing Manager is to have one set of printing routines
that are independent of the type of printer used, to which all printed output can be sent.
The Printing Manager will select the selected printer driver (must be on the system
disk and chosen by the Chooser desk accessory) and directs the printing operation. The
ROUTE 128 statement directs all output to the specified device, after which whatever
Quickdraw commands are sent will be executed. In ZBasic, the PLOT, CIRCLE, BOX,
COLOR, PEN, PICTURE commands use Quickdraw, and therefore are supported for
printing. At this point, Quickdraw commands sent to the printer are executed the same
as if they were sent to the screen (which you've probably done before). One thing
lacking in the ZBasic implementation is control over the PrOpenDoc, PrOpenPage,
PrClosePage, PrCloseDoc routines as discussed in Inside Macintosh.. Instead the CLEAR
LPRINT command is used to "CLEAR" out all the impending printing. I'm not sure
exactly which routines the CLEAR LPRINT statement actually calls.
The PRHANDLE command returns a handle to the Printing Manager record. It
should be noted that until the Printing Manager is opened, the record will contain
whatever random garbage was located in the memory allocated for the print record. You
must open the print manager by using DEF PAGE or DEF LPRINT. Then the PRHANDLE
function may be used. The document and page is opened when the DEF LPRINT statement
is executed. The ZBasic manual does not give more than an example to indicate the
parameters which are returned by PEEKing into the print record memory locations.
The actual parameters are explained in detail in Inside Macintosh.. I attempted to
duplicate the data referred to in the ZBasic manual (pg. D-62) in the Pascal program.
I found that it was not hard to follow the data, but there were a few mistakes in the
ZBasic implementation. Both the printer port and the printer type parameters did not
seem to function properly. These parameters are labeled in the demo program. It
should also be noted that until a document is printed the printing record does not
contain the correct information (appears to be random stuff). After printing, the data
appears to be mostly correct except for those noted. The pascal program gave correct
results every time (before and after printing). I have no explanation for why ZBasic
does not behave like Pascal except that this may indicate another area that needs
debugging for Zedcor so beware.
The ZBasic demo demonstrates a technique in using the printing manager from
your Zbasic application. The program opens the printing manager using the DEF
LPRINT statement and then prints the print record parameters (as outlined in the
ZBasic manual), after which a Quickdraw command is given to draw a box around the
page. The page size was determined from the print parameters. A helpful command to
use was the COORDINATE command. Notice that the coordinates of the page were used as
the coordinates for the quickdraw drawing rectangle (the Grafport) by using the
following statement: COORDINATE PEEK WORD(P+28),PEEK WORD(P+26) which
reads the page size from the printing record. If your printed output will use fonts, etc.,
you may want to know the page size so you know where to place the characters on the
page.
Lightspeed Pascal shows you how the Printing Manager is really used. It should
be helpful to walk through the setup of the Pascal procedures in order to understand the
Printing Manager better. First off for those just beginning or not familiar with
Lightspeed Pascal, you must create a new project and add the PrLink and MacPrint
routines from the Resource folder on the Lightspeed Pascal system disk. These are the
routines which will be loaded into RAM when the Printing Manager is opened. Of
course, the other Macintosh Toolbox calls are automatically included in the new
project. Next, the file containing the Pascal program below must be added to the
project. For those using another Pascal or language, note that PrLink is Apple's Print
Manager interface that is released only in object file format. However, Paul Snively