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:
const SwModify* GetRegisteredIn() const { return m_pRegisteredIn; }
SwModify* GetRegisteredIn() { return m_pRegisteredIn; }
void EndListeningAll();
void StartListeningToSameModifyAs(const SwClient&);
// get information about attribute
......
......@@ -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)
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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() :
......
......@@ -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();
......
......@@ -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;
......
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