From a27966454efc25591fe198548d38e5eafe443a68 Mon Sep 17 00:00:00 2001 From: Bjoern Michaelsen Date: Mon, 16 Nov 2020 00:21:46 +0100 Subject: Replace needless SwClientNotifyCalls with CallSwClientNotify Change-Id: I967d458be7cd7c68ff410357da0cb0163dcb454e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105908 Tested-by: Jenkins Reviewed-by: Bjoern Michaelsen --- sw/inc/reffld.hxx | 3 +- sw/source/core/doc/DocumentFieldsManager.cxx | 23 +++++------- sw/source/core/fields/reffld.cxx | 53 ++++++++++++++++------------ 3 files changed, 42 insertions(+), 37 deletions(-) (limited to 'sw') diff --git a/sw/inc/reffld.hxx b/sw/inc/reffld.hxx index 6d9ee86f7950..c76fe074c854 100644 --- a/sw/inc/reffld.hxx +++ b/sw/inc/reffld.hxx @@ -67,7 +67,7 @@ class SAL_DLLPUBLIC_RTTI SwGetRefFieldType final : public SwFieldType SwDoc& m_rDoc; /// Overlay in order to update all ref-fields. - virtual void Modify( const SfxPoolItem*, const SfxPoolItem* ) override; + virtual void SwClientNotify(const SwModify&, const SfxHint&) override; public: SwGetRefFieldType(SwDoc& rDoc ); virtual std::unique_ptr Copy() const override; @@ -80,6 +80,7 @@ public: sal_uInt16 nSubType, sal_uInt16 nSeqNo, sal_Int32* pStt, sal_Int32* pEnd = nullptr, SwRootFrame const* pLayout = nullptr); + void UpdateGetReferences(); }; class SW_DLLPUBLIC SwGetRefField final : public SwField diff --git a/sw/source/core/doc/DocumentFieldsManager.cxx b/sw/source/core/doc/DocumentFieldsManager.cxx index bafe9c29fb00..cbae4727e10d 100644 --- a/sw/source/core/doc/DocumentFieldsManager.cxx +++ b/sw/source/core/doc/DocumentFieldsManager.cxx @@ -179,11 +179,6 @@ namespace #endif } } - void lcl_SwClientNotify(sw::BroadcastingModify& rModify, const SfxPoolItem* pNew) - { - const sw::LegacyModifyHint aHint(nullptr, pNew); - rModify.SwClientNotifyCall(rModify, aHint); - } } namespace sw @@ -409,7 +404,7 @@ void DocumentFieldsManager::UpdateFields( bool bCloseDB ) case SwFieldIds::Dde: { SwMsgPoolItem aUpdateDDE( RES_UPDATEDDETBL ); - lcl_SwClientNotify(*pFieldType, &aUpdateDDE ); + pFieldType->CallSwClientNotify(sw::LegacyModifyHint(nullptr, &aUpdateDDE)); break; } case SwFieldIds::GetExp: @@ -419,7 +414,7 @@ void DocumentFieldsManager::UpdateFields( bool bCloseDB ) // Expression fields are treated separately break; default: - lcl_SwClientNotify(*pFieldType, nullptr ); + pFieldType->CallSwClientNotify(sw::LegacyModifyHint(nullptr, nullptr)); } } @@ -567,7 +562,7 @@ bool DocumentFieldsManager::UpdateField(SwTextField * pDstTextField, SwField & r if (bUpdateFields) UpdateTableFields( &aTableUpdate ); else - lcl_SwClientNotify(*pNewField->GetTyp(), &aTableUpdate); + pNewField->GetTyp()->CallSwClientNotify(sw::LegacyModifyHint(nullptr, &aTableUpdate)); if (! bUpdateFields) bTableSelBreak = true; @@ -577,7 +572,7 @@ bool DocumentFieldsManager::UpdateField(SwTextField * pDstTextField, SwField & r case SwFieldIds::Macro: if( bUpdateFields && pDstTextField->GetpTextNode() ) - lcl_SwClientNotify(*pDstTextField->GetpTextNode(), pDstFormatField); + pDstTextField->GetpTextNode()->TriggerNodeUpdate(sw::LegacyModifyHint(nullptr, pDstFormatField)); break; case SwFieldIds::DatabaseName: @@ -620,9 +615,9 @@ bool DocumentFieldsManager::UpdateField(SwTextField * pDstTextField, SwField & r /// Update reference and table fields void DocumentFieldsManager::UpdateRefFields() { - for( auto const & pFieldType : *mpFieldTypes ) - if( SwFieldIds::GetRef == pFieldType->Which() ) - lcl_SwClientNotify(*pFieldType, nullptr ); + for(auto const& pFieldType: *mpFieldTypes) + if(SwFieldIds::GetRef == pFieldType->Which()) + static_cast(pFieldType.get())->UpdateGetReferences(); } void DocumentFieldsManager::UpdateTableFields( SfxPoolItem* pHt ) @@ -1355,10 +1350,10 @@ void DocumentFieldsManager::UpdatePageFields( SfxPoolItem* pMsgHint ) case SwFieldIds::Chapter: case SwFieldIds::GetExp: case SwFieldIds::RefPageGet: - lcl_SwClientNotify(*pFieldType, pMsgHint); + pFieldType->CallSwClientNotify(sw::LegacyModifyHint(nullptr, pMsgHint)); break; case SwFieldIds::DocStat: - lcl_SwClientNotify(*pFieldType, nullptr); + pFieldType->CallSwClientNotify(sw::LegacyModifyHint(nullptr, nullptr)); break; default: break; } diff --git a/sw/source/core/fields/reffld.cxx b/sw/source/core/fields/reffld.cxx index 7d9e73feb7de..b7e75f405d6b 100644 --- a/sw/source/core/fields/reffld.cxx +++ b/sw/source/core/fields/reffld.cxx @@ -1070,33 +1070,42 @@ std::unique_ptr SwGetRefFieldType::Copy() const return std::make_unique( m_rDoc ); } -void SwGetRefFieldType::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew ) +void SwGetRefFieldType::UpdateGetReferences() { - // update to all GetReference fields - if( !pNew && !pOld ) + std::vector vFields; + GatherFields(vFields, false); + for(auto pFormatField: vFields) { - std::vector vFields; - GatherFields(vFields, false); - for(auto pFormatField: vFields) + // update only the GetRef fields + //JP 3.4.2001: Task 71231 - we need the correct language + SwGetRefField* pGRef = static_cast(pFormatField->GetField()); + const SwTextField* pTField; + if(!pGRef->GetLanguage() && + nullptr != (pTField = pFormatField->GetTextField()) && + pTField->GetpTextNode()) { - // update only the GetRef fields - //JP 3.4.2001: Task 71231 - we need the correct language - SwGetRefField* pGRef = static_cast(pFormatField->GetField()); - const SwTextField* pTField; - if( !pGRef->GetLanguage() && - nullptr != ( pTField = pFormatField->GetTextField()) && - pTField->GetpTextNode() ) - { - pGRef->SetLanguage( pTField->GetpTextNode()->GetLang( - pTField->GetStart() ) ); - } - - // #i81002# - pGRef->UpdateField( pFormatField->GetTextField() ); + pGRef->SetLanguage(pTField->GetpTextNode()->GetLang(pTField->GetStart())); } + + // #i81002# + pGRef->UpdateField(pFormatField->GetTextField()); } - // forward to text fields, they "expand" the text - NotifyClients( pOld, pNew ); + NotifyClients(nullptr, nullptr); +} + +void SwGetRefFieldType::SwClientNotify(const SwModify&, const SfxHint& rHint) +{ + auto pLegacy = dynamic_cast(&rHint); + if(!pLegacy) + return; + if(!pLegacy->m_pNew && !pLegacy->m_pOld) + // update to all GetReference fields + // hopefully, this codepath is soon dead code, and + // UpdateGetReferences gets only called directly + UpdateGetReferences(); + else + // forward to text fields, they "expand" the text + NotifyClients(pLegacy->m_pOld, pLegacy->m_pNew); } namespace sw { -- cgit v1.2.3