sw/inc/swtable.hxx | 1 sw/source/core/doc/DocumentFieldsManager.cxx | 2 - sw/source/core/docnode/ndtbl.cxx | 6 ---- sw/source/core/table/swtable.cxx | 35 +++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 6 deletions(-)
New commits: commit 7c680a96122f7f90114932ef5fdb48328c327268 Author: Bjoern Michaelsen <bjoern.michael...@libreoffice.org> AuthorDate: Tue Mar 7 01:28:56 2023 +0100 Commit: Bjoern Michaelsen <bjoern.michael...@libreoffice.org> CommitDate: Mon Mar 27 06:20:28 2023 +0000 refactor table merge Change-Id: Ia4d5b3fc04cc032a182b4bf7f7570fc250ed8504 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148739 Tested-by: Jenkins Reviewed-by: Bjoern Michaelsen <bjoern.michael...@libreoffice.org> diff --git a/sw/inc/swtable.hxx b/sw/inc/swtable.hxx index 39e54edb2f33..f40059e3c986 100644 --- a/sw/inc/swtable.hxx +++ b/sw/inc/swtable.hxx @@ -365,6 +365,7 @@ public: { UpdateFields(TBL_RELBOXNAME); }; void SwitchFormulasToInternalRepresentation() { UpdateFields(TBL_BOXPTR); } + void Merge(SwTable& rTable, SwHistory* pHistory); void dumpAsXml(xmlTextWriterPtr pWriter) const; }; diff --git a/sw/source/core/doc/DocumentFieldsManager.cxx b/sw/source/core/doc/DocumentFieldsManager.cxx index a395dc352392..3ba8c6314cea 100644 --- a/sw/source/core/doc/DocumentFieldsManager.cxx +++ b/sw/source/core/doc/DocumentFieldsManager.cxx @@ -602,7 +602,7 @@ void DocumentFieldsManager::UpdateTableFields( SfxPoolItem* pHt ) if(pHt && RES_TABLEFML_UPDATE == pHt->Which()) pUpdateField = static_cast<SwTableFormulaUpdate*>(pHt); assert(!pHt || pUpdateField); - assert(!pUpdateField || pUpdateField->m_eFlags == TBL_CALC || pUpdateField->m_eFlags == TBL_SPLITTBL || pUpdateField->m_eFlags == TBL_MERGETBL); + assert(!pUpdateField || pUpdateField->m_eFlags == TBL_CALC || pUpdateField->m_eFlags == TBL_SPLITTBL); auto pFieldType = GetFieldType( SwFieldIds::Table, OUString(), false ); if(pFieldType && (!pUpdateField || pUpdateField->m_eFlags == TBL_CALC)) { diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx index 9f0a89ccad51..4526721a3250 100644 --- a/sw/source/core/docnode/ndtbl.cxx +++ b/sw/source/core/docnode/ndtbl.cxx @@ -3471,11 +3471,7 @@ bool SwDoc::MergeTable( const SwPosition& rPos, bool bWithPrev ) } // Adapt all "TableFormulas" - SwTableFormulaUpdate aMsgHint( &pTableNd->GetTable() ); - aMsgHint.m_aData.pDelTable = &pDelTableNd->GetTable(); - aMsgHint.m_eFlags = TBL_MERGETBL; - aMsgHint.m_pHistory = pHistory.get(); - getIDocumentFieldsAccess().UpdateTableFields( &aMsgHint ); + pTableNd->GetTable().Merge(pDelTableNd->GetTable(), pHistory.get()); // The actual merge bool bRet = rNds.MergeTable( bWithPrev ? *pTableNd : *pDelTableNd, !bWithPrev ); diff --git a/sw/source/core/table/swtable.cxx b/sw/source/core/table/swtable.cxx index 867e76deed1c..96d3b4903255 100644 --- a/sw/source/core/table/swtable.cxx +++ b/sw/source/core/table/swtable.cxx @@ -62,6 +62,7 @@ #include <o3tl/string_view.hxx> #include <svl/numformat.hxx> #include <txtfld.hxx> +#include <rolbck.hxx> #ifdef DBG_UTIL #define CHECK_TABLE(t) (t).CheckConsistency(); @@ -1613,6 +1614,40 @@ bool SwTable::IsDeleted() const return true; } +void SwTable::Merge(SwTable& rTable, SwHistory* pHistory) +{ + SwTableFormulaUpdate aHint(this); + aHint.m_aData.pDelTable = &rTable; + aHint.m_eFlags = TBL_MERGETBL; + aHint.m_pHistory = pHistory; + // process all table box formulas + for(SfxPoolItem* pItem : GetFrameFormat()->GetDoc()->GetAttrPool().GetItemSurrogates(RES_BOXATR_FORMULA)) + { + auto pBoxFormula = pItem->DynamicWhichCast(RES_BOXATR_FORMULA); + assert(pBoxFormula); + if(pBoxFormula->GetDefinedIn()) + { + const SwNode* pNd = pBoxFormula->GetNodeOfFormula(); + // for a history record the unchanged formula is needed + SwTableBoxFormula aCopy(*pBoxFormula); + aHint.m_bModified = false; + pBoxFormula->ToSplitMergeBoxNm(aHint); + + if(aHint.m_bModified) + { + // external rendering + aCopy.PtrToBoxNm(this); + aHint.m_pHistory->Add( + &aCopy, + &aCopy, + pNd->FindTableBoxStartNode()->GetIndex()); + } + } + else + pBoxFormula->ToSplitMergeBoxNm(aHint); + } +} + void SwTable::UpdateFields(TableFormulaUpdateFlags eFlags) { auto pDoc = GetFrameFormat()->GetDoc();