Kaydet (Commit) ced60a5f authored tarafından Bjoern Michaelsen's avatar Bjoern Michaelsen Kaydeden (comit) Björn Michaelsen

introduce SwClient::StartListeningToSameModifyAs

- ... as it is a common pattern

Change-Id: Ie6a9b803e1e763fb0c01d808fac107df88f79460
Reviewed-on: https://gerrit.libreoffice.org/48647Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarBjörn Michaelsen <bjoern.michaelsen@libreoffice.org>
üst 3edf5279
...@@ -133,6 +133,7 @@ public: ...@@ -133,6 +133,7 @@ public:
const SwModify* GetRegisteredIn() const { return m_pRegisteredIn; } const SwModify* GetRegisteredIn() const { return m_pRegisteredIn; }
SwModify* GetRegisteredIn() { return m_pRegisteredIn; } SwModify* GetRegisteredIn() { return m_pRegisteredIn; }
void EndListeningAll(); void EndListeningAll();
void StartListeningToSameModifyAs(const SwClient&);
// get information about attribute // get information about attribute
......
...@@ -68,6 +68,14 @@ void SwClient::SwClientNotify(const SwModify&, const SfxHint& rHint) ...@@ -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() void SwClient::EndListeningAll()
{ {
if(m_pRegisteredIn) if(m_pRegisteredIn)
......
...@@ -125,19 +125,14 @@ SwFormat &SwFormat::operator=(const SwFormat& rFormat) ...@@ -125,19 +125,14 @@ SwFormat &SwFormat::operator=(const SwFormat& rFormat)
ModifyNotification( &aChgOld, &aChgNew ); // send all modified ones ModifyNotification( &aChgOld, &aChgNew ); // send all modified ones
} }
if( GetRegisteredIn() != rFormat.GetRegisteredIn() ) if(GetRegisteredIn() != rFormat.GetRegisteredIn())
{ {
EndListeningAll(); StartListeningToSameModifyAs(rFormat);
if( rFormat.GetRegisteredIn() ) m_aSet.SetParent( GetRegisteredIn()
{ ? &rFormat.m_aSet
const_cast<SwFormat&>(rFormat).GetRegisteredInNonConst()->Add(this); : nullptr);
m_aSet.SetParent( &rFormat.m_aSet );
}
else
{
m_aSet.SetParent( nullptr );
}
} }
m_bAutoFormat = rFormat.m_bAutoFormat; m_bAutoFormat = rFormat.m_bAutoFormat;
m_bHidden = rFormat.m_bHidden; m_bHidden = rFormat.m_bHidden;
m_bAutoUpdateFormat = rFormat.m_bAutoUpdateFormat; m_bAutoUpdateFormat = rFormat.m_bAutoUpdateFormat;
......
...@@ -133,10 +133,7 @@ SwAutoCompleteClient& SwAutoCompleteClient::operator=(const SwAutoCompleteClient ...@@ -133,10 +133,7 @@ SwAutoCompleteClient& SwAutoCompleteClient::operator=(const SwAutoCompleteClient
{ {
pAutoCompleteWord = rClient.pAutoCompleteWord; pAutoCompleteWord = rClient.pAutoCompleteWord;
pDoc = rClient.pDoc; pDoc = rClient.pDoc;
if(rClient.GetRegisteredIn()) StartListeningToSameModifyAs(rClient);
const_cast<SwModify*>(rClient.GetRegisteredIn())->Add(this);
else
EndListeningAll();
return *this; return *this;
} }
......
...@@ -39,26 +39,10 @@ ...@@ -39,26 +39,10 @@
SwEndNoteInfo& SwEndNoteInfo::operator=(const SwEndNoteInfo& rInfo) SwEndNoteInfo& SwEndNoteInfo::operator=(const SwEndNoteInfo& rInfo)
{ {
if( rInfo.GetFootnoteTextColl() ) StartListeningToSameModifyAs(rInfo);
rInfo.GetFootnoteTextColl()->Add(this); aPageDescDep.StartListeningToSameModifyAs(rInfo.aPageDescDep);
else aCharFormatDep.StartListeningToSameModifyAs(rInfo.aCharFormatDep);
EndListeningAll(); aAnchorCharFormatDep.StartListeningToSameModifyAs(rInfo.aAnchorCharFormatDep);
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();
aFormat = rInfo.aFormat; aFormat = rInfo.aFormat;
nFootnoteOffset = rInfo.nFootnoteOffset; nFootnoteOffset = rInfo.nFootnoteOffset;
...@@ -95,15 +79,9 @@ SwEndNoteInfo::SwEndNoteInfo(const SwEndNoteInfo& rInfo) : ...@@ -95,15 +79,9 @@ SwEndNoteInfo::SwEndNoteInfo(const SwEndNoteInfo& rInfo) :
aFormat( rInfo.aFormat ), aFormat( rInfo.aFormat ),
nFootnoteOffset( rInfo.nFootnoteOffset ) nFootnoteOffset( rInfo.nFootnoteOffset )
{ {
if( rInfo.aPageDescDep.GetRegisteredIn() ) aPageDescDep.StartListeningToSameModifyAs(rInfo.aPageDescDep);
const_cast<SwModify*>(rInfo.aPageDescDep.GetRegisteredIn())->Add( &aPageDescDep ); aCharFormatDep.StartListeningToSameModifyAs(rInfo.aCharFormatDep);
aAnchorCharFormatDep.StartListeningToSameModifyAs(rInfo.aAnchorCharFormatDep);
if( rInfo.aCharFormatDep.GetRegisteredIn() )
const_cast<SwModify*>(rInfo.aCharFormatDep.GetRegisteredIn())->Add( &aCharFormatDep );
if( rInfo.aAnchorCharFormatDep.GetRegisteredIn() )
const_cast<SwModify*>(rInfo.aAnchorCharFormatDep.GetRegisteredIn())->Add(
&aAnchorCharFormatDep );
} }
SwEndNoteInfo::SwEndNoteInfo() : SwEndNoteInfo::SwEndNoteInfo() :
......
...@@ -76,16 +76,12 @@ SwLineNumberInfo::SwLineNumberInfo(const SwLineNumberInfo &rCpy ) : SwClient(), ...@@ -76,16 +76,12 @@ SwLineNumberInfo::SwLineNumberInfo(const SwLineNumberInfo &rCpy ) : SwClient(),
bCountInFlys( rCpy.IsCountInFlys() ), bCountInFlys( rCpy.IsCountInFlys() ),
bRestartEachPage( rCpy.IsRestartEachPage() ) bRestartEachPage( rCpy.IsRestartEachPage() )
{ {
if ( rCpy.GetRegisteredIn() ) StartListeningToSameModifyAs(rCpy);
const_cast<SwModify*>(rCpy.GetRegisteredIn())->Add( this );
} }
SwLineNumberInfo& SwLineNumberInfo::operator=(const SwLineNumberInfo &rCpy) SwLineNumberInfo& SwLineNumberInfo::operator=(const SwLineNumberInfo &rCpy)
{ {
if ( rCpy.GetRegisteredIn() ) StartListeningToSameModifyAs(rCpy);
const_cast<SwModify*>(rCpy.GetRegisteredIn())->Add( this );
else
EndListeningAll();
aType = rCpy.GetNumType(); aType = rCpy.GetNumType();
aDivider = rCpy.GetDivider(); aDivider = rCpy.GetDivider();
......
...@@ -257,10 +257,7 @@ bool SwNumFormat::IsItemize() const ...@@ -257,10 +257,7 @@ bool SwNumFormat::IsItemize() const
SwNumFormat& SwNumFormat::operator=( const SwNumFormat& rNumFormat) SwNumFormat& SwNumFormat::operator=( const SwNumFormat& rNumFormat)
{ {
SvxNumberFormat::operator=(rNumFormat); SvxNumberFormat::operator=(rNumFormat);
if( rNumFormat.GetRegisteredIn() ) StartListeningToSameModifyAs(rNumFormat);
rNumFormat.GetRegisteredInNonConst()->Add( this );
else
EndListeningAll();
//For i120928,record the cp info of graphic within bullet //For i120928,record the cp info of graphic within bullet
m_cGrfBulletCP = rNumFormat.m_cGrfBulletCP; m_cGrfBulletCP = rNumFormat.m_cGrfBulletCP;
return *this; return *this;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment