[Libreoffice-commits] core.git: sw/inc sw/source

Bjoern Michaelsen bjoern.michaelsen at libreoffice.org
Tue Mar 13 21:41:05 UTC 2018


 sw/inc/pagedesc.hxx                |    5 +-
 sw/source/core/layout/pagedesc.cxx |   62 ++++++++++++++++++++++++++-----------
 2 files changed, 47 insertions(+), 20 deletions(-)

New commits:
commit efcb9a7078e08a367816b825d14419ddf351ff3e
Author: Bjoern Michaelsen <bjoern.michaelsen at libreoffice.org>
Date:   Tue Mar 13 00:04:04 2018 +0100

    use sw::WriterMultiListener instead of SwDepend in SwPageDesc
    
    Change-Id: Ifaf9c808e04e736d0a1f7eaf884b8674ac78e0f3
    Reviewed-on: https://gerrit.libreoffice.org/51189
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Björn Michaelsen <bjoern.michaelsen at libreoffice.org>

diff --git a/sw/inc/pagedesc.hxx b/sw/inc/pagedesc.hxx
index 60e5958de00e..c12d4349173a 100644
--- a/sw/inc/pagedesc.hxx
+++ b/sw/inc/pagedesc.hxx
@@ -146,7 +146,8 @@ class SW_DLLPUBLIC SwPageDesc : public SwModify
     // FIXME epicycles growing here - page margins need to be stored differently
     SwFrameFormat    m_FirstMaster;
     SwFrameFormat    m_FirstLeft;
-    SwDepend    m_Depend; ///< Because of grid alignment (Registerhaltigkeit).
+    sw::WriterMultiListener m_aDepends; ///< Because of grid alignment (Registerhaltigkeit).
+    mutable const SwTextFormatColl* m_pTextFormatColl;
     SwPageDesc *m_pFollow;
     sal_uInt16  m_nRegHeight; ///< Sentence spacing and fontascent of style.
     sal_uInt16  m_nRegAscent; ///< For grid alignment (Registerhaltigkeit).
@@ -177,7 +178,7 @@ class SW_DLLPUBLIC SwPageDesc : public SwModify
     };
 
 protected:
-    virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNewValue ) override;
+    virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
 
 public:
     const OUString& GetName() const { return m_StyleName; }
diff --git a/sw/source/core/layout/pagedesc.cxx b/sw/source/core/layout/pagedesc.cxx
index 65ee423f6f64..b1b1927f2418 100644
--- a/sw/source/core/layout/pagedesc.cxx
+++ b/sw/source/core/layout/pagedesc.cxx
@@ -45,7 +45,7 @@ SwPageDesc::SwPageDesc(const OUString& rName, SwFrameFormat *pFormat, SwDoc *con
     , m_Left( pDoc->GetAttrPool(), rName, pFormat )
     , m_FirstMaster( pDoc->GetAttrPool(), rName, pFormat )
     , m_FirstLeft( pDoc->GetAttrPool(), rName, pFormat )
-    , m_Depend( this, nullptr )
+    , m_aDepends(*this)
     , m_pFollow( this )
     , m_nRegHeight( 0 )
     , m_nRegAscent( 0 )
@@ -65,7 +65,8 @@ SwPageDesc::SwPageDesc( const SwPageDesc &rCpy )
     , m_Left( rCpy.GetLeft() )
     , m_FirstMaster( rCpy.GetFirstMaster() )
     , m_FirstLeft( rCpy.GetFirstLeft() )
-    , m_Depend( this, const_cast<SwModify*>(rCpy.m_Depend.GetRegisteredIn()) )
+    , m_aDepends(*this)
+    , m_pTextFormatColl(nullptr)
     , m_pFollow( rCpy.m_pFollow )
     , m_nRegHeight( rCpy.GetRegHeight() )
     , m_nRegAscent( rCpy.GetRegAscent() )
@@ -76,6 +77,11 @@ SwPageDesc::SwPageDesc( const SwPageDesc &rCpy )
     , m_IsFootnoteInfo( rCpy.GetFootnoteInfo() )
     , m_pdList( nullptr )
 {
+    if(rCpy.m_pTextFormatColl && const_cast<sw::WriterMultiListener*>(&rCpy.m_aDepends)->IsListeningTo(rCpy.m_pTextFormatColl))
+    {
+        m_pTextFormatColl = rCpy.m_pTextFormatColl;
+        m_aDepends.StartListening(const_cast<SwTextFormatColl*>(m_pTextFormatColl));
+    }
 }
 
 SwPageDesc & SwPageDesc::operator = (const SwPageDesc & rSrc)
@@ -86,6 +92,14 @@ SwPageDesc & SwPageDesc::operator = (const SwPageDesc & rSrc)
     m_Left = rSrc.m_Left;
     m_FirstMaster = rSrc.m_FirstMaster;
     m_FirstLeft = rSrc.m_FirstLeft;
+    m_aDepends.EndListeningAll();
+    if(rSrc.m_pTextFormatColl && const_cast<sw::WriterMultiListener*>(&rSrc.m_aDepends)->IsListeningTo(rSrc.m_pTextFormatColl))
+    {
+        m_pTextFormatColl = rSrc.m_pTextFormatColl;
+        m_aDepends.StartListening(const_cast<SwTextFormatColl*>(m_pTextFormatColl));
+    }
+    else
+        m_pTextFormatColl = nullptr;
 
     if (rSrc.m_pFollow == &rSrc)
         m_pFollow = this;
@@ -167,15 +181,13 @@ bool SwPageDesc::GetInfo( SfxPoolItem & rInfo ) const
 }
 
 /// set the style for the grid alignment
-void SwPageDesc::SetRegisterFormatColl( const SwTextFormatColl* pFormat )
+void SwPageDesc::SetRegisterFormatColl(const SwTextFormatColl* pFormat)
 {
-    if( pFormat != GetRegisterFormatColl() )
+    if(pFormat != m_pTextFormatColl)
     {
-        if( pFormat )
-            const_cast<SwTextFormatColl*>(pFormat)->Add(&m_Depend);
-        else
-            const_cast<SwTextFormatColl*>(GetRegisterFormatColl())->Remove(&m_Depend);
-
+        m_aDepends.EndListeningAll();
+        m_pTextFormatColl = pFormat;
+        m_aDepends.StartListening(const_cast<SwTextFormatColl*>(m_pTextFormatColl));
         RegisterChange();
     }
 }
@@ -183,8 +195,9 @@ void SwPageDesc::SetRegisterFormatColl( const SwTextFormatColl* pFormat )
 /// retrieve the style for the grid alignment
 const SwTextFormatColl* SwPageDesc::GetRegisterFormatColl() const
 {
-    const SwModify* pReg = m_Depend.GetRegisteredIn();
-    return static_cast<const SwTextFormatColl*>(pReg);
+    if(!const_cast<sw::WriterMultiListener*>(&m_aDepends)->IsListeningTo(m_pTextFormatColl))
+        m_pTextFormatColl = nullptr;
+    return m_pTextFormatColl;
 }
 
 /// notify all affected page frames
@@ -240,15 +253,28 @@ void SwPageDesc::RegisterChange()
 }
 
 /// special handling if the style of the grid alignment changes
-void SwPageDesc::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew )
+void SwPageDesc::SwClientNotify(const SwModify& rModify, const SfxHint& rHint)
 {
-    const sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
-    NotifyClients( pOld, pNew );
-
-    if ( (RES_ATTRSET_CHG == nWhich) || (RES_FMT_CHG == nWhich)
-        || isCHRATR(nWhich) || (RES_PARATR_LINESPACING == nWhich) )
+    if(auto pLegacyHint = dynamic_cast<const sw::LegacyModifyHint*>(&rHint))
     {
-        RegisterChange();
+        const sal_uInt16 nWhich = pLegacyHint->m_pOld
+                ? pLegacyHint->m_pOld->Which()
+                : pLegacyHint->m_pNew
+                ? pLegacyHint->m_pNew->Which()
+                : 0;
+        NotifyClients(pLegacyHint->m_pOld, pLegacyHint->m_pNew);
+        if((RES_ATTRSET_CHG == nWhich)
+                || (RES_FMT_CHG == nWhich)
+                || isCHRATR(nWhich)
+                || (RES_PARATR_LINESPACING == nWhich))
+            RegisterChange();
+    }
+    else if (auto pModifyChangedHint = dynamic_cast<const sw::ModifyChangedHint*>(&rHint))
+    {
+        if(m_pTextFormatColl == &rModify)
+            m_pTextFormatColl = static_cast<const SwTextFormatColl*>(pModifyChangedHint->m_pNew);
+        else
+            assert(false);
     }
 }
 


More information about the Libreoffice-commits mailing list