From 49a32d5567a07ce0deb901a491a9cedb3cd3bbfc Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Wed, 31 Jul 2019 18:01:30 +0200 Subject: tdf#126138 sw: disambiguate SwTabFrame::FindLastContent() Most callers don't actually care about the SwContentFrame but want its upper; introduce FindLastContentOrTable() for those. Last frame can be a SwTabFrame quite simply if you delete the trailing paragraph with Ctrl+Shift+Del from the last cell of nested table. Change-Id: Ieab9e1ff2a5fa7b75d84dfc3cc4d17c867751b0c Reviewed-on: https://gerrit.libreoffice.org/76759 Tested-by: Jenkins Reviewed-by: Michael Stahl --- sw/source/core/layout/findfrm.cxx | 4 ++-- sw/source/core/layout/flowfrm.cxx | 2 +- sw/source/core/layout/frmtool.cxx | 14 +++++++++----- sw/source/core/layout/sectfrm.cxx | 2 +- sw/source/core/layout/tabfrm.cxx | 26 +++++++++++++++----------- 5 files changed, 28 insertions(+), 20 deletions(-) (limited to 'sw/source/core/layout') diff --git a/sw/source/core/layout/findfrm.cxx b/sw/source/core/layout/findfrm.cxx index 786c7627d7c9..4bd1a5dde202 100644 --- a/sw/source/core/layout/findfrm.cxx +++ b/sw/source/core/layout/findfrm.cxx @@ -782,7 +782,7 @@ SwFrame *SwFrame::FindNext_() if ( static_cast(this)->GetFollow() ) return static_cast(this)->GetFollow(); - pThis = static_cast(this)->FindLastContent(); + pThis = static_cast(this)->FindLastContentOrTable(); if ( !pThis ) pThis = this; bIgnoreTab = true; @@ -912,7 +912,7 @@ SwContentFrame *SwFrame::FindNextCnt_( const bool _bInSameFootnote ) if( pThis ) return static_cast(pThis); } - pThis = static_cast(this)->FindLastContent(); + pThis = static_cast(this)->FindLastContentOrTable(); if ( !pThis ) return nullptr; } diff --git a/sw/source/core/layout/flowfrm.cxx b/sw/source/core/layout/flowfrm.cxx index 20ba1d50420d..b7461e038356 100644 --- a/sw/source/core/layout/flowfrm.cxx +++ b/sw/source/core/layout/flowfrm.cxx @@ -916,7 +916,7 @@ SwLayoutFrame *SwFrame::GetNextLeaf( MakePageType eMakePage ) SwLayoutFrame *pLayLeaf = nullptr; if ( IsTabFrame() ) { - SwContentFrame* pTmp = static_cast(this)->FindLastContent(); + SwFrame *const pTmp = static_cast(this)->FindLastContentOrTable(); if ( pTmp ) pLayLeaf = pTmp->GetUpper(); } diff --git a/sw/source/core/layout/frmtool.cxx b/sw/source/core/layout/frmtool.cxx index 416037b25fbd..3a762e6ce885 100644 --- a/sw/source/core/layout/frmtool.cxx +++ b/sw/source/core/layout/frmtool.cxx @@ -3706,11 +3706,15 @@ const SwContentFrame* GetCellContent( const SwLayoutFrame& rCell ) const SwTabFrame* pTmpTab = pContent->FindTabFrame(); if ( pTmpTab != pTab ) { - pContent = pTmpTab->FindLastContent(); - if ( pContent ) - - pContent = pContent->FindNextCnt(); - + SwFrame const*const pTmp = pTmpTab->FindLastContentOrTable(); + if (pTmp) + { + pContent = pTmp->FindNextCnt(); + } + else + { + pContent = nullptr; + } } else break; diff --git a/sw/source/core/layout/sectfrm.cxx b/sw/source/core/layout/sectfrm.cxx index 58d0c7d4d5ad..d10d90aeee65 100644 --- a/sw/source/core/layout/sectfrm.cxx +++ b/sw/source/core/layout/sectfrm.cxx @@ -1667,7 +1667,7 @@ SwLayoutFrame *SwFrame::GetNextSctLeaf( MakePageType eMakePage ) pLayLeaf = nullptr; else if( IsTabFrame() ) { - SwContentFrame* pTmpCnt = static_cast(this)->FindLastContent(); + SwFrame *const pTmpCnt = static_cast(this)->FindLastContentOrTable(); pLayLeaf = pTmpCnt ? pTmpCnt->GetUpper() : nullptr; } else if (pCellLeaf && CanContainSplitSection(this)) diff --git a/sw/source/core/layout/tabfrm.cxx b/sw/source/core/layout/tabfrm.cxx index 76a064017ad8..960bb9462007 100644 --- a/sw/source/core/layout/tabfrm.cxx +++ b/sw/source/core/layout/tabfrm.cxx @@ -3336,7 +3336,7 @@ bool SwTabFrame::GetInfo( SfxPoolItem &rHint ) const return true; } -SwContentFrame *SwTabFrame::FindLastContent() +SwFrame *SwTabFrame::FindLastContentOrTable() { SwFrame *pRet = m_pLower; @@ -3398,19 +3398,23 @@ SwContentFrame *SwTabFrame::FindLastContent() while ( pRet->GetNext() ) pRet = pRet->GetNext(); - while (pRet && pRet->IsTabFrame()) // possibly there's only tables here! - { // tdf#126138 skip table, don't look inside - // TODO this is actually not ideal, e.g. SwFrame::FindNext_() might - // -if there's a table at the end- return a lower frame inside that - // table instead of the "next" one... probably this function should - // really return SwFrame* to be able to return a SwTabFrame? - pRet = pRet->GetPrev(); - } - - if (pRet && pRet->IsSctFrame()) + if (pRet->IsSctFrame()) pRet = static_cast(pRet)->FindLastContent(); } + assert(pRet == nullptr || dynamic_cast(pRet) || dynamic_cast(pRet)); + return pRet; +} + +SwContentFrame *SwTabFrame::FindLastContent() +{ + SwFrame * pRet(FindLastContentOrTable()); + + while (pRet && pRet->IsTabFrame()) // possibly there's only tables here! + { // tdf#126138 skip table, don't look inside + pRet = pRet->GetPrev(); + } + assert(pRet == nullptr || dynamic_cast(pRet)); return static_cast(pRet); } -- cgit v1.2.3