home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / Developer University / DU Projects / Data / Sources / Content.cpp < prev    next >
Encoding:
Text File  |  1996-12-11  |  3.6 KB  |  135 lines  |  [TEXT/CWIE]

  1. //    Release Version:    $ ODF 3 $
  2. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  3.  
  4. //========================================================================================
  5. #include "Data.hpp"
  6.  
  7. #ifndef CONTENT_H
  8. #include "Content.h"
  9. #endif
  10.  
  11. #ifndef PART_H
  12. #include "Part.h"
  13. #endif
  14.  
  15. #ifndef PIZZA_H
  16. #include "Pizza.h"            //  CPizza
  17. #endif
  18.  
  19. //--- OpenDoc ------------------------------------------------------------------
  20. #ifndef SOM_Module_OpenDoc_StdProps_defined
  21. #include <StdProps.xh>        // kODPropContents
  22. #endif
  23.  
  24. //========================================================================================
  25. #ifdef FW_BUILD_MAC
  26. #pragma segment Data
  27. #endif
  28.  
  29. //========================================================================================
  30. // Template instantiation
  31. #include "FWTColl.tpp"
  32.  
  33. FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollection, CPizzaCollection)
  34. FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollectionIterator, CPizzaCollectionIterator)
  35.  
  36. #ifdef FW_USE_TEMPLATE_PRAGMAS
  37.     #pragma template_access public
  38.     #pragma template FW_TOrderedCollection<CPizzaCollection>
  39.     #pragma template FW_TOrderedCollectionIterator<CPizzaCollectionIterator>
  40. #else
  41.     template class FW_TOrderedCollection<CPizzaCollection>;
  42.     template class FW_TOrderedCollectionIterator<CPizzaCollectionIterator>;
  43. #endif
  44.  
  45. FW_DEFINE_AUTO(CDataContent)
  46.  
  47. //----------------------------------------------------------------------------------------
  48. CDataContent::CDataContent(Environment* ev, CDataPart* part)
  49.  :    FW_CContent(ev, part),
  50.     fEmbeddedString("Embedded string"),
  51.     fStringPtr(NULL),
  52.     fBufferPtr(NULL),
  53.     fBufferBytes(0),
  54.     fPart(part),
  55.     fNumPizzas(0),
  56.     fPizzaList(NULL)
  57. {
  58.     fStringPtr = FW_NEW(FW_CString, ("String Pointer") );
  59.  
  60.     // init buffer
  61.     fBufferBytes = 1000;
  62.     fBufferPtr = FW_CMemoryManager::AllocateBlock(fBufferBytes);    
  63.  
  64.     fPizzaList = FW_NEW(CPizzaCollection, ());
  65.     FW_END_CONSTRUCTOR
  66. }
  67.  
  68. //----------------------------------------------------------------------------------------
  69. CDataContent::~CDataContent()
  70. {
  71.     FW_START_DESTRUCTOR
  72.     delete fStringPtr;
  73.     FW_CMemoryManager::FreeBlock(fBufferPtr);
  74.     CPizza* pizza = NULL;
  75.     while ((pizza = fPizzaList->First()) != NULL) {
  76.         fPizzaList->Remove(pizza);
  77.         delete pizza;
  78.         }
  79.     delete fPizzaList;
  80. }
  81.  
  82. //----------------------------------------------------------------------------------------
  83. CPizzaCollection*
  84. CDataContent::MyGetPizzaList()
  85. {
  86.     return fPizzaList;
  87. }
  88.  
  89. //----------------------------------------------------------------------------------------
  90. void
  91. CDataContent::MyIncrement(Environment* ev, FW_CPoint& position)
  92. {
  93.     fNumPizzas++;
  94.  
  95.     FW_CPoint halfSize( FW_IntToFixed(15), FW_IntToFixed(15) );
  96.     FW_CRect bounds(position - halfSize, position + halfSize);
  97.  
  98.     CPizza* pizza = new CPizza(bounds);
  99.     fPizzaList->AddLast(pizza);
  100.     fPart->MyPartChanged(ev, bounds);
  101. }
  102.  
  103. //----------------------------------------------------------------------------------------
  104. void
  105. CDataContent::ExternalizeKind(Environment* ev,
  106.                             ODStorageUnit* storageUnit,
  107.                             FW_CKind* kind,
  108.                             FW_StorageKinds storageKind,
  109.                             FW_CPromise* promise,
  110.                             FW_CCloneInfo* cloneInfo)
  111. {
  112.     FW_UNUSED(ev);
  113.     FW_UNUSED(storageUnit);
  114.     FW_UNUSED(kind);
  115.     FW_UNUSED(storageKind);
  116.     FW_UNUSED(promise);
  117.     FW_UNUSED(cloneInfo);
  118. }
  119.  
  120. //----------------------------------------------------------------------------------------
  121. FW_Boolean 
  122. CDataContent::InternalizeKind(Environment* ev,
  123.                             ODStorageUnit* storageUnit, 
  124.                             FW_CKind* kind,
  125.                             FW_StorageKinds storageKind,
  126.                             FW_CCloneInfo* cloneInfo)
  127. {
  128.     FW_UNUSED(ev);
  129.     FW_UNUSED(storageUnit);
  130.     FW_UNUSED(kind);
  131.     FW_UNUSED(storageKind);
  132.     FW_UNUSED(cloneInfo);
  133.     return FALSE;
  134. }
  135.