sw/inc/calbck.hxx | 5 sw/source/core/access/accdoc.cxx | 16 + sw/source/core/attr/swatrset.cxx | 30 +-- sw/source/core/bastyp/breakit.cxx | 16 - sw/source/core/bastyp/calc.cxx | 12 + sw/source/core/bastyp/index.cxx | 16 + sw/source/core/crsr/callnk.cxx | 17 +- sw/source/core/crsr/crsrsh.cxx | 52 ++++-- sw/source/core/crsr/crstrvl.cxx | 309 ++++++++++++++++++++++---------------- sw/source/core/crsr/findattr.cxx | 126 +++++++++------ sw/source/core/crsr/pam.cxx | 8 sw/source/core/crsr/swcrsr.cxx | 53 ++++-- sw/source/core/crsr/trvlcol.cxx | 46 ++--- sw/source/core/crsr/trvlfnfl.cxx | 14 + sw/source/core/crsr/trvlreg.cxx | 34 ++-- 15 files changed, 457 insertions(+), 297 deletions(-)
New commits: commit 9a3b47afab1750eba0451d59a8bac53302d85b2f Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Fri Apr 17 09:00:44 2020 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Fri Apr 17 13:03:38 2020 +0200 loplugin:buriedassign in sw(1) Change-Id: Ifaab4ab1bde3ff8236b51244098c81e6f460fbd5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92408 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/inc/calbck.hxx b/sw/inc/calbck.hxx index e0f71b8e9229..fc17b826f965 100644 --- a/sw/inc/calbck.hxx +++ b/sw/inc/calbck.hxx @@ -312,7 +312,8 @@ namespace sw if(m_pPosition) while( m_pPosition->m_pLeft ) m_pPosition = m_pPosition->m_pLeft; - return m_pCurrent = m_pPosition; + m_pCurrent = m_pPosition; + return m_pCurrent; } ~ClientIteratorBase() override { @@ -326,7 +327,7 @@ namespace sw // SwModify::Add() asserts this bool IsChanged() const { return m_pPosition != m_pCurrent; } // ensures the iterator to point at a current client - WriterListener* Sync() { return m_pCurrent = m_pPosition; } + WriterListener* Sync() { m_pCurrent = m_pPosition; return m_pCurrent; } }; } diff --git a/sw/source/core/access/accdoc.cxx b/sw/source/core/access/accdoc.cxx index 3b518626647d..18ae284d440c 100644 --- a/sw/source/core/access/accdoc.cxx +++ b/sw/source/core/access/accdoc.cxx @@ -747,19 +747,21 @@ css::uno::Sequence< css::uno::Any > o3tl::sorted_vector<SwFrame*> vFrameList; do { - if ( _pStartCursor && _pStartCursor->HasMark() ) + if ( !_pStartCursor ) + break; + if ( _pStartCursor->HasMark() ) { SwContentNode* pContentNode = _pStartCursor->GetContentNode(); - SwFrame *const pFrame = pContentNode - ? pContentNode->getLayoutFrame(pCursorShell->GetLayout(), _pStartCursor->GetPoint()) - : nullptr; - if ( pFrame ) + if (pContentNode) { - vFrameList.insert( pFrame ); + SwFrame *const pFrame = pContentNode->getLayoutFrame(pCursorShell->GetLayout(), _pStartCursor->GetPoint()); + if ( pFrame ) + vFrameList.insert( pFrame ); } } + _pStartCursor = _pStartCursor->GetNext(); } - while( _pStartCursor && ( (_pStartCursor = _pStartCursor->GetNext()) != _pStartCursor2) ); + while( _pStartCursor != _pStartCursor2 ); if ( !vFrameList.empty() ) { diff --git a/sw/source/core/attr/swatrset.cxx b/sw/source/core/attr/swatrset.cxx index 3870d7334afe..d62df7e94719 100644 --- a/sw/source/core/attr/swatrset.cxx +++ b/sw/source/core/attr/swatrset.cxx @@ -263,9 +263,8 @@ bool SwAttrSet::SetModifyAtAttr( const SwModify* pModify ) { // If CharFormat is set and it is set in different attribute pools then // the CharFormat has to be copied. - SwCharFormat* pCharFormat; - if( nullptr != ( pCharFormat = const_cast<SwFormatDrop*>(static_cast<const SwFormatDrop*>(pItem))->GetCharFormat() ) - && GetPool() != pCharFormat->GetAttrSet().GetPool() ) + SwCharFormat* pCharFormat = const_cast<SwFormatDrop*>(static_cast<const SwFormatDrop*>(pItem))->GetCharFormat(); + if( pCharFormat && GetPool() != pCharFormat->GetAttrSet().GetPool() ) { pCharFormat = GetDoc()->CopyCharFormat( *pCharFormat ); const_cast<SwFormatDrop*>(static_cast<const SwFormatDrop*>(pItem))->SetCharFormat( pCharFormat ); @@ -370,20 +369,23 @@ void SwAttrSet::CopyToModify( SwModify& rMod ) const const SwPageDesc* pPgDesc; if( pSrcDoc != pDstDoc && SfxItemState::SET == GetItemState( - RES_PAGEDESC, false, &pItem ) && - nullptr != ( pPgDesc = static_cast<const SwFormatPageDesc*>(pItem)->GetPageDesc()) ) + RES_PAGEDESC, false, &pItem )) { - tmpSet.reset(new SfxItemSet(*this)); - - SwPageDesc* pDstPgDesc = pDstDoc->FindPageDesc(pPgDesc->GetName()); - if( !pDstPgDesc ) + pPgDesc = static_cast<const SwFormatPageDesc*>(pItem)->GetPageDesc(); + if( pPgDesc ) { - pDstPgDesc = pDstDoc->MakePageDesc(pPgDesc->GetName()); - pDstDoc->CopyPageDesc( *pPgDesc, *pDstPgDesc ); + tmpSet.reset(new SfxItemSet(*this)); + + SwPageDesc* pDstPgDesc = pDstDoc->FindPageDesc(pPgDesc->GetName()); + if( !pDstPgDesc ) + { + pDstPgDesc = pDstDoc->MakePageDesc(pPgDesc->GetName()); + pDstDoc->CopyPageDesc( *pPgDesc, *pDstPgDesc ); + } + SwFormatPageDesc aDesc( pDstPgDesc ); + aDesc.SetNumOffset( static_cast<const SwFormatPageDesc*>(pItem)->GetNumOffset() ); + tmpSet->Put( aDesc ); } - SwFormatPageDesc aDesc( pDstPgDesc ); - aDesc.SetNumOffset( static_cast<const SwFormatPageDesc*>(pItem)->GetNumOffset() ); - tmpSet->Put( aDesc ); } if( pSrcDoc != pDstDoc && SfxItemState::SET == GetItemState( RES_ANCHOR, false, &pItem ) diff --git a/sw/source/core/bastyp/breakit.cxx b/sw/source/core/bastyp/breakit.cxx index 964e9a37d5b2..af77672f7eb8 100644 --- a/sw/source/core/bastyp/breakit.cxx +++ b/sw/source/core/bastyp/breakit.cxx @@ -105,18 +105,18 @@ sal_uInt16 SwBreakIt::GetRealScriptOfText( const OUString& rText, sal_Int32 nPos break; } } - if( i18n::ScriptType::WEAK == nScript && - nPos && - 0 < ( nChgPos = m_xBreak->beginOfScript(rText, nPos, nScript) ) ) + if( i18n::ScriptType::WEAK == nScript && nPos ) { - nScript = m_xBreak->getScriptType(rText, nChgPos-1); + nChgPos = m_xBreak->beginOfScript(rText, nPos, nScript); + if( 0 < nChgPos ) + nScript = m_xBreak->getScriptType(rText, nChgPos-1); } - if( i18n::ScriptType::WEAK == nScript && - rText.getLength() > ( nChgPos = m_xBreak->endOfScript(rText, nPos, nScript) ) && - 0 <= nChgPos ) + if( i18n::ScriptType::WEAK == nScript ) { - nScript = m_xBreak->getScriptType(rText, nChgPos); + nChgPos = m_xBreak->endOfScript(rText, nPos, nScript); + if( rText.getLength() > nChgPos && 0 <= nChgPos ) + nScript = m_xBreak->getScriptType(rText, nChgPos); } } if( i18n::ScriptType::WEAK == nScript ) diff --git a/sw/source/core/bastyp/calc.cxx b/sw/source/core/bastyp/calc.cxx index b82a328ad3d8..ffe3d9d9c92b 100644 --- a/sw/source/core/bastyp/calc.cxx +++ b/sw/source/core/bastyp/calc.cxx @@ -358,8 +358,13 @@ SwSbxValue SwCalc::Calculate( const OUString& rStr ) m_sCommand = rStr; m_nCommandPos = 0; - while( (m_eCurrOper = GetToken()) != CALC_ENDCALC && m_eError == SwCalcError::NONE ) + for (;;) + { + m_eCurrOper = GetToken(); + if (m_eCurrOper == CALC_ENDCALC || m_eError != SwCalcError::NONE ) + break; nResult = Expr(); + } if( m_eError != SwCalcError::NONE) nResult.PutDouble( DBL_MAX ); @@ -615,7 +620,10 @@ CharClass* SwCalc::GetCharClass() SwCalcOper SwCalc::GetToken() { if( m_nCommandPos >= m_sCommand.getLength() ) - return m_eCurrOper = CALC_ENDCALC; + { + m_eCurrOper = CALC_ENDCALC; + return m_eCurrOper; + } using namespace ::com::sun::star::i18n; { diff --git a/sw/source/core/bastyp/index.cxx b/sw/source/core/bastyp/index.cxx index 4f740948abff..073b6656311d 100644 --- a/sw/source/core/bastyp/index.cxx +++ b/sw/source/core/bastyp/index.cxx @@ -87,9 +87,13 @@ SwIndex& SwIndex::ChgValue( const SwIndex& rIdx, sal_Int32 nNewValue ) SwIndex* pFnd = const_cast<SwIndex*>(&rIdx); if (rIdx.m_nIndex > nNewValue) // move forwards { - SwIndex* pPrv; - while ((nullptr != (pPrv = pFnd->m_pPrev)) && (pPrv->m_nIndex > nNewValue)) + for (;;) + { + SwIndex* pPrv = pFnd->m_pPrev; + if (!pPrv || pPrv->m_nIndex <= nNewValue) + break; pFnd = pPrv; + } if( pFnd != this ) { @@ -107,9 +111,13 @@ SwIndex& SwIndex::ChgValue( const SwIndex& rIdx, sal_Int32 nNewValue ) } else if (rIdx.m_nIndex < nNewValue) { - SwIndex* pNxt; - while ((nullptr != (pNxt = pFnd->m_pNext)) && (pNxt->m_nIndex < nNewValue)) + for (;;) + { + SwIndex* pNxt = pFnd->m_pNext; + if (!pNxt || pNxt->m_nIndex >= nNewValue) + break; pFnd = pNxt; + } if( pFnd != this ) { diff --git a/sw/source/core/crsr/callnk.cxx b/sw/source/core/crsr/callnk.cxx index 4d27742fca12..90905da63b7a 100644 --- a/sw/source/core/crsr/callnk.cxx +++ b/sw/source/core/crsr/callnk.cxx @@ -197,8 +197,13 @@ SwCallLink::~SwCallLink() COVERITY_NOEXCEPT_FALSE const SwFrame* pFrame; const SwFlyFrame *pFlyFrame; - if (!m_rShell.ActionPend() && nullptr != (pFrame = pCNd->getLayoutFrame(m_rShell.GetLayout(), nullptr, nullptr)) && - nullptr != ( pFlyFrame = pFrame->FindFlyFrame() ) && !m_rShell.IsTableMode() ) + if (m_rShell.ActionPend()) + return; + pFrame = pCNd->getLayoutFrame(m_rShell.GetLayout(), nullptr, nullptr); + if (!pFrame) + return; + pFlyFrame = pFrame->FindFlyFrame(); + if ( pFlyFrame && !m_rShell.IsTableMode() ) { const SwNodeIndex* pIndex = pFlyFrame->GetFormat()->GetContent().GetContentIdx(); OSL_ENSURE( pIndex, "Fly without Content" ); @@ -224,9 +229,13 @@ long SwCallLink::getLayoutFrame(const SwRootFrame* pRoot, if( pFrame->HasFollow() ) { TextFrameIndex const nPos(pFrame->MapModelToView(&rNd, nCntPos)); - while( nullptr != ( pNext = pFrame->GetFollow() ) && - nPos >= pNext->GetOffset()) + for (;;) + { + pNext = pFrame->GetFollow(); + if(!pNext || nPos < pNext->GetOffset()) + break; pFrame = pNext; + } } return pFrame->getFrameArea().Left(); diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx index 7a33146ac52f..d7b4ffc1988b 100644 --- a/sw/source/core/crsr/crsrsh.cxx +++ b/sw/source/core/crsr/crsrsh.cxx @@ -194,12 +194,18 @@ SwPaM* SwCursorShell::GetCursor( bool bMakeTableCursor ) const //don't re-create 'parked' cursors const SwContentNode* pCNd; if( m_pTableCursor->GetPoint()->nNode.GetIndex() && - m_pTableCursor->GetMark()->nNode.GetIndex() && - nullptr != ( pCNd = m_pTableCursor->GetContentNode() ) && pCNd->getLayoutFrame( GetLayout() ) && - nullptr != ( pCNd = m_pTableCursor->GetContentNode(false) ) && pCNd->getLayoutFrame( GetLayout() ) ) + m_pTableCursor->GetMark()->nNode.GetIndex() ) { - SwShellTableCursor* pTC = m_pTableCursor; - GetLayout()->MakeTableCursors( *pTC ); + pCNd = m_pTableCursor->GetContentNode(); + if( pCNd && pCNd->getLayoutFrame( GetLayout() ) ) + { + pCNd = m_pTableCursor->GetContentNode(false); + if( pCNd && pCNd->getLayoutFrame( GetLayout() ) ) + { + SwShellTableCursor* pTC = m_pTableCursor; + GetLayout()->MakeTableCursors( *pTC ); + } + } } } @@ -637,13 +643,13 @@ bool SwCursorShell::MovePage( SwWhichPage fnWhichPage, SwPosPage fnPosPage ) std::pair<Point, bool> tmp(rPt, false); SwContentFrame * pFrame = m_pCurrentCursor->GetContentNode()-> getLayoutFrame(GetLayout(), m_pCurrentCursor->GetPoint(), &tmp); - if( pFrame && ( bRet = GetFrameInPage( pFrame, fnWhichPage, - fnPosPage, m_pCurrentCursor ) ) && + if( pFrame && GetFrameInPage( pFrame, fnWhichPage, fnPosPage, m_pCurrentCursor ) && !m_pCurrentCursor->IsSelOvr( SwCursorSelOverFlags::Toggle | SwCursorSelOverFlags::ChangePos )) + { UpdateCursor(); - else - bRet = false; + bRet = true; + } } return bRet; } @@ -1224,11 +1230,15 @@ sal_uInt16 SwCursorShell::GetPageNumSeqNonEmpty() const SwContentFrame* pCFrame = GetCurrFrame(/*bCalcFrame*/true); const SwPageFrame* pPg = nullptr; - if (!pCFrame || nullptr == (pPg = pCFrame->FindPageFrame())) + if (!pCFrame ) { - pPg = Imp()->GetFirstVisPage(GetOut()); - while (pPg && pPg->IsEmptyPage()) - pPg = static_cast<const SwPageFrame*>(pPg->GetNext()); + pPg = pCFrame->FindPageFrame(); + if( !pPg ) + { + pPg = Imp()->GetFirstVisPage(GetOut()); + while (pPg && pPg->IsEmptyPage()) + pPg = static_cast<const SwPageFrame*>(pPg->GetNext()); + } } sal_uInt16 nPageNo = 0; @@ -2850,7 +2860,8 @@ void SwCursorShell::ParkCursor( const SwNodeIndex &rIdx ) std::unique_ptr<SwPaM> pNew( new SwPaM( *GetCursor()->GetPoint() ) ); if( pNode->GetStartNode() ) { - if( ( pNode = pNode->StartOfSectionNode())->IsTableNode() ) + pNode = pNode->StartOfSectionNode(); + if( pNode->IsTableNode() ) { // the given node is in a table, thus park cursor to table node // (outside of the table) @@ -3728,10 +3739,15 @@ void SwCursorShell::GetSmartTagRect( const Point& rPt, SwRect& rSelectRect ) SwTextNode *pNode; const SwWrongList *pSmartTagList; - if( GetLayout()->GetModelPositionForViewPoint( &aPos, aPt, &eTmpState ) && - nullptr != (pNode = aPos.nNode.GetNode().GetTextNode()) && - nullptr != (pSmartTagList = pNode->GetSmartTags()) && - !pNode->IsInProtectSect() ) + if( !GetLayout()->GetModelPositionForViewPoint( &aPos, aPt, &eTmpState ) ) + return; + pNode = aPos.nNode.GetNode().GetTextNode(); + if( !pNode ) + return; + pSmartTagList = pNode->GetSmartTags(); + if( !pSmartTagList ) + return; + if( !pNode->IsInProtectSect() ) { sal_Int32 nBegin = aPos.nContent.GetIndex(); sal_Int32 nLen = 1; diff --git a/sw/source/core/crsr/crstrvl.cxx b/sw/source/core/crsr/crstrvl.cxx index 79cd6551bc4e..c9ced018ee83 100644 --- a/sw/source/core/crsr/crstrvl.cxx +++ b/sw/source/core/crsr/crstrvl.cxx @@ -376,39 +376,42 @@ void SwCursorShell::GotoTOXMarkBase() // for the actual index const SwTOXType* pType = aMarks[0]->GetTOXType(); SwIterator<SwTOXBase,SwTOXType> aIter( *pType ); - const SwSectionFormat* pSectFormat; for( SwTOXBase* pTOX = aIter.First(); pTOX; pTOX = aIter.Next() ) { - const SwSectionNode* pSectNd; - if( dynamic_cast<const SwTOXBaseSection*>( pTOX) != nullptr && - nullptr != ( pSectFormat = static_cast<SwTOXBaseSection*>(pTOX)->GetFormat() ) && - nullptr != ( pSectNd = pSectFormat->GetSectionNode() )) + auto pTOXBaseSection = dynamic_cast<const SwTOXBaseSection*>( pTOX); + if( !pTOXBaseSection ) + continue; + auto pSectFormat = pTOXBaseSection->GetFormat(); + if( !pSectFormat ) + continue; + const SwSectionNode* pSectNd = pSectFormat->GetSectionNode(); + if (!pSectNd) + continue; + SwNodeIndex aIdx( *pSectNd, 1 ); + SwContentNode* pCNd = aIdx.GetNode().GetContentNode(); + if( !pCNd ) + pCNd = GetDoc()->GetNodes().GoNext( &aIdx ); + if( !pCNd ) + continue; + if( pCNd->EndOfSectionIndex() >= pSectNd->EndOfSectionIndex() ) + continue; + const SwContentFrame* pCFrame = pCNd->getLayoutFrame( GetLayout() ); + if( pCFrame && ( IsReadOnlyAvailable() || !pCFrame->IsProtected() ) ) { - SwNodeIndex aIdx( *pSectNd, 1 ); - SwContentNode* pCNd = aIdx.GetNode().GetContentNode(); - if( !pCNd ) - pCNd = GetDoc()->GetNodes().GoNext( &aIdx ); - const SwContentFrame* pCFrame; - if( pCNd && - pCNd->EndOfSectionIndex() < pSectNd->EndOfSectionIndex() && - nullptr != ( pCFrame = pCNd->getLayoutFrame( GetLayout() ) ) && - ( IsReadOnlyAvailable() || !pCFrame->IsProtected() )) - { - SwCallLink aLk( *this ); // watch Cursor-Moves - SwCursorSaveState aSaveState( *m_pCurrentCursor ); - assert(pCFrame->IsTextFrame()); - *m_pCurrentCursor->GetPoint() = - static_cast<SwTextFrame const*>(pCFrame) - ->MapViewToModelPos(TextFrameIndex(0)); - bRet = !m_pCurrentCursor->IsInProtectTable() && - !m_pCurrentCursor->IsSelOvr(); - if( bRet ) - UpdateCursor(SwCursorShell::SCROLLWIN|SwCursorShell::CHKRANGE|SwCursorShell::READONLY); - break; - } + SwCallLink aLk( *this ); // watch Cursor-Moves + SwCursorSaveState aSaveState( *m_pCurrentCursor ); + assert(pCFrame->IsTextFrame()); + *m_pCurrentCursor->GetPoint() = + static_cast<SwTextFrame const*>(pCFrame) + ->MapViewToModelPos(TextFrameIndex(0)); + bRet = !m_pCurrentCursor->IsInProtectTable() && + !m_pCurrentCursor->IsSelOvr(); + if( bRet ) + UpdateCursor(SwCursorShell::SCROLLWIN|SwCursorShell::CHKRANGE|SwCursorShell::READONLY); + break; } - } + } } } @@ -460,28 +463,33 @@ bool SwCursorShell::GotoNxtPrvTableFormula( bool bNext, bool bOnlyErrors ) { const SwTableBox* pTBox; auto pFormulaItem = dynamic_cast<const SwTableBoxFormula*>(pItem); - if( pFormulaItem && - nullptr != (pTBox = pFormulaItem->GetTableBox() ) && - pTBox->GetSttNd() && - pTBox->GetSttNd()->GetNodes().IsDocNodes() && - ( !bOnlyErrors || - !pFormulaItem->HasValidBoxes() ) ) + if( !pFormulaItem ) + continue; + pTBox = pFormulaItem->GetTableBox(); + if( pTBox && + pTBox->GetSttNd() && + pTBox->GetSttNd()->GetNodes().IsDocNodes() && + ( !bOnlyErrors || + !pFormulaItem->HasValidBoxes() ) ) { const SwContentFrame* pCFrame; SwNodeIndex aIdx( *pTBox->GetSttNd() ); const SwContentNode* pCNd = GetDoc()->GetNodes().GoNext( &aIdx ); std::pair<Point, bool> const tmp(aPt, false); - if (pCNd && nullptr != (pCFrame = pCNd->getLayoutFrame(GetLayout(), nullptr, &tmp)) && - (IsReadOnlyAvailable() || !pCFrame->IsProtected() )) + if (pCNd) { - SetGetExpField aCmp( *pTBox ); - aCmp.SetBodyPos( *pCFrame ); - - if( bNext ? ( aCurGEF < aCmp && aCmp < aFndGEF ) - : ( aCmp < aCurGEF && aFndGEF < aCmp )) + pCFrame = pCNd->getLayoutFrame(GetLayout(), nullptr, &tmp); + if (pCFrame && (IsReadOnlyAvailable() || !pCFrame->IsProtected() )) { - aFndGEF = aCmp; - bFnd = true; + SetGetExpField aCmp( *pTBox ); + aCmp.SetBodyPos( *pCFrame ); + + if( bNext ? ( aCurGEF < aCmp && aCmp < aFndGEF ) + : ( aCmp < aCurGEF && aFndGEF < aCmp )) + { + aFndGEF = aCmp; + bFnd = true; + } } } } @@ -564,14 +572,17 @@ bool SwCursorShell::GotoNxtPrvTOXMark( bool bNext ) for (const SfxPoolItem* pItem : GetDoc()->GetAttrPool().GetItemSurrogates(RES_TXTATR_TOXMARK)) { auto pToxMarkItem = dynamic_cast<const SwTOXMark*>(pItem); - const SwContentFrame* pCFrame; - + if( !pToxMarkItem ) + continue; + pTextTOX = pToxMarkItem->GetTextTOXMark(); + if( !pTextTOX ) + continue; + pTextNd = &pTextTOX->GetTextNode(); + if( !pTextNd->GetNodes().IsDocNodes() ) + continue; std::pair<Point, bool> const tmp(aPt, false); - if( pToxMarkItem && - nullptr != (pTextTOX = pToxMarkItem->GetTextTOXMark() ) && - ( pTextNd = &pTextTOX->GetTextNode())->GetNodes().IsDocNodes() && - nullptr != (pCFrame = pTextNd->getLayoutFrame(GetLayout(), nullptr, &tmp)) && - ( IsReadOnlyAvailable() || !pCFrame->IsProtected() )) + const SwContentFrame* pCFrame = pTextNd->getLayoutFrame(GetLayout(), nullptr, &tmp); + if( pCFrame && ( IsReadOnlyAvailable() || !pCFrame->IsProtected() )) { SwNodeIndex aNdIndex( *pTextNd ); // UNIX needs this object SetGetExpField aCmp( aNdIndex, *pTextTOX ); @@ -1366,8 +1377,12 @@ bool SwCursorShell::GetContentAtPos( const Point& rPt, rContentAtPos.eContentAtPos = IsAttrAtPos::SmartTag; std::pair<Point, bool> tmp(aPt, true); - if (pFieldRect && nullptr != (pFrame = pTextNd->getLayoutFrame(GetLayout(), nullptr, &tmp))) - pFrame->GetCharRect( *pFieldRect, aPos, &aTmpState ); + if (pFieldRect) + { + pFrame = pTextNd->getLayoutFrame(GetLayout(), nullptr, &tmp); + if (pFrame) + pFrame->GetCharRect( *pFieldRect, aPos, &aTmpState ); + } } } } @@ -1388,15 +1403,19 @@ bool SwCursorShell::GetContentAtPos( const Point& rPt, if ( pField ) { - std::pair<Point, bool> tmp(aPt, true); - if (pFieldRect && nullptr != (pFrame = pTextNd->getLayoutFrame(GetLayout(), nullptr, &tmp))) + if (pFieldRect) { - //tdf#116397 now that we looking for the bounds of the field drop the SmartTag - //index within field setting so we don't the bounds of the char within the field - SwSpecialPos* pSpecialPos = aTmpState.m_pSpecialPos; - aTmpState.m_pSpecialPos = nullptr; - pFrame->GetCharRect( *pFieldRect, aPos, &aTmpState ); - aTmpState.m_pSpecialPos = pSpecialPos; + std::pair<Point, bool> tmp(aPt, true); + pFrame = pTextNd->getLayoutFrame(GetLayout(), nullptr, &tmp); + if (pFrame) + { + //tdf#116397 now that we looking for the bounds of the field drop the SmartTag + //index within field setting so we don't the bounds of the char within the field + SwSpecialPos* pSpecialPos = aTmpState.m_pSpecialPos; + aTmpState.m_pSpecialPos = nullptr; + pFrame->GetCharRect( *pFieldRect, aPos, &aTmpState ); + aTmpState.m_pSpecialPos = pSpecialPos; + } } if( bSetCursor ) @@ -1495,9 +1514,13 @@ bool SwCursorShell::GetContentAtPos( const Point& rPt, rContentAtPos.pFndTextAttr = pTextAttr; rContentAtPos.aFnd.pAttr = &pTextAttr->GetAttr(); - std::pair<Point, bool> tmp(aPt, true); - if (pFieldRect && nullptr != (pFrame = pTextNd->getLayoutFrame(GetLayout(), nullptr, &tmp))) - pFrame->GetCharRect( *pFieldRect, aPos, &aTmpState ); + if (pFieldRect) + { + std::pair<Point, bool> tmp(aPt, true); + pFrame = pTextNd->getLayoutFrame(GetLayout(), nullptr, &tmp); + if (pFrame) + pFrame->GetCharRect( *pFieldRect, aPos, &aTmpState ); + } } } } @@ -1563,8 +1586,12 @@ bool SwCursorShell::GetContentAtPos( const Point& rPt, rContentAtPos.aFnd.pAttr = &pTextAttr->GetAttr(); std::pair<Point, bool> tmp(aPt, true); - if (pFieldRect && nullptr != (pFrame = pTextNd->getLayoutFrame(GetLayout(), nullptr, &tmp))) - pFrame->GetCharRect( *pFieldRect, aPos, &aTmpState ); + if (pFieldRect) + { + pFrame = pTextNd->getLayoutFrame(GetLayout(), nullptr, &tmp); + if (pFrame) + pFrame->GetCharRect( *pFieldRect, aPos, &aTmpState ); + } } } } @@ -1602,22 +1629,26 @@ bool SwCursorShell::GetContentAtPos( const Point& rPt, rContentAtPos.eContentAtPos = IsAttrAtPos::InetAttr; rContentAtPos.pFndTextAttr = pTextAttr; - std::pair<Point, bool> tmp(aPt, true); - if (pFieldRect && nullptr != (pFrame = pTextNd->getLayoutFrame(GetLayout(), nullptr, &tmp))) + if (pFieldRect) { - //get bounding box of range - SwRect aStart; - SwPosition aStartPos(*pTextNd, nSt); - pFrame->GetCharRect(aStart, aStartPos, &aTmpState); - SwRect aEnd; - SwPosition aEndPos(*pTextNd, nEnd); - pFrame->GetCharRect(aEnd, aEndPos, &aTmpState); - if (aStart.Top() != aEnd.Top() || aStart.Bottom() != aEnd.Bottom()) + std::pair<Point, bool> tmp(aPt, true); + pFrame = pTextNd->getLayoutFrame(GetLayout(), nullptr, &tmp); + if (pFrame) { - aStart.Left(pFrame->getFrameArea().Left()); - aEnd.Right(pFrame->getFrameArea().Right()); + //get bounding box of range + SwRect aStart; + SwPosition aStartPos(*pTextNd, nSt); + pFrame->GetCharRect(aStart, aStartPos, &aTmpState); + SwRect aEnd; + SwPosition aEndPos(*pTextNd, nEnd); + pFrame->GetCharRect(aEnd, aEndPos, &aTmpState); + if (aStart.Top() != aEnd.Top() || aStart.Bottom() != aEnd.Bottom()) + { + aStart.Left(pFrame->getFrameArea().Left()); + aEnd.Right(pFrame->getFrameArea().Right()); + } + *pFieldRect = aStart.Union(aEnd); } - *pFieldRect = aStart.Union(aEnd); } } } @@ -1634,37 +1665,41 @@ bool SwCursorShell::GetContentAtPos( const Point& rPt, rContentAtPos.pFndTextAttr = nullptr; bRet = true; - std::pair<Point, bool> tmp(aPt, true); - if (pFieldRect && nullptr != (pFrame = pTextNd->getLayoutFrame(GetLayout(), nullptr, &tmp))) + if (pFieldRect) { - // not sure if this should be limited to one - // paragraph, or mark the entire redline; let's - // leave it limited to one for now... - sal_Int32 nStart; - sal_Int32 nEnd; - pRedl->CalcStartEnd(pTextNd->GetIndex(), nStart, nEnd); - if (nStart == COMPLETE_STRING) - { - // consistency: found pRedl, so there must be - // something in pTextNd - assert(nEnd != COMPLETE_STRING); - nStart = 0; - } - if (nEnd == COMPLETE_STRING) - { - nEnd = pTextNd->Len(); - } - //get bounding box of range - SwRect aStart; - pFrame->GetCharRect(aStart, SwPosition(*pTextNd, nStart), &aTmpState); - SwRect aEnd; - pFrame->GetCharRect(aEnd, SwPosition(*pTextNd, nEnd), &aTmpState); - if (aStart.Top() != aEnd.Top() || aStart.Bottom() != aEnd.Bottom()) + std::pair<Point, bool> tmp(aPt, true); + pFrame = pTextNd->getLayoutFrame(GetLayout(), nullptr, &tmp); + if( pFrame ) { - aStart.Left(pFrame->getFrameArea().Left()); - aEnd.Right(pFrame->getFrameArea().Right()); + // not sure if this should be limited to one + // paragraph, or mark the entire redline; let's + // leave it limited to one for now... + sal_Int32 nStart; + sal_Int32 nEnd; + pRedl->CalcStartEnd(pTextNd->GetIndex(), nStart, nEnd); + if (nStart == COMPLETE_STRING) + { + // consistency: found pRedl, so there must be + // something in pTextNd + assert(nEnd != COMPLETE_STRING); + nStart = 0; + } + if (nEnd == COMPLETE_STRING) + { + nEnd = pTextNd->Len(); + } + //get bounding box of range + SwRect aStart; + pFrame->GetCharRect(aStart, SwPosition(*pTextNd, nStart), &aTmpState); + SwRect aEnd; + pFrame->GetCharRect(aEnd, SwPosition(*pTextNd, nEnd), &aTmpState); + if (aStart.Top() != aEnd.Top() || aStart.Bottom() != aEnd.Bottom()) + { + aStart.Left(pFrame->getFrameArea().Left()); + aEnd.Right(pFrame->getFrameArea().Right()); + } + *pFieldRect = aStart.Union(aEnd); } - *pFieldRect = aStart.Union(aEnd); } } } @@ -1892,10 +1927,13 @@ bool SwContentAtPos::IsInProtectSect() const } } - const SwContentFrame* pFrame; - return pNd && ( pNd->IsInProtectSect() || - (nullptr != (pFrame = pNd->getLayoutFrame(pNd->GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout(), nullptr, nullptr)) && - pFrame->IsProtected() )); + if( !pNd ) + return false; + if( pNd->IsInProtectSect() ) + return true; + + const SwContentFrame* pFrame = pNd->getLayoutFrame(pNd->GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout(), nullptr, nullptr); + return pFrame && pFrame->IsProtected() ; } bool SwContentAtPos::IsInRTLText()const @@ -2235,16 +2273,18 @@ const SwRangeRedline* SwCursorShell::GotoRedline_( SwRedlineTable::size_type nAr { *m_pCurrentCursor->GetPoint() = *pFnd->Start(); - SwContentNode* pCNd; SwNodeIndex* pIdx = &m_pCurrentCursor->GetPoint()->nNode; - if( !pIdx->GetNode().IsContentNode() && - nullptr != ( pCNd = GetDoc()->GetNodes().GoNextSection( pIdx, - true, IsReadOnlyAvailable() )) ) + if( !pIdx->GetNode().IsContentNode() ) { - if( *pIdx <= pFnd->End()->nNode ) - m_pCurrentCursor->GetPoint()->nContent.Assign( pCNd, 0 ); - else - pFnd = nullptr; + SwContentNode* pCNd = GetDoc()->GetNodes().GoNextSection( pIdx, + true, IsReadOnlyAvailable() ); + if( pCNd ) + { + if( *pIdx <= pFnd->End()->nNode ) + m_pCurrentCursor->GetPoint()->nContent.Assign( pCNd, 0 ); + else + pFnd = nullptr; + } } if( pFnd && bSelect ) @@ -2252,7 +2292,7 @@ const SwRangeRedline* SwCursorShell::GotoRedline_( SwRedlineTable::size_type nAr m_pCurrentCursor->SetMark(); if( RedlineType::FmtColl == pFnd->GetType() ) { - pCNd = pIdx->GetNode().GetContentNode(); + SwContentNode* pCNd = pIdx->GetNode().GetContentNode(); m_pCurrentCursor->GetPoint()->nContent.Assign( pCNd, pCNd->Len() ); m_pCurrentCursor->GetMark()->nContent.Assign( pCNd, 0 ); } @@ -2260,14 +2300,17 @@ const SwRangeRedline* SwCursorShell::GotoRedline_( SwRedlineTable::size_type nAr *m_pCurrentCursor->GetPoint() = *pFnd->End(); pIdx = &m_pCurrentCursor->GetPoint()->nNode; - if( !pIdx->GetNode().IsContentNode() && - nullptr != ( pCNd = SwNodes::GoPrevSection( pIdx, - true, IsReadOnlyAvailable() )) ) + if( !pIdx->GetNode().IsContentNode() ) { - if( *pIdx >= m_pCurrentCursor->GetMark()->nNode ) - m_pCurrentCursor->GetPoint()->nContent.Assign( pCNd, pCNd->Len() ); - else - pFnd = nullptr; + SwContentNode* pCNd = SwNodes::GoPrevSection( pIdx, + true, IsReadOnlyAvailable() ); + if( pCNd ) + { + if( *pIdx >= m_pCurrentCursor->GetMark()->nNode ) + m_pCurrentCursor->GetPoint()->nContent.Assign( pCNd, pCNd->Len() ); + else + pFnd = nullptr; + } } } @@ -2416,8 +2459,12 @@ bool SwCursorShell::SelectNxtPrvHyperlink( bool bNext ) const SwContentNode* pCNd = aCurPos.GetNodeFromContent()->GetContentNode(); SwContentFrame* pFrame; std::pair<Point, bool> tmp(aPt, true); - if (pCNd && nullptr != (pFrame = pCNd->getLayoutFrame(GetLayout(), nullptr, &tmp))) - aCurPos.SetBodyPos( *pFrame ); + if (pCNd) + { + pFrame = pCNd->getLayoutFrame(GetLayout(), nullptr, &tmp); + if( pFrame ) + aCurPos.SetBodyPos( *pFrame ); + } } // check first all the hyperlink fields @@ -2429,8 +2476,9 @@ bool SwCursorShell::SelectNxtPrvHyperlink( bool bNext ) SwIterator<SwTextINetFormat,SwCharFormat> aIter(*(*pFormats)[--n]); for( SwTextINetFormat* pFnd = aIter.First(); pFnd; pFnd = aIter.Next() ) - if( nullptr != ( pTextNd = pFnd->GetpTextNode()) && - pTextNd->GetNodes().IsDocNodes() ) + { + pTextNd = pFnd->GetpTextNode(); + if( pTextNd && pTextNd->GetNodes().IsDocNodes() ) { SwTextINetFormat& rAttr = *pFnd; SwPosition aTmpPos( *pTextNd ); @@ -2461,6 +2509,7 @@ bool SwCursorShell::SelectNxtPrvHyperlink( bool bNext ) aCmpPos = aPos; } } + } } } diff --git a/sw/source/core/crsr/findattr.cxx b/sw/source/core/crsr/findattr.cxx index 061932700c7c..fc0a7abb5dfa 100644 --- a/sw/source/core/crsr/findattr.cxx +++ b/sw/source/core/crsr/findattr.cxx @@ -394,7 +394,8 @@ bool SwAttrCheckArr::SetAttrFwd( const SwTextAttr& rAttr ) } else if( pArrPtr->nStt <= aTmp.nStt ) { - if( ( pCmp = &m_pFindArr[ n ])->nWhich ) + pCmp = &m_pFindArr[ n ]; + if( pCmp->nWhich ) { if( pCmp->nEnd < pArrPtr->nEnd ) // extend pCmp->nEnd = pArrPtr->nEnd; @@ -419,7 +420,8 @@ bool SwAttrCheckArr::SetAttrFwd( const SwTextAttr& rAttr ) *pTmpItem )) { // search attribute and extend if needed - if( !( pCmp = &m_pFindArr[ nWhch - m_nArrStart ])->nWhich ) + pCmp = &m_pFindArr[ nWhch - m_nArrStart ]; + if( !pCmp->nWhich ) { *pCmp = aTmp; // not found, insert m_nFound++; @@ -439,24 +441,28 @@ bool SwAttrCheckArr::SetAttrFwd( const SwTextAttr& rAttr ) } // then is has to go on the stack - if( !bContinue && ( pCmp = &m_pFindArr[ nWhch - m_nArrStart ])->nWhich ) + if( !bContinue ) { - // exists on stack, only if it is even bigger - if( pCmp->nEnd > aTmp.nEnd ) + pCmp = &m_pFindArr[ nWhch - m_nArrStart ]; + if (pCmp->nWhich ) { - OSL_ENSURE( !m_pStackArr[ nWhch - m_nArrStart ].nWhich, - "slot on stack is still in use" ); + // exists on stack, only if it is even bigger + if( pCmp->nEnd > aTmp.nEnd ) + { + OSL_ENSURE( !m_pStackArr[ nWhch - m_nArrStart ].nWhich, + "slot on stack is still in use" ); - if( aTmp.nStt <= pCmp->nStt ) - pCmp->nStt = aTmp.nEnd; - else - pCmp->nEnd = aTmp.nStt; + if( aTmp.nStt <= pCmp->nStt ) + pCmp->nStt = aTmp.nEnd; + else + pCmp->nEnd = aTmp.nStt; - m_pStackArr[ nWhch - m_nArrStart ] = *pCmp; - m_nStackCount++; + m_pStackArr[ nWhch - m_nArrStart ] = *pCmp; + m_nStackCount++; + } + pCmp->nWhich = 0; + m_nFound--; } - pCmp->nWhich = 0; - m_nFound--; } } if( pIter ) @@ -547,7 +553,8 @@ bool SwAttrCheckArr::SetAttrBwd( const SwTextAttr& rAttr ) } else if( pArrPtr->nEnd >= aTmp.nEnd ) { - if( ( pCmp = &m_pFindArr[ n ])->nWhich ) + pCmp = &m_pFindArr[ n ]; + if( pCmp->nWhich ) { if( pCmp->nStt > pArrPtr->nStt ) // extend pCmp->nStt = pArrPtr->nStt; @@ -571,7 +578,8 @@ bool SwAttrCheckArr::SetAttrBwd( const SwTextAttr& rAttr ) *pTmpItem ) ) { // search attribute and extend if needed - if( !( pCmp = &m_pFindArr[ nWhch - m_nArrStart ])->nWhich ) + pCmp = &m_pFindArr[ nWhch - m_nArrStart ]; + if( !pCmp->nWhich ) { *pCmp = aTmp; // not found, insert m_nFound++; @@ -591,24 +599,28 @@ bool SwAttrCheckArr::SetAttrBwd( const SwTextAttr& rAttr ) } // then is has to go on the stack - if( !bContinue && ( pCmp = &m_pFindArr[ nWhch - m_nArrStart ])->nWhich ) + if( !bContinue ) { - // exists on stack, only if it is even bigger - if( pCmp->nStt < aTmp.nStt ) + pCmp = &m_pFindArr[ nWhch - m_nArrStart ]; + if( pCmp->nWhich ) { - OSL_ENSURE( !m_pStackArr[ nWhch - m_nArrStart ].nWhich, - "slot on stack is still in use" ); + // exists on stack, only if it is even bigger + if( pCmp->nStt < aTmp.nStt ) + { + OSL_ENSURE( !m_pStackArr[ nWhch - m_nArrStart ].nWhich, + "slot on stack is still in use" ); - if( aTmp.nEnd <= pCmp->nEnd ) - pCmp->nEnd = aTmp.nStt; - else - pCmp->nStt = aTmp.nEnd; + if( aTmp.nEnd <= pCmp->nEnd ) + pCmp->nEnd = aTmp.nStt; + else + pCmp->nStt = aTmp.nEnd; - m_pStackArr[ nWhch - m_nArrStart ] = *pCmp; - m_nStackCount++; + m_pStackArr[ nWhch - m_nArrStart ] = *pCmp; + m_nStackCount++; + } + pCmp->nWhich = 0; + m_nFound--; } - pCmp->nWhich = 0; - m_nFound--; } } if( pIter ) @@ -706,7 +718,9 @@ static bool lcl_SearchForward( const SwTextNode& rTextNd, SwAttrCheckArr& rCmpAr if( rCmpArr.Found() ) { for( ; nPos < rHtArr.Count(); ++nPos ) - if( !rCmpArr.SetAttrFwd( *( pAttr = rHtArr.Get( nPos )) ) ) + { + pAttr = rHtArr.Get( nPos ); + if( !rCmpArr.SetAttrFwd( *pAttr ) ) { if( rCmpArr.GetNdStt() < pAttr->GetStart() ) { @@ -719,6 +733,7 @@ static bool lcl_SearchForward( const SwTextNode& rTextNd, SwAttrCheckArr& rCmpAr // continue search break; } + } if( nPos == rHtArr.Count() && rCmpArr.Found() ) { @@ -731,14 +746,18 @@ static bool lcl_SearchForward( const SwTextNode& rTextNd, SwAttrCheckArr& rCmpAr sal_Int32 nSttPos; for( ; nPos < rHtArr.Count(); ++nPos ) - if( rCmpArr.SetAttrFwd( *( pAttr = rHtArr.Get( nPos )) ) ) + { + pAttr = rHtArr.Get( nPos ); + if( rCmpArr.SetAttrFwd( *pAttr ) ) { // Do multiple start at that position? Do also check those: nSttPos = pAttr->GetStart(); - while( ++nPos < rHtArr.Count() && nSttPos == - ( pAttr = rHtArr.Get( nPos ))->GetStart() && - rCmpArr.SetAttrFwd( *pAttr ) ) - ; + while( ++nPos < rHtArr.Count() ) + { + pAttr = rHtArr.Get( nPos ); + if( nSttPos != pAttr->GetStart() || !rCmpArr.SetAttrFwd( *pAttr ) ) + break; + } if( !rCmpArr.Found() ) continue; @@ -750,9 +769,13 @@ static bool lcl_SearchForward( const SwTextNode& rTextNd, SwAttrCheckArr& rCmpAr lcl_SetAttrPam( rPam, nSttPos, &nEndPos, true ); return true; } + } - if( !rCmpArr.CheckStack() || - (nSttPos = rCmpArr.Start()) > (nEndPos = rCmpArr.End()) ) + if( !rCmpArr.CheckStack() ) + return false; + nSttPos = rCmpArr.Start(); + nEndPos = rCmpArr.End(); + if( nSttPos > nEndPos ) return false; lcl_SetAttrPam( rPam, nSttPos, &nEndPos, true ); @@ -782,7 +805,9 @@ static bool lcl_SearchBackward( const SwTextNode& rTextNd, SwAttrCheckArr& rCmpA if( rCmpArr.Found() ) { while( nPos ) - if( !rCmpArr.SetAttrBwd( *( pAttr = rHtArr.GetSortedByEnd( --nPos )) ) ) + { + pAttr = rHtArr.GetSortedByEnd( --nPos ); + if( !rCmpArr.SetAttrBwd( *pAttr ) ) { nSttPos = pAttr->GetAnyEnd(); if( nSttPos < rCmpArr.GetNdEnd() ) @@ -796,6 +821,7 @@ static bool lcl_SearchBackward( const SwTextNode& rTextNd, SwAttrCheckArr& rCmpA // continue search break; } + } if( !nPos && rCmpArr.Found() ) { @@ -807,16 +833,20 @@ static bool lcl_SearchBackward( const SwTextNode& rTextNd, SwAttrCheckArr& rCmpA } while( nPos ) - if( rCmpArr.SetAttrBwd( *( pAttr = rHtArr.GetSortedByEnd( --nPos )) ) ) + { + pAttr = rHtArr.GetSortedByEnd( --nPos ); + if( rCmpArr.SetAttrBwd( *pAttr ) ) { // Do multiple start at that position? Do also check those: if( nPos ) { nEndPos = pAttr->GetAnyEnd(); - while( --nPos && nEndPos == - ( pAttr = rHtArr.GetSortedByEnd( nPos ))->GetAnyEnd() && - rCmpArr.SetAttrBwd( *pAttr ) ) - ; + while( --nPos ) + { + pAttr = rHtArr.GetSortedByEnd( nPos ); + if( nEndPos != pAttr->GetAnyEnd() || !rCmpArr.SetAttrBwd( *pAttr ) ) + break; + } } if( !rCmpArr.Found() ) continue; @@ -828,9 +858,13 @@ static bool lcl_SearchBackward( const SwTextNode& rTextNd, SwAttrCheckArr& rCmpA lcl_SetAttrPam( rPam, nSttPos, &nEndPos, false ); return true; } + } - if( !rCmpArr.CheckStack() || - (nSttPos = rCmpArr.Start()) > (nEndPos = rCmpArr.End()) ) + if( !rCmpArr.CheckStack() ) + return false; + nSttPos = rCmpArr.Start(); + nEndPos = rCmpArr.End(); + if( nSttPos > nEndPos ) return false; lcl_SetAttrPam( rPam, nSttPos, &nEndPos, false ); diff --git a/sw/source/core/crsr/pam.cxx b/sw/source/core/crsr/pam.cxx index 59ed41a036b1..c10f6ea37f58 100644 --- a/sw/source/core/crsr/pam.cxx +++ b/sw/source/core/crsr/pam.cxx @@ -229,9 +229,13 @@ static bool lcl_ChkOneRange( CHKSECTION eSec, bool bChkSections, if( !pNd->StartOfSectionIndex() ) return false; - while( ( pTmp = pNd->StartOfSectionNode())->EndOfSectionNode() != - &rBaseEnd ) + for (;;) + { + pTmp = pNd->StartOfSectionNode(); + if (pTmp->EndOfSectionNode() == &rBaseEnd ) + break; pNd = pTmp; + } sal_uLong nSttIdx = pNd->GetIndex(), nEndIdx = pNd->EndOfSectionIndex(); return nSttIdx <= nStt && nStt <= nEndIdx && diff --git a/sw/source/core/crsr/swcrsr.cxx b/sw/source/core/crsr/swcrsr.cxx index 9881a260f382..08c914b8c67a 100644 --- a/sw/source/core/crsr/swcrsr.cxx +++ b/sw/source/core/crsr/swcrsr.cxx @@ -340,9 +340,12 @@ bool SwCursor::IsSelOvr( SwCursorSelOverFlags eFlags ) // skip to the next/prev valid paragraph with a layout SwNodeIndex& rPtIdx = GetPoint()->nNode; bool bGoNxt = m_vSavePos.back().nNode < rPtIdx.GetIndex(); - while( nullptr != ( pFrame = ( bGoNxt ? pFrame->GetNextContentFrame() : pFrame->GetPrevContentFrame() )) - && 0 == pFrame->getFrameArea().Height() ) - ; + for (;;) + { + pFrame = bGoNxt ? pFrame->GetNextContentFrame() : pFrame->GetPrevContentFrame(); + if (!pFrame || 0 != pFrame->getFrameArea().Height() ) + break; + } // #i72394# skip to prev/next valid paragraph with a layout in case // the first search did not succeed: @@ -424,7 +427,8 @@ bool SwCursor::IsSelOvr( SwCursorSelOverFlags eFlags ) return true; // we need a frame } - if( (pNd = &GetMark()->nNode.GetNode())->IsContentNode() + pNd = &GetMark()->nNode.GetNode(); + if( pNd->IsContentNode() && !static_cast<const SwContentNode*>(pNd)->getLayoutFrame( pDoc->getIDocumentLayoutAccess().GetCurrentLayout() ) && !dynamic_cast<SwUnoCursor*>(this) ) { @@ -535,9 +539,15 @@ bool SwCursor::IsSelOvr( SwCursorSelOverFlags eFlags ) return false; } } - if( bSelTop - ? ( !pMyNd->IsEndNode() || nullptr == ( pPtNd = pMyNd->FindTableNode() )) - : nullptr == ( pPtNd = pMyNd->GetTableNode() )) + if( bSelTop ) + { + if ( !pMyNd->IsEndNode() ) + break; + pPtNd = pMyNd->FindTableNode(); + } + else + pPtNd = pMyNd->GetTableNode(); + if (!pPtNd) break; } while( true ); } @@ -629,8 +639,8 @@ SetNextCursor: } // end of table, so go to next node ++aCellStt; - SwNode* pNd; - if( ( pNd = &aCellStt.GetNode())->IsEndNode() || HasMark()) + SwNode* pNd = &aCellStt.GetNode(); + if( pNd->IsEndNode() || HasMark()) { // if only table in FlyFrame or SSelection then stay on old position if( bChgCursor ) @@ -653,7 +663,8 @@ SetNextCursor: bool bProt = true; GoPrevCell: for (;;) { - if( !( pNd = &aCellStt.GetNode())->IsEndNode() ) + pNd = &aCellStt.GetNode(); + if( !pNd->IsEndNode() ) break; aCellStt.Assign( *pNd->StartOfSectionNode(), +1 ); if( nullptr == ( pCNd = aCellStt.GetNode().GetContentNode() )) @@ -679,7 +690,8 @@ SetPrevCursor: } // at the beginning of a table, so go to next node --aCellStt; - if( ( pNd = &aCellStt.GetNode())->IsStartNode() || HasMark() ) + pNd = &aCellStt.GetNode(); + if( pNd->IsStartNode() || HasMark() ) { // if only table in FlyFrame or SSelection then stay on old position if( bChgCursor ) @@ -780,13 +792,14 @@ static sal_uLong lcl_FindSelection( SwFindParas& rParas, SwCursor* pCurrentCurso pPHdl.reset(new PercentHdl( aRegion )); // as long as found and not at same position - while( *pSttPos <= *pEndPos && - 0 != ( nFndRet = rParas.DoFind(*pCurrentCursor, fnMove, - aRegion, bInReadOnly)) && - ( !pFndRing || - *pFndRing->GetPoint() != *pCurrentCursor->GetPoint() || - *pFndRing->GetMark() != *pCurrentCursor->GetMark() )) + while( *pSttPos <= *pEndPos ) { + nFndRet = rParas.DoFind(*pCurrentCursor, fnMove, aRegion, bInReadOnly); + if( 0 == nFndRet || + ( pFndRing && + *pFndRing->GetPoint() == *pCurrentCursor->GetPoint() && + *pFndRing->GetMark() == *pCurrentCursor->GetMark() )) + break; if( !( FIND_NO_RING & nFndRet )) { // #i24084# - create ring similar to the one in CreateCursor @@ -2372,7 +2385,8 @@ SwCursor* SwTableCursor::MakeBoxSels( SwCursor* pCurrentCursor ) pPos->nContent.Assign( const_cast<SwContentNode*>(static_cast<const SwContentNode*>(pNd)), 0 ); aIdx.Assign( *pSttNd->EndOfSectionNode(), - 1 ); - if( !( pNd = &aIdx.GetNode())->IsContentNode() ) + pNd = &aIdx.GetNode(); + if( !pNd->IsContentNode() ) pNd = SwNodes::GoPrevSection( &aIdx, true, false ); pPos = pCur->GetPoint(); @@ -2417,7 +2431,8 @@ SwCursor* SwTableCursor::MakeBoxSels( SwCursor* pCurrentCursor ) SwPosition* pPos = pNew->GetPoint(); pPos->nNode.Assign( *pSttNd->EndOfSectionNode(), - 1 ); - if( !( pNd = &pPos->nNode.GetNode())->IsContentNode() ) + pNd = &pPos->nNode.GetNode(); + if( !pNd->IsContentNode() ) pNd = SwNodes::GoPrevSection( &pPos->nNode, true, false ); pPos->nContent.Assign(static_cast<SwContentNode*>(pNd), pNd ? static_cast<SwContentNode*>(pNd)->Len() : 0); diff --git a/sw/source/core/crsr/trvlcol.cxx b/sw/source/core/crsr/trvlcol.cxx index b05bf7c503cb..8e1de5ba8ab5 100644 --- a/sw/source/core/crsr/trvlcol.cxx +++ b/sw/source/core/crsr/trvlcol.cxx @@ -65,34 +65,36 @@ SwContentFrame* GetColumnEnd( const SwLayoutFrame* pColFrame ) void SwCursorShell::MoveColumn( SwWhichColumn fnWhichCol, SwPosColumn fnPosCol ) { - if( !m_pTableCursor ) + if( m_pTableCursor ) + return; + SwLayoutFrame* pLayFrame = GetCurrFrame()->GetUpper(); + if( !pLayFrame ) + return; + pLayFrame = (*fnWhichCol)( pLayFrame ); + if( pLayFrame ) { - SwLayoutFrame* pLayFrame = GetCurrFrame()->GetUpper(); - if( pLayFrame && nullptr != ( pLayFrame = (*fnWhichCol)( pLayFrame )) ) + SwContentFrame* pCnt = (*fnPosCol)( pLayFrame ); + if( pCnt ) { - SwContentFrame* pCnt = (*fnPosCol)( pLayFrame ); - if( pCnt ) - { - SET_CURR_SHELL( this ); - SwCallLink aLk( *this ); // watch Cursor-Moves; call Link if needed - SwCursorSaveState aSaveState( *m_pCurrentCursor ); + SET_CURR_SHELL( this ); + SwCallLink aLk( *this ); // watch Cursor-Moves; call Link if needed + SwCursorSaveState aSaveState( *m_pCurrentCursor ); - pCnt->Calc(GetOut()); + pCnt->Calc(GetOut()); - Point aPt( pCnt->getFrameArea().Pos() + pCnt->getFramePrintArea().Pos() ); - if( fnPosCol == GetColumnEnd ) - { - aPt.setX(aPt.getX() + pCnt->getFramePrintArea().Width()); - aPt.setY(aPt.getY() + pCnt->getFramePrintArea().Height()); - } + Point aPt( pCnt->getFrameArea().Pos() + pCnt->getFramePrintArea().Pos() ); + if( fnPosCol == GetColumnEnd ) + { + aPt.setX(aPt.getX() + pCnt->getFramePrintArea().Width()); + aPt.setY(aPt.getY() + pCnt->getFramePrintArea().Height()); + } - pCnt->GetModelPositionForViewPoint( m_pCurrentCursor->GetPoint(), aPt ); + pCnt->GetModelPositionForViewPoint( m_pCurrentCursor->GetPoint(), aPt ); - if( !m_pCurrentCursor->IsInProtectTable( true ) && - !m_pCurrentCursor->IsSelOvr() ) - { - UpdateCursor(); - } + if( !m_pCurrentCursor->IsInProtectTable( true ) && + !m_pCurrentCursor->IsSelOvr() ) + { + UpdateCursor(); } } } diff --git a/sw/source/core/crsr/trvlfnfl.cxx b/sw/source/core/crsr/trvlfnfl.cxx index 155e37187f81..e0eb9ca48711 100644 --- a/sw/source/core/crsr/trvlfnfl.cxx +++ b/sw/source/core/crsr/trvlfnfl.cxx @@ -94,9 +94,13 @@ bool SwCursorShell::GotoFootnoteText() GetCursor_()->Start(), &tmp); const SwFootnoteBossFrame* pFootnoteBoss; bool bSkip = pFrame && pFrame->IsInFootnote(); - while( pFrame && nullptr != ( pFootnoteBoss = pFrame->FindFootnoteBossFrame() ) ) + while( pFrame ) { - if( nullptr != ( pFrame = pFootnoteBoss->FindFootnoteCont() ) ) + pFootnoteBoss = pFrame->FindFootnoteBossFrame(); + if (!pFootnoteBoss) + break; + pFrame = pFootnoteBoss->FindFootnoteCont(); + if( pFrame ) { if( bSkip ) bSkip = false; @@ -134,10 +138,11 @@ bool SwCursor::GotoFootnoteAnchor() if( pSttNd ) { // search in all footnotes in document for this StartIndex - const SwTextFootnote* pTextFootnote; const SwFootnoteIdxs& rFootnoteArr = pSttNd->GetDoc()->GetFootnoteIdxs(); for( size_t n = 0; n < rFootnoteArr.size(); ++n ) - if( nullptr != ( pTextFootnote = rFootnoteArr[ n ])->GetStartNode() && + { + const SwTextFootnote* pTextFootnote = rFootnoteArr[ n ]; + if( nullptr != pTextFootnote->GetStartNode() && pSttNd == &pTextFootnote->GetStartNode()->GetNode() ) { SwCursorSaveState aSaveState( *this ); @@ -149,6 +154,7 @@ bool SwCursor::GotoFootnoteAnchor() return !IsSelOvr( SwCursorSelOverFlags::CheckNodeSection | SwCursorSelOverFlags::Toggle ); } + } } return false; } diff --git a/sw/source/core/crsr/trvlreg.cxx b/sw/source/core/crsr/trvlreg.cxx index ecec0f16ee85..1648caf8f162 100644 --- a/sw/source/core/crsr/trvlreg.cxx +++ b/sw/source/core/crsr/trvlreg.cxx @@ -40,9 +40,11 @@ bool GotoPrevRegion( SwPaM& rCurrentCursor, SwMoveFnCollection const & fnPosRegi SwNodeIndex aOldIdx = aIdx; sal_uLong nLastNd = rCurrentCursor.GetDoc()->GetNodes().Count() - 1; do { - while( aIdx.GetIndex() && - nullptr == ( pNd = aIdx.GetNode().StartOfSectionNode()->GetSectionNode()) ) + while( aIdx.GetIndex() ) { + pNd = aIdx.GetNode().StartOfSectionNode()->GetSectionNode(); + if (pNd) + break; --aIdx; if ( aIdx == aOldIdx ) { @@ -113,9 +115,11 @@ bool GotoNextRegion( SwPaM& rCurrentCursor, SwMoveFnCollection const & fnPosRegi SwNodeIndex aOldIdx = aIdx; sal_uLong nEndCount = aIdx.GetNode().GetNodes().Count()-1; do { - while( aIdx.GetIndex() < nEndCount && - nullptr == ( pNd = aIdx.GetNode().GetSectionNode()) ) + while( aIdx.GetIndex() < nEndCount ) { + pNd = aIdx.GetNode().GetSectionNode(); + if (pNd) + break; ++aIdx; if ( aIdx == aOldIdx ) { @@ -245,19 +249,19 @@ bool SwCursor::GotoRegion( const OUString& rName ) for( SwSectionFormats::size_type n = rFormats.size(); n; ) { const SwSectionFormat* pFormat = rFormats[ --n ]; - const SwNodeIndex* pIdx = nullptr; - const SwSection* pSect; - if( nullptr != ( pSect = pFormat->GetSection() ) && - pSect->GetSectionName() == rName && - nullptr != ( pIdx = pFormat->GetContent().GetContentIdx() ) && - pIdx->GetNode().GetNodes().IsDocNodes() ) + const SwSection* pSect = pFormat->GetSection(); + if( pSect && pSect->GetSectionName() == rName ) { - // area in normal nodes array - SwCursorSaveState aSaveState( *this ); + const SwNodeIndex* pIdx = pFormat->GetContent().GetContentIdx(); + if( pIdx && pIdx->GetNode().GetNodes().IsDocNodes() ) + { + // area in normal nodes array + SwCursorSaveState aSaveState( *this ); - GetPoint()->nNode = *pIdx; - Move( fnMoveForward, GoInContent ); - bRet = !IsSelOvr(); + GetPoint()->nNode = *pIdx; + Move( fnMoveForward, GoInContent ); + bRet = !IsSelOvr(); + } } } return bRet; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits