summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorBjoern Michaelsen <bjoern.michaelsen@libreoffice.org>2020-02-08 23:00:26 +0100
committerBjörn Michaelsen <bjoern.michaelsen@libreoffice.org>2020-02-10 19:51:23 +0100
commit7477b3ca599bc1d0e8e84fa3674032b0da4117b3 (patch)
tree9119c505645df85b44fbe96a3c34e61e2bbfdcaa /sw
parentcc0759f1e2bea4241d878ee57deaab9e50e24a3d (diff)
refactor PostIt access to SwFormatFields in ...
- SwTextShell::ExecField() - PostItManager Change-Id: I7eabf0a7d8170d0dacf3069925abfe1a91a4a9f5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88334 Tested-by: Jenkins Reviewed-by: Björn Michaelsen <bjoern.michaelsen@libreoffice.org>
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/fldbas.hxx3
-rw-r--r--sw/inc/fmtfld.hxx12
-rw-r--r--sw/source/core/fields/fldbas.cxx11
-rw-r--r--sw/source/core/txtnode/atrfld.cxx15
-rw-r--r--sw/source/uibase/docvw/PostItMgr.cxx26
-rw-r--r--sw/source/uibase/shells/textfld.cxx27
6 files changed, 54 insertions, 40 deletions
diff --git a/sw/inc/fldbas.hxx b/sw/inc/fldbas.hxx
index 19fad702c4ad..0b7367a24509 100644
--- a/sw/inc/fldbas.hxx
+++ b/sw/inc/fldbas.hxx
@@ -32,6 +32,7 @@ class SwField;
class SwFormatField;
class SwRootFrame;
class SvNumberFormatter;
+class IDocumentRedlineAccess;
namespace com { namespace sun { namespace star { namespace beans { class XPropertySet; } } } }
namespace com { namespace sun { namespace star { namespace uno { class Any; } } } }
@@ -270,6 +271,8 @@ public:
inline void UpdateFields() const;
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
SwFormatField* FindFormatForField(const SwField*) const;
+ SwFormatField* FindFormatForPostItId(sal_uInt32 nPostItId) const;
+ void CollectPostIts(std::vector<SwFormatField*>& rvFormatFields, IDocumentRedlineAccess const& rIDRA, bool HideRedlines);
};
inline void SwFieldType::UpdateFields() const
diff --git a/sw/inc/fmtfld.hxx b/sw/inc/fmtfld.hxx
index 7857b9915c6b..812bc7403209 100644
--- a/sw/inc/fmtfld.hxx
+++ b/sw/inc/fmtfld.hxx
@@ -32,6 +32,7 @@ class SwTextField;
class SwView;
class SwFieldType;
class SwFormatField;
+class IDocumentRedlineAccess;
namespace com { namespace sun { namespace star { namespace text { class XTextField; } } } }
namespace sw {
@@ -40,6 +41,17 @@ namespace sw {
SwFormatField*& m_rpFormat;
FindFormatForFieldHint(const SwField* pField, SwFormatField*& rpFormat) : m_pField(pField), m_rpFormat(rpFormat) {};
};
+ struct FindFormatForPostItIdHint final : SfxHint {
+ const sal_uInt32 m_nPostItId;
+ SwFormatField*& m_rpFormat;
+ FindFormatForPostItIdHint(const sal_uInt32 nPostItId, SwFormatField*& rpFormat) : m_nPostItId(nPostItId), m_rpFormat(rpFormat) {};
+ };
+ struct CollectPostItsHint final : SfxHint {
+ std::vector<SwFormatField*>& m_rvFormatFields;
+ IDocumentRedlineAccess const& m_rIDRA;
+ const bool m_bHideRedlines;
+ CollectPostItsHint(std::vector<SwFormatField*>& rvFormatFields, IDocumentRedlineAccess const& rIDRA, bool bHideRedlines) : m_rvFormatFields(rvFormatFields), m_rIDRA(rIDRA), m_bHideRedlines(bHideRedlines) {};
+ };
}
diff --git a/sw/source/core/fields/fldbas.cxx b/sw/source/core/fields/fldbas.cxx
index 252fa47584d1..b2345906496d 100644
--- a/sw/source/core/fields/fldbas.cxx
+++ b/sw/source/core/fields/fldbas.cxx
@@ -162,6 +162,17 @@ SwFormatField* SwFieldType::FindFormatForField(const SwField* pField) const {
return pFormat;
}
+SwFormatField* SwFieldType::FindFormatForPostItId(sal_uInt32 nPostItId) const {
+ SwFormatField* pFormat = nullptr;
+ CallSwClientNotify(sw::FindFormatForPostItIdHint(nPostItId, pFormat));
+ return pFormat;
+}
+
+void SwFieldType::CollectPostIts(std::vector<SwFormatField*>& rvFormatFields, IDocumentRedlineAccess const& rIDRA, const bool bHideRedlines)
+{
+ CallSwClientNotify(sw::CollectPostItsHint(rvFormatFields, rIDRA, bHideRedlines));
+}
+
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 91261b6bedfb..6042ad99b931 100644
--- a/sw/source/core/txtnode/atrfld.cxx
+++ b/sw/source/core/txtnode/atrfld.cxx
@@ -223,7 +223,7 @@ void SwFormatField::InvalidateField()
void SwFormatField::SwClientNotify( const SwModify& rModify, const SfxHint& rHint )
{
SwClient::SwClientNotify(rModify, rHint);
- if (const SwFieldHint* pFieldHint = dynamic_cast<const SwFieldHint*>( &rHint ))
+ if (const auto pFieldHint = dynamic_cast<const SwFieldHint*>( &rHint ))
{
if( !mpTextField )
return;
@@ -240,15 +240,24 @@ void SwFormatField::SwClientNotify( const SwModify& rModify, const SfxHint& rHin
pPaM->Move( fnMoveForward );
pDoc->getIDocumentContentOperations().DeleteRange( *pPaM );
pDoc->getIDocumentContentOperations().InsertString( *pPaM, aEntry );
- } else if (const sw::LegacyModifyHint* pLegacyHint = dynamic_cast<const sw::LegacyModifyHint*>( &rHint ))
+ } else if (const auto 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 ))
+ } else if (const auto pFindForFieldHint = dynamic_cast<const sw::FindFormatForFieldHint*>( &rHint ))
{
if(pFindForFieldHint->m_rpFormat == nullptr && pFindForFieldHint->m_pField == GetField())
pFindForFieldHint->m_rpFormat = this;
+ } else if (const auto pFindForPostItIdHint = dynamic_cast<const sw::FindFormatForPostItIdHint*>( &rHint ))
+ {
+ auto pPostItField = dynamic_cast<SwPostItField*>(mpField.get());
+ if(pPostItField && pFindForPostItIdHint->m_rpFormat == nullptr && pFindForPostItIdHint->m_nPostItId == pPostItField->GetPostItId())
+ pFindForPostItIdHint->m_rpFormat = this;
+ } else if (const auto pCollectPostItsHint = dynamic_cast<const sw::CollectPostItsHint*>( &rHint ))
+ {
+ if(GetTextField() && IsFieldInDoc() && (!pCollectPostItsHint->m_bHideRedlines || !sw::IsFieldDeletedInModel(pCollectPostItsHint->m_rIDRA, *GetTextField())))
+ pCollectPostItsHint->m_rvFormatFields.push_back(this);
}
}
diff --git a/sw/source/uibase/docvw/PostItMgr.cxx b/sw/source/uibase/docvw/PostItMgr.cxx
index 97dbe010ef50..9d691e4bbddb 100644
--- a/sw/source/uibase/docvw/PostItMgr.cxx
+++ b/sw/source/uibase/docvw/PostItMgr.cxx
@@ -1295,27 +1295,15 @@ bool SwPostItMgr::LayoutByPage(std::vector<SwAnnotationWin*> &aVisiblePostItList
return bScrollbars;
}
-void SwPostItMgr::AddPostIts(bool bCheckExistence, bool bFocus)
+void SwPostItMgr::AddPostIts(const bool bCheckExistence, const bool bFocus)
{
- bool bEmpty = mvPostItFields.empty();
+ const bool bEmpty = mvPostItFields.empty();
+ IDocumentRedlineAccess const& rIDRA(mpWrtShell->getIDocumentRedlineAccess());
SwFieldType* pType = mpView->GetDocShell()->GetDoc()->getIDocumentFieldsAccess().GetFieldType(SwFieldIds::Postit, OUString(),false);
- SwIterator<SwFormatField,SwFieldType> aIter( *pType );
- SwFormatField* pSwFormatField = aIter.First();
- while(pSwFormatField)
- {
- if ( pSwFormatField->GetTextField())
- {
- IDocumentRedlineAccess const& rIDRA(mpWrtShell->getIDocumentRedlineAccess());
- if (pSwFormatField->IsFieldInDoc()
- && (!mpWrtShell->GetLayout()->IsHideRedlines()
- || !sw::IsFieldDeletedInModel(rIDRA, *pSwFormatField->GetTextField())))
- {
- InsertItem(pSwFormatField,bCheckExistence,bFocus);
- }
- }
- pSwFormatField = aIter.Next();
- }
-
+ std::vector<SwFormatField*> vFormatFields;
+ pType->CollectPostIts(vFormatFields, rIDRA, mpWrtShell->GetLayout()->IsHideRedlines());
+ for(auto pFormatField : vFormatFields)
+ InsertItem(pFormatField, bCheckExistence, bFocus);
// if we just added the first one we have to update the view for centering
if (bEmpty && !mvPostItFields.empty())
PrepareView(true);
diff --git a/sw/source/uibase/shells/textfld.cxx b/sw/source/uibase/shells/textfld.cxx
index a025187c8d75..0a2ef5d50054 100644
--- a/sw/source/uibase/shells/textfld.cxx
+++ b/sw/source/uibase/shells/textfld.cxx
@@ -376,27 +376,18 @@ void SwTextShell::ExecField(SfxRequest &rReq)
if (pIdItem && !pIdItem->GetValue().isEmpty())
{
SwFieldType* pType = rSh.GetDoc()->getIDocumentFieldsAccess().GetFieldType(SwFieldIds::Postit, OUString(), false);
- SwIterator<SwFormatField,SwFieldType> aIter( *pType );
- SwFormatField* pSwFormatField = aIter.First();
- while( pSwFormatField )
+ if(pType->FindFormatForPostItId(pIdItem->GetValue().toUInt32()))
{
- if ( static_cast<SwPostItField*>(pSwFormatField->GetField())->GetPostItId() == pIdItem->GetValue().toUInt32() )
+ auto pMgr = GetView().GetPostItMgr();
+ auto pWin = pMgr->GetAnnotationWin(pIdItem->GetValue().toUInt32());
+ if(pWin)
{
- sw::annotation::SwAnnotationWin* pWin = GetView().GetPostItMgr()->GetAnnotationWin(pIdItem->GetValue().toUInt32());
- if (pWin)
- {
- const SvxPostItTextItem* pTextItem = rReq.GetArg<SvxPostItTextItem>(SID_ATTR_POSTIT_TEXT);
- OUString sText;
- if ( pTextItem )
- sText = pTextItem->GetValue();
-
- GetView().GetPostItMgr()->RegisterAnswerText(sText);
- pWin->ExecuteCommand(nSlot);
- }
-
- break;
+ OUString sText;
+ if(const auto pTextItem = rReq.GetArg<SvxPostItTextItem>(SID_ATTR_POSTIT_TEXT))
+ sText = pTextItem->GetValue();
+ pMgr->RegisterAnswerText(sText);
+ pWin->ExecuteCommand(nSlot);
}
- pSwFormatField = aIter.Next();
}
}
}