summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sw/inc/calbck.hxx2
-rw-r--r--sw/inc/ftninfo.hxx13
-rw-r--r--sw/source/core/attr/calbck.cxx2
-rw-r--r--sw/source/core/doc/docftn.cxx172
-rw-r--r--sw/source/core/unocore/unosett.cxx12
5 files changed, 117 insertions, 84 deletions
diff --git a/sw/inc/calbck.hxx b/sw/inc/calbck.hxx
index dea6e20c24aa..d3aac141da78 100644
--- a/sw/inc/calbck.hxx
+++ b/sw/inc/calbck.hxx
@@ -241,7 +241,7 @@ class SW_DLLPUBLIC SwMultiDepend final
: m_rToTell(rToTell) {}
void StartListening(SwModify* pDepend);
void EndListening(SwModify* pDepend);
- bool IsListeningTo(const SwModify* const pDepend);
+ bool IsListeningTo(const SwModify* const pDepend) const;
void EndListeningAll();
};
diff --git a/sw/inc/ftninfo.hxx b/sw/inc/ftninfo.hxx
index 9a6982a81893..ebd4d5d51bcc 100644
--- a/sw/inc/ftninfo.hxx
+++ b/sw/inc/ftninfo.hxx
@@ -32,13 +32,16 @@ class SwDoc;
class SW_DLLPUBLIC SwEndNoteInfo : public SwClient
{
- SwDepend aPageDescDep;
- SwDepend aCharFormatDep, aAnchorCharFormatDep;
+ SwMultiDepend aDepends;
+ mutable SwTextFormatColl* pFootnoteTextColl;
+ mutable SwPageDesc* pPageDesc;
+ mutable SwCharFormat* pCharFormat;
+ mutable SwCharFormat* pAnchorFormat;
OUString sPrefix;
OUString sSuffix;
protected:
bool m_bEndNote;
- virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew ) override;
+ virtual void SwClientNotify( const SwModify&, const SfxHint& rHint ) override;
public:
SvxNumberType aFormat;
@@ -50,15 +53,13 @@ public:
bool DependsOn( const SwPageDesc* ) const;
void SetFootnoteTextColl(SwTextFormatColl& rColl);
- SwTextFormatColl* GetFootnoteTextColl() const { return const_cast<SwTextFormatColl*>(static_cast<const SwTextFormatColl*>(GetRegisteredIn())); } // can be 0.
+ SwTextFormatColl* GetFootnoteTextColl() const; // can be 0.
SwCharFormat* GetCharFormat(SwDoc &rDoc) const;
void SetCharFormat( SwCharFormat* );
- SwClient *GetCharFormatDep() const { return const_cast<SwClient*>(static_cast<SwClient const *>(&aCharFormatDep)); }
SwCharFormat* GetAnchorCharFormat(SwDoc &rDoc) const;
void SetAnchorCharFormat( SwCharFormat* );
- SwClient *GetAnchorCharFormatDep() const { return const_cast<SwClient*>(static_cast<SwClient const *>(&aAnchorCharFormatDep)); }
SwEndNoteInfo & operator=(const SwEndNoteInfo&);
bool operator==( const SwEndNoteInfo &rInf ) const;
diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx
index c389e1d3fe14..ce7f01d56ac2 100644
--- a/sw/source/core/attr/calbck.cxx
+++ b/sw/source/core/attr/calbck.cxx
@@ -288,7 +288,7 @@ void SwMultiDepend::StartListening(SwModify* pDepend)
}
-bool SwMultiDepend::IsListeningTo(const SwModify* const pBroadcaster)
+bool SwMultiDepend::IsListeningTo(const SwModify* const pBroadcaster) const
{
return std::any_of(m_vDepends.begin(), m_vDepends.end(),
[&pBroadcaster](const SwDepend& aListener)
diff --git a/sw/source/core/doc/docftn.cxx b/sw/source/core/doc/docftn.cxx
index 3ddfcf96c9ee..0f89177f0e3e 100644
--- a/sw/source/core/doc/docftn.cxx
+++ b/sw/source/core/doc/docftn.cxx
@@ -39,11 +39,19 @@
SwEndNoteInfo& SwEndNoteInfo::operator=(const SwEndNoteInfo& rInfo)
{
- StartListeningToSameModifyAs(rInfo);
- aPageDescDep.StartListeningToSameModifyAs(rInfo.aPageDescDep);
- aCharFormatDep.StartListeningToSameModifyAs(rInfo.aCharFormatDep);
- aAnchorCharFormatDep.StartListeningToSameModifyAs(rInfo.aAnchorCharFormatDep);
-
+ aDepends.EndListeningAll();
+ pFootnoteTextColl = rInfo.pFootnoteTextColl;
+ pPageDesc = rInfo.pPageDesc;
+ pCharFormat = rInfo.pCharFormat;
+ pAnchorFormat = rInfo.pAnchorFormat;
+ if(pFootnoteTextColl)
+ aDepends.StartListening(pFootnoteTextColl);
+ if(pPageDesc)
+ aDepends.StartListening(pPageDesc);
+ if(pCharFormat)
+ aDepends.StartListening(pCharFormat);
+ if(pAnchorFormat)
+ aDepends.StartListening(pAnchorFormat);
aFormat = rInfo.aFormat;
nFootnoteOffset = rInfo.nFootnoteOffset;
m_bEndNote = rInfo.m_bEndNote;
@@ -54,13 +62,10 @@ SwEndNoteInfo& SwEndNoteInfo::operator=(const SwEndNoteInfo& rInfo)
bool SwEndNoteInfo::operator==( const SwEndNoteInfo& rInfo ) const
{
- return aPageDescDep.GetRegisteredIn() ==
- rInfo.aPageDescDep.GetRegisteredIn() &&
- aCharFormatDep.GetRegisteredIn() ==
- rInfo.aCharFormatDep.GetRegisteredIn() &&
- aAnchorCharFormatDep.GetRegisteredIn() ==
- rInfo.aAnchorCharFormatDep.GetRegisteredIn() &&
- GetFootnoteTextColl() == rInfo.GetFootnoteTextColl() &&
+ return pFootnoteTextColl == rInfo.pFootnoteTextColl &&
+ pPageDesc == rInfo.pPageDesc &&
+ pCharFormat == rInfo.pCharFormat &&
+ pAnchorFormat == rInfo.pAnchorFormat &&
aFormat.GetNumberingType() == rInfo.aFormat.GetNumberingType() &&
nFootnoteOffset == rInfo.nFootnoteOffset &&
m_bEndNote == rInfo.m_bEndNote &&
@@ -69,123 +74,154 @@ bool SwEndNoteInfo::operator==( const SwEndNoteInfo& rInfo ) const
}
SwEndNoteInfo::SwEndNoteInfo(const SwEndNoteInfo& rInfo) :
- SwClient( rInfo.GetFootnoteTextColl() ),
- aPageDescDep( this, nullptr ),
- aCharFormatDep( this, nullptr ),
- aAnchorCharFormatDep( this, nullptr ),
+ SwClient(nullptr),
+ aDepends(*this),
+ pFootnoteTextColl(nullptr),
+ pPageDesc(rInfo.pPageDesc),
+ pCharFormat(nullptr),
+ pAnchorFormat(nullptr),
sPrefix( rInfo.sPrefix ),
sSuffix( rInfo.sSuffix ),
m_bEndNote( true ),
aFormat( rInfo.aFormat ),
nFootnoteOffset( rInfo.nFootnoteOffset )
{
- aPageDescDep.StartListeningToSameModifyAs(rInfo.aPageDescDep);
- aCharFormatDep.StartListeningToSameModifyAs(rInfo.aCharFormatDep);
- aAnchorCharFormatDep.StartListeningToSameModifyAs(rInfo.aAnchorCharFormatDep);
+ if(rInfo.aDepends.IsListeningTo(rInfo.pFootnoteTextColl))
+ SetFootnoteTextColl(*rInfo.pFootnoteTextColl);
+ if(rInfo.aDepends.IsListeningTo(rInfo.pPageDesc))
+ ChgPageDesc(rInfo.pPageDesc);
+ if(rInfo.aDepends.IsListeningTo(rInfo.pCharFormat))
+ SetCharFormat(rInfo.pCharFormat);
+ if(rInfo.aDepends.IsListeningTo(rInfo.pAnchorFormat))
+ SetAnchorCharFormat(rInfo.pAnchorFormat);
}
SwEndNoteInfo::SwEndNoteInfo() :
- SwClient(nullptr),
- aPageDescDep( this, nullptr ),
- aCharFormatDep( this, nullptr ),
- aAnchorCharFormatDep( this, nullptr ),
+ aDepends(*this),
m_bEndNote( true ),
nFootnoteOffset( 0 )
{
aFormat.SetNumberingType(SVX_NUM_ROMAN_LOWER);
}
-SwPageDesc *SwEndNoteInfo::GetPageDesc( SwDoc &rDoc ) const
+SwPageDesc* SwEndNoteInfo::GetPageDesc(SwDoc& rDoc) const
{
- if ( !aPageDescDep.GetRegisteredIn() )
+ if(!pPageDesc || !aDepends.IsListeningTo(pPageDesc))
{
- SwPageDesc *pDesc = rDoc.getIDocumentStylePoolAccess().GetPageDescFromPool( static_cast<sal_uInt16>(
- m_bEndNote ? RES_POOLPAGE_ENDNOTE : RES_POOLPAGE_FOOTNOTE ) );
- pDesc->Add( &const_cast<SwClient&>(static_cast<const SwClient&>(aPageDescDep)) );
+ pPageDesc = rDoc.getIDocumentStylePoolAccess().GetPageDescFromPool( static_cast<sal_uInt16>(
+ m_bEndNote ? RES_POOLPAGE_ENDNOTE : RES_POOLPAGE_FOOTNOTE ) );
+ const_cast<SwMultiDepend*>(&aDepends)->StartListening(pPageDesc);
}
-
- return const_cast<SwPageDesc*>(static_cast<const SwPageDesc*>( aPageDescDep.GetRegisteredIn() ));
+ return pPageDesc;
}
bool SwEndNoteInfo::KnowsPageDesc() const
{
- return (aPageDescDep.GetRegisteredIn() != nullptr);
+ return pPageDesc && aDepends.IsListeningTo(pPageDesc);
}
bool SwEndNoteInfo::DependsOn( const SwPageDesc* pDesc ) const
{
- return ( aPageDescDep.GetRegisteredIn() == pDesc );
+ return aDepends.IsListeningTo(pPageDesc) && pPageDesc == pDesc;
}
-void SwEndNoteInfo::ChgPageDesc( SwPageDesc *pDesc )
+void SwEndNoteInfo::ChgPageDesc(SwPageDesc* pDesc)
{
- pDesc->Add( &static_cast<SwClient&>(aPageDescDep) );
+ aDepends.EndListening(pPageDesc);
+ pPageDesc = pDesc;
+ aDepends.StartListening(pPageDesc);
+}
+
+SwTextFormatColl* SwEndNoteInfo::GetFootnoteTextColl() const
+{
+ if(!aDepends.IsListeningTo(pFootnoteTextColl))
+ {
+ pFootnoteTextColl = nullptr;
+ }
+ return pFootnoteTextColl;
}
void SwEndNoteInfo::SetFootnoteTextColl(SwTextFormatColl& rFormat)
{
- rFormat.Add(this);
+ aDepends.EndListening(pFootnoteTextColl);
+ pFootnoteTextColl = &rFormat;
+ aDepends.StartListening(pFootnoteTextColl);
}
SwCharFormat* SwEndNoteInfo::GetCharFormat(SwDoc &rDoc) const
{
- if ( !aCharFormatDep.GetRegisteredIn() )
+ if(!pCharFormat || !aDepends.IsListeningTo(pCharFormat))
{
- SwCharFormat* pFormat = rDoc.getIDocumentStylePoolAccess().GetCharFormatFromPool( static_cast<sal_uInt16>(
+ pCharFormat = rDoc.getIDocumentStylePoolAccess().GetCharFormatFromPool( static_cast<sal_uInt16>(
m_bEndNote ? RES_POOLCHR_ENDNOTE : RES_POOLCHR_FOOTNOTE ) );
- pFormat->Add( &const_cast<SwClient&>(static_cast<const SwClient&>(aCharFormatDep)) );
+ const_cast<SwMultiDepend*>(&aDepends)->StartListening(pCharFormat);
}
- return const_cast<SwCharFormat*>(static_cast<const SwCharFormat*>(aCharFormatDep.GetRegisteredIn()));
+ return pCharFormat;
}
-void SwEndNoteInfo::SetCharFormat( SwCharFormat* pChFormat )
+void SwEndNoteInfo::SetCharFormat(SwCharFormat* pChFormat)
{
- OSL_ENSURE(pChFormat, "no CharFormat?");
- pChFormat->Add( &static_cast<SwClient&>(aCharFormatDep) );
+ aDepends.EndListening(pCharFormat);
+ pCharFormat = pChFormat;
+ aDepends.StartListening(pCharFormat);
}
-SwCharFormat* SwEndNoteInfo::GetAnchorCharFormat(SwDoc &rDoc) const
+SwCharFormat* SwEndNoteInfo::GetAnchorCharFormat(SwDoc& rDoc) const
{
- if( !aAnchorCharFormatDep.GetRegisteredIn() )
+ if(!pAnchorFormat || !aDepends.IsListeningTo(pAnchorFormat))
{
- SwCharFormat* pFormat = rDoc.getIDocumentStylePoolAccess().GetCharFormatFromPool( static_cast<sal_uInt16>(
+ pAnchorFormat = rDoc.getIDocumentStylePoolAccess().GetCharFormatFromPool( static_cast<sal_uInt16>(
m_bEndNote ? RES_POOLCHR_ENDNOTE_ANCHOR : RES_POOLCHR_FOOTNOTE_ANCHOR ) );
- pFormat->Add( &const_cast<SwClient&>(static_cast<const SwClient&>(aAnchorCharFormatDep)) );
+ const_cast<SwMultiDepend*>(&aDepends)->StartListening(pAnchorFormat);
}
- return const_cast<SwCharFormat*>(static_cast<const SwCharFormat*>(aAnchorCharFormatDep.GetRegisteredIn()));
+ return pAnchorFormat;
}
-void SwEndNoteInfo::SetAnchorCharFormat( SwCharFormat* pChFormat )
+void SwEndNoteInfo::SetAnchorCharFormat( SwCharFormat* pAnFormat )
{
- OSL_ENSURE(pChFormat, "no CharFormat?");
- pChFormat->Add( &static_cast<SwClient&>(aAnchorCharFormatDep) );
+ aDepends.EndListening(pAnchorFormat);
+ pAnchorFormat = pAnFormat;
+ aDepends.StartListening(pAnchorFormat);
}
-void SwEndNoteInfo::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
+void SwEndNoteInfo::SwClientNotify(const SwModify& rModify, const SfxHint& rHint)
{
- const sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0 ;
-
- if( RES_ATTRSET_CHG == nWhich ||
- RES_FMT_CHG == nWhich )
+ if (auto pLegacyHint = dynamic_cast<const sw::LegacyModifyHint*>(&rHint))
{
- SwDoc* pDoc;
- if( aCharFormatDep.GetRegisteredIn() )
- pDoc = static_cast<SwFormat*>(aCharFormatDep.GetRegisteredIn())->GetDoc();
- else
- pDoc = static_cast<SwFormat*>(aAnchorCharFormatDep.GetRegisteredIn())->GetDoc();
- SwFootnoteIdxs& rFootnoteIdxs = pDoc->GetFootnoteIdxs();
- for( size_t nPos = 0; nPos < rFootnoteIdxs.size(); ++nPos )
+ const sal_uInt16 nWhich = pLegacyHint->m_pOld
+ ? pLegacyHint->m_pOld->Which()
+ : pLegacyHint->m_pNew
+ ? pLegacyHint->m_pNew->Which() : 0 ;
+
+ if(RES_ATTRSET_CHG == nWhich || RES_FMT_CHG == nWhich)
{
- SwTextFootnote *pTextFootnote = rFootnoteIdxs[ nPos ];
- const SwFormatFootnote &rFootnote = pTextFootnote->GetFootnote();
- if ( rFootnote.IsEndNote() == m_bEndNote )
+ SwDoc* pDoc = pCharFormat
+ ? pCharFormat->GetDoc()
+ : pAnchorFormat->GetDoc();
+
+ SwFootnoteIdxs& rFootnoteIdxs = pDoc->GetFootnoteIdxs();
+ for(size_t nPos = 0; nPos < rFootnoteIdxs.size(); ++nPos)
{
- pTextFootnote->SetNumber(rFootnote.GetNumber(), rFootnote.GetNumStr());
+ SwTextFootnote *pTextFootnote = rFootnoteIdxs[ nPos ];
+ const SwFormatFootnote &rFootnote = pTextFootnote->GetFootnote();
+ if ( rFootnote.IsEndNote() == m_bEndNote )
+ {
+ pTextFootnote->SetNumber(rFootnote.GetNumber(), rFootnote.GetNumStr());
+ }
}
}
+ else if (nWhich == RES_OBJECTDYING)
+ {
+ if(&rModify == pFootnoteTextColl)
+ pFootnoteTextColl = nullptr;
+ if(&rModify == pPageDesc)
+ pPageDesc = nullptr;
+ if(&rModify == pCharFormat)
+ pCharFormat = nullptr;
+ if(&rModify == pAnchorFormat)
+ pAnchorFormat = nullptr;
+ }
}
- else
- CheckRegistration( pOld );
}
SwFootnoteInfo& SwFootnoteInfo::operator=(const SwFootnoteInfo& rInfo)
diff --git a/sw/source/core/unocore/unosett.cxx b/sw/source/core/unocore/unosett.cxx
index 8841f50de1db..c8490c4bf974 100644
--- a/sw/source/core/unocore/unosett.cxx
+++ b/sw/source/core/unocore/unosett.cxx
@@ -492,13 +492,11 @@ uno::Any SwXFootnoteProperties::getPropertyValue(const OUString& rPropertyName)
const SwCharFormat* pCharFormat = nullptr;
if( pEntry->nWID == WID_ANCHOR_CHARACTER_STYLE )
{
- if( rFootnoteInfo.GetAnchorCharFormatDep()->GetRegisteredIn() )
- pCharFormat = rFootnoteInfo.GetAnchorCharFormat(*pDoc);
+ pCharFormat = rFootnoteInfo.GetAnchorCharFormat(*pDoc);
}
else
{
- if( rFootnoteInfo.GetCharFormatDep()->GetRegisteredIn() )
- pCharFormat = rFootnoteInfo.GetCharFormat(*pDoc);
+ pCharFormat = rFootnoteInfo.GetCharFormat(*pDoc);
}
if( pCharFormat )
{
@@ -715,13 +713,11 @@ uno::Any SwXEndnoteProperties::getPropertyValue(const OUString& rPropertyName)
const SwCharFormat* pCharFormat = nullptr;
if( pEntry->nWID == WID_ANCHOR_CHARACTER_STYLE )
{
- if( rEndInfo.GetAnchorCharFormatDep()->GetRegisteredIn() )
- pCharFormat = rEndInfo.GetAnchorCharFormat(*pDoc);
+ pCharFormat = rEndInfo.GetAnchorCharFormat(*pDoc);
}
else
{
- if( rEndInfo.GetCharFormatDep()->GetRegisteredIn() )
- pCharFormat = rEndInfo.GetCharFormat(*pDoc);
+ pCharFormat = rEndInfo.GetCharFormat(*pDoc);
}
if( pCharFormat )
{