// $Revision: 1.3 $ // Copyright (C) 1995 Taligent, Inc. All rights reserved. #ifndef TaligentSamples_HYPERTEXTSCRAPITEM #include "HypertextScrapItem.h" #endif #ifndef TaligentSamples_COLLECTIONCOPY #include "CollectionCopy.h" #endif #ifndef TaligentSamples_LIBWWWINTERFACE #include "LibWWWInterface.h" #endif #ifndef Taligent_UNICODEGENERAL #include #endif #ifndef Taligent_TRANSCODING #include #endif MCollectibleDefinitionsMacro(THypertextScrapItem, kOriginalVersion); THypertextScrapItem::THypertextScrapItem() : TScrapItem(), fText(), fTitle(), fLibWWWHText(NIL) { // the NIL comparators ensure that identical text ranges will still be // allowed to serve as keys, since the default compares by pointer // address, which will not be the same for identical strings. fLinkStack = TDequeOf >(NIL, new TPolymorphicStreamer >); } THypertextScrapItem::THypertextScrapItem(const THypertextScrapItem& source) : TScrapItem(source), fText(source.fText), fTitle(source.fTitle), fLibWWWHText(NIL) { fLinkStack = TDequeOf >(NIL, new TPolymorphicStreamer >); CopyCollectionContents(source.fLinkStack, fLinkStack); } THypertextScrapItem::~THypertextScrapItem() { delete fLibWWWHText; fLinkStack.DeleteAll(); } THypertextScrapItem& THypertextScrapItem::operator=(const THypertextScrapItem& source) { if (&source != this) { TScrapItem::operator=(source); fText = source.fText; fTitle = source.fTitle; fLinkStack.DeleteAll(); CopyCollectionContents(source.fLinkStack, fLinkStack); } return *this; } TStream& THypertextScrapItem::operator>>=(TStream& toStream) const { ::WriteVersion(toStream); TScrapItem::operator>>=(toStream); fText >>= toStream; fTitle >>= toStream; fLinkStack >>= toStream; return toStream; } TStream& THypertextScrapItem::operator<<=(TStream& fromStream) { ::ReadVersion(fromStream, kOriginalVersion, kOriginalVersion); TScrapItem::operator<<=(fromStream); fText <<= fromStream; fTitle <<= fromStream; fLinkStack <<= fromStream; return fromStream; } const TText* THypertextScrapItem::GetText() const { return &fText; } const TText* THypertextScrapItem::GetTitle() const { return &fTitle; } void THypertextScrapItem::SetTitle(const TText& titleText) { fTitle = titleText; } void THypertextScrapItem::Append(const TText& text) { fText.Insert(text); } void THypertextScrapItem::AddStyle(const TStyle& style, const TTextRange& range) { fText.AddStyles(style, range); } void THypertextScrapItem::InternalCopyAvailableTypes( TSequenceOf& result, TMemoryHeap &whichHeap) const { TTypeDescription* type = new (whichHeap) TTypeDescription(StaticTypeInfo(TText)); result.Add(type); } void THypertextScrapItem::AddLinkRange(const TTextRange& range, const TURL& destination) { fLinkStack.Push(new TKeyValuePair(new TTextRange(range), new TURL(destination))); } TIteratorOver >* THypertextScrapItem::CreateLinkIterator() const { return fLinkStack.CreateIterator(); }