// $Revision: 1.5 $ // Copyright (C) 1995 Taligent, Inc. All rights reserved. #ifndef TaligentSamples_XBMTRANSLATOR #include "XBMTranslator.h" #endif #ifndef TaligentSamples_XBM #include "XBM.h" #endif #ifndef TaligentSamples_ATOMICMODEL #include #endif #ifndef TaligentSamples_GRAPHICDOCUMENTVIEW #include #endif #ifndef Taligent_GUICOMPOUNDDOCUMENT #include #endif #ifndef Taligent_SCRAPITEMON #include #endif MCollectibleDefinitionsMacro(TXBMTranslator, kOriginalVersion); const TTypeDescription TXBMTranslator::kGraphicScrapType( StaticTypeInfo(TScrapItemOn)); const TTypeDescription TXBMTranslator::kEmbedderModelScrapType = TEmbedderModel::GetTypeDescription(); TXBMTranslator::TXBMTranslator() { } TXBMTranslator::TXBMTranslator(const TXBMTranslator& source) : TForeignDataTranslator(source) { } TXBMTranslator::~TXBMTranslator() { } TXBMTranslator& TXBMTranslator::operator=(const TXBMTranslator& source) { if (&source != this) { TForeignDataTranslator::operator=(source); } return *this; } TStream& TXBMTranslator::operator>>=(TStream& toStream) const { ::WriteVersion(toStream); TForeignDataTranslator::operator>>=(toStream); return toStream; } TStream& TXBMTranslator::operator<<=(TStream& fromStream) { ::ReadVersion(fromStream, kOriginalVersion, kOriginalVersion); TForeignDataTranslator::operator<<=(fromStream); return fromStream; } TScrapItem* TXBMTranslator::CreateScrapItem(const TForeignData& inputData, const TTypeDescription& desiredType, TMemoryHeap* heap) const { TAllocationHeap newHeap(heap); TDeleterFor scrapItem = 0; if (desiredType == kGraphicScrapType) { MGraphic* graphic = CreateGraphic(inputData); scrapItem = new (newHeap) TScrapItemOn(graphic, TGPoint::kOrigin); } else if (desiredType == kEmbedderModelScrapType) { MGraphic* graphic = CreateGraphic(inputData); TModel* model = new (newHeap) TAtomicModelOn(graphic); TModelPresenterState* presenterState = new (newHeap) TGUIPresenterStateFor >; scrapItem = CreateEmbedderScrapItem(model, presenterState, heap); } else { throw TForeignDataException(TForeignDataException::kInvalidTranslator); } return scrapItem.OrphanObject(); } void TXBMTranslator::ExportData(const TTypeDescription& inputType, const TScrapItem& inputData, const TForeignDataType& desiredType, TForeignData& output) const { // not currently implemented. throw TForeignDataException(TForeignDataException::kInvalidTranslator); } MGraphic* TXBMTranslator::CreateGraphic(const TForeignData& inputData) const { TDeleterFor stream = inputData.CreateStreamForReading(); TXBMConverter converter; TModifiableImage* image = converter.CreateFrom(*stream); return (MGraphic*)image; }