/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
m_bHidden = rOther.m_bHidden; // FIXME: old code did not assign m_bHiddenFlag ? // FIXME: why should m_bCondHiddenFlag always default to true?
m_bCondHiddenFlag = true;
SwDoc& rDoc = pFormat->GetDoc(); if( rDoc.IsInDtor() )
{ // We reattach our Format to the default FrameFormat // to not get any dependencies if( pFormat->DerivedFrom() != rDoc.GetDfltFrameFormat() )
pFormat->RegisterToFormat( *rDoc.GetDfltFrameFormat() );
} else
{
pFormat->Remove(*this); // remove
SvtListener::EndListeningAll();
if (SectionType::Content != m_Data.GetType())
{
rDoc.getIDocumentLinksAdministration().GetLinkManager().Remove( m_RefLink.get() );
}
if (m_RefObj.is())
{
rDoc.getIDocumentLinksAdministration().GetLinkManager().RemoveServer( m_RefObj.get() );
}
// If the Section is the last Client in the Format we can delete it
pFormat->RemoveAllUnos(); if( !pFormat->HasWriterListeners() )
{ // Do not add to the Undo. This should've happened earlier.
::sw::UndoGuard const undoGuard(rDoc.GetIDocumentUndoRedo());
rDoc.DelSectionFormat( pFormat );
}
} if (m_RefObj.is())
{
m_RefObj->Closed();
}
}
void SwSection::SetSectionData(SwSectionData const& rData)
{ boolconst bOldHidden( m_Data.IsHidden() ); boolconst bOldCondHidden{m_Data.IsCondHidden()};
m_Data = rData; // The next two may actually overwrite the m_Data.m_bProtect or EditInReadonly Flag // in Modify, which should result in same flag value as the old code!
SetProtect(m_Data.IsProtectFlag());
SetEditInReadonly(m_Data.IsEditInReadonlyFlag()); if (bOldHidden != m_Data.IsHidden()
|| bOldCondHidden != m_Data.IsCondHidden()) // check if changed...
{
ImplSetHiddenFlag(m_Data.IsHidden(), m_Data.IsCondHidden());
}
}
bool SwSection::DataEquals(SwSectionData const& rCmp) const
{ // note that the old code compared the flags of the parameter with the // format attributes of this; the following mess should do the same...
(void) GetLinkFileName(); // updates m_sLinkFileName boolconst bProtect(m_Data.IsProtectFlag()); boolconst bEditInReadonly(m_Data.IsEditInReadonlyFlag());
m_Data.SetProtectFlag(IsProtect());
m_Data.SetEditInReadonlyFlag(IsEditInReadonly()); boolconst bResult( m_Data == rCmp );
m_Data.SetProtectFlag(bProtect);
m_Data.SetEditInReadonlyFlag(bEditInReadonly); return bResult;
}
if (bHide) // should be hidden
{ if (!m_Data.IsHiddenFlag()) // is not hidden
{ // Is the Parent hidden? // This should be shown by the bHiddenFlag.
// Tell all Children that they are hidden const sw::SectionHidden aHint;
pFormat->CallSwClientNotify(aHint);
}
} elseif (m_Data.IsHiddenFlag()) // show Nodes again
{ // Show all Frames // Only if the Parent Section is not restricting us!
SwSection* pParentSect = pFormat->GetParentSection(); if( !pParentSect || !pParentSect->IsHiddenFlag() )
{ // Tell all Children that the Parent is not hidden anymore const sw::SectionHidden aHint(false);
pFormat->CallSwClientNotify(aHint);
}
}
}
void SwSection::Notify(SfxHint const& rHint)
{ if (rHint.GetId() == SfxHintId::SwSectionHidden)
{ auto rSectionHidden = static_cast<const sw::SectionHidden&>(rHint);
m_Data.SetHiddenFlag(rSectionHidden.m_isHidden || (m_Data.IsHidden() && m_Data.IsCondHidden())); return;
} if (rHint.GetId() == SfxHintId::SwObjectDying)
{ auto pDyingHint = static_cast<const sw::ObjectDyingHint*>(&rHint);
CheckRegistration( *pDyingHint ); return;
} if (rHint.GetId() != SfxHintId::SwLegacyModify && rHint.GetId() != SfxHintId::SwAttrSetChange) return;
bool bUpdateFootnote = false; if (rHint.GetId() == SfxHintId::SwLegacyModify)
{ auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); auto pOld = pLegacy->m_pOld; auto pNew = pLegacy->m_pNew; switch(pLegacy->GetWhich())
{ case RES_PROTECT: if( pNew )
{ bool bNewFlag = static_cast<const SvxProtectItem*>(pNew)->IsContentProtected(); // this used to inherit the flag from the parent, but then there is // no way to turn it off in an inner section
m_Data.SetProtectFlag( bNewFlag );
} return; // edit in readonly sections case RES_EDIT_IN_READONLY: if( pNew )
{ constbool bNewFlag = static_cast<const SwFormatEditInReadonly*>(pNew)->GetValue();
m_Data.SetEditInReadonlyFlag( bNewFlag );
} return;
case RES_COL: // Is handled by the Layout, if appropriate break;
// Set/remove the linked FileName
OUString const & SwSection::GetLinkFileName() const
{ if (m_RefLink.is())
{
OUString sTmp; switch (m_Data.GetType())
{ case SectionType::DdeLink:
sTmp = m_RefLink->GetLinkSourceName(); break;
case SectionType::FileLink:
{
OUString sRange;
OUString sFilter; if (m_RefLink->GetLinkManager() &&
sfx2::LinkManager::GetDisplayNames(
m_RefLink.get(), nullptr, &sTmp, &sRange, &sFilter ))
{
sTmp += OUStringChar(sfx2::cTokenSeparator) + sFilter
+ OUStringChar(sfx2::cTokenSeparator) + sRange;
} elseif( GetFormat() && !GetFormat()->GetSectionNode() )
{ // If the Section is in the UndoNodesArray, the LinkManager // does not contain the Link, thus it cannot be queried for it. // Thus return the current Name. return m_Data.GetLinkFileName();
}
} break; default: break;
}
m_Data.SetLinkFileName(sTmp);
} return m_Data.GetLinkFileName();
}
SwSectionNode* pSectNd; const SwNodeIndex* pIdx = GetContent( false ).GetContentIdx(); if( pIdx && &GetDoc().GetNodes() == &pIdx->GetNodes() &&
nullptr != (pSectNd = pIdx->GetNode().GetSectionNode() ))
{
SwSection& rSect = pSectNd->GetSection(); // If it was a linked Section, we need to make all Child Links // visible again if( rSect.IsConnected() )
SwSection::MakeChildLinksVisible( *pSectNd );
// Check whether we need to be visible, before deleting the Nodes if( rSect.IsHiddenFlag() )
{
SwSection* pParentSect = rSect.GetParent(); if( !pParentSect || !pParentSect->IsHiddenFlag() )
{ // Make Nodes visible again
rSect.SetHidden(false);
}
} // mba: test iteration; objects are removed while iterating // use hint which allows to specify, if the content shall be saved or not
CallSwClientNotify( SwSectionFrameMoveAndDeleteHint( true ) );
// Do not destroy all Frames in aDepend (Frames are recognized with a dynamic_cast). void SwSectionFormat::DelFrames()
{
SwSectionNode* pSectNd; const SwNodeIndex* pIdx = GetContent(false).GetContentIdx(); if( pIdx && &GetDoc().GetNodes() == &pIdx->GetNodes() &&
nullptr != (pSectNd = pIdx->GetNode().GetSectionNode() ))
{ // First delete the <SwSectionFrame> of the <SwSectionFormat> instance // mba: test iteration as objects are removed in iteration // use hint which allows to specify, if the content shall be saved or not
CallSwClientNotify( SwSectionFrameMoveAndDeleteHint( false ) );
// Then delete frames of the nested <SwSectionFormat> instances
SwIterator<SwSectionFormat,SwSectionFormat> aIter( *this );
SwSectionFormat *pLast = aIter.First(); while ( pLast )
{
pLast->DelFrames();
pLast = aIter.Next();
}
// Send Hint for PageDesc. Actually the Layout contained in the // Paste of the Frame itself would need to do this. But that leads // to subsequent errors, which we'd need to solve at run-time.
SwNodeIndex aNextNd( *pIdx );
SwContentNode* pCNd = SwNodes::GoNextSection(&aNextNd, true, false); if( pCNd )
{ const SfxPoolItem& rItem = pCNd->GetSwAttrSet().Get(RES_PAGEDESC);
pCNd->CallSwClientNotify(sw::LegacyModifyHint(&rItem, &rItem));
}
}
// Get info from the Format bool SwSectionFormat::GetInfo(SwFindNearestNode& rInfo) const
{ if(GetFormatAttr( RES_PAGEDESC ).GetPageDesc())
{ const SwSectionNode* pNd = GetSectionNode(); if(pNd)
rInfo.CheckNode(*pNd);
} returntrue;
}
// get all Sections that have been derived from this one void SwSectionFormat::GetChildSections( SwSections& rArr,
SectionSort eSort, bool bAllSections ) const
{
rArr.clear();
// Do we need any sorting? if( 1 < rArr.size() ) switch( eSort )
{ case SectionSort::Pos:
std::sort( rArr.begin(), rArr.end(), lcl_SectionCmpPos ); break; case SectionSort::Not: break;
}
}
// See whether the Section is within the Nodes or the UndoNodes array bool SwSectionFormat::IsInNodesArr() const
{ const SwNodeIndex* pIdx = GetContent(false).GetContentIdx(); return pIdx && &pIdx->GetNodes() == &GetDoc().GetNodes();
}
// Parent was changed void SwSectionFormat::UpdateParent()
{ if(!HasWriterListeners()) return;
// n.b.: if the section format represents an index, then there is both a // SwXDocumentIndex and a SwXTextSection instance for this single core object. // these two can both implement XMetadatable and forward to the same core // section format. but here only one UNO object can be returned, // so always return the text section.
uno::Reference< rdf::XMetadatable >
SwSectionFormat::MakeUnoObject()
{
rtl::Reference<SwXTextSection> xMeta;
SwSection *const pSection( GetSection() ); if (pSection)
{
xMeta = SwXTextSection::CreateXTextSection(this,
SectionType::ToxHeader == pSection->GetType());
} return xMeta;
}
void SwSectionFormats::dumpAsXml(xmlTextWriterPtr pWriter) const
{
(void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwSectionFormats")); for (size_t i = 0; i < size(); ++i)
GetFormat(i)->dumpAsXml(pWriter);
(void)xmlTextWriterEndElement(pWriter);
}
// Method to break section links inside a linked section staticvoid lcl_BreakSectionLinksInSect( const SwSectionNode& rSectNd )
{ if ( !rSectNd.GetSection().IsConnected() )
{
OSL_FAIL( "method - no Link at Section of SectionNode" ); return;
} const ::sfx2::SvBaseLink* pOwnLink( &(rSectNd.GetSection().GetBaseLink() ) ); const ::sfx2::SvBaseLinks& rLnks = rSectNd.GetDoc().getIDocumentLinksAdministration().GetLinkManager().GetLinks(); for ( auto n = rLnks.size(); n > 0; )
{
SwIntrnlSectRefLink* pSectLnk = dynamic_cast<SwIntrnlSectRefLink*>(&(*rLnks[ --n ])); if ( pSectLnk && pSectLnk != pOwnLink &&
pSectLnk->IsInRange( rSectNd.GetIndex(), rSectNd.EndOfSectionIndex() ) )
{ // break the link of the corresponding section. // the link is also removed from the link manager
SwSectionNode* pSectNode = pSectLnk->GetSectNode();
assert(pSectNode);
pSectNode->GetSection().BreakLink();
// for robustness, because link is removed from the link manager if ( n > rLnks.size() )
{
n = rLnks.size();
}
}
}
}
if( !pSectNd || rDoc.IsInDtor() || ChkNoDataFlag() ||
sfx2::LinkManager::RegisterStatusInfoId() == nDataFormat )
{ // Should we be in the Undo already? return SUCCESS;
}
// #i38810# - Due to possible existing signatures, the // document has to be modified after updating a link.
rDoc.getIDocumentState().SetModified(); // set additional flag that links have been updated, in order to check this // during load.
rDoc.getIDocumentLinksAdministration().SetLinksUpdated( true );
// store page count of the source document to calculate // the physical page number of the objects anchored at page const SwDocStat& rDStat = pSrcDoc->getIDocumentStatistics().GetDocStat();
m_rSectFormat.GetSection()->SetPageNum(rDStat.nPage);
// tdf#121119 keep objects anchored at page auto pSrcFormats = pSrcDoc->GetSpzFrameFormats();
sal_uInt32 nPrevPages = 0; for( sw::SpzFrameFormat* pCpyFormat: *pSrcFormats)
{
SwFormatAnchor aAnchor( pCpyFormat->GetAnchor() ); if ( RndStdIds::FLY_AT_PAGE == aAnchor.GetAnchorId() )
{ // add file name of the source document to the name of the copied object // Note: used for the recognition of the copied objects anchored at page
pCpyFormat->SetFormatName( UIName(pCpyFormat->GetName().toString() + " (" + sFileName + ")") );
// sum page counts of the previous sections if ( nPrevPages == 0 )
{ const SwSectionFormats& rFormats = rDoc.GetSections(); for( size_t n = 0; n < rFormats.size() && rFormats[n] != &m_rSectFormat; ++n )
{ if ( const SwSection * pGlobalDocSection = rFormats[n]->GetGlobalDocSection() )
nPrevPages += pGlobalDocSection->GetPageNum();
}
}
// set corrected physical page number of the object
aAnchor.SetPageNum( nPrevPages + aAnchor.GetPageNum() );
// copy object anchored at page to the target document
rDoc.getIDocumentLayoutAccess().CopyLayoutFormat( *pCpyFormat, aAnchor, true, true );
}
}
// Delete last Node, only if it was copied successfully // (the Section contains more than one Node) if( SwNodeOffset(2) < pSectNd->EndOfSectionIndex() - pSectNd->GetIndex() )
{
aSave = rInsPos;
pPam->Move( fnMoveBackward, GoInNode );
pPam->SetMark(); // Rewire both SwPositions
// remove all undo actions and turn undo on again
rDoc.GetIDocumentUndoRedo().DelAllUndoObj();
rDoc.GetIDocumentUndoRedo().DoUndo(bWasUndo);
rDoc.getIDocumentLinksAdministration().SetVisibleLinks( bWasVisibleLinks );
// Make all Links within the Section visible again
SwSectionNode* pSectNd = m_rSectFormat.GetSectionNode(); if( pSectNd )
SwSection::MakeChildLinksVisible( *pSectNd );
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.