[Libreoffice-commits] core.git: Branch 'libreoffice-6-1' - sw/inc sw/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Jul 18 21:44:20 UTC 2018


 sw/inc/calbck.hxx                |   44 ++++++++
 sw/inc/ndtxt.hxx                 |    1 
 sw/inc/node.hxx                  |   15 +--
 sw/source/core/docnode/node.cxx  |  191 ++++++++++++++++++++-------------------
 sw/source/core/txtnode/ndtxt.cxx |  134 +++++++++++++--------------
 5 files changed, 217 insertions(+), 168 deletions(-)

New commits:
commit a6fc577ca0303006e5668f52ffc93c3cdf0effd6
Author:     Xisco Fauli <xiscofauli at libreoffice.org>
AuthorDate: Mon Jul 16 21:49:47 2018 +0200
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Wed Jul 18 23:43:57 2018 +0200

    tdf#118738: use SwDepend instead of WriterMultiListener in SwContentNode
    
    This reverts commit 83243003b46dfb258c2b41049b0e1cb82a2d7ddb
    
    use WriterMultiListener instead of SwDepend in SwContentNode
    - also move SwContentNode and SwTextNode from
      Modify to SwClientNotify
    - this removes the last public use of SwDepend, which should now become
      an implementation detail of WriterMultiListener
    
    and commit ecf50fe71596c3edba8ce437481ab80ae1cd8935
    
    remove now obsolete SwDepend
    
    Revert them for now ( specially before the relese of LibreOffice 6.1 )
    until a fix for the bugs listed in tdf#118738 is provided
    
    Change-Id: I174feb3b092ff31b4c4837011c31343296c0c693
    Reviewed-on: https://gerrit.libreoffice.org/57698
    Tested-by: Jenkins
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/sw/inc/calbck.hxx b/sw/inc/calbck.hxx
index 967e4be6a314..a8deff0a772b 100644
--- a/sw/inc/calbck.hxx
+++ b/sw/inc/calbck.hxx
@@ -223,6 +223,50 @@ public:
     bool HasOnlyOneListener() { return m_pWriterListeners && m_pWriterListeners->IsLast(); }
 };
 
+// SwDepend
+
+/*
+ * Helper class for objects that need to depend on more than one SwClient
+ */
+class SW_DLLPUBLIC SwDepend final : public SwClient
+{
+    SwClient *m_pToTell;
+
+public:
+    SwDepend(SwClient *pTellHim, SwModify *pDepend) : SwClient(pDepend), m_pToTell(pTellHim) {}
+    SwDepend(SwDepend&) = delete;
+    SwDepend(SwDepend&& o)
+        : SwClient(std::move(o)), m_pToTell(o.m_pToTell)
+    {
+        o.m_pToTell = nullptr;
+    }
+
+    /** get Client information */
+    virtual bool GetInfo( SfxPoolItem& rInfo) const override
+        { return m_pToTell == nullptr || m_pToTell->GetInfo( rInfo ); }
+private:
+    virtual void Modify( const SfxPoolItem* pOldValue, const SfxPoolItem *pNewValue ) override
+    {
+        SwClientNotify(*GetRegisteredIn(), sw::LegacyModifyHint(pOldValue, pNewValue));
+    }
+    virtual void SwClientNotify( const SwModify& rModify, const SfxHint& rHint ) override
+    {
+        if (auto pLegacyHint = dynamic_cast<const sw::LegacyModifyHint*>(&rHint))
+        {
+            if( pLegacyHint->m_pNew && pLegacyHint->m_pNew->Which() == RES_OBJECTDYING )
+            {
+                auto pModifyChanged = CheckRegistration(pLegacyHint->m_pOld);
+                if(pModifyChanged)
+                    m_pToTell->SwClientNotify(rModify, *pModifyChanged);
+            }
+            else if( m_pToTell )
+                m_pToTell->ModifyNotification(pLegacyHint->m_pOld, pLegacyHint->m_pNew);
+        }
+        else if(m_pToTell)
+            m_pToTell->SwClientNotifyCall(rModify, rHint);
+    }
+};
+
 template<typename TElementType, typename TSource, sw::IteratorMode eMode> class SwIterator;
 
 namespace sw
diff --git a/sw/inc/ndtxt.hxx b/sw/inc/ndtxt.hxx
index d1a8801eb9c7..e40e056a1964 100644
--- a/sw/inc/ndtxt.hxx
+++ b/sw/inc/ndtxt.hxx
@@ -205,6 +205,7 @@ public:
 
 protected:
     /// for hanging TextFormatCollections somewhere else (Outline-Numbering!)
+    virtual void Modify( const SfxPoolItem*, const SfxPoolItem* ) override;
     virtual void SwClientNotify( const SwModify&, const SfxHint& ) override;
 
 public:
diff --git a/sw/inc/node.hxx b/sw/inc/node.hxx
index 1a8a4dc69c82..d8ab5576feff 100644
--- a/sw/inc/node.hxx
+++ b/sw/inc/node.hxx
@@ -360,8 +360,9 @@ private:
 class SW_DLLPUBLIC SwContentNode: public SwModify, public SwNode, public SwIndexReg
 {
 
-    sw::WriterMultiListener m_aCondCollListener;
-    SwFormatColl* m_pCondColl;
+//FEATURE::CONDCOLL
+    std::unique_ptr<SwDepend> m_pCondColl;
+//FEATURE::CONDCOLL
     mutable bool mbSetModifyAtAttr;
 
 protected:
@@ -382,7 +383,7 @@ protected:
        SwAttrSet (handle): */
     sal_uInt16 ClearItemsFromAttrSet( const std::vector<sal_uInt16>& rWhichIds );
 
-    virtual void SwClientNotify( const SwModify&, const SfxHint& rHint) override;
+    virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) override;
 
 public:
 
@@ -718,14 +719,14 @@ inline const SwDoc* SwNode::GetDoc() const
 
 inline SwFormatColl* SwContentNode::GetCondFormatColl() const
 {
-    return m_pCondColl;
+    return m_pCondColl ? static_cast<SwFormatColl*>(m_pCondColl->GetRegisteredIn()) : nullptr;
 }
 
 inline SwFormatColl& SwContentNode::GetAnyFormatColl() const
 {
-    return m_pCondColl
-            ? *m_pCondColl
-            : *const_cast<SwFormatColl*>(static_cast<const SwFormatColl*>(GetRegisteredIn()));
+    return m_pCondColl && m_pCondColl->GetRegisteredIn()
+                ? *static_cast<SwFormatColl*>(m_pCondColl->GetRegisteredIn())
+                : *const_cast<SwFormatColl*>(static_cast<const SwFormatColl*>(GetRegisteredIn()));
 }
 
 inline const SwAttrSet& SwContentNode::GetSwAttrSet() const
diff --git a/sw/source/core/docnode/node.cxx b/sw/source/core/docnode/node.cxx
index 7abe6c8b07e9..f4fcda3d1229 100644
--- a/sw/source/core/docnode/node.cxx
+++ b/sw/source/core/docnode/node.cxx
@@ -1004,7 +1004,6 @@ SwContentNode::SwContentNode( const SwNodeIndex &rWhere, const SwNodeType nNdTyp
                             SwFormatColl *pColl )
     : SwModify( pColl ),     // CursorsShell, FrameFormat,
     SwNode( rWhere, nNdType ),
-    m_aCondCollListener( *this ),
     m_pCondColl( nullptr ),
     mbSetModifyAtAttr( false )
 {
@@ -1019,94 +1018,91 @@ SwContentNode::~SwContentNode()
         DelFrames(false);
     }
 
-    m_aCondCollListener.EndListeningAll();
-    m_pCondColl = nullptr;
+    m_pCondColl.reset();
 
     if ( mpAttrSet.get() && mbSetModifyAtAttr )
         const_cast<SwAttrSet*>(static_cast<const SwAttrSet*>(mpAttrSet.get()))->SetModifyAtAttr( nullptr );
 }
 
-void SwContentNode::SwClientNotify( const SwModify&, const SfxHint& rHint)
+void SwContentNode::Modify( const SfxPoolItem* pOldValue, const SfxPoolItem* pNewValue )
 {
-    if (auto pLegacyHint = dynamic_cast<const sw::LegacyModifyHint*>(&rHint))
-    {
-        const sal_uInt16 nWhich = pLegacyHint->m_pOld
-                ? pLegacyHint->m_pOld->Which()
-                : pLegacyHint->m_pNew
-                ? pLegacyHint->m_pNew->Which()
-                : 0 ;
+    sal_uInt16 nWhich = pOldValue ? pOldValue->Which() :
+                    pNewValue ? pNewValue->Which() : 0 ;
 
-        bool bSetParent = false;
-        bool bCalcHidden = false;
-        SwFormatColl* pFormatColl = nullptr;
-        switch(nWhich)
+    switch( nWhich )
+    {
+    case RES_OBJECTDYING :
+        if (pNewValue)
         {
-            case RES_OBJECTDYING:
+            SwFormat * pFormat = static_cast<SwFormat *>( static_cast<const SwPtrMsgPoolItem *>(pNewValue)->pObject );
+
+            // Do not mangle pointers if it is the upper-most format!
+            if( GetRegisteredIn() == pFormat )
+            {
+                if( pFormat->GetRegisteredIn() )
                 {
-                    SwFormat* pFormat = pLegacyHint->m_pNew
-                            ? static_cast<SwFormat*>(static_cast<const SwPtrMsgPoolItem*>(pLegacyHint->m_pNew)->pObject)
-                            : nullptr;
-                    // Do not mangle pointers if it is the upper-most format!
-                    if(pFormat && GetRegisteredIn() == pFormat)
-                    {
-                        if(pFormat->GetRegisteredIn())
-                        {
-                            // If Parent, register anew in the new Parent
-                            pFormat->GetRegisteredIn()->Add(this);
-                            pFormatColl = GetFormatColl();
-                        }
-                        else
-                            EndListeningAll();
-                        bSetParent = true;
-                    }
+                    // If Parent, register anew in the new Parent
+                    pFormat->GetRegisteredIn()->Add( this );
+                    if ( GetpSwAttrSet() )
+                        AttrSetHandleHelper::SetParent( mpAttrSet, *this, GetFormatColl(), GetFormatColl() );
                 }
-                break;
-
-            case RES_FMT_CHG:
-                // If the Format parent was switched, register the Attrset at the new one
-                // Skip own Modify!
-                if(GetpSwAttrSet()
-                        && pLegacyHint->m_pNew
-                        && static_cast<const SwFormatChg*>(pLegacyHint->m_pNew)->pChangedFormat == GetRegisteredIn())
+                else
                 {
-                    pFormatColl = GetFormatColl();
-                    bSetParent = true;
+                    // Else register anyways when dying
+                    EndListeningAll();
+                    if ( GetpSwAttrSet() )
+                        AttrSetHandleHelper::SetParent( mpAttrSet, *this, nullptr, nullptr );
                 }
-                break;
-
-            case RES_CONDCOLL_CONDCHG:
-                if(pLegacyHint->m_pNew
-                        && static_cast<const SwCondCollCondChg*>(pLegacyHint->m_pNew)->pChangedFormat == GetRegisteredIn()
-                        && &GetNodes() == &GetDoc()->GetNodes() )
-                    ChkCondColl();
-                return;    // Do not pass through to the base class/Frames
-
-            case RES_ATTRSET_CHG:
-                if (GetNodes().IsDocNodes()
-                        && IsTextNode()
-                        && pLegacyHint->m_pOld
-                        && SfxItemState::SET == static_cast<const SwAttrSetChg*>(pLegacyHint->m_pOld)->GetChgSet()->GetItemState(RES_CHRATR_HIDDEN, false))
-                    bCalcHidden = true;
-                break;
-
-            case RES_UPDATE_ATTR:
-                if (GetNodes().IsDocNodes()
-                        && IsTextNode()
-                        && pLegacyHint->m_pNew
-                        && RES_ATTRSET_CHG == static_cast<const SwUpdateAttr*>(pLegacyHint->m_pNew)->getWhichAttr())
-                    bCalcHidden = true;
-                break;
+            }
         }
-        if(bSetParent && GetpSwAttrSet())
-            AttrSetHandleHelper::SetParent(mpAttrSet, *this, pFormatColl, pFormatColl);
-        if(bCalcHidden)
-            static_cast<SwTextNode*>(this)->SetCalcHiddenCharFlags();
-        NotifyClients(pLegacyHint->m_pOld, pLegacyHint->m_pNew);
-    }
-    else if (auto pModifyChangedHint = dynamic_cast<const sw::ModifyChangedHint*>(&rHint))
-    {
-        m_pCondColl = const_cast<SwFormatColl*>(static_cast<const SwFormatColl*>(pModifyChangedHint->m_pNew));
+        break;
+
+    case RES_FMT_CHG:
+        // If the Format parent was switched, register the Attrset at the new one
+        // Skip own Modify!
+        if( GetpSwAttrSet() && pNewValue &&
+            static_cast<const SwFormatChg*>(pNewValue)->pChangedFormat == GetRegisteredIn() )
+        {
+            // Attach Set to the new parent
+            AttrSetHandleHelper::SetParent( mpAttrSet, *this, GetFormatColl(), GetFormatColl() );
+        }
+        break;
+
+//FEATURE::CONDCOLL
+    case RES_CONDCOLL_CONDCHG:
+        if( pNewValue && static_cast<const SwCondCollCondChg*>(pNewValue)->pChangedFormat == GetRegisteredIn() &&
+            &GetNodes() == &GetDoc()->GetNodes() )
+        {
+            ChkCondColl();
+        }
+        return ;    // Do not pass through to the base class/Frames
+//FEATURE::CONDCOLL
+
+    case RES_ATTRSET_CHG:
+        if (GetNodes().IsDocNodes() && IsTextNode() && pOldValue)
+        {
+            if( SfxItemState::SET == static_cast<const SwAttrSetChg*>(pOldValue)->GetChgSet()->GetItemState(
+                RES_CHRATR_HIDDEN, false ) )
+            {
+                static_cast<SwTextNode*>(this)->SetCalcHiddenCharFlags();
+            }
+        }
+        break;
+
+    case RES_UPDATE_ATTR:
+        if (GetNodes().IsDocNodes() && IsTextNode() && pNewValue)
+        {
+            const sal_uInt16 nTmp = static_cast<const SwUpdateAttr*>(pNewValue)->getWhichAttr();
+            if ( RES_ATTRSET_CHG == nTmp )
+            {
+                // TODO: anybody wants to do some optimization here?
+                static_cast<SwTextNode*>(this)->SetCalcHiddenCharFlags();
+            }
+        }
+        break;
     }
+
+    NotifyClients( pOldValue, pNewValue );
 }
 
 bool SwContentNode::InvalidateNumRule()
@@ -1165,11 +1161,19 @@ SwFormatColl *SwContentNode::ChgFormatColl( SwFormatColl *pNewColl )
         if( GetpSwAttrSet() )
             AttrSetHandleHelper::SetParent( mpAttrSet, *this, pNewColl, pNewColl );
 
-        SetCondFormatColl( nullptr );
+//FEATURE::CONDCOLL
+        // TODO: HACK: We need to recheck this condition according to the new template!
+        if( true /*pNewColl */ )
+        {
+            SetCondFormatColl( nullptr );
+        }
+//FEATURE::CONDCOLL
 
         if( !IsModifyLocked() )
         {
-            ChkCondColl();
+            SwFormatChg aTmp1( pOldColl );
+            SwFormatChg aTmp2( pNewColl );
+            SwContentNode::Modify( &aTmp1, &aTmp2 );
         }
     }
     if ( IsInCache() )
@@ -1752,29 +1756,32 @@ bool SwContentNode::CanJoinPrev( SwNodeIndex* pIdx ) const
     return true;
 }
 
-void SwContentNode::SetCondFormatColl(SwFormatColl* pColl)
+//FEATURE::CONDCOLL
+void SwContentNode::SetCondFormatColl( SwFormatColl* pColl )
 {
     if( (!pColl && m_pCondColl) || ( pColl && !m_pCondColl ) ||
         ( pColl && pColl != m_pCondColl->GetRegisteredIn() ) )
     {
         SwFormatColl* pOldColl = GetCondFormatColl();
-        m_aCondCollListener.EndListeningAll();
-        if(pColl)
-            m_aCondCollListener.StartListening(pColl);
-        m_pCondColl = pColl;
-        if(GetpSwAttrSet())
-            AttrSetHandleHelper::SetParent(mpAttrSet, *this, &GetAnyFormatColl(), GetFormatColl());
-
-        if(!IsModifyLocked())
+        m_pCondColl.reset();
+        if( pColl )
+            m_pCondColl.reset(new SwDepend( this, pColl ));
+
+        if( GetpSwAttrSet() )
+        {
+            AttrSetHandleHelper::SetParent( mpAttrSet, *this, &GetAnyFormatColl(), GetFormatColl() );
+        }
+
+        if( !IsModifyLocked() )
         {
-            SwFormatChg aTmp1(pOldColl ? pOldColl : GetFormatColl());
-            SwFormatChg aTmp2(pColl ? pColl : GetFormatColl());
-            NotifyClients(&aTmp1, &aTmp2);
+            SwFormatChg aTmp1( pOldColl ? pOldColl : GetFormatColl() );
+            SwFormatChg aTmp2( pColl ? pColl : GetFormatColl() );
+            NotifyClients( &aTmp1, &aTmp2 );
         }
-        if(IsInCache())
+        if( IsInCache() )
         {
-            SwFrame::GetCache().Delete(this);
-            SetInCache(false);
+            SwFrame::GetCache().Delete( this );
+            SetInCache( false );
         }
     }
 }
diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index e8106bb859fe..f78c47b47242 100755
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -3590,6 +3590,67 @@ namespace {
     // End of method <HandleModifyAtTextNode>
 }
 
+void SwTextNode::Modify( const SfxPoolItem* pOldValue, const SfxPoolItem* pNewValue )
+{
+    bool bWasNotifiable = m_bNotifiable;
+    m_bNotifiable = false;
+
+    // Override Modify so that deleting styles works properly (outline
+    // numbering!).
+    // Never call ChgTextCollUpdateNum for Nodes in Undo.
+    if( pOldValue && pNewValue && RES_FMT_CHG == pOldValue->Which() &&
+        GetRegisteredIn() == static_cast<const SwFormatChg*>(pNewValue)->pChangedFormat &&
+        GetNodes().IsDocNodes() )
+    {
+        ChgTextCollUpdateNum(
+                        static_cast<const SwTextFormatColl*>(static_cast<const SwFormatChg*>(pOldValue)->pChangedFormat),
+                        static_cast<const SwTextFormatColl*>(static_cast<const SwFormatChg*>(pNewValue)->pChangedFormat) );
+    }
+
+    // reset fill information
+    if (maFillAttributes.get() && pNewValue)
+    {
+        const sal_uInt16 nWhich = pNewValue->Which();
+        bool bReset(RES_FMT_CHG == nWhich); // ..on format change (e.g. style changed)
+
+        if(!bReset && RES_ATTRSET_CHG == nWhich) // ..on ItemChange from DrawingLayer FillAttributes
+        {
+            SfxItemIter aIter(*static_cast<const SwAttrSetChg*>(pNewValue)->GetChgSet());
+
+            for(const SfxPoolItem* pItem = aIter.FirstItem(); pItem && !bReset; pItem = aIter.NextItem())
+            {
+                bReset = !IsInvalidItem(pItem) && pItem->Which() >= XATTR_FILL_FIRST && pItem->Which() <= XATTR_FILL_LAST;
+            }
+        }
+
+        if(bReset)
+        {
+            maFillAttributes.reset();
+        }
+    }
+
+    if ( !mbInSetOrResetAttr )
+    {
+        HandleModifyAtTextNode( *this, pOldValue, pNewValue );
+    }
+
+    SwContentNode::Modify( pOldValue, pNewValue );
+
+    SwDoc * pDoc = GetDoc();
+    // #125329# - assure that text node is in document nodes array
+    if ( pDoc && !pDoc->IsInDtor() && &pDoc->GetNodes() == &GetNodes() )
+    {
+        pDoc->GetNodes().UpdateOutlineNode(*this);
+    }
+
+    m_bNotifiable = bWasNotifiable;
+
+    if (pOldValue && (RES_REMOVE_UNO_OBJECT == pOldValue->Which()))
+    {   // invalidate cached uno object
+        SetXParagraph(css::uno::Reference<css::text::XTextContent>(nullptr));
+    }
+}
+
 SwFormatColl* SwTextNode::ChgFormatColl( SwFormatColl *pNewColl )
 {
     OSL_ENSURE( pNewColl,"ChgFormatColl: Collectionpointer has value 0." );
@@ -4919,75 +4980,10 @@ bool SwTextNode::IsInContent() const
 
 void SwTextNode::SwClientNotify( const SwModify& rModify, const SfxHint& rHint )
 {
-    if (auto pLegacyHint = dynamic_cast<const sw::LegacyModifyHint*>(&rHint))
-    {
-        bool bWasNotifiable = m_bNotifiable;
-        m_bNotifiable = false;
-
-        const auto pOldValue = pLegacyHint->m_pOld;
-        const auto pNewValue = pLegacyHint->m_pNew;
-        // Override Modify so that deleting styles works properly (outline
-        // numbering!).
-        // Never call ChgTextCollUpdateNum for Nodes in Undo.
-        if( pOldValue
-                && pNewValue
-                && RES_FMT_CHG == pOldValue->Which()
-                && GetRegisteredIn() == static_cast<const SwFormatChg*>(pNewValue)->pChangedFormat
-                && GetNodes().IsDocNodes() )
-        {
-            ChgTextCollUpdateNum(
-                    static_cast<const SwTextFormatColl*>(static_cast<const SwFormatChg*>(pOldValue)->pChangedFormat),
-                    static_cast<const SwTextFormatColl*>(static_cast<const SwFormatChg*>(pNewValue)->pChangedFormat) );
-        }
-
-        // reset fill information
-        if (maFillAttributes.get() && pNewValue)
-        {
-            const sal_uInt16 nWhich = pNewValue->Which();
-            bool bReset(RES_FMT_CHG == nWhich); // ..on format change (e.g. style changed)
-
-            if(!bReset && RES_ATTRSET_CHG == nWhich) // ..on ItemChange from DrawingLayer FillAttributes
-            {
-                SfxItemIter aIter(*static_cast<const SwAttrSetChg*>(pNewValue)->GetChgSet());
-
-                for(const SfxPoolItem* pItem = aIter.FirstItem(); pItem && !bReset; pItem = aIter.NextItem())
-                {
-                    bReset = !IsInvalidItem(pItem) && pItem->Which() >= XATTR_FILL_FIRST && pItem->Which() <= XATTR_FILL_LAST;
-                }
-            }
-
-            if(bReset)
-            {
-                maFillAttributes.reset();
-            }
-        }
-
-        if ( !mbInSetOrResetAttr )
-        {
-            HandleModifyAtTextNode( *this, pOldValue, pNewValue );
-        }
-
-        SwContentNode::SwClientNotify(rModify, rHint);
-
-        SwDoc* pDoc = GetDoc();
-        // #125329# - assure that text node is in document nodes array
-        if ( pDoc && !pDoc->IsInDtor() && &pDoc->GetNodes() == &GetNodes() )
-        {
-            pDoc->GetNodes().UpdateOutlineNode(*this);
-        }
-
-        m_bNotifiable = bWasNotifiable;
-
-        if (pOldValue && (RES_REMOVE_UNO_OBJECT == pOldValue->Which()))
-        {   // invalidate cached uno object
-            SetXParagraph(css::uno::Reference<css::text::XTextContent>(nullptr));
-        }
-    }
-    else if (auto pHint = dynamic_cast<const SwAttrHint*>(&rHint))
-    {
-        if ( pHint && &rModify == GetRegisteredIn() )
-            ChkCondColl();
-    }
+    SwClient::SwClientNotify(rModify, rHint);
+    const SwAttrHint* pHint = dynamic_cast<const SwAttrHint*>(&rHint);
+    if ( pHint && &rModify == GetRegisteredIn() )
+        ChkCondColl();
 }
 
 uno::Reference< rdf::XMetadatable >


More information about the Libreoffice-commits mailing list