[Libreoffice-commits] core.git: sw/inc sw/source
Bjoern Michaelsen (via logerrit)
logerrit at kemper.freedesktop.org
Sat Feb 8 20:40:41 UTC 2020
sw/inc/fldbas.hxx | 3 +++
sw/inc/fmtfld.hxx | 10 ++++++++++
sw/source/core/fields/fldbas.cxx | 6 ++++++
sw/source/core/txtnode/atrfld.cxx | 12 +++++++++---
sw/source/uibase/wrtsh/wrtsh1.cxx | 13 ++-----------
5 files changed, 30 insertions(+), 14 deletions(-)
New commits:
commit 6b2b0af1936ddc57992b01a56725d4acadffc806
Author: Bjoern Michaelsen <bjoern.michaelsen at libreoffice.org>
AuthorDate: Sat Feb 8 12:19:17 2020 +0100
Commit: Björn Michaelsen <bjoern.michaelsen at libreoffice.org>
CommitDate: Sat Feb 8 21:40:00 2020 +0100
introduce SwFieldType::FindFormatForField and use it (once)
Change-Id: Id7136b936c0585e7013f3d06ad97436b51522da3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88264
Tested-by: Jenkins
Reviewed-by: Björn Michaelsen <bjoern.michaelsen at libreoffice.org>
diff --git a/sw/inc/fldbas.hxx b/sw/inc/fldbas.hxx
index 664f74b45242..19fad702c4ad 100644
--- a/sw/inc/fldbas.hxx
+++ b/sw/inc/fldbas.hxx
@@ -28,6 +28,8 @@
#include <climits>
class SwDoc;
+class SwField;
+class SwFormatField;
class SwRootFrame;
class SvNumberFormatter;
namespace com { namespace sun { namespace star { namespace beans { class XPropertySet; } } } }
@@ -267,6 +269,7 @@ public:
inline void UpdateFields() const;
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
+ SwFormatField* FindFormatForField(const SwField*) const;
};
inline void SwFieldType::UpdateFields() const
diff --git a/sw/inc/fmtfld.hxx b/sw/inc/fmtfld.hxx
index cde0efe48f5a..7857b9915c6b 100644
--- a/sw/inc/fmtfld.hxx
+++ b/sw/inc/fmtfld.hxx
@@ -31,8 +31,18 @@ class SwField;
class SwTextField;
class SwView;
class SwFieldType;
+class SwFormatField;
namespace com { namespace sun { namespace star { namespace text { class XTextField; } } } }
+namespace sw {
+ struct FindFormatForFieldHint final : SfxHint {
+ const SwField* m_pField;
+ SwFormatField*& m_rpFormat;
+ FindFormatForFieldHint(const SwField* pField, SwFormatField*& rpFormat) : m_pField(pField), m_rpFormat(rpFormat) {};
+ };
+}
+
+
// ATT_FLD
class SW_DLLPUBLIC SwFormatField final
: public SfxPoolItem
diff --git a/sw/source/core/fields/fldbas.cxx b/sw/source/core/fields/fldbas.cxx
index cb69dde129fe..252fa47584d1 100644
--- a/sw/source/core/fields/fldbas.cxx
+++ b/sw/source/core/fields/fldbas.cxx
@@ -156,6 +156,12 @@ void SwFieldType::dumpAsXml(xmlTextWriterPtr pWriter) const
xmlTextWriterEndElement(pWriter);
}
+SwFormatField* SwFieldType::FindFormatForField(const SwField* pField) const {
+ SwFormatField* pFormat = nullptr;
+ CallSwClientNotify(sw::FindFormatForFieldHint(pField, pFormat));
+ return pFormat;
+}
+
void SwFieldTypes::dumpAsXml(xmlTextWriterPtr pWriter) const
{
xmlTextWriterStartElement(pWriter, BAD_CAST("SwFieldTypes"));
diff --git a/sw/source/core/txtnode/atrfld.cxx b/sw/source/core/txtnode/atrfld.cxx
index 4f0bbaf9a7cc..91261b6bedfb 100644
--- a/sw/source/core/txtnode/atrfld.cxx
+++ b/sw/source/core/txtnode/atrfld.cxx
@@ -223,11 +223,11 @@ void SwFormatField::InvalidateField()
void SwFormatField::SwClientNotify( const SwModify& rModify, const SfxHint& rHint )
{
SwClient::SwClientNotify(rModify, rHint);
- if( !mpTextField )
- return;
-
if (const SwFieldHint* pFieldHint = dynamic_cast<const SwFieldHint*>( &rHint ))
{
+ if( !mpTextField )
+ return;
+
// replace field content by text
SwPaM* pPaM = pFieldHint->m_pPaM;
SwDoc* pDoc = pPaM->GetDoc();
@@ -242,7 +242,13 @@ void SwFormatField::SwClientNotify( const SwModify& rModify, const SfxHint& rHin
pDoc->getIDocumentContentOperations().InsertString( *pPaM, aEntry );
} else if (const sw::LegacyModifyHint* pLegacyHint = dynamic_cast<const sw::LegacyModifyHint*>( &rHint ))
{
+ if( !mpTextField )
+ return;
UpdateTextNode(pLegacyHint->m_pOld, pLegacyHint->m_pNew);
+ } else if (const sw::FindFormatForFieldHint* pFindForFieldHint = dynamic_cast<const sw::FindFormatForFieldHint*>( &rHint ))
+ {
+ if(pFindForFieldHint->m_rpFormat == nullptr && pFindForFieldHint->m_pField == GetField())
+ pFindForFieldHint->m_rpFormat = this;
}
}
diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx
index fdb4c56938d7..4225c59b68ec 100644
--- a/sw/source/uibase/wrtsh/wrtsh1.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh1.cxx
@@ -1978,17 +1978,8 @@ void SwWrtShell::InsertPostIt(SwFieldMgr& rFieldMgr, const SfxRequest& rReq)
if (pPostIt)
{
SwFieldType* pType = GetDoc()->getIDocumentFieldsAccess().GetFieldType(SwFieldIds::Postit, OUString(), false);
- SwIterator<SwFormatField,SwFieldType> aIter( *pType );
- SwFormatField* pSwFormatField = aIter.First();
- while( pSwFormatField )
- {
- if ( pSwFormatField->GetField() == pPostIt )
- {
- pSwFormatField->Broadcast( SwFormatFieldHint( nullptr, SwFormatFieldHintWhich::FOCUS, &GetView() ) );
- break;
- }
- pSwFormatField = aIter.Next();
- }
+ if(auto pFormat = pType->FindFormatForField(pPostIt))
+ pFormat->Broadcast( SwFormatFieldHint( nullptr, SwFormatFieldHintWhich::FOCUS, &GetView() ) );
}
}
More information about the Libreoffice-commits
mailing list