[Libreoffice-commits] core.git: sw/inc sw/source
Bjoern Michaelsen
bjoern.michaelsen at libreoffice.org
Sat May 5 06:14:33 UTC 2018
sw/inc/ndtxt.hxx | 1
sw/inc/node.hxx | 15 +--
sw/source/core/docnode/node.cxx | 191 ++++++++++++++++++---------------------
sw/source/core/txtnode/ndtxt.cxx | 134 ++++++++++++++-------------
4 files changed, 168 insertions(+), 173 deletions(-)
New commits:
commit 83243003b46dfb258c2b41049b0e1cb82a2d7ddb
Author: Bjoern Michaelsen <bjoern.michaelsen at libreoffice.org>
Date: Fri May 4 08:44:47 2018 +0200
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
Change-Id: I5ae3a7a091fb2b6bb3bce44a0adc4f41f07a0c30
Reviewed-on: https://gerrit.libreoffice.org/53835
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Björn Michaelsen <bjoern.michaelsen at libreoffice.org>
diff --git a/sw/inc/ndtxt.hxx b/sw/inc/ndtxt.hxx
index 269e66ed7516..56fbc4189371 100644
--- a/sw/inc/ndtxt.hxx
+++ b/sw/inc/ndtxt.hxx
@@ -198,7 +198,6 @@ 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 27078a918be4..1862bdf64d64 100644
--- a/sw/inc/node.hxx
+++ b/sw/inc/node.hxx
@@ -349,9 +349,8 @@ private:
class SW_DLLPUBLIC SwContentNode: public SwModify, public SwNode, public SwIndexReg
{
-//FEATURE::CONDCOLL
- std::unique_ptr<SwDepend> m_pCondColl;
-//FEATURE::CONDCOLL
+ sw::WriterMultiListener m_aCondCollListener;
+ SwFormatColl* m_pCondColl;
mutable bool mbSetModifyAtAttr;
protected:
@@ -372,7 +371,7 @@ protected:
SwAttrSet (handle): */
sal_uInt16 ClearItemsFromAttrSet( const std::vector<sal_uInt16>& rWhichIds );
- virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) override;
+ virtual void SwClientNotify( const SwModify&, const SfxHint& rHint) override;
public:
@@ -708,14 +707,14 @@ inline const SwDoc* SwNode::GetDoc() const
inline SwFormatColl* SwContentNode::GetCondFormatColl() const
{
- return m_pCondColl ? static_cast<SwFormatColl*>(m_pCondColl->GetRegisteredIn()) : nullptr;
+ return m_pCondColl;
}
inline SwFormatColl& SwContentNode::GetAnyFormatColl() const
{
- return m_pCondColl && m_pCondColl->GetRegisteredIn()
- ? *static_cast<SwFormatColl*>(m_pCondColl->GetRegisteredIn())
- : *const_cast<SwFormatColl*>(static_cast<const SwFormatColl*>(GetRegisteredIn()));
+ return m_pCondColl
+ ? *m_pCondColl
+ : *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 4253cd7ec1f4..337483f81de1 100644
--- a/sw/source/core/docnode/node.cxx
+++ b/sw/source/core/docnode/node.cxx
@@ -1002,6 +1002,7 @@ 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 )
{
@@ -1013,91 +1014,94 @@ SwContentNode::~SwContentNode()
// Thus, we need to delete all Frames in the dependency list.
DelFrames(false);
- m_pCondColl.reset();
+ m_aCondCollListener.EndListeningAll();
+ m_pCondColl = nullptr;
if ( mpAttrSet.get() && mbSetModifyAtAttr )
const_cast<SwAttrSet*>(static_cast<const SwAttrSet*>(mpAttrSet.get()))->SetModifyAtAttr( nullptr );
}
-void SwContentNode::Modify( const SfxPoolItem* pOldValue, const SfxPoolItem* pNewValue )
+void SwContentNode::SwClientNotify( const SwModify&, const SfxHint& rHint)
{
- sal_uInt16 nWhich = pOldValue ? pOldValue->Which() :
- pNewValue ? pNewValue->Which() : 0 ;
-
- switch( nWhich )
+ if (auto pLegacyHint = dynamic_cast<const sw::LegacyModifyHint*>(&rHint))
{
- case RES_OBJECTDYING :
- if (pNewValue)
- {
- SwFormat * pFormat = static_cast<SwFormat *>( static_cast<const SwPtrMsgPoolItem *>(pNewValue)->pObject );
+ const sal_uInt16 nWhich = pLegacyHint->m_pOld
+ ? pLegacyHint->m_pOld->Which()
+ : pLegacyHint->m_pNew
+ ? pLegacyHint->m_pNew->Which()
+ : 0 ;
- // Do not mangle pointers if it is the upper-most format!
- if( GetRegisteredIn() == pFormat )
- {
- if( pFormat->GetRegisteredIn() )
+ bool bSetParent = false;
+ bool bCalcHidden = false;
+ SwFormatColl* pFormatColl = nullptr;
+ switch(nWhich)
+ {
+ case RES_OBJECTDYING:
{
- // If Parent, register anew in the new Parent
- pFormat->GetRegisteredIn()->Add( this );
- if ( GetpSwAttrSet() )
- AttrSetHandleHelper::SetParent( mpAttrSet, *this, GetFormatColl(), GetFormatColl() );
+ 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;
+ }
}
- else
+ 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 register anyways when dying
- EndListeningAll();
- if ( GetpSwAttrSet() )
- AttrSetHandleHelper::SetParent( mpAttrSet, *this, nullptr, nullptr );
+ pFormatColl = GetFormatColl();
+ bSetParent = true;
}
- }
- }
- 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;
+
+ 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;
}
- 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));
}
-
- NotifyClients( pOldValue, pNewValue );
}
bool SwContentNode::InvalidateNumRule()
@@ -1156,19 +1160,11 @@ SwFormatColl *SwContentNode::ChgFormatColl( SwFormatColl *pNewColl )
if( GetpSwAttrSet() )
AttrSetHandleHelper::SetParent( mpAttrSet, *this, pNewColl, pNewColl );
-//FEATURE::CONDCOLL
- // TODO: HACK: We need to recheck this condition according to the new template!
- if( true /*pNewColl */ )
- {
- SetCondFormatColl( nullptr );
- }
-//FEATURE::CONDCOLL
+ SetCondFormatColl( nullptr );
if( !IsModifyLocked() )
{
- SwFormatChg aTmp1( pOldColl );
- SwFormatChg aTmp2( pNewColl );
- SwContentNode::Modify( &aTmp1, &aTmp2 );
+ ChkCondColl();
}
}
if ( IsInCache() )
@@ -1756,32 +1752,29 @@ bool SwContentNode::CanJoinPrev( SwNodeIndex* pIdx ) const
return true;
}
-//FEATURE::CONDCOLL
-void SwContentNode::SetCondFormatColl( SwFormatColl* pColl )
+void SwContentNode::SetCondFormatColl(SwFormatColl* pColl)
{
if( (!pColl && m_pCondColl) || ( pColl && !m_pCondColl ) ||
( pColl && pColl != m_pCondColl->GetRegisteredIn() ) )
{
SwFormatColl* pOldColl = GetCondFormatColl();
- m_pCondColl.reset();
- if( pColl )
- m_pCondColl.reset(new SwDepend( this, pColl ));
-
- if( GetpSwAttrSet() )
- {
- AttrSetHandleHelper::SetParent( mpAttrSet, *this, &GetAnyFormatColl(), GetFormatColl() );
- }
-
- if( !IsModifyLocked() )
+ m_aCondCollListener.EndListeningAll();
+ if(pColl)
+ m_aCondCollListener.StartListening(pColl);
+ m_pCondColl = 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 93f753645c41..389e2320c613 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -3549,67 +3549,6 @@ 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." );
@@ -4939,10 +4878,75 @@ bool SwTextNode::IsInContent() const
void SwTextNode::SwClientNotify( const SwModify& rModify, const SfxHint& rHint )
{
- SwClient::SwClientNotify(rModify, rHint);
- const SwAttrHint* pHint = dynamic_cast<const SwAttrHint*>(&rHint);
- if ( pHint && &rModify == GetRegisteredIn() )
- ChkCondColl();
+ 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();
+ }
}
uno::Reference< rdf::XMetadatable >
More information about the Libreoffice-commits
mailing list