home *** CD-ROM | disk | FTP | other *** search
- /*
- ** This is the TPICTDoc class definition. This class is an adaptation of
- ** the class of the same name in the book, Elements of C++ Macintosh
- ** Programming, by Dan Weston.
- **
- ** Copyright © 1991 Mark Gross
- ** (RR2, Box 84, Clayville, NY 13322);
- ** this file may be published everywhere, but no charge
- ** may be made for its use. Please contact me about any bugs found.
- ** I'm also looking for Macintosh development work, so drop me a line
- ** if you think I could help.
- */
-
- #include "TPICTDoc.h"
- #include "magics.h"
-
- TDoc *TPICTDoc::Init(OSType theCreator, SFReply *reply)
- {
- inherited::Init(theCreator, reply);
-
- fPict = NULL;
- fHeader = NULL;
- fPrintRecord = NULL;
- return this;
- }/*end of function*/
-
-
- Boolean TPICTDoc::InitDoc(void)
- {
- if(TScrollDoc::InitDoc())
- {
- fPrintRecord = (THPrint) NewHandle(sizeof(TPrint) );
- if(fPrintRecord != NULL)
- {
- PrOpen();
- PrintDefault(fPrintRecord);
- PrClose();
- return TRUE;
- }
- }
- return FALSE;
- }/*end of function*/
-
-
-
- void TPICTDoc::Delete(void)
- {
-
- if(fHeader != NULL)
- {
- DisposHandle(fHeader);
- fHeader = NULL;
- }
- if (fPict != NULL)
- {
- KillPicture((PicHandle) fPict);
- fPict = NULL;
- }
- if(fPrintRecord != NULL)
- {
- DisposHandle((Handle) fPrintRecord);
- fPrintRecord = NULL;
- }
- inherited::Delete();
- }/*end of function*/
-
-
- short TPICTDoc::GetVertSize(void)
- {
- Rect r;
-
- if(fPict)
- {
- r = (**((PicHandle)fPict)).picFrame;
- return r.bottom - r.top;
- }
- else
- return 0;
- }/*end of function*/
-
-
- short TPICTDoc::GetHorizSize(void)
- {
- Rect r;
-
- if(fPict)
- {
- r = (**((PicHandle)fPict)).picFrame;
- return r.right - r.left;
- }
- else
- return 0;
- }/*end of function*/
-
-
- short TPICTDoc::GetVertLineScrollAmount(void)
- {
- return 16;
- }
-
- short TPICTDoc::GetHorizLineScrollAmount(void)
- {
- return 16;
- }
-
-
-
- void TPICTDoc::Draw(Rect *r)
- {
- Rect r_temp;
-
- if (fPict != NULL)
- {
- EraseRect(r);
- r_temp = (**(PicHandle)fPict).picFrame;
- DrawPicture( (PicHandle) fPict, &r_temp );
- }
- }/*end of function*/
-
-
- OSType TPICTDoc::GetDocType(void)
- {
- return 'PICT';
- }/*end of function*/
-
-
-
- Boolean TPICTDoc::ReadDocFile(short refNum)
- {
- long PictLength, headerLength=kPictHeaderSize;
- OSErr err;
- Handle thePic, theHeader;
-
- if (fDocWindow)
- {
- err = GetEOF(refNum, &PictLength);
- PictLength -= kPictHeaderSize;
- thePic = NewHandle(PictLength);
-
- if(thePic == NULL)
- {
- ErrorAlert(rDocErrorStrings, sNoMem);
- return FALSE;
- }
- theHeader = NewHandle(headerLength);
-
- if (theHeader == NULL)
- {
- ErrorAlert(rDocErrorStrings, sNoMem);
- return FALSE;
- }
- HLock(thePic);
- HLock(theHeader);
-
- err = SetFPos(refNum, fsFromStart, 0);
- err = FSRead(refNum, &headerLength, *theHeader);
- err = FSRead(refNum, &PictLength, *thePic);
-
- HUnlock(thePic);
- HUnlock(theHeader);
-
- if(err == noErr)
- {
- fPict = thePic;
- fHeader = theHeader;
- AdjustScrollBars();
- return TRUE;
- }
- else
- {
- DisposHandle(thePic);
- DisposHandle(theHeader);
- return FALSE;
- }
- }/*end if fDocWindow*/
- return FALSE;
- }/*end of function*/
-
-
-
- Boolean TPICTDoc::CanSaveAs(void)
- {
- return FALSE;
- }
-
-
-
- void TPICTDoc::DoPageSetup(void)
- {
- PrOpen();
- (void)PrStlDialog(fPrintRecord);
- PrClose();
- }/*end of function*/
-
-
- void TPICTDoc::DoPrint(void)
- {
- TPPrPort printPort;
- Rect r;
- TPrStatus status;
- THPrint tmpPrintRecord;
-
- tmpPrintRecord = fPrintRecord;
- PrOpen();
- if (PrValidate(tmpPrintRecord) )
- if (!PrStlDialog(tmpPrintRecord) )
- {
- PrClose();
- return;
- }
-
- if (!PrJobDialog(tmpPrintRecord) )
- {
- PrClose();
- return;
- }
-
- printPort = PrOpenDoc(tmpPrintRecord, NULL, NULL);
-
- PrOpenPage(printPort, NULL);
-
- SetRect(&r, 0, 0, 0, 0);
- Draw(&r);
-
- PrClosePage(printPort);
-
- PrCloseDoc(printPort);
-
- if ((**tmpPrintRecord).prJob.bJDocLoop != 0)
- PrPicFile(tmpPrintRecord, NULL, NULL, NULL, &status);
-
- PrClose();
- }/*end of function*/
-
-
-
-
-
- Boolean TPICTDoc::CanPrint(void)
- {
- return TRUE;
- }
-
- Boolean TPICTDoc::CanPageSetup(void)
- {
- return TRUE;
- }
-