Print.c

/*------------------------------------------------------------------------------
 *
 *  Apple Developer Technical Support
 *
 *  Printing routines
 *
 *  Program:    AEObject-Edition Sample
 *  File:       Print.c -    C Source
 *
 *  by:         C.K. Haun <TR>
 *
 *  Copyright © 1990-1992 Apple Computer, Inc.
 *  All rights reserved.
 *
 *------------------------------------------------------------------------------
 * This file does the printing for this application.  VERY minimal
 *----------------------------------------------------------------------------*/
 
#define __PRINTSTUFF__
 
 
 
#include "Sampdefines.h"
/* prototypes */
 
 
#pragma segment Print
 
 
/* external references */
 
/* PrintIt prints the window passed to it.  The Boolean tells the function */
/* what to do when printing is finished.  This is in place if Print was selected */
/* from the Finder, the window will be closed after it's been printed */
/* and the application will exit */
/* ¥Note:  As you can see, I don't use the Boolean.  The Finder does what it */
/* should, and quits us itself after a Finder print, so it is no longer necessary */
/* I've left it in here so past users of EditionSample can see why the change was made */
 
void PrintIt(WindowPtr theWind,Boolean bye)
{
#pragma unused(bye)
    THPrint myPrintRec;
    TPPrPort myPrintPort;
    TPrStatus myStats;
    extern Boolean gShowPub;
    extern Boolean gShowSub;
    extern Boolean gShowingAll;
    Boolean temp1, temp2, temp3;
    windowCHandle drawers;
    temp1 = gShowPub;
    temp2 = gShowSub;
    temp3 = gShowingAll;
    gShowPub = gShowSub = gShowingAll = false;
    drawers = (windowCHandle)GetWRefCon(theWind);
    HLock((Handle)drawers);                                 /* lock it down so things don't get stupid */
    PrOpen();
    myPrintRec = (THPrint)NewHandle(sizeof(TPrint));
    PrintDefault(myPrintRec);
    if (PrJobDialog(myPrintRec)) {
        myPrintPort = PrOpenDoc(myPrintRec, nil, nil);
        PrOpenPage(myPrintPort, nil);
        /* jump to the drawing function stored for this window */
        (ProcPtr)((*drawers)->drawMe)(drawers, theWind);
        /* that doesn't draw the text, by the way.  TEUpdate doesn't draw text the way you might think */
        if((*drawers)->boxHandle){
        Handle theText = TEGetText((*drawers)->boxHandle);
        Size theSize = GetHandleSize(theText);
        Rect theRect = (*(*drawers)->boxHandle)->destRect;
        TextFont(monaco);
        TextSize(9);
        HLock(theText);
        TETextBox((Ptr)*theText,theSize,&theRect,0);
        HUnlock(theText);
        
        }
        HUnlock((Handle)drawers);                           /* all done */
        PrClosePage(myPrintPort);
        PrCloseDoc(myPrintPort);
        PrPicFile(myPrintRec, nil, nil, nil, &myStats);
    }
    DisposeHandle((Handle)myPrintRec);
    PrClose();
    gShowPub = temp1;
    gShowSub = temp2;
    gShowingAll == temp3;
}
 
 
#undef __PRINTSTUFF__