From 733b831970204059b9d89eff203551d6d3bf4bbe Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Tue, 5 Jan 2010 16:37:41 +0100 Subject: swunolocking1: swtypes.hxx: rename frame anchor types enum RndStdIds: rename frame anchor types (FLY_*) to be more intuitive. [note the completely ridiculous number of files that care about anchor types] --- sw/source/core/inc/flyfrm.hxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'sw/source/core/inc') diff --git a/sw/source/core/inc/flyfrm.hxx b/sw/source/core/inc/flyfrm.hxx index dc8975f3fd47..61004c3816a5 100644 --- a/sw/source/core/inc/flyfrm.hxx +++ b/sw/source/core/inc/flyfrm.hxx @@ -109,10 +109,10 @@ protected: //(CheckClip) nur das Format aufgerufen wird; //nicht aber die Breite anhand der Attribute //wieder bestimmt wird. - BOOL bInCnt :1; // FLY_IN_CNTNT, als Zeichen verankert - BOOL bAtCnt :1; // FLY_AT_CNTNT, am Absatz verankert - BOOL bLayout :1; // FLY_PAGE, FLY_AT_FLY, an Seite oder Rahmen - BOOL bAutoPosition :1; // FLY_AUTO_CNTNT, im Text verankerter Rahmen + BOOL bInCnt :1; // FLY_AS_CHAR, anchored as character + BOOL bAtCnt :1; // FLY_AT_PARA, anchored at paragraph + BOOL bLayout :1; // FLY_AT_PAGE, FLY_AT_FLY, at page or at frame + BOOL bAutoPosition :1; // FLY_AT_CHAR, anchored at character BOOL bNoShrink :1; // temporary forbud of shrinking to avoid loops BOOL bLockDeleteContent :1; // If the flag is set, the content of the // fly frame is not deleted if moved to -- cgit v1.2.3 From eb1338534074029d8135c9a475cd301a8d11e3e3 Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Tue, 5 Jan 2010 16:37:42 +0100 Subject: swunolocking1: calbck.hxx: SwClientIter constructor takes a const& parameter --- sw/inc/calbck.hxx | 5 ++--- sw/source/core/attr/calbck.cxx | 2 +- sw/source/core/inc/frmtool.hxx | 2 +- sw/source/core/layout/frmtool.cxx | 4 ++-- 4 files changed, 6 insertions(+), 7 deletions(-) (limited to 'sw/source/core/inc') diff --git a/sw/inc/calbck.hxx b/sw/inc/calbck.hxx index 7a8ff7f8f471..cde55aec812e 100644 --- a/sw/inc/calbck.hxx +++ b/sw/inc/calbck.hxx @@ -202,7 +202,7 @@ class SwClientIter friend SwClient* SwModify::_Remove(SwClient *); // fuer Ptr-Korrektur friend void SwModify::Add(SwClient *); // nur fuer ASSERT ! - SwModify& rRoot; + SwModify const& rRoot; SwClient *pAkt, *pDelNext; // fuers Updaten der aller Iteratoren beim Einfuegen/Loeschen von // Clients, wenn der Iterator gerade draufsteht. @@ -213,11 +213,10 @@ class SwClientIter TypeId aSrchId; // fuer First/Next - suche diesen Type public: - SW_DLLPUBLIC SwClientIter( SwModify& ); + SW_DLLPUBLIC SwClientIter( SwModify const& ); SW_DLLPUBLIC ~SwClientIter(); const SwModify& GetModify() const { return rRoot; } - SwModify& GetModify() { return rRoot; } #ifndef CFRONT SwClient* operator++(int); // zum Naechsten diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx index e4410c26e8bb..a844356d1e2e 100644 --- a/sw/source/core/attr/calbck.cxx +++ b/sw/source/core/attr/calbck.cxx @@ -463,7 +463,7 @@ BOOL SwDepend::GetInfo( SfxPoolItem& rInfo ) const /********************************************************************/ -SwClientIter::SwClientIter( SwModify& rModify ) +SwClientIter::SwClientIter( SwModify const& rModify ) : rRoot( rModify ) { // hinten einketten! diff --git a/sw/source/core/inc/frmtool.hxx b/sw/source/core/inc/frmtool.hxx index ed172b310a01..8cb536f32cba 100644 --- a/sw/source/core/inc/frmtool.hxx +++ b/sw/source/core/inc/frmtool.hxx @@ -141,7 +141,7 @@ const SwFrm * MA_FASTCALL FindPage( const SwRect &rRect, const SwFrm *pPage ); // JP 07.05.98: wird von SwCntntNode::GetFrm und von SwFlyFrm::GetFrm // gerufen -SwFrm* GetFrmOfModify( SwModify&, USHORT nFrmType, const Point* = 0, +SwFrm* GetFrmOfModify( SwModify const&, USHORT const nFrmType, const Point* = 0, const SwPosition *pPos = 0, const BOOL bCalcFrm = FALSE ); diff --git a/sw/source/core/layout/frmtool.cxx b/sw/source/core/layout/frmtool.cxx index f3ac0f966c67..e04b9746a2f8 100644 --- a/sw/source/core/layout/frmtool.cxx +++ b/sw/source/core/layout/frmtool.cxx @@ -3519,8 +3519,8 @@ const SwFrm* MA_FASTCALL FindPage( const SwRect &rRect, const SwFrm *pPage ) return pPage; } -SwFrm* GetFrmOfModify( SwModify& rMod, USHORT nFrmType, const Point* pPoint, - const SwPosition *pPos, const BOOL bCalcFrm ) +SwFrm* GetFrmOfModify( SwModify const& rMod, USHORT const nFrmType, + const Point* pPoint, const SwPosition *pPos, const BOOL bCalcFrm ) { SwFrm *pMinFrm = 0, *pTmpFrm; SwRect aCalcRect; -- cgit v1.2.3 From dd567990b4372498dfbe5063082c792f241ee41d Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Fri, 8 Jan 2010 17:13:49 +0100 Subject: swunolocking1: #i105557#: fix locking for SwXMeta: move SwClient base to pImpl struct, and use UnoImplPtr to lock destructor. replace broken SwClient iteration with a WeakReference in sw::Meta. make constructor protected, and add factory function CreateXMeta. use new XUnoTunnel and XServiceInfo helpers. --- sw/inc/fmtmeta.hxx | 14 +- sw/source/core/inc/unometa.hxx | 193 +++++++++++++------------ sw/source/core/txtnode/fmtatr2.cxx | 31 +--- sw/source/core/unocore/unoportenum.cxx | 57 +++++--- sw/source/core/unocore/unorefmk.cxx | 251 ++++++++++++++++++++------------- 5 files changed, 311 insertions(+), 235 deletions(-) (limited to 'sw/source/core/inc') diff --git a/sw/inc/fmtmeta.hxx b/sw/inc/fmtmeta.hxx index 6d3f63ece477..792a7d8374db 100755 --- a/sw/inc/fmtmeta.hxx +++ b/sw/inc/fmtmeta.hxx @@ -31,6 +31,8 @@ #ifndef SW_FMTMETA_HXX #define SW_FMTMETA_HXX +#include + #include #include @@ -141,7 +143,10 @@ class Meta { protected: friend class ::SwFmtMeta; // SetFmtMeta, NotifyChangeTxtNode - friend class ::SwXMeta; // GetTxtNode, GetTxtAttr + friend class ::SwXMeta; // GetTxtNode, GetTxtAttr, Get/SetXMeta + + ::com::sun::star::uno::WeakReference< + ::com::sun::star::rdf::XMetadatable> m_wXMeta; SwFmtMeta * m_pFmt; @@ -153,6 +158,13 @@ protected: void NotifyChangeTxtNode(); + ::com::sun::star::uno::WeakReference< + ::com::sun::star::rdf::XMetadatable> const& GetXMeta() const + { return m_wXMeta; } + void SetXMeta(::com::sun::star::uno::Reference< + ::com::sun::star::rdf::XMetadatable> const& xMeta) + { m_wXMeta = xMeta; } + public: explicit Meta(SwFmtMeta * const i_pFmt = 0); virtual ~Meta(); diff --git a/sw/source/core/inc/unometa.hxx b/sw/source/core/inc/unometa.hxx index 1dc1985f7dfe..5568aa88b52e 100755 --- a/sw/source/core/inc/unometa.hxx +++ b/sw/source/core/inc/unometa.hxx @@ -31,19 +31,21 @@ #ifndef SW_UNOMETA_HXX #define SW_UNOMETA_HXX -#include "calbck.hxx" - -#include -#include -#include +#include #include #include +#include #include #include #include -#include +#include +#include + +#include + +#include typedef ::std::deque< @@ -52,42 +54,78 @@ typedef ::std::deque< class SwXTextRange; class SwPaM; -class SwTxtMeta; +class SwTxtNode; + namespace sw { class Meta; class MetaField; } -typedef -::cppu::ImplInheritanceHelper5 -< ::sfx2::MetadatableMixin -, ::com::sun::star::lang::XUnoTunnel -, ::com::sun::star::lang::XServiceInfo -, ::com::sun::star::text::XTextContent -, ::com::sun::star::text::XText -, ::com::sun::star::container::XEnumerationAccess -> SwXMetaBaseClass; +typedef ::cppu::ImplInheritanceHelper5 +< ::sfx2::MetadatableMixin +, ::com::sun::star::lang::XUnoTunnel +, ::com::sun::star::lang::XServiceInfo +, ::com::sun::star::container::XEnumerationAccess +, ::com::sun::star::text::XTextContent +, ::com::sun::star::text::XText +> SwXMeta_Base; class SwXMeta - : public SwXMetaBaseClass - , public SwClient + : public SwXMeta_Base , private ::boost::noncopyable { -private: - struct Impl; - ::std::auto_ptr m_pImpl; + +public: + + class Impl; protected: + + ::sw::UnoImplPtr m_pImpl; + + virtual void SAL_CALL AttachImpl( + const ::com::sun::star::uno::Reference< + ::com::sun::star::text::XTextRange > & xTextRange, + const USHORT nWhich) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::uno::RuntimeException); + virtual ~SwXMeta(); -public: - SwXMeta(SwDoc *const pDoc, + /// @param pDoc and pMeta != 0, but not & because of ImplInheritanceHelper + SwXMeta(SwDoc *const pDoc, ::sw::Meta *const pMeta, ::com::sun::star::uno::Reference< ::com::sun::star::text::XText> const& xParentText, - TextRangeList_t * const pPortions, SwTxtMeta * const pHint); + TextRangeList_t const*const pPortions); + +public: + SwXMeta(SwDoc *const pDoc); - TYPEINFO(); + static ::com::sun::star::uno::Reference< + ::com::sun::star::rdf::XMetadatable > + CreateXMeta( + ::sw::Meta & rMeta, + ::com::sun::star::uno::Reference< ::com::sun::star::text::XText> + const& xParentText = 0, + ::std::auto_ptr pPortions = + ::std::auto_ptr(0)); + + /// init params with position of the attribute content (w/out CH_TXTATR) + bool SetContentRange( + SwTxtNode *& rpNode, xub_StrLen & rStart, xub_StrLen & rEnd) const; + ::com::sun::star::uno::Reference< ::com::sun::star::text::XText > + GetParentText() const; + + bool CheckForOwnMemberMeta(const SwXTextRange* const pRange, + const SwPaM* const pPam, bool bAbsorb) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::uno::RuntimeException); + + // MetadatableMixin + virtual ::sfx2::Metadatable * GetCoreObject(); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > + GetModel(); static const ::com::sun::star::uno::Sequence< sal_Int8 > & getUnoTunnelId(); @@ -118,6 +156,18 @@ public: ::com::sun::star::lang::XEventListener > & xListener) throw (::com::sun::star::uno::RuntimeException); + // XElementAccess + virtual ::com::sun::star::uno::Type SAL_CALL getElementType() + throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL hasElements() + throw (::com::sun::star::uno::RuntimeException); + + // XEnumerationAccess + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::container::XEnumeration > SAL_CALL + createEnumeration() + throw (::com::sun::star::uno::RuntimeException); + // XTextContent virtual void SAL_CALL attach( const ::com::sun::star::uno::Reference< @@ -180,72 +230,37 @@ public: throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException); - // XElementAccess - virtual ::com::sun::star::uno::Type SAL_CALL getElementType() - throw (::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL hasElements() - throw (::com::sun::star::uno::RuntimeException); - - // XEnumerationAccess - virtual ::com::sun::star::uno::Reference< - ::com::sun::star::container::XEnumeration > SAL_CALL - createEnumeration() - throw (::com::sun::star::uno::RuntimeException); - - // MetadatableMixin - virtual ::sfx2::Metadatable * GetCoreObject(); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > - GetModel(); - - // SwClient - virtual void Modify( SfxPoolItem *pOld, SfxPoolItem *pNew ); - - /// init params with position of the attribute content (w/out CH_TXTATR) - bool SetContentRange( - SwTxtNode *& rpNode, xub_StrLen & rStart, xub_StrLen & rEnd) const; - ::com::sun::star::uno::Reference< ::com::sun::star::text::XText > - GetParentText() const; - - bool CheckForOwnMemberMeta(const SwXTextRange* const pRange, - const SwPaM* const pPam, bool bAbsorb) - throw (::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::uno::RuntimeException); - -protected: - virtual void SAL_CALL AttachImpl( - const ::com::sun::star::uno::Reference< - ::com::sun::star::text::XTextRange > & xTextRange, - const USHORT nWhich) - throw ( ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::uno::RuntimeException ); - -private: - inline const ::sw::Meta * GetMeta() const; - }; -typedef -::cppu::ImplInheritanceHelper2 -< SwXMeta -, ::com::sun::star::beans::XPropertySet -, ::com::sun::star::text::XTextField -> SwXMetaFieldBaseClass; +typedef ::cppu::ImplInheritanceHelper2 +< SwXMeta +, ::com::sun::star::beans::XPropertySet +, ::com::sun::star::text::XTextField +> SwXMetaField_Base; class SwXMetaField - : public SwXMetaFieldBaseClass + : public SwXMetaField_Base { + private: + virtual ~SwXMetaField(); -private: - inline const ::sw::MetaField * GetMetaField() const; + friend ::com::sun::star::uno::Reference< + ::com::sun::star::rdf::XMetadatable > + SwXMeta::CreateXMeta(::sw::Meta &, + ::com::sun::star::uno::Reference< ::com::sun::star::text::XText> + const&, + ::std::auto_ptr pPortions); -public: - SwXMetaField(SwDoc *const pDoc, + SwXMetaField(SwDoc *const pDoc, ::sw::Meta *const pMeta, ::com::sun::star::uno::Reference< ::com::sun::star::text::XText> const& xParentText, - TextRangeList_t * const pPortions, SwTxtMeta * const pHint); + TextRangeList_t const*const pPortions); + +public: + SwXMetaField(SwDoc *const pDoc); // XServiceInfo @@ -270,16 +285,6 @@ public: ::com::sun::star::lang::XEventListener > & xListener) throw (::com::sun::star::uno::RuntimeException); - // XTextContent - virtual void SAL_CALL attach( - const ::com::sun::star::uno::Reference< - ::com::sun::star::text::XTextRange > & xTextRange) - throw ( ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::uno::RuntimeException ); - virtual ::com::sun::star::uno::Reference< - ::com::sun::star::text::XTextRange > SAL_CALL getAnchor() - throw (::com::sun::star::uno::RuntimeException); - // XPropertySet virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL @@ -327,6 +332,16 @@ public: ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + // XTextContent + virtual void SAL_CALL attach( + const ::com::sun::star::uno::Reference< + ::com::sun::star::text::XTextRange > & xTextRange) + throw ( ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::uno::RuntimeException ); + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::text::XTextRange > SAL_CALL getAnchor() + throw (::com::sun::star::uno::RuntimeException); + // XTextField virtual rtl::OUString SAL_CALL getPresentation(sal_Bool bShowCommand) throw (::com::sun::star::uno::RuntimeException); diff --git a/sw/source/core/txtnode/fmtatr2.cxx b/sw/source/core/txtnode/fmtatr2.cxx index f7fe06d6b006..e76b7f8e4cb1 100644 --- a/sw/source/core/txtnode/fmtatr2.cxx +++ b/sw/source/core/txtnode/fmtatr2.cxx @@ -57,7 +57,6 @@ #include // for meta #include // for meta #include -#include #include #include // GetNumberFormat @@ -750,6 +749,10 @@ void Meta::Modify( SfxPoolItem *pOld, SfxPoolItem *pNew ) { NotifyChangeTxtNode(); SwModify::Modify(pOld, pNew); + if (pOld && (RES_REMOVE_UNO_OBJECT == pOld->Which())) + { // invalidate cached uno object + SetXMeta(uno::Reference(0)); + } } // sw::Metadatable @@ -788,31 +791,7 @@ bool Meta::IsInContent() const ::com::sun::star::uno::Reference< ::com::sun::star::rdf::XMetadatable > Meta::MakeUnoObject() { - // re-use existing SwXMeta - SwClientIter iter( *this ); - SwClient * pClient( iter.First( TYPE( SwXMeta ) ) ); - while (pClient) { - SwXMeta *const pMeta( dynamic_cast(pClient) ); - if (pMeta && pMeta->GetCoreObject() == this) { - return pMeta; - } - pClient = iter.Next(); - } - - // create new SwXMeta - SwTxtMeta * const pTxtAttr( GetTxtAttr() ); - OSL_ENSURE(pTxtAttr, "MakeUnoObject: no text attr?"); - if (!pTxtAttr) return 0; - SwTxtNode * const pTxtNode( pTxtAttr->GetTxtNode() ); - OSL_ENSURE(pTxtNode, "MakeUnoObject: no text node?"); - if (!pTxtNode) return 0; - const SwPosition aPos(*pTxtNode, *pTxtAttr->GetStart()); - const uno::Reference xParentText( - SwXTextRange::CreateParentXText(pTxtNode->GetDoc(), aPos) ); - if (!xParentText.is()) return 0; - return (RES_TXTATR_META == m_pFmt->Which()) - ? new SwXMeta (pTxtNode->GetDoc(), xParentText, 0, pTxtAttr) - : new SwXMetaField(pTxtNode->GetDoc(), xParentText, 0, pTxtAttr); + return SwXMeta::CreateXMeta(*this); } /************************************************************************* diff --git a/sw/source/core/unocore/unoportenum.cxx b/sw/source/core/unocore/unoportenum.cxx index 8ce587ef8bc6..e7426091f745 100644 --- a/sw/source/core/unocore/unoportenum.cxx +++ b/sw/source/core/unocore/unoportenum.cxx @@ -54,6 +54,7 @@ #include #include #include +#include #include #include #include @@ -492,6 +493,33 @@ lcl_CreateTOXMarkPortion( return pPortion; } +//----------------------------------------------------------------------------- +static uno::Reference +lcl_CreateMetaPortion( + uno::Reference const& xParent, + const SwUnoCrsr * const pUnoCrsr, + SwTxtAttr & rAttr, ::std::auto_ptr & pPortions) +{ + const uno::Reference xMeta( SwXMeta::CreateXMeta( + *static_cast(rAttr.GetAttr()).GetMeta(), + xParent, pPortions)); + SwXTextPortion * pPortion(0); + if (RES_TXTATR_META == rAttr.Which()) + { + const uno::Reference xContent(xMeta, + uno::UNO_QUERY); + pPortion = new SwXTextPortion(pUnoCrsr, xParent, PORTION_META); + pPortion->SetMeta(xContent); + } + else + { + const uno::Reference xField(xMeta, uno::UNO_QUERY); + pPortion = new SwXTextPortion(pUnoCrsr, xParent, PORTION_FIELD); + pPortion->SetTextField(xField); + } + return pPortion; +} + //----------------------------------------------------------------------------- static void lcl_ExportBookmark( @@ -692,30 +720,13 @@ lcl_ExportHints( } else { - TextRangeList_t *const pCurrentPortions(Top.first); + ::std::auto_ptr + pCurrentPortions(Top.first); rPortionStack.pop(); - SwXTextPortion * pPortion; - if (RES_TXTATR_META == nWhich) - { - SwXMeta * const pMeta = - new SwXMeta(pDoc, xParent, - pCurrentPortions, - static_cast(pAttr)); - pPortion = new SwXTextPortion( - pUnoCrsr, xParent, PORTION_META); - pPortion->SetMeta(pMeta); - } - else - { - SwXMetaField * const pMeta = - new SwXMetaField(pDoc, xParent, - pCurrentPortions, - static_cast(pAttr)); - pPortion = new SwXTextPortion( - pUnoCrsr, xParent, PORTION_FIELD); - pPortion->SetTextField(pMeta); - } - rPortionStack.top().first->push_back(pPortion); + const uno::Reference xPortion( + lcl_CreateMetaPortion(xParent, pUnoCrsr, + *pAttr, pCurrentPortions)); + rPortionStack.top().first->push_back(xPortion); } } break; diff --git a/sw/source/core/unocore/unorefmk.cxx b/sw/source/core/unocore/unorefmk.cxx index 13b52a6b226b..8e1d18f1dae8 100644 --- a/sw/source/core/unocore/unorefmk.cxx +++ b/sw/source/core/unocore/unorefmk.cxx @@ -493,6 +493,8 @@ public: const uno::Reference< text::XTextRange > & xTextPosition) throw (uno::RuntimeException); + SwXMeta & GetXMeta() { return m_rMeta; } + }; SwXMetaText::SwXMetaText(SwDoc & rDoc, SwXMeta & rMeta) @@ -598,8 +600,12 @@ SwXMetaText::createTextCursorByRange( // this list is created by SwXTextPortionEnumeration // the Meta listens at the SwTxtNode and throws away the cache when it changes -struct SwXMeta::Impl +class SwXMeta::Impl + : public SwClient { + +public: + SwEventListenerContainer m_ListenerContainer; ::std::auto_ptr m_pTextPortions; // 3 possible states: not attached, attached, disposed @@ -608,37 +614,132 @@ struct SwXMeta::Impl uno::Reference m_xParentText; SwXMetaText m_Text; - Impl(SwXMeta & rThis, SwDoc & rDoc, + Impl( SwXMeta & rThis, SwDoc & rDoc, + ::sw::Meta * const pMeta, uno::Reference const& xParentText, - TextRangeList_t const * const pPortions, - SwTxtMeta const * const pHint) - : m_ListenerContainer( - static_cast< ::cppu::OWeakObject* >(&rThis)) + TextRangeList_t const * const pPortions) + : SwClient(pMeta) + , m_ListenerContainer(static_cast< ::cppu::OWeakObject* >(&rThis)) , m_pTextPortions( pPortions ) , m_bIsDisposed( false ) - , m_bIsDescriptor( 0 == pHint ) + , m_bIsDescriptor(0 == pMeta) , m_xParentText(xParentText) , m_Text(rDoc, rThis) { } -}; -TYPEINIT1(SwXMeta, SwClient); + inline const ::sw::Meta * GetMeta() const; + // only for SwXMetaField! + inline const ::sw::MetaField * GetMetaField() const; + + // SwClient + virtual void Modify(SfxPoolItem *pOld, SfxPoolItem *pNew); -inline const ::sw::Meta * SwXMeta::GetMeta() const +}; + +inline const ::sw::Meta * SwXMeta::Impl::GetMeta() const { return static_cast< const ::sw::Meta * >(GetRegisteredIn()); } +// SwModify +void SwXMeta::Impl::Modify( SfxPoolItem *pOld, SfxPoolItem *pNew ) +{ + m_pTextPortions.reset(); // throw away cache (SwTxtNode changed) + + ClientModify(this, pOld, pNew); + + if (!GetRegisteredIn()) // removed => dispose + { + m_ListenerContainer.Disposing(); + m_bIsDisposed = true; + m_Text.Invalidate(); + } +} + uno::Reference SwXMeta::GetParentText() const { return m_pImpl->m_xParentText; } +SwXMeta::SwXMeta(SwDoc *const pDoc, ::sw::Meta *const pMeta, + uno::Reference const& xParentText, + TextRangeList_t const*const pPortions) + : m_pImpl( new SwXMeta::Impl(*this, *pDoc, pMeta, xParentText, pPortions) ) +{ +} + +SwXMeta::SwXMeta(SwDoc *const pDoc) + : m_pImpl( new SwXMeta::Impl(*this, *pDoc, 0, 0, 0) ) +{ +} + +SwXMeta::~SwXMeta() +{ +} + +uno::Reference +SwXMeta::CreateXMeta(::sw::Meta & rMeta, + uno::Reference const& i_xParent, + ::std::auto_ptr pPortions) +{ + // re-use existing SwXMeta + // #i105557#: do not iterate over the registered clients: race condition + uno::Reference xMeta(rMeta.GetXMeta()); + if (xMeta.is()) + { + if (pPortions.get()) // set cache in the XMeta to the given portions + { + const uno::Reference xUT(xMeta, uno::UNO_QUERY); + SwXMeta *const pXMeta( + ::sw::UnoTunnelGetImplementation(xUT)); + OSL_ENSURE(pXMeta, "no pXMeta?"); + // NB: the meta must always be created with the complete content + // if SwXTextPortionEnumeration is created for a selection, + // it must be checked that the Meta is contained in the selection! + pXMeta->m_pImpl->m_pTextPortions = pPortions; + // ??? is this necessary? + if (pXMeta->m_pImpl->m_xParentText.get() != i_xParent.get()) + { + OSL_ENSURE(false, "SwXMeta with different parent?"); + pXMeta->m_pImpl->m_xParentText.set(i_xParent); + } + } + return xMeta; + } + + // create new SwXMeta + SwTxtNode * const pTxtNode( rMeta.GetTxtNode() ); + OSL_ENSURE(pTxtNode, "CreateXMeta: no text node?"); + if (!pTxtNode) { return 0; } + uno::Reference xParentText(i_xParent); + if (!xParentText.is()) + { + SwTxtMeta * const pTxtAttr( rMeta.GetTxtAttr() ); + OSL_ENSURE(pTxtAttr, "CreateXMeta: no text attr?"); + if (!pTxtAttr) { return 0; } + const SwPosition aPos(*pTxtNode, *pTxtAttr->GetStart()); + xParentText.set( + SwXTextRange::CreateParentXText(pTxtNode->GetDoc(), aPos) ); + } + if (!xParentText.is()) { return 0; } + SwXMeta *const pXMeta( (RES_TXTATR_META == rMeta.GetFmtMeta()->Which()) + ? new SwXMeta (pTxtNode->GetDoc(), &rMeta, xParentText, + pPortions.release()) // temporarily un-auto_ptr :-( + : new SwXMetaField(pTxtNode->GetDoc(), &rMeta, xParentText, + pPortions.release())); + // this is why the constructor is private: need to acquire pXMeta here + xMeta.set(pXMeta); + // in order to initialize the weak pointer cache in the core object + rMeta.SetXMeta(xMeta); + return xMeta; +} + + bool SwXMeta::SetContentRange( SwTxtNode *& rpNode, xub_StrLen & rStart, xub_StrLen & rEnd ) const { - ::sw::Meta const * const pMeta( GetMeta() ); + ::sw::Meta const * const pMeta( m_pImpl->GetMeta() ); if (pMeta) { SwTxtMeta const * const pTxtAttr( pMeta->GetTxtAttr() ); @@ -657,23 +758,6 @@ bool SwXMeta::SetContentRange( return false; } -SwXMeta::SwXMeta(SwDoc *const pDoc, - uno::Reference const& xParentText, - TextRangeList_t * const pPortions, SwTxtMeta * const pHint) - : m_pImpl( new SwXMeta::Impl(*this, *pDoc, xParentText, pPortions, pHint) ) -{ - if (pHint) - { - ::sw::Meta * const pMeta( - static_cast(pHint->GetAttr()).GetMeta() ); - ASSERT(pMeta, "SwXMeta: no meta?") - if (pMeta) - { - pMeta->Add(this); - } - } -} - bool SwXMeta::CheckForOwnMemberMeta(const SwXTextRange* const pRange, const SwPaM* const pPam, bool bAbsorb) throw (lang::IllegalArgumentException, uno::RuntimeException) @@ -744,16 +828,6 @@ bool SwXMeta::CheckForOwnMemberMeta(const SwXTextRange* const pRange, return bForceExpandHints; } - -SwXMeta::SwXMeta(SwDoc *const pDoc) - : m_pImpl( new SwXMeta::Impl(*this, *pDoc, 0, 0, 0) ) -{ -} - -SwXMeta::~SwXMeta() -{ -} - const uno::Sequence< sal_Int8 > & SwXMeta::getUnoTunnelId() { static uno::Sequence< sal_Int8 > aSeq( ::CreateUnoTunnelId() ); @@ -765,14 +839,7 @@ sal_Int64 SAL_CALL SwXMeta::getSomething( const uno::Sequence< sal_Int8 > & i_rId ) throw (uno::RuntimeException) { - if ( i_rId.getLength() == 16 && - 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), - i_rId.getConstArray(), 16 ) ) - { - return sal::static_int_cast< sal_Int64 >( - reinterpret_cast< sal_IntPtr >(this) ); - } - return 0; + return ::sw::UnoTunnelImpl(i_rId, this); } // XServiceInfo @@ -782,21 +849,26 @@ SwXMeta::getImplementationName() throw (uno::RuntimeException) return C2U("SwXMeta"); } +static char const*const g_ServicesMeta[] = +{ + "com.sun.star.text.TextContent", + "com.sun.star.text.InContentMetadata", +}; +static const size_t g_nServicesMeta( + sizeof(g_ServicesMeta)/sizeof(g_ServicesMeta[0])); + sal_Bool SAL_CALL SwXMeta::supportsService(const ::rtl::OUString& rServiceName) throw (uno::RuntimeException) { - return rServiceName.equalsAscii("com.sun.star.text.TextContent") - || rServiceName.equalsAscii("com.sun.star.text.InContentMetadata"); + return ::sw::SupportsServiceImpl( + g_nServicesMeta, g_ServicesMeta, rServiceName); } uno::Sequence< ::rtl::OUString > SAL_CALL SwXMeta::getSupportedServiceNames() throw (uno::RuntimeException) { - uno::Sequence< ::rtl::OUString > aRet(2); - aRet[0] = C2U("com.sun.star.text.TextContent"); - aRet[1] = C2U("com.sun.star.text.InContentMetadata"); - return aRet; + return ::sw::GetSupportedServiceNamesImpl(g_nServicesMeta, g_ServicesMeta); } @@ -886,14 +958,10 @@ throw (lang::IllegalArgumentException, uno::RuntimeException) C2S("SwXMeta::attach(): argument is no XUnoTunnel"), static_cast< ::cppu::OWeakObject* >(this), 0); } - SwXTextRange * const pRange( - reinterpret_cast< SwXTextRange * >( - sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( - SwXTextRange::getUnoTunnelId() ))) ); - OTextCursorHelper * const pCursor( pRange ? 0 : - reinterpret_cast< OTextCursorHelper * >( - sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( - OTextCursorHelper::getUnoTunnelId() ))) ); + SwXTextRange *const pRange( + ::sw::UnoTunnelGetImplementation(xRangeTunnel)); + OTextCursorHelper *const pCursor( (pRange) ? 0 : + ::sw::UnoTunnelGetImplementation(xRangeTunnel)); if (!pRange && !pCursor) { throw lang::IllegalArgumentException( @@ -945,7 +1013,8 @@ throw (lang::IllegalArgumentException, uno::RuntimeException) static_cast< ::cppu::OWeakObject* >(this)); } - pMeta->Add(this); + pMeta->Add(m_pImpl.get()); + pMeta->SetXMeta(uno::Reference(this)); m_pImpl->m_xParentText = SwXTextRange::CreateParentXText(pDoc, *aPam.GetPoint()); @@ -1102,7 +1171,7 @@ SwXMeta::hasElements() throw (uno::RuntimeException) { vos::OGuard g(Application::GetSolarMutex()); - return GetRegisteredIn() ? sal_True : sal_False; + return m_pImpl->GetRegisteredIn() ? sal_True : sal_False; } // XEnumerationAccess @@ -1118,7 +1187,7 @@ SwXMeta::createEnumeration() throw (uno::RuntimeException) if (m_pImpl->m_bIsDescriptor) { throw uno::RuntimeException( - C2S("getAnchor(): not inserted"), + C2S("createEnumeration(): not inserted"), static_cast< ::cppu::OWeakObject* >(this)); } @@ -1147,12 +1216,12 @@ SwXMeta::createEnumeration() throw (uno::RuntimeException) // MetadatableMixin ::sfx2::Metadatable* SwXMeta::GetCoreObject() { - return const_cast< ::sw::Meta * >(GetMeta()); + return const_cast< ::sw::Meta * >(m_pImpl->GetMeta()); } uno::Reference SwXMeta::GetModel() { - ::sw::Meta const * const pMeta( GetMeta() ); + ::sw::Meta const * const pMeta( m_pImpl->GetMeta() ); if (pMeta) { SwTxtNode const * const pTxtNode( pMeta->GetTxtNode() ); @@ -1165,42 +1234,27 @@ uno::Reference SwXMeta::GetModel() return 0; } -// SwModify -void SwXMeta::Modify( SfxPoolItem *pOld, SfxPoolItem *pNew ) -{ - m_pImpl->m_pTextPortions.reset(); // throw away cache (SwTxtNode changed) - - ClientModify(this, pOld, pNew); - - if (!GetRegisteredIn()) // removed => dispose - { - m_pImpl->m_ListenerContainer.Disposing(); - m_pImpl->m_bIsDisposed = true; - m_pImpl->m_Text.Invalidate(); - } -} - /****************************************************************** * SwXMetaField ******************************************************************/ -inline const ::sw::MetaField * SwXMetaField::GetMetaField() const +inline const ::sw::MetaField * SwXMeta::Impl::GetMetaField() const { return static_cast< const ::sw::MetaField * >(GetRegisteredIn()); } -SwXMetaField::SwXMetaField(SwDoc *const pDoc, +SwXMetaField::SwXMetaField(SwDoc *const pDoc, ::sw::Meta *const pMeta, uno::Reference const& xParentText, - TextRangeList_t * const pPortions, SwTxtMeta * const pHint) - : SwXMetaFieldBaseClass(pDoc, xParentText, pPortions, pHint) + TextRangeList_t const*const pPortions) + : SwXMetaField_Base(pDoc, pMeta, xParentText, pPortions) { - ASSERT(!pHint || RES_TXTATR_METAFIELD == pHint->Which(), + ASSERT(pMeta && dynamic_cast< ::sw::MetaField* >(pMeta), "SwXMetaField created for wrong hint!"); } SwXMetaField::SwXMetaField(SwDoc *const pDoc) - : SwXMetaFieldBaseClass(pDoc) + : SwXMetaField_Base(pDoc) { } @@ -1215,23 +1269,28 @@ SwXMetaField::getImplementationName() throw (uno::RuntimeException) return C2U("SwXMetaField"); } +static char const*const g_ServicesMetaField[] = +{ + "com.sun.star.text.TextContent", + "com.sun.star.text.TextField", + "com.sun.star.text.textfield.MetadataField", +}; +static const size_t g_nServicesMetaField( + sizeof(g_ServicesMetaField)/sizeof(g_ServicesMetaField[0])); + sal_Bool SAL_CALL SwXMetaField::supportsService(const ::rtl::OUString& rServiceName) throw (uno::RuntimeException) { - return rServiceName.equalsAscii("com.sun.star.text.TextContent") - || rServiceName.equalsAscii("com.sun.star.text.TextField") - || rServiceName.equalsAscii("com.sun.star.text.textfield.MetadataField"); + return ::sw::SupportsServiceImpl( + g_nServicesMetaField, g_ServicesMetaField, rServiceName); } uno::Sequence< ::rtl::OUString > SAL_CALL SwXMetaField::getSupportedServiceNames() throw (uno::RuntimeException) { - uno::Sequence< ::rtl::OUString > aRet(3); - aRet[0] = C2U("com.sun.star.text.TextContent"); - aRet[1] = C2U("com.sun.star.text.TextField"); - aRet[2] = C2U("com.sun.star.text.textfield.MetadataField"); - return aRet; + return ::sw::GetSupportedServiceNamesImpl( + g_nServicesMetaField, g_ServicesMetaField); } // XComponent @@ -1293,7 +1352,7 @@ throw (beans::UnknownPropertyException, beans::PropertyVetoException, vos::OGuard g(Application::GetSolarMutex()); ::sw::MetaField * const pMeta( - const_cast< ::sw::MetaField * >(GetMetaField()) ); + const_cast< ::sw::MetaField * >(m_pImpl->GetMetaField()) ); if (!pMeta) throw lang::DisposedException(); @@ -1326,7 +1385,7 @@ throw (beans::UnknownPropertyException, lang::WrappedTargetException, { vos::OGuard g(Application::GetSolarMutex()); - ::sw::MetaField const * const pMeta( GetMetaField() ); + ::sw::MetaField const * const pMeta( m_pImpl->GetMetaField() ); if (!pMeta) throw lang::DisposedException(); -- cgit v1.2.3 From 440e521dad8c97e939460af857c6a851b220c52e Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Fri, 8 Jan 2010 17:13:50 +0100 Subject: swunolocking1: #i105557#: fix locking for SwXBookmark: add Impl struct, and use UnoImplPtr to lock destructor. move all implementation details out of header, into Impl struct. replace broken SwClient iteration with a WeakReference in sw::mark::MarkBase. make constructor protected, and add factory function CreateXBookmark. use new XUnoTunnel and XServiceInfo helpers. clean up the implementation a little. remove SwXBookmarks::GetObject(). --- sw/inc/unobookmark.hxx | 48 ++-- sw/inc/unocoll.hxx | 1 - sw/source/core/crsr/bookmrk.cxx | 30 +-- sw/source/core/inc/bookmrk.hxx | 24 +- sw/source/core/unocore/unobkm.cxx | 480 ++++++++++++++++++++++----------- sw/source/core/unocore/unocoll.cxx | 31 +-- sw/source/core/unocore/unoportenum.cxx | 15 +- sw/source/ui/uno/unotxvw.cxx | 17 +- 8 files changed, 399 insertions(+), 247 deletions(-) (limited to 'sw/source/core/inc') diff --git a/sw/inc/unobookmark.hxx b/sw/inc/unobookmark.hxx index 2b16d7828001..46d0054551b7 100644 --- a/sw/inc/unobookmark.hxx +++ b/sw/inc/unobookmark.hxx @@ -41,12 +41,10 @@ #include -#include #include +#include #include -#include -#include class SwDoc; @@ -63,33 +61,15 @@ typedef ::cppu::ImplInheritanceHelper5 class SwXBookmark : public SwXBookmark_Base - , private SwClient { private: - SwEventListenerContainer m_aLstnrCntnr; - SwDoc* m_pDoc; - String m_aName; - ::sw::mark::IMark* m_pRegisteredBookmark; - - void registerInMark(::sw::mark::IMark* const pBkmk); + class Impl; + ::sw::UnoImplPtr m_pImpl; protected: - virtual ~SwXBookmark(); - -public: - - SwXBookmark(::sw::mark::IMark* pMark = 0, SwDoc* pDoc = 0); - - const ::sw::mark::IMark* GetBookmark() const - { return m_pRegisteredBookmark; } - ::sw::mark::IMark* GetBookmark() - { return m_pRegisteredBookmark; } - SwDoc* GetDoc() - { return m_pDoc; } - void attachToRangeEx( const ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > & xTextRange, @@ -102,10 +82,26 @@ public: throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); - TYPEINFO(); + const ::sw::mark::IMark* GetBookmark() const; - // SwClient - virtual void Modify( SfxPoolItem *pOld, SfxPoolItem *pNew ); + virtual ~SwXBookmark(); + + /// @param pDoc and pMark != 0, but not & because of ImplInheritanceHelper + SwXBookmark(::sw::mark::IMark *const pMark, SwDoc *const pDoc); + +public: + + /// descriptor + SwXBookmark(); + + static ::com::sun::star::uno::Reference< + ::com::sun::star::text::XTextContent> + CreateXBookmark(SwDoc & rDoc, ::sw::mark::IMark & rBookmark); + + /// @return IMark for this, but only if it lives in pDoc + static ::sw::mark::IMark const* GetBookmarkInDoc(SwDoc const*const pDoc, + const ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XUnoTunnel> & xUT); // MetadatableMixin virtual ::sfx2::Metadatable* GetCoreObject(); diff --git a/sw/inc/unocoll.hxx b/sw/inc/unocoll.hxx index b630668f8965..f4d54a55adca 100644 --- a/sw/inc/unocoll.hxx +++ b/sw/inc/unocoll.hxx @@ -481,7 +481,6 @@ class SwXBookmarks : public SwCollectionBaseClass, virtual BOOL SAL_CALL supportsService(const rtl::OUString& ServiceName) throw( ::com::sun::star::uno::RuntimeException ); virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames(void) throw( ::com::sun::star::uno::RuntimeException ); - static SwXBookmark* GetObject( ::sw::mark::IMark& rBkm, SwDoc* pDoc); }; class SwXNumberingRulesCollection : public cppu::WeakImplHelper1 diff --git a/sw/source/core/crsr/bookmrk.cxx b/sw/source/core/crsr/bookmrk.cxx index 1028c7b2b432..a9321324be3a 100644 --- a/sw/source/core/crsr/bookmrk.cxx +++ b/sw/source/core/crsr/bookmrk.cxx @@ -49,6 +49,7 @@ SV_IMPL_REF( SwServerObject ) using namespace ::sw::mark; +using namespace ::com::sun::star; namespace { @@ -147,6 +148,16 @@ namespace sw { namespace mark return aResult.append(nCount++).append(sUniquePostfix).makeStringAndClear(); } + // SwClient + void MarkBase::Modify(SfxPoolItem *pOld, SfxPoolItem *pNew) + { + SwModify::Modify(pOld, pNew); + if (pOld && (RES_REMOVE_UNO_OBJECT == pOld->Which())) + { // invalidate cached uno object + SetXBookmark(uno::Reference(0)); + } + } + NavigatorReminder::NavigatorReminder(const SwPaM& rPaM) : MarkBase(rPaM, our_sNamePrefix) @@ -240,24 +251,13 @@ namespace sw { namespace mark return !pDoc->IsInHeaderFooter( SwNodeIndex(GetMarkPos().nNode) ); } - ::com::sun::star::uno::Reference< ::com::sun::star::rdf::XMetadatable > - Bookmark::MakeUnoObject() + uno::Reference< rdf::XMetadatable > Bookmark::MakeUnoObject() { - // re-use existing SwXBookmark - SwClientIter iter( *this ); - SwClient * pClient( iter.First( TYPE( SwXBookmark ) ) ); - while (pClient) { - SwXBookmark *const pBookmark( dynamic_cast(pClient) ); - if (pBookmark && pBookmark->GetCoreObject() == this) { - return pBookmark; - } - pClient = iter.Next(); - } - - // create new SwXBookmark SwDoc *const pDoc( GetMarkPos().GetDoc() ); OSL_ENSURE(pDoc, "Bookmark::MakeUnoObject: no doc?"); - return new SwXBookmark(this, pDoc); + const uno::Reference< rdf::XMetadatable> xMeta( + SwXBookmark::CreateXBookmark(*pDoc, *this), uno::UNO_QUERY); + return xMeta; } diff --git a/sw/source/core/inc/bookmrk.hxx b/sw/source/core/inc/bookmrk.hxx index 18f8860ecab9..313df12fddb7 100644 --- a/sw/source/core/inc/bookmrk.hxx +++ b/sw/source/core/inc/bookmrk.hxx @@ -31,12 +31,20 @@ #ifndef _BOOKMRK_HXX #define _BOOKMRK_HXX -#include +#include + #include #include #include +#include + + +namespace com { namespace sun { namespace star { + namespace text { class XTextContent; } +} } } + struct SwPosition; // fwd Decl. wg. UI class SwDoc; @@ -90,6 +98,17 @@ namespace sw { namespace mark {} virtual ~MarkBase(); + + // SwClient + virtual void Modify( SfxPoolItem *pOld, SfxPoolItem *pNew ); + + const ::com::sun::star::uno::WeakReference< + ::com::sun::star::text::XTextContent> & GetXBookmark() const + { return m_wXBookmark; } + void SetXBookmark(::com::sun::star::uno::Reference< + ::com::sun::star::text::XTextContent> const& xBkmk) + { m_wXBookmark = xBkmk; } + protected: MarkBase(const SwPaM& rPaM, const ::rtl::OUString& rName); @@ -97,6 +116,9 @@ namespace sw { namespace mark ::boost::scoped_ptr m_pPos2; ::rtl::OUString m_aName; static ::rtl::OUString GenerateNewName(const ::rtl::OUString& rPrefix); + + ::com::sun::star::uno::WeakReference< + ::com::sun::star::text::XTextContent> m_wXBookmark; }; class NavigatorReminder diff --git a/sw/source/core/unocore/unobkm.cxx b/sw/source/core/unocore/unobkm.cxx index 282ae6b389a8..86b8b3ee8403 100644 --- a/sw/source/core/unocore/unobkm.cxx +++ b/sw/source/core/unocore/unobkm.cxx @@ -34,11 +34,13 @@ #include #include #include + #include #include #include #include #include +#include #include #include #include @@ -52,13 +54,8 @@ using namespace ::com::sun::star; -using namespace ::com::sun::star::lang; -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::text; -using namespace ::com::sun::star::container; -using namespace ::com::sun::star::beans; using ::rtl::OUString; -using ::rtl::OUStringBuffer; + namespace { @@ -66,7 +63,7 @@ namespace { static const OUString sStart = OUString(String(SW_RES(STR_START_QUOTE))); static const OUString sEnd = OUString(String(SW_RES(STR_END_QUOTE))); - OUStringBuffer sBuf(64); + ::rtl::OUStringBuffer sBuf(64); return sBuf.append(sStart).append(rName).append(sEnd).makeStringAndClear(); } } @@ -74,184 +71,307 @@ namespace /****************************************************************** * SwXBookmark ******************************************************************/ -TYPEINIT1(SwXBookmark, SwClient) -void SwXBookmark::registerInMark(::sw::mark::IMark* const pBkmk) +class SwXBookmark::Impl + : public SwClient +{ + +public: + SwEventListenerContainer m_ListenerContainer; + SwDoc * m_pDoc; + ::sw::mark::IMark * m_pRegisteredBookmark; + ::rtl::OUString m_sMarkName; + + + Impl( SwXBookmark & rThis, + SwDoc *const pDoc, ::sw::mark::IMark *const /*pBookmark*/) + : SwClient() + , m_ListenerContainer(static_cast< ::cppu::OWeakObject* >(&rThis)) + , m_pDoc(pDoc) + , m_pRegisteredBookmark(0) + { + // DO NOT regiserInMark here! (because SetXBookmark would delete rThis) + } + + void registerInMark(SwXBookmark & rThis, ::sw::mark::IMark *const pBkmk); + + // SwClient + virtual void Modify(SfxPoolItem *pOld, SfxPoolItem *pNew); + +}; + +void SwXBookmark::Impl::Modify(SfxPoolItem *pOld, SfxPoolItem *pNew) +{ + ClientModify(this, pOld, pNew); + if (!GetRegisteredIn()) + { + m_pRegisteredBookmark = NULL; + m_pDoc = NULL; + m_ListenerContainer.Disposing(); + } +} + +void SwXBookmark::Impl::registerInMark(SwXBookmark & rThis, + ::sw::mark::IMark *const pBkmk) { if (pBkmk) { pBkmk->Add(this); + ::sw::mark::MarkBase *const pMarkBase( + dynamic_cast< ::sw::mark::MarkBase * >(pBkmk)); + OSL_ENSURE(pMarkBase, "registerInMark: no MarkBase?"); + if (pMarkBase) + { + const uno::Reference xBookmark(& rThis); + pMarkBase->SetXBookmark(xBookmark); + } } else if (m_pRegisteredBookmark) { - m_aName = m_pRegisteredBookmark->GetName(); + m_sMarkName = m_pRegisteredBookmark->GetName(); m_pRegisteredBookmark->Remove(this); } m_pRegisteredBookmark = pBkmk; } -const uno::Sequence< sal_Int8 > & SwXBookmark::getUnoTunnelId() + +const ::sw::mark::IMark* SwXBookmark::GetBookmark() const { - static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId(); - return aSeq; + return m_pImpl->m_pRegisteredBookmark; } -sal_Int64 SAL_CALL SwXBookmark::getSomething( const uno::Sequence< sal_Int8 >& rId ) - throw(uno::RuntimeException) +SwXBookmark::SwXBookmark(::sw::mark::IMark *const pBkmk, SwDoc *const pDoc) + : m_pImpl( new SwXBookmark::Impl(*this, pDoc, pBkmk) ) { - if( rId.getLength() == 16 - && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) +} + +SwXBookmark::SwXBookmark() + : m_pImpl( new SwXBookmark::Impl(*this, 0, 0) ) +{ +} + +SwXBookmark::~SwXBookmark() +{ +} + +uno::Reference +SwXBookmark::CreateXBookmark(SwDoc & rDoc, ::sw::mark::IMark & rBookmark) +{ + // #i105557#: do not iterate over the registered clients: race condition + ::sw::mark::MarkBase *const pMarkBase( + dynamic_cast< ::sw::mark::MarkBase * >(&rBookmark)); + OSL_ENSURE(pMarkBase, "CreateXBookmark: no MarkBase?"); + if (!pMarkBase) { return 0; } + uno::Reference xBookmark(pMarkBase->GetXBookmark()); + if (!xBookmark.is()) { - return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >(this) ); + // FIXME: These belong in XTextFieldsSupplier + //if (dynamic_cast< ::sw::mark::TextFieldmark* >(&rBkmk)) + // pXBkmk = new SwXFieldmark(false, &rBkmk, pDoc); + //else if (dynamic_cast< ::sw::mark::CheckboxFieldmark* >(&rBkmk)) + // pXBkmk = new SwXFieldmark(true, &rBkmk, pDoc); + //else + OSL_ENSURE( + dynamic_cast< ::sw::mark::IBookmark* >(&rBookmark), + "" + "SwXBookmark requested for non-bookmark mark."); + SwXBookmark *const pXBookmark = new SwXBookmark(&rBookmark, &rDoc); + xBookmark.set(pXBookmark); + pXBookmark->m_pImpl->registerInMark(*pXBookmark, pMarkBase); + } + return xBookmark; +} + +::sw::mark::IMark const* SwXBookmark::GetBookmarkInDoc(SwDoc const*const pDoc, + const uno::Reference< lang::XUnoTunnel> & xUT) +{ + SwXBookmark *const pXBkm( + ::sw::UnoTunnelGetImplementation(xUT)); + if (pXBkm && (pDoc == pXBkm->m_pImpl->m_pDoc)) + { + return pXBkm->m_pImpl->m_pRegisteredBookmark; } return 0; } -SwXBookmark::SwXBookmark(::sw::mark::IMark* pBkmk, SwDoc* pDoc) - : m_aLstnrCntnr((text::XTextContent*)this) - , m_pDoc(pDoc) - , m_pRegisteredBookmark(NULL) +const uno::Sequence< sal_Int8 > & SwXBookmark::getUnoTunnelId() { - registerInMark(pBkmk); + static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId(); + return aSeq; } -SwXBookmark::~SwXBookmark() -{ } +sal_Int64 SAL_CALL +SwXBookmark::getSomething(const uno::Sequence< sal_Int8 >& rId) +throw (uno::RuntimeException) +{ + return ::sw::UnoTunnelImpl(rId, this); +} void SwXBookmark::attachToRangeEx( const uno::Reference< text::XTextRange > & xTextRange, IDocumentMarkAccess::MarkType eType) - throw(lang::IllegalArgumentException, uno::RuntimeException) +throw (lang::IllegalArgumentException, uno::RuntimeException) { - if(m_pRegisteredBookmark) + if (m_pImpl->m_pRegisteredBookmark) + { throw uno::RuntimeException(); + } - uno::Reference xRangeTunnel( xTextRange, uno::UNO_QUERY); + const uno::Reference xRangeTunnel( + xTextRange, uno::UNO_QUERY); SwXTextRange* pRange = 0; OTextCursorHelper* pCursor = 0; if(xRangeTunnel.is()) { + pRange = ::sw::UnoTunnelGetImplementation(xRangeTunnel); + pCursor = + ::sw::UnoTunnelGetImplementation(xRangeTunnel); + } - pRange = reinterpret_cast< SwXTextRange * >( - sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( SwXTextRange::getUnoTunnelId() ))); - pCursor = reinterpret_cast< OTextCursorHelper * >( - sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() ))); + SwDoc *const pDoc = + (pRange) ? pRange->GetDoc() : ((pCursor) ? pCursor->GetDoc() : 0); + if (!pDoc) + { + throw lang::IllegalArgumentException(); } - SwDoc* pDc = pRange ? (SwDoc*)pRange->GetDoc() : pCursor ? - (SwDoc*)pCursor->GetDoc() : 0; - if(pDc) + m_pImpl->m_pDoc = pDoc; + SwUnoInternalPaM aPam(*m_pImpl->m_pDoc); + SwXTextRange::XTextRangeToSwPaM(aPam, xTextRange); + UnoActionContext aCont(m_pImpl->m_pDoc); + if (!m_pImpl->m_sMarkName.getLength()) { - m_pDoc = pDc; - SwUnoInternalPaM aPam(*m_pDoc); - SwXTextRange::XTextRangeToSwPaM(aPam, xTextRange); - UnoActionContext aCont(m_pDoc); - if(!m_aName.Len()) - m_aName = OUString::createFromAscii("Bookmark"); - if(eType == IDocumentMarkAccess::BOOKMARK && ::sw::mark::CrossRefNumItemBookmark::IsLegalName(m_aName)) - eType = IDocumentMarkAccess::CROSSREF_NUMITEM_BOOKMARK; - else if(eType == IDocumentMarkAccess::BOOKMARK && ::sw::mark::CrossRefHeadingBookmark::IsLegalName(m_aName)) - eType = IDocumentMarkAccess::CROSSREF_HEADING_BOOKMARK; - registerInMark(m_pDoc->getIDocumentMarkAccess()->makeMark(aPam, m_aName, eType)); - // --> OD 2007-10-23 #i81002# - // Check, if bookmark has been created. - // E.g., the creation of a cross-reference bookmark is suppress, - // if the PaM isn't a valid one for cross-reference bookmarks. - if(!m_pRegisteredBookmark) - { - OSL_ENSURE(false, - "" - " - could not create Mark."); - throw lang::IllegalArgumentException(); - } - // <-- + m_pImpl->m_sMarkName = OUString::createFromAscii("Bookmark"); } - else + if ((eType == IDocumentMarkAccess::BOOKMARK) && + ::sw::mark::CrossRefNumItemBookmark::IsLegalName(m_pImpl->m_sMarkName)) + { + eType = IDocumentMarkAccess::CROSSREF_NUMITEM_BOOKMARK; + } + else if ((eType == IDocumentMarkAccess::BOOKMARK) && + ::sw::mark::CrossRefHeadingBookmark::IsLegalName(m_pImpl->m_sMarkName)) + { + eType = IDocumentMarkAccess::CROSSREF_HEADING_BOOKMARK; + } + m_pImpl->registerInMark(*this, + m_pImpl->m_pDoc->getIDocumentMarkAccess()->makeMark( + aPam, m_pImpl->m_sMarkName, eType)); + // --> OD 2007-10-23 #i81002# + // Check, if bookmark has been created. + // E.g., the creation of a cross-reference bookmark is suppress, + // if the PaM isn't a valid one for cross-reference bookmarks. + if (!m_pImpl->m_pRegisteredBookmark) + { + OSL_ENSURE(false, + "" + " - could not create Mark."); throw lang::IllegalArgumentException(); + } + // <-- } -void SwXBookmark::attachToRange(const uno::Reference< text::XTextRange > & xTextRange) - throw( lang::IllegalArgumentException, uno::RuntimeException ) +void SwXBookmark::attachToRange( + const uno::Reference< text::XTextRange > & xTextRange) +throw (lang::IllegalArgumentException, uno::RuntimeException) { attachToRangeEx(xTextRange, IDocumentMarkAccess::BOOKMARK); } -void SwXBookmark::attach(const uno::Reference< text::XTextRange > & xTextRange) - throw( lang::IllegalArgumentException, uno::RuntimeException ) +void SAL_CALL +SwXBookmark::attach(const uno::Reference< text::XTextRange > & xTextRange) +throw (lang::IllegalArgumentException, uno::RuntimeException) { vos::OGuard aGuard(Application::GetSolarMutex()); attachToRange( xTextRange ); } -uno::Reference< text::XTextRange > SwXBookmark::getAnchor(void) - throw( uno::RuntimeException ) +uno::Reference< text::XTextRange > SAL_CALL +SwXBookmark::getAnchor() throw (uno::RuntimeException) { vos::OGuard aGuard(Application::GetSolarMutex()); - uno::Reference< text::XTextRange > aRet; - if(m_pRegisteredBookmark) - aRet = SwXTextRange::CreateTextRangeFromPosition( - m_pDoc, - m_pRegisteredBookmark->GetMarkPos(), - m_pRegisteredBookmark->IsExpanded() ? &m_pRegisteredBookmark->GetOtherMarkPos() : NULL); - else + + if (!m_pImpl->m_pRegisteredBookmark) + { throw uno::RuntimeException(); - return aRet; + } + return SwXTextRange::CreateTextRangeFromPosition( + m_pImpl->m_pDoc, + m_pImpl->m_pRegisteredBookmark->GetMarkPos(), + (m_pImpl->m_pRegisteredBookmark->IsExpanded()) + ? &m_pImpl->m_pRegisteredBookmark->GetOtherMarkPos() : NULL); } -void SwXBookmark::dispose(void) - throw( uno::RuntimeException ) +void SAL_CALL SwXBookmark::dispose() throw (uno::RuntimeException) { vos::OGuard aGuard(Application::GetSolarMutex()); - if(m_pRegisteredBookmark) - GetDoc()->getIDocumentMarkAccess()->deleteMark(m_pRegisteredBookmark); - else - throw uno::RuntimeException(); + if (m_pImpl->m_pRegisteredBookmark) + { + m_pImpl->m_pDoc->getIDocumentMarkAccess()->deleteMark( + m_pImpl->m_pRegisteredBookmark); + } } -void SwXBookmark::addEventListener(const uno::Reference< lang::XEventListener > & aListener) - throw( uno::RuntimeException ) +void SAL_CALL SwXBookmark::addEventListener( + const uno::Reference< lang::XEventListener > & xListener) +throw (uno::RuntimeException) { - if(!m_pRegisteredBookmark) + vos::OGuard g(Application::GetSolarMutex()); + + if (!m_pImpl->m_pRegisteredBookmark) + { throw uno::RuntimeException(); - m_aLstnrCntnr.AddListener(aListener); + } + m_pImpl->m_ListenerContainer.AddListener(xListener); } -void SwXBookmark::removeEventListener(const uno::Reference< lang::XEventListener > & aListener) - throw( uno::RuntimeException ) +void SAL_CALL SwXBookmark::removeEventListener( + const uno::Reference< lang::XEventListener > & xListener) +throw (uno::RuntimeException) { - if(!m_pRegisteredBookmark || !m_aLstnrCntnr.RemoveListener(aListener)) + vos::OGuard g(Application::GetSolarMutex()); + + if (!m_pImpl->m_pRegisteredBookmark || + !m_pImpl->m_ListenerContainer.RemoveListener(xListener)) + { throw uno::RuntimeException(); + } } -OUString SwXBookmark::getName(void) - throw(uno::RuntimeException) +OUString SAL_CALL SwXBookmark::getName() +throw (uno::RuntimeException) { vos::OGuard aGuard(Application::GetSolarMutex()); - OUString sRet; - if(m_pRegisteredBookmark) - sRet = m_pRegisteredBookmark->GetName(); - else - sRet = m_aName; - return sRet; + + return (m_pImpl->m_pRegisteredBookmark) + ? m_pImpl->m_pRegisteredBookmark->GetName() + : m_pImpl->m_sMarkName; } -void SwXBookmark::setName(const OUString& rName) - throw(uno::RuntimeException) +void SAL_CALL SwXBookmark::setName(const OUString& rName) +throw (uno::RuntimeException) { vos::OGuard aGuard(Application::GetSolarMutex()); - if(!m_pRegisteredBookmark) - m_aName = rName; - if(!m_pRegisteredBookmark || getName() == rName) + + if (!m_pImpl->m_pRegisteredBookmark) + { + m_pImpl->m_sMarkName = rName; + } + if (!m_pImpl->m_pRegisteredBookmark || (getName() == rName)) + { return; - IDocumentMarkAccess* const pMarkAccess = m_pDoc->getIDocumentMarkAccess(); + } + IDocumentMarkAccess *const pMarkAccess = + m_pImpl->m_pDoc->getIDocumentMarkAccess(); if(pMarkAccess->findMark(rName) != pMarkAccess->getMarksEnd()) + { throw uno::RuntimeException(); + } - SwPaM aPam(m_pRegisteredBookmark->GetMarkPos()); - if(m_pRegisteredBookmark->IsExpanded()) + SwPaM aPam(m_pImpl->m_pRegisteredBookmark->GetMarkPos()); + if (m_pImpl->m_pRegisteredBookmark->IsExpanded()) { aPam.SetMark(); - *aPam.GetMark() = m_pRegisteredBookmark->GetOtherMarkPos(); + *aPam.GetMark() = m_pImpl->m_pRegisteredBookmark->GetOtherMarkPos(); } SwRewriter aRewriter; @@ -259,114 +379,145 @@ void SwXBookmark::setName(const OUString& rName) aRewriter.AddRule(UNDO_ARG2, SW_RES(STR_YIELDS)); aRewriter.AddRule(UNDO_ARG3, lcl_QuoteName(rName)); - m_pDoc->StartUndo(UNDO_BOOKMARK_RENAME, &aRewriter); - pMarkAccess->renameMark(m_pRegisteredBookmark, rName); - m_pDoc->EndUndo(UNDO_BOOKMARK_RENAME, NULL); + m_pImpl->m_pDoc->StartUndo(UNDO_BOOKMARK_RENAME, &aRewriter); + pMarkAccess->renameMark(m_pImpl->m_pRegisteredBookmark, rName); + m_pImpl->m_pDoc->EndUndo(UNDO_BOOKMARK_RENAME, NULL); } -OUString SwXBookmark::getImplementationName(void) throw( uno::RuntimeException ) +OUString SAL_CALL +SwXBookmark::getImplementationName() throw (uno::RuntimeException) { return OUString::createFromAscii("SwXBookmark"); } -sal_Bool SwXBookmark::supportsService(const OUString& rServiceName) - throw( uno::RuntimeException ) +static char const*const g_ServicesBookmark[] = { - return !rServiceName.compareToAscii("com.sun.star.text.Bookmark") || - !rServiceName.compareToAscii("com.sun.star.document.LinkTarget") || - !rServiceName.compareToAscii("com.sun.star.text.TextContent"); -} - -uno::Sequence< OUString > SwXBookmark::getSupportedServiceNames(void) - throw( uno::RuntimeException ) + "com.sun.star.text.TextContent", + "com.sun.star.text.Bookmark", + "com.sun.star.document.LinkTarget", +}; +static const size_t g_nServicesBookmark( + sizeof(g_ServicesBookmark)/sizeof(g_ServicesBookmark[0])); + +sal_Bool SAL_CALL SwXBookmark::supportsService(const OUString& rServiceName) +throw (uno::RuntimeException) { - uno::Sequence< OUString > aRet(3); - aRet[0] = OUString::createFromAscii("com.sun.star.text.Bookmark"); - aRet[1] = OUString::createFromAscii("com.sun.star.document.LinkTarget"); - aRet[2] = OUString::createFromAscii("com.sun.star.text.TextContent"); - return aRet; + return ::sw::SupportsServiceImpl( + g_nServicesBookmark, g_ServicesBookmark, rServiceName); } -void SwXBookmark::Modify(SfxPoolItem *pOld, SfxPoolItem *pNew) +uno::Sequence< OUString > SAL_CALL +SwXBookmark::getSupportedServiceNames() throw (uno::RuntimeException) { - ClientModify(this, pOld, pNew); - if(!GetRegisteredIn()) - { - m_pRegisteredBookmark = NULL; - m_pDoc = NULL; - m_aLstnrCntnr.Disposing(); - } + return ::sw::GetSupportedServiceNamesImpl( + g_nServicesBookmark, g_ServicesBookmark); } // MetadatableMixin ::sfx2::Metadatable* SwXBookmark::GetCoreObject() { - return dynamic_cast< ::sfx2::Metadatable* >( GetBookmark() ); + return dynamic_cast< ::sfx2::Metadatable* >(m_pImpl->m_pRegisteredBookmark); } uno::Reference SwXBookmark::GetModel() { - if (GetDoc()) + if (m_pImpl->m_pDoc) { - SwDocShell const * const pShell( GetDoc()->GetDocShell() ); + SwDocShell const * const pShell( m_pImpl->m_pDoc->GetDocShell() ); return (pShell) ? pShell->GetModel() : 0; } return 0; } -uno::Reference< beans::XPropertySetInfo > SwXBookmark::getPropertySetInfo(void) - throw( uno::RuntimeException ) +uno::Reference< beans::XPropertySetInfo > SAL_CALL +SwXBookmark::getPropertySetInfo() throw (uno::RuntimeException) { - static uno::Reference< beans::XPropertySetInfo > aRef; - if(!aRef.is()) - { - aRef = aSwMapProvider.GetPropertySet(PROPERTY_MAP_BOOKMARK)->getPropertySetInfo(); - } - return aRef; + vos::OGuard g(Application::GetSolarMutex()); + + static uno::Reference< beans::XPropertySetInfo > xRef( + aSwMapProvider.GetPropertySet(PROPERTY_MAP_BOOKMARK) + ->getPropertySetInfo() ); + return xRef; } -void SwXBookmark::setPropertyValue(const OUString& PropertyName, const uno::Any& /*aValue*/) - throw( beans::UnknownPropertyException, - beans::PropertyVetoException, - lang::IllegalArgumentException, - lang::WrappedTargetException, - uno::RuntimeException ) +void SAL_CALL +SwXBookmark::setPropertyValue(const OUString& PropertyName, + const uno::Any& /*rValue*/) +throw (beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, + uno::RuntimeException) { // nothing to set here - throw IllegalArgumentException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Property is read-only: " ) ) + PropertyName, static_cast < cppu::OWeakObject * > ( this ), 0 ); + throw lang::IllegalArgumentException( ::rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("Property is read-only: ")) + + PropertyName, static_cast< cppu::OWeakObject * >(this), 0 ); } -uno::Any SwXBookmark::getPropertyValue(const OUString& rPropertyName) - throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException ) +uno::Any SAL_CALL SwXBookmark::getPropertyValue(const OUString& rPropertyName) +throw (beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) { + vos::OGuard g(Application::GetSolarMutex()); + uno::Any aRet; if(!SwXParagraph::getDefaultTextContentValue(aRet, rPropertyName)) { if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_LINK_DISPLAY_NAME))) + { aRet <<= getName(); + } } return aRet; } -void SwXBookmark::addPropertyChangeListener(const OUString& /*PropertyName*/, - const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/) - throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException ) -{ } +void SAL_CALL +SwXBookmark::addPropertyChangeListener( + const ::rtl::OUString& /*rPropertyName*/, + const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/) +throw (beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + OSL_ENSURE(false, + "SwXBookmark::addPropertyChangeListener(): not implemented"); +} -void SwXBookmark::removePropertyChangeListener(const OUString& /*PropertyName*/, - const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/) - throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException ) -{ } +void SAL_CALL +SwXBookmark::removePropertyChangeListener( + const ::rtl::OUString& /*rPropertyName*/, + const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/) +throw (beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + OSL_ENSURE(false, + "SwXBookmark::removePropertyChangeListener(): not implemented"); +} -void SwXBookmark::addVetoableChangeListener(const OUString& /*PropertyName*/, - const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/) - throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException ) -{ } +void SAL_CALL +SwXBookmark::addVetoableChangeListener( + const ::rtl::OUString& /*rPropertyName*/, + const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/) +throw (beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + OSL_ENSURE(false, + "SwXBookmark::addVetoableChangeListener(): not implemented"); +} -void SwXBookmark::removeVetoableChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/) - throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException ) -{ } +void SAL_CALL +SwXBookmark::removeVetoableChangeListener( + const ::rtl::OUString& /*rPropertyName*/, + const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/) +throw (beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + OSL_ENSURE(false, + "SwXBookmark::removeVetoableChangeListener(): not implemented"); +} + +/****************************************************************** + * SwXFieldmark + ******************************************************************/ SwXFieldmark::SwXFieldmark(bool _isReplacementObject, ::sw::mark::IMark* pBkm, SwDoc* pDc) : SwXFieldmark_Base(pBkm, pDc) @@ -436,3 +587,4 @@ void SAL_CALL SwXFieldmark::setDescription( const ::rtl::OUString& description ) else throw uno::RuntimeException(); } + diff --git a/sw/source/core/unocore/unocoll.cxx b/sw/source/core/unocore/unocoll.cxx index 72606237ec70..87f96ba72346 100644 --- a/sw/source/core/unocore/unocoll.cxx +++ b/sw/source/core/unocore/unocoll.cxx @@ -1529,8 +1529,9 @@ uno::Any SwXBookmarks::getByIndex(sal_Int32 nIndex) uno::Any aRet; ::sw::mark::IMark* pBkmk = pMarkAccess->getBookmarksBegin()[nIndex].get(); - uno::Reference< XTextContent > xRef = GetObject(*pBkmk, GetDoc()); - aRet.setValue(&xRef, ::getCppuType((uno::Reference*)0)); + const uno::Reference< text::XTextContent > xRef = + SwXBookmark::CreateXBookmark(*GetDoc(), *pBkmk); + aRet <<= xRef; return aRet; } @@ -1547,8 +1548,9 @@ uno::Any SwXBookmarks::getByName(const rtl::OUString& rName) throw NoSuchElementException(); uno::Any aRet; - uno::Reference< XTextContent > xRef = SwXBookmarks::GetObject(*(ppBkmk->get()), GetDoc()); - aRet.setValue(&xRef, ::getCppuType((uno::Reference*)0)); + const uno::Reference< text::XTextContent > xRef = + SwXBookmark::CreateXBookmark(*GetDoc(), *(ppBkmk->get())); + aRet <<= xRef; return aRet; } @@ -1594,27 +1596,6 @@ sal_Bool SwXBookmarks::hasElements(void) return GetDoc()->getIDocumentMarkAccess()->getBookmarksCount() != 0; } -SwXBookmark* SwXBookmarks::GetObject( ::sw::mark::IMark& rBkmk, SwDoc* pDoc) -{ - SwModify* const pModify = static_cast(&rBkmk); - SwXBookmark* pXBkmk = (SwXBookmark*)SwClientIter(*pModify).First(TYPE(SwXBookmark)); - if(!pXBkmk) - { - // FIXME: These belong in XTextFieldsSupplier - //if (dynamic_cast< ::sw::mark::TextFieldmark* >(&rBkmk)) - // pXBkmk = new SwXFieldmark(false, &rBkmk, pDoc); - //else if (dynamic_cast< ::sw::mark::CheckboxFieldmark* >(&rBkmk)) - // pXBkmk = new SwXFieldmark(true, &rBkmk, pDoc); - //else - OSL_ENSURE( - dynamic_cast< ::sw::mark::IBookmark* >(&rBkmk), - "" - "SwXBookmark requested for non-bookmark mark."); - pXBkmk = new SwXBookmark(&rBkmk, pDoc); - } - return pXBkmk; -} - /****************************************************************** * ******************************************************************/ diff --git a/sw/source/core/unocore/unoportenum.cxx b/sw/source/core/unocore/unoportenum.cxx index e7426091f745..605554253bf8 100644 --- a/sw/source/core/unocore/unoportenum.cxx +++ b/sw/source/core/unocore/unoportenum.cxx @@ -100,8 +100,9 @@ namespace BYTE nBkmType; const SwPosition aPosition; - SwXBookmarkPortion_Impl( SwXBookmark* pXMark, BYTE nType, const SwPosition &rPosition ) - : xBookmark ( pXMark ) + SwXBookmarkPortion_Impl(uno::Reference const& xMark, + const BYTE nType, SwPosition const& rPosition) + : xBookmark ( xMark ) , nBkmType ( nType ) , aPosition ( rPosition ) { @@ -165,7 +166,9 @@ namespace { const BYTE nType = hasOther ? BKM_TYPE_START : BKM_TYPE_START_END; rBkmArr.insert(SwXBookmarkPortion_ImplSharedPtr( - new SwXBookmarkPortion_Impl ( SwXBookmarks::GetObject(*pBkmk, &rDoc ), nType, rStartPos))); + new SwXBookmarkPortion_Impl( + SwXBookmark::CreateXBookmark(rDoc, *pBkmk), + nType, rStartPos))); } const SwPosition& rEndPos = pBkmk->GetMarkEnd(); @@ -183,8 +186,12 @@ namespace pEndPos = pCrossRefEndPos.get(); } if(pEndPos) + { rBkmArr.insert(SwXBookmarkPortion_ImplSharedPtr( - new SwXBookmarkPortion_Impl ( SwXBookmarks::GetObject(*pBkmk, &rDoc ), BKM_TYPE_END, *pEndPos))); + new SwXBookmarkPortion_Impl( + SwXBookmark::CreateXBookmark(rDoc, *pBkmk), + BKM_TYPE_END, *pEndPos))); + } } } } diff --git a/sw/source/ui/uno/unotxvw.cxx b/sw/source/ui/uno/unotxvw.cxx index 9da88953d481..35a4c5a2f92c 100644 --- a/sw/source/ui/uno/unotxvw.cxx +++ b/sw/source/ui/uno/unotxvw.cxx @@ -433,19 +433,14 @@ sal_Bool SwXTextView::select(const uno::Any& aInterface) throw( lang::IllegalArg if(xBkm.is() && xIfcTunnel.is()) { - SwXBookmark* pBkm = reinterpret_cast( - xIfcTunnel->getSomething(SwXBookmark::getUnoTunnelId())); - if(pBkm && pBkm->GetDoc() == pDoc) + ::sw::mark::IMark const*const pMark( + SwXBookmark::GetBookmarkInDoc(pDoc, xIfcTunnel) ); + if (pMark) { - IDocumentMarkAccess* const pMarkAccess = rSh.getIDocumentMarkAccess(); - IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->findMark(pBkm->getName()); - if( ppMark != pMarkAccess->getMarksEnd() ) - { - rSh.EnterStdMode(); - rSh.GotoMark( ppMark->get() ); - } - return sal_True; + rSh.EnterStdMode(); + rSh.GotoMark(pMark); } + return sal_True; } // IndexMark, Index, TextField, Draw, Section, Footnote, Paragraph // -- cgit v1.2.3 From 220dc1e003f4a26a2d92b6c9bb2464a9b9d63b0e Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Fri, 8 Jan 2010 17:13:52 +0100 Subject: swunolocking1: #i105557#: SwXTextRange: try to hide the implementation detail that SwXTextRange registers at a bookmark from its clients by using SwXTextRange::GetPositions(). --- sw/inc/unotext.hxx | 5 +- sw/inc/unotextrange.hxx | 6 +- sw/source/core/inc/unometa.hxx | 4 +- sw/source/core/unocore/unoobj.cxx | 87 ++++++++---------------- sw/source/core/unocore/unoobj2.cxx | 8 +-- sw/source/core/unocore/unorefmk.cxx | 63 +++++------------- sw/source/core/unocore/unotext.cxx | 128 ++++++++++++++---------------------- sw/source/ui/uno/unoatxt.cxx | 48 ++++++-------- sw/source/ui/uno/unotxvw.cxx | 9 ++- 9 files changed, 130 insertions(+), 228 deletions(-) (limited to 'sw/source/core/inc') diff --git a/sw/inc/unotext.hxx b/sw/inc/unotext.hxx index 499e0620dae4..97a45ece73cf 100644 --- a/sw/inc/unotext.hxx +++ b/sw/inc/unotext.hxx @@ -93,7 +93,7 @@ private: virtual void PrepareForAttach( ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > & xRange, - SwXTextRange const * const pRange, SwPaM const * const pPam); + SwPaM const & rPam); protected: @@ -136,8 +136,7 @@ public: throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); virtual bool CheckForOwnMemberMeta( - const SwXTextRange* const pRange, - const SwPaM* const pPam, bool bAbsorb) + const SwPaM & rPam, const bool bAbsorb) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); diff --git a/sw/inc/unotextrange.hxx b/sw/inc/unotextrange.hxx index 94d4996b4633..079296d2a441 100644 --- a/sw/inc/unotextrange.hxx +++ b/sw/inc/unotextrange.hxx @@ -130,7 +130,9 @@ private: xParentText; ::sw::mark::IMark* pMark; - void _CreateNewBookmark(SwPaM& rPam); + const ::sw::mark::IMark * GetBookmark() const + { return pMark; } + void SetPositions(SwPaM const& rPam); //TODO: new exception type for protected content void DeleteAndInsert(const String& rText, const bool bForceExpandHints) throw (::com::sun::star::uno::RuntimeException); @@ -153,8 +155,6 @@ public: { return pDoc; } SwDoc* GetDoc() { return pDoc; } - const ::sw::mark::IMark * GetBookmark() const - { return pMark; } static BOOL XTextRangeToSwPaM(SwUnoInternalPaM& rToFill, const ::com::sun::star::uno::Reference< diff --git a/sw/source/core/inc/unometa.hxx b/sw/source/core/inc/unometa.hxx index 5568aa88b52e..39f81caa902a 100755 --- a/sw/source/core/inc/unometa.hxx +++ b/sw/source/core/inc/unometa.hxx @@ -52,7 +52,6 @@ typedef ::std::deque< ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > > TextRangeList_t; -class SwXTextRange; class SwPaM; class SwTxtNode; @@ -117,8 +116,7 @@ public: ::com::sun::star::uno::Reference< ::com::sun::star::text::XText > GetParentText() const; - bool CheckForOwnMemberMeta(const SwXTextRange* const pRange, - const SwPaM* const pPam, bool bAbsorb) + bool CheckForOwnMemberMeta(const SwPaM & rPam, const bool bAbsorb) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); diff --git a/sw/source/core/unocore/unoobj.cxx b/sw/source/core/unocore/unoobj.cxx index eb89201cf978..b48451b90cf9 100644 --- a/sw/source/core/unocore/unoobj.cxx +++ b/sw/source/core/unocore/unoobj.cxx @@ -1181,17 +1181,26 @@ void SwXTextCursor::gotoRange(const uno::Reference< XTextRange > & xRange, sal_B const SwStartNode* pOwnStartNode = pOwnCursor->GetNode()-> FindSttNodeByType(eSearchNodeType); - const SwNode* pSrcNode = 0; - if(pCursor && pCursor->GetPaM()) + SwPaM aPam(GetDoc()->GetNodes()); + const SwPaM * pPam(0); + if (pCursor) { - pSrcNode = pCursor->GetPaM()->GetNode(); + pPam = pCursor->GetPaM(); } - else if(pRange && pRange->GetBookmark()) + else if (pRange) { - ::sw::mark::IMark const * const pBkmk = pRange->GetBookmark(); - pSrcNode = &pBkmk->GetMarkPos().nNode.GetNode(); + if (pRange->GetPositions(aPam)) + { + pPam = & aPam; + } + } + + if (!pPam) + { + throw uno::RuntimeException(); } - const SwStartNode* pTmp = pSrcNode ? pSrcNode->FindSttNodeByType(eSearchNodeType) : 0; + const SwStartNode* pTmp = + pPam->GetNode()->FindSttNodeByType(eSearchNodeType); //SectionNodes ueberspringen while(pTmp && pTmp->IsSectionNode()) @@ -1209,16 +1218,9 @@ void SwXTextCursor::gotoRange(const uno::Reference< XTextRange > & xRange, sal_B if (CURSOR_META == eType) { - const SwPosition & rPoint( (pRange) - ? pRange->GetBookmark()->GetMarkPos() - : *pCursor->GetPaM()->GetPoint() ); - const SwPosition & rMark ( (pRange) - ? ((pRange->GetBookmark()->IsExpanded()) - ? pRange->GetBookmark()->GetOtherMarkPos() : rPoint) - : *pCursor->GetPaM()->GetMark() ); - SwPaM aPam(rPoint, rMark); + SwPaM CopyPam(*pPam->GetMark(), *pPam->GetPoint()); const bool bNotForced( - lcl_ForceIntoMeta(aPam, xParentText, META_CHECK_BOTH) ); + lcl_ForceIntoMeta(CopyPam, xParentText, META_CHECK_BOTH) ); if (!bNotForced) { throw uno::RuntimeException( @@ -1241,26 +1243,9 @@ void SwXTextCursor::gotoRange(const uno::Reference< XTextRange > & xRange, sal_B aOwnLeft = aOwnRight; aOwnRight = aTmp; } - SwPosition* pParamLeft; - SwPosition* pParamRight; - if(pCursor) - { - const SwPaM* pTmp2 = pCursor->GetPaM(); - pParamLeft = new SwPosition(*pTmp2->GetPoint()); - pParamRight = new SwPosition(pTmp2->HasMark() ? *pTmp2->GetMark() : *pParamLeft); - } - else - { - ::sw::mark::IMark const * const pBkmk = pRange->GetBookmark(); - pParamLeft = new SwPosition(pBkmk->GetMarkPos()); - pParamRight = new SwPosition(pBkmk->IsExpanded() ? pBkmk->GetOtherMarkPos() : *pParamLeft); - } - if(*pParamRight < *pParamLeft) - { - SwPosition* pTmp2 = pParamLeft; - pParamLeft = pParamRight; - pParamRight = pTmp2; - } + SwPosition const* pParamLeft = pPam->Start(); + SwPosition const* pParamRight = pPam->End(); + // jetzt sind vier SwPositions da, zwei davon werden gebraucht, also welche? if(aOwnRight > *pParamRight) *pOwnCursor->GetPoint() = aOwnRight; @@ -1271,35 +1256,19 @@ void SwXTextCursor::gotoRange(const uno::Reference< XTextRange > & xRange, sal_B *pOwnCursor->GetMark() = aOwnLeft; else *pOwnCursor->GetMark() = *pParamLeft; - delete pParamLeft; - delete pParamRight; } else { - //der Cursor soll dem uebergebenen Range entsprechen - if(pCursor) + // cursor should be the given range + *pOwnCursor->GetPoint() = *pPam->GetPoint(); + if (pPam->HasMark()) { - const SwPaM* pTmp2 = pCursor->GetPaM(); - *pOwnCursor->GetPoint() = *pTmp2->GetPoint(); - if(pTmp2->HasMark()) - { - pOwnCursor->SetMark(); - *pOwnCursor->GetMark() = *pTmp2->GetMark(); - } - else - pOwnCursor->DeleteMark(); + pOwnCursor->SetMark(); + *pOwnCursor->GetMark() = *pPam->GetMark(); } else { - ::sw::mark::IMark const * const pBkmk = pRange->GetBookmark(); - *pOwnCursor->GetPoint() = pBkmk->GetMarkPos(); - if(pBkmk->IsExpanded()) - { - pOwnCursor->SetMark(); - *pOwnCursor->GetMark() = pBkmk->GetOtherMarkPos(); - } - else - pOwnCursor->DeleteMark(); + pOwnCursor->DeleteMark(); } } } @@ -1923,7 +1892,7 @@ void SwXTextCursor::setString(const OUString& aString) throw( uno::RuntimeExcept const bool bForceExpandHints( (CURSOR_META != eType) ? false : dynamic_cast(xParentText.get())->CheckForOwnMemberMeta( - 0, GetPaM(), true) ); + *GetPaM(), true) ); DeleteAndInsert(aString, bForceExpandHints); } /* -----------------------------03.05.00 12:56-------------------------------- diff --git a/sw/source/core/unocore/unoobj2.cxx b/sw/source/core/unocore/unoobj2.cxx index 57c533833985..6ca031d041ba 100644 --- a/sw/source/core/unocore/unoobj2.cxx +++ b/sw/source/core/unocore/unoobj2.cxx @@ -1377,7 +1377,7 @@ SwXTextRange::SwXTextRange(SwPaM& rPam, xParentText(rxParent), pMark(NULL) { - _CreateNewBookmark(rPam); + SetPositions(rPam); } SwXTextRange::SwXTextRange(SwFrmFmt& rTblFmt) : @@ -1394,7 +1394,7 @@ SwXTextRange::SwXTextRange(SwFrmFmt& rTblFmt) : SwPosition aPosition( *pTblNode ); SwPaM aPam( aPosition ); - _CreateNewBookmark( aPam ); + SetPositions( aPam ); } SwXTextRange::~SwXTextRange() @@ -1405,7 +1405,7 @@ SwXTextRange::~SwXTextRange() pDoc->getIDocumentMarkAccess()->deleteMark(pBkmk); } -void SwXTextRange::_CreateNewBookmark(SwPaM& rPam) +void SwXTextRange::SetPositions(const SwPaM& rPam) { IDocumentMarkAccess* const pMarkAccess = pDoc->getIDocumentMarkAccess(); @@ -1452,7 +1452,7 @@ void SwXTextRange::DeleteAndInsert( SwXTextCursor::SelectPam(aNewCrsr, sal_True); aNewCrsr.Left(rText.Len(), CRSR_SKIP_CHARS, FALSE, FALSE); } - _CreateNewBookmark(aNewCrsr); + SetPositions(aNewCrsr); pDoc->EndUndo(UNDO_INSERT, NULL); } } diff --git a/sw/source/core/unocore/unorefmk.cxx b/sw/source/core/unocore/unorefmk.cxx index 39e93acd19dc..68516a923eb7 100644 --- a/sw/source/core/unocore/unorefmk.cxx +++ b/sw/source/core/unocore/unorefmk.cxx @@ -586,12 +586,10 @@ private: SwXMeta & m_rMeta; virtual void PrepareForAttach(uno::Reference< text::XTextRange > & xRange, - const SwXTextRange* const pRange, const SwPaM * const pPam); + const SwPaM & rPam); - virtual bool CheckForOwnMemberMeta(const SwXTextRange* const pRange, - const SwPaM* const pPam, bool bAbsorb) - throw (::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::uno::RuntimeException); + virtual bool CheckForOwnMemberMeta(const SwPaM & rPam, const bool bAbsorb) + throw (lang::IllegalArgumentException, uno::RuntimeException); protected: virtual const SwStartNode *GetStartNode() const; @@ -637,41 +635,18 @@ const SwStartNode *SwXMetaText::GetStartNode() const } void SwXMetaText::PrepareForAttach( uno::Reference & xRange, - const SwXTextRange* const pRange, const SwPaM * const pPam) + const SwPaM & rPam) { - SwPosition const* pPoint(0); - SwPosition const* pMark (0); - if (pRange) - { - ::sw::mark::IMark const& rIMark(*pRange->GetBookmark()); - pMark = &rIMark.GetMarkPos(); - if (rIMark.IsExpanded()) - { - pMark = &rIMark.GetOtherMarkPos(); - } - } - else if (pPam) - { - pPoint = pPam->GetPoint(); - if (pPam->HasMark()) - { - pMark = pPam->GetMark(); - } - } // create a new cursor to prevent modifying SwXTextRange - if (pPoint) - { - xRange = static_cast( - new SwXTextCursor(&m_rMeta, *pPoint, CURSOR_META, GetDoc(), pMark)); - } + xRange = static_cast( + new SwXTextCursor(&m_rMeta, *rPam.GetPoint(), CURSOR_META, + GetDoc(), (rPam.HasMark()) ? rPam.GetMark() : 0)); } -bool SwXMetaText::CheckForOwnMemberMeta(const SwXTextRange* const pRange, - const SwPaM* const pPam, bool bAbsorb) - throw (::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::uno::RuntimeException) +bool SwXMetaText::CheckForOwnMemberMeta(const SwPaM & rPam, const bool bAbsorb) + throw (lang::IllegalArgumentException, uno::RuntimeException) { - return m_rMeta.CheckForOwnMemberMeta(pRange, pPam, bAbsorb); + return m_rMeta.CheckForOwnMemberMeta(rPam, bAbsorb); } uno::Reference< text::XTextCursor > SwXMetaText::createCursor() @@ -884,11 +859,9 @@ bool SwXMeta::SetContentRange( return false; } -bool SwXMeta::CheckForOwnMemberMeta(const SwXTextRange* const pRange, - const SwPaM* const pPam, bool bAbsorb) +bool SwXMeta::CheckForOwnMemberMeta(const SwPaM & rPam, const bool bAbsorb) throw (lang::IllegalArgumentException, uno::RuntimeException) { - ASSERT((pPam && !pRange) || (!pPam && pRange), "ERROR: pam xor range"); SwTxtNode * pTxtNode; xub_StrLen nMetaStart; xub_StrLen nMetaEnd; @@ -896,9 +869,8 @@ bool SwXMeta::CheckForOwnMemberMeta(const SwXTextRange* const pRange, ASSERT(bSuccess, "no pam?"); if (!bSuccess) throw lang::DisposedException(); - SwPosition const * const pStartPos( (pPam) - ? pPam->Start() - : &pRange->GetBookmark()->GetMarkStart() ); + + SwPosition const * const pStartPos( rPam.Start() ); if (&pStartPos->nNode.GetNode() != pTxtNode) { throw lang::IllegalArgumentException( @@ -921,14 +893,9 @@ bool SwXMeta::CheckForOwnMemberMeta(const SwXTextRange* const pRange, { bForceExpandHints = true; } - const bool bHasEnd( (pPam) - ? pPam->HasMark() - : pRange->GetBookmark()->IsExpanded()); - if (bHasEnd && bAbsorb) + if (rPam.HasMark() && bAbsorb) { - SwPosition const * const pEndPos( (pPam) - ? pPam->End() - : &pRange->GetBookmark()->GetMarkEnd() ); + SwPosition const * const pEndPos( rPam.End() ); if (&pEndPos->nNode.GetNode() != pTxtNode) { throw lang::IllegalArgumentException( diff --git a/sw/source/core/unocore/unotext.cxx b/sw/source/core/unocore/unotext.cxx index 4b0a259f2120..7c0fe114b489 100644 --- a/sw/source/core/unocore/unotext.cxx +++ b/sw/source/core/unocore/unotext.cxx @@ -91,16 +91,13 @@ const sal_Char cInvalidObject[] = "this object is invalid"; -----------------------------------------------------------------------*/ -void SwXText::PrepareForAttach( ::com::sun::star::uno::Reference< - ::com::sun::star::text::XTextRange > &, - const SwXTextRange* const, const SwPaM * const) +void +SwXText::PrepareForAttach(uno::Reference< text::XTextRange > &, const SwPaM &) { } -bool SwXText::CheckForOwnMemberMeta(const SwXTextRange* const, - const SwPaM* const, bool) - throw (::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::uno::RuntimeException) +bool SwXText::CheckForOwnMemberMeta(const SwPaM &, const bool) + throw (lang::IllegalArgumentException, uno::RuntimeException) { ASSERT(CURSOR_META != eCrsrType, "should not be called!"); return false; @@ -285,35 +282,43 @@ void SwXText::insertString(const uno::Reference< text::XTextRange >& xTextRange, if(pRange && pRange->GetDoc() == GetDoc() || pCursor && pCursor->GetDoc() == GetDoc()) { - const SwStartNode* pOwnStartNode = GetStartNode(); - if(pCursor) + const SwStartNode *const pOwnStartNode = GetStartNode(); + SwPaM aPam(GetDoc()->GetNodes()); + const SwPaM * pPam(0); + if (pCursor) { - const SwStartNode* pTmp = pCursor->GetPaM()->GetNode()->StartOfSectionNode(); - while(pTmp && pTmp->IsSectionNode()) - { - pTmp = pTmp->StartOfSectionNode(); - } - if( !pOwnStartNode || pOwnStartNode != pTmp) + pPam = pCursor->GetPaM(); + } + else // pRange + { + if (pRange->GetPositions(aPam)) { - throw uno::RuntimeException(); + pPam = &aPam; } } - else //dann pRange + if (!pPam) { - ::sw::mark::IMark const * const pBkmk = pRange->GetBookmark(); - const SwStartNode* pTmp = pBkmk->GetMarkPos().nNode.GetNode().StartOfSectionNode(); - while(pTmp && pTmp->IsSectionNode()) + throw uno::RuntimeException(); + } + else + { + const SwStartNode* pTmp(pPam->GetNode()->StartOfSectionNode()); + while (pTmp && pTmp->IsSectionNode()) + { pTmp = pTmp->StartOfSectionNode(); - if(!pOwnStartNode || pOwnStartNode != pTmp) + } + if (!pOwnStartNode || (pOwnStartNode != pTmp)) + { throw uno::RuntimeException(); + } } + bool bForceExpandHints( false ); if (CURSOR_META == eCrsrType) { try { - bForceExpandHints = CheckForOwnMemberMeta( - pRange, (pCursor) ? pCursor->GetPaM() : 0, bAbsorb); + bForceExpandHints = CheckForOwnMemberMeta(*pPam, bAbsorb); } catch (lang::IllegalArgumentException & iae) { @@ -348,10 +353,7 @@ void SwXText::insertString(const uno::Reference< text::XTextRange >& xTextRange, //hier wird ein PaM angelegt, der vor dem Parameter-PaM liegt, damit der //Text davor eingefuegt wird UnoActionContext aContext(GetDoc()); - const SwPosition* pPos = pCursor - ? pCursor->GetPaM()->Start() - : &pRange->GetBookmark()->GetMarkStart(); - SwPaM aInsertPam(*pPos); + SwPaM aInsertPam(*pPam->Start()); const sal_Bool bGroupUndo = GetDoc()->DoesGroupUndo(); GetDoc()->DoGroupUndo(sal_False); @@ -382,8 +384,7 @@ void SwXText::insertControlCharacter(const uno::Reference< text::XTextRange > & SwUnoInternalPaM aPam(*GetDoc()); if(SwXTextRange::XTextRangeToSwPaM(aPam, xTextRange)) { - const bool bForceExpandHints( - CheckForOwnMemberMeta( 0, &aPam, bAbsorb) ); + const bool bForceExpandHints(CheckForOwnMemberMeta(aPam, bAbsorb)); const enum IDocumentContentOperations::InsertFlags nInsertFlags = (bForceExpandHints) @@ -424,7 +425,7 @@ void SwXText::insertControlCharacter(const uno::Reference< text::XTextRange > & } if(pRange) { - pRange->_CreateNewBookmark(aTmp); + pRange->SetPositions(aTmp); } else if(pCursor) { @@ -462,7 +463,9 @@ void SwXText::insertControlCharacter(const uno::Reference< text::XTextRange > & aCrsr.Left(1, CRSR_SKIP_CHARS, FALSE, FALSE); //hier muss der uebergebene PaM umgesetzt werden: if(pRange) - pRange->_CreateNewBookmark(aCrsr); + { + pRange->SetPositions(aCrsr); + } else { SwPaM* pUnoCrsr = pCursor->GetPaM(); @@ -541,33 +544,8 @@ void SwXText::insertTextContent(const uno::Reference< text::XTextRange > & xRang ; } - const SwNode* pSrcNode = 0; - if(pCursor && pCursor->GetPaM()) - { - pSrcNode = pCursor->GetPaM()->GetNode(); - } - else if (pRange && pRange->GetBookmark()) - { - ::sw::mark::IMark const * const pBkmk = pRange->GetBookmark(); - pSrcNode = &pBkmk->GetMarkPos().nNode.GetNode(); - } - else if (pPortion && pPortion->GetCursor()) - { - pSrcNode = pPortion->GetCursor()->GetNode(); - } - else if (pText) - { - uno::Reference xTextCursor = pText->createCursor(); - xTextCursor->gotoEnd(sal_True); - uno::Reference xCrsrTunnel( xTextCursor, uno::UNO_QUERY ); - pCursor = reinterpret_cast< OTextCursorHelper * >( - sal::static_int_cast< sal_IntPtr >( xCrsrTunnel->getSomething( OTextCursorHelper::getUnoTunnelId()) )); - pSrcNode = pCursor->GetPaM()->GetNode(); - } - else - throw lang::IllegalArgumentException(); - - const SwStartNode* pTmp = pSrcNode->FindSttNodeByType(eSearchNodeType); + const SwStartNode* pTmp = + aPam.GetNode()->FindSttNodeByType(eSearchNodeType); //SectionNodes ueberspringen while(pTmp && pTmp->IsSectionNode()) @@ -587,8 +565,7 @@ void SwXText::insertTextContent(const uno::Reference< text::XTextRange > & xRang throw aRunException; } - const bool bForceExpandHints( CheckForOwnMemberMeta( - pRange, (pCursor) ? pCursor->GetPaM() : 0, bAbsorb) ); + const bool bForceExpandHints(CheckForOwnMemberMeta(aPam, bAbsorb)); // Sonderbehandlung fuer Contents, die den Range nicht ersetzen, sonder darueber gelegt werden // Bookmarks, IndexEntry @@ -627,8 +604,7 @@ void SwXText::insertTextContent(const uno::Reference< text::XTextRange > & xRang if (bForceExpandHints) { // if necessary, replace xTempRange with a new SwXTextCursor - PrepareForAttach(xTempRange, pRange, - (pCursor) ? pCursor->GetPaM() : 0); + PrepareForAttach(xTempRange, aPam); } xContent->attach(xTempRange); } @@ -1047,13 +1023,19 @@ sal_Bool SwXText::CheckForOwnMember( } const SwNode* pSrcNode; - if(pCursor) + if (pCursor) + { pSrcNode = pCursor->GetPaM()->GetNode(); - else //dann pRange + } + else // pRange { - ::sw::mark::IMark const * const pBkmk = pRange->GetBookmark(); - pSrcNode = &pBkmk->GetMarkPos().nNode.GetNode(); + SwPaM aPam(pRange->GetDoc()->GetNodes().GetEndOfContent()); + if (pRange->GetPositions(aPam)) + { + pSrcNode = aPam.GetNode(); + } } + if (!pSrcNode) { return sal_False; } const SwStartNode* pTmp = pSrcNode->FindSttNodeByType(eSearchNodeType); //SectionNodes ueberspringen @@ -1107,18 +1089,8 @@ sal_Int16 SwXText::ComparePositions( if(CheckForOwnMember(pRange1, pCursor1) && CheckForOwnMember( pRange2, pCursor2)) { - const SwPosition *pStart1 = 0; - const SwPosition *pStart2 = 0; - - if(pRange1) - pStart1 = pRange1->GetBookmark() ? &(pRange1->GetBookmark()->GetMarkStart()) : 0; - else - pStart1 = pCursor1->GetPaM() ? pCursor1->GetPaM()->Start() : 0; - - if(pRange2) - pStart2 = pRange2->GetBookmark() ? &(pRange2->GetBookmark()->GetMarkStart()) : 0; - else - pStart2 = pCursor2->GetPaM() ? pCursor2->GetPaM()->Start() : 0; + SwPosition const*const pStart1 = aPam1.Start(); + SwPosition const*const pStart2 = aPam2.Start(); if(pStart1 && pStart2) { diff --git a/sw/source/ui/uno/unoatxt.cxx b/sw/source/ui/uno/unoatxt.cxx index 87d27b15a76b..d3e03aa307a6 100644 --- a/sw/source/ui/uno/unoatxt.cxx +++ b/sw/source/ui/uno/unoatxt.cxx @@ -411,25 +411,25 @@ sal_Bool lcl_CopySelToDoc( SwDoc* pInsDoc, OTextCursorHelper* pxCursor, SwXTextR SwCntntNode * pNd = aIdx.GetNode().GetCntntNode(); SwPosition aPos( aIdx, SwIndex( pNd, pNd->Len() )); - sal_Bool bRet = sal_False; + bool bRet = false; pInsDoc->LockExpFlds(); { + SwDoc *const pDoc((pxCursor) ? pxCursor->GetDoc() : pxRange->GetDoc()); + SwPaM aPam(pDoc->GetNodes()); + SwPaM * pPam(0); if(pxCursor) { - SwPaM* pUnoCrsr = pxCursor->GetPaM(); - bRet = pxCursor->GetDoc()->CopyRange( *pUnoCrsr, aPos, false ) - || bRet; + pPam = pxCursor->GetPaM(); } else { - const ::sw::mark::IMark* const pBkmk = pxRange->GetBookmark(); - if(pBkmk && pBkmk->IsExpanded()) + if (pxRange->GetPositions(aPam)) { - SwPaM aTmp(pBkmk->GetOtherMarkPos(), pBkmk->GetMarkPos()); - bRet = pxRange->GetDoc()->CopyRange(aTmp, aPos, false) - || bRet; + pPam = & aPam; } } + if (!pPam) { return false; } + bRet = pDoc->CopyRange( *pPam, aPos, false ) || bRet; } pInsDoc->UnlockExpFlds(); @@ -1113,7 +1113,7 @@ void SwXAutoTextEntry::applyTo(const uno::Reference< text::XTextRange > & xTextR } SwDoc* pDoc = 0; - if ( pRange && pRange->GetBookmark()) + if (pRange) pDoc = pRange->GetDoc(); else if ( pCursor ) pDoc = pCursor->GetDoc(); @@ -1131,29 +1131,23 @@ void SwXAutoTextEntry::applyTo(const uno::Reference< text::XTextRange > & xTextR if(!pDoc) throw uno::RuntimeException(); - SwPaM* pInsertPaM = 0; - if(pRange) + + SwPaM InsertPaM(pDoc->GetNodes()); + if (pRange) { - const ::sw::mark::IMark* const pBkmk = pRange->GetBookmark(); - if(pBkmk->IsExpanded()) - pInsertPaM = new SwPaM(pBkmk->GetOtherMarkPos(), pBkmk->GetMarkPos()); - else - pInsertPaM = new SwPaM(pBkmk->GetMarkPos()); + if (!pRange->GetPositions(InsertPaM)) + { + throw uno::RuntimeException(); + } } else { - SwPaM* pCrsr = pCursor->GetPaM(); - if(pCrsr->HasMark()) - pInsertPaM = new SwPaM(*pCrsr->GetPoint(), *pCrsr->GetMark()); - else - pInsertPaM = new SwPaM(*pCrsr->GetPoint()); + InsertPaM = *pCursor->GetPaM(); } - SwTextBlocks* pBlock = pGlossaries->GetGroupDoc(sGroupName); - sal_Bool bResult = pBlock && !pBlock->GetError() && - pDoc->InsertGlossary( *pBlock, sEntryName, *pInsertPaM); - delete pBlock; - delete pInsertPaM; + ::std::auto_ptr pBlock(pGlossaries->GetGroupDoc(sGroupName)); + const bool bResult = pBlock.get() && !pBlock->GetError() + && pDoc->InsertGlossary( *pBlock, sEntryName, InsertPaM); if(!bResult) throw uno::RuntimeException(); diff --git a/sw/source/ui/uno/unotxvw.cxx b/sw/source/ui/uno/unotxvw.cxx index 6df8553be298..9e637ca58260 100644 --- a/sw/source/ui/uno/unotxvw.cxx +++ b/sw/source/ui/uno/unotxvw.cxx @@ -1418,10 +1418,13 @@ void SwXTextViewCursor::gotoRange( { pSrcNode = pCursor->GetPaM()->GetNode(); } - else if(pRange && pRange->GetBookmark()) + else if (pRange) { - const ::sw::mark::IMark* const pBkmk = pRange->GetBookmark(); - pSrcNode = &(pBkmk->GetMarkPos().nNode.GetNode()); + SwPaM aPam(pRange->GetDoc()->GetNodes()); + if (pRange->GetPositions(aPam)) + { + pSrcNode = aPam.GetNode(); + } } else if (pPara && pPara->GetTxtNode()) { -- cgit v1.2.3 From 82aba30102fe1cce3f6582bfbe29bacb7498363d Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Fri, 8 Jan 2010 17:13:59 +0100 Subject: swunolocking1: #i105557#: remove class SwUnoCallBack. everything SwUnoCallBack class does has unfixable race conditions. in SwDoc, the uno callback is now a plain SwModify. --- sw/inc/doc.hxx | 3 +- sw/source/core/doc/docnew.cxx | 3 +- sw/source/core/inc/unoclbck.hxx | 52 --------------------- sw/source/core/unocore/makefile.mk | 1 - sw/source/core/unocore/unoclbck.cxx | 85 ---------------------------------- sw/source/core/unocore/unocoll.cxx | 1 - sw/source/core/unocore/unoobj.cxx | 1 - sw/source/core/unocore/unoobj2.cxx | 1 - sw/source/core/unocore/unoportenum.cxx | 16 ++----- 9 files changed, 6 insertions(+), 157 deletions(-) delete mode 100644 sw/source/core/inc/unoclbck.hxx delete mode 100644 sw/source/core/unocore/unoclbck.cxx (limited to 'sw/source/core/inc') diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx index de82d9056ff9..0066b37b4575 100644 --- a/sw/inc/doc.hxx +++ b/sw/inc/doc.hxx @@ -199,7 +199,6 @@ class SwLayouter; class SdrView; class SdrMarkList; class SwAuthEntry; -class SwUnoCallBack; class SwLayoutCache; class IStyleAccess; struct SwCallMouseEvent; @@ -391,7 +390,7 @@ class SW_DLLPUBLIC SwDoc : SwLayoutCache *pLayoutCache; // Layout cache to read and save with the // document for a faster formatting - SwUnoCallBack *pUnoCallBack; + SwModify *pUnoCallBack; IGrammarContact *mpGrammarContact; // for grammar checking in paragraphs during editing mutable comphelper::ImplementationReference< SwChartDataProvider diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx index 71c42cf27176..7b333ad1f960 100644 --- a/sw/source/core/doc/docnew.cxx +++ b/sw/source/core/doc/docnew.cxx @@ -90,7 +90,6 @@ #include #include #include -#include #include #include #include @@ -259,7 +258,7 @@ SwDoc::SwDoc() : pStyleAccess( 0 ), // <-- pLayoutCache( 0 ), - pUnoCallBack(new SwUnoCallBack(0)), + pUnoCallBack(new SwModify(0)), mpGrammarContact( 0 ), aChartDataProviderImplRef(), pChartControllerHelper( 0 ), diff --git a/sw/source/core/inc/unoclbck.hxx b/sw/source/core/inc/unoclbck.hxx deleted file mode 100644 index 30a338f358f6..000000000000 --- a/sw/source/core/inc/unoclbck.hxx +++ /dev/null @@ -1,52 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: unoclbck.hxx,v $ - * $Revision: 1.6 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ -#ifndef _UNOCLBCK_HXX -#define _UNOCLBCK_HXX -#include - -class SwXReferenceMark; -class SwFmtRefMark; -class SwFmtFtn; -class SwXFootnote; -class SwTOXMark; -class SwXDocumentIndexMark; - -class SwUnoCallBack : public SwModify -{ -public: - SwUnoCallBack(SwModify *pToRegisterIn); - virtual ~SwUnoCallBack(); - - // returns the API object of a reference mark if available - SwXReferenceMark* GetRefMark(const SwFmtRefMark& rMark); - SwXFootnote* GetFootnote(const SwFmtFtn& rMark); - SwXDocumentIndexMark* GetTOXMark(const SwTOXMark& rMark); -}; -#endif diff --git a/sw/source/core/unocore/makefile.mk b/sw/source/core/unocore/makefile.mk index b364956a3d0c..31c6f4f72668 100644 --- a/sw/source/core/unocore/makefile.mk +++ b/sw/source/core/unocore/makefile.mk @@ -115,7 +115,6 @@ SLOFILES = \ $(SLO)$/unotextmarkup.obj\ $(SLO)$/TextCursorHelper.obj \ $(SLO)$/unotext.obj\ - $(SLO)$/unoclbck.obj\ $(SLO)$/unomap.obj\ $(SLO)$/unoprnms.obj\ $(SLO)$/XMLRangeHelper.obj diff --git a/sw/source/core/unocore/unoclbck.cxx b/sw/source/core/unocore/unoclbck.cxx deleted file mode 100644 index 6e5b08210147..000000000000 --- a/sw/source/core/unocore/unoclbck.cxx +++ /dev/null @@ -1,85 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: unoclbck.cxx,v $ - * $Revision: 1.10 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_sw.hxx" - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* -----------------------------06.01.00 13:51-------------------------------- - - ---------------------------------------------------------------------------*/ -SwUnoCallBack::SwUnoCallBack(SwModify *pToRegisterIn) : - SwModify(pToRegisterIn) -{ -} -/* -----------------------------06.01.00 13:51-------------------------------- - - ---------------------------------------------------------------------------*/ -SwUnoCallBack::~SwUnoCallBack() -{ -} -/* -----------------------------01.09.00 12:03-------------------------------- - - ---------------------------------------------------------------------------*/ -SwXReferenceMark* SwUnoCallBack::GetRefMark(const SwFmtRefMark& rMark) -{ - return SwXReferenceMark::GetReferenceMark(*this, rMark); -} - -/* -----------------------------05.09.00 12:38-------------------------------- - - ---------------------------------------------------------------------------*/ -SwXFootnote* SwUnoCallBack::GetFootnote(const SwFmtFtn& rMark) -{ - return SwXFootnote::GetXFootnote(*this, rMark); -} - -/* -----------------------------27.11.00 17:15-------------------------------- - - ---------------------------------------------------------------------------*/ -SwXDocumentIndexMark* SwUnoCallBack::GetTOXMark(const SwTOXMark& /*rMark*/) -{ - return 0; -} - diff --git a/sw/source/core/unocore/unocoll.cxx b/sw/source/core/unocore/unocoll.cxx index 57f9b05a9c01..daafeb65888b 100644 --- a/sw/source/core/unocore/unocoll.cxx +++ b/sw/source/core/unocore/unocoll.cxx @@ -43,7 +43,6 @@ #include #include #include -#include #include #include #include diff --git a/sw/source/core/unocore/unoobj.cxx b/sw/source/core/unocore/unoobj.cxx index ba86f9c509b1..e1601dcbcad1 100644 --- a/sw/source/core/unocore/unoobj.cxx +++ b/sw/source/core/unocore/unoobj.cxx @@ -84,7 +84,6 @@ #include #include #include -#include #include #include #include diff --git a/sw/source/core/unocore/unoobj2.cxx b/sw/source/core/unocore/unoobj2.cxx index 53b0da94b12d..90d8c7538a0d 100644 --- a/sw/source/core/unocore/unoobj2.cxx +++ b/sw/source/core/unocore/unoobj2.cxx @@ -75,7 +75,6 @@ #include #include #include -#include #include #include #include diff --git a/sw/source/core/unocore/unoportenum.cxx b/sw/source/core/unocore/unoportenum.cxx index 6e29ff314cf8..fd9722db9616 100644 --- a/sw/source/core/unocore/unoportenum.cxx +++ b/sw/source/core/unocore/unoportenum.cxx @@ -45,7 +45,6 @@ #include #include #include -#include #include #include #include @@ -429,9 +428,7 @@ lcl_CreateRefMarkPortion( SwDoc* pDoc = pUnoCrsr->GetDoc(); const SwFmtRefMark& rRefMark = static_cast(rAttr.GetAttr()); - Reference xContent = - static_cast(pDoc->GetUnoCallBack()) - ->GetRefMark(rRefMark); + Reference xContent; if (!xContent.is()) { xContent = new SwXReferenceMark(pDoc, &rRefMark); @@ -476,15 +473,10 @@ lcl_CreateTOXMarkPortion( SwDoc* pDoc = pUnoCrsr->GetDoc(); const SwTOXMark& rTOXMark = static_cast(rAttr.GetAttr()); - Reference xContent = - static_cast(pDoc->GetUnoCallBack()) - ->GetTOXMark(rTOXMark); - if (!xContent.is()) - { - xContent.set( SwXDocumentIndexMark::CreateXDocumentIndexMark(*pDoc, + Reference xContent( + SwXDocumentIndexMark::CreateXDocumentIndexMark(*pDoc, *const_cast(rTOXMark.GetTOXType()), rTOXMark), - uno::UNO_QUERY); - } + uno::UNO_QUERY); SwXTextPortion* pPortion = 0; if (!bEnd) -- cgit v1.2.3