sw/inc/flypos.hxx | 22 ++++++++-------------- sw/qa/extras/ww8export/ww8export.cxx | 4 ++-- sw/qa/extras/ww8import/ww8import.cxx | 8 ++++---- sw/source/core/doc/DocumentDrawModelManager.cxx | 4 ++-- sw/source/core/doc/doclay.cxx | 10 +++++----- sw/source/core/layout/flypos.cxx | 24 +++++++----------------- sw/source/core/unocore/unoobj2.cxx | 4 ++-- sw/source/filter/html/htmlfly.cxx | 2 +- sw/source/filter/html/htmlflywriter.cxx | 6 +++--- sw/source/filter/ww8/writerhelper.cxx | 6 +++--- 10 files changed, 37 insertions(+), 53 deletions(-)
New commits: commit 3369a24c48781fd5b8afe9bb707f92588825f6c3 Author: Noel Grandin <[email protected]> AuthorDate: Wed Aug 24 21:03:01 2022 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Thu Aug 25 07:57:57 2022 +0200 Use SwNode instead of SwNodeIndex in SwPosFlyFrame part of hiding the internals of SwPosition. Also (*) Just define the whole class in the header, it is a dead simple data carrier. Then the virtual destructor and the SAL_DLLPUBLIC_RTTI becomes unnecessary. (*) No need to use shared_ptr, these are never shared, the call sites read the data and then discard them. Change-Id: I7fb64fd2bfa3469a7dfa4a325bb508457ca759a6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138776 Tested-by: Jenkins Reviewed-by: Noel Grandin <[email protected]> diff --git a/sw/inc/flypos.hxx b/sw/inc/flypos.hxx index fc098c4ffaab..d04ff03bff24 100644 --- a/sw/inc/flypos.hxx +++ b/sw/inc/flypos.hxx @@ -24,31 +24,25 @@ #include <set> class SwFrameFormat; -class SwNodeIndex; +class SwNode; /// For querying current flys in document. -class SAL_DLLPUBLIC_RTTI SwPosFlyFrame final +class SwPosFlyFrame final { const SwFrameFormat* m_pFrameFormat; ///< FlyFrameFormat - SwNodeIndex* m_pNodeIndex; ///< Index for node is sufficient. + const SwNode* m_pNode; sal_uInt32 m_nOrdNum; + public: - SwPosFlyFrame( const SwNodeIndex& , const SwFrameFormat*, sal_uInt16 nArrPos ); - virtual ~SwPosFlyFrame(); ///< Virtual for Writer (DLL !!) + SwPosFlyFrame(const SwNode& rNd, const SwFrameFormat* pFormat, sal_uInt16 nArrPos); const SwFrameFormat& GetFormat() const { return *m_pFrameFormat; } - const SwNodeIndex& GetNdIndex() const { return *m_pNodeIndex; } + const SwNode& GetNode() const { return *m_pNode; } sal_uInt32 GetOrdNum() const { return m_nOrdNum; } }; -// define needed classes to safely handle an array of allocated SwPosFlyFrame(s). -// SwPosFlyFrames can be handled by value (as return value), only refcounts to -// contained SwPosFlyFrame* will be copied. When releasing the last SwPosFlyFramePtr -// instance the allocated instance will be freed. The array is sorted by -// GetNdIndex by using a std::set container. -typedef std::shared_ptr< SwPosFlyFrame > SwPosFlyFramePtr; -struct SwPosFlyFrameCmp { bool operator()(const SwPosFlyFramePtr& rA, const SwPosFlyFramePtr& rB) const; }; -typedef std::set< SwPosFlyFramePtr, SwPosFlyFrameCmp > SwPosFlyFrames; +struct SwPosFlyFrameCmp { bool operator()(const SwPosFlyFrame& rA, const SwPosFlyFrame& rB) const; }; +typedef std::set< SwPosFlyFrame, SwPosFlyFrameCmp > SwPosFlyFrames; #endif // INCLUDED_SW_INC_FLYPOS_HXX diff --git a/sw/qa/extras/ww8export/ww8export.cxx b/sw/qa/extras/ww8export/ww8export.cxx index 998b67971e3f..802717ad1ed5 100644 --- a/sw/qa/extras/ww8export/ww8export.cxx +++ b/sw/qa/extras/ww8export/ww8export.cxx @@ -809,9 +809,9 @@ DECLARE_WW8EXPORT_TEST(testTdf122425_2, "tdf122425_2.doc") SwPosFlyFrames aPosFlyFrames = pDoc->GetAllFlyFormats(nullptr, false); // There is one fly frame in the document: the text box CPPUNIT_ASSERT_EQUAL(size_t(1), aPosFlyFrames.size()); - for (const auto& rPosFlyFrame : aPosFlyFrames) + for (const SwPosFlyFrame& rPosFlyFrame : aPosFlyFrames) { - const SwFrameFormat& rFormat = rPosFlyFrame->GetFormat(); + const SwFrameFormat& rFormat = rPosFlyFrame.GetFormat(); const SfxPoolItem* pItem = nullptr; // Check for correct explicitly-set values of UL spacings. Previously this was "DEFAULT", diff --git a/sw/qa/extras/ww8import/ww8import.cxx b/sw/qa/extras/ww8import/ww8import.cxx index ab35fa9d7346..c41b86d2f8e2 100644 --- a/sw/qa/extras/ww8import/ww8import.cxx +++ b/sw/qa/extras/ww8import/ww8import.cxx @@ -156,9 +156,9 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf121734) SwPosFlyFrames aPosFlyFrames = pDoc->GetAllFlyFormats(nullptr, false); // There is only one fly frame in the document: the one with the imported floating table CPPUNIT_ASSERT_EQUAL(size_t(1), aPosFlyFrames.size()); - for (const auto& rPosFlyFrame : aPosFlyFrames) + for (const SwPosFlyFrame& rPosFlyFrame : aPosFlyFrames) { - const SwFrameFormat& rFormat = rPosFlyFrame->GetFormat(); + const SwFrameFormat& rFormat = rPosFlyFrame.GetFormat(); const SfxPoolItem* pItem = nullptr; // The LR and UL spacings and borders must all be set explicitly; @@ -225,9 +225,9 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf122425_1) SwPosFlyFrames aPosFlyFrames = pDoc->GetAllFlyFormats(nullptr, false); // There are two fly frames in the document: for first page's header, and for other pages' CPPUNIT_ASSERT_EQUAL(size_t(2), aPosFlyFrames.size()); - for (const auto& rPosFlyFrame : aPosFlyFrames) + for (const SwPosFlyFrame& rPosFlyFrame : aPosFlyFrames) { - const SwFrameFormat& rFormat = rPosFlyFrame->GetFormat(); + const SwFrameFormat& rFormat = rPosFlyFrame.GetFormat(); const SfxPoolItem* pItem = nullptr; // The LR and UL spacings and borders must all be set explicitly; diff --git a/sw/source/core/doc/DocumentDrawModelManager.cxx b/sw/source/core/doc/DocumentDrawModelManager.cxx index 21bde0ebfe75..990bb8a4732b 100644 --- a/sw/source/core/doc/DocumentDrawModelManager.cxx +++ b/sw/source/core/doc/DocumentDrawModelManager.cxx @@ -298,10 +298,10 @@ bool DocumentDrawModelManager::Search(const SwPaM& rPaM, const SvxSearchItem& rS { SwPosFlyFrames aFrames = m_rDoc.GetAllFlyFormats(&rPaM, /*bDrawAlso=*/true); - for (const SwPosFlyFramePtr& pPosFlyFrame : aFrames) + for (const SwPosFlyFrame& rPosFlyFrame : aFrames) { // Filter for at-paragraph anchored draw frames. - const SwFrameFormat& rFrameFormat = pPosFlyFrame->GetFormat(); + const SwFrameFormat& rFrameFormat = rPosFlyFrame.GetFormat(); const SwFormatAnchor& rAnchor = rFrameFormat.GetAnchor(); if (rAnchor.GetAnchorId() != RndStdIds::FLY_AT_PARA || rFrameFormat.Which() != RES_DRAWFRMFMT) continue; diff --git a/sw/source/core/doc/doclay.cxx b/sw/source/core/doc/doclay.cxx index 14781dcd7e03..7065d20b214a 100644 --- a/sw/source/core/doc/doclay.cxx +++ b/sw/source/core/doc/doclay.cxx @@ -519,7 +519,7 @@ SwPosFlyFrames SwDoc::GetAllFlyFormats( const SwPaM* pCmpRange, bool bDrawAlso, if( pCmpRange && !lcl_TstFlyRange( pCmpRange, pAPos, rAnchor.GetAnchorId() )) continue; // not a valid FlyFrame - aRetval.insert(std::make_shared<SwPosFlyFrame>(pAPos->nNode, pFly, aRetval.size())); + aRetval.insert(SwPosFlyFrame(pAPos->GetNode(), pFly, aRetval.size())); } } } @@ -567,10 +567,10 @@ SwPosFlyFrames SwDoc::GetAllFlyFormats( const SwPaM* pCmpRange, bool bDrawAlso, } if ( pContentFrame ) { - SwNodeIndex aIdx( pContentFrame->IsTextFrame() - ? *static_cast<SwTextFrame const*>(pContentFrame)->GetTextNodeFirst() - : *static_cast<SwNoTextFrame const*>(pContentFrame)->GetNode() ); - aRetval.insert(std::make_shared<SwPosFlyFrame>(aIdx, pFly, aRetval.size())); + const SwNode* pNd( pContentFrame->IsTextFrame() + ? static_cast<SwTextFrame const*>(pContentFrame)->GetTextNodeFirst() + : static_cast<SwNoTextFrame const*>(pContentFrame)->GetNode() ); + aRetval.insert(SwPosFlyFrame(*pNd, pFly, aRetval.size())); } } } diff --git a/sw/source/core/layout/flypos.cxx b/sw/source/core/layout/flypos.cxx index 0a7ab2dcae4a..27e52e37aab2 100644 --- a/sw/source/core/layout/flypos.cxx +++ b/sw/source/core/layout/flypos.cxx @@ -24,26 +24,25 @@ #include <frameformats.hxx> #include <svx/swframetypes.hxx> -bool SwPosFlyFrameCmp::operator()(const SwPosFlyFramePtr& rA, const SwPosFlyFramePtr& rB) const +bool SwPosFlyFrameCmp::operator()(const SwPosFlyFrame& rA, const SwPosFlyFrame& rB) const { - if (rA->GetNdIndex() == rB->GetNdIndex()) + if (rA.GetNode() == rB.GetNode()) { // In this case, the order number decides! - return rA->GetOrdNum() < rB->GetOrdNum(); + return rA.GetOrdNum() < rB.GetOrdNum(); } - return rA->GetNdIndex() < rB->GetNdIndex(); + return rA.GetNode() < rB.GetNode(); } -SwPosFlyFrame::SwPosFlyFrame(const SwNodeIndex& rIdx, const SwFrameFormat* pFormat, - sal_uInt16 nArrPos) +SwPosFlyFrame::SwPosFlyFrame(const SwNode& rNd, const SwFrameFormat* pFormat, sal_uInt16 nArrPos) : m_pFrameFormat(pFormat) - , m_pNodeIndex(const_cast<SwNodeIndex*>(&rIdx)) + , m_pNode(&rNd) , m_nOrdNum(SAL_MAX_UINT32) { const SwFormatAnchor& rAnchor = pFormat->GetAnchor(); if (RndStdIds::FLY_AT_PAGE == rAnchor.GetAnchorId()) - m_pNodeIndex = new SwNodeIndex(rIdx); + ; else if (pFormat->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell()) pFormat->CallSwClientNotify(sw::GetZOrderHint(m_nOrdNum)); if (m_nOrdNum == SAL_MAX_UINT32) @@ -53,13 +52,4 @@ SwPosFlyFrame::SwPosFlyFrame(const SwNodeIndex& rIdx, const SwFrameFormat* pForm } } -SwPosFlyFrame::~SwPosFlyFrame() -{ - const SwFormatAnchor& rAnchor = m_pFrameFormat->GetAnchor(); - if (RndStdIds::FLY_AT_PAGE == rAnchor.GetAnchorId()) - { - delete m_pNodeIndex; - } -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/unocore/unoobj2.cxx b/sw/source/core/unocore/unoobj2.cxx index 2661081665d1..a20e89d1ca1c 100644 --- a/sw/source/core/unocore/unoobj2.cxx +++ b/sw/source/core/unocore/unoobj2.cxx @@ -1751,9 +1751,9 @@ SwXParaFrameEnumerationImpl::SwXParaFrameEnumerationImpl( if (PARAFRAME_PORTION_TEXTRANGE == eParaFrameMode) { //get all frames that are bound at paragraph or at character - for(const auto& pFlyFrame : rPaM.GetDoc().GetAllFlyFormats(&GetCursor(), false, true)) + for(const SwPosFlyFrame& rFlyFrame : rPaM.GetDoc().GetAllFlyFormats(&GetCursor(), false, true)) { - const auto pFrameFormat = const_cast<SwFrameFormat*>(&pFlyFrame->GetFormat()); + const auto pFrameFormat = const_cast<SwFrameFormat*>(&rFlyFrame.GetFormat()); m_vFrames.push_back(std::make_shared<sw::FrameClient>(pFrameFormat)); } } diff --git a/sw/source/filter/html/htmlfly.cxx b/sw/source/filter/html/htmlfly.cxx index 573fd865d0fa..2c50a4de78bc 100644 --- a/sw/source/filter/html/htmlfly.cxx +++ b/sw/source/filter/html/htmlfly.cxx @@ -35,7 +35,7 @@ SwHTMLPosFlyFrame::SwHTMLPosFlyFrame( const SwPosFlyFrame& rPosFly, AllHtmlFlags nFlags ) : m_pFrameFormat( &rPosFly.GetFormat() ), m_pSdrObject( pSdrObj ), - m_aNodeIndex( rPosFly.GetNdIndex() ), + m_aNodeIndex( rPosFly.GetNode() ), m_nOrdNum( rPosFly.GetOrdNum() ), m_nContentIndex( 0 ), m_nAllFlags( nFlags ) diff --git a/sw/source/filter/html/htmlflywriter.cxx b/sw/source/filter/html/htmlflywriter.cxx index 4efee1377701..425cce1d5095 100644 --- a/sw/source/filter/html/htmlflywriter.cxx +++ b/sw/source/filter/html/htmlflywriter.cxx @@ -296,9 +296,9 @@ void SwHTMLWriter::CollectFlyFrames() SwPosFlyFrames aFlyPos( m_pDoc->GetAllFlyFormats(m_bWriteAll ? nullptr : m_pCurrentPam.get(), true)); - for(const auto& rpItem : aFlyPos) + for(const SwPosFlyFrame& rItem : aFlyPos) { - const SwFrameFormat& rFrameFormat = rpItem->GetFormat(); + const SwFrameFormat& rFrameFormat = rItem.GetFormat(); const SdrObject *pSdrObj = nullptr; const SwPosition *pAPos; const SwContentNode *pACNd; @@ -348,7 +348,7 @@ void SwHTMLWriter::CollectFlyFrames() if( !m_pHTMLPosFlyFrames ) m_pHTMLPosFlyFrames.reset(new SwHTMLPosFlyFrames); - m_pHTMLPosFlyFrames->insert( std::make_unique<SwHTMLPosFlyFrame>(*rpItem, pSdrObj, nMode) ); + m_pHTMLPosFlyFrames->insert( std::make_unique<SwHTMLPosFlyFrame>(rItem, pSdrObj, nMode) ); } } diff --git a/sw/source/filter/ww8/writerhelper.cxx b/sw/source/filter/ww8/writerhelper.cxx index 80a75c4bd2c0..fd2241ef236c 100644 --- a/sw/source/filter/ww8/writerhelper.cxx +++ b/sw/source/filter/ww8/writerhelper.cxx @@ -110,9 +110,9 @@ namespace { ww8::Frames aRet; - for(const auto& rpFly : rFlys) + for(const auto& rFly : rFlys) { - const SwFrameFormat &rEntry = rpFly->GetFormat(); + const SwFrameFormat &rEntry = rFly.GetFormat(); if (const SwPosition* pAnchor = rEntry.GetAnchor().GetContentAnchor()) { @@ -123,7 +123,7 @@ namespace } else { - SwPosition aPos(rpFly->GetNdIndex()); + SwPosition aPos(rFly.GetNode()); aRet.emplace_back(rEntry, aPos); } }
