From f14a3a043dec75bf2c2ee7e0e8b62aefe4ef6acf Mon Sep 17 00:00:00 2001 From: Bjoern Michaelsen Date: Sun, 31 May 2015 01:09:24 +0200 Subject: [PATCH] use UnoCursorPointer in SwXTextRanges Change-Id: Iabcb98f664739aaae0d92b4f2a6b0e50bdcbc09b --- sw/inc/unocrsr.hxx | 3 +++ sw/source/core/unocore/unoobj2.cxx | 38 ++++-------------------------- 2 files changed, 7 insertions(+), 34 deletions(-) diff --git a/sw/inc/unocrsr.hxx b/sw/inc/unocrsr.hxx index 4d2c38010f26..6952506e7765 100644 --- a/sw/inc/unocrsr.hxx +++ b/sw/inc/unocrsr.hxx @@ -107,6 +107,9 @@ namespace sw class UnoCursorPointer : public SwClient { public: + UnoCursorPointer() + : m_pCursor(nullptr) + {} UnoCursorPointer(std::shared_ptr pCursor) : m_pCursor(pCursor) { diff --git a/sw/source/core/unocore/unoobj2.cxx b/sw/source/core/unocore/unoobj2.cxx index d1cf9aec9434..623ebcd57d93 100644 --- a/sw/source/core/unocore/unoobj2.cxx +++ b/sw/source/core/unocore/unoobj2.cxx @@ -1467,56 +1467,26 @@ throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception) } class SwXTextRanges::Impl - : public SwClient { public: ::std::vector< uno::Reference< text::XTextRange > > m_Ranges; - std::shared_ptr m_pUnoCursor; + sw::UnoCursorPointer m_pUnoCursor; explicit Impl(SwPaM *const pPaM) { if (pPaM) { - m_pUnoCursor = pPaM->GetDoc()->CreateUnoCrsr(*pPaM->GetPoint()); - m_pUnoCursor->Add(this); + m_pUnoCursor.reset(pPaM->GetDoc()->CreateUnoCrsr(*pPaM->GetPoint())); ::sw::DeepCopyPaM(*pPaM, *GetCursor()); } MakeRanges(); } - virtual ~Impl() { - if(m_pUnoCursor) - m_pUnoCursor->Remove(this); - } - - SwUnoCrsr * GetCursor() { - return static_cast( - GetRegisteredIn()); - } - + SwUnoCrsr* GetCursor() + { return &(*m_pUnoCursor); } void MakeRanges(); - -protected: - // SwClient - virtual void Modify( const SfxPoolItem *pOld, const SfxPoolItem *pNew) SAL_OVERRIDE; - virtual void SwClientNotify(const SwModify& rModify, const SfxHint& rHint) SAL_OVERRIDE; }; -void SwXTextRanges::Impl::Modify( const SfxPoolItem *pOld, const SfxPoolItem *pNew) -{ - ClientModify(this, pOld, pNew); -} - -void SwXTextRanges::Impl::SwClientNotify(const SwModify& rModify, const SfxHint& rHint) -{ - SwClient::SwClientNotify(rModify, rHint); - if(m_pUnoCursor && typeid(rHint) == typeid(sw::DocDisposingHint)) - { - m_pUnoCursor->Remove(this); - m_pUnoCursor.reset(); - } -} - void SwXTextRanges::Impl::MakeRanges() { if (GetCursor())