From ced60a5fa7824caff07846d7dd8abad3c0f31b55 Mon Sep 17 00:00:00 2001 From: Bjoern Michaelsen Date: Fri, 26 Jan 2018 02:16:21 +0100 Subject: introduce SwClient::StartListeningToSameModifyAs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ... as it is a common pattern Change-Id: Ie6a9b803e1e763fb0c01d808fac107df88f79460 Reviewed-on: https://gerrit.libreoffice.org/48647 Tested-by: Jenkins Reviewed-by: Björn Michaelsen --- sw/inc/calbck.hxx | 1 + sw/source/core/attr/calbck.cxx | 8 ++++++++ sw/source/core/attr/format.cxx | 17 ++++++----------- sw/source/core/doc/acmplwrd.cxx | 5 +---- sw/source/core/doc/docftn.cxx | 36 +++++++----------------------------- sw/source/core/doc/lineinfo.cxx | 8 ++------ sw/source/core/doc/number.cxx | 5 +---- 7 files changed, 26 insertions(+), 54 deletions(-) (limited to 'sw') diff --git a/sw/inc/calbck.hxx b/sw/inc/calbck.hxx index 06b6266bd32d..ea4181a190ea 100644 --- a/sw/inc/calbck.hxx +++ b/sw/inc/calbck.hxx @@ -133,6 +133,7 @@ public: const SwModify* GetRegisteredIn() const { return m_pRegisteredIn; } SwModify* GetRegisteredIn() { return m_pRegisteredIn; } void EndListeningAll(); + void StartListeningToSameModifyAs(const SwClient&); // get information about attribute diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx index 400792527a00..98376e649a93 100644 --- a/sw/source/core/attr/calbck.cxx +++ b/sw/source/core/attr/calbck.cxx @@ -68,6 +68,14 @@ void SwClient::SwClientNotify(const SwModify&, const SfxHint& rHint) } }; +void SwClient::StartListeningToSameModifyAs(const SwClient& other) +{ + if(other.m_pRegisteredIn) + other.m_pRegisteredIn->Add(this); + else + EndListeningAll(); +} + void SwClient::EndListeningAll() { if(m_pRegisteredIn) diff --git a/sw/source/core/attr/format.cxx b/sw/source/core/attr/format.cxx index f526a300cbef..3ef7ada2ffcb 100644 --- a/sw/source/core/attr/format.cxx +++ b/sw/source/core/attr/format.cxx @@ -125,19 +125,14 @@ SwFormat &SwFormat::operator=(const SwFormat& rFormat) ModifyNotification( &aChgOld, &aChgNew ); // send all modified ones } - if( GetRegisteredIn() != rFormat.GetRegisteredIn() ) + if(GetRegisteredIn() != rFormat.GetRegisteredIn()) { - EndListeningAll(); - if( rFormat.GetRegisteredIn() ) - { - const_cast(rFormat).GetRegisteredInNonConst()->Add(this); - m_aSet.SetParent( &rFormat.m_aSet ); - } - else - { - m_aSet.SetParent( nullptr ); - } + StartListeningToSameModifyAs(rFormat); + m_aSet.SetParent( GetRegisteredIn() + ? &rFormat.m_aSet + : nullptr); } + m_bAutoFormat = rFormat.m_bAutoFormat; m_bHidden = rFormat.m_bHidden; m_bAutoUpdateFormat = rFormat.m_bAutoUpdateFormat; diff --git a/sw/source/core/doc/acmplwrd.cxx b/sw/source/core/doc/acmplwrd.cxx index 90a2ac2d148c..77a887b21f95 100644 --- a/sw/source/core/doc/acmplwrd.cxx +++ b/sw/source/core/doc/acmplwrd.cxx @@ -133,10 +133,7 @@ SwAutoCompleteClient& SwAutoCompleteClient::operator=(const SwAutoCompleteClient { pAutoCompleteWord = rClient.pAutoCompleteWord; pDoc = rClient.pDoc; - if(rClient.GetRegisteredIn()) - const_cast(rClient.GetRegisteredIn())->Add(this); - else - EndListeningAll(); + StartListeningToSameModifyAs(rClient); return *this; } diff --git a/sw/source/core/doc/docftn.cxx b/sw/source/core/doc/docftn.cxx index 66b2587c5855..3ddfcf96c9ee 100644 --- a/sw/source/core/doc/docftn.cxx +++ b/sw/source/core/doc/docftn.cxx @@ -39,26 +39,10 @@ SwEndNoteInfo& SwEndNoteInfo::operator=(const SwEndNoteInfo& rInfo) { - if( rInfo.GetFootnoteTextColl() ) - rInfo.GetFootnoteTextColl()->Add(this); - else - EndListeningAll(); - - if ( rInfo.aPageDescDep.GetRegisteredIn() ) - const_cast(rInfo.aPageDescDep.GetRegisteredIn())->Add( &aPageDescDep ); - else - aPageDescDep.EndListeningAll(); - - if ( rInfo.aCharFormatDep.GetRegisteredIn() ) - const_cast(rInfo.aCharFormatDep.GetRegisteredIn())->Add( &aCharFormatDep ); - else - aCharFormatDep.EndListeningAll(); - - if ( rInfo.aAnchorCharFormatDep.GetRegisteredIn() ) - const_cast(rInfo.aAnchorCharFormatDep.GetRegisteredIn())->Add( - &aAnchorCharFormatDep ); - else - aAnchorCharFormatDep.EndListeningAll(); + StartListeningToSameModifyAs(rInfo); + aPageDescDep.StartListeningToSameModifyAs(rInfo.aPageDescDep); + aCharFormatDep.StartListeningToSameModifyAs(rInfo.aCharFormatDep); + aAnchorCharFormatDep.StartListeningToSameModifyAs(rInfo.aAnchorCharFormatDep); aFormat = rInfo.aFormat; nFootnoteOffset = rInfo.nFootnoteOffset; @@ -95,15 +79,9 @@ SwEndNoteInfo::SwEndNoteInfo(const SwEndNoteInfo& rInfo) : aFormat( rInfo.aFormat ), nFootnoteOffset( rInfo.nFootnoteOffset ) { - if( rInfo.aPageDescDep.GetRegisteredIn() ) - const_cast(rInfo.aPageDescDep.GetRegisteredIn())->Add( &aPageDescDep ); - - if( rInfo.aCharFormatDep.GetRegisteredIn() ) - const_cast(rInfo.aCharFormatDep.GetRegisteredIn())->Add( &aCharFormatDep ); - - if( rInfo.aAnchorCharFormatDep.GetRegisteredIn() ) - const_cast(rInfo.aAnchorCharFormatDep.GetRegisteredIn())->Add( - &aAnchorCharFormatDep ); + aPageDescDep.StartListeningToSameModifyAs(rInfo.aPageDescDep); + aCharFormatDep.StartListeningToSameModifyAs(rInfo.aCharFormatDep); + aAnchorCharFormatDep.StartListeningToSameModifyAs(rInfo.aAnchorCharFormatDep); } SwEndNoteInfo::SwEndNoteInfo() : diff --git a/sw/source/core/doc/lineinfo.cxx b/sw/source/core/doc/lineinfo.cxx index f8599bd94f1d..3774fa3f7604 100644 --- a/sw/source/core/doc/lineinfo.cxx +++ b/sw/source/core/doc/lineinfo.cxx @@ -76,16 +76,12 @@ SwLineNumberInfo::SwLineNumberInfo(const SwLineNumberInfo &rCpy ) : SwClient(), bCountInFlys( rCpy.IsCountInFlys() ), bRestartEachPage( rCpy.IsRestartEachPage() ) { - if ( rCpy.GetRegisteredIn() ) - const_cast(rCpy.GetRegisteredIn())->Add( this ); + StartListeningToSameModifyAs(rCpy); } SwLineNumberInfo& SwLineNumberInfo::operator=(const SwLineNumberInfo &rCpy) { - if ( rCpy.GetRegisteredIn() ) - const_cast(rCpy.GetRegisteredIn())->Add( this ); - else - EndListeningAll(); + StartListeningToSameModifyAs(rCpy); aType = rCpy.GetNumType(); aDivider = rCpy.GetDivider(); diff --git a/sw/source/core/doc/number.cxx b/sw/source/core/doc/number.cxx index 8912e30363b7..7a8574065a87 100644 --- a/sw/source/core/doc/number.cxx +++ b/sw/source/core/doc/number.cxx @@ -257,10 +257,7 @@ bool SwNumFormat::IsItemize() const SwNumFormat& SwNumFormat::operator=( const SwNumFormat& rNumFormat) { SvxNumberFormat::operator=(rNumFormat); - if( rNumFormat.GetRegisteredIn() ) - rNumFormat.GetRegisteredInNonConst()->Add( this ); - else - EndListeningAll(); + StartListeningToSameModifyAs(rNumFormat); //For i120928,record the cp info of graphic within bullet m_cGrfBulletCP = rNumFormat.m_cGrfBulletCP; return *this; -- cgit