summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjoern Michaelsen <bjoern.michaelsen@libreoffice.org>2018-01-26 02:16:21 +0100
committerBjoern Michaelsen <bjoern.michaelsen@libreoffice.org>2018-01-26 02:16:35 +0100
commit83e6cfd99b202afdb7f4103d9c1ecfe612219ddc (patch)
tree1c93a2385d97cca5111dd7eb3402fd38c90e3cd6
parent5872783c90250ad7c5794a1eafa0a1d7ef19dc6a (diff)
introduce SwClient::StartListeningToSameModifyAs
- ... as it is a common pattern Change-Id: Ie6a9b803e1e763fb0c01d808fac107df88f79460
-rw-r--r--sw/inc/calbck.hxx1
-rw-r--r--sw/source/core/attr/calbck.cxx8
-rw-r--r--sw/source/core/attr/format.cxx17
-rw-r--r--sw/source/core/doc/acmplwrd.cxx5
-rw-r--r--sw/source/core/doc/docftn.cxx36
-rw-r--r--sw/source/core/doc/lineinfo.cxx8
-rw-r--r--sw/source/core/doc/number.cxx5
7 files changed, 26 insertions, 54 deletions
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<SwFormat&>(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<SwModify*>(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<SwModify*>(rInfo.aPageDescDep.GetRegisteredIn())->Add( &aPageDescDep );
- else
- aPageDescDep.EndListeningAll();
-
- if ( rInfo.aCharFormatDep.GetRegisteredIn() )
- const_cast<SwModify*>(rInfo.aCharFormatDep.GetRegisteredIn())->Add( &aCharFormatDep );
- else
- aCharFormatDep.EndListeningAll();
-
- if ( rInfo.aAnchorCharFormatDep.GetRegisteredIn() )
- const_cast<SwModify*>(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<SwModify*>(rInfo.aPageDescDep.GetRegisteredIn())->Add( &aPageDescDep );
-
- if( rInfo.aCharFormatDep.GetRegisteredIn() )
- const_cast<SwModify*>(rInfo.aCharFormatDep.GetRegisteredIn())->Add( &aCharFormatDep );
-
- if( rInfo.aAnchorCharFormatDep.GetRegisteredIn() )
- const_cast<SwModify*>(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<SwModify*>(rCpy.GetRegisteredIn())->Add( this );
+ StartListeningToSameModifyAs(rCpy);
}
SwLineNumberInfo& SwLineNumberInfo::operator=(const SwLineNumberInfo &rCpy)
{
- if ( rCpy.GetRegisteredIn() )
- const_cast<SwModify*>(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;