diff --git a/sw/inc/unocrsr.hxx b/sw/inc/unocrsr.hxx index 6952506e7765..323607395151 100644 --- a/sw/inc/unocrsr.hxx +++ b/sw/inc/unocrsr.hxx @@ -115,6 +115,13 @@ namespace sw { m_pCursor->Add(this); } + UnoCursorPointer(const UnoCursorPointer& pOther) + : SwClient(nullptr) + , m_pCursor(pOther.m_pCursor) + { + if(m_pCursor) + m_pCursor->Add(this); + } virtual ~UnoCursorPointer() SAL_OVERRIDE { if(m_pCursor) @@ -132,6 +139,13 @@ namespace sw { return *m_pCursor.get(); } SwUnoCrsr* operator->() const { return m_pCursor.get(); } + UnoCursorPointer& operator=(UnoCursorPointer aOther) + { + if(aOther.m_pCursor) + aOther.m_pCursor->Add(this); + m_pCursor = aOther.m_pCursor; + return *this; + } explicit operator bool() const { return static_cast(m_pCursor); } void reset(std::shared_ptr pNew) diff --git a/sw/source/uibase/inc/navmgr.hxx b/sw/source/uibase/inc/navmgr.hxx index 28309597f332..1c6baa98e8b8 100644 --- a/sw/source/uibase/inc/navmgr.hxx +++ b/sw/source/uibase/inc/navmgr.hxx @@ -15,12 +15,13 @@ #include "swtypes.hxx" #include "calbck.hxx" #include "unocrsr.hxx" +#include "vcl/svapp.hxx" class SwWrtShell; struct SwPosition; class SwUnoCrsr; -class SwNavigationMgr : SwClient +class SwNavigationMgr { private: /* @@ -32,7 +33,7 @@ private: * (e.g. click a link, or double click an entry from the navigator). * Every use of the back/forward buttons results in moving the stack pointer within the navigation history */ - typedef ::std::vector< std::shared_ptr > Stack_t; + typedef ::std::vector< sw::UnoCursorPointer > Stack_t; Stack_t m_entries; Stack_t::size_type m_nCurrent; /* Current position within the navigation history */ SwWrtShell & m_rMyShell; /* The active shell within which the navigation occurs */ @@ -44,11 +45,8 @@ public: SwNavigationMgr( SwWrtShell & rShell ); virtual ~SwNavigationMgr() { - for(auto pEntry : m_entries) - { - if(pEntry && GetRegisteredIn() == pEntry.get()) - pEntry->Remove(this); - } + SolarMutexGuard g; + m_entries.clear(); } /* Can we go back in the history ? */ bool backEnabled() ; @@ -60,7 +58,6 @@ public: void goForward() ; /* The method that adds the position pPos to the navigation history */ bool addEntry(const SwPosition& rPos); - void SwClientNotify(const SwModify& rModify, const SfxHint& rHint) SAL_OVERRIDE; }; #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/wrtsh/navmgr.cxx b/sw/source/uibase/wrtsh/navmgr.cxx index 6740fa58d71e..1811532e2d50 100644 --- a/sw/source/uibase/wrtsh/navmgr.cxx +++ b/sw/source/uibase/wrtsh/navmgr.cxx @@ -162,17 +162,15 @@ bool SwNavigationMgr::addEntry(const SwPosition& rPos) { if (*m_entries.back()->GetPoint() != rPos) { - std::shared_ptr pCursor(m_rMyShell.GetDoc()->CreateUnoCrsr(rPos)); + sw::UnoCursorPointer pCursor(m_rMyShell.GetDoc()->CreateUnoCrsr(rPos)); m_entries.push_back(pCursor); - pCursor->Add(this); } bRet = true; } else { if ( (!m_entries.empty() && *m_entries.back()->GetPoint() != rPos) || m_entries.empty() ) { - auto pCursor(m_rMyShell.GetDoc()->CreateUnoCrsr(rPos)); + sw::UnoCursorPointer pCursor(m_rMyShell.GetDoc()->CreateUnoCrsr(rPos)); m_entries.push_back(pCursor); - pCursor->Add(this); bRet = true; } if (m_entries.size() > 1 && *m_entries.back()->GetPoint() == rPos) @@ -216,14 +214,4 @@ bool SwNavigationMgr::addEntry(const SwPosition& rPos) { return bRet; } -void SwNavigationMgr::SwClientNotify(const SwModify& rModify, const SfxHint& rHint) -{ - if(typeid(rHint) == typeid(sw::DocDisposingHint)) - { - m_entries.clear(); - } - else - SwClient::SwClientNotify(rModify, rHint); -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */