home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-16 | 4.0 KB | 150 lines | [TEXT/CWIE] |
- // Release Version: $ ODF 1 $
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
-
- //========================================================================================
- #include "DataSave.hpp"
-
- #ifndef CONTENT_H
- #include "Content.h"
- #endif
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef PIZZA_H
- #include "Pizza.h" // CPizza
- #endif
-
- #ifndef FWEVENTU_H
- #include "FWEventU.h" // FW_IsCommandKeyPressed
- #endif
-
- //========================================================================================
- #ifdef FW_BUILD_MAC
- #pragma segment DataSave
- #endif
-
- //========================================================================================
- FW_DEFINE_AUTO(CPizzaCollection)
- FW_DEFINE_AUTO(CPizzaCollectionIterator)
- FW_DEFINE_AUTO(CDataSaveContent)
-
- //----------------------------------------------------------------------------------------
- CDataSaveContent::CDataSaveContent(Environment* ev, CDataSavePart* part)
- : FW_CContent(ev, part),
- fPart(part),
- fNumPizzas(0),
- fPizzaList(NULL)
- {
- fPizzaList = FW_NEW(CPizzaCollection, ());
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- CDataSaveContent::~CDataSaveContent()
- {
- FW_START_DESTRUCTOR
- CPizza* pizza = NULL;
- while ((pizza = (CPizza*)fPizzaList->First()) != NULL) {
- fPizzaList->Remove(pizza);
- delete pizza;
- }
- delete fPizzaList;
- }
-
- //----------------------------------------------------------------------------------------
- CPizzaCollection*
- CDataSaveContent::MyGetPizzaList()
- {
- return fPizzaList;
- }
-
- //----------------------------------------------------------------------------------------
- void
- CDataSaveContent::MyIncrement(Environment* ev, FW_CPoint& position)
- {
- fNumPizzas++;
- FW_CPoint halfSize( FW_IntToFixed(15), FW_IntToFixed(15) );
- FW_CRect bounds(position - halfSize, position + halfSize);
- CPizza* pizza = new CPizza(bounds);
- fPizzaList->AddLast(pizza);
- fPart->Changed(ev);
- fPart->MyInvalidatePresentation(ev, bounds);
- }
-
- //----------------------------------------------------------------------------------------
- void
- CDataSaveContent::MyAddPizza(Environment* ev, CPizza* pizza)
- {
- fNumPizzas++;
- fPizzaList->AddLast(pizza);
- fPart->MyInvalidatePresentation(ev, pizza->GetBounds());
- }
-
- //----------------------------------------------------------------------------------------
- void
- CDataSaveContent::MyRemoveLastPizza(Environment* ev, CPizza* pizza)
- {
- fNumPizzas--;
- fPizzaList->RemoveLast();
- fPart->MyInvalidatePresentation(ev, pizza->GetBounds());
- }
-
- //----------------------------------------------------------------------------------------
- void
- CDataSaveContent::Externalize(Environment* ev,
- ODStorageUnit* storageUnit,
- FW_EStorageKinds storageKind,
- FW_CCloneInfo* cloneInfo)
- {
- FW_UNUSED(cloneInfo);
- FW_UNUSED(storageKind);
- FW_PStorageUnitSink suSink(ev, storageUnit, kODPropContents, fPart->GetPartKind(ev));
- FW_CWritableStream stream(suSink);
-
- // write number
- stream << fNumPizzas;
-
- // write each item
- CPizzaCollectionIterator iter(fPizzaList);
- CPizza* pizza = NULL;
- for (pizza = iter.First(); iter.IsNotComplete(); pizza = iter.Next())
- FW_WRITE_DYNAMIC_OBJECT(stream, pizza, CPizza);
-
- #ifdef FW_BUILD_MAC
- if (::FW_IsCommandKeyPressed()) {
- FW_LOG_MESSAGE("Number of pizzas =");
- Str255 numString;
- ::NumToString(fNumPizzas, numString);
- DebugStr(numString);
- }
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- FW_Boolean
- CDataSaveContent::Internalize(Environment* ev,
- ODStorageUnit* storageUnit,
- FW_EStorageKinds storageKind,
- FW_CCloneInfo* cloneInfo)
- {
- FW_UNUSED(cloneInfo);
- FW_UNUSED(storageKind);
- FW_PStorageUnitSink suSink(ev, storageUnit, kODPropContents, fPart->GetPartKind(ev));
- FW_CReadableStream stream(suSink);
- // read number
- stream >> fNumPizzas;
- // read items; make list
- CPizza* pizza = NULL;
- for (long count = 0; count < fNumPizzas; count++) {
- FW_READ_DYNAMIC_OBJECT(stream, &pizza, CPizza);
- fPizzaList->AddLast(pizza);
- }
- return true;
- }
-