[Libreoffice-commits] core.git: 2 commits - sw/source

Michael Stahl (via logerrit) logerrit at kemper.freedesktop.org
Thu Aug 1 09:01:29 UTC 2019


 sw/source/core/docnode/ndtbl1.cxx |    2 +-
 sw/source/core/frmedt/tblsel.cxx  |    6 +++---
 sw/source/core/inc/tabfrm.hxx     |    7 +++++++
 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  |   18 ++++++++++++++++--
 8 files changed, 40 insertions(+), 15 deletions(-)

New commits:
commit 49a32d5567a07ce0deb901a491a9cedb3cd3bbfc
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Wed Jul 31 18:01:30 2019 +0200
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Thu Aug 1 11:00:55 2019 +0200

    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 <Michael.Stahl at cib.de>

diff --git a/sw/source/core/docnode/ndtbl1.cxx b/sw/source/core/docnode/ndtbl1.cxx
index 9781ccd87911..33832c265ef4 100644
--- a/sw/source/core/docnode/ndtbl1.cxx
+++ b/sw/source/core/docnode/ndtbl1.cxx
@@ -1502,7 +1502,7 @@ void SwDoc::AdjustCellWidth( const SwCursor& rCursor,
     // It's more robust if we calculate the minimum values for the whole Table
     const SwTabFrame *pTab = pStart->ImplFindTabFrame();
     pStart = const_cast<SwLayoutFrame*>(static_cast<SwLayoutFrame const *>(pTab->FirstCell()));
-    pEnd   = const_cast<SwLayoutFrame*>(pTab->FindLastContent()->GetUpper());
+    pEnd   = const_cast<SwLayoutFrame*>(pTab->FindLastContentOrTable()->GetUpper());
     while( !pEnd->IsCellFrame() )
         pEnd = pEnd->GetUpper();
     ::lcl_CalcColValues( aMins, aTabCols, pStart, pEnd, false, /*bColumnWidth=*/true );
diff --git a/sw/source/core/frmedt/tblsel.cxx b/sw/source/core/frmedt/tblsel.cxx
index 11c516b9b0b6..52b3551b2eb5 100644
--- a/sw/source/core/frmedt/tblsel.cxx
+++ b/sw/source/core/frmedt/tblsel.cxx
@@ -1689,7 +1689,7 @@ static void lcl_FindStartEndCol( const SwLayoutFrame *&rpStart,
         nEX = ::lcl_CalcWish( rpEnd, nWish, nPrtWidth ) + aRectFnSet.GetPrtLeft(*pTab);
     }
 
-    const SwContentFrame* pLastContent = pTab->FindLastContent();
+    SwFrame const*const pLastContent = pTab->FindLastContentOrTable();
     rpEnd = pLastContent ? pLastContent->GetUpper() : nullptr;
     // --> Made code robust. If pTab does not have a lower,
     // we would crash here.
@@ -1745,7 +1745,7 @@ static void lcl_FindStartEndCol( const SwLayoutFrame *&rpStart,
         {
             pTmpTab = static_cast<const SwTabFrame*>(pTmpTab->FindPrev());
             OSL_ENSURE( pTmpTab->IsTabFrame(), "Predecessor of Follow not Master.");
-            rpEnd = pTmpTab->FindLastContent()->GetUpper();
+            rpEnd = pTmpTab->FindLastContentOrTable()->GetUpper();
             while( !rpEnd->IsCellFrame() )
                 rpEnd = rpEnd->GetUpper();
             while ( aRectFnSet.GetLeft(rpEnd->getFrameArea()) > nEX )
@@ -1921,7 +1921,7 @@ void MakeSelUnions( SwSelUnions& rUnions, const SwLayoutFrame *pStart,
                     pFirst = ::lcl_FindNextCellFrame( pFirst );
             }
             const SwLayoutFrame* pLast = nullptr;
-            const SwFrame* pLastContent = pTable->FindLastContent();
+            SwFrame const*const pLastContent = pTable->FindLastContentOrTable();
             if ( pLastContent )
                 pLast = ::lcl_FindCellFrame( pLastContent->GetUpper() );
 
diff --git a/sw/source/core/inc/tabfrm.hxx b/sw/source/core/inc/tabfrm.hxx
index cc57d46d8492..40b9923ba744 100644
--- a/sw/source/core/inc/tabfrm.hxx
+++ b/sw/source/core/inc/tabfrm.hxx
@@ -136,6 +136,8 @@ public:
     virtual bool Prepare( const PrepareHint ePrep = PREP_CLEAR,
                           const void *pVoid = nullptr, bool bNotify = true ) override;
 
+                 SwFrame *FindLastContentOrTable();
+    inline const SwFrame *FindLastContentOrTable() const;
                  SwContentFrame *FindLastContent();
     inline const SwContentFrame *FindLastContent() const;
 
@@ -228,6 +230,11 @@ public:
     virtual void dumpAsXmlAttributes(xmlTextWriterPtr writer) const override;
 };
 
+inline const SwFrame *SwTabFrame::FindLastContentOrTable() const
+{
+    return const_cast<SwTabFrame*>(this)->FindLastContentOrTable();
+}
+
 inline const SwContentFrame *SwTabFrame::FindLastContent() const
 {
     return const_cast<SwTabFrame*>(this)->FindLastContent();
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<SwTabFrame*>(this)->GetFollow() )
             return static_cast<SwTabFrame*>(this)->GetFollow();
 
-        pThis = static_cast<SwTabFrame*>(this)->FindLastContent();
+        pThis = static_cast<SwTabFrame*>(this)->FindLastContentOrTable();
         if ( !pThis )
             pThis = this;
         bIgnoreTab = true;
@@ -912,7 +912,7 @@ SwContentFrame *SwFrame::FindNextCnt_( const bool _bInSameFootnote )
             if( pThis )
                 return static_cast<SwContentFrame*>(pThis);
         }
-        pThis = static_cast<SwTabFrame*>(this)->FindLastContent();
+        pThis = static_cast<SwTabFrame*>(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<SwTabFrame*>(this)->FindLastContent();
+        SwFrame *const pTmp = static_cast<SwTabFrame*>(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<SwTabFrame*>(this)->FindLastContent();
+        SwFrame *const pTmpCnt = static_cast<SwTabFrame*>(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<SwSectionFrame*>(pRet)->FindLastContent();
     }
 
+    assert(pRet == nullptr || dynamic_cast<SwContentFrame*>(pRet) || dynamic_cast<SwTabFrame*>(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<SwContentFrame*>(pRet));
     return static_cast<SwContentFrame*>(pRet);
 }
commit b93216e8253c984a3ce36a9fc55516aa85f98d5f
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Wed Jul 31 15:16:02 2019 +0200
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Thu Aug 1 11:00:48 2019 +0200

    tdf#126138 sw: invalid static_cast in SwTabFrame::FindLastContent()
    
    Change-Id: I64412f32f1be78a647710e96f0a92cd78921d784
    Reviewed-on: https://gerrit.libreoffice.org/76755
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <Michael.Stahl at cib.de>

diff --git a/sw/source/core/layout/tabfrm.cxx b/sw/source/core/layout/tabfrm.cxx
index 21607647593b..76a064017ad8 100644
--- a/sw/source/core/layout/tabfrm.cxx
+++ b/sw/source/core/layout/tabfrm.cxx
@@ -3398,10 +3398,20 @@ SwContentFrame *SwTabFrame::FindLastContent()
         while ( pRet->GetNext() )
             pRet = pRet->GetNext();
 
-        if( pRet->IsSctFrame() )
+        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())
             pRet = static_cast<SwSectionFrame*>(pRet)->FindLastContent();
     }
 
+    assert(pRet == nullptr || dynamic_cast<SwContentFrame*>(pRet));
     return static_cast<SwContentFrame*>(pRet);
 }
 


More information about the Libreoffice-commits mailing list