diff options
author | Michael Stahl <mst@openoffice.org> | 2010-01-08 17:14:00 +0100 |
---|---|---|
committer | Michael Stahl <mst@openoffice.org> | 2010-01-08 17:14:00 +0100 |
commit | c93ddde38115731d4e5ca2dd41f0dced93625cd7 (patch) | |
tree | 74002daa81f8c531f551b5efa120c9a264a630a9 /sw/source | |
parent | 82aba30102fe1cce3f6582bfbe29bacb7498363d (diff) |
swunolocking1: #i107771#: SwXDocumentIndexMark:
register at SwTOXMark instead of UnoCallBack.
implement instance caching with a WeakReference in SwTOXMark.
[the ODF export depends on caching: see XMLIndexMarkExport::GetID()]
Diffstat (limited to 'sw/source')
-rw-r--r-- | sw/source/core/docnode/nodes.cxx | 4 | ||||
-rw-r--r-- | sw/source/core/tox/tox.cxx | 34 | ||||
-rw-r--r-- | sw/source/core/txtnode/thints.cxx | 2 | ||||
-rw-r--r-- | sw/source/core/unocore/unocrsrhelper.cxx | 3 | ||||
-rw-r--r-- | sw/source/core/unocore/unoidx.cxx | 49 | ||||
-rw-r--r-- | sw/source/core/unocore/unoportenum.cxx | 8 |
6 files changed, 54 insertions, 46 deletions
diff --git a/sw/source/core/docnode/nodes.cxx b/sw/source/core/docnode/nodes.cxx index 29d9c61e1ad8..78008db5da00 100644 --- a/sw/source/core/docnode/nodes.cxx +++ b/sw/source/core/docnode/nodes.cxx @@ -48,6 +48,7 @@ #include <swddetbl.hxx> #include <frame.hxx> #include <txtatr.hxx> +#include <tox.hxx> // InvalidateTOXMark #include <docsh.hxx> #include <svtools/smplhint.hxx> @@ -341,7 +342,8 @@ void SwNodes::ChgNode( SwNodeIndex& rDelPos, ULONG nSz, break; case RES_TXTATR_TOXMARK: - nDelMsg = RES_TOXMARK_DELETED; + static_cast<SwTOXMark&>(pAttr->GetAttr()) + .InvalidateTOXMark(); break; case RES_TXTATR_REFMARK: diff --git a/sw/source/core/tox/tox.cxx b/sw/source/core/tox/tox.cxx index ddf9a2563a4b..5779b985346d 100644 --- a/sw/source/core/tox/tox.cxx +++ b/sw/source/core/tox/tox.cxx @@ -50,6 +50,7 @@ #include <paratr.hxx> #include <svx/tstpitem.hxx> #include <SwStyleNameMapper.hxx> +#include <hints.hxx> // SwPtrMsgPoolItem // -> #i21237# #include <algorithm> @@ -176,10 +177,11 @@ SwFormTokens lcl_GetAuthPattern(USHORT nTypeId) --------------------------------------------------------------------*/ - // Konstruktor fuers Default vom Attribut-Pool +/// pool default constructor SwTOXMark::SwTOXMark() - : SfxPoolItem( RES_TXTATR_TOXMARK ), - SwClient( 0 ), + : SfxPoolItem( RES_TXTATR_TOXMARK ) + , SwModify( 0 ) + , pTxtAttr( 0 ), bAutoGenerated(FALSE), bMainEntry(FALSE) @@ -188,8 +190,9 @@ SwTOXMark::SwTOXMark() SwTOXMark::SwTOXMark( const SwTOXType* pTyp ) - : SfxPoolItem( RES_TXTATR_TOXMARK ), - SwClient( (SwModify*)pTyp ), + : SfxPoolItem( RES_TXTATR_TOXMARK ) + , SwModify( const_cast<SwTOXType*>(pTyp) ) + , pTxtAttr( 0 ), nLevel( 0 ), bAutoGenerated(FALSE), bMainEntry(FALSE) @@ -198,8 +201,9 @@ SwTOXMark::SwTOXMark( const SwTOXType* pTyp ) SwTOXMark::SwTOXMark( const SwTOXMark& rCopy ) - : SfxPoolItem( RES_TXTATR_TOXMARK ), - SwClient((SwModify*)rCopy.GetRegisteredIn()), + : SfxPoolItem( RES_TXTATR_TOXMARK ) + , SwModify(rCopy.pRegisteredIn) + , aPrimaryKey( rCopy.aPrimaryKey ), aSecondaryKey( rCopy.aSecondaryKey ), aTextReading( rCopy.aTextReading ), aPrimaryKeyReading( rCopy.aPrimaryKeyReading ), @@ -230,6 +234,22 @@ SfxPoolItem* SwTOXMark::Clone( SfxItemPool* ) const return new SwTOXMark( *this ); } +void SwTOXMark::Modify(SfxPoolItem* pOld, SfxPoolItem* pNew) +{ + SwModify::Modify(pOld, pNew); + if (pOld && (RES_REMOVE_UNO_OBJECT == pOld->Which())) + { // invalidate cached uno object + SetXTOXMark(::com::sun::star::uno::Reference< + ::com::sun::star::text::XDocumentIndexMark>(0)); + } +} + +void SwTOXMark::InvalidateTOXMark() +{ + SwPtrMsgPoolItem aMsgHint( RES_REMOVE_UNO_OBJECT, + &static_cast<SwModify&>(*this) ); // cast to base class! + Modify(&aMsgHint, &aMsgHint); +} String SwTOXMark::GetText() const { diff --git a/sw/source/core/txtnode/thints.cxx b/sw/source/core/txtnode/thints.cxx index 3300294f9e4b..5fdbc0026353 100644 --- a/sw/source/core/txtnode/thints.cxx +++ b/sw/source/core/txtnode/thints.cxx @@ -1174,7 +1174,7 @@ void SwTxtNode::DestroyAttr( SwTxtAttr* pAttr ) break; case RES_TXTATR_TOXMARK: - nDelMsg = RES_TOXMARK_DELETED; + static_cast<SwTOXMark&>(pAttr->GetAttr()).InvalidateTOXMark(); break; case RES_TXTATR_REFMARK: diff --git a/sw/source/core/unocore/unocrsrhelper.cxx b/sw/source/core/unocore/unocrsrhelper.cxx index 642b0b5030aa..e5540bb9bc3b 100644 --- a/sw/source/core/unocore/unocrsrhelper.cxx +++ b/sw/source/core/unocore/unocrsrhelper.cxx @@ -313,7 +313,8 @@ sal_Bool getCrsrPropertyValue(const SfxItemPropertySimpleEntry& rEntry { if( pAny ) { - const SwTOXMark& rMark = pTxtAttr->GetTOXMark(); + SwTOXMark & rMark = + static_cast<SwTOXMark&>(pTxtAttr->GetAttr()); const uno::Reference< text::XDocumentIndexMark > xRef = SwXDocumentIndexMark::CreateXDocumentIndexMark( *rPam.GetDoc(), diff --git a/sw/source/core/unocore/unoidx.cxx b/sw/source/core/unocore/unoidx.cxx index 807b230c5b6d..db2ab16e5784 100644 --- a/sw/source/core/unocore/unoidx.cxx +++ b/sw/source/core/unocore/unoidx.cxx @@ -1598,7 +1598,7 @@ public: SwDoc *const pDoc, const enum TOXTypes eType, SwTOXType *const pType, SwTOXMark const*const pMark) - : SwClient((pDoc) ? pDoc->GetUnoCallBack() : 0) + : SwClient(const_cast<SwTOXMark*>(pMark)) , m_rPropSet( *aSwMapProvider.GetPropertySet(lcl_TypeToPropertyMap_Mark(eType))) , m_eTOXType(eType) @@ -1654,19 +1654,6 @@ void SwXDocumentIndexMark::Impl::Modify(SfxPoolItem *pOld, SfxPoolItem *pNew) { Invalidate(); } - else if (pOld) - { - switch (pOld->Which()) - { - case RES_TOXMARK_DELETED: - if (static_cast<const void*>(m_pTOXMark) == - static_cast<SwPtrMsgPoolItem *>(pOld)->pObject) - { - Invalidate(); - } - break; - } - } } /*-- 14.12.98 10:25:43--------------------------------------------------- @@ -1680,7 +1667,7 @@ SwXDocumentIndexMark::SwXDocumentIndexMark(const TOXTypes eToxType) -----------------------------------------------------------------------*/ SwXDocumentIndexMark::SwXDocumentIndexMark(SwDoc & rDoc, - SwTOXType & rType, const SwTOXMark & rMark) + SwTOXType & rType, SwTOXMark & rMark) : m_pImpl( new SwXDocumentIndexMark::Impl(*this, &rDoc, rType.GetType(), &rType, &rMark) ) { @@ -1694,23 +1681,20 @@ SwXDocumentIndexMark::~SwXDocumentIndexMark() uno::Reference<text::XDocumentIndexMark> SwXDocumentIndexMark::CreateXDocumentIndexMark( - SwDoc & rDoc, SwTOXType & rType, const SwTOXMark & rMark) + SwDoc & rDoc, SwTOXType & rType, SwTOXMark & rMark) { + // re-use existing SwXDocumentIndexMark + // NB: xmloff depends on this caching to generate ID from the address! // #i105557#: do not iterate over the registered clients: race condition - // to do this properly requires the SwXDocumentIndexMark to register at the - // format directly, not at the unocallback -#if 0 - SwClientIter aIter(*pType); - SwXDocumentIndexMark::Impl* pxMark = (SwXDocumentIndexMark::Impl*) - aIter.First(TYPE(SwXDocumentIndexMark::Impl)); - while( pxMark ) - { - if(pxMark->m_pTOXMark == pMark) - return pxMark->m_rThis; - pxMark = (SwXDocumentIndexMark::Impl*)aIter.Next(); + uno::Reference< text::XDocumentIndexMark > xTOXMark(rMark.GetXTOXMark()); + if (!xTOXMark.is()) + { + SwXDocumentIndexMark *const pNew = + new SwXDocumentIndexMark(rDoc, rType, rMark); + xTOXMark.set(pNew); + rMark.SetXTOXMark(xTOXMark); } -#endif - return new SwXDocumentIndexMark(rDoc, rType, rMark); + return xTOXMark; } /* -----------------------------10.03.00 18:02-------------------------------- @@ -1955,8 +1939,6 @@ throw (lang::IllegalArgumentException, uno::RuntimeException) { throw lang::IllegalArgumentException(); } - pDoc->GetUnoCallBack()->Add(m_pImpl.get()); - const_cast<SwTOXType*>(pTOXType)->Add(&m_pImpl->m_TypeDepend); SwUnoInternalPaM aPam(*pDoc); //das muss jetzt sal_True liefern @@ -2046,6 +2028,9 @@ throw (lang::IllegalArgumentException, uno::RuntimeException) m_pImpl->m_pTOXMark = &pTxtAttr->GetTOXMark(); m_pImpl->m_pDoc = pDoc; m_pImpl->m_bIsDescriptor = sal_False; + + const_cast<SwTOXMark*>(m_pImpl->m_pTOXMark)->Add(m_pImpl.get()); + const_cast<SwTOXType*>(pTOXType)->Add(&m_pImpl->m_TypeDepend); } /*-- 14.12.98 10:25:45--------------------------------------------------- @@ -2268,7 +2253,7 @@ throw (beans::UnknownPropertyException, beans::PropertyVetoException, if(pTxtAttr) { m_pImpl->m_pTOXMark = &pTxtAttr->GetTOXMark(); - m_pImpl->m_pDoc->GetUnoCallBack()->Add(m_pImpl.get()); + const_cast<SwTOXMark*>(m_pImpl->m_pTOXMark)->Add(m_pImpl.get()); pType->Add(&m_pImpl->m_TypeDepend); } } diff --git a/sw/source/core/unocore/unoportenum.cxx b/sw/source/core/unocore/unoportenum.cxx index fd9722db9616..7996a5e13bcf 100644 --- a/sw/source/core/unocore/unoportenum.cxx +++ b/sw/source/core/unocore/unoportenum.cxx @@ -468,12 +468,12 @@ static Reference<XTextRange> lcl_CreateTOXMarkPortion( Reference<XText> const& xParent, const SwUnoCrsr * const pUnoCrsr, - const SwTxtAttr & rAttr, const bool bEnd) + SwTxtAttr & rAttr, const bool bEnd) { SwDoc* pDoc = pUnoCrsr->GetDoc(); - const SwTOXMark& rTOXMark = static_cast<const SwTOXMark&>(rAttr.GetAttr()); + SwTOXMark & rTOXMark = static_cast<SwTOXMark&>(rAttr.GetAttr()); - Reference<XTextContent> xContent( + const Reference<XTextContent> xContent( SwXDocumentIndexMark::CreateXDocumentIndexMark(*pDoc, *const_cast<SwTOXType*>(rTOXMark.GetTOXType()), rTOXMark), uno::UNO_QUERY); @@ -742,7 +742,7 @@ lcl_ExportHints( while(nStartIndex < pHints->GetStartCount() && nCurrentIndex >= (nNextStart = (*pHints->GetStart(nStartIndex)->GetStart()))) { - const SwTxtAttr * const pAttr = pHints->GetStart(nStartIndex); + SwTxtAttr * const pAttr = pHints->GetStart(nStartIndex); USHORT nAttrWhich = pAttr->Which(); if (nNextStart == nCurrentIndex) { |