summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2022-08-08 15:07:27 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2022-08-10 08:07:43 +0200
commitc83f85dcd9960e73564fe9a1b5866bee6c779118 (patch)
tree0eb1dc6213598aac896be7b7120177658afd1069
parentunique_ptr->optional in MoveNodeRange (diff)
downloadcore-c83f85dcd9960e73564fe9a1b5866bee6c779118.tar.gz
core-c83f85dcd9960e73564fe9a1b5866bee6c779118.zip
unique_ptr->optional in SwTextFootnote
Change-Id: Icc08fde3d385403d59fde8555f4b1d160209f3a1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138057 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--sw/inc/txtftn.hxx6
-rw-r--r--sw/source/core/edit/edattr.cxx2
-rw-r--r--sw/source/core/fields/reffld.cxx2
-rw-r--r--sw/source/core/txtnode/atrftn.cxx45
-rw-r--r--sw/source/filter/html/htmlftn.cxx4
5 files changed, 26 insertions, 33 deletions
diff --git a/sw/inc/txtftn.hxx b/sw/inc/txtftn.hxx
index cd3af3c2074e..57cab883565f 100644
--- a/sw/inc/txtftn.hxx
+++ b/sw/inc/txtftn.hxx
@@ -21,16 +21,16 @@
#include <rtl/ustring.hxx>
#include "txatbase.hxx"
+#include "ndindex.hxx"
class SwNodeIndex;
-class SwTextNode;
class SwNodes;
class SwDoc;
class SwRootFrame;
class SW_DLLPUBLIC SwTextFootnote final : public SwTextAttr
{
- std::unique_ptr<SwNodeIndex> m_pStartNode;
+ std::optional<SwNodeIndex> m_oStartNode;
SwTextNode * m_pTextNode;
sal_uInt16 m_nSeqNo;
@@ -38,7 +38,7 @@ public:
SwTextFootnote( SwFormatFootnote& rAttr, sal_Int32 nStart );
virtual ~SwTextFootnote() override;
- SwNodeIndex *GetStartNode() const { return m_pStartNode.get(); }
+ const SwNodeIndex *GetStartNode() const { return m_oStartNode ? &*m_oStartNode : nullptr; }
void SetStartNode( const SwNodeIndex *pNode, bool bDelNodes = true );
void SetNumber(sal_uInt16 nNumber, sal_uInt16 nNumberRLHidden, const OUString &sNumStr);
void CopyFootnote(SwTextFootnote & rDest, SwTextNode & rDestNode) const;
diff --git a/sw/source/core/edit/edattr.cxx b/sw/source/core/edit/edattr.cxx
index 610adc8c42f5..459ff365d8b7 100644
--- a/sw/source/core/edit/edattr.cxx
+++ b/sw/source/core/edit/edattr.cxx
@@ -455,7 +455,7 @@ size_t SwEditShell::GetSeqFootnoteList( SwSeqFieldList& rList, bool bEndNotes )
if ( rFootnote.IsEndNote() != bEndNotes )
continue;
- SwNodeIndex* pIdx = pTextFootnote->GetStartNode();
+ const SwNodeIndex* pIdx = pTextFootnote->GetStartNode();
if( pIdx )
{
SwNodeIndex aIdx( *pIdx, 1 );
diff --git a/sw/source/core/fields/reffld.cxx b/sw/source/core/fields/reffld.cxx
index 03ad0ee90920..c304f311df7f 100644
--- a/sw/source/core/fields/reffld.cxx
+++ b/sw/source/core/fields/reffld.cxx
@@ -1269,7 +1269,7 @@ SwTextNode* SwGetRefFieldType::FindAnchor( SwDoc* pDoc, const OUString& rRefMark
}
// otherwise: the position at the start of the footnote
// will be mapped to something visible at least...
- SwNodeIndex* pIdx = pFootnoteIdx->GetStartNode();
+ const SwNodeIndex* pIdx = pFootnoteIdx->GetStartNode();
if( pIdx )
{
SwNodeIndex aIdx( *pIdx, 1 );
diff --git a/sw/source/core/txtnode/atrftn.cxx b/sw/source/core/txtnode/atrftn.cxx
index 69dc06c3db98..79dd0f903605 100644
--- a/sw/source/core/txtnode/atrftn.cxx
+++ b/sw/source/core/txtnode/atrftn.cxx
@@ -300,16 +300,9 @@ void SwTextFootnote::SetStartNode( const SwNodeIndex *pNewNode, bool bDelNode )
{
if( pNewNode )
{
- if ( !m_pStartNode )
- {
- m_pStartNode.reset(new SwNodeIndex(*pNewNode));
- }
- else
- {
- *m_pStartNode = *pNewNode;
- }
+ m_oStartNode = *pNewNode;
}
- else if ( m_pStartNode )
+ else if ( m_oStartNode )
{
// need to do 2 things:
// 1) unregister footnotes at their pages
@@ -325,7 +318,7 @@ void SwTextFootnote::SetStartNode( const SwNodeIndex *pNewNode, bool bDelNode )
// attribute isn't anchored in the TextNode yet.
// If it is deleted (e.g. Insert File with footnote
// inside fly frame), the content must also be deleted.
- pDoc = &m_pStartNode->GetNodes().GetDoc();
+ pDoc = &m_oStartNode->GetNodes().GetDoc();
}
// If called from ~SwDoc(), must not delete the footnote nodes,
@@ -336,7 +329,7 @@ void SwTextFootnote::SetStartNode( const SwNodeIndex *pNewNode, bool bDelNode )
{
// 2) delete the section for the footnote nodes
// it's possible that the Inserts have already been deleted (how???)
- pDoc->getIDocumentContentOperations().DeleteSection( &m_pStartNode->GetNode() );
+ pDoc->getIDocumentContentOperations().DeleteSection( &m_oStartNode->GetNode() );
}
else
// If the nodes are not deleted, their frames must be removed
@@ -344,7 +337,7 @@ void SwTextFootnote::SetStartNode( const SwNodeIndex *pNewNode, bool bDelNode )
// them (particularly not Undo)
DelFrames( nullptr );
}
- m_pStartNode.reset();
+ m_oStartNode.reset();
// remove the footnote from the SwDoc's array
for( size_t n = 0; n < pDoc->GetFootnoteIdxs().size(); ++n )
@@ -381,11 +374,11 @@ void SwTextFootnote::InvalidateNumberInLayout()
SwNodes &rNodes = m_pTextNode->GetDoc().GetNodes();
const sw::LegacyModifyHint aHint(nullptr, &GetFootnote());
m_pTextNode->TriggerNodeUpdate(aHint);
- if ( m_pStartNode )
+ if ( m_oStartNode )
{
// must iterate over all TextNodes because of footnotes on other pages
- SwNodeOffset nSttIdx = m_pStartNode->GetIndex() + 1;
- SwNodeOffset nEndIdx = m_pStartNode->GetNode().EndOfSectionIndex();
+ SwNodeOffset nSttIdx = m_oStartNode->GetIndex() + 1;
+ SwNodeOffset nEndIdx = m_oStartNode->GetNode().EndOfSectionIndex();
for( ; nSttIdx < nEndIdx; ++nSttIdx )
{
SwNode* pNd;
@@ -399,21 +392,21 @@ void SwTextFootnote::CopyFootnote(
SwTextFootnote & rDest,
SwTextNode & rDestNode ) const
{
- if (m_pStartNode && !rDest.GetStartNode())
+ if (m_oStartNode && !rDest.GetStartNode())
{
// dest missing node section? create it here!
// (happens in SwTextNode::CopyText if pDest == this)
rDest.MakeNewTextSection( rDestNode.GetNodes() );
}
- if (m_pStartNode && rDest.GetStartNode())
+ if (m_oStartNode && rDest.GetStartNode())
{
// footnotes not necessarily in same document!
SwDoc& rDstDoc = rDestNode.GetDoc();
SwNodes &rDstNodes = rDstDoc.GetNodes();
// copy only the content of the section
- SwNodeRange aRg( m_pStartNode->GetNode(), SwNodeOffset(1),
- *m_pStartNode->GetNode().EndOfSectionNode() );
+ SwNodeRange aRg( m_oStartNode->GetNode(), SwNodeOffset(1),
+ *m_oStartNode->GetNode().EndOfSectionNode() );
// insert at the end of rDest, i.e., the nodes are appended.
// nDestLen contains number of ContentNodes in rDest _before_ copy.
@@ -441,7 +434,7 @@ void SwTextFootnote::CopyFootnote(
/// create a new nodes-array section for the footnote
void SwTextFootnote::MakeNewTextSection( SwNodes& rNodes )
{
- if ( m_pStartNode )
+ if ( m_oStartNode )
return;
// set the footnote style on the SwTextNode
@@ -466,7 +459,7 @@ void SwTextFootnote::MakeNewTextSection( SwNodes& rNodes )
SwStartNode* pSttNd = rNodes.MakeTextSection( rNodes.GetEndOfInserts(),
SwFootnoteStartNode, pFormatColl );
- m_pStartNode.reset(new SwNodeIndex(*pSttNd));
+ m_oStartNode = *pSttNd;
}
void SwTextFootnote::DelFrames(SwRootFrame const*const pRoot)
@@ -497,10 +490,10 @@ void SwTextFootnote::DelFrames(SwRootFrame const*const pRoot)
}
//JP 13.05.97: if the layout is deleted before the footnotes are deleted,
// try to delete the footnote's frames by another way
- if ( bFrameFnd || !m_pStartNode )
+ if ( bFrameFnd || !m_oStartNode )
return;
- SwNodeIndex aIdx( *m_pStartNode );
+ SwNodeIndex aIdx( *m_oStartNode );
SwContentNode* pCNd = m_pTextNode->GetNodes().GoNext( &aIdx );
if( !pCNd )
return;
@@ -586,11 +579,11 @@ void SwTextFootnote::dumpAsXml(xmlTextWriterPtr pWriter) const
(void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwTextFootnote"));
SwTextAttr::dumpAsXml(pWriter);
- if (m_pStartNode)
+ if (m_oStartNode)
{
- (void)xmlTextWriterStartElement(pWriter, BAD_CAST("m_pStartNode"));
+ (void)xmlTextWriterStartElement(pWriter, BAD_CAST("m_oStartNode"));
(void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("index"),
- BAD_CAST(OString::number(sal_Int32(m_pStartNode->GetIndex())).getStr()));
+ BAD_CAST(OString::number(sal_Int32(m_oStartNode->GetIndex())).getStr()));
(void)xmlTextWriterEndElement(pWriter);
}
if (m_pTextNode)
diff --git a/sw/source/filter/html/htmlftn.cxx b/sw/source/filter/html/htmlftn.cxx
index 45f5b76b84eb..9e7ab7cc9a64 100644
--- a/sw/source/filter/html/htmlftn.cxx
+++ b/sw/source/filter/html/htmlftn.cxx
@@ -230,7 +230,7 @@ SwNodeIndex *SwHTMLParser::GetFootEndNoteSection( const OUString& rName )
{
if (m_pFootEndNoteImpl->aTextFootnotes[i].sName == aName)
{
- pStartNodeIdx = m_pFootEndNoteImpl->aTextFootnotes[i].pTextFootnote->GetStartNode();
+ pStartNodeIdx = const_cast<SwNodeIndex*>(m_pFootEndNoteImpl->aTextFootnotes[i].pTextFootnote->GetStartNode());
m_pFootEndNoteImpl->aTextFootnotes.erase( m_pFootEndNoteImpl->aTextFootnotes.begin() + i );
if (m_pFootEndNoteImpl->aTextFootnotes.empty())
{
@@ -371,7 +371,7 @@ void SwHTMLWriter::OutFootEndNotes()
IncIndentLevel(); // indent content of <DIV>
OSL_ENSURE( pTextFootnote, "SwHTMLWriter::OutFootEndNotes: SwTextFootnote is missing" );
- SwNodeIndex *pSttNdIdx = pTextFootnote->GetStartNode();
+ const SwNodeIndex *pSttNdIdx = pTextFootnote->GetStartNode();
OSL_ENSURE( pSttNdIdx,
"SwHTMLWriter::OutFootEndNotes: StartNode-Index is missing" );
if( pSttNdIdx )