diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-11-28 13:34:25 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-11-28 21:01:05 +0100 |
commit | acc08fb5d3427f882d55e43167e9cca0eb344c24 (patch) | |
tree | 66271cea2555f251f8f90b5441c8ebeea5b9a538 /sw | |
parent | 24cc33655c7d54741c8b8d80244a285471558f0f (diff) |
Add some more utility methods to SwFormatAnchor
Change-Id: I3ad607428470b95d32891cc18e8e82f0cf113626
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143380
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/fmtanchr.hxx | 2 | ||||
-rw-r--r-- | sw/source/core/layout/atrfrm.cxx | 17 | ||||
-rw-r--r-- | sw/source/core/unocore/unodraw.cxx | 28 | ||||
-rw-r--r-- | sw/source/core/unocore/unoframe.cxx | 27 | ||||
-rw-r--r-- | sw/source/core/unocore/unoobj2.cxx | 11 | ||||
-rw-r--r-- | sw/source/core/unocore/unoportenum.cxx | 5 | ||||
-rw-r--r-- | sw/source/filter/html/htmlfly.cxx | 2 | ||||
-rw-r--r-- | sw/source/uibase/docvw/edtwin.cxx | 4 | ||||
-rw-r--r-- | sw/source/uibase/wrtsh/wrtsh1.cxx | 4 |
9 files changed, 57 insertions, 43 deletions
diff --git a/sw/inc/fmtanchr.hxx b/sw/inc/fmtanchr.hxx index 8a4001319b25..fb6702378b66 100644 --- a/sw/inc/fmtanchr.hxx +++ b/sw/inc/fmtanchr.hxx @@ -72,6 +72,8 @@ public: SwNode* GetAnchorNode() const; const SwPosition* GetContentAnchor() const { return m_oContentAnchor ? &*m_oContentAnchor : nullptr; } + SwContentNode* GetAnchorContentNode() const; + sal_Int32 GetAnchorContentOffset() const; void SetAnchor( const SwPosition *pPos ); // #i28701# diff --git a/sw/source/core/layout/atrfrm.cxx b/sw/source/core/layout/atrfrm.cxx index 9e4105d21753..b3075dc54d58 100644 --- a/sw/source/core/layout/atrfrm.cxx +++ b/sw/source/core/layout/atrfrm.cxx @@ -1612,6 +1612,23 @@ SwNode* SwFormatAnchor::GetAnchorNode() const return &m_oContentAnchor->nNode.GetNode(); } +SwContentNode* SwFormatAnchor::GetAnchorContentNode() const +{ + SwNode* pAnchorNode = GetAnchorNode(); + if (pAnchorNode) + return pAnchorNode->GetContentNode(); + return nullptr; +} + +sal_Int32 SwFormatAnchor::GetAnchorContentOffset() const +{ + if (!m_oContentAnchor) + return 0; + if (m_oContentAnchor->nContent.GetContentNode()) + return m_oContentAnchor->nContent.GetIndex(); + return 0; +} + SwFormatAnchor& SwFormatAnchor::operator=(const SwFormatAnchor& rAnchor) { if (this != &rAnchor) diff --git a/sw/source/core/unocore/unodraw.cxx b/sw/source/core/unocore/unodraw.cxx index e816380ad253..9a2ff848de69 100644 --- a/sw/source/core/unocore/unodraw.cxx +++ b/sw/source/core/unocore/unodraw.cxx @@ -1064,10 +1064,9 @@ void SwXShape::setPropertyValue(const OUString& rPropertyName, const uno::Any& a //With AnchorAsCharacter the current TextAttribute has to be deleted. //Tbis removes the frame format too. //To prevent this the connection between format and attribute has to be broken before. - const SwPosition *pPos = aAnchor.GetContentAnchor(); - SwTextNode *pTextNode = pPos->GetNode().GetTextNode(); + SwTextNode *pTextNode = aAnchor.GetAnchorNode()->GetTextNode(); SAL_WARN_IF( !pTextNode->HasHints(), "sw.uno", "Missing FlyInCnt-Hint." ); - const sal_Int32 nIdx = pPos->GetContentIndex(); + const sal_Int32 nIdx = aAnchor.GetAnchorContentOffset(); SwTextAttr * const pHint = pTextNode->GetTextAttrForCharAt( nIdx, RES_TXTATR_FLYCNT ); @@ -1218,10 +1217,9 @@ void SwXShape::setPropertyValue(const OUString& rPropertyName, const uno::Any& a //With AnchorAsCharacter the current TextAttribute has to be deleted. //Tbis removes the frame format too. //To prevent this the connection between format and attribute has to be broken before. - const SwPosition *pPos = rOldAnchor.GetContentAnchor(); - SwTextNode *pTextNode = pPos->GetNode().GetTextNode(); + SwTextNode *pTextNode = rOldAnchor.GetAnchorNode()->GetTextNode(); SAL_WARN_IF( !pTextNode->HasHints(), "sw.uno", "Missing FlyInCnt-Hint." ); - const sal_Int32 nIdx = pPos->GetContentIndex(); + const sal_Int32 nIdx = rOldAnchor.GetAnchorContentOffset(); SwTextAttr * const pHint = pTextNode->GetTextAttrForCharAt( nIdx, RES_TXTATR_FLYCNT ); @@ -1459,7 +1457,7 @@ uno::Any SwXShape::getPropertyValue(const OUString& rPropertyName) } else { - if ( aAnchor.GetContentAnchor() ) + if ( aAnchor.GetAnchorNode() ) { const rtl::Reference<SwXTextRange> xTextRange = SwXTextRange::CreateXTextRange( @@ -2051,16 +2049,16 @@ uno::Reference< text::XTextRange > SwXShape::getAnchor() // return an anchor for non-page bound frames // and for page bound frames that have a page no == NULL and a content position if ((rAnchor.GetAnchorId() != RndStdIds::FLY_AT_PAGE) || - (rAnchor.GetContentAnchor() && !rAnchor.GetPageNum())) + (rAnchor.GetAnchorNode() && !rAnchor.GetPageNum())) { - const SwPosition &rPos = *(pFormat->GetAnchor().GetContentAnchor()); if (rAnchor.GetAnchorId() == RndStdIds::FLY_AT_PARA) { // ensure that SwXTextRange has SwContentIndex - aRef = SwXTextRange::CreateXTextRange(*pFormat->GetDoc(), SwPosition(rPos.GetNode()), nullptr); + const SwNode* pAnchorNode = rAnchor.GetAnchorNode(); + aRef = SwXTextRange::CreateXTextRange(*pFormat->GetDoc(), SwPosition(*pAnchorNode), nullptr); } else { - aRef = SwXTextRange::CreateXTextRange(*pFormat->GetDoc(), rPos, nullptr); + aRef = SwXTextRange::CreateXTextRange(*pFormat->GetDoc(), *rAnchor.GetContentAnchor(), nullptr); } } } @@ -2096,11 +2094,11 @@ void SwXShape::dispose() !pObj->getParentSdrObjectFromSdrObject() && pObj->IsInserted() ) { - if (pFormat->GetAnchor().GetAnchorId() == RndStdIds::FLY_AS_CHAR) + const SwFormatAnchor& rFormatAnchor = pFormat->GetAnchor(); + if (rFormatAnchor.GetAnchorId() == RndStdIds::FLY_AS_CHAR) { - const SwPosition &rPos = *(pFormat->GetAnchor().GetContentAnchor()); - SwTextNode *pTextNode = rPos.GetNode().GetTextNode(); - const sal_Int32 nIdx = rPos.GetContentIndex(); + SwTextNode *pTextNode = rFormatAnchor.GetAnchorNode()->GetTextNode(); + const sal_Int32 nIdx = rFormatAnchor.GetAnchorContentOffset(); pTextNode->DeleteAttributes( RES_TXTATR_FLYCNT, nIdx ); } else diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx index e7e03326c0a3..95b8956ea0a9 100644 --- a/sw/source/core/unocore/unoframe.cxx +++ b/sw/source/core/unocore/unoframe.cxx @@ -1869,8 +1869,8 @@ void SwXFrame::setPropertyValue(const OUString& rPropertyName, const ::uno::Any& SwFormatAnchor aAnchor = static_cast<const SwFormatAnchor&>(aSet.Get(pEntry->nWID)); if(aAnchor.GetAnchorId() == RndStdIds::FLY_AT_FLY) { - const ::SwPosition* pPosition = aAnchor.GetContentAnchor(); - SwFrameFormat* pFlyFormat = pPosition ? pPosition->GetNode().GetFlyFormat() : nullptr; + const ::SwNode* pAnchorNode = aAnchor.GetAnchorNode(); + SwFrameFormat* pFlyFormat = pAnchorNode ? pAnchorNode->GetFlyFormat() : nullptr; if(!pFlyFormat || pFlyFormat->Which() == RES_DRAWFRMFMT) { lang::IllegalArgumentException aExcept; @@ -1879,14 +1879,14 @@ void SwXFrame::setPropertyValue(const OUString& rPropertyName, const ::uno::Any& } else { - SwPosition aPos = *pPosition; + SwPosition aPos = *aAnchor.GetContentAnchor(); aPos.Assign( *pFlyFormat->GetContent().GetContentIdx() ); aAnchor.SetAnchor(&aPos); aSet.Put(aAnchor); } } else if ((aAnchor.GetAnchorId() != RndStdIds::FLY_AT_PAGE) && - !aAnchor.GetContentAnchor()) + !aAnchor.GetAnchorNode()) { SwNode& rNode = pDoc->GetNodes().GetEndOfContent(); SwPaM aPam(rNode); @@ -2281,10 +2281,10 @@ uno::Any SwXFrame::getPropertyValue(const OUString& rPropertyName) { if (!m_xParentText.is()) { - const SwPosition* pContentAnchor = pFormat->GetAnchor().GetContentAnchor(); - if (pContentAnchor) + const SwFormatAnchor& rFormatAnchor = pFormat->GetAnchor(); + if (rFormatAnchor.GetAnchorNode()) { - m_xParentText = sw::CreateParentXText(*pFormat->GetDoc(), *pContentAnchor); + m_xParentText = sw::CreateParentXText(*pFormat->GetDoc(), *rFormatAnchor.GetContentAnchor()); } } aAny <<= m_xParentText; @@ -2674,11 +2674,11 @@ void SwXFrame::dispose() ( pObj->GetUserCall() && !static_cast<SwContact*>(pObj->GetUserCall())->IsInDTOR() ) ) ) { - if (pFormat->GetAnchor().GetAnchorId() == RndStdIds::FLY_AS_CHAR) + const SwFormatAnchor& rFormatAnchor = pFormat->GetAnchor(); + if (rFormatAnchor.GetAnchorId() == RndStdIds::FLY_AS_CHAR) { - const SwPosition &rPos = *(pFormat->GetAnchor().GetContentAnchor()); - SwTextNode *pTextNode = rPos.GetNode().GetTextNode(); - const sal_Int32 nIdx = rPos.GetContentIndex(); + SwTextNode *pTextNode = rFormatAnchor.GetAnchorNode()->GetTextNode(); + const sal_Int32 nIdx = rFormatAnchor.GetAnchorContentOffset(); pTextNode->DeleteAttributes( RES_TXTATR_FLYCNT, nIdx, nIdx ); } else @@ -2701,14 +2701,13 @@ uno::Reference< text::XTextRange > SwXFrame::getAnchor() if ((rAnchor.GetAnchorId() != RndStdIds::FLY_AT_PAGE) || (rAnchor.GetAnchorNode() && !rAnchor.GetPageNum())) { - const SwPosition &rPos = *(rAnchor.GetContentAnchor()); if (rAnchor.GetAnchorId() == RndStdIds::FLY_AT_PARA) { // ensure that SwXTextRange has SwContentIndex - aRef = SwXTextRange::CreateXTextRange(*pFormat->GetDoc(), SwPosition(rPos.GetNode()), nullptr); + aRef = SwXTextRange::CreateXTextRange(*pFormat->GetDoc(), SwPosition(*rAnchor.GetAnchorNode()), nullptr); } else { - aRef = SwXTextRange::CreateXTextRange(*pFormat->GetDoc(), rPos, nullptr); + aRef = SwXTextRange::CreateXTextRange(*pFormat->GetDoc(), *rAnchor.GetContentAnchor(), nullptr); } } diff --git a/sw/source/core/unocore/unoobj2.cxx b/sw/source/core/unocore/unoobj2.cxx index c8af3285f9de..90abc362431d 100644 --- a/sw/source/core/unocore/unoobj2.cxx +++ b/sw/source/core/unocore/unoobj2.cxx @@ -124,8 +124,7 @@ struct FrameClientSortListLess continue; if(rFormat.GetAnchor().GetAnchorId() == nAnchorType) { - const auto nIdx = - rFormat.GetAnchor().GetContentAnchor()->GetContentIndex(); + const sal_Int32 nIdx = rFormat.GetAnchor().GetAnchorContentOffset(); const auto nOrder = rFormat.GetAnchor().GetOrder(); rFrames.emplace_back(nIdx, nOrder, std::make_unique<sw::FrameClient>(&rFormat)); } @@ -162,15 +161,15 @@ void CollectFrameAtNode( const SwNode& rNd, { const SwFrameFormat* pFormat = rFormats[ i ]; const SwFormatAnchor& rAnchor = pFormat->GetAnchor(); - const SwPosition* pAnchorPos; + const SwNode* pAnchorNode; if( rAnchor.GetAnchorId() == nChkType && - nullptr != (pAnchorPos = rAnchor.GetContentAnchor()) && - pAnchorPos->GetNode() == rNd ) + nullptr != (pAnchorNode = rAnchor.GetAnchorNode()) && + *pAnchorNode == rNd ) { // OD 2004-05-07 #i28701# - determine insert position for // sorted <rFrameArr> - const sal_Int32 nIndex = pAnchorPos->GetContentIndex(); + const sal_Int32 nIndex = rAnchor.GetAnchorContentOffset(); sal_uInt32 nOrder = rAnchor.GetOrder(); rFrames.emplace_back(nIndex, nOrder, std::make_unique<sw::FrameClient>(const_cast<SwFrameFormat*>(pFormat))); diff --git a/sw/source/core/unocore/unoportenum.cxx b/sw/source/core/unocore/unoportenum.cxx index 0e1e95053a3f..edf00a50f170 100644 --- a/sw/source/core/unocore/unoportenum.cxx +++ b/sw/source/core/unocore/unoportenum.cxx @@ -1270,11 +1270,10 @@ static void lcl_ExtractFramePositions(FrameClientSortList_t& rFrames, sal_Int32 auto& rFormat = *const_cast<SwFrameFormat*>(pFrame); const SwFormatAnchor& rAnchor = rFormat.GetAnchor(); - const SwPosition* pPosition = rAnchor.GetContentAnchor(); - if (!pPosition) + if (!rAnchor.GetAnchorNode()) continue; - rFramePositions.insert(pPosition->GetContentIndex()); + rFramePositions.insert(rAnchor.GetAnchorContentOffset()); } } diff --git a/sw/source/filter/html/htmlfly.cxx b/sw/source/filter/html/htmlfly.cxx index f76f1d536888..c4fe7dfa1006 100644 --- a/sw/source/filter/html/htmlfly.cxx +++ b/sw/source/filter/html/htmlfly.cxx @@ -51,7 +51,7 @@ SwHTMLPosFlyFrame::SwHTMLPosFlyFrame( const SwPosFlyFrame& rPosFly, if( !rAnchor.GetAnchorNode() ) return; - m_nContentIndex = rAnchor.GetContentAnchor()->GetContentIndex(); + m_nContentIndex = rAnchor.GetAnchorContentOffset(); sal_Int16 eHoriRel = rPosFly.GetFormat().GetHoriOrient(). GetRelationOrient(); if( text::RelOrientation::FRAME == eHoriRel || text::RelOrientation::PRINT_AREA == eHoriRel ) diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx index 0ffec86f5ed0..298f4da5fa45 100644 --- a/sw/source/uibase/docvw/edtwin.cxx +++ b/sw/source/uibase/docvw/edtwin.cxx @@ -1559,7 +1559,7 @@ void SwEditWin::KeyInput(const KeyEvent &rKEvt) SwTextNode* pTextNode = pAnchorNode->GetTextNode(); if (pTextNode) { - sal_Int32 nContentIdx = rFormatAnchor.GetContentAnchor()->GetContentIndex(); + sal_Int32 nContentIdx = rFormatAnchor.GetAnchorContentOffset(); SwTextAttr* pAttr = pTextNode->GetTextAttrAt( nContentIdx, RES_TXTATR_CONTENTCONTROL, ::sw::GetTextAttrMode::Parent); if (pAttr) @@ -4821,7 +4821,7 @@ void SwEditWin::MouseButtonUp(const MouseEvent& rMEvt) if (pTextNode) { SwTextAttr* pAttr = pTextNode->GetTextAttrAt( - rFormatAnchor.GetContentAnchor()->GetContentIndex(), RES_TXTATR_CONTENTCONTROL, + rFormatAnchor.GetAnchorContentOffset(), RES_TXTATR_CONTENTCONTROL, ::sw::GetTextAttrMode::Parent); if (pAttr) { diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx index b2b8ce6d10a9..adf96052e8fa 100644 --- a/sw/source/uibase/wrtsh/wrtsh1.cxx +++ b/sw/source/uibase/wrtsh/wrtsh1.cxx @@ -1115,8 +1115,8 @@ void SwWrtShell::InsertContentControl(SwContentControlType eType) { SwCursor* pCursor = getShellCursor(true); pCursor->DeleteMark(); - const SwPosition* pAnchor = pFrameFormat->GetAnchor().GetContentAnchor(); - pCursor->GetPoint()->Assign( *pAnchor->GetContentNode(), pAnchor->GetContentIndex() + 1); + const SwFormatAnchor& rFormatAnchor = pFrameFormat->GetAnchor(); + pCursor->GetPoint()->Assign( *rFormatAnchor.GetAnchorContentNode(), rFormatAnchor.GetAnchorContentOffset() + 1); } // Select before the anchor position. |