// $Revision: 1.3 $ // Copyright (C) 1994 Taligent, Inc. All rights reserved. #ifndef TaligentSamples_GRAPHICDOCUMENTSTATIONERY #include "GraphicDocumentStationery.h" #endif #ifndef TaligentSamples_GRPHICDOCUMENTVIEW #include "GraphicDocumentView.h" #endif #ifndef Taligent_MULTIPLEROOTLOCATOR #include #endif MCollectibleDefinitionsMacro(TGraphicDocumentStationery, kOriginalVersion); // This ensures that the stationery will be instantiated in the library // so it can be created by RunDocument. Since it is created with a NIL // graphic, it will not be directly usable. static TGraphicDocumentStationery instantiatedStationery(NIL); TDocumentReference TGraphicDocumentStationery::OpenGraphicDocument(MGraphic* adoptGraphic, const TFileSystemEntityName& documentName) { TDocumentReference documentReference; TMultipleRootLocator locator(THostSpecificPathName("Places/DefaultUserHomePage")); TDirectory directory = locator.GetWritableDirectory(TRUE); try { TDocumentComponentStationery* componentStationery = new TGraphicDocumentStationery(adoptGraphic); TCompoundDocumentStationery stationery(componentStationery); documentReference = stationery.CreateDocument( TStandardStorageMechanism(directory, documentName)); TDeleterFor environment( TPlaceEnvironment::CopyPlaceEnvironmentFor( TPlaceReference::GetDefaultPlace())); environment->OpenDocument(documentReference); } catch (const TStandardException& exception) { qprintf("ERROR: Unable to open graphic document\n"); } return documentReference; } TGraphicDocumentStationery::TGraphicDocumentStationery() : TDocumentComponentStationery(), fAdoptedGraphic(NIL) { } TGraphicDocumentStationery::TGraphicDocumentStationery(MGraphic* adoptGraphic) : TDocumentComponentStationery(), fAdoptedGraphic(adoptGraphic) { } TGraphicDocumentStationery::~TGraphicDocumentStationery() { delete fAdoptedGraphic; } TStream& TGraphicDocumentStationery::operator>>=(TStream& toStream) const { ::WriteVersion(toStream); TDocumentComponentStationery::operator>>=(toStream); ::Flatten(fAdoptedGraphic, toStream); return toStream; } TStream& TGraphicDocumentStationery::operator<<=(TStream& fromStream) { ::ReadVersion(fromStream, kOriginalVersion, kOriginalVersion); TDocumentComponentStationery::operator<<=(fromStream); ::Resurrect(fAdoptedGraphic, fromStream); return fromStream; } TModel* TGraphicDocumentStationery::CreateModel() { TAtomicModelOn* model = new TAtomicModelOn(::CopyPointer(fAdoptedGraphic)); return model; } TModelPresenterState* TGraphicDocumentStationery::CreateModelPresenterState() { return new TGUIPresenterStateFor >; }