summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMichael Stahl <mst@openoffice.org>2010-01-08 17:14:00 +0100
committerMichael Stahl <mst@openoffice.org>2010-01-08 17:14:00 +0100
commitc93ddde38115731d4e5ca2dd41f0dced93625cd7 (patch)
tree74002daa81f8c531f551b5efa120c9a264a630a9 /sw
parent82aba30102fe1cce3f6582bfbe29bacb7498363d (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')
-rw-r--r--sw/inc/tox.hxx32
-rw-r--r--sw/inc/unoidx.hxx4
-rw-r--r--sw/source/core/docnode/nodes.cxx4
-rw-r--r--sw/source/core/tox/tox.cxx34
-rw-r--r--sw/source/core/txtnode/thints.cxx2
-rw-r--r--sw/source/core/unocore/unocrsrhelper.cxx3
-rw-r--r--sw/source/core/unocore/unoidx.cxx49
-rw-r--r--sw/source/core/unocore/unoportenum.cxx8
8 files changed, 84 insertions, 52 deletions
diff --git a/sw/inc/tox.hxx b/sw/inc/tox.hxx
index 9223ffa2d9df..b7384212a4e5 100644
--- a/sw/inc/tox.hxx
+++ b/sw/inc/tox.hxx
@@ -27,8 +27,10 @@
* for a copy of the LGPLv3 License.
*
************************************************************************/
-#ifndef _TOX_HXX
-#define _TOX_HXX
+#ifndef SW_TOX_HXX
+#define SW_TOX_HXX
+
+#include <cppuhelper/weakref.hxx>
#include <i18npool/lang.h>
#include <tools/string.hxx>
@@ -47,6 +49,11 @@
#define INCLUDED_VECTOR
#endif
+
+namespace com { namespace sun { namespace star {
+ namespace text { class XDocumentIndexMark; }
+} } }
+
class SwTOXType;
class SwTOXMark;
class SwTxtTOXMark;
@@ -61,7 +68,9 @@ SV_DECL_PTRARR(SwTOXMarks, SwTOXMark*, 0, 10)
#define IVER_TOXMARK_STRPOOL ((USHORT)1)
#define IVER_TOXMARK_NEWTOX ((USHORT)2)
-class SW_DLLPUBLIC SwTOXMark : public SfxPoolItem, public SwClient
+class SW_DLLPUBLIC SwTOXMark
+ : public SfxPoolItem
+ , public SwModify
{
friend void _InitCore();
friend class SwTxtTOXMark;
@@ -80,6 +89,8 @@ class SW_DLLPUBLIC SwTOXMark : public SfxPoolItem, public SwClient
BOOL bAutoGenerated : 1; // generated using a concordance file
BOOL bMainEntry : 1; // main entry emphasized by character style
+ ::com::sun::star::uno::WeakReference<
+ ::com::sun::star::text::XDocumentIndexMark> m_wXDocumentIndexMark;
SwTOXMark(); // to create the dflt. atr. in _InitCore
@@ -97,6 +108,11 @@ public:
virtual int operator==( const SfxPoolItem& ) const;
virtual SfxPoolItem* Clone( SfxItemPool* pPool = 0 ) const;
+ // SwClient
+ virtual void Modify( SfxPoolItem* pOld, SfxPoolItem* pNew );
+
+ void InvalidateTOXMark();
+
String GetText() const;
inline BOOL IsAlternativeText() const;
@@ -131,6 +147,14 @@ public:
const SwTxtTOXMark* GetTxtTOXMark() const { return pTxtAttr; }
SwTxtTOXMark* GetTxtTOXMark() { return pTxtAttr; }
+
+ SW_DLLPRIVATE ::com::sun::star::uno::WeakReference<
+ ::com::sun::star::text::XDocumentIndexMark> const& GetXTOXMark() const
+ { return m_wXDocumentIndexMark; }
+ SW_DLLPRIVATE void SetXTOXMark(::com::sun::star::uno::Reference<
+ ::com::sun::star::text::XDocumentIndexMark> const& xMark)
+ { m_wXDocumentIndexMark = xMark; }
+
};
/*--------------------------------------------------------------------
@@ -769,4 +793,4 @@ inline void SwTOXBase::SetOptions(USHORT nOpt)
}
-#endif // _TOX_HXX
+#endif // SW_TOX_HXX
diff --git a/sw/inc/unoidx.hxx b/sw/inc/unoidx.hxx
index dd1edce22d0d..664b0c46a78b 100644
--- a/sw/inc/unoidx.hxx
+++ b/sw/inc/unoidx.hxx
@@ -207,7 +207,7 @@ private:
virtual ~SwXDocumentIndexMark();
SwXDocumentIndexMark(SwDoc & rDoc,
- SwTOXType & rType, const SwTOXMark & rMark);
+ SwTOXType & rType, SwTOXMark & rMark);
public:
@@ -217,7 +217,7 @@ public:
static ::com::sun::star::uno::Reference<
::com::sun::star::text::XDocumentIndexMark>
CreateXDocumentIndexMark(SwDoc & rDoc,
- SwTOXType & rType, const SwTOXMark & rMark);
+ SwTOXType & rType, SwTOXMark & rMark);
static const ::com::sun::star::uno::Sequence< sal_Int8 > & getUnoTunnelId();
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)
{