diff options
author | Michael Stahl <mstahl@redhat.com> | 2012-01-10 22:07:29 +0100 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2012-01-10 22:07:29 +0100 |
commit | 0e898354fc76339a9a007b30f1ebe123981d0426 (patch) | |
tree | 8af3c88c78c35d05b2e32d37cdfe584ccd4a5713 | |
parent | e9624f00e1c125860fa63ef10c7148f1a0b84cbb (diff) |
sw: SwNavigationMgr: don't store SwPositions
Using SwPosition to store the history is an awful ideal as that isn't
corrected when the node it points to is deleted, which could cause
crashes when the user then wants to jump there.
SwUnoCrsr looks like a better fit as it is automatically corrected.
-rw-r--r-- | sw/source/ui/inc/navmgr.hxx | 19 | ||||
-rw-r--r-- | sw/source/ui/wrtsh/navmgr.cxx | 31 |
2 files changed, 28 insertions, 22 deletions
diff --git a/sw/source/ui/inc/navmgr.hxx b/sw/source/ui/inc/navmgr.hxx index 423c3eb6f6a8..29b63defbaa2 100644 --- a/sw/source/ui/inc/navmgr.hxx +++ b/sw/source/ui/inc/navmgr.hxx @@ -29,29 +29,32 @@ #ifndef SW_NAVMGR_HXX #define SW_NAVMGR_HXX +#include <vector> + +#include <boost/shared_ptr.hpp> + #include "swtypes.hxx" -#include "pam.hxx" -#include "swdllapi.h" class SwWrtShell; struct SwPosition; +class SwUnoCrsr; + class SwNavigationMgr { private: /* * List of entries in the navigation history - * Each entry is a SwPosition, which represents a position within the document - * SwPosition is given by a node index (SwNodeIndex) which usually represents the paragraph the position is in - * and an index (SwIndex), which represents the position inside this paragraph. - * You can find more on SwPositions at http://wiki.services.openoffice.org/wiki/Writer_Core_And_Layout + * Entries are SwUnoCrsr because thos gets corrected automatically + * when nodes are deleted. * * The navigation history behaves as a stack, to which items are added when we jump to a new position * (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 */ - std::vector<SwPosition> m_entries; - std::vector<SwPosition>::size_type m_nCurrent; /* Current position within the navigation history */ + typedef ::std::vector< ::boost::shared_ptr<SwUnoCrsr> > 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 */ void GotoSwPosition(const SwPosition &rPos); diff --git a/sw/source/ui/wrtsh/navmgr.cxx b/sw/source/ui/wrtsh/navmgr.cxx index f2d746073214..6ee622241e8c 100644 --- a/sw/source/ui/wrtsh/navmgr.cxx +++ b/sw/source/ui/wrtsh/navmgr.cxx @@ -33,6 +33,8 @@ #include <sfx2/viewfrm.hxx> #include <cmdid.h> #include <view.hxx> +#include <doc.hxx> +#include <unocrsr.hxx> #include <com/sun/star/frame/XLayoutManager.hpp> @@ -134,7 +136,7 @@ void SwNavigationMgr::goBack() { } m_nCurrent--; /* Position cursor to appropriate navigation history entry */ - GotoSwPosition(m_entries[m_nCurrent]); + GotoSwPosition(*m_entries[m_nCurrent]->GetPoint()); /* Refresh the buttons */ if (bForwardWasDisabled) m_rMyShell.GetView().GetViewFrame()->GetBindings().Invalidate(FN_NAVIGATION_FORWARD); @@ -161,7 +163,7 @@ void SwNavigationMgr::goForward() { * We have to increment it to go to the next entry */ m_nCurrent++; - GotoSwPosition(m_entries[m_nCurrent]); + GotoSwPosition(*m_entries[m_nCurrent]->GetPoint()); /* Refresh the buttons */ if (bBackWasDisabled) m_rMyShell.GetView().GetViewFrame()->GetBindings().Invalidate(FN_NAVIGATION_BACK); @@ -188,30 +190,31 @@ bool SwNavigationMgr::addEntry(const SwPosition& rPos) { int curr = m_nCurrent; /* Index from which we'll twist the tail. */ int n = (number_ofm_entries - curr) / 2; /* Number of entries that will swap places */ for (int i = 0; i < n; i++) { - SwPosition temp = m_entries[curr + i]; - m_entries[curr + i] = m_entries[number_ofm_entries -1 - i]; - m_entries[number_ofm_entries -1 - i] = temp; + ::std::swap(m_entries[curr + i], m_entries[number_ofm_entries -1 - i]); } - if (m_entries.back() != rPos) - m_entries.push_back(rPos); - - + if (*m_entries.back()->GetPoint() != rPos) + { + SwUnoCrsr *const pCursor = m_rMyShell.GetDoc()->CreateUnoCrsr(rPos); + m_entries.push_back(::boost::shared_ptr<SwUnoCrsr>(pCursor)); + } bRet = true; } else { - if ( (m_entries.size() > 0 && m_entries.back() != rPos) || (m_entries.size() == 0) ) { - m_entries.push_back(rPos); + if ( (m_entries.size() > 0 && *m_entries.back()->GetPoint() != rPos) || (m_entries.size() == 0) ) { + SwUnoCrsr *const pCursor = m_rMyShell.GetDoc()->CreateUnoCrsr(rPos); + m_entries.push_back(::boost::shared_ptr<SwUnoCrsr>(pCursor)); bRet = true; } - if (m_entries.size() > 1 && m_entries.back() == rPos) + if (m_entries.size() > 1 && *m_entries.back()->GetPoint() == rPos) bRet = true; - if (m_entries.size() == 1 && m_entries.back() == rPos) + if (m_entries.size() == 1 && *m_entries.back()->GetPoint() == rPos) bRet = false; } #else m_entries.erase(m_entries.begin() + m_nCurrent, m_entries.end()); - m_entries.push_back(rPos); + SwUnoCrsr *const pCursor = m_rMyShell.GetDoc()->CreateUnoCrsr(rPos); + m_entries.push_back(::boost::shared_ptr<SwUnoCrsr>(pCursor)); bRet = true; #endif m_nCurrent = m_entries.size(); |