// $Revision: 1.7 $ // SetGraphConstructorCommand.C // Copyright (C) 1994, 1995 Taligent, Inc. All rights reserved. #ifndef TaligentSamples_SETGRAPHCONSTRUCTORCOMMAND #include "SetGraphConstructorCommand.h" #endif #ifndef TaligentSamples_STOCKGRAPHCONSTRUCTOR #include "StockGraphConstructor.h" #endif #ifndef TaligentSamples_VIEWERPRESENTERSTATE #include "ViewerPresenterState.h" #endif TaligentTypeExtensionMacro(TSetGraphConstructorCommand); TSetGraphConstructorCommand::TSetGraphConstructorCommand( const TSetGraphConstructorCommand& source) : TCommandOn(source), fConstructor(NIL) { fConstructor = ::CopyPointer(source.fConstructor.GetObject()); } TSetGraphConstructorCommand::TSetGraphConstructorCommand( TStockGraphConstructor* adoptedConstructorToSet) : TCommandOn(kSerialUndo), fConstructor(adoptedConstructorToSet) { } TSetGraphConstructorCommand::~TSetGraphConstructorCommand() { } TSetGraphConstructorCommand& TSetGraphConstructorCommand::operator=(const TSetGraphConstructorCommand& source) { if (&source != this) { TCommandOn::operator=(source); fConstructor = ::CopyPointer(source.fConstructor.GetObject()); } return *this; } TStream& TSetGraphConstructorCommand::operator>>=(TStream& toStream) const { ::WriteVersion(toStream, kOriginalVersion); TCommandOn::operator>>=(toStream); ::Flatten(fConstructor.GetObject(), toStream); return toStream; } TStream& TSetGraphConstructorCommand::operator<<=(TStream& fromStream) { ::ReadVersion(fromStream, kOriginalVersion, kOriginalVersion); TCommandOn::operator<<=(fromStream); TStockGraphConstructor* constructor = NIL; ::Resurrect(constructor, fromStream); fConstructor = constructor; return fromStream; } TSetGraphConstructorCommand::TSetGraphConstructorCommand() : TCommandOn(kSerialUndo), fConstructor(NIL) { } void TSetGraphConstructorCommand::HandleDoBegin(TPresenterStateSelection& target) { TViewerPresenterState* presenterState = TViewerPresenterState::LookupForWriting(target.GetPresenterStateReference()); TStockGraphConstructor* oldGraphConstructor = presenterState->OrphanGraphConstructor(); presenterState->AdoptGraphConstructor(fConstructor.OrphanObject()); presenterState->NotifyOfChange(presenterState->GetNewGraphConstructorInterest()); fConstructor = oldGraphConstructor; } void TSetGraphConstructorCommand::HandleUndo(TPresenterStateSelection& target) { HandleDoBegin(target); } void TSetGraphConstructorCommand::HandleRedo(TPresenterStateSelection& target) { HandleDoBegin(target); }