use UnoCursorPointer in SwNavigationMgr

Change-Id: I7c7431edd79cf4527f97c7dc0695d49174b61e2c
This commit is contained in:
Bjoern Michaelsen
2015-06-03 00:36:14 +02:00
parent 683bac5b96
commit a2c467a58a
3 changed files with 21 additions and 22 deletions

View File

@@ -115,6 +115,13 @@ namespace sw
{ {
m_pCursor->Add(this); 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 virtual ~UnoCursorPointer() SAL_OVERRIDE
{ {
if(m_pCursor) if(m_pCursor)
@@ -132,6 +139,13 @@ namespace sw
{ return *m_pCursor.get(); } { return *m_pCursor.get(); }
SwUnoCrsr* operator->() const SwUnoCrsr* operator->() const
{ return m_pCursor.get(); } { 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 explicit operator bool() const
{ return static_cast<bool>(m_pCursor); } { return static_cast<bool>(m_pCursor); }
void reset(std::shared_ptr<SwUnoCrsr> pNew) void reset(std::shared_ptr<SwUnoCrsr> pNew)

View File

@@ -15,12 +15,13 @@
#include "swtypes.hxx" #include "swtypes.hxx"
#include "calbck.hxx" #include "calbck.hxx"
#include "unocrsr.hxx" #include "unocrsr.hxx"
#include "vcl/svapp.hxx"
class SwWrtShell; class SwWrtShell;
struct SwPosition; struct SwPosition;
class SwUnoCrsr; class SwUnoCrsr;
class SwNavigationMgr : SwClient class SwNavigationMgr
{ {
private: private:
/* /*
@@ -32,7 +33,7 @@ private:
* (e.g. click a link, or double click an entry from the navigator). * (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 * Every use of the back/forward buttons results in moving the stack pointer within the navigation history
*/ */
typedef ::std::vector< std::shared_ptr<SwUnoCrsr> > Stack_t; typedef ::std::vector< sw::UnoCursorPointer > Stack_t;
Stack_t m_entries; Stack_t m_entries;
Stack_t::size_type m_nCurrent; /* Current position within the navigation history */ Stack_t::size_type m_nCurrent; /* Current position within the navigation history */
SwWrtShell & m_rMyShell; /* The active shell within which the navigation occurs */ SwWrtShell & m_rMyShell; /* The active shell within which the navigation occurs */
@@ -44,11 +45,8 @@ public:
SwNavigationMgr( SwWrtShell & rShell ); SwNavigationMgr( SwWrtShell & rShell );
virtual ~SwNavigationMgr() virtual ~SwNavigationMgr()
{ {
for(auto pEntry : m_entries) SolarMutexGuard g;
{ m_entries.clear();
if(pEntry && GetRegisteredIn() == pEntry.get())
pEntry->Remove(this);
}
} }
/* Can we go back in the history ? */ /* Can we go back in the history ? */
bool backEnabled() ; bool backEnabled() ;
@@ -60,7 +58,6 @@ public:
void goForward() ; void goForward() ;
/* The method that adds the position pPos to the navigation history */ /* The method that adds the position pPos to the navigation history */
bool addEntry(const SwPosition& rPos); bool addEntry(const SwPosition& rPos);
void SwClientNotify(const SwModify& rModify, const SfxHint& rHint) SAL_OVERRIDE;
}; };
#endif #endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@@ -162,17 +162,15 @@ bool SwNavigationMgr::addEntry(const SwPosition& rPos) {
if (*m_entries.back()->GetPoint() != rPos) if (*m_entries.back()->GetPoint() != rPos)
{ {
std::shared_ptr<SwUnoCrsr> pCursor(m_rMyShell.GetDoc()->CreateUnoCrsr(rPos)); sw::UnoCursorPointer pCursor(m_rMyShell.GetDoc()->CreateUnoCrsr(rPos));
m_entries.push_back(pCursor); m_entries.push_back(pCursor);
pCursor->Add(this);
} }
bRet = true; bRet = true;
} }
else { else {
if ( (!m_entries.empty() && *m_entries.back()->GetPoint() != rPos) || m_entries.empty() ) { 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); m_entries.push_back(pCursor);
pCursor->Add(this);
bRet = true; bRet = true;
} }
if (m_entries.size() > 1 && *m_entries.back()->GetPoint() == rPos) if (m_entries.size() > 1 && *m_entries.back()->GetPoint() == rPos)
@@ -216,14 +214,4 @@ bool SwNavigationMgr::addEntry(const SwPosition& rPos) {
return bRet; 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: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */