home *** CD-ROM | disk | FTP | other *** search
/ Mac Expert 1995 Winter / Mac Expert - Winter 95.iso / Les fichiers / Communications / Divers / DinkClass ƒ / DC Scribble / DScribbleDoc.c < prev    next >
Encoding:
Text File  |  1992-10-11  |  3.9 KB  |  208 lines  |  [TEXT/KAHL]

  1. /*
  2.     File:        DScribbleDoc.c
  3.  
  4.     Written by:    Mark Gross
  5.  
  6.     Copyright:    © 1992 by Applied Technical Software, all rights reserved.
  7.     Use at your own risk.
  8.  
  9. */
  10. //This is the diffinition of the DScribbleDocument Class
  11.  
  12. #include "DScribbleDoc.h"
  13. #include "DScribbleWind.h"
  14.  
  15.  
  16.  
  17.  
  18. DScribbleDoc::DScribbleDoc(void)
  19. {
  20.     // Stub
  21. }
  22.  
  23. DScribbleDoc::~DScribbleDoc()
  24. {
  25.     if( fPict != NULL)
  26.         KillPicture( fPict);
  27.     if(fPictHeader != NULL)
  28.         DisposHandle(fPictHeader);
  29. }
  30.  
  31.  
  32. DDocument* DScribbleDoc::Init( Boolean OpenFromFile)
  33. {
  34.     DDocument *inheritedDoc;
  35.     
  36.     fPict = NULL;
  37.     fPictHeader = NULL;
  38.     
  39.     inheritedDoc = inherited::Init(OpenFromFile);
  40.  
  41.      return inheritedDoc;
  42. }
  43.  
  44.  
  45. void DScribbleDoc::AEInitDoc(FSSpec *theFSS)
  46. {
  47.     fPict = NULL;
  48.  
  49.     inherited::AEInitDoc(theFSS);        
  50. }//end member function AEInitDoc
  51.  
  52.  
  53.  void DScribbleDoc::HandleMenuChoice(short menuID, short menuItem)
  54.  {
  55.      if(menuID == rPenMenu)
  56.     {
  57.         switch(menuItem)
  58.         {
  59.             case i1X1:
  60.                 ((DScribbleWind *)fDWindow)->fPenSize = 1;
  61.                 break;
  62.             case i2X2:
  63.                 ((DScribbleWind *)fDWindow)->fPenSize = 2;
  64.                 break;
  65.             case i3X3:
  66.                 ((DScribbleWind *)fDWindow)->fPenSize = 3;
  67.                 break;
  68.             case iBlack:
  69.                 ((DScribbleWind *)fDWindow)->fPenPat = patBlack;
  70.                 break;
  71.             case iGray:
  72.                 ((DScribbleWind *)fDWindow)->fPenPat = patGray;
  73.                 break;
  74.             case iWhite:
  75.                 ((DScribbleWind *)fDWindow)->fPenPat = patWhite;
  76.                 break;
  77.             default:
  78.                 break;
  79.         }//end switch menuitem
  80.     }// end if rPenMenu
  81.         
  82.     inherited::HandleMenuChoice(menuID, menuItem);
  83.     
  84. }// end of HandleMenuChoice member fuction
  85.  
  86.  
  87.              
  88.  void DScribbleDoc::SetUpMenues(void)
  89.  {
  90.     MenuHandle    menu;
  91.     
  92.     menu = GetMHandle(rPenMenu);
  93.  
  94.     EnableMenuItem( menu, i1X1, TRUE);
  95.     EnableMenuItem( menu, i2X2, TRUE);
  96.     EnableMenuItem( menu, i3X3, TRUE);
  97.     EnableMenuItem( menu, iBlack, TRUE);
  98.     EnableMenuItem( menu, iGray, TRUE);
  99.     EnableMenuItem( menu, iWhite, TRUE);
  100.  
  101.     CheckItem(menu,i1X1, ((DScribbleWind *)fDWindow)->fPenSize == 1);
  102.     CheckItem(menu,i2X2, ((DScribbleWind *)fDWindow)->fPenSize == 2);
  103.     CheckItem(menu,i3X3, ((DScribbleWind *)fDWindow)->fPenSize == 3);
  104.     CheckItem(menu, iBlack, ((DScribbleWind *)fDWindow)->fPenPat == patBlack);
  105.     CheckItem(menu, iGray, ((DScribbleWind *)fDWindow)->fPenPat == patGray);
  106.     CheckItem(menu, iWhite, ((DScribbleWind *)fDWindow)->fPenPat == patWhite);
  107.     
  108.     inherited::SetUpMenues();
  109. }// end of SetUpMenues function
  110.  
  111.  
  112. DWindow* DScribbleDoc::MakeWindow(Boolean hasColorWindows)
  113. {    
  114.     DScribbleWind *newWindow;
  115.     
  116.     //newWindow = new DWindow;
  117.     newWindow = new DScribbleWind;
  118.     fDWindow = newWindow;
  119.         
  120.     if (newWindow->Init(this, hasColorWindows))
  121.         return newWindow;
  122.     else
  123.     {
  124.         fDWindow = NULL;
  125.         return fDWindow;
  126.     }    
  127. }//end member function MakeWindow
  128.  
  129.  
  130.  
  131. // 
  132. // Read data into the Scribble application spacific data structures.
  133. // This funciton gets called from the OpenFile member function
  134. //
  135.  
  136. OSErr DScribbleDoc::ReadData(short refNum, long *size)
  137. {
  138.     OSErr fileError;
  139.     Handle data;
  140.     long headerLength;
  141.     
  142.     headerLength = 512;
  143.  
  144.     fPictHeader = NewHandle(headerLength);
  145.     if(fPictHeader == NULL)
  146.         return FALSE;
  147.     
  148.     HLock(fPictHeader);
  149.     fileError = FSRead(refNum, &headerLength, *fPictHeader);
  150.     HUnlock(fPictHeader);
  151.     
  152.     if(fileError != noErr)
  153.     {
  154.         DisposHandle( fPictHeader);
  155.         return fileError;
  156.     }
  157.     
  158.     *size -= headerLength;
  159.  
  160.     fPict = (PicHandle)NewHandle(*size);
  161.     if(fPict == NULL)
  162.         return FALSE;
  163.     
  164.     HLock(fPict);
  165.     fileError = FSRead(refNum, size, *fPict);
  166.     HUnlock(fPict);
  167.     
  168.     if(fileError != noErr)
  169.     {
  170.         DisposHandle( fPict);
  171.         return fileError;
  172.     }
  173.     
  174.     fFileRef = refNum;
  175.     return fileError;    
  176. }
  177.  
  178. //
  179. // Write the data out to the disk
  180. //
  181.  
  182. OSErr DScribbleDoc::WriteData(short refNum)
  183. {
  184.     OSErr fileError;
  185.     Handle data;
  186.     long dataCount;
  187.  
  188.     data = (Handle) fPict;
  189.     if(data == NULL)
  190.         return FALSE;
  191.     
  192.     // first write out the header info
  193.     data = fPictHeader;
  194.     dataCount = 512;
  195.     HLock(data);
  196.     fileError = FSWrite(refNum, &dataCount, *data);
  197.     HUnlock(data);
  198.  
  199.     // next write out the pict itself
  200.     data = (Handle) fPict;
  201.     dataCount = GetHandleSize(data);    
  202.     HLock(data);
  203.     fileError = FSWrite(refNum, &dataCount, *data);
  204.     HUnlock(data);
  205.     
  206.     return fileError;    
  207. }
  208.