#ifndef PRINTING_H
#define PRINTING_H

#ifndef MACERRORS_H
#include <CarbonCore/MacErrors.h>
#endif

#ifndef  QUICKDRAW_H
//#include <QD/Quickdraw.h>
#endif

#ifndef  DIALOGS_H
#include <HIToolbox/Dialogs.h>
#endif


#include <HYS/Printing.h>
#if PRAGMA_ONCE
#pragma once
#endif

#ifdef __cplusplus
extern "C" {
#endif

/*Constants
enum {
   iPrPgFst    = 1,     / page range constant--first page /
   iPrRelease  = 3,     / current version number of the printer driver /
   iPrPgFract  = 120,   / page scale factor /
   iPFMaxPgs   = 128,   / maximum pages in spool file /
   iPrPgMax    = 9999,  / page range constant--last page /

   / PrCtlCall constants for the iWhichCtl parameter /
   iPrBitsCtl     = 4,  / print a bitmap object /
   iPrIOCtl       = 5,  / perform text streaming /
   iPrEvtCtl      = 6,  / print object specified in lParam1 parameter /
   iPrDevCtl      = 7,  / device control command /

   / constants used with iPrBitsCtl (in the lParam1 parameter 
      of PrCtlCall) /
   lScreenBits    = 0,           / resolution is 80 x 72 dpi /
   lPaintBits     = 1,           / resolution is 72 x 72 dpi /
   lHiScreenBits  = 0x00000002,  / resolution is 160 x 144 dpi /
   lHiPaintBits   = 0x00000003,  / resolution is 144 x 144 dpi /

   / constants used with iPrEvtCtl (in the lParam3 parameter 
      of PrCtlCall) /
   lPrEvtAll      = 0x0002FFFD,  / the entire screen /
   lPrEvtTop      = 0x0001FFFD,  / the frontmost window /
/ constants used with iPrDevCtl (in the lParam1 parameter 
      of PrCtlCall) /
   lPrReset       = 0x00010000,  / reserved /
   lPrLineFeed    = 0x00030000,  / paper advance /
   lPrLFStd       = 0x0003FFFF,  / carriage return with line feed /
   lPrLFSixth     = 0x0003FFFF,  / used for low-level call for 
                                    ImageWriter /
   lPrPageEnd     = 0x00020000,  / end page /
   lPrDocOpen     = 0x00010000,  / open document for printing /
   lPrPageOpen    = 0x00040000,  / open page for printing /
   lPrPageClose   = 0x00020000,  / close page for printing /
   lPrDocClose    = 0x00050000,  / close document for printing /
bDraftLoop     = 0,           / draft-quality printing /
   bSpoolLoop     = 1,           / deferred printing /
   bUser1Loop     = 2,           / reserved /
   bUser2Loop     = 3,           / reserved /
iPrSavPFil     = -1,          / problem saving print file /
   iPrAbort       = 0x0080,      / the user pressed Command-period /

   iFMgrCtl       = 8,           / File Mgr's dialog-hook proc's control 
                                    number /
   pPrGlobals     = 0x00000944,     / PrVars low memory area /

   iPrDrvrRef     = -3, / reference number of printer driver /

   / opcodes used with PrGeneral /
   getRslDataOp   = 4,  / get resolutions for the current printer /
   setRslOp       = 5,  / set resolutions for a TPrint record /
   draftBitsOp    = 6,  / force enhanced draft-quality printing /
   noDraftBitsOp  = 7,  / cancel enhanced draft-quality printing /
   getRotnOp      = 8,  / get page orientation of a TPrint record /

   / result code from PrGeneral /
   noSuchRsl      = 1,  / resolution not supported /
};*/


enum {
   iPrPgFst    = 1,     /* page range constant--first page */
   iPrRelease  = 3,     /* current version number of the printer driver */
   iPrPgFract  = 120,   /* page scale factor */
   iPFMaxPgs   = 128,   /* maximum pages in spool file */
   iPrPgMax    = 9999,  /* page range constant--last page */

   /* PrCtlCall constants for the iWhichCtl parameter */
   iPrBitsCtl     = 4,  /* print a bitmap object */
   iPrIOCtl       = 5,  /* perform text streaming */
   iPrEvtCtl      = 6,  /* print object specified in lParam1 parameter */
   iPrDevCtl      = 7,  /* device control command */

   /* constants used with iPrBitsCtl (in the lParam1 parameter 
      of PrCtlCall) */
   lScreenBits    = 0,           /* resolution is 80 x 72 dpi */
   lPaintBits     = 1,           /* resolution is 72 x 72 dpi */
   lHiScreenBits  = 0x00000002,  /* resolution is 160 x 144 dpi */
   lHiPaintBits   = 0x00000003,  /* resolution is 144 x 144 dpi */

   /* constants used with iPrEvtCtl (in the lParam3 parameter 
      of PrCtlCall) */
   lPrEvtAll      = 0x0002FFFD,  /* the entire screen */
   lPrEvtTop      = 0x0001FFFD,  /* the frontmost window */
/* constants used with iPrDevCtl (in the lParam1 parameter 
      of PrCtlCall) */
   lPrReset       = 0x00010000,  /* reserved */
   lPrLineFeed    = 0x00030000,  /* paper advance */
   lPrLFStd       = 0x0003FFFF,  /* carriage return with line feed */
   lPrLFSixth     = 0x0003FFFF,  /* used for low-level call for 
                                    ImageWriter */
   lPrPageEnd     = 0x00020000,  /* end page */
   lPrDocOpen     = 0x00010000,  /* open document for printing */
   lPrPageOpen    = 0x00040000,  /* open page for printing */
   lPrPageClose   = 0x00020000,  /* close page for printing */
   lPrDocClose    = 0x00050000,  /* close document for printing */
bDraftLoop     = 0,           /* draft-quality printing */
   bSpoolLoop     = 1,           /* deferred printing */
   bUser1Loop     = 2,           /* reserved */
   bUser2Loop     = 3,           /* reserved */
iPrSavPFil     = -1,          /* problem saving print file */
   iPrAbort       = 0x0080,      /* the user pressed Command-period */

   iFMgrCtl       = 8,           /* File Mgr's dialog-hook proc's control 
                                    number */
   pPrGlobals     = 0x00000944,     /* PrVars low memory area */

   iPrDrvrRef     = -3, /* reference number of printer driver */

   /* opcodes used with PrGeneral */
   getRslDataOp   = 4,  /* get resolutions for the current printer */
   setRslOp       = 5,  /* set resolutions for a TPrint record */
   draftBitsOp    = 6,  /* force enhanced draft-quality printing */
   noDraftBitsOp  = 7,  /* cancel enhanced draft-quality printing */
   getRotnOp      = 8,  /* get page orientation of a TPrint record */

   /* result code from PrGeneral */
   noSuchRsl      = 1,  /* resolution not supported */
};


/*Data Types
struct TPrint {         / print record /
   short    iPrVersion; / reserved /
   TPrInfo  prInfo;     / resolution of device & page rectangle /
   Rect     rPaper;     / paper rectangle /
   TPrStl   prStl;      / printer driver number & feed type /
   TPrInfo  prInfoPT;   / reserved /
   TPrXInfo prXInfo;    / reserved /
   TPrJob   prJob;      / information from the job dialog box / 
   short    printX[19]; / reserved /
};
typedef struct TPrint TPrint;
typedef TPrint TPPrint, THPrint;
struct TPrInfo {        / printer information record /
   short    iDev;       / reserved /
   short    iVRes;      / vertical resolution of printer, in dpi /
   short    iHRes;      / horizontal resolution of printer, in dpi /
   Rect     rPage;      / the page rectangle /
};
typedef struct TPrInfo TPrInfo;
typedef TPrInfo TPPrInfo;
struct TPrJob {         / print job record /
   short    iFstPage;   / first page of page range /
   short    iLstPage;   / last page of page range /
   short    iCopies;    / number of copies /
   char     bJDocLoop;  / printing method: draft or deferred /
   Boolean  fFromUsr;   / reserved /
   PrIdleProcPtr
            pIdleProc;  / pointer to an idle procedure /
   StringPtr
            pFileName;  / spool filename: NIL for default /
   short    iFileVol;   / spool file volume; set to 0 initially /
   char     bFileVers;  / spool file version; set to 0 initially /
   char     bJobX;      / reserved /
};
typedef struct TPrJob TPrJob;
typedef TPrJob TPPrJob;
struct TPrStl {      / printing style record /
   short    wDev;    / device number of printer /
   short    iPageV;  / reserved /
   short    iPageH;  / reserved /
   char     bPort;   / reserved /
   TFeed    feed;    / feed type /
};
typedef struct TPrStl TPrStl;
typedef TPrStl TPPrStl;
struct TPrStatus {         / printing status record /
   short       iTotPages;  / total pages in print file /
   short       iCurPage;   / current page number /
   short       iTotCopies; / total copies requested /
   short       iCurCopy;   / current copy number /
   short       iTotBands;  / reserved /
   short       iCurBand;   / reserved /
   Boolean     fPgDirty;   / TRUE if current page has been written to /
   Boolean     fImaging;   / reserved /
   THPrint     hPrint;     / handle to the active TPrint record /
   TPPrPort    pPrPort;    / pointer to the active printing graphics port /
   PicHandle   hPic;       / handle to the active picture /
};
typedef struct TPrStatus TPrStatus;
typedef TPrStatus TPPrStatus;
struct TPrDlg {               / print dialog box record /
   DialogRecord   Dlg;        / a dialog record /
   ModalFilterProcPtr
                  pFltrProc;  / pointer to event filter /
   PItemProcPtr   pItemProc;  / pointer to item-handling function /
   THPrint        hPrintUsr;  / handle to a TPrint record /
   Boolean        fDoIt;      / TRUE means user clicked OK /
   Boolean        fDone;      / TRUE means user clicked OK or Cancel /
   long           lUser1;     / storage for your application /
   long           lUser2;     / storage for your application /
   long           lUser3;     / storage for your application /
   long           lUser4;     / storage for your application /
};
typedef struct TPrDlg TPrDlg;
typedef TPrDlg TPPrDlg;
typedef pascal TPPrDlg (PDlgInitProcPtr)(THPrint hPrint);
truct TPrPort {         / printing graphics port record /
   GrafPort gPort;      / graphics port for printing /
   QDProcs  gProcs;     / procedures for printing in the graphics port /
   long     lGParam1;   / reserved /
   long     lGParam2;   / reserved /
   long     lGParam3;   / reserved /
   long     lGParam4;   / reserved /
   Boolean  fOurPtr;    / reserved /
   Boolean  fOurBits;   / reserved /
};
typedef struct TPrPort TPrPort;
typedef TPrPort TPPrPort;
enum {feedCut,feedFanfold,feedMechCut,feedOther};
typedef unsigned char TFeed;
enum {scanTB,scanBT,scanLR,scanRL};
typedef unsigned char TScan;
typedef Rect TPRect;
typedef pascal void (PrIdleProcPtr)(void);
typedef pascal void (PItemProcPtr)(DialogPtr theDialog, short item);
/ structures used by PrGeneral /
struct TGnlData {
   short iOpCode;    / opcode passed to PrGeneral /
   short iError;     / result code returned by PrGeneral /
   long  lReserved;  / more fields here depending on call /
};
typedef struct TGnlData TGnlData;
struct TGetRslBlk {        / get-resolution record /
   short    iOpCode;       / the getRslDataOp opcode /
   short    iError;        / result code returned by PrGeneral /
   long     lReserved;     / reserved /
   short    iRgType;       / printer driver version number /
   TRslRg   xRslRg;        / x-direction resolution range /
   TRslRg   yRslRg;        / y-direction resolution range /
   short    iRslRecCnt;    / number of resolution records /
   TRslRec  rgRslRec[27];  / array of resolution records /
};
typedef struct TGetRslBlk TGetRslBlk;
struct TRslRg {   
   short    iMin;          / minimum resolution supported /
   short    iMax;          / maximum resolution supported /
};
typedef struct TRslRg TRslRg;
struct TRslRec {  
   short    iXRsl;         / discrete resolution, x direction /
   short    iYRsl;         / discrete resolution, y direction /
};
typedef struct TRslRec TRslRec;
struct TSetRslBlk {        / set-resolution record /
   short    iOpCode;       / the setRslOp opcode /
   short    iError;        / result code returned by PrGeneral /
   long     lReserved;     / reserved /
   THPrint  hPrint;        / handle to the current TPrint record /
   short    iXRsl;         / x-direction resolution you want /
   short    iYRsl;         / y-direction resolution you want /
};
typedef struct TSetRslBlk TSetRslBlk;
struct TDftBitsBlk {       / draft bits record /
   short    iOpCode;       / draftBitsOp or noDraftBitsOp opcode /
   short    iError;        / result code returned by PrGeneral /
   long     lReserved;     / reserved /
   THPrint  hPrint;        / handle to the current TPrint record /
};
typedef struct TDftBitsBlk TDftBitsBlk;
struct TGetRotnBlk {       / page orientation record /
   short    iOpCode;       / the getRotnOp opcode /
   short    iError;        / result code returned by PrGeneral /
   long     lReserved;     / reserved /
   THPrint  hPrint;        / handle to current TPrint record /
   Boolean  fLandscape;    / TRUE if user selected landscape printing /
   char     bXtra;         / reserved /
};
typedef struct TGetRotnBlk TGetRotnBlk;*/

struct TRslRec {  
   short    iXRsl;         /* discrete resolution, x direction */
   short    iYRsl;         /* discrete resolution, y direction */
};
typedef struct TRslRec TRslRec;

struct TRslRg {   
   short    iMin;          /* minimum resolution supported */
   short    iMax;          /* maximum resolution supported */
};
typedef struct TRslRg TRslRg;


typedef pascal void (*PItemProcPtr)(DialogPtr theDialog, short item);

struct TPrPort {         /* printing graphics port record */
   GrafPort gPort;      /* graphics port for printing */
   QDProcs  gProcs;     /* procedures for printing in the graphics port */
   long     lGParam1;   /* reserved */
   long     lGParam2;   /* reserved */
   long     lGParam3;   /* reserved */
   long     lGParam4;   /* reserved */
   Boolean  fOurPtr;    /* reserved */
   Boolean  fOurBits;   /* reserved */
};
typedef struct TPrPort TPrPort;
typedef TPrPort *TPPrPort;


typedef pascal void (*PrIdleProcPtr)(void);


struct TPrJob {         /* print job record */
   short    iFstPage;   /* first page of page range */
   short    iLstPage;   /* last page of page range */
   short    iCopies;    /* number of copies */
   char     bJDocLoop;  /* printing method: draft or deferred */
   Boolean  fFromUsr;   /* reserved */
   PrIdleProcPtr
            pIdleProc;  /* pointer to an idle procedure */
   StringPtr
            pFileName;  /* spool filename: NIL for default */
   short    iFileVol;   /* spool file volume; set to 0 initially */
   char     bFileVers;  /* spool file version; set to 0 initially */
   char     bJobX;      /* reserved */
};
typedef struct TPrJob TPrJob;
typedef TPrJob *TPPrJob;


enum {feedCut,feedFanfold,feedMechCut,feedOther};
typedef unsigned char TFeed;


struct TPrStl {      /* printing style record */
   short    wDev;    /* device number of printer */
   short    iPageV;  /* reserved */
   short    iPageH;  /* reserved */
   char     bPort;   /* reserved */
   TFeed    feed;    /* feed type */
};
typedef struct TPrStl TPrStl;
typedef TPrStl *TPPrStl;


struct TPrInfo {        /* printer information record */
   short    iDev;       /* reserved */
   short    iVRes;      /* vertical resolution of printer, in dpi */
   short    iHRes;      /* horizontal resolution of printer, in dpi */
   Rect     rPage;      /* the page rectangle */
};
typedef struct TPrInfo TPrInfo;
typedef TPrInfo *TPPrInfo;


struct TPrint {         /* print record */
   short    iPrVersion; /* reserved */
   TPrInfo  prInfo;     /* resolution of device & page rectangle */
   Rect     rPaper;     /* paper rectangle */
   TPrStl   prStl;      /* printer driver number & feed type */
   TPrInfo  prInfoPT;   /* reserved */
   TPrXInfo prXInfo;    /* reserved */
   TPrJob   prJob;      /* information from the job dialog box */ 
   short    printX[19]; /* reserved */
};
typedef struct TPrint TPrint;
typedef TPrint *TPPrint, **THPrint;


struct TPrStatus {         /* printing status record */
   short       iTotPages;  /* total pages in print file */
   short       iCurPage;   /* current page number */
   short       iTotCopies; /* total copies requested */
   short       iCurCopy;   /* current copy number */
   short       iTotBands;  /* reserved */
   short       iCurBand;   /* reserved */
   Boolean     fPgDirty;   /* TRUE if current page has been written to */
   Boolean     fImaging;   /* reserved */
   THPrint     hPrint;     /* handle to the active TPrint record */
   TPPrPort    pPrPort;    /* pointer to the active printing graphics port */
   PicHandle   hPic;       /* handle to the active picture */
};
typedef struct TPrStatus TPrStatus;
typedef TPrStatus *TPPrStatus;
struct TPrDlg {               /* print dialog box record */
   DialogRecord   Dlg;        /* a dialog record */
   ModalFilterProcPtr
                  pFltrProc;  /* pointer to event filter */
   PItemProcPtr   pItemProc;  /* pointer to item-handling function */
   THPrint        hPrintUsr;  /* handle to a TPrint record */
   Boolean        fDoIt;      /* TRUE means user clicked OK */
   Boolean        fDone;      /* TRUE means user clicked OK or Cancel */
   long           lUser1;     /* storage for your application */
   long           lUser2;     /* storage for your application */
   long           lUser3;     /* storage for your application */
   long           lUser4;     /* storage for your application */
};
typedef struct TPrDlg TPrDlg;
typedef TPrDlg *TPPrDlg;
typedef pascal TPPrDlg (*PDlgInitProcPtr)(THPrint hPrint);
enum {scanTB,scanBT,scanLR,scanRL};
typedef unsigned char TScan;
typedef Rect *TPRect;


/* structures used by PrGeneral */
struct TGnlData {
   short iOpCode;    /* opcode passed to PrGeneral */
   short iError;     /* result code returned by PrGeneral */
   long  lReserved;  /* more fields here depending on call */
};
typedef struct TGnlData TGnlData;
struct TGetRslBlk {        /* get-resolution record */
   short    iOpCode;       /* the getRslDataOp opcode */
   short    iError;        /* result code returned by PrGeneral */
   long     lReserved;     /* reserved */
   short    iRgType;       /* printer driver version number */
   TRslRg   xRslRg;        /* x-direction resolution range */
   TRslRg   yRslRg;        /* y-direction resolution range */
   short    iRslRecCnt;    /* number of resolution records */
   TRslRec  rgRslRec[27];  /* array of resolution records */
};
typedef struct TGetRslBlk TGetRslBlk;

struct TSetRslBlk {        /* set-resolution record */
   short    iOpCode;       /* the setRslOp opcode */
   short    iError;        /* result code returned by PrGeneral */
   long     lReserved;     /* reserved */
   THPrint  hPrint;        /* handle to the current TPrint record */
   short    iXRsl;         /* x-direction resolution you want */
   short    iYRsl;         /* y-direction resolution you want */
};
typedef struct TSetRslBlk TSetRslBlk;
struct TDftBitsBlk {       /* draft bits record */
   short    iOpCode;       /* draftBitsOp or noDraftBitsOp opcode */
   short    iError;        /* result code returned by PrGeneral */
   long     lReserved;     /* reserved */
   THPrint  hPrint;        /* handle to the current TPrint record */
};
typedef struct TDftBitsBlk TDftBitsBlk;
struct TGetRotnBlk {       /* page orientation record */
   short    iOpCode;       /* the getRotnOp opcode */
   short    iError;        /* result code returned by PrGeneral */
   long     lReserved;     /* reserved */
   THPrint  hPrint;        /* handle to current TPrint record */
   Boolean  fLandscape;    /* TRUE if user selected landscape printing */
   char     bXtra;         /* reserved */
};
typedef struct TGetRotnBlk TGetRotnBlk;

//function

/*Opening and Closing the Printing Manager
pascal void PrOpen              (void); 
pascal void PrClose             (void); */
pascal void PrOpen              (void); 
pascal void PrClose             (void); 

/*Handling Printing Errors
pascal short PrError            (void); 
pascal void PrSetError          (short iErr);*/
pascal short PrError            (void); 

/*Displaying and Customizing the Print Dialog Boxes
pascal Boolean PrStlDialog      (THPrint hPrint); 
pascal Boolean PrJobDialog      (THPrint hPrint); 
pascal Boolean PrDlgMain        (THPrint hPrint, PDlgInitProcPtr pDlgInit); 
pascal TPPrDlg PrStlInit        (THPrint hPrint); 
pascal TPPrDlg PrJobInit        (THPrint hPrint); 
pascal void PrJobMerge          (THPrint hPrintSrc, THPrint hPrintDst); */
pascal Boolean PrStlDialog      (THPrint hPrint); 
pascal Boolean PrJobDialog      (THPrint hPrint); 

/*Printing a Document
pascal TPPrPort PrOpenDoc       (THPrint hPrint, TPPrPort pPrPort, Ptr pIOBuf); 
pascal void PrCloseDoc          (TPPrPort pPrPort); 
pascal void PrOpenPage          (TPPrPort pPrPort, TPRect pPageFrame); 
pascal void PrClosePage         (TPPrPort pPrPort); 
pascal void PrPicFile           (THPrint hPrint, TPPrPort pPrPort, Ptr pIOBuf,
                                 Ptr pDevBuf, TPrStatus *prStatus); */
pascal TPPrPort PrOpenDoc       (THPrint hPrint, TPPrPort pPrPort, Ptr pIOBuf); 
pascal void PrCloseDoc          (TPPrPort pPrPort); 
pascal void PrOpenPage          (TPPrPort pPrPort, TPRect pPageFrame); 
pascal void PrClosePage         (TPPrPort pPrPort); 
pascal void PrPicFile           (THPrint hPrint, TPPrPort pPrPort, Ptr pIOBuf,
                                 Ptr pDevBuf, TPrStatus *prStatus); 

/*Initializing and Validating TPrint Records
pascal void PrintDefault        (THPrint hPrint); 
pascal Boolean PrValidate       (THPrint hPrint); */
pascal void PrintDefault        (THPrint hPrint); 

#ifdef __cplusplus
}
#endif

#endif 
