summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjoern Michaelsen <bjoern.michaelsen@libreoffice.org>2020-02-04 01:50:56 +0100
committerBjörn Michaelsen <bjoern.michaelsen@libreoffice.org>2020-02-07 19:49:13 +0100
commitc73b5e969b2f9abdb2b9191938ca30bec5af725d (patch)
tree5bb49b193f7c143f380d8e5ce580552b588888ec
parent61fbdb13121643c6faf917912bd39c6b9720888a (diff)
SwFormatField::Modify no more (folded into SwClientNotify)
- refactor out field formatting * make direct calls explicit with new UpdateTextNode() call * try to bring at least some sanity to the event handler Change-Id: I40a39ddf70476b7fa0bf5e157fb263e863bb1d20 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87927 Tested-by: Jenkins Reviewed-by: Björn Michaelsen <bjoern.michaelsen@libreoffice.org>
-rw-r--r--sw/inc/fmtfld.hxx3
-rw-r--r--sw/source/core/doc/DocumentFieldsManager.cxx8
-rw-r--r--sw/source/core/doc/docfld.cxx2
-rw-r--r--sw/source/core/fields/ddefld.cxx2
-rw-r--r--sw/source/core/txtnode/atrfld.cxx111
5 files changed, 75 insertions, 51 deletions
diff --git a/sw/inc/fmtfld.hxx b/sw/inc/fmtfld.hxx
index 18d8ffb136f8..cde0efe48f5a 100644
--- a/sw/inc/fmtfld.hxx
+++ b/sw/inc/fmtfld.hxx
@@ -47,7 +47,6 @@ class SW_DLLPUBLIC SwFormatField final
std::unique_ptr<SwField> mpField;
SwTextField* mpTextField; // the TextAttribute
- virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) override;
virtual void SwClientNotify( const SwModify& rModify, const SfxHint& rHint ) override;
public:
@@ -105,6 +104,8 @@ public:
SAL_DLLPRIVATE void SetXTextField(css::uno::Reference<css::text::XTextField> const& xTextField)
{ m_wXTextField = xTextField; }
void dumpAsXml(xmlTextWriterPtr pWriter) const override;
+
+ void UpdateTextNode(const SfxPoolItem* pOld, const SfxPoolItem* pNew);
};
enum class SwFormatFieldHintWhich
diff --git a/sw/source/core/doc/DocumentFieldsManager.cxx b/sw/source/core/doc/DocumentFieldsManager.cxx
index 134d8cab9968..24bfce63ee5b 100644
--- a/sw/source/core/doc/DocumentFieldsManager.cxx
+++ b/sw/source/core/doc/DocumentFieldsManager.cxx
@@ -601,7 +601,7 @@ bool DocumentFieldsManager::UpdateField(SwTextField * pDstTextField, SwField & r
[[fallthrough]];
default:
- pDstFormatField->ModifyNotification( nullptr, pMsgHint );
+ pDstFormatField->UpdateTextNode(nullptr, pMsgHint);
}
// The fields we can calculate here are being triggered for an update
@@ -798,7 +798,7 @@ void DocumentFieldsManager::UpdateTableFields( SfxPoolItem* pHt )
}
pCalc->SetCalcError( SwCalcError::NONE );
}
- pFormatField->ModifyNotification( nullptr, pHt );
+ pFormatField->UpdateTextNode(nullptr, pHt);
}
}
@@ -1282,7 +1282,7 @@ void DocumentFieldsManager::UpdateExpFieldsImpl(
pInputField->UnlockNotifyContentChange();
}
});
- pFormatField->ModifyNotification(nullptr, nullptr); // trigger formatting
+ pFormatField->UpdateTextNode(nullptr, nullptr); // trigger formatting
}
if (pUpdateField == pTextField) // if only this one is updated
@@ -1537,7 +1537,7 @@ void DocumentFieldsManager::SetFixFields( const DateTime* pNewDateTime )
// Trigger formatting
if( bChgd )
- pFormatField->ModifyNotification( nullptr, nullptr );
+ pFormatField->UpdateTextNode(nullptr, nullptr);
}
}
}
diff --git a/sw/source/core/doc/docfld.cxx b/sw/source/core/doc/docfld.cxx
index 8b5f7d467328..16acdec86cfa 100644
--- a/sw/source/core/doc/docfld.cxx
+++ b/sw/source/core/doc/docfld.cxx
@@ -940,7 +940,7 @@ void SwDocUpdateField::MakeFieldList_( SwDoc& rDoc, int eGetMode )
// evaluate field
const_cast<SwHiddenTextField*>(static_cast<const SwHiddenTextField*>(pField))->Evaluate(&rDoc);
// trigger formatting
- const_cast<SwFormatField*>(pFormatField)->ModifyNotification( nullptr, nullptr );
+ const_cast<SwFormatField*>(pFormatField)->UpdateTextNode(nullptr, nullptr);
}
break;
diff --git a/sw/source/core/fields/ddefld.cxx b/sw/source/core/fields/ddefld.cxx
index 7d6c91d31d17..ebc065153f18 100644
--- a/sw/source/core/fields/ddefld.cxx
+++ b/sw/source/core/fields/ddefld.cxx
@@ -124,7 +124,7 @@ public:
else if( pSh )
pSh->StartAction();
}
- pLast->ModifyNotification( nullptr, &aUpdateDDE );
+ static_cast<SwFormatField*>(pLast)->UpdateTextNode( nullptr, &aUpdateDDE );
bCallModify = true;
}
}
diff --git a/sw/source/core/txtnode/atrfld.cxx b/sw/source/core/txtnode/atrfld.cxx
index 3bc232ece517..4f0bbaf9a7cc 100644
--- a/sw/source/core/txtnode/atrfld.cxx
+++ b/sw/source/core/txtnode/atrfld.cxx
@@ -226,25 +226,27 @@ void SwFormatField::SwClientNotify( const SwModify& rModify, const SfxHint& rHin
if( !mpTextField )
return;
- const SwFieldHint* pHint = dynamic_cast<const SwFieldHint*>( &rHint );
- if ( pHint )
+ if (const SwFieldHint* pFieldHint = dynamic_cast<const SwFieldHint*>( &rHint ))
{
// replace field content by text
- SwPaM* pPaM = pHint->m_pPaM;
+ SwPaM* pPaM = pFieldHint->m_pPaM;
SwDoc* pDoc = pPaM->GetDoc();
const SwTextNode& rTextNode = mpTextField->GetTextNode();
pPaM->GetPoint()->nNode = rTextNode;
pPaM->GetPoint()->nContent.Assign( const_cast<SwTextNode*>(&rTextNode), mpTextField->GetStart() );
- OUString const aEntry(mpField->ExpandField(pDoc->IsClipBoard(), pHint->m_pLayout));
+ OUString const aEntry(mpField->ExpandField(pDoc->IsClipBoard(), pFieldHint->m_pLayout));
pPaM->SetMark();
pPaM->Move( fnMoveForward );
pDoc->getIDocumentContentOperations().DeleteRange( *pPaM );
pDoc->getIDocumentContentOperations().InsertString( *pPaM, aEntry );
+ } else if (const sw::LegacyModifyHint* pLegacyHint = dynamic_cast<const sw::LegacyModifyHint*>( &rHint ))
+ {
+ UpdateTextNode(pLegacyHint->m_pOld, pLegacyHint->m_pNew);
}
}
-void SwFormatField::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
+void SwFormatField::UpdateTextNode(const SfxPoolItem* pOld, const SfxPoolItem* pNew)
{
if (pOld && (RES_REMOVE_UNO_OBJECT == pOld->Which()))
{ // invalidate cached UNO object
@@ -263,59 +265,80 @@ void SwFormatField::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
SwTextNode* pTextNd = &mpTextField->GetTextNode();
OSL_ENSURE( pTextNd, "Where is my Node?" );
- if( pNew )
+
+ bool bTriggerNode = false;
+ bool bExpand = false;
+ const SfxPoolItem* pNodeOld = nullptr;
+ const SfxPoolItem* pNodeNew = nullptr;
+ if(pNew)
{
- switch( pNew->Which() )
+ switch(pNew->Which())
{
case RES_REFMARKFLD_UPDATE:
- // update GetRef fields
- if( SwFieldIds::GetRef == mpField->GetTyp()->Which() )
- {
- // #i81002#
- static_cast<SwGetRefField*>(mpField.get())->UpdateField( mpTextField );
- }
- break;
+ // update GetRef fields
+ if( SwFieldIds::GetRef == mpField->GetTyp()->Which() )
+ {
+ // #i81002#
+ static_cast<SwGetRefField*>(mpField.get())->UpdateField( mpTextField );
+ }
+ break;
case RES_DOCPOS_UPDATE:
- // handled in SwTextFrame::Modify()
- pTextNd->ModifyNotification( pNew, this );
- return;
-
+ // handled in SwTextFrame::Modify()
+ bTriggerNode = true;
+ pNodeOld = pNew;
+ pNodeNew = this;
+ break;
case RES_ATTRSET_CHG:
case RES_FMT_CHG:
- pTextNd->ModifyNotification( pOld, pNew );
- return;
+ bTriggerNode = true;
+ pNodeOld = pOld;
+ pNodeNew = pNew;
+ break;
default:
- break;
+ break;
}
}
-
- switch (mpField->GetTyp()->Which())
+ if(!bTriggerNode)
{
- case SwFieldIds::HiddenPara:
- if( !pOld || RES_HIDDENPARA_PRINT != pOld->Which() )
+ switch (mpField->GetTyp()->Which())
+ {
+ case SwFieldIds::HiddenPara:
+ if( !pOld || pOld->Which() != RES_HIDDENPARA_PRINT ) {
+ bExpand =true;
+ break;
+ }
+ [[fallthrough]];
+ case SwFieldIds::DbSetNumber:
+ case SwFieldIds::DbNumSet:
+ case SwFieldIds::DbNextSet:
+ case SwFieldIds::DatabaseName:
+ bTriggerNode = true;
+ pNodeNew = pNew;
break;
- [[fallthrough]];
- case SwFieldIds::DbSetNumber:
- case SwFieldIds::DbNumSet:
- case SwFieldIds::DbNextSet:
- case SwFieldIds::DatabaseName:
- pTextNd->ModifyNotification( nullptr, pNew);
- return;
- default: break;
+ case SwFieldIds::User:
+ {
+ SwUserFieldType* pType = static_cast<SwUserFieldType*>(mpField->GetTyp());
+ if(!pType->IsValid())
+ {
+ SwCalc aCalc( *pTextNd->GetDoc() );
+ pType->GetValue( aCalc );
+ }
+ bExpand = true;
+ }
+ break;
+ default:
+ bExpand = true;
+ break;
+ }
}
-
- if( SwFieldIds::User == mpField->GetTyp()->Which() )
+ if(bTriggerNode)
{
- SwUserFieldType* pType = static_cast<SwUserFieldType*>(mpField->GetTyp());
- if(!pType->IsValid())
- {
- SwCalc aCalc( *pTextNd->GetDoc() );
- pType->GetValue( aCalc );
- }
+ pTextNd->ModifyNotification(pNodeOld, pNodeNew);
+ }
+ if(bExpand)
+ {
+ mpTextField->ExpandTextField( pOld == nullptr && pNew == nullptr );
}
-
- const bool bForceNotify = (pOld == nullptr) && (pNew == nullptr);
- mpTextField->ExpandTextField( bForceNotify );
}
bool SwFormatField::GetInfo( SfxPoolItem& rInfo ) const