sw/inc/ddefld.hxx | 1 sw/source/core/doc/DocumentFieldsManager.cxx | 6 + sw/source/core/fields/ddefld.cxx | 100 ++++++++++++++------------- 3 files changed, 57 insertions(+), 50 deletions(-)
New commits: commit cae107bab822acc198569750ae5b9a272f7ae996 Author: Bjoern Michaelsen <bjoern.michael...@libreoffice.org> AuthorDate: Mon Oct 25 00:52:32 2021 +0200 Commit: Bjoern Michaelsen <bjoern.michael...@libreoffice.org> CommitDate: Fri Oct 29 02:59:36 2021 +0200 consolidate DDE updates in FieldType Change-Id: I70243dad4cd62ab1f601d010e0bcf441831ec556 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124130 Reviewed-by: Michael Stahl <michael.st...@allotropia.de> Tested-by: Jenkins diff --git a/sw/inc/ddefld.hxx b/sw/inc/ddefld.hxx index a9ca4db81b52..ccb72ff25b24 100644 --- a/sw/inc/ddefld.hxx +++ b/sw/inc/ddefld.hxx @@ -99,6 +99,7 @@ public: void DecRefCnt() { if( !--m_nRefCount && m_pDoc ) RefCntChgd(); } void SetCRLFDelFlag( bool bFlag ) { m_bCRLFFlag = bFlag; } + void UpdateDDE(const bool bNotifyShells = true); }; // DDE-field diff --git a/sw/source/core/doc/DocumentFieldsManager.cxx b/sw/source/core/doc/DocumentFieldsManager.cxx index b15e043aa795..530f4ea22bec 100644 --- a/sw/source/core/doc/DocumentFieldsManager.cxx +++ b/sw/source/core/doc/DocumentFieldsManager.cxx @@ -49,6 +49,7 @@ #include <fldbas.hxx> #include <expfld.hxx> #include <ddefld.hxx> +#include <swddetbl.hxx> #include <authfld.hxx> #include <usrfld.hxx> #include <ndindex.hxx> @@ -405,8 +406,9 @@ void DocumentFieldsManager::UpdateFields( bool bCloseDB ) case SwFieldIds::Dde: { - SwMsgPoolItem aUpdateDDE( RES_UPDATEDDETBL ); - pFieldType->CallSwClientNotify(sw::LegacyModifyHint(nullptr, &aUpdateDDE)); + assert(dynamic_cast<SwDDEFieldType*>(pFieldType.get())); + auto pDDEFieldType = static_cast<SwDDEFieldType*>(pFieldType.get()); + pDDEFieldType->UpdateDDE(false); break; } case SwFieldIds::GetExp: diff --git a/sw/source/core/fields/ddefld.cxx b/sw/source/core/fields/ddefld.cxx index 590fcef86cad..8b326d02cd62 100644 --- a/sw/source/core/fields/ddefld.cxx +++ b/sw/source/core/fields/ddefld.cxx @@ -97,54 +97,8 @@ public: return SUCCESS; } - OSL_ENSURE(m_rFieldType.GetDoc(), "no pDoc"); - - // no dependencies left? - if (!m_rFieldType.IsModifyLocked() && !ChkNoDataFlag()) - { - SwViewShell* pSh = m_rFieldType.GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell(); - SwEditShell* pESh = m_rFieldType.GetDoc()->GetEditShell(); - - // Search for fields. If no valid found, disconnect. - SwMsgPoolItem aUpdateDDE( RES_UPDATEDDETBL ); - m_rFieldType.LockModify(); - - std::vector<SwFormatField*> vFields; - std::vector<SwDDETable*> vTables; - m_rFieldType.GatherFields(vFields, false); - m_rFieldType.GatherDdeTables(vTables); - const bool bDoAction = vFields.size() || vTables.size(); - if(bDoAction) - { - if(pESh) - pESh->StartAllAction(); - else if(pSh) - pSh->StartAction(); - } - - // DDE fields attribute in the text - for(auto pFormatField: vFields) - { - if(pFormatField->GetTextField()) - pFormatField->UpdateTextNode( nullptr, &aUpdateDDE ); - } - // a DDE tables in the text - for(auto pTable: vTables) - pTable->ChangeContent(); - - m_rFieldType.UnlockModify(); - - if(bDoAction) - { - if(pESh) - pESh->EndAllAction(); - else if(pSh) - pSh->EndAction(); - - if(pSh) - pSh->GetDoc()->getIDocumentState().SetModified(); - } - } + if(!ChkNoDataFlag()) + m_rFieldType.UpdateDDE(); return SUCCESS; } @@ -332,6 +286,56 @@ void SwDDEFieldType::PutValue( const uno::Any& rVal, sal_uInt16 nWhichId ) SetCmd( sNewCmd.makeStringAndClear() ); } +void SwDDEFieldType::UpdateDDE(const bool bNotifyShells) +{ + auto pDoc = GetDoc(); + assert(pDoc); + if(IsModifyLocked()) + return; + SwViewShell* pSh = bNotifyShells ? pDoc->getIDocumentLayoutAccess().GetCurrentViewShell() : nullptr; + SwEditShell* pESh = bNotifyShells ? pDoc->GetEditShell() : nullptr; + + // Search for fields. If no valid found, disconnect. + LockModify(); + + std::vector<SwFormatField*> vFields; + std::vector<SwDDETable*> vTables; + GatherFields(vFields, false); + GatherDdeTables(vTables); + const bool bDoAction = vFields.size() || vTables.size(); + if(bDoAction) + { + if(pESh) + pESh->StartAllAction(); + else if(pSh) + pSh->StartAction(); + } + + // DDE fields attribute in the text + SwMsgPoolItem aUpdateDDE(RES_UPDATEDDETBL); + for(auto pFormatField: vFields) + { + if(pFormatField->GetTextField()) + pFormatField->UpdateTextNode( nullptr, &aUpdateDDE ); + } + // a DDE tables in the text + for(auto pTable: vTables) + pTable->ChangeContent(); + + UnlockModify(); + + if(bDoAction) + { + if(pESh) + pESh->EndAllAction(); + else if(pSh) + pSh->EndAction(); + + if(pSh) + pSh->GetDoc()->getIDocumentState().SetModified(); + } +} + SwDDEField::SwDDEField( SwDDEFieldType* pInitType ) : SwField(pInitType) {