diff --git a/sw/source/core/crsr/findattr.cxx b/sw/source/core/crsr/findattr.cxx index 7b7c475189e5..626a590a07b2 100644 --- a/sw/source/core/crsr/findattr.cxx +++ b/sw/source/core/crsr/findattr.cxx @@ -918,7 +918,8 @@ bool FindAttrImpl(SwPaM & rSearchPam, bool bCharAttr = isCHRATR(nWhich) || isTXTATR(nWhich); assert(isTXTATR(nWhich)); // sw_redlinehide: only works for non-formatting hints such as needed in UpdateFields; use FindAttrsImpl for others - std::unique_ptr pPam(sw::MakeRegion(fnMove, rRegion)); + std::optional oPam; + sw::MakeRegion(fnMove, rRegion, oPam); bool bFound = false; bool bFirst = true; @@ -927,18 +928,18 @@ bool FindAttrImpl(SwPaM & rSearchPam, // if at beginning/end then move it out of the node if( bSrchForward - ? pPam->GetPoint()->GetContentIndex() == pPam->GetContentNode()->Len() - : !pPam->GetPoint()->GetContentIndex() ) + ? oPam->GetPoint()->GetContentIndex() == oPam->GetContentNode()->Len() + : !oPam->GetPoint()->GetContentIndex() ) { - if( !(*fnMove.fnNds)( &pPam->GetPoint()->nNode, false )) + if( !(*fnMove.fnNds)( &oPam->GetPoint()->nNode, false )) { return false; } - SwContentNode *pNd = pPam->GetContentNode(); - pPam->GetPoint()->nContent.Assign( pNd, bSrchForward ? 0 : pNd->Len() ); + SwContentNode *pNd = oPam->GetContentNode(); + oPam->GetPoint()->nContent.Assign( pNd, bSrchForward ? 0 : pNd->Len() ); } - while (nullptr != (pNode = ::GetNode(*pPam, bFirst, fnMove, bInReadOnly, pLayout))) + while (nullptr != (pNode = ::GetNode(*oPam, bFirst, fnMove, bInReadOnly, pLayout))) { if( bCharAttr ) { @@ -960,9 +961,9 @@ bool FindAttrImpl(SwPaM & rSearchPam, pAttr = iter.NextAttr(&pAttrNode); } while (pAttr - && (pAttrNode->GetIndex() < pPam->GetPoint()->GetNodeIndex() - || (pAttrNode->GetIndex() == pPam->GetPoint()->GetNodeIndex() - && pAttr->GetStart() < pPam->GetPoint()->GetContentIndex()) + && (pAttrNode->GetIndex() < oPam->GetPoint()->GetNodeIndex() + || (pAttrNode->GetIndex() == oPam->GetPoint()->GetNodeIndex() + && pAttr->GetStart() < oPam->GetPoint()->GetContentIndex()) || pAttr->Which() != nWhich)); } else @@ -973,22 +974,22 @@ bool FindAttrImpl(SwPaM & rSearchPam, pAttr = iter.PrevAttr(&pAttrNode); } while (pAttr - && (pPam->GetPoint()->GetNodeIndex() < pAttrNode->GetIndex() - || (pPam->GetPoint()->GetNodeIndex() == pAttrNode->GetIndex() - && pPam->GetPoint()->GetContentIndex() <= pAttr->GetStart()) + && (oPam->GetPoint()->GetNodeIndex() < pAttrNode->GetIndex() + || (oPam->GetPoint()->GetNodeIndex() == pAttrNode->GetIndex() + && oPam->GetPoint()->GetContentIndex() <= pAttr->GetStart()) || pAttr->Which() != nWhich)); } if (pAttr) { assert(pAttrNode); - pPam->GetPoint()->nNode = *pAttrNode; - lcl_SetAttrPam(*pPam, pAttr->GetStart(), pAttr->End(), bSrchForward); + oPam->GetPoint()->nNode = *pAttrNode; + lcl_SetAttrPam(*oPam, pAttr->GetStart(), pAttr->End(), bSrchForward); bFound = true; break; } } else if (!pLayout && pNode->GetTextNode()->HasHints() && - lcl_SearchAttr(*pNode->GetTextNode(), *pPam, rAttr, fnMove)) + lcl_SearchAttr(*pNode->GetTextNode(), *oPam, rAttr, fnMove)) { bFound = true; } @@ -996,8 +997,8 @@ bool FindAttrImpl(SwPaM & rSearchPam, { // set to the values of the attribute rSearchPam.SetMark(); - *rSearchPam.GetPoint() = *pPam->GetPoint(); - *rSearchPam.GetMark() = *pPam->GetMark(); + *rSearchPam.GetPoint() = *oPam->GetPoint(); + *rSearchPam.GetMark() = *oPam->GetMark(); break; } else if (isTXTATR(nWhich)) @@ -1044,7 +1045,8 @@ static bool FindAttrsImpl(SwPaM & rSearchPam, const SwPaM & rRegion, bool bInReadOnly, bool bMoveFirst, SwRootFrame const*const pLayout) { - std::unique_ptr pPam(sw::MakeRegion(fnMove, rRegion)); + std::optional oPam; + sw::MakeRegion(fnMove, rRegion, oPam); bool bFound = false; bool bFirst = true; @@ -1064,18 +1066,18 @@ static bool FindAttrsImpl(SwPaM & rSearchPam, // if at beginning/end then move it out of the node if( bMoveFirst && ( bSrchForward - ? pPam->GetPoint()->GetContentIndex() == pPam->GetContentNode()->Len() - : !pPam->GetPoint()->GetContentIndex() ) ) + ? oPam->GetPoint()->GetContentIndex() == oPam->GetContentNode()->Len() + : !oPam->GetPoint()->GetContentIndex() ) ) { - if( !(*fnMove.fnNds)( &pPam->GetPoint()->nNode, false )) + if( !(*fnMove.fnNds)( &oPam->GetPoint()->nNode, false )) { return false; } - SwContentNode *pNd = pPam->GetContentNode(); - pPam->GetPoint()->nContent.Assign( pNd, bSrchForward ? 0 : pNd->Len() ); + SwContentNode *pNd = oPam->GetContentNode(); + oPam->GetPoint()->nContent.Assign( pNd, bSrchForward ? 0 : pNd->Len() ); } - while (nullptr != (pNode = ::GetNode(*pPam, bFirst, fnMove, bInReadOnly, pLayout))) + while (nullptr != (pNode = ::GetNode(*oPam, bFirst, fnMove, bInReadOnly, pLayout))) { SwTextFrame const*const pFrame(pLayout && pNode->IsTextNode() ? static_cast(pNode->getLayoutFrame(pLayout)) @@ -1100,8 +1102,8 @@ static bool FindAttrsImpl(SwPaM & rSearchPam, sw::MergedPara const*const pMergedPara(pFrame ? pFrame->GetMergedPara() : nullptr); if (pMergedPara) { - SwPosition const& rStart(*pPam->Start()); - SwPosition const& rEnd(*pPam->End()); + SwPosition const& rStart(*oPam->Start()); + SwPosition const& rEnd(*oPam->End()); // no extents? fall back to searching index 0 of propsnode // to find its node items if (pMergedPara->extents.empty()) @@ -1113,7 +1115,7 @@ static bool FindAttrsImpl(SwPaM & rSearchPam, bFound = (*fnSearch)(*pNode->GetTextNode(), aCmpArr, tmp); if (bFound) { - *pPam = tmp; + *oPam = tmp; } } } @@ -1153,7 +1155,7 @@ static bool FindAttrsImpl(SwPaM & rSearchPam, bFound = (*fnSearch)(*rExtent.pNode, aCmpArr, tmp); if (bFound) { - *pPam = tmp; + *oPam = tmp; break; } } @@ -1161,14 +1163,14 @@ static bool FindAttrsImpl(SwPaM & rSearchPam, } else { - bFound = (*fnSearch)(*pNode->GetTextNode(), aCmpArr, *pPam); + bFound = (*fnSearch)(*pNode->GetTextNode(), aCmpArr, *oPam); } if (bFound) { // set to the values of the attribute rSearchPam.SetMark(); - *rSearchPam.GetPoint() = *pPam->GetPoint(); - *rSearchPam.GetMark() = *pPam->GetMark(); + *rSearchPam.GetPoint() = *oPam->GetPoint(); + *rSearchPam.GetMark() = *oPam->GetMark(); break; } continue; // text attribute @@ -1192,14 +1194,14 @@ static bool FindAttrsImpl(SwPaM & rSearchPam, // BACKWARD: SPoint at the beginning, GetMark at the end of the node if (pFrame) { - *rSearchPam.GetPoint() = *pPam->GetPoint(); + *rSearchPam.GetPoint() = *oPam->GetPoint(); rSearchPam.SetMark(); *rSearchPam.GetMark() = pFrame->MapViewToModelPos( TextFrameIndex(bSrchForward ? pFrame->GetText().getLength() : 0)); } else { - *rSearchPam.GetPoint() = *pPam->GetPoint(); + *rSearchPam.GetPoint() = *oPam->GetPoint(); rSearchPam.SetMark(); if (bSrchForward) { diff --git a/sw/source/core/crsr/findfmt.cxx b/sw/source/core/crsr/findfmt.cxx index 725c4934153d..555d28bd543e 100644 --- a/sw/source/core/crsr/findfmt.cxx +++ b/sw/source/core/crsr/findfmt.cxx @@ -32,24 +32,25 @@ bool FindFormatImpl(SwPaM & rSearchPam, { bool bFound = false; const bool bSrchForward = &fnMove == &fnMoveForward; - std::unique_ptr pPam(MakeRegion( fnMove, rRegion )); + std::optional oPam; + MakeRegion( fnMove, rRegion, oPam ); // if at beginning/end then move it out of the node if( bSrchForward - ? pPam->GetPoint()->GetContentIndex() == pPam->GetContentNode()->Len() - : !pPam->GetPoint()->GetContentIndex() ) + ? oPam->GetPoint()->GetContentIndex() == oPam->GetContentNode()->Len() + : !oPam->GetPoint()->GetContentIndex() ) { - if( !(*fnMove.fnNds)( &pPam->GetPoint()->nNode, false )) + if( !(*fnMove.fnNds)( &oPam->GetPoint()->nNode, false )) { return false; } - SwContentNode *pNd = pPam->GetPoint()->GetNode().GetContentNode(); - pPam->GetPoint()->nContent.Assign( pNd, bSrchForward ? 0 : pNd->Len() ); + SwContentNode *pNd = oPam->GetPoint()->GetNode().GetContentNode(); + oPam->GetPoint()->nContent.Assign( pNd, bSrchForward ? 0 : pNd->Len() ); } bool bFirst = true; SwContentNode* pNode; - while (nullptr != (pNode = ::GetNode(*pPam, bFirst, fnMove, bInReadOnly, pLayout))) + while (nullptr != (pNode = ::GetNode(*oPam, bFirst, fnMove, bInReadOnly, pLayout))) { SwTextFrame const*const pFrame(pLayout && pNode->IsTextNode() ? static_cast(pNode->getLayoutFrame(pLayout)) @@ -68,14 +69,14 @@ bool FindFormatImpl(SwPaM & rSearchPam, // always: incl. start and incl. end if (pFrame) { - *rSearchPam.GetPoint() = *pPam->GetPoint(); + *rSearchPam.GetPoint() = *oPam->GetPoint(); rSearchPam.SetMark(); *rSearchPam.GetMark() = pFrame->MapViewToModelPos( TextFrameIndex(bSrchForward ? pFrame->GetText().getLength() : 0)); } else { - *rSearchPam.GetPoint() = *pPam->GetPoint(); + *rSearchPam.GetPoint() = *oPam->GetPoint(); rSearchPam.SetMark(); pNode->MakeEndIndex( &rSearchPam.GetPoint()->nContent ); rSearchPam.GetMark()->nContent = 0; diff --git a/sw/source/core/crsr/findtxt.cxx b/sw/source/core/crsr/findtxt.cxx index 0ae04af5017b..be23fe43a18c 100644 --- a/sw/source/core/crsr/findtxt.cxx +++ b/sw/source/core/crsr/findtxt.cxx @@ -376,10 +376,11 @@ bool FindTextImpl(SwPaM & rSearchPam, if( rSearchOpt.searchString.isEmpty() ) return false; - std::unique_ptr pPam = sw::MakeRegion(fnMove, rRegion); + std::optional oPam; + sw::MakeRegion(fnMove, rRegion, oPam); const bool bSrchForward = &fnMove == &fnMoveForward; - SwNodeIndex& rNdIdx = pPam->GetPoint()->nNode; - SwContentIndex& rContentIdx = pPam->GetPoint()->nContent; + SwNodeIndex& rNdIdx = oPam->GetPoint()->nNode; + SwContentIndex& rContentIdx = oPam->GetPoint()->nContent; // If bFound is true then the string was found and is between nStart and nEnd bool bFound = false; @@ -401,7 +402,7 @@ bool FindTextImpl(SwPaM & rSearchPam, } // LanguageType eLastLang = 0; - while (nullptr != (pNode = ::GetNode(*pPam, bFirst, fnMove, bInReadOnly, pLayout))) + while (nullptr != (pNode = ::GetNode(*oPam, bFirst, fnMove, bInReadOnly, pLayout))) { if( pNode->IsTextNode() ) { @@ -421,16 +422,16 @@ bool FindTextImpl(SwPaM & rSearchPam, } AmbiguousIndex nEnd; if (pLayout - ? FrameContainsNode(*pFrame, pPam->GetMark()->GetNodeIndex()) - : rNdIdx == pPam->GetMark()->nNode) + ? FrameContainsNode(*pFrame, oPam->GetMark()->GetNodeIndex()) + : rNdIdx == oPam->GetMark()->nNode) { if (pLayout) { - nEnd.SetFrameIndex(pFrame->MapModelToViewPos(*pPam->GetMark())); + nEnd.SetFrameIndex(pFrame->MapModelToViewPos(*oPam->GetMark())); } else { - nEnd.SetModelIndex(pPam->GetMark()->GetContentIndex()); + nEnd.SetModelIndex(oPam->GetMark()->GetContentIndex()); } } else @@ -454,7 +455,7 @@ bool FindTextImpl(SwPaM & rSearchPam, AmbiguousIndex nStart; if (pLayout) { - nStart.SetFrameIndex(pFrame->MapModelToViewPos(*pPam->GetPoint())); + nStart.SetFrameIndex(pFrame->MapModelToViewPos(*oPam->GetPoint())); } else { @@ -679,7 +680,7 @@ bool FindTextImpl(SwPaM & rSearchPam, bRegSearch, bChkEmptyPara, bChkParaEnd, nStartInside, nEndInside, nTextLen, pNode->GetTextNode(), pFrame, pLayout, - pPam.get() ); + oPam ? &*oPam : nullptr ); if ( bFound ) break; else @@ -712,7 +713,7 @@ bool FindTextImpl(SwPaM & rSearchPam, bRegSearch, bChkEmptyPara, bChkParaEnd, nStart, nEnd, nTextLen, pNode->GetTextNode(), pFrame, pLayout, - pPam.get() ); + oPam ? &*oPam : nullptr ); } if (bFound) break; diff --git a/sw/source/core/crsr/pam.cxx b/sw/source/core/crsr/pam.cxx index b4db9c4275cd..b84973ec7c74 100644 --- a/sw/source/core/crsr/pam.cxx +++ b/sw/source/core/crsr/pam.cxx @@ -629,22 +629,17 @@ namespace sw { @param fnMove Contains information if beginning or end of document. @param pOrigRg The given region. - - @return Newly created range, in Ring with parameter pOrigRg. + @param rPam returns newly created range, in Ring with parameter pOrigRg. */ -std::unique_ptr MakeRegion(SwMoveFnCollection const & fnMove, - const SwPaM & rOrigRg) +void MakeRegion(SwMoveFnCollection const & fnMove, + const SwPaM & rOrigRg, std::optional& rPam) { - std::unique_ptr pPam; - { - pPam.reset(new SwPaM(rOrigRg, const_cast(&rOrigRg))); // given search range - // make sure that SPoint is on the "real" start position - // FORWARD: SPoint always smaller than GetMark - // BACKWARD: SPoint always bigger than GetMark - if( (pPam->GetMark()->*fnMove.fnCmpOp)( *pPam->GetPoint() ) ) - pPam->Exchange(); - } - return pPam; + rPam.emplace(rOrigRg, const_cast(&rOrigRg)); // given search range + // make sure that SPoint is on the "real" start position + // FORWARD: SPoint always smaller than GetMark + // BACKWARD: SPoint always bigger than GetMark + if( (rPam->GetMark()->*fnMove.fnCmpOp)( *rPam->GetPoint() ) ) + rPam->Exchange(); } } // namespace sw diff --git a/sw/source/core/inc/pamtyp.hxx b/sw/source/core/inc/pamtyp.hxx index 837f553f1cfb..fa9d34af3dda 100644 --- a/sw/source/core/inc/pamtyp.hxx +++ b/sw/source/core/inc/pamtyp.hxx @@ -23,6 +23,7 @@ #include #include +#include class SwpHints; struct SwPosition; @@ -87,8 +88,8 @@ SwContentNode* GetNode(SwPaM&, bool&, SwMoveFnCollection const &, namespace sw { - std::unique_ptr MakeRegion(SwMoveFnCollection const & fnMove, - const SwPaM & rOrigRg); + void MakeRegion(SwMoveFnCollection const & fnMove, + const SwPaM & rOrigRg, std::optional& rDestinaton); /// Search. bool FindTextImpl(SwPaM & rSearchPam,