// $Revision: 1.1 $ // SimnpleDragAndDropItem.C // Copyright (C) 1994, 1995 Taligent, Inc. All rights reserved. #ifndef Taligent_SIMPLEDRAGANDDROPITEM #include "SimpleDragAndDropItem.h" #endif #ifndef Taligent_ASSERTIONS #include #endif MCollectibleDefinitionsMacro(TSimpleDragAndDropItem, kOriginalVersion); TSimpleDragAndDropItem::TSimpleDragAndDropItem() : TDragAndDropItem(), fDictionary(new TOperatorKeyValuePairComparator, new TPolymorphicPairStreamer >), fScraps(new TOperatorComparator, new TPolymorphicStreamer) { } TSimpleDragAndDropItem::TSimpleDragAndDropItem(const TViewHandle &viewForActions) : TDragAndDropItem(viewForActions), fDictionary(new TOperatorKeyValuePairComparator, new TPolymorphicPairStreamer >), fScraps(new TOperatorComparator, new TPolymorphicStreamer) { } TSimpleDragAndDropItem::TSimpleDragAndDropItem(const TSimpleDragAndDropItem& source) : TDragAndDropItem(source), fDictionary(new TOperatorKeyValuePairComparator, new TPolymorphicPairStreamer >), fScraps(new TOperatorComparator, new TPolymorphicStreamer) { CopyDictionaryAndScraps(source.fScraps); } TSimpleDragAndDropItem::~TSimpleDragAndDropItem() { fDictionary.DeleteAllKeys(); fScraps.DeleteAll(); } TSimpleDragAndDropItem& TSimpleDragAndDropItem::operator=(const TSimpleDragAndDropItem& source) { if (&source != this) { TDragAndDropItem::operator=(source); fDictionary.DeleteAllKeys(); fScraps.DeleteAll(); CopyDictionaryAndScraps(source.fScraps); } return *this; } TStream& TSimpleDragAndDropItem::operator>>=(TStream& toStream) const { ::WriteVersion(toStream); TDragAndDropItem::operator>>=(toStream); fDictionary >>= toStream; fScraps >>= toStream; return toStream; } TStream& TSimpleDragAndDropItem::operator<<=(TStream& fromStream) { ::ReadVersion(fromStream, kOriginalVersion, kOriginalVersion); TDragAndDropItem::operator<<=(fromStream); fDictionary <<= fromStream; fScraps <<= fromStream; return fromStream; } void TSimpleDragAndDropItem::CopyAvailableTypes(TSequenceOf& result, TMemoryHeap* whichHeap) const { TDeleterFor > > iterator = fDictionary.CreateIterator(); for (TKeyValuePair* scrap = iterator->First(); scrap != NIL; scrap = iterator->Next()) { result.Add(new (TAllocationHeap(whichHeap)) TTypeDescription(*scrap->GetKey())); } } TScrapItem* TSimpleDragAndDropItem::FindItemMatchingDescription(const TTypeDescription &theDescription) { TDeleterFor > > iterator = fDictionary.CreateIterator(); for (TKeyValuePair* scrap = iterator->First(); scrap != NIL; scrap = iterator->Next()) { if (theDescription == *scrap->GetKey()) { return scrap->GetValue(); } } ::Assertion(false, "Whoa! Bogus type passed to TSimpleDragAndDropItem::FindItemMatchingDescription"); return NIL; } void TSimpleDragAndDropItem::AdoptScrapItem(TScrapItem* scrapItem) { ::Assertion(scrapItem != NIL, "NIL was passed to TSimpleDragAndDropItem::AdoptScrapItem"); TDequeOf types; scrapItem->CopyAvailableTypes(types); TDeleterFor > iterator = types.CreateIterator(); fScraps.Add(scrapItem); for (TTypeDescription* type = iterator->First(); type != NIL; type = iterator->Next()) { fDictionary.Add(new TKeyValuePair( new TTypeDescription(*type), scrapItem)); } } void TSimpleDragAndDropItem::CopyDictionaryAndScraps(const TDequeOf& otherScraps) { TDeleterFor > iterator = otherScraps.CreateIterator(); for (TScrapItem* scrap = iterator->First(); scrap != NIL; scrap = iterator->Next()) { AdoptScrapItem(::Copy(*scrap)); } }