// $Revision: 1.10 $ // Copyright (C) 1994 Taligent, Inc. All rights reserved. #ifndef Taligent_GUICOMPOUNDDOCUMENTEMBEDDER #include "GUICompoundDocumentEmbedder.h" #endif #ifndef Taligent_GUICOMPOUNDDOCUMENTCOMMAND #include "GUICompoundDocumentCommand.h" #endif #ifndef Taligent_LABEL #include #endif typedef TGUIDocumentComponentCommandBindingTo TLayoutBinding; class TLayoutCommand : public TCommandOn { public: TLayoutCommand( const TDocumentComponentReference&); TLayoutCommand( const TLayoutCommand& ); ~TLayoutCommand(); void SetRect( const TGRect& ); virtual TStream& operator>>=( TStream& toWhere ) const; virtual TStream& operator<<=( TStream& fromWhere ); MCollectibleDeclarationsMacro(TLayoutCommand); protected: TLayoutCommand(); void HandleDoBegin( MEmbeddedComponentAccessor& ); void HandleDoIncrement( MEmbeddedComponentAccessor& ); void HandleUndo( MEmbeddedComponentAccessor& ); void HandleRedo( MEmbeddedComponentAccessor& ); #ifndef NO_Internal private: TDocumentComponentReference fDocumentComponentReference; TGRect fInitial; TGRect fFinal; enum Version { kOriginalVersion }; #endif }; class TComponentAreaRectControlStateImplementation { public: TComponentAreaRectControlStateImplementation(); ~TComponentAreaRectControlStateImplementation(); TGUIBundle* fBundle; TDocumentComponentReference fDocumentComponentReference; TLayoutBinding* fBinding; }; TComponentAreaRectControlStateImplementation:: TComponentAreaRectControlStateImplementation() : fBundle( NIL ), fDocumentComponentReference(), fBinding( NIL ) { } TComponentAreaRectControlStateImplementation:: ~TComponentAreaRectControlStateImplementation() { } MCollectibleDefinitionsMacro(TComponentAreaRectControlState,kOriginalVersion); TComponentAreaRectControlState::TComponentAreaRectControlState() : TRectControlState(), fImp( new(::kSameHeap, this) TComponentAreaRectControlStateImplementation) { } TComponentAreaRectControlState::TComponentAreaRectControlState( const TDocumentComponentReference& theCompRef, TGUIBundle* theBundleToAlias ) : TRectControlState(), fImp( new(::kSameHeap, this) TComponentAreaRectControlStateImplementation) { fImp->fBundle = theBundleToAlias; fImp->fDocumentComponentReference = theCompRef; } TComponentAreaRectControlState::TComponentAreaRectControlState( const TComponentAreaRectControlState& o): TRectControlState( o ), fImp( new(::kSameHeap, this) TComponentAreaRectControlStateImplementation) { } TComponentAreaRectControlState::~TComponentAreaRectControlState() { delete fImp; } TGUIBundle* TComponentAreaRectControlState::GetGUIBundle() const { if ( fImp->fBundle == NIL ) { // TBD: pick better exception throw TDocumentException( TDocumentException::kNILObject ); } return fImp->fBundle; } void TComponentAreaRectControlState::SetGUIBundle( TGUIBundle* theBundleToAlias ) { fImp->fBundle = theBundleToAlias; } TDocumentComponentReference TComponentAreaRectControlState::GetDocumentComponentReference() const { return fImp->fDocumentComponentReference; } void TComponentAreaRectControlState::SetDocumentComponentReference( const TDocumentComponentReference& theCompRef ) { fImp->fDocumentComponentReference = theCompRef ; } TGRect TComponentAreaRectControlState::GetRect() const { //TBD: get area from model const TModelPointerTo theModel( GetGUIBundle()->GetModelReference()); TModelSelection* theSelection = theModel->CreateSelection(); TDeleterFor forCleanup = theSelection; MEmbeddedComponentAccessor* theAccessor; DynamicCastTo( theAccessor, theSelection ); TGRect theRect( 10, 10, 90, 90 ); if ( theAccessor ) { TGArea theArea; theAccessor->GetComponentArea( fImp->fDocumentComponentReference, theArea ); theRect = theArea.GetBounds(); } return theRect; } void TComponentAreaRectControlState::IntermediateSetRect( const TGRect& theRect ) { //TBD: issue do increment on command to change area bool isFirst = false; if (fImp->fBinding == NIL ) { isFirst = true; MEmbeddedComponentAccessor* theAccessor = NIL; { const TModelPointerTo theModel( GetGUIBundle()->GetModelReference()); TModelSelection* theSelection = theModel->CreateSelection(); theSelection->DeselectAll(); DynamicCastTo( theAccessor, theSelection ); if ( theAccessor == NIL ) { delete theSelection; throw TCompoundDocumentException( TCompoundDocumentException:: kTargetNotAcceptable ); } } TLayoutCommand* theCommand = new TLayoutCommand( fImp->fDocumentComponentReference ); fImp->fBinding = new TLayoutBinding( theCommand, theAccessor, *GetGUIBundle(), TStandardText( "Frame Resize" ) ); fImp->fBinding->SetUpdateCurrentSelection( false ); } if (fImp->fBinding != NIL ) { ((TLayoutCommand*)(fImp->fBinding->GetCommand()))->SetRect( theRect ); TCompoundDocumentSurrogate theSurrogate( GetGUIBundle()->GetDocumentReference() ); try { if ( isFirst ) { theSurrogate.DoBegin( *fImp->fBinding ); } else { theSurrogate.DoIncrement( *fImp->fBinding ); } } catch( ... ) { } } } void TComponentAreaRectControlState::FinalSetRect( const TGRect& theRect ) { IntermediateSetRect( theRect ); if (fImp->fBinding != NIL ) { TCompoundDocumentSurrogate theSurrogate( GetGUIBundle()->GetDocumentReference() ); try { theSurrogate.AdoptAndDoEnd( fImp->fBinding ); } catch( ... ) { } fImp->fBinding = NIL; } } bool TComponentAreaRectControlState::IsSelected() const { const TDocumentComponentSelection* theCompSelection = GetGUIBundle()->GetCurrentSelection(); bool result = false; MEmbeddedComponentAccessor* theAccessor = NIL; if ( theCompSelection != NIL && theCompSelection->GetModelSelection() != NIL && theCompSelection->GetModelSelection()->GetModelReference()== GetGUIBundle()->GetModelReference() ) { const TModelSelection* theModelSelection = theCompSelection->GetModelSelection(); DynamicCastTo( theAccessor, theModelSelection ); } if ( theAccessor ) { result = theAccessor->IsSelected( fImp->fDocumentComponentReference ); } return result; } void TComponentAreaRectControlState::Update( const TInterest& ) { } void TComponentAreaRectControlState::AddInterests(TSetOf &set) { try { set.Add( new TGUIBundleInterest( GetGUIBundle()->GetCurrentSelectionChangeInterest() ) ); const TModelPointerTo theModel( GetGUIBundle()->GetModelReference() ); TDeleterFor theSelection = theModel->CreateSelection(); MEmbeddedComponentAccessor* theAccessor; DynamicCastTo( theAccessor, theSelection.GetObject() ); if ( theAccessor ) { theAccessor->AddInterests( set ); } } catch( ... ) { } } // Standard operators and MCollectible overrides TComponentAreaRectControlState& TComponentAreaRectControlState::operator =( const TComponentAreaRectControlState& other ) { if ( &other != this) { TRectControlState::operator=( other ); // TComponentAreaRectControlState specific assignment here } return *this; } TStream& TComponentAreaRectControlState::operator >>=(TStream& toWhere ) const { WriteVersion(toWhere); TRectControlState::operator >>= ( toWhere ); // Add streaming code for TComponentAreaRectControlState here return toWhere; } TStream& TComponentAreaRectControlState::operator <<=(TStream& fromWhere ) { VersionInfo theVersion = ReadVersion( fromWhere ); switch (theVersion) { case kOriginalVersion: TRectControlState::operator <<= ( fromWhere ); // Add streaming code for TComponentAreaRectControlState here break; default: throw TInvalidVersionError(); break; } return fromWhere; } long TComponentAreaRectControlState::Hash() const { // The hash value should be constant throughout the lifetime // of an instance. return 0; } bool TComponentAreaRectControlState::IsEqual( const MCollectible* other ) const { bool result; if (typeid(*this) == typeid(*other)) { TComponentAreaRectControlState* otherTComponentAreaRectControlState= (TComponentAreaRectControlState *) other; result = true; } else { result = false; } return result; } // // TLayoutCommand Implementation // MCollectibleDefinitionsMacro(TLayoutCommand,kOriginalVersion); TLayoutCommand::TLayoutCommand(const TDocumentComponentReference& component) : TCommandOn( TCommonCommand::kSerialUndo ), fDocumentComponentReference( component ), fInitial(), fFinal() { } TLayoutCommand::TLayoutCommand() : TCommandOn( TCommonCommand::kSerialUndo ), fDocumentComponentReference(), fInitial(), fFinal() { } TLayoutCommand::TLayoutCommand( const TLayoutCommand& o) : TCommandOn( o ), fDocumentComponentReference(), fInitial( o.fInitial ), fFinal( o.fFinal ) { } TLayoutCommand::~TLayoutCommand() { } void TLayoutCommand::SetRect( const TGRect& theRect ) { fFinal = theRect; } void TLayoutCommand::HandleDoBegin( MEmbeddedComponentAccessor& theAccessor ) { TGArea theArea; theAccessor.GetComponentArea( fDocumentComponentReference, theArea ); fInitial = theArea.GetBounds(); theAccessor.SetComponentArea( fDocumentComponentReference, fFinal ); } void TLayoutCommand::HandleDoIncrement( MEmbeddedComponentAccessor& theAccessor ) { theAccessor.SetComponentArea( fDocumentComponentReference, fFinal ); } void TLayoutCommand::HandleUndo( MEmbeddedComponentAccessor& theAccessor ) { theAccessor.SetComponentArea( fDocumentComponentReference, fInitial ); } void TLayoutCommand::HandleRedo( MEmbeddedComponentAccessor& theAccessor ) { theAccessor.SetComponentArea( fDocumentComponentReference, fFinal ); } TStream& TLayoutCommand::operator>>=( TStream& toWhere ) const { WriteVersion(toWhere); TCommandOn::operator >>= ( toWhere ); fDocumentComponentReference >>= toWhere; fInitial >>= toWhere; fFinal >>= toWhere; return toWhere; } TStream& TLayoutCommand::operator<<=( TStream& fromWhere ) { VersionInfo theVersion = ReadVersion( fromWhere ); switch (theVersion) { case kOriginalVersion: TCommandOn::operator <<= ( fromWhere ); fDocumentComponentReference <<= fromWhere; fInitial <<= fromWhere; fFinal <<= fromWhere; break; default: throw TInvalidVersionError(); break; } return fromWhere; }