// $Revision: 1.65 $ // Copyright (C) 1993-1995 Taligent, Inc. All Rights Reserved. #ifndef Taligent_BASICPLACES #include #endif #ifndef Taligent_WINDOWGROUP #include #endif #ifndef Taligent_COMPOUNDDOCUMENT #include #endif #ifndef Taligent_GUICOMPOUNDDOCUMENT #include "GUICompoundDocument.h" #endif #ifndef Taligent_GUICOMPOUNDDOCUMENTEMBEDDER #include "GUICompoundDocumentEmbedder.h" #endif #ifndef Taligent_GUICOMPOUNDDOCUMENTPRIVATE #include "GUICompoundDocumentPrivate.h" #endif #ifndef Taligent_LINKCREATEPRESENTERFUNCTOR #include "LinkCreatePresenterFunctor.h" #endif #ifndef Taligent_LOCALCLIPAREASNAPSHOT #include #endif #ifndef Taligent_VIEWREQUEST #include #endif #ifndef Taligent_LINKINGCOMMANDS #include "LinkingCommands.h" #endif #ifndef Taligent_LINKINGBORDER #include "LinkingBorder.h" #endif #ifndef Taligent_SMARTPOINTER #include #endif #ifndef Taligent_GUIEMBEDDERFRAMEINTERACTIONPOLICY #include "GUIEmbedderFrameInteractionPolicy.h" #endif // Needed for backwards-compatability with GraphicDocument. class TDocumentComponentViewImplementation { public: TDocumentComponentViewImplementation(); ~TDocumentComponentViewImplementation(); TRequestBasedMemberFunctionConnectionTo fConnection; }; TDocumentComponentViewImplementation::TDocumentComponentViewImplementation(): fConnection() { } TDocumentComponentViewImplementation::~TDocumentComponentViewImplementation() { } class TBasicFrameViewImplementation { public: TBasicFrameViewImplementation(); ~TBasicFrameViewImplementation(); TGUIPresenter* fPresenter; TRectControlState* fControlState; TRequestBasedMemberFunctionConnectionTo fConnection; // enum ELinkTypes { kDataSourceLink, kDataDestLink, kRefSourceLink, kRefDestLink, kUnknown }; TBasicFrameView::ELinkTypes fLinkType; }; TBasicFrameViewImplementation::TBasicFrameViewImplementation() : fPresenter( NIL ), fConnection(), fControlState( NIL ), fLinkType( TBasicFrameView::kUnknown ) { } TBasicFrameViewImplementation::~TBasicFrameViewImplementation() { delete fControlState; if (fPresenter) { fPresenter->Close(); delete fPresenter; } } // // TBasicFrameView Implementation // MCollectibleDefinitionsMacro(TBasicFrameView,kOriginalVersion); TBasicFrameView::TBasicFrameView( TGUIPresenter* thePresenter ) : TPrimitiveFrameView(), fImp( NIL ), VViewInitialize( &gMetaInfo ) { fImp = new(::kSameHeap, this) TBasicFrameViewImplementation; CheckForInitializeNoInit( &gMetaInfo ); Init( thePresenter, NIL ); } TBasicFrameView::TBasicFrameView( TGUIPresenter* thePresenter, TRectControlState* theCS ) : TPrimitiveFrameView(), fImp( NIL ), VViewInitialize( &gMetaInfo ) { fImp = new(::kSameHeap, this) TBasicFrameViewImplementation; CheckForInitializeNoInit( &gMetaInfo ); Init( thePresenter, theCS ); } TBasicFrameView::TBasicFrameView() : TPrimitiveFrameView(), fImp( NIL ), VViewInitialize( &gMetaInfo ) { fImp = new(::kSameHeap, this) TBasicFrameViewImplementation; CheckForInitializeNoInit( &gMetaInfo ); Init( NIL, NIL ); } TBasicFrameView::TBasicFrameView( const TBasicFrameView& copy ) : TPrimitiveFrameView( copy ), fImp( NIL ), VViewInitialize( &gMetaInfo ) { fImp = new(::kSameHeap, this) TBasicFrameViewImplementation; CheckForInitializeNoInit( &gMetaInfo ); Init( ::CopyPointer(copy.fImp->fPresenter), ::CopyPointer(copy.fImp->fControlState) ); } TBasicFrameView::~TBasicFrameView() { CheckForFinalizeNoInit( &gMetaInfo ); delete fImp; fImp = NIL; } TActivatibleView* TBasicFrameView::GetDefaultActiveChild() { if ( fImp->fPresenter ) { return fImp->fPresenter->GetDefaultActiveChild(); } return NIL; } void TBasicFrameView::Init( TGUIPresenter* thePresenter, TRectControlState* theCS ) { fImp->fPresenter = thePresenter; fImp->fControlState = theCS; if (thePresenter) { // TActivatibleView* theView = thePresenter->CreateMainViewForFrame(); // if (theView) // { // AdoptActivatibleChild( theView ); // } TView* theView = thePresenter->CreateMainView(); if (theView) { AdoptChild(theView); } TGUIPresenterActionBehavior* presenterActionBehavior = new TGUIPresenterActionBehavior(thePresenter,this,false); AdoptBehavior(presenterActionBehavior); thePresenter->Open(); } TLinkFrameBorder *theBorder = new TLinkFrameBorder(); AdoptLinkBorder(theBorder); fShowLinks = false; } void TBasicFrameView::AdoptState( TRectControlState* theControlState ) { ::Assertion( theControlState != NIL, "TBasicFrameView::AdoptControlState " " control state must not be NIL" ); if ( theControlState != fImp->fControlState ) { delete fImp->fControlState; fImp->fControlState = theControlState; } } void TBasicFrameView::HandleRequestMoveResizeInParent( const TGRect& theNewRect, bool isLast ) { if (fImp->fControlState) { fImp->fControlState->SetParent( this ); if (fImp->fControlState->IsEnabled()) { if ( ! isLast ) { fImp->fControlState->IntermediateSetRect( theNewRect ); } else { fImp->fControlState->FinalSetRect( theNewRect ); } } } else { SetAllocatedAreaInParent( theNewRect ); } } void TBasicFrameView::ResetState() { TGRect theOldRect = GetAllocatedArea(); TLinkFrameBorder *aLinkBorder = *fLinkBorder; if (aLinkBorder == NIL) return; TGRect theInnerRect = aLinkBorder->ExteriorToInterior(theOldRect); TFrameBorder::EVisualState state = aLinkBorder->GetVisualState(); aLinkBorder->SetVisualState(state); TGRect theNewRect = aLinkBorder->InteriorToExterior( theInnerRect ); if ( theNewRect != theOldRect ) { // See comment in SetAllocatedArea() about why we cast to TGArea. SetAllocatedArea( TGArea(theInnerRect) ); } } void TBasicFrameView::HandleChildActivate() { TPrimitiveFrameView::HandleChildActivate(); if ( fImp->fPresenter) { fImp->fPresenter->Activate( this ); } } void TBasicFrameView::HandleChildDeactivate() { TPrimitiveFrameView::HandleChildDeactivate(); if ( fImp->fPresenter ) { fImp->fPresenter->Deactivate( this ); } } void TBasicFrameView::HandleAfterConnectionToViewRoot() { TPrimitiveFrameView::HandleAfterConnectionToViewRoot(); if (fImp->fControlState ) { fImp->fConnection.SetReceiver( this ); fImp->fConnection.SetRequestProcessor( GetRequestProcessor() ); TSetOf theInterests; fImp->fControlState->AddInterests( theInterests ); if (theInterests.Count() > 0) { TSetOfIterator iter( &theInterests ); TInterest *interest = iter.First(); while (interest) { fImp->fConnection.AdoptInterest( interest, &(TBasicFrameView::HandleNotification)); interest = iter.Next(); } fImp->fConnection.Connect(); } } // Need to break it for linking support if (fImp->fPresenter) { fImp->fConnection.SetReceiver( this ); fImp->fConnection.SetRequestProcessor( GetRequestProcessor() ); fImp->fConnection.AddInterest(TGUIDocumentPresenter::CreateShowLinkChangedInterest(), &(TBasicFrameView::HandleShowLinkChanged)); TModelReference theModelRef = fImp->fPresenter->GetGUIBundle()->GetModelReference(); try { const TModelPointerTo theModel(theModelRef); fImp->fConnection.AddInterest( theModel->GetAddedLinkInterest(), TBasicFrameView::HandleAddedLink); fImp->fConnection.AddInterest(theModel->GetRemovedLinkInterest(), TBasicFrameView::HandleRemovedLink); } catch (...) { qprintf("TBasicFrameView::HandleSetPort: Cannot get model. Add/Remove link interest not added\n"); } fImp->fConnection.Connect(); } } void TBasicFrameView::HandleBeforeDisconnectionFromViewRoot() { if ( fImp->fConnection.IsConnected() ) { if ( fImp->fPresenter || fImp->fControlState) { fImp->fConnection.Disconnect(); fImp->fConnection.RemoveAllInterests(); } } TPrimitiveFrameView::HandleBeforeDisconnectionFromViewRoot(); } void TBasicFrameView::HandleRemovedLink(const TNotification& n) { // Later TLinkFrameBorder *aLinkBorder = (TLinkFrameBorder*)(*fLinkBorder); if (aLinkBorder == NIL) return; aLinkBorder->SetShowLinks(false); fShowLinks = false; if ( (fImp->fLinkType == TBasicFrameView::kDataSourceLink) || (fImp->fLinkType == TBasicFrameView::kDataDestLink) || (fImp->fLinkType == TBasicFrameView::kRefDestLink) || (fImp->fLinkType == TBasicFrameView::kRefSourceLink )) { fImp->fLinkType = TBasicFrameView::kUnknown; aLinkBorder->SetLinkType((TLinkFrameBorder::ELinkTypes) fImp->fLinkType); } // Reset the thickness of the border to Normal ResetState(); TView::Invalidate(); } void TBasicFrameView::HandleAddedLink(const TNotification& n) { TGUIBundle *theBundle = NIL; theBundle = fImp->fPresenter->GetGUIBundle(); TDocumentPresenter *theDocumentPresenter = NIL; theDocumentPresenter = (TDocumentPresenter *) TDocumentPresenter::Lookup(theBundle->GetDocumentPresenterReference()); TGUIDocumentPresenter *theGUIDocumentPresenter = NIL; DynamicCastTo(theGUIDocumentPresenter,theDocumentPresenter); // Need to do this for Reference Link const TModelLinkNotification *linkNotification = (TModelLinkNotification *)&n; TModelLinkReference theAddedLink = linkNotification->GetModelLinkReference(); TModelLink* aLink = NIL; aLink = GetLink(TBasicFrameView::kRefDestLink); if (!aLink) aLink = GetLink(TBasicFrameView::kRefSourceLink); // if ShowLink in DocumentPreseterState is true // Any link created needs to be shown, when showlinks menu is on. if ( theGUIDocumentPresenter && ( theGUIDocumentPresenter->GetShowLinks() || aLink ) ) { ShowLinks(true); } } void TBasicFrameView::ShowLinks(bool sLinks) { TLinkFrameBorder *aLinkBorder = (TLinkFrameBorder*)(*fLinkBorder); if (aLinkBorder == NIL) return; if (sLinks) { TGUIBundle *theBundle = NIL; theBundle = fImp->fPresenter->GetGUIBundle(); if (theBundle) { TModelReference theModelRef = theBundle->GetModelReference(); try { TDocumentComponentReadEntry theEntry( theModelRef ); const TModel* theModel = TModel::LookupForReading( theModelRef ); TModelAnchorReference theAnchorRef = NonConst(theModel)->GetWholeModelAnchorReference(); TModelAnchor *theModelAnchor = theModel->LookupAnchor(theAnchorRef); TDeleterFor > theIterator = theModelAnchor->CreateLinkIterator(); // check for the following attributes in the links. TReferenceLinkAttribute theRefLinkAttr; TDataLinkAttribute theDataLinkAttr; TDestinationLinkAttribute theDestLinkAttr; TSourceLinkAttribute theSourceLinkAttr; // Return Values from copy TDataLinkAttribute* theDLAttr = NIL; TReferenceLinkAttribute* theRLAttr = NIL; TDestinationLinkAttribute* theDstLnkAttr = NIL; TSourceLinkAttribute* theSrcLnkAttr = NIL; for ( TModelLink* aLink = theIterator->First(); aLink != NIL; aLink = theIterator->Next() ) { // if the properties are present then provide the proper feedback. theDLAttr = ( TDataLinkAttribute* ) aLink->CopyAttribute( theDataLinkAttr ); if (theDLAttr == NIL) // Can a link be both data and Reference Link?? theRLAttr = ( TReferenceLinkAttribute* ) aLink->CopyAttribute(theRefLinkAttr); // I think I should not be doing this Reference Links. Talk to Tom about it. if ( theDLAttr || theRLAttr ) { theDstLnkAttr = ( TDestinationLinkAttribute* ) aLink->CopyAttribute( theDestLinkAttr ); theSrcLnkAttr = ( TSourceLinkAttribute* ) aLink->CopyAttribute( theSourceLinkAttr ); if (theDLAttr) { if ( theDstLnkAttr ) // Future: Can a link be both Source and Destination? fImp->fLinkType = TBasicFrameView::kDataDestLink; else if ( theSrcLnkAttr ) fImp->fLinkType = TBasicFrameView::kDataSourceLink; } else { if ( theDstLnkAttr ) // Future: Can a link be both Source and Destination? fImp->fLinkType = TBasicFrameView::kRefDestLink; else if ( theSrcLnkAttr ) fImp->fLinkType = TBasicFrameView::kRefSourceLink; } } theDLAttr = NIL; theRLAttr = NIL; theDstLnkAttr = NIL; theSrcLnkAttr = NIL; } if ( fImp->fLinkType != TBasicFrameView::kUnknown) { fShowLinks = true; aLinkBorder->SetShowLinks(true); // Reset the thickness of the border to Normal // if (aLinkBorder->GetVisualState() == TFrameBorder::kNormal) ResetState(); // set the right info in the Border for type of link to be displayed. aLinkBorder->SetLinkType((TLinkFrameBorder::ELinkTypes) fImp->fLinkType); TView::Invalidate(); } } catch(...) { qprintf("TBasicFrameView::DrawContent: Could not get model\n"); } } } else { aLinkBorder->SetShowLinks(false); fShowLinks = false; if ( (fImp->fLinkType == TBasicFrameView::kDataSourceLink) || (fImp->fLinkType == TBasicFrameView::kDataDestLink) ) { fImp->fLinkType = TBasicFrameView::kUnknown; aLinkBorder->SetLinkType((TLinkFrameBorder::ELinkTypes) fImp->fLinkType); } // Reset the thickness of the border to Normal //if (aLinkBorder->GetVisualState() == TFrameBorder::kNormal) ResetState(); TView::Invalidate(); } } void TBasicFrameView::HandleShowLinkChanged(const TNotification& n) { TGUIBundle *theBundle = NIL; theBundle = fImp->fPresenter->GetGUIBundle(); TDocumentPresenter *theDocumentPresenter = NIL; theDocumentPresenter = (TDocumentPresenter *) TDocumentPresenter::Lookup(theBundle->GetDocumentPresenterReference()); TGUIDocumentPresenter *theGUIDocumentPresenter = NIL; DynamicCastTo(theGUIDocumentPresenter,theDocumentPresenter); // if ShowLink in DocumentPreseterState is true // Any link created needs to be shown, when showlinks menu is on. if (theGUIDocumentPresenter) { ShowLinks(theGUIDocumentPresenter->GetShowLinks()); } } void TBasicFrameView::DrawContents(TGrafPort& port) const { TPrintingFlagSnapshot printingFlag(port); if (printingFlag.IsPrintingPort()) return; TGArea localClip = TLocalClipAreaSnapshot(port).GetClipArea(); TGRect interior = GetInteriorAllocatedArea(); TGRect clipRect = localClip.GetBounds(); // Draw Frame. TPrimitiveFrameView::DrawContents(port); TLinkFrameBorder *aLinkBorder = (TLinkFrameBorder*)(*fLinkBorder); if (aLinkBorder && aLinkBorder->IsShowLink()) { if (aLinkBorder->GetVisualState() == TFrameBorder::kNormal) aLinkBorder->DrawNormalLinkBorder(port); else aLinkBorder->DrawLinks(port); } } bool TBasicFrameView::OpenDocumentAtOtherEnd(const TModelLink *aLink) { if (aLink) { TModelAnchorReference sourceRef = aLink->GetThereReference(); if (sourceRef.IsDefined()) { TDocumentReference theDocRef(sourceRef); if (!TDocumentPresenter::LookupFor(theDocRef)) { try { TLinkCreatePresenterFunctor aFunctor; TPlaceReference aPlaceRef = TPlaceReference::GetDefaultPlace(); TDocumentSurrogate aDocSurrogate(theDocRef); aFunctor(aDocSurrogate, aPlaceRef); return true; } catch (...) { qprintf("TBasicFrameView::OpenDocumentAtOtherEnd: Cannot Open the Document\n"); } } } } return false; } bool TBasicFrameView::MouseDown(TMouseDownEvent& mouseDownEvent) { TLinkFrameBorder *aLinkBorder = (TLinkFrameBorder *) (*fLinkBorder); if ((aLinkBorder == NIL) || (!aLinkBorder->IsShowLink())) { return TPrimitiveFrameView::MouseDown(mouseDownEvent); } // if mouse down is in the link graphic group than bool result = false; TGPoint mousePoint = mouseDownEvent.GetEventPosition(); int clicks = mouseDownEvent.GetClickCount(); TGRect localRect = aLinkBorder->GetGraphic()->GetLooseFitBounds(); TGArea localArea = TGArea(localRect); TGArea globalArea = localArea; LocalToGlobal(globalArea); TGRect globalRect = globalArea.GetBounds(); if (globalRect.Contains(mousePoint)) { CancelEventActivation(); TModelLink* aLink = NIL; if (fImp->fLinkType == TBasicFrameView::kDataDestLink) aLink = GetLink(TBasicFrameView::kDataDestLink); else if (fImp->fLinkType == TBasicFrameView::kRefSourceLink) aLink = GetLink(TBasicFrameView::kRefSourceLink); if (aLink) result = OpenDocumentAtOtherEnd(aLink); } else result = TPrimitiveFrameView::MouseDown(mouseDownEvent); return result; } TModelLink* TBasicFrameView::GetLink(ELinkTypes linkType) { TGUIBundle *theBundle = NIL; theBundle = fImp->fPresenter->GetGUIBundle(); TModelLink *rLink = NIL; if (theBundle) { TModelReference theModelRef = theBundle->GetModelReference(); try { TDocumentComponentReadEntry entry( theModelRef ); const TModel* theModel = TModel::LookupForReading( theModelRef ); TModelAnchorReference theAnchorRef = NonConst(theModel)->GetWholeModelAnchorReference(); TModelAnchor *theModelAnchor = theModel->LookupAnchor(theAnchorRef); TDeleterFor > theIterator = theModelAnchor->CreateLinkIterator(); // check for the following attributes in the links. TReferenceLinkAttribute theRefLinkAttr; TDataLinkAttribute theDataLinkAttr; TDestinationLinkAttribute theDestLinkAttr; TSourceLinkAttribute theSourceLinkAttr; // Return Values from copy TDataLinkAttribute* theDLAttr = NIL; TReferenceLinkAttribute* theRLAttr = NIL; TDestinationLinkAttribute* theDstLnkAttr = NIL; TSourceLinkAttribute* theSrcLnkAttr = NIL; for ( TModelLink* aLink = theIterator->First(); aLink != NIL; aLink = theIterator->Next() ) { switch (linkType) { case kDataDestLink: theDLAttr = ( TDataLinkAttribute* ) aLink->CopyAttribute( theDataLinkAttr ); if (theDLAttr) theDstLnkAttr = ( TDestinationLinkAttribute* ) aLink->CopyAttribute( theDestLinkAttr ); if (theDstLnkAttr) rLink = aLink; break; case kDataSourceLink: theDLAttr = ( TDataLinkAttribute* ) aLink->CopyAttribute( theDataLinkAttr ); if (theDLAttr) theSrcLnkAttr = ( TSourceLinkAttribute* ) aLink->CopyAttribute( theSourceLinkAttr ); if (theSrcLnkAttr) rLink = aLink; break; case kRefDestLink: theRLAttr = ( TReferenceLinkAttribute* ) aLink->CopyAttribute(theRefLinkAttr); if (theRLAttr) theDstLnkAttr = ( TDestinationLinkAttribute* ) aLink->CopyAttribute( theDestLinkAttr ); if (theDstLnkAttr) rLink = aLink; break; case kRefSourceLink: theRLAttr = ( TReferenceLinkAttribute* ) aLink->CopyAttribute(theRefLinkAttr); if (theRLAttr) theSrcLnkAttr = ( TSourceLinkAttribute* ) aLink->CopyAttribute( theSourceLinkAttr ); if (theSrcLnkAttr) rLink = aLink; break; } theDLAttr = NIL; theRLAttr = NIL; theDstLnkAttr = NIL; theSrcLnkAttr = NIL; } } catch(...) { qprintf("TBasicFrameView::GetDesinationLink Could not get model\n"); } } return rLink; } void TBasicFrameView::AdoptLinkBorder(TLinkFrameBorder *theBorder) { TPrimitiveFrameView::AdoptBorder(theBorder); fLinkBorder = new THandleTo(theBorder); theBorder->AliasHandleToLinkBorder(*fLinkBorder); } void TBasicFrameView::HandleNotification( const TNotification& n ) { if (fImp->fControlState && n.GetInterest() ) { fImp->fControlState->SetParent( this ); TGRect theInnerRect = GetInteriorAllocatedAreaInParent(); fImp->fControlState->Update( *n.GetInterest() ); SetSelected( fImp->fControlState->IsSelected() ); TGRect theRect = fImp->fControlState->GetRect(); if ( theRect != theInnerRect ) { SetAllocatedAreaInParent( theRect ); } } } TBasicFrameView& TBasicFrameView::operator=( const TBasicFrameView& other ) { if ( &other != this) { TPrimitiveFrameView::operator=( other ); // TBasicFrameView specific assignment here } return *this; } static TGUIPresenter* GetPresenter( const TDocumentComponent& theComponent, const TGUIBundle& theParentBundle ) { TPresenterStateReference thePSRef = theComponent.GetPresenterStateReference(); TGUIPresenter* thePresenter; TGUIPresenterState* theGUIState; const TModelPresenterState* thePS = TModelPresenterState::LookupForReading( thePSRef ); DynamicCastTo( theGUIState, thePS ); if ( theGUIState != NIL ) thePresenter = theGUIState->CreatePresenter( theParentBundle, false ); return thePresenter; } // // TFrameView Implementation // MCollectibleDefinitionsMacro(TFrameView,kOriginalVersion); TFrameView::TFrameView( const TDocumentComponent& theComponent, const TGUIBundle& theParentBundle ) : TBasicFrameView( ::GetPresenter( theComponent, theParentBundle ) ), VViewInitialize( &gMetaInfo ) { CheckForInitializeNoInit( &gMetaInfo ); } TFrameView::TFrameView( const TDocumentComponent& theComponent, const TGUIBundle& theParentBundle, TRectControlState* theCS ) : TBasicFrameView( ::GetPresenter( theComponent, theParentBundle ), theCS ), VViewInitialize( &gMetaInfo ) { CheckForInitializeNoInit( &gMetaInfo ); } TFrameView::TFrameView() : TBasicFrameView(), VViewInitialize( &gMetaInfo ) { CheckForInitializeNoInit( &gMetaInfo ); } TFrameView::TFrameView( const TFrameView& copy ) : TBasicFrameView( copy ), VViewInitialize( &gMetaInfo ) { CheckForInitializeNoInit( &gMetaInfo ); } TFrameView::~TFrameView() { CheckForFinalizeNoInit( &gMetaInfo ); } TFrameView& TFrameView::operator=( const TFrameView& other ) { if ( &other != this) { // TBasicFrameView::operator=( other ); } return *this; } // // TDocumentComponentView Implementation // MCollectibleDefinitionsMacro(TDocumentComponentView,kOriginalVersion); TDocumentComponentView::TDocumentComponentView( TGUIBundle* theBundleToAlias) : TContentView(), MGUIBundle(), VViewInitialize( &gMetaInfo ) { fImp = new(::kSameHeap, this) TDocumentComponentViewImplementation; SetGUIBundle(theBundleToAlias); CheckForInitializeNoInit( &gMetaInfo ); } TDocumentComponentView::TDocumentComponentView( TGUIBundle* theBundleToAlias, const TGPoint& itsAllocatedArea, const TGPoint& itsLocation, bool visible ) : TContentView(itsAllocatedArea, itsLocation, visible), MGUIBundle(), VViewInitialize( &gMetaInfo ) { fImp = new(::kSameHeap, this) TDocumentComponentViewImplementation; SetGUIBundle(theBundleToAlias); CheckForInitializeNoInit( &gMetaInfo ); } TDocumentComponentView::TDocumentComponentView( TGUIBundle* theBundleToAlias, const TGArea& itsAllocatedArea, const TGPoint& itsLocation, bool visible ) : TContentView(itsAllocatedArea, itsLocation, visible), MGUIBundle(), VViewInitialize( &gMetaInfo ) { fImp = new(::kSameHeap, this) TDocumentComponentViewImplementation; SetGUIBundle(theBundleToAlias); CheckForInitializeNoInit( &gMetaInfo ); } TDocumentComponentView::TDocumentComponentView(const TDocumentComponentView& copy) : TContentView(), MGUIBundle(copy), VViewInitialize( &gMetaInfo ) { fImp = new(::kSameHeap, this) TDocumentComponentViewImplementation; CheckForInitializeNoInit( &gMetaInfo ); } TDocumentComponentView::TDocumentComponentView() : TContentView(), MGUIBundle(), VViewInitialize( &gMetaInfo ) { fImp = new(::kSameHeap, this) TDocumentComponentViewImplementation; CheckForInitializeNoInit( &gMetaInfo ); } TDocumentComponentView::~TDocumentComponentView() { CheckForFinalizeNoInit( &gMetaInfo ); } TStream& TDocumentComponentView::operator>>= (TStream& toWhere) const { TContentView::operator>>=(toWhere); MGUIBundle::operator>>=(toWhere); return toWhere; } TStream& TDocumentComponentView::operator<<= (TStream& fromWhere) { TContentView::operator<<=(fromWhere); MGUIBundle::operator<<=(fromWhere); return fromWhere; } void TDocumentComponentView::SetBundle(TGUIBundle *theBundleToAlias) { GetGUIBundleConnection()->SetGUIBundle(theBundleToAlias); } void TDocumentComponentView::HandleAfterConnectionToViewRoot() { TContentView::HandleAfterConnectionToViewRoot(); fImp->fConnection.SetReceiver( this ); fImp->fConnection.SetRequestProcessor( GetRequestProcessor() ); if (GetGUIBundle() != NIL) { const TModelPointerTo theModel(GetModelReference()); fImp->fConnection.AddInterest( theModel->GetAllChangesInterest(), InternalHandleAllModelChanges); fImp->fConnection.AddInterest( GetSelectionChangedForPresenterInterest(), HandleCurrentSelectionChanged); } fImp->fConnection.Connect(); } void TDocumentComponentView::HandleBeforeDisconnectionFromViewRoot() { fImp->fConnection.Disconnect(); fImp->fConnection.RemoveAllInterests(); TContentView::HandleBeforeDisconnectionFromViewRoot(); } void TDocumentComponentView::HandleCurrentSelectionChanged( const TNotification& theNotification ) { HandleNotification( theNotification ); } void TDocumentComponentView::InternalHandleAllModelChanges( const TNotification& theNotification ) { const TInterest *interest = theNotification.GetInterest(); TDocumentComponentReadEntry theEntry( GetModelReference() ); const TModel* theModel = TModel::LookupForReading( GetModelReference() ); if (*interest == theModel->GetAddedLinkInterest()) HandleAddedLink(theNotification); if (*interest == theModel->GetRemovedLinkInterest()) HandleRemovedLink(theNotification); if (*interest == theModel->GetAddedAnchorInterest()) HandleAddedAnchor(theNotification); if (*interest == theModel->GetRemovedAnchorInterest()) HandleRemovedAnchor(theNotification); if (*interest == theModel->GetAnchorContentsReplacedInterest()) HandleAnchorContentsReplaced(theNotification); else HandleModelChanged(theNotification); } void TDocumentComponentView::HandleAddedLink( const TNotification& theNotification ) { } void TDocumentComponentView::HandleRemovedLink( const TNotification& theNotification ) { } void TDocumentComponentView::HandleAddedAnchor( const TNotification& theNotification ) { } void TDocumentComponentView::HandleRemovedAnchor( const TNotification& theNotification ) { } void TDocumentComponentView::HandleAnchorContentsReplaced( const TNotification& theNotification ) { HandleNotification( theNotification ); } void TDocumentComponentView::HandleModelChanged( const TNotification& theNotification ) { HandleNotification( theNotification ); } void TDocumentComponentView::HandleNotification( const TNotification& ) { InvalidateAll(); } TDocumentComponentView& TDocumentComponentView::operator=( const TDocumentComponentView& other) { if ( &other != this) { // inherited::operator=( other ); // TDocumentComponentView specific assignment here } return *this; } // // TGUIEmbedderModelView Implementation // MCollectibleDefinitionsMacro( TGUIEmbedderModelView, kOriginalVersion ); const TRGBColor TGUIEmbedderModelView::fgNormalColor( 1.0, 1.0, 1.0 ); const TRGBColor TGUIEmbedderModelView::fgSelectedColor( 1.0, 1.0, 0.6 ); const TRGBColor TGUIEmbedderModelView::fgActiveSelectedColor( 1.0, 1.0, 0.2 ); TGUIEmbedderModelView::TGUIEmbedderModelView( TGUIBundle* theBundleToAlias ) : TDocumentComponentView( theBundleToAlias ), MMouseEventHandler(), fConnection(), fEmbeddedViews( new(kSameHeap, this) TMCollectibleKeyValuePairComparator< TDocumentComponentReference, TFrameView>, new(kSameHeap, this) TPolymorphicPairStreamer > ), VViewInitialize( &gMetaInfo ) { CheckForInitializeNoInit( &gMetaInfo ); } TGUIEmbedderModelView::TGUIEmbedderModelView( const TGUIEmbedderModelView& copy ) : TDocumentComponentView( copy ), MMouseEventHandler( copy ), fConnection(), fEmbeddedViews( new(kSameHeap, this) TMCollectibleKeyValuePairComparator< TDocumentComponentReference, TFrameView>, new(kSameHeap, this) TPolymorphicPairStreamer > ), VViewInitialize( &gMetaInfo ) { CheckForInitializeNoInit( &gMetaInfo ); } TGUIEmbedderModelView::TGUIEmbedderModelView() : TDocumentComponentView(), MMouseEventHandler(), fConnection(), fEmbeddedViews( new(kSameHeap, this) TMCollectibleKeyValuePairComparator< TDocumentComponentReference, TFrameView>, new(kSameHeap, this) TPolymorphicPairStreamer > ), VViewInitialize( &gMetaInfo ) { CheckForInitializeNoInit( &gMetaInfo ); } TGUIEmbedderModelView::~TGUIEmbedderModelView() { CheckForFinalizeNoInit( &gMetaInfo ); } TStream& TGUIEmbedderModelView::operator>>= (TStream& toWhere) const { TDocumentComponentView::operator>>=(toWhere); return toWhere; } TStream& TGUIEmbedderModelView::operator<<= (TStream& fromWhere) { TDocumentComponentView::operator<<=(fromWhere); return fromWhere; } void TGUIEmbedderModelView::HandleAfterConnectionToViewRoot() { TDocumentComponentView::HandleAfterConnectionToViewRoot(); fConnection.SetRequestProcessor( GetRequestProcessor() ); fConnection.SetReceiver( this ); if ( GetGUIBundle() != NIL ) { try { const TModelPointerTo theModel( GetModelReference() ); fConnection.AddInterest( theModel->GetAddedComponentInterest(), &TGUIEmbedderModelView::HandleAddedComponent ); fConnection.AddInterest( theModel->GetRemovedComponentInterest(), &TGUIEmbedderModelView::HandleRemovedComponent ); fConnection.AddInterest( theModel->GetComponentAreaChangedInterest(), &TGUIEmbedderModelView::HandleComponentAreaChanged ); // Create views for all embedded models. TDeleterFor< TIteratorOver > aCompIterator = theModel->CreateComponentIterator(); for ( TComponentArea* aComp = aCompIterator->First(); aComp != NIL; aComp = aCompIterator->Next() ) { CreateComponentAreaView( *aComp ); } } catch( const TCompoundDocumentException& ) { // Model may not exist. } } fConnection.Connect(); } void TGUIEmbedderModelView::HandleBeforeDisconnectionFromViewRoot() { // Removed presentations for all embedded models. TDictionaryOfIterator theIterator( &fEmbeddedViews ); for ( TKeyValuePair* aPair = theIterator.First(); aPair != NIL; aPair = theIterator.Next() ) { OrphanChild( *aPair->GetValue() ); } fEmbeddedViews.DeleteAll(); fConnection.Disconnect(); fConnection.RemoveAllInterests(); TDocumentComponentView::HandleBeforeDisconnectionFromViewRoot(); } void TGUIEmbedderModelView::HandleActivate() { TDocumentComponentView::HandleActivate(); // We're becoming active, show feedback on selected frames. const TDocumentComponentSelection* theSelection = GetCurrentSelection(); const MEmbeddedComponentAccessor* theAccessor = NIL; if ( theSelection ) { const TModelSelection* theModelSelection = theSelection->GetModelSelection(); DynamicCastTo( theAccessor, theModelSelection ); } // If the selection has changed. if ( theAccessor != NIL ) { // Set selected state of embedded frames. TDictionaryOfIterator theIterator( &fEmbeddedViews ); for ( TKeyValuePair* aPair = theIterator.First(); aPair != NIL; aPair = theIterator.Next() ) { aPair->GetValue()->SetSelected( theAccessor->IsSelected( *aPair->GetKey() ) ); } } Invalidate(); } void TGUIEmbedderModelView::HandleDeactivate() { TDocumentComponentView::HandleDeactivate(); // We're becoming inactive, deselect all frames. TDictionaryOfIterator theIterator( &fEmbeddedViews ); for ( TKeyValuePair* aPair = theIterator.First(); aPair != NIL; aPair = theIterator.Next() ) { aPair->GetValue()->SetSelected( false ); } Invalidate(); } TIteratorOver >* TGUIEmbedderModelView::CreateFrameIterator() const { return new TDictionaryOfIterator ( &fEmbeddedViews ); } void TGUIEmbedderModelView::CreateComponentAreaView( const TComponentArea& theCompLayout ) { TFrameView* theFrameView = NIL; theFrameView = fEmbeddedViews.ValueAt( theCompLayout.GetComponent()->GetReference()); if ( theFrameView == NIL ) { theFrameView = HandleCreateComponentAreaView( theCompLayout ); if ( theFrameView != NIL ) { fEmbeddedViews.AddKeyValuePair( new TDocumentComponentReference( theCompLayout.GetComponent()->GetReference() ), theFrameView ); AdoptChild( theFrameView ); } } } TFrameView* TGUIEmbedderModelView::HandleCreateComponentAreaView( const TComponentArea& theCompLayout ) { return new TComponentAreaFrameView( theCompLayout, *GetGUIBundle() ); } void TGUIEmbedderModelView::DeleteComponentAreaView( const TDocumentComponentReference& theCompRef ) { TFrameView* theFrameView = NIL; theFrameView = fEmbeddedViews.Delete( NonConst(&theCompRef) ); if ( theFrameView != NIL ) { OrphanChild( *theFrameView ); HandleDeleteComponentAreaView( theCompRef, theFrameView ); } } void TGUIEmbedderModelView::HandleDeleteComponentAreaView( const TDocumentComponentReference& theCompRef, TFrameView* theFrameView ) { delete theFrameView; } void TGUIEmbedderModelView::UpdateComponentAreaView( const TComponentArea& theCompLayout ) { TFrameView* theFrameView = NIL; theFrameView = fEmbeddedViews.ValueAt( theCompLayout.GetComponent()->GetReference()); if ( theFrameView != NIL ) { HandleUpdateComponentAreaView( theCompLayout, *theFrameView ); } } void TGUIEmbedderModelView::HandleUpdateComponentAreaView( const TComponentArea& theCompLayout, TFrameView& theFrameView ) { TGArea theArea = theCompLayout.GetArea(); theFrameView.SetAllocatedAreaInParent( theArea ); } void TGUIEmbedderModelView::DrawContents( TGrafPort& thePort ) const { } void TGUIEmbedderModelView::HandleAddedComponent( const TNotification& theNotification ) { const TDocumentComponentNotification& theComponentNotification = (const TDocumentComponentNotification&) theNotification; const TModelPointerTo theModel( GetModelReference() ); TDocumentComponentReference theCompRef = theComponentNotification.GetComponentReference(); const TComponentArea* theLayout = theModel->LookupComponent( theCompRef ); if ( theLayout ) { CreateComponentAreaView( *theLayout ); } } void TGUIEmbedderModelView::HandleRemovedComponent( const TNotification& theNotification ) { const TDocumentComponentNotification& theComponentNotification = (const TDocumentComponentNotification&) theNotification; DeleteComponentAreaView( theComponentNotification.GetComponentReference() ); } void TGUIEmbedderModelView::HandleComponentAreaChanged( const TNotification& theNotification ) { const TDocumentComponentNotification& theComponentNotification = (const TDocumentComponentNotification&) theNotification; const TModelPointerTo theModel( GetModelReference() ); TDocumentComponentReference theCompRef = theComponentNotification.GetComponentReference(); const TComponentArea* theLayout = theModel->LookupComponent( theCompRef ); if ( theLayout ) { UpdateComponentAreaView( *theLayout ); } } bool TGUIEmbedderModelView::MouseDown( TMouseDownEvent& mouseDown ) { RegisterSimpleTarget( *InternalGetEventReceiver() ); TGUIEmbedderModelSelectionInteractor *theInteractor = new TGUIEmbedderModelSelectionInteractor( this ); mouseDown.StartInteractor( theInteractor ); return true; } void TGUIEmbedderModelView::SelectComponentsIntersecting( const TGRect& theRect, TGUIEmbedderModelSelection& theEmbedderSelelction) { // Iterate over the component views, selecting each that intersects with // the bounds. theEmbedderSelelction.DeselectAllComponents(); TDictionaryOfIterator i ( &fEmbeddedViews ); TKeyValuePair* aPair; for ( aPair = i.First(); aPair != NIL; aPair = i.Next() ) { if ( aPair->GetValue()-> GetAllocatedAreaInParent().Intersects( theRect ) ) { theEmbedderSelelction.SelectComponent( *aPair->GetKey() ); } } } void TGUIEmbedderModelView::HandleSelectionDragStart( const TGPoint& ) { TModelSelection* theSelection = NIL; { const TModelPointerTo theModel(GetModelReference()); theSelection = theModel->CreateSelection(); } theSelection->DeselectAll(); AdoptCurrentModelSelection( theSelection ); } void TGUIEmbedderModelView::HandleSelectionDragChange( const TGRect& theOldDragBounds, const TGRect& theNewDragBounds ) { TModelSelection* theSelection = ::CopyPointer( GetCurrentModelSelection() ); if ( theSelection == NIL ) { const TModelPointerTo theModel( GetModelReference() ); theSelection = theModel->CreateSelection(); } TGUIEmbedderModelSelection* theEmbedderSelection; DynamicCastTo( theEmbedderSelection, theSelection ); if ( theEmbedderSelection ) { SelectComponentsIntersecting( theNewDragBounds, *theEmbedderSelection ); } AdoptCurrentModelSelection( theSelection ); InvalidateAll(); } void TGUIEmbedderModelView::HandleSelectionDragEnd( const TGRect& theDragBounds ) { TModelSelection* theSelection = ::CopyPointer( GetCurrentModelSelection() ); if ( theSelection == NIL ) { const TModelPointerTo theModel( GetModelReference() ); theSelection = theModel->CreateSelection(); } TGUIEmbedderModelSelection* theEmbedderSelection; DynamicCastTo( theEmbedderSelection, theSelection ); if ( theEmbedderSelection ) { SelectComponentsIntersecting( theDragBounds, *theEmbedderSelection ); } AdoptCurrentModelSelection( theSelection ); InvalidateAll(); } TGUIEmbedderModelView& TGUIEmbedderModelView::operator=( const TGUIEmbedderModelView& other ) { if ( &other != this) { //TDocumentComponentView::operator=( other ); // TGUIEmbedderModelView specific assignment here } return *this; } // // TComponentAreaFrameView Implementation // MCollectibleDefinitionsMacro(TComponentAreaFrameView,kOriginalVersion); TComponentAreaFrameView::TComponentAreaFrameView( const TComponentArea& theLayout, const TGUIBundle& theBundle ) : TFrameView( *theLayout.GetComponent(), theBundle ), VViewInitialize( &gMetaInfo ) { CheckForInitializeNoInit( &gMetaInfo ); SetAllocatedAreaInParent( theLayout.GetArea() ); TComponentAreaRectControlState* theCS = new TComponentAreaRectControlState; theCS->SetGUIBundle( NonConst(&theBundle) ); theCS->SetDocumentComponentReference( theLayout.GetComponent()->GetReference() ); AdoptInteractionPolicy(new TEmbedderFrameInteractionPolicy(NonConst(this), NonConst(&theBundle), theLayout.GetComponent()->GetReference() )); AdoptState( theCS ); } TComponentAreaFrameView::TComponentAreaFrameView( const TComponentArea& theLayout, const TGUIBundle& theBundle, TRectControlState* theCS ) : TFrameView( *theLayout.GetComponent(), theBundle, theCS ), VViewInitialize( &gMetaInfo ) { CheckForInitializeNoInit( &gMetaInfo ); SetAllocatedAreaInParent( theLayout.GetArea() ); AdoptInteractionPolicy(new TEmbedderFrameInteractionPolicy(NonConst(this), NonConst(&theBundle), theLayout.GetComponent()->GetReference() )); } TComponentAreaFrameView::TComponentAreaFrameView(): TFrameView(), VViewInitialize( &gMetaInfo ) { CheckForInitializeNoInit( &gMetaInfo ); } TComponentAreaFrameView::TComponentAreaFrameView( const TComponentAreaFrameView& o ) : TFrameView( o ), VViewInitialize( &gMetaInfo ) { CheckForInitializeNoInit( &gMetaInfo ); } TComponentAreaFrameView::~TComponentAreaFrameView() { CheckForFinalizeNoInit( &gMetaInfo ); }