#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include #include #define dQuit 132 #define iQuitTitle 1 #define iQuitIcon 2 #define iQuitText 3 #define iQuitYes 4 #define iQuitNo 5 #define dIError 129 #define iIErrorTitle 1 #define iIErrorValue 5 #define iIErrorOk 3 #define iIErrorCancel 4 #define iIErrorText 6 #define mFile 129 #define iPref 1 #define iPrintSetup 6 #define iPrint 7 #define iQuit 9 #define iDup 3 #define iFinal 4 #define dFinal 128 #define iFinalTitle 1 #define iFinalNo 2 #define iFinalYes 3 #define dDup 129 #define iDupTitle 1 #define iDupOk 2 #define iDupPickText 3 #define iDupText 4 WindowPtr gWindowPtr; THPrint gTPrintHdl; Handle gTextHdl; PicHandle gPictureHdl; Boolean gPrintStructureInited = false; Boolean gInhibitPrintStructuresInfo = false; SInt32 gFirstAppendedItemNo; PItemUPP gOldItemEvaluateFunctionUPP; PItemUPP gNewItemEvaluateFunctionUPP; SInt16 gFontNumber; SInt16 gFontSize; RGBColor gWhiteColour = { 0xFFFF, 0xFFFF, 0xFFFF }; RGBColor gBlackColour = { 0x0000, 0x0000, 0x0000 }; RGBColor gBlueColour = { 0x1818, 0x4B4B, 0x8181 }; TEHandle gEditRecHdl; FILE *f; TPPrDlg gTPrDlgStructurePtr; PDlgInitUPP gInitializationFunctionUPP; PItemUPP gNewItemEvaluateFunctionUPP; ModalFilterUPP gEventFilterUPP; #define rText 128 #define rPicture 128 #define rJobDialogAppendDITL 128 #define iPopupButton 1 #define iRadioButton10pt 2 #define iRadioButton12pt 3 #define iRadioButton14pt 4 #define iCheckboxFracWidths 5 #define kMargin 90 #define MIN(a,b) ((a) < (b) ? (a) : (b)) //OSErr doCreatePrintRecord (void); void main (void); void doInitManagers (void); void doEvents (EventRecord *); void doUpdate (EventRecord *); void doMenuChoice (long); void doPrinting (void); OSErr doCreatePrintRecord (void); void doPrStyleDialog (void); SInt16 doCalcNumberOfPages (Rect); void doDrawPage (Rect,SInt16,SInt16); SInt16 doGetPageOrientation (void); Boolean doIsPrGeneralThere (void); void doPrintRecordsInfo (void); void doDrawRectStrings (Str255,SInt16,SInt16,Str255,SInt16,SInt16,Str255); void doDrawPageOrientation (void); void doErrorAlert (SInt16,Boolean); void doConcatPStrings (Str255,Str255); void doPrintSetup (void); pascal Boolean eventFilter(DialogPtr, EventRecord *, SInt16 *); pascal TPPrDlg initialisationFunction (THPrint); void doAppendTheDITL (TPPrDlg); pascal void itemEvaluationFunction (TPPrDlg, SInt16); pascal Boolean OurFilter(DialogPtr, EventRecord *, short *); pascal Boolean OurFilter(DialogPtr dlg, EventRecord *event, short *itemHit) { return false; } void main(void) { TPrint **print; TPrPort *printPort; Rect rect; SInt16 printError; Handle iHandle, mBarHandle; int AllDone =0; EventRecord theEvent; long mChoice; short theMenu,theMenuItem,done,thePart; Rect iRect; Str255 theItem,theText; MenuHandle mHandle; Point thePoint; DialogPtr TheDialog; WindowPtr aWindow; short itemHit, itemHit2; OSErr theErr; MaxApplZone(); MoreMasters(); InitGraf (&qd.thePort); InitFonts(); InitWindows(); InitMenus(); TEInit(); InitDialogs(NULL); InitCursor(); FlushEvents(everyEvent,0); // RegisterAppearanceClient(); // Gestalt(gestaltColorPickerVersion, version); // AEInstallEventHandler(kCoreEventClass,kAEQuitApplication,doQuitAppEventUPP, 0L, false); // PrClose; gTextHdl = GetResource('TEXT', rText); gPictureHdl = GetPicture(rPicture); mBarHandle = GetNewMBar(128); SetMenuBar(mBarHandle); DrawMenuBar(); AllDone=1; while (AllDone==1) { WaitNextEvent(everyEvent, &theEvent, 0L, 0L); switch(theEvent.what) { case mouseDown: GetMouse(&thePoint); thePart = FindWindow(theEvent.where, &aWindow); switch (thePart) { case inMenuBar: mChoice = MenuSelect(theEvent.where); if (mChoice > 0) { theMenu=HiWord(mChoice); theMenuItem=LoWord(mChoice); switch(theMenu) { case mFile: switch(theMenuItem) { case iPref: SysBeep(1); break; case iPrintSetup: doPrintSetup(); break; case iPrint: doPrinting(); break; case iQuit: SysBeep(1); itemHit = 0; //ok = iQuitYes; TheDialog=GetNewDialog(dQuit,nil, (WindowPtr)-1); do { theErr = SetDialogDefaultItem(TheDialog, iQuitNo); ModalDialog(NewModalFilterProc(OurFilter), &itemHit); if (itemHit == iQuitNo) break; else if (itemHit == iQuitYes) { fclose(f); AllDone = 0; break; } } while ((itemHit != iQuitYes) || (itemHit != iQuitNo)); break; case iDup: itemHit = 0; //ok = iQuitYes; TheDialog=GetNewDialog(dDup,nil, (WindowPtr)-1); do { theErr = SetDialogDefaultItem(TheDialog, iDupOk); ModalDialog(NewModalFilterProc(OurFilter), &itemHit); // if (itemHit == iDupNo) // break; if (itemHit == iDupOk) { break; } } while (itemHit != iDupOk); break; case iFinal: itemHit = 0; //ok = iQuitYes; TheDialog=GetNewDialog(dFinal,nil, (WindowPtr)-1); do { theErr = SetDialogDefaultItem(TheDialog, iFinalYes); ModalDialog(NewModalFilterProc(OurFilter), &itemHit); if (itemHit == iFinalNo) break; else if (itemHit == iFinalYes) { break; } } while ((itemHit != iFinalYes) || (itemHit != iFinalNo)); break; } //break; break; } HiliteMenu(0); } break; } } } fflush(stdin); fflush(stdout); fclose(f); // return 0; } void doPrintSetup(void) { SInt16 printError; PrOpen(); printError = PrError(); if (printError == noErr) { if (!gPrintStructureInited) { printError = doCreatePrintRecord(); } PrStlDialog(gTPrintHdl); } PrClose(); } void doUpdate(EventRecord *eventStrucPtr) { WindowPtr windowPtr; windowPtr = (WindowPtr) eventStrucPtr->message; BeginUpdate(windowPtr); doPrintRecordsInfo(); EndUpdate(windowPtr); } pascal TPPrDlg initialisationFunction(THPrint hPrint) { ControlHandle controlHdl; MenuHandle menuHdl; SInt16 numberOfItems, a, fontNumber; Str255 fontName; // ........................ append the DITL doAppendTheDITL(gTPrDlgStructurePtr); // ... make pop-up menu WYSIWYG, check second radio button, set fractional widths off // GetDialogItemAsControl((DialogPtr) gTPrDlgStructurePtr,gFirstAppendedItemNo, // &controlHdl); // GetControlData(controlHdl,kControlNoPart,kControlPopupButtonMenuHandleTag, // sizeof(menuHdl),(Ptr) &menuHdl,NULL); numberOfItems = CountMenuItems(menuHdl); for(a=1;a<=numberOfItems;a++) { GetMenuItemText(menuHdl,a,fontName); GetFNum(fontName,&fontNumber); // SetMenuItemFontID(menuHdl,a,fontNumber); } // GetDialogItemAsControl((DialogPtr) gTPrDlgStructurePtr,gFirstAppendedItemNo + 2, // &controlHdl); SetControlValue(controlHdl,1); gFontSize = 12; // GetDialogItemAsControl((DialogPtr) gTPrDlgStructurePtr,gFirstAppendedItemNo + 4, // &controlHdl); SetControlValue(controlHdl,0); SetFractEnable(false); // ........ save old evaluation function and assign new evaluation function gOldItemEvaluateFunctionUPP = gTPrDlgStructurePtr->pItemProc; gTPrDlgStructurePtr->pItemProc = gNewItemEvaluateFunctionUPP; // ................. assign new event filter function gTPrDlgStructurePtr->pFltrProc = gEventFilterUPP; // ...... PrDlgMain expects a pointer to the modified dialog to be returned return gTPrDlgStructurePtr; } void doAppendTheDITL(TPPrDlg theDialog) { Handle ditlHdl; SInt16 numberOfExistingItems; ditlHdl = GetResource('DITL',rJobDialogAppendDITL); numberOfExistingItems = CountDITL((DialogPtr) theDialog); AppendDITL((DialogPtr) theDialog,(Handle) ditlHdl,appendDITLBottom); gFirstAppendedItemNo = numberOfExistingItems + 1; } void doPrinting(void) { GrafPtr oldPort; SInt16 printError; Boolean userClickedOK; SInt16 numberOfPages, numberOfCopies; SInt16 firstPage, lastPage, copy, page; TPPrPort printPortPtr; TPrStatus tprStatus; GetPort(&oldPort); PrOpen(); // if(PrError() == noErr) if(1) { if(!gPrintStructureInited) printError = doCreatePrintRecord(); else printError = noErr; gTPrDlgStructurePtr = PrJobInit(gTPrintHdl); printError = PrError(); if(printError == noErr) { // gInitializationFunctionUPP = NewPDlgInitProc((ProcPtr) initialisationFunction); // gNewItemEvaluateFunctionUPP = NewPItemProc((ProcPtr) itemEvaluationFunction); gEventFilterUPP = NewModalFilterProc((ProcPtr) eventFilter); SysBeep(1); // userClickedOK = PrDlgMain(gTPrintHdl,gInitializationFunctionUPP); userClickedOK = PrJobDialog(gTPrintHdl); DisposeRoutineDescriptor(gInitializationFunctionUPP); DisposeRoutineDescriptor(gNewItemEvaluateFunctionUPP); DisposeRoutineDescriptor(gEventFilterUPP); if(userClickedOK) { gInhibitPrintStructuresInfo = true; numberOfPages = doCalcNumberOfPages((*gTPrintHdl)->prInfo.rPage); numberOfCopies = (*gTPrintHdl)->prJob.iCopies; firstPage = (*gTPrintHdl)->prJob.iFstPage; lastPage = (*gTPrintHdl)->prJob.iLstPage; (*gTPrintHdl)->prJob.iFstPage = 1; (*gTPrintHdl)->prJob.iLstPage = iPrPgMax; if(numberOfPages < lastPage) lastPage = numberOfPages; for(copy=1;copyprJob.bJDocLoop == bSpoolLoop) && (PrError() == noErr)) PrPicFile(gTPrintHdl,NULL,NULL,NULL,&tprStatus); } printPortPtr = PrOpenDoc(gTPrintHdl,NULL,NULL); } if(PrError() == noErr) { PrOpenPage(printPortPtr,NULL); if(PrError() == noErr) doDrawPage((*gTPrintHdl)->prInfo.rPage,page,numberOfPages); PrClosePage(printPortPtr); } } PrCloseDoc(printPortPtr); if(((*gTPrintHdl)->prJob.bJDocLoop == bSpoolLoop) && (PrError() == noErr)) PrPicFile(gTPrintHdl,NULL,NULL,NULL,&tprStatus); } } } } printError = PrError(); PrClose(); if(printError != noErr && printError != iPrAbort) doErrorAlert(printError,false); SetPort(oldPort); doPrintRecordsInfo(); } SInt16 doCalcNumberOfPages(Rect pageRect) { Rect destRect, pictureRect; SInt16 heightDestRect, linesPerPage, numberOfPages; RGBForeColor(&gBlackColour); RGBBackColor(&gWhiteColour); EraseRect(&(gWindowPtr->portRect)); SetRect(&destRect,pageRect.left + kMargin,pageRect.top + (kMargin * 1.5), pageRect.right - kMargin,pageRect.bottom - (kMargin * 1.5)); OffsetRect(&destRect,- (kMargin - 5),- ((kMargin * 1.5) - 5)); TextFont(gFontNumber); TextSize(gFontSize); gEditRecHdl = TENew(&destRect,&destRect); TEInsert(*gTextHdl,GetHandleSize(gTextHdl),gEditRecHdl); heightDestRect = destRect.bottom - destRect.top; linesPerPage = heightDestRect / (*gEditRecHdl)->lineHeight; numberOfPages = ((*gEditRecHdl)->nLines / linesPerPage) + 1; SetRect(&pictureRect,destRect.left,destRect.top, destRect.left + ((*gPictureHdl)->picFrame.right - (*gPictureHdl)->picFrame.left), destRect.top + ((*gPictureHdl)->picFrame.bottom - (*gPictureHdl)->picFrame.top)); DrawPicture(gPictureHdl,&pictureRect); return(numberOfPages); } void doDrawPage(Rect pageRect,SInt16 pageNumber,SInt16 numberOfpages) { Rect destRect, pictureRect, rect2; SInt16 heightDestRect, linesPerPage, numberOfLines; TEHandle pageEditRecHdl; Handle textHdl; SInt32 startOffset, endOffset; Str255 theString; Rect rect[10], tempR,dataBounds,sizeRect,ctrlRect,menurec[10],textrect[10],textframe[10]; Point cSize; SetRect(&destRect,pageRect.left + kMargin,pageRect.top + (kMargin * 1.5), pageRect.right - kMargin,pageRect.bottom - (kMargin * 1.5)); heightDestRect = destRect.bottom - destRect.top; linesPerPage = heightDestRect / (*gEditRecHdl)->lineHeight; numberOfLines = (*gEditRecHdl)->nLines; TextFont(gFontNumber); TextSize(gFontSize); pageEditRecHdl = TENew(&destRect,&destRect); textHdl = (*gEditRecHdl)->hText; startOffset = (*gEditRecHdl)->lineStarts[(pageNumber - 1) * linesPerPage]; if(pageNumber == numberOfpages) endOffset = (*gEditRecHdl)->lineStarts[numberOfLines]; else endOffset = (*gEditRecHdl)->lineStarts[pageNumber * linesPerPage]; HLock(textHdl); TEInsert(*textHdl + startOffset,endOffset - startOffset,pageEditRecHdl); HUnlock(textHdl); if(pageNumber == 1) { // SetRect(&pictureRect,destRect.left,destRect.top, // destRect.left + ((*gPictureHdl)->picFrame.right - (*gPictureHdl)->picFrame.left), // destRect.top + ((*gPictureHdl)->picFrame.bottom - (*gPictureHdl)->picFrame.top)); // DrawPicture(gPictureHdl,&pictureRect); } SetRect(&textrect[0], 250,100,400,115); SetRect(&textrect[1], 250,120,400,135); FrameRect(&textrect[0]); FrameRect(&textrect[1]); SetRect(&dataBounds,0,0,1,0); SetPt(&cSize,0,0); SetRect(&tempR,0,94,150,417); SetRect(&rect2, 200, 300, 400, 500); PaintRect(&rect2); MoveTo(destRect.left,pageRect.bottom - 25); NumToString((SInt32) pageNumber,theString); DrawString(theString); } void doPrintRecordsInfo(void) { RGBColor oldForeColour, oldBackColour; SInt16 fontNum; Str255 s2, s3; if(FrontWindow() == gWindowPtr && gPrintStructureInited && !gInhibitPrintStructuresInfo) { GetForeColor(&oldForeColour); GetBackColor(&oldBackColour); RGBForeColor(&gWhiteColour); RGBBackColor(&gBlueColour); EraseRect(&(gWindowPtr->portRect)); GetFNum("\pGeneva",&fontNum); TextFont(fontNum); TextSize(10); MoveTo(20,25); TextFace(bold); DrawString("\pFrom TPrint, TPrInfo and TPrStl structures:"); TextFace(normal); NumToString((long) (*gTPrintHdl)->rPaper.top,s2); NumToString((long) (*gTPrintHdl)->rPaper.left,s3); doDrawRectStrings("\pPaper Rectangle (top,left):",20,45,s2,190,45,s3); NumToString((long) (*gTPrintHdl)->rPaper.bottom,s2); NumToString((long) (*gTPrintHdl)->rPaper.right,s3); doDrawRectStrings("\pPaper Rectangle (bottom,right):",20,60,s2,190,60,s3); NumToString((long) ((*gTPrintHdl)->prInfo.rPage).top,s2); NumToString((long) ((*gTPrintHdl)->prInfo.rPage).left,s3); doDrawRectStrings("\pPage Rectangle (top,left):",20,75,s2,190,75,s3); NumToString((long) ((*gTPrintHdl)->prInfo.rPage).bottom,s2); NumToString((long) ((*gTPrintHdl)->prInfo.rPage).right,s3); doDrawRectStrings("\pPage Rectangle (bottom,right):",20,90,s2,190,90,s3); MoveTo(20,105); DrawString("\pFeed Type:"); MoveTo(190,105); if((*gTPrintHdl)->prStl.feed == 0) DrawString("\pCut sheet"); else if((*gTPrintHdl)->prStl.feed == 1) DrawString("\pFanfold"); MoveTo(20,120); DrawString("\pVertical resolution:"); NumToString((long) (*gTPrintHdl)->prInfo.iVRes,s2); MoveTo(190,120); DrawString(s2); MoveTo(20,135); DrawString("\pHorizontal resolution:"); NumToString((long) (*gTPrintHdl)->prInfo.iHRes,s2); MoveTo(190,135); DrawString(s2); MoveTo(20,155); TextFace(bold); DrawString("\pFrom TPrJob structure:"); TextFace(normal); MoveTo(20,175); DrawString("\pFirst Page:"); NumToString((long) (*gTPrintHdl)->prJob.iFstPage,s2); MoveTo(190,175); DrawString(s2); MoveTo(20,190); DrawString("\pLast Page:"); NumToString((long) (*gTPrintHdl)->prJob.iLstPage,s2); MoveTo(190,190); DrawString(s2); MoveTo(20,205); DrawString("\pNumber of Copies:"); NumToString((long) (*gTPrintHdl)->prJob.iCopies,s2); MoveTo(190,205); DrawString(s2); MoveTo(20,245); DrawString("\pNote: Some printer drivers always set the iCopies field of the TPrJob"); MoveTo(20,260); DrawString("\pstructure to 1 and handle multiple copies internally."); } RGBForeColor(&oldForeColour); RGBBackColor(&oldBackColour); } /* pascal void itemEvaluationFunction(TPPrDlg theDialog, SInt16 itemHit) { SInt16 localizedItemNo, controlValue; ControlHandle controlHdl; MenuHandle menuHdl; Str255 itemName; localizedItemNo = itemHit - gFirstAppendedItemNo + 1; if(localizedItemNo > 0) { if(localizedItemNo == iPopupButton) { GetMenuItemText(menuHdl,controlValue,itemName); GetFNum(itemName,&gFontNumber); } else if(localizedItemNo >= iRadioButton10pt && localizedItemNo <= iRadioButton14pt) { if(localizedItemNo == iRadioButton10pt) gFontSize = 10; else if(localizedItemNo == iRadioButton12pt) gFontSize = 12; else if(localizedItemNo == iRadioButton14pt) gFontSize = 14; } else if(localizedItemNo == iCheckboxFracWidths) { } } else { CallPItemProc(gOldItemEvaluateFunctionUPP,(DialogPtr) theDialog,itemHit); } } // ´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´ eventFilter */ pascal Boolean eventFilter(DialogPtr dialogPtr,EventRecord *eventStrucPtr, SInt16 *itemHit) { Boolean handledEvent; GrafPtr oldPort; handledEvent = false; if((eventStrucPtr->what == updateEvt) && ((WindowPtr) eventStrucPtr->message != dialogPtr)) { doUpdate(eventStrucPtr); } else { GetPort(&oldPort); SetPort(dialogPtr); handledEvent = StdFilterProc(dialogPtr,eventStrucPtr,itemHit); SetPort(oldPort); } return(handledEvent); } // ´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´ doDrawRectStrings void doDrawRectStrings(Str255 s1,SInt16 x1,SInt16 y1,Str255 s2,SInt16 x2, SInt16 y2,Str255 s3) { MoveTo(x1,y1); DrawString(s1); MoveTo(x2,y2); DrawString("\p("); DrawString(s2); DrawString("\p,"); DrawString(s3); DrawString("\p)"); } // ´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´ doErrorAlert void doErrorAlert(SInt16 errorType,Boolean fatal) { AlertStdAlertParamRec paramRec; Str255 theString, errorString = "\pPrinting Manager Error "; SInt16 itemHit; paramRec.movable = true; paramRec.helpButton = false; paramRec.filterProc = NULL; paramRec.defaultText = (StringPtr) kAlertDefaultOKText; paramRec.cancelText = NULL; paramRec.otherText = NULL; paramRec.defaultButton = kAlertStdAlertOKButton; paramRec.cancelButton = 0; paramRec.position = kWindowDefaultPosition; NumToString((long) errorType,theString); doConcatPStrings(errorString,theString); if(!fatal) ; // StandardAlert(kAlertCautionAlert,errorString,NULL,¦mRec,&itemHit); else { // StandardAlert(kAlertStopAlert,errorString,NULL,¦mRec,&itemHit); ExitToShell(); } } // ´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´ doConcatPStrings void doConcatPStrings(Str255 targetString,Str255 appendString) { SInt16 appendLength; appendLength = MIN(appendString[0],255 - targetString[0]); if(appendLength > 0) { BlockMoveData(appendString+1,targetString+targetString[0]+1,(SInt32) appendLength); targetString[0] += appendLength; } } OSErr doCreatePrintRecord (void) { SInt16 printError; gTPrintHdl = (THPrint) NewHandleClear(sizeof(TPrint)); PrintDefault(gTPrintHdl); gPrintStructureInited = true; } /* pascal void doPrintIdle(void) { GrafPtr oldPort; EventRecord eventRec; Boolean gotEvent; SInt16 itemHit; Boolean handled, cancelled; GetPort(&oldPort); SetPort(gPrintStatusDlg); gotEvent = WaitNextEvent(everyEvent,&eventRec,15,NULL); if(gotEvent) { // doHandleEvent should handle update and activate events. This also // enables background applications to receive update events while the // "print status" modal dialog is open. handled = doHandleEvent(gPrintStatusDlg,&eventRec,&itemHit); // doDidUserCancel should scan for Command-period key-down events (see // Chapter 23 - // Miscellany) and also for mouse-down events indicating // that the user clicked the Stop Printing button. cancelled = doDidUserCancel(); if(cancelled) itemHit = kStopButton; // To handle hits in the "print status" dialog, doHandleHitsInStatusBox // should check the item number passed to it. For the Stop Printing // button, it should call PrSetError, specifying the error code iPrAbort. // For hits in other items, it should set the cursor to a wristwatch // cursor. handled = doHandleHitsInStatusBox(itemHit); }; // doUpdateStatus should update those items in "print status" dialog box // that report printing status the user. doUpdateStatusInformation(cancelled); SetPort(oldPort); } */