sw/inc/swtblfmt.hxx              |    3 +++
 sw/source/core/attr/cellatr.cxx  |   16 ++++------------
 sw/source/core/table/swtable.cxx |   16 ++++++++++------
 sw/source/core/undo/unattr.cxx   |    8 ++++----
 4 files changed, 21 insertions(+), 22 deletions(-)

New commits:
commit 422150be82ed892ecf31a8ab76c1d1ca801dcda8
Author:     Bjoern Michaelsen <bjoern.michael...@libreoffice.org>
AuthorDate: Sat Aug 7 12:08:07 2021 +0200
Commit:     Bjoern Michaelsen <bjoern.michael...@libreoffice.org>
CommitDate: Thu Aug 12 13:10:12 2021 +0200

    Capsulate TableBox<>TableBoxFormat relation in a function
    
    Change-Id: I731e9bae04147f7453721661228e78a16ed585db
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120160
    Tested-by: Jenkins
    Reviewed-by: Bjoern Michaelsen <bjoern.michael...@libreoffice.org>

diff --git a/sw/inc/swtblfmt.hxx b/sw/inc/swtblfmt.hxx
index e61049919df1..a8ba7d31f630 100644
--- a/sw/inc/swtblfmt.hxx
+++ b/sw/inc/swtblfmt.hxx
@@ -60,6 +60,9 @@ class SAL_DLLPUBLIC_RTTI SwTableBoxFormat final: public 
SwFrameFormat
 
 public:
     virtual bool supportsFullDrawingLayerFillAttributeSet() const override;
+    SwTableBox* GetTableBox();
+    const SwTableBox* GetTableBox() const
+            { return const_cast<SwTableBoxFormat*>(this)->GetTableBox(); };
 };
 
 #endif
diff --git a/sw/source/core/attr/cellatr.cxx b/sw/source/core/attr/cellatr.cxx
index 09003a7fff64..3fdfb0772c6a 100644
--- a/sw/source/core/attr/cellatr.cxx
+++ b/sw/source/core/attr/cellatr.cxx
@@ -84,22 +84,14 @@ SwTableBoxFormula* SwTableBoxFormula::Clone( SfxItemPool* ) 
const
 */
 const SwNode* SwTableBoxFormula::GetNodeOfFormula() const
 {
-    const SwNode* pRet = nullptr;
-    if( m_pDefinedIn )
-    {
-        SwTableBox* pBox = SwIterator<SwTableBox,sw::BroadcastingModify>( 
*m_pDefinedIn ).First();
-        if( pBox )
-            pRet = pBox->GetSttNd();
-    }
-    return pRet;
+    auto pTableBox = GetTableBox();
+    return pTableBox ? pTableBox->GetSttNd() : nullptr;
 }
 
 SwTableBox* SwTableBoxFormula::GetTableBox()
 {
-    SwTableBox* pBox = nullptr;
-    if( m_pDefinedIn )
-        pBox = SwIterator<SwTableBox,sw::BroadcastingModify>( *m_pDefinedIn 
).First();
-    return pBox;
+    assert(!m_pDefinedIn || dynamic_cast<SwTableBoxFormat*>(m_pDefinedIn));
+    return m_pDefinedIn ? 
static_cast<SwTableBoxFormat*>(m_pDefinedIn)->GetTableBox() : nullptr;
 }
 
 void SwTableBoxFormula::ChangeState( const SfxPoolItem* pItem )
diff --git a/sw/source/core/table/swtable.cxx b/sw/source/core/table/swtable.cxx
index 5f633ef65546..3d595e2d614d 100644
--- a/sw/source/core/table/swtable.cxx
+++ b/sw/source/core/table/swtable.cxx
@@ -2273,6 +2273,15 @@ void SwTableBoxFormat::BoxAttributeChanged(SwTableBox& 
rBox, const SwTableBoxNum
         ChgNumToText(rBox, nNewFormat);
 }
 
+SwTableBox* SwTableBoxFormat::SwTableBoxFormat::GetTableBox()
+{
+    SwIterator<SwTableBox,SwFormat> aIter(*this);
+    auto pBox = aIter.First();
+    SAL_INFO_IF(!pBox, "sw.core", "no box found at format");
+    SAL_WARN_IF(pBox && aIter.Next(), "sw.core", "more than one box found at 
format");
+    return pBox;
+}
+
 // for detection of modifications (mainly TableBoxAttribute)
 void SwTableBoxFormat::SwClientNotify(const SwModify& rMod, const SfxHint& 
rHint)
 {
@@ -2321,12 +2330,7 @@ void SwTableBoxFormat::SwClientNotify(const SwModify& 
rMod, const SfxHint& rHint
            SfxItemState::SET == GetItemState(RES_BOXATR_VALUE, false) ||
            SfxItemState::SET == GetItemState(RES_BOXATR_FORMULA, false) )
         {
-            // fetch the box
-            SwIterator<SwTableBox,SwFormat> aIter(*this);
-            SwTableBox* pBox = aIter.First();
-            SAL_INFO_IF(!pBox, "sw.core", "no box found at format");
-            SAL_WARN_IF(pBox && aIter.Next(), "sw.core", "more than one box 
found at format");
-            if(pBox)
+            if(auto pBox = GetTableBox())
                 BoxAttributeChanged(*pBox, pNewFormat, pNewFormula, pNewVal, 
nOldFormat);
         }
     }
diff --git a/sw/source/core/undo/unattr.cxx b/sw/source/core/undo/unattr.cxx
index cbd9fe52cd99..5329f1c00c59 100644
--- a/sw/source/core/undo/unattr.cxx
+++ b/sw/source/core/undo/unattr.cxx
@@ -141,11 +141,11 @@ void SwUndoFormatAttr::Init( const SwFormat & rFormat )
             }
         } else if (dynamic_cast<const SwSectionFormat*>(&rFormat)) {
             m_nNodeIndex = rFormat.GetContent().GetContentIdx()->GetIndex();
-        } else if ( dynamic_cast< const SwTableBoxFormat* >( &rFormat ) !=  
nullptr ) {
-            SwTableBox * pTableBox = SwIterator<SwTableBox,SwFormat>( rFormat 
).First();
-            if ( pTableBox ) {
+        } else if(auto pBoxFormat = dynamic_cast<const 
SwTableBoxFormat*>(&rFormat))
+        {
+            auto pTableBox = pBoxFormat->GetTableBox();
+            if(pTableBox)
                 m_nNodeIndex = pTableBox->GetSttIdx();
-            }
         }
     }
 }

Reply via email to