diff options
author | Michael Stahl <mstahl@redhat.com> | 2014-09-11 10:27:23 +0200 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2014-09-11 10:31:46 +0200 |
commit | cd994fc07f82bf950410bbdc88fbc4de7805547a (patch) | |
tree | e101bee3da5bfcb670f9826e6fa9de008f436b29 /sw | |
parent | b553b534575b2ef8e9dab96819c133414c4a0dc8 (diff) |
sw: factor out a function to encapsulate object lifetimes
Change-Id: Ie49cb4729d70f2b1fee9a2b7bd4ac095732a3d58
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/core/crsr/crstrvl.cxx | 59 |
1 files changed, 34 insertions, 25 deletions
diff --git a/sw/source/core/crsr/crstrvl.cxx b/sw/source/core/crsr/crstrvl.cxx index 86ebf8cd034b..ab6c2d41f9a8 100644 --- a/sw/source/core/crsr/crstrvl.cxx +++ b/sw/source/core/crsr/crstrvl.cxx @@ -608,6 +608,37 @@ void lcl_MakeFldLst( } } +static _SetGetExpFlds::const_iterator +lcl_FindField(bool & o_rFound, _SetGetExpFlds const& rSrtLst, + SwRootFrm *const pLayout, SwTxtNode *const pTxtNode, + SwTxtFld *const pTxtFld, SwPosition const& rPos, + sal_Int32 const nContentOffset) +{ + boost::scoped_ptr<_SetGetExpFld> pSrch; + boost::scoped_ptr<SwIndex> pIndex; + if (-1 == nContentOffset) + { + pSrch.reset(new _SetGetExpFld(rPos.nNode, pTxtFld, &rPos.nContent)); + } + else + { + pIndex.reset(new SwIndex(rPos.nNode.GetNode().GetCntntNode(), nContentOffset)); + pSrch.reset(new _SetGetExpFld(rPos.nNode, pTxtFld, pIndex.get())); + } + + if (rPos.nNode.GetIndex() < pTxtNode->GetNodes().GetEndOfExtras().GetIndex()) + { + // also at collection use only the first frame + Point aPt; + pSrch->SetBodyPos(*pTxtNode->getLayoutFrm(pLayout, &aPt, &rPos, false)); + } + + _SetGetExpFlds::const_iterator it = rSrtLst.lower_bound(pSrch.get()); + + o_rFound = (**it == *pSrch); + return it; +} + bool SwCrsrShell::MoveFldType( const SwFieldType* pFldType, const bool bNext, @@ -693,31 +724,9 @@ bool SwCrsrShell::MoveFldType( && rPos.nContent.GetIndex() != pTxtFld->GetStart()) nContentOffset = pTxtFld->GetStart(); } - - _SetGetExpFld *pSrch = NULL; - SwIndex *pIndex = NULL; - if( -1 == nContentOffset ) - { - pSrch = new _SetGetExpFld( rPos.nNode, pTxtFld, &rPos.nContent ); - } - else - { - pIndex = new SwIndex( rPos.nNode.GetNode().GetCntntNode(), nContentOffset ); - pSrch = new _SetGetExpFld( rPos.nNode, pTxtFld, pIndex ); - } - - if( rPos.nNode.GetIndex() < mpDoc->GetNodes().GetEndOfExtras().GetIndex() ) - { - // also at collection use only the first frame - Point aPt; - pSrch->SetBodyPos( *pTNd->getLayoutFrm( GetLayout(), &aPt, &rPos, false ) ); - } - - it = aSrtLst.lower_bound( pSrch ); - - bool isSrch = (**it == *pSrch); - delete pIndex; - delete pSrch; + bool isSrch; + it = lcl_FindField(isSrch, aSrtLst, + GetLayout(), pTNd, pTxtFld, rPos, nContentOffset); if( bDelFld ) { |