sw/inc/IDocumentFieldsAccess.hxx             |    3 +-
 sw/inc/cellatr.hxx                           |   15 +++++++++-
 sw/inc/hintids.hxx                           |    1 
 sw/inc/hints.hxx                             |    2 -
 sw/source/core/attr/cellatr.cxx              |   39 ---------------------------
 sw/source/core/attr/hints.cxx                |    9 +++---
 sw/source/core/doc/DocumentFieldsManager.cxx |   31 ++++++---------------
 sw/source/core/docnode/ndtbl.cxx             |    3 --
 sw/source/core/edit/edtab.cxx                |    3 --
 sw/source/core/inc/DocumentFieldsManager.hxx |    2 -
 sw/source/core/table/swtable.cxx             |    4 --
 sw/source/core/undo/untbl.cxx                |    3 --
 sw/source/core/unocore/unotbl.cxx            |    6 +---
 13 files changed, 39 insertions(+), 82 deletions(-)

New commits:
commit 1bdd92bceb5997d5d0ed27b59734c88f7546a4da
Author:     Bjoern Michaelsen <bjoern.michael...@libreoffice.org>
AuthorDate: Wed Mar 22 23:18:27 2023 +0100
Commit:     Bjoern Michaelsen <bjoern.michael...@libreoffice.org>
CommitDate: Thu Mar 30 21:49:59 2023 +0000

    SwTableFormulaUpdate: SwMsgPoolItem no more
    
    - get rid of legacy call with unused WhichId (TABLEFML_UPDATE)
    - simplify and inlune ChangeSate, by now only handling TBL_CALC
    - simplify params for UpdateTableFields (explictly just one SwTable*)
    
    Change-Id: Ie356c2a17eab0b557efb54719d33e278b887eef5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149591
    Tested-by: Jenkins
    Reviewed-by: Bjoern Michaelsen <bjoern.michael...@libreoffice.org>

diff --git a/sw/inc/IDocumentFieldsAccess.hxx b/sw/inc/IDocumentFieldsAccess.hxx
index c31e6a646ed0..d0bdfe34589b 100644
--- a/sw/inc/IDocumentFieldsAccess.hxx
+++ b/sw/inc/IDocumentFieldsAccess.hxx
@@ -38,6 +38,7 @@ class SwMsgPoolItem;
 class DateTime;
 class SetGetExpField;
 class SwNode;
+class SwTable;
 enum class SwFieldIds : sal_uInt16;
 template <class T> class SwHashTable;
 struct HashStr;
@@ -95,7 +96,7 @@ namespace com::sun::star::uno { class Any; }
 
     virtual void UpdateRefFields() = 0;
 
-    virtual void UpdateTableFields(SfxPoolItem* pHt) = 0;
+    virtual void UpdateTableFields(const SwTable* pTable) = 0;
 
     virtual void UpdateExpFields(SwTextField* pField, bool bUpdateRefFields) = 
0;
 
diff --git a/sw/inc/cellatr.hxx b/sw/inc/cellatr.hxx
index 2d85015a8901..05b1e965ef0b 100644
--- a/sw/inc/cellatr.hxx
+++ b/sw/inc/cellatr.hxx
@@ -26,6 +26,7 @@
 #include "format.hxx"
 #include "hintids.hxx"
 #include "cellfml.hxx"
+#include "node.hxx"
 
 class SwHistory;
 
@@ -75,7 +76,19 @@ public:
 
     void TryBoxNmToPtr();
     void ToSplitMergeBoxNmWithHistory(SwTableFormulaUpdate& rUpdate, 
SwHistory* pHistory);
-    void ChangeState( const SfxPoolItem* pItem );
+    void ChangeState()
+    {
+        if(!m_pDefinedIn)
+            return;
+        // detect table that contains this attribute
+        const SwNode* pNd = GetNodeOfFormula();
+        if(!pNd) // || &pNd->GetNodes() != &pNd->GetDoc().GetNodes())
+            return;
+        const SwTableNode* pTableNd = pNd->FindTableNode();
+        if(pTableNd == nullptr)
+            return;
+        ChgValid(false);
+    }
     void Calc( SwTableCalcPara& rCalcPara, double& rValue );
 };
 
diff --git a/sw/inc/hintids.hxx b/sw/inc/hintids.hxx
index 330b0042b3a9..a8418566f5ec 100644
--- a/sw/inc/hintids.hxx
+++ b/sw/inc/hintids.hxx
@@ -433,7 +433,6 @@ constexpr TypedWhichId<SwFormatChg> RES_FMT_CHG(168);
 constexpr TypedWhichId<SwAttrSetChg> RES_ATTRSET_CHG(169);
 constexpr TypedWhichId<SwUpdateAttr> RES_UPDATE_ATTR(170);
 constexpr TypedWhichId<SwPtrMsgPoolItem> RES_REFMARKFLD_UPDATE(171);
-constexpr TypedWhichId<SwTableFormulaUpdate> RES_TABLEFML_UPDATE(173);
 constexpr TypedWhichId<SwMsgPoolItem> RES_UPDATEDDETBL(174);
 constexpr TypedWhichId<SwMsgPoolItem> RES_TBLHEADLINECHG(175);
 constexpr TypedWhichId<SwAutoFormatGetDocNode> RES_AUTOFMT_DOCNODE(176);
diff --git a/sw/inc/hints.hxx b/sw/inc/hints.hxx
index 2b870373dcf1..6b993795c058 100644
--- a/sw/inc/hints.hxx
+++ b/sw/inc/hints.hxx
@@ -299,7 +299,7 @@ enum TableFormulaUpdateFlags { TBL_CALC = 0,
                          TBL_MERGETBL,
                          TBL_SPLITTBL
                        };
-class SwTableFormulaUpdate final : public SwMsgPoolItem
+class SwTableFormulaUpdate final
 {
 public:
     const SwTable* m_pTable;         ///< Pointer to the current table
diff --git a/sw/source/core/attr/cellatr.cxx b/sw/source/core/attr/cellatr.cxx
index 1c445bb03067..9023cca2f793 100644
--- a/sw/source/core/attr/cellatr.cxx
+++ b/sw/source/core/attr/cellatr.cxx
@@ -126,45 +126,6 @@ void 
SwTableBoxFormula::ToSplitMergeBoxNmWithHistory(SwTableFormulaUpdate& rUpda
             pNd->FindTableBoxStartNode()->GetIndex());
     }
 }
-void SwTableBoxFormula::ChangeState( const SfxPoolItem* pItem )
-{
-    if( !m_pDefinedIn )
-        return ;
-
-    SwTableFormulaUpdate* pUpdateField;
-    if( !pItem || RES_TABLEFML_UPDATE != pItem->Which() )
-    {
-        // reset value flag
-        ChgValid( false );
-        return ;
-    }
-
-    pUpdateField = const_cast<SwTableFormulaUpdate*>(static_cast<const 
SwTableFormulaUpdate*>(pItem));
-
-    // detect table that contains this attribute
-    const SwTableNode* pTableNd;
-    const SwNode* pNd = GetNodeOfFormula();
-    if (!pNd || &pNd->GetNodes() != &pNd->GetDoc().GetNodes())
-        return;
-    pTableNd = pNd->FindTableNode();
-    if( pTableNd == nullptr )
-        return;
-
-    switch( pUpdateField->m_eFlags )
-    {
-    case TBL_CALC:
-        // reset value flag
-        ChgValid( false );
-        break;
-    case TBL_BOXPTR:
-    case TBL_RELBOXNAME:
-    case TBL_BOXNAME:
-    case TBL_SPLITTBL:
-    case TBL_MERGETBL:
-        assert(false); // PtrToBoxNm, ToRelBoxNm and BoxNmToPtr are all public 
-- use just them directly
-        break;
-    }
-}
 
 void SwTableBoxFormula::Calc( SwTableCalcPara& rCalcPara, double& rValue )
 {
diff --git a/sw/source/core/attr/hints.cxx b/sw/source/core/attr/hints.cxx
index f1e41491a726..3da0c5939283 100644
--- a/sw/source/core/attr/hints.cxx
+++ b/sw/source/core/attr/hints.cxx
@@ -81,10 +81,11 @@ SwUpdateAttr::SwUpdateAttr( sal_Int32 nS, sal_Int32 nE, 
sal_uInt16 nW, std::vect
 {
 }
 
-SwTableFormulaUpdate::SwTableFormulaUpdate( const SwTable* pNewTable )
-    : SwMsgPoolItem( RES_TABLEFML_UPDATE ),
-    m_pTable( pNewTable ), m_pHistory( nullptr ), m_nSplitLine( USHRT_MAX ),
-    m_eFlags( TBL_CALC )
+SwTableFormulaUpdate::SwTableFormulaUpdate(const SwTable* pNewTable)
+    : m_pTable(pNewTable)
+    , m_pHistory(nullptr)
+    , m_nSplitLine(USHRT_MAX)
+    , m_eFlags(TBL_CALC)
 {
     m_aData.pDelTable = nullptr;
     m_bModified = m_bBehindSplitLine = false;
diff --git a/sw/source/core/doc/DocumentFieldsManager.cxx 
b/sw/source/core/doc/DocumentFieldsManager.cxx
index 788efe790ecb..cff26818dd34 100644
--- a/sw/source/core/doc/DocumentFieldsManager.cxx
+++ b/sw/source/core/doc/DocumentFieldsManager.cxx
@@ -533,12 +533,10 @@ bool DocumentFieldsManager::UpdateField(SwTextField * 
pDstTextField, SwField & r
                     SwDoc::IsIdxInTable(aTableNdIdx);
                 if( pTableNd )
                 {
-                    SwTableFormulaUpdate aTableUpdate( &pTableNd->
-                                                 GetTable() );
                     if (bUpdateFields)
-                        UpdateTableFields( &aTableUpdate );
+                        UpdateTableFields(&pTableNd->GetTable());
                     else
-                        
pNewField->GetTyp()->CallSwClientNotify(sw::LegacyModifyHint(nullptr, 
&aTableUpdate));
+                        
pNewField->GetTyp()->CallSwClientNotify(sw::LegacyModifyHint(nullptr, nullptr));
 
                     if (! bUpdateFields)
                         bTableSelBreak = true;
@@ -596,15 +594,10 @@ void DocumentFieldsManager::UpdateRefFields()
             
static_cast<SwGetRefFieldType*>(pFieldType.get())->UpdateGetReferences();
 }
 
-void DocumentFieldsManager::UpdateTableFields( SfxPoolItem* pHt )
+void DocumentFieldsManager::UpdateTableFields(const SwTable* pTable)
 {
-    SwTableFormulaUpdate* pUpdateField = nullptr;
-    if(pHt && RES_TABLEFML_UPDATE == pHt->Which())
-        pUpdateField = static_cast<SwTableFormulaUpdate*>(pHt);
-    assert(!pHt || pUpdateField);
-    assert(!pUpdateField || pUpdateField->m_eFlags == TBL_CALC);
     auto pFieldType = GetFieldType( SwFieldIds::Table, OUString(), false );
-    if(pFieldType && (!pUpdateField || pUpdateField->m_eFlags == TBL_CALC))
+    if(pFieldType)
     {
         std::vector<SwFormatField*> vFields;
         pFieldType->GatherFields(vFields);
@@ -616,8 +609,8 @@ void DocumentFieldsManager::UpdateTableFields( SfxPoolItem* 
pHt )
             // re-set the value flag
             // JP 17.06.96: internal representation of all formulas
             //              (reference to other table!!!)
-            if(pUpdateField && nsSwExtendedSubType::SUB_CMD & 
pField->GetSubType())
-                pField->PtrToBoxNm(pUpdateField->m_pTable);
+            if(pTable && nsSwExtendedSubType::SUB_CMD & pField->GetSubType())
+                pField->PtrToBoxNm(pTable);
             else
                 // reset the value flag for all
                 pField->ChgValid(false);
@@ -628,7 +621,7 @@ void DocumentFieldsManager::UpdateTableFields( SfxPoolItem* 
pHt )
     {
         auto pBoxFormula = 
const_cast<SwTableBoxFormula*>(pItem->DynamicWhichCast(RES_BOXATR_FORMULA));
         if(pBoxFormula && pBoxFormula->GetDefinedIn())
-            pBoxFormula->ChangeState(pHt);
+            pBoxFormula->ChangeState();
     }
 
     SwRootFrame const* pLayout(nullptr);
@@ -638,10 +631,6 @@ void DocumentFieldsManager::UpdateTableFields( 
SfxPoolItem* pHt )
         pLayout = pLay;
     }
 
-    // all fields/boxes are now invalid, so we can start to calculate
-    if(pHt && pUpdateField->m_eFlags != TBL_CALC)
-        return;
-
     std::optional<SwCalc> oCalc;
 
     if( pFieldType )
@@ -668,7 +657,7 @@ void DocumentFieldsManager::UpdateTableFields( SfxPoolItem* 
pHt )
                     continue;
 
                 // if this field is not in the to-be-updated table, skip it
-                if( pHt && &pTableNd->GetTable() != pUpdateField->m_pTable )
+                if(pTable && &pTableNd->GetTable() != pTable)
                     continue;
 
                 if( !oCalc )
@@ -722,7 +711,7 @@ void DocumentFieldsManager::UpdateTableFields( SfxPoolItem* 
pHt )
                 }
                 oCalc->SetCalcError( SwCalcError::NONE );
             }
-            pFormatField->UpdateTextNode(nullptr, pHt);
+            pFormatField->UpdateTextNode(nullptr, nullptr);
         }
     }
 
@@ -736,7 +725,7 @@ void DocumentFieldsManager::UpdateTableFields( SfxPoolItem* 
pHt )
         if(!pBox || !pBox->GetSttNd() || 
!pBox->GetSttNd()->GetNodes().IsDocNodes())
             continue;
         const SwTableNode* pTableNd = pBox->GetSttNd()->FindTableNode();
-        if(pHt && &pTableNd->GetTable() != pUpdateField->m_pTable)
+        if(pTable && &pTableNd->GetTable() != pTable)
             continue;
         double nValue;
         if( !oCalc )
diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx
index b7952080f68c..c405b4bca84a 100644
--- a/sw/source/core/docnode/ndtbl.cxx
+++ b/sw/source/core/docnode/ndtbl.cxx
@@ -4116,8 +4116,7 @@ void SwDoc::ChkBoxNumFormat( SwTableBox& rBox, bool 
bCallUpdate )
     const SwTableNode* pTableNd = rBox.GetSttNd()->FindTableNode();
     if( bCallUpdate )
     {
-        SwTableFormulaUpdate aTableUpdate( &pTableNd->GetTable() );
-        getIDocumentFieldsAccess().UpdateTableFields( &aTableUpdate );
+        getIDocumentFieldsAccess().UpdateTableFields(&pTableNd->GetTable());
 
         // TL_CHART2: update charts (when cursor leaves cell and
         // automatic update is enabled)
diff --git a/sw/source/core/edit/edtab.cxx b/sw/source/core/edit/edtab.cxx
index ed653b298896..303149770208 100644
--- a/sw/source/core/edit/edtab.cxx
+++ b/sw/source/core/edit/edtab.cxx
@@ -262,8 +262,7 @@ void SwEditShell::UpdateTable()
         if( DoesUndo() )
             StartUndo();
         EndAllTableBoxEdit();
-        SwTableFormulaUpdate aTableUpdate( &pTableNd->GetTable() );
-        GetDoc()->getIDocumentFieldsAccess().UpdateTableFields( &aTableUpdate 
);
+        
GetDoc()->getIDocumentFieldsAccess().UpdateTableFields(&pTableNd->GetTable());
         if( DoesUndo() )
             EndUndo();
         EndAllAction();
diff --git a/sw/source/core/inc/DocumentFieldsManager.hxx 
b/sw/source/core/inc/DocumentFieldsManager.hxx
index 0f1aede584cb..f7a8f2757fc0 100644
--- a/sw/source/core/inc/DocumentFieldsManager.hxx
+++ b/sw/source/core/inc/DocumentFieldsManager.hxx
@@ -45,7 +45,7 @@ public:
     virtual void PutValueToField(const SwPosition & rPos, const css::uno::Any& 
rVal, sal_uInt16 nWhich) override;
     virtual bool UpdateField(SwTextField * rDstFormatField, SwField & 
rSrcField, const SwMsgPoolItem * pMsgHint, bool bUpdateTableFields) override;
     virtual void UpdateRefFields() override;
-    virtual void UpdateTableFields(SfxPoolItem* pHt) override;
+    virtual void UpdateTableFields(const SwTable* pTable) override;
     virtual void UpdateExpFields(SwTextField* pField, bool bUpdateRefFields) 
override;
     virtual void UpdateUsrFields() override;
     virtual void UpdatePageFields(const SwTwips) override;
diff --git a/sw/source/core/table/swtable.cxx b/sw/source/core/table/swtable.cxx
index 61811d546906..83bd94623526 100644
--- a/sw/source/core/table/swtable.cxx
+++ b/sw/source/core/table/swtable.cxx
@@ -1708,8 +1708,6 @@ void SwTable::UpdateFields(TableFormulaUpdateFlags eFlags)
         }
     }
     // process all table box formulas
-    SwTableFormulaUpdate aHint(this);
-    aHint.m_eFlags = eFlags;
     for(const SfxPoolItem* pItem : 
pDoc->GetAttrPool().GetItemSurrogates(RES_BOXATR_FORMULA))
     {
         auto pBoxFormula = 
const_cast<SwTableBoxFormula*>(pItem->DynamicWhichCast(RES_BOXATR_FORMULA));
@@ -1718,7 +1716,7 @@ void SwTable::UpdateFields(TableFormulaUpdateFlags eFlags)
             if(eFlags == TBL_BOXPTR)
                 pBoxFormula->TryBoxNmToPtr();
             else
-                pBoxFormula->ChangeState(&aHint);
+                pBoxFormula->ChangeState();
         }
     }
 }
diff --git a/sw/source/core/undo/untbl.cxx b/sw/source/core/undo/untbl.cxx
index 7e9d2614ac02..fffd8e8b4e51 100644
--- a/sw/source/core/undo/untbl.cxx
+++ b/sw/source/core/undo/untbl.cxx
@@ -2292,8 +2292,7 @@ void SwUndoTableNumFormat::RedoImpl(::sw::UndoRedoContext 
& rContext)
     if( m_bNewFormula )
     {
         // No matter what was set, an update of the table is always a good idea
-        SwTableFormulaUpdate aTableUpdate( 
&pSttNd->FindTableNode()->GetTable() );
-        rDoc.getIDocumentFieldsAccess().UpdateTableFields( &aTableUpdate );
+        
rDoc.getIDocumentFieldsAccess().UpdateTableFields(&pSttNd->FindTableNode()->GetTable());
     }
 
     if( !pNd->IsContentNode() )
diff --git a/sw/source/core/unocore/unotbl.cxx 
b/sw/source/core/unocore/unotbl.cxx
index 5aa0297e661d..15eba1dfd116 100644
--- a/sw/source/core/unocore/unotbl.cxx
+++ b/sw/source/core/unocore/unotbl.cxx
@@ -710,8 +710,7 @@ void sw_setValue( SwXCell &rCell, double nVal )
     aSet.Put(aVal);
     pDoc->SetTableBoxFormulaAttrs( *rCell.m_pBox, aSet );
     // update table
-    SwTableFormulaUpdate aTableUpdate( SwTable::FindTable( 
rCell.GetFrameFormat() ));
-    pDoc->getIDocumentFieldsAccess().UpdateTableFields( &aTableUpdate );
+    
pDoc->getIDocumentFieldsAccess().UpdateTableFields(SwTable::FindTable(rCell.GetFrameFormat()));
 }
 
 
@@ -853,8 +852,7 @@ void SwXCell::setFormula(const OUString& rFormula)
     aSet.Put(aFormula);
     GetDoc()->SetTableBoxFormulaAttrs( *m_pBox, aSet );
     // update table
-    SwTableFormulaUpdate aTableUpdate( SwTable::FindTable( GetFrameFormat() ));
-    pMyDoc->getIDocumentFieldsAccess().UpdateTableFields( &aTableUpdate );
+    
pMyDoc->getIDocumentFieldsAccess().UpdateTableFields(SwTable::FindTable(GetFrameFormat()));
 }
 
 double SwXCell::getValue()

Reply via email to