[Libreoffice-commits] .: Branch 'libreoffice-3-5' - 2 commits - sw/source

Michael Stahl mst at kemper.freedesktop.org
Tue Jan 10 13:25:56 PST 2012


 sw/source/ui/inc/navmgr.hxx   |   29 +++++++-------
 sw/source/ui/wrtsh/navmgr.cxx |   87 +++++++++++++++++++++---------------------
 sw/source/ui/wrtsh/wrtsh1.cxx |    2 
 3 files changed, 62 insertions(+), 56 deletions(-)

New commits:
commit debb4be8886a4c5fd0a714dfd1b53306b836b800
Author: Michael Stahl <mstahl at redhat.com>
Date:   Tue Jan 10 22:07:29 2012 +0100

    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.
    (cherry picked from commit 0e898354fc76339a9a007b30f1ebe123981d0426)

diff --git a/sw/source/ui/inc/navmgr.hxx b/sw/source/ui/inc/navmgr.hxx
index 423c3eb..29b63de 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 f2d7460..6ee6222 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();
commit 3aa47f378c5f2dbf83fb6ec72d6bbaf0d63d9e51
Author: Michael Stahl <mstahl at redhat.com>
Date:   Tue Jan 10 21:29:12 2012 +0100

    sw: SwNavigationMgr: style cleanup
    (cherry picked from commit e9624f00e1c125860fa63ef10c7148f1a0b84cbb)

diff --git a/sw/source/ui/inc/navmgr.hxx b/sw/source/ui/inc/navmgr.hxx
index 2a86172..423c3eb 100644
--- a/sw/source/ui/inc/navmgr.hxx
+++ b/sw/source/ui/inc/navmgr.hxx
@@ -26,8 +26,8 @@
  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
  * instead of those above.
  */
-#ifndef _NAVMGR_HXX
-#define _NAVMGR_HXX
+#ifndef SW_NAVMGR_HXX
+#define SW_NAVMGR_HXX
 
 #include "swtypes.hxx"
 #include "pam.hxx"
@@ -36,7 +36,7 @@
 class   SwWrtShell;
 struct  SwPosition;
 
-class SW_DLLPUBLIC SwNavigationMgr
+class SwNavigationMgr
 {
 private:
     /*
@@ -50,15 +50,15 @@ 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
      */
-    std::vector<SwPosition> _entries;
-    std::vector<SwPosition>::size_type _nCurrent; /* Current position within the navigation history */
-    SwWrtShell* _pMyShell; /* The active shell within which the navigation occurs */
+    std::vector<SwPosition> m_entries;
+    std::vector<SwPosition>::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);
 
 public:
     /* Constructor that initializes the shell to the current shell */
-    SwNavigationMgr( SwWrtShell* pShell );
+    SwNavigationMgr( SwWrtShell & rShell );
     /* Can we go back in the history ? */
     sal_Bool backEnabled() ;
     /* Can we go forward in the history ? */
diff --git a/sw/source/ui/wrtsh/navmgr.cxx b/sw/source/ui/wrtsh/navmgr.cxx
index 8d49bdc..f2d7460 100644
--- a/sw/source/ui/wrtsh/navmgr.cxx
+++ b/sw/source/ui/wrtsh/navmgr.cxx
@@ -48,32 +48,32 @@ namespace css = ::com::sun::star;
  *  This method positions the cursor to the position rPos
  */
 void SwNavigationMgr::GotoSwPosition(const SwPosition &rPos) {
-    SwWrtShell& rSh = *_pMyShell;
     /* EnterStdMode() prevents the cursor to 'block' the current shell when it should move from the image back to the normal shell */
-    rSh.EnterStdMode();
-    rSh.StartAllAction();
+    m_rMyShell.EnterStdMode();
+    m_rMyShell.StartAllAction();
     /*
      *    cursor consists of two SwPositions: Point and Mark.
      *  Such a pair is called a PaM. SwPaM is derived from SwRing.
      *  The Ring contains the single regions of a multi-selection.
      */
-    SwPaM* pPaM = rSh.GetCrsr();
+    SwPaM* pPaM = m_rMyShell.GetCrsr();
 
     if(pPaM->HasMark())
         pPaM->DeleteMark();      // If there was a selection, get rid of it
     *pPaM->GetPoint() = rPos;    // Position Cursor
 
-    rSh.EndAllAction();
+    m_rMyShell.EndAllAction();
 }
 /*
  * Ctor for the SwNavigationMgr class
  * Sets the shell to the current shell
  * and the index of the current position to 0
  */
-
-SwNavigationMgr::SwNavigationMgr(SwWrtShell* pShell)
-    : _nCurrent(0), _pMyShell(pShell) {
+SwNavigationMgr::SwNavigationMgr(SwWrtShell & rShell)
+    : m_nCurrent(0), m_rMyShell(rShell)
+{
 }
+
 /*
  * This method is used by the navigation shell - defined in sw/source/ui/inc/navsh.hxx
  * and implemented in sw/source/ui/shells/navsh.cxx
@@ -81,17 +81,17 @@ SwNavigationMgr::SwNavigationMgr(SwWrtShell* pShell)
  * The back button should be enabled only if there are some entries in the navigation history
  */
 sal_Bool SwNavigationMgr::backEnabled() {
-    return (_nCurrent > 0);
+    return (m_nCurrent > 0);
 }
 /*
  * Similar to backEnabled() method.
  * The forward button should be enabled if we ever clicked back
  * Due to the implementation of the navigation class, this is when the
  * current position within the navigation history entries in not the last one
- * i.e. when the _nCurrent index is not at the end of the _entries vector
+ * i.e. when the m_nCurrent index is not at the end of the m_entries vector
  */
 sal_Bool SwNavigationMgr::forwardEnabled() {
-    return _nCurrent+1 < _entries.size();
+    return m_nCurrent+1 < m_entries.size();
 }
 
 
@@ -107,9 +107,8 @@ void SwNavigationMgr::goBack()  {
      * this check prevents segmentation faults and in this way the class is not relying on the UI
      */
     if (backEnabled()) {
-        SwWrtShell& rSh = *_pMyShell;
         /* Trying to get the current cursor */
-        SwPaM* pPaM = rSh.GetCrsr();
+        SwPaM* pPaM = m_rMyShell.GetCrsr();
         if (!pPaM) {
             return;
         }
@@ -130,17 +129,17 @@ void SwNavigationMgr::goBack()  {
              */
             /* The addEntry() method returns true iff we should decrement the index before navigating back */
             if (addEntry(*pPaM->GetPoint()) ) {
-                _nCurrent--;
+                m_nCurrent--;
             }
         }
-        _nCurrent--;
+        m_nCurrent--;
         /* Position cursor to appropriate navigation history entry */
-        GotoSwPosition(_entries[_nCurrent]);
+        GotoSwPosition(m_entries[m_nCurrent]);
         /* Refresh the buttons */
         if (bForwardWasDisabled)
-            _pMyShell->GetView().GetViewFrame()->GetBindings().Invalidate(FN_NAVIGATION_FORWARD);
+            m_rMyShell.GetView().GetViewFrame()->GetBindings().Invalidate(FN_NAVIGATION_FORWARD);
         if (!backEnabled())
-            _pMyShell->GetView().GetViewFrame()->GetBindings().Invalidate(FN_NAVIGATION_BACK);
+            m_rMyShell.GetView().GetViewFrame()->GetBindings().Invalidate(FN_NAVIGATION_BACK);
     }
 }
 /*
@@ -161,13 +160,13 @@ void SwNavigationMgr::goForward() {
          * The current index is positioned at the current entry in the navigation history
          * We have to increment it to go to the next entry
          */
-        _nCurrent++;
-        GotoSwPosition(_entries[_nCurrent]);
+        m_nCurrent++;
+        GotoSwPosition(m_entries[m_nCurrent]);
         /* Refresh the buttons */
         if (bBackWasDisabled)
-            _pMyShell->GetView().GetViewFrame()->GetBindings().Invalidate(FN_NAVIGATION_BACK);
+            m_rMyShell.GetView().GetViewFrame()->GetBindings().Invalidate(FN_NAVIGATION_BACK);
         if (!forwardEnabled())
-            _pMyShell->GetView().GetViewFrame()->GetBindings().Invalidate(FN_NAVIGATION_FORWARD);
+            m_rMyShell.GetView().GetViewFrame()->GetBindings().Invalidate(FN_NAVIGATION_FORWARD);
     }
 }
 /*
@@ -185,46 +184,47 @@ bool SwNavigationMgr::addEntry(const SwPosition& rPos) {
     /* If any forward history exists, twist the tail of the list from the current position to the end */
     if (bForwardWasEnabled) {
 
-        size_t number_of_entries = _entries.size(); /* To avoid calling _entries.size() multiple times */
-        int curr = _nCurrent; /* Index from which we'll twist the tail. */
-        int n = (number_of_entries - curr) / 2; /* Number of entries that will swap places */
+        size_t number_ofm_entries = m_entries.size(); /* To avoid calling m_entries.size() multiple times */
+        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 = _entries[curr + i];
-            _entries[curr + i] = _entries[number_of_entries -1 - i];
-            _entries[number_of_entries -1 - i] = temp;
+            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;
         }
 
-           if (_entries.back() != rPos)
-           _entries.push_back(rPos);
+           if (m_entries.back() != rPos)
+           m_entries.push_back(rPos);
 
 
         bRet = true;
     }
     else {
-        if ( (_entries.size() > 0 && _entries.back() != rPos) || (_entries.size() == 0) ) {
-            _entries.push_back(rPos);
+        if ( (m_entries.size() > 0 && m_entries.back() != rPos) || (m_entries.size() == 0) ) {
+            m_entries.push_back(rPos);
             bRet = true;
         }
-        if (_entries.size() > 1 && _entries.back() == rPos)
+        if (m_entries.size() > 1 && m_entries.back() == rPos)
             bRet = true;
-        if (_entries.size() == 1 && _entries.back() == rPos)
+        if (m_entries.size() == 1 && m_entries.back() == rPos)
             bRet = false;
     }
 #else
-    _entries.erase(_entries.begin() + _nCurrent, _entries.end());
-    _entries.push_back(rPos);
+    m_entries.erase(m_entries.begin() + m_nCurrent, m_entries.end());
+    m_entries.push_back(rPos);
     bRet = true;
 #endif
-    _nCurrent = _entries.size();
+    m_nCurrent = m_entries.size();
 
     /* Refresh buttons */
     if (bBackWasDisabled)
-        _pMyShell->GetView().GetViewFrame()->GetBindings().Invalidate(FN_NAVIGATION_BACK);
+        m_rMyShell.GetView().GetViewFrame()->GetBindings().Invalidate(FN_NAVIGATION_BACK);
     if (bForwardWasEnabled)
-        _pMyShell->GetView().GetViewFrame()->GetBindings().Invalidate(FN_NAVIGATION_FORWARD);
+        m_rMyShell.GetView().GetViewFrame()->GetBindings().Invalidate(FN_NAVIGATION_FORWARD);
 
     /* show the Navigation toolbar */
-    css::uno::Reference< css::frame::XFrame > xFrame = _pMyShell->GetView().GetViewFrame()->GetFrame().GetFrameInterface();
+    css::uno::Reference< css::frame::XFrame > xFrame =
+        m_rMyShell.GetView().GetViewFrame()->GetFrame().GetFrameInterface();
     if (xFrame.is())
     {
         css::uno::Reference< css::beans::XPropertySet > xPropSet(xFrame, css::uno::UNO_QUERY);
diff --git a/sw/source/ui/wrtsh/wrtsh1.cxx b/sw/source/ui/wrtsh/wrtsh1.cxx
index d042c4d..47541de 100644
--- a/sw/source/ui/wrtsh/wrtsh1.cxx
+++ b/sw/source/ui/wrtsh/wrtsh1.cxx
@@ -126,7 +126,7 @@ using namespace com::sun::star;
         ePageMove(MV_NO),\
         pCrsrStack(0),  \
         rView(rShell),\
-        aNavigationMgr(this), \
+        aNavigationMgr(*this), \
         bDestOnStack(sal_False)
 
 #define BITFLD_INI_LIST \


More information about the Libreoffice-commits mailing list