[Libreoffice-commits] core.git: 8 commits - sw/source

Bjoern Michaelsen bjoern.michaelsen at canonical.com
Wed Jun 11 07:24:14 PDT 2014


 sw/source/core/doc/docbm.cxx |  187 ++++++++++++++++++++++---------------------
 1 file changed, 99 insertions(+), 88 deletions(-)

New commits:
commit aa6e78eeefac7af70bfa51892715fe03bea755db
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Wed Jun 11 15:30:54 2014 +0200

    BOOST_FOREACH and constness
    
    Change-Id: I86c86cfa245c78ce8e21d85831de5ae82f67f81e

diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx
index e05bd4a..f05d867 100644
--- a/sw/source/core/doc/docbm.cxx
+++ b/sw/source/core/doc/docbm.cxx
@@ -2075,19 +2075,16 @@ void CntntIdxStoreImpl::RestoreBkmksLen(SwNode& rNd, sal_uLong nLen, sal_Int32 n
     const SwDoc* pDoc = rNd.GetDoc();
     IDocumentMarkAccess* const pMarkAccess = const_cast<IDocumentMarkAccess*>(pDoc->getIDocumentMarkAccess());
     SwCntntNode* pCNd = (SwCntntNode*)rNd.GetCntntNode();
-    for(
-        std::vector<BkmkEntry>::const_iterator pEntry = m_aBkmkEntries.begin();
-        pEntry != m_aBkmkEntries.end();
-        ++pEntry)
+    BOOST_FOREACH(const BkmkEntry& aEntry, m_aBkmkEntries)
     {
-        if( !pEntry->m_nCntnt >= nCorrLen )
+        if( !aEntry.m_nCntnt >= nCorrLen )
         {
-            if (MarkBase* pMark = dynamic_cast<MarkBase*>(pMarkAccess->getAllMarksBegin()[pEntry->m_nBkmkIdx].get()))
+            if (MarkBase* pMark = dynamic_cast<MarkBase*>(pMarkAccess->getAllMarksBegin()[aEntry.m_nBkmkIdx].get()))
             {
-                SwPosition aNewPos(GetRightMarkPos(pMark, pEntry->m_bOther));
+                SwPosition aNewPos(GetRightMarkPos(pMark, aEntry.m_bOther));
                 aNewPos.nNode = *pCNd;
-                aNewPos.nContent.Assign(pCNd, ::std::min(pEntry->m_nCntnt, static_cast<sal_Int32>(nLen)));
-                SetRightMarkPos(pMark, pEntry->m_bOther, &aNewPos);
+                aNewPos.nContent.Assign(pCNd, ::std::min(aEntry.m_nCntnt, static_cast<sal_Int32>(nLen)));
+                SetRightMarkPos(pMark, aEntry.m_bOther, &aNewPos);
             }
         }
     }
commit 99c1de27bfcf3f785266211f44835a6269d8a809
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Wed Jun 11 15:28:26 2014 +0200

    BOOST_FOREACH and constness
    
    Change-Id: I832bc8fcdfb4997c2eaae3f0cb5d7014df20f2fd

diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx
index ad9dec1..e05bd4a 100644
--- a/sw/source/core/doc/docbm.cxx
+++ b/sw/source/core/doc/docbm.cxx
@@ -20,6 +20,7 @@
 #include <MarkManager.hxx>
 #include <bookmrk.hxx>
 #include <boost/bind.hpp>
+#include <boost/foreach.hpp>
 #include <cntfrm.hxx>
 #include <crossrefbookmark.hxx>
 #include <annotationmark.hxx>
@@ -2057,17 +2058,14 @@ void CntntIdxStoreImpl::RestoreBkmks(SwDoc* pDoc, sal_uLong nNode, sal_Int32 nOf
 {
     IDocumentMarkAccess* const pMarkAccess = pDoc->getIDocumentMarkAccess();
     SwCntntNode* pCNd = pDoc->GetNodes()[ nNode ]->GetCntntNode();
-    for(
-        std::vector<BkmkEntry>::const_iterator pEntry = m_aBkmkEntries.begin();
-        pEntry != m_aBkmkEntries.end();
-        ++pEntry)
+    BOOST_FOREACH(const BkmkEntry& aEntry, m_aBkmkEntries)
     {
-        if (MarkBase* pMark = dynamic_cast<MarkBase*>(pMarkAccess->getAllMarksBegin()[pEntry->m_nBkmkIdx].get()))
+        if (MarkBase* pMark = dynamic_cast<MarkBase*>(pMarkAccess->getAllMarksBegin()[aEntry.m_nBkmkIdx].get()))
         {
-            SwPosition aNewPos(GetRightMarkPos(pMark, pEntry->m_bOther));
+            SwPosition aNewPos(GetRightMarkPos(pMark, aEntry.m_bOther));
             aNewPos.nNode = *pCNd;
-            aNewPos.nContent.Assign(pCNd, pEntry->m_nCntnt + nOffset);
-            SetRightMarkPos(pMark, pEntry->m_bOther, &aNewPos);
+            aNewPos.nContent.Assign(pCNd, aEntry.m_nCntnt + nOffset);
+            SetRightMarkPos(pMark, aEntry.m_bOther, &aNewPos);
         }
     }
 }
commit 958492d4d3642eb94e3d97a4206a9ce52985fab9
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Wed Jun 11 15:21:06 2014 +0200

    simplify MarkPos conditional
    
    Change-Id: If109980429f2f87e06065837eaec7129b2ece336

diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx
index 3cdfbd3..ad9dec1 100644
--- a/sw/source/core/doc/docbm.cxx
+++ b/sw/source/core/doc/docbm.cxx
@@ -2009,6 +2009,10 @@ namespace
             inline void SaveBkmks(SwDoc* pDoc, sal_uLong nNode, sal_Int32 nCntnt);
             inline void RestoreBkmks(SwDoc* pDoc, sal_uLong nNode, sal_Int32 nOffset);
             inline void RestoreBkmksLen(SwNode& rNd, sal_uLong nLen, sal_Int32 nCorrLen);
+            inline const SwPosition& GetRightMarkPos(::sw::mark::IMark* pMark, bool bOther)
+                { return bOther ? pMark->GetOtherMarkPos() : pMark->GetMarkPos(); };
+            inline void SetRightMarkPos(MarkBase* pMark, bool bOther, const SwPosition* const pPos)
+                { bOther ? pMark->SetOtherMarkPos(*pPos) : pMark->SetMarkPos(*pPos); };
     };
 }
 
@@ -2060,20 +2064,10 @@ void CntntIdxStoreImpl::RestoreBkmks(SwDoc* pDoc, sal_uLong nNode, sal_Int32 nOf
     {
         if (MarkBase* pMark = dynamic_cast<MarkBase*>(pMarkAccess->getAllMarksBegin()[pEntry->m_nBkmkIdx].get()))
         {
-            if(pEntry->m_bOther)
-            {
-                SwPosition aNewPos(pMark->GetOtherMarkPos());
-                aNewPos.nNode = *pCNd;
-                aNewPos.nContent.Assign(pCNd, pEntry->m_nCntnt + nOffset);
-                pMark->SetOtherMarkPos(aNewPos);
-            }
-            else
-            {
-                SwPosition aNewPos(pMark->GetMarkPos());
-                aNewPos.nNode = *pCNd;
-                aNewPos.nContent.Assign(pCNd, pEntry->m_nCntnt + nOffset);
-                pMark->SetMarkPos(aNewPos);
-            }
+            SwPosition aNewPos(GetRightMarkPos(pMark, pEntry->m_bOther));
+            aNewPos.nNode = *pCNd;
+            aNewPos.nContent.Assign(pCNd, pEntry->m_nCntnt + nOffset);
+            SetRightMarkPos(pMark, pEntry->m_bOther, &aNewPos);
         }
     }
 }
@@ -2092,20 +2086,10 @@ void CntntIdxStoreImpl::RestoreBkmksLen(SwNode& rNd, sal_uLong nLen, sal_Int32 n
         {
             if (MarkBase* pMark = dynamic_cast<MarkBase*>(pMarkAccess->getAllMarksBegin()[pEntry->m_nBkmkIdx].get()))
             {
-                if(pEntry->m_bOther)
-                {
-                    SwPosition aNewPos(pMark->GetOtherMarkPos());
-                    aNewPos.nNode = *pCNd;
-                    aNewPos.nContent.Assign(pCNd, ::std::min(pEntry->m_nCntnt, static_cast<sal_Int32>(nLen)));
-                    pMark->SetOtherMarkPos(aNewPos);
-                }
-                else
-                {
-                    SwPosition aNewPos(pMark->GetMarkPos());
-                    aNewPos.nNode = *pCNd;
-                    aNewPos.nContent.Assign(pCNd, ::std::min(pEntry->m_nCntnt, static_cast<sal_Int32>(nLen)));
-                    pMark->SetMarkPos(aNewPos);
-                }
+                SwPosition aNewPos(GetRightMarkPos(pMark, pEntry->m_bOther));
+                aNewPos.nNode = *pCNd;
+                aNewPos.nContent.Assign(pCNd, ::std::min(pEntry->m_nCntnt, static_cast<sal_Int32>(nLen)));
+                SetRightMarkPos(pMark, pEntry->m_bOther, &aNewPos);
             }
         }
     }
commit 5deaac4ff9956c80ad16dc14c9085d91b5eb0aba
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Wed Jun 11 14:59:45 2014 +0200

    simplify cascading conditionals
    
    Change-Id: I957d7c368f6b7158c74268f7274d59e8a25b83e8

diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx
index 53423ba..3cdfbd3 100644
--- a/sw/source/core/doc/docbm.cxx
+++ b/sw/source/core/doc/docbm.cxx
@@ -2058,19 +2058,16 @@ void CntntIdxStoreImpl::RestoreBkmks(SwDoc* pDoc, sal_uLong nNode, sal_Int32 nOf
         pEntry != m_aBkmkEntries.end();
         ++pEntry)
     {
-        if(pEntry->m_bOther)
+        if (MarkBase* pMark = dynamic_cast<MarkBase*>(pMarkAccess->getAllMarksBegin()[pEntry->m_nBkmkIdx].get()))
         {
-            if (MarkBase* pMark = dynamic_cast<MarkBase*>(pMarkAccess->getAllMarksBegin()[pEntry->m_nBkmkIdx].get()))
+            if(pEntry->m_bOther)
             {
                 SwPosition aNewPos(pMark->GetOtherMarkPos());
                 aNewPos.nNode = *pCNd;
                 aNewPos.nContent.Assign(pCNd, pEntry->m_nCntnt + nOffset);
                 pMark->SetOtherMarkPos(aNewPos);
             }
-        }
-        else
-        {
-            if (MarkBase* pMark = dynamic_cast<MarkBase*>(pMarkAccess->getAllMarksBegin()[pEntry->m_nBkmkIdx].get()))
+            else
             {
                 SwPosition aNewPos(pMark->GetMarkPos());
                 aNewPos.nNode = *pCNd;
@@ -2093,19 +2090,16 @@ void CntntIdxStoreImpl::RestoreBkmksLen(SwNode& rNd, sal_uLong nLen, sal_Int32 n
     {
         if( !pEntry->m_nCntnt >= nCorrLen )
         {
-            if(pEntry->m_bOther)
+            if (MarkBase* pMark = dynamic_cast<MarkBase*>(pMarkAccess->getAllMarksBegin()[pEntry->m_nBkmkIdx].get()))
             {
-                if (MarkBase* pMark = dynamic_cast<MarkBase*>(pMarkAccess->getAllMarksBegin()[pEntry->m_nBkmkIdx].get()))
+                if(pEntry->m_bOther)
                 {
                     SwPosition aNewPos(pMark->GetOtherMarkPos());
                     aNewPos.nNode = *pCNd;
                     aNewPos.nContent.Assign(pCNd, ::std::min(pEntry->m_nCntnt, static_cast<sal_Int32>(nLen)));
                     pMark->SetOtherMarkPos(aNewPos);
                 }
-            }
-            else
-            {
-                if (MarkBase* pMark = dynamic_cast<MarkBase*>(pMarkAccess->getAllMarksBegin()[pEntry->m_nBkmkIdx].get()))
+                else
                 {
                     SwPosition aNewPos(pMark->GetMarkPos());
                     aNewPos.nNode = *pCNd;
commit 6c7f0e8bfacac44493e44c4ea613d064c3fb5348
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Wed Jun 11 14:42:24 2014 +0200

    remove now redundant old implementation
    
    Change-Id: Ieab4fc54be0b2e5ad547f81a7a70d84284161c47

diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx
index 5fef4b7..53423ba 100644
--- a/sw/source/core/doc/docbm.cxx
+++ b/sw/source/core/doc/docbm.cxx
@@ -1181,8 +1181,6 @@ namespace
     //  2nd long contains the ContentPosition
 
     //  CntntType --
-    //          0x8000 = Bookmark Pos1
-    //          0x8001 = Bookmark Pos2
     //          0x2000 = Paragraph anchored frame
     //          0x2001 = frame anchored at character, which should be moved
     //          0x1000 = Redline Mark
@@ -1512,42 +1510,6 @@ void _SaveCntntIdx(SwDoc* pDoc,
 {
     // 1. Bookmarks
     _SwSaveTypeCountContent aSave;
-    aSave.SetTypeAndCount( 0x8000, 0 );
-
-    IDocumentMarkAccess* const pMarkAccess = pDoc->getIDocumentMarkAccess();
-    const sal_Int32 nMarksCount = pMarkAccess->getAllMarksCount();
-    for ( ; aSave.GetCount() < nMarksCount; aSave.IncCount() )
-    {
-        bool bMarkPosEqual = false;
-        const ::sw::mark::IMark* pBkmk = (pMarkAccess->getAllMarksBegin() + aSave.GetCount())->get();
-        if(pBkmk->GetMarkPos().nNode.GetIndex() == nNode
-            && pBkmk->GetMarkPos().nContent.GetIndex() <= nCntnt)
-        {
-            if(pBkmk->GetMarkPos().nContent.GetIndex() < nCntnt)
-            {
-                aSave.SetContent(pBkmk->GetMarkPos().nContent.GetIndex());
-                aSave.Add(rSaveArr);
-            }
-            else // if a bookmark position is equal nCntnt, the other position
-                bMarkPosEqual = true; // has to decide if it is added to the array
-        }
-
-        if(pBkmk->IsExpanded()
-            && pBkmk->GetOtherMarkPos().nNode.GetIndex() == nNode
-            && pBkmk->GetOtherMarkPos().nContent.GetIndex() <= nCntnt)
-        {
-            if(bMarkPosEqual)
-            { // the other position is before, the (main) position is equal
-                aSave.SetContent(pBkmk->GetMarkPos().nContent.GetIndex());
-                aSave.Add(rSaveArr);
-            }
-            aSave.SetContent(pBkmk->GetOtherMarkPos().nContent.GetIndex());
-            aSave.IncType();
-            aSave.Add(rSaveArr);
-            aSave.DecType();
-        }
-    }
-
     // 2. Redlines
     aSave.SetTypeAndCount( 0x1000, 0 );
     const SwRedlineTbl& rRedlTbl = pDoc->GetRedlineTbl();
@@ -1726,7 +1688,6 @@ void _RestoreCntntIdx(SwDoc* pDoc,
     SwCntntNode* pCNd = pDoc->GetNodes()[ nNode ]->GetCntntNode();
     const SwRedlineTbl& rRedlTbl = pDoc->GetRedlineTbl();
     SwFrmFmts* pSpz = pDoc->GetSpzFrmFmts();
-    IDocumentMarkAccess* const pMarkAccess = pDoc->getIDocumentMarkAccess();
     sal_uInt16 n = 0;
     while( n < rSaveArr.size() )
     {
@@ -1734,24 +1695,6 @@ void _RestoreCntntIdx(SwDoc* pDoc,
         SwPosition* pPos = 0;
         switch( aSave.GetType() )
         {
-            case 0x8000:
-            if (MarkBase* pMark = dynamic_cast<MarkBase*>(pMarkAccess->getAllMarksBegin()[aSave.GetCount()].get()))
-            {
-                SwPosition aNewPos(pMark->GetMarkPos());
-                aNewPos.nNode = *pCNd;
-                aNewPos.nContent.Assign(pCNd, aSave.GetContent() + nOffset);
-                pMark->SetMarkPos(aNewPos);
-            }
-            break;
-            case 0x8001:
-            if (MarkBase* pMark = dynamic_cast<MarkBase*>(pMarkAccess->getAllMarksBegin()[aSave.GetCount()].get()))
-            {
-                SwPosition aNewPos(pMark->GetOtherMarkPos());
-                aNewPos.nNode = *pCNd;
-                aNewPos.nContent.Assign(pCNd, aSave.GetContent() + nOffset);
-                pMark->SetOtherMarkPos(aNewPos);
-            }
-            break;
             case 0x1001:
                 pPos = (SwPosition*)rRedlTbl[ aSave.GetCount() ]->GetPoint();
                 break;
@@ -1888,7 +1831,6 @@ void _RestoreCntntIdx(std::vector<sal_uLong> &rSaveArr,
     const SwDoc* pDoc = rNd.GetDoc();
     const SwRedlineTbl& rRedlTbl = pDoc->GetRedlineTbl();
     const SwFrmFmts* pSpz = pDoc->GetSpzFrmFmts();
-    const IDocumentMarkAccess* const pMarkAccess = pDoc->getIDocumentMarkAccess();
     SwCntntNode* pCNd = (SwCntntNode*)rNd.GetCntntNode();
 
     sal_uInt16 n = 0;
@@ -1902,30 +1844,6 @@ void _RestoreCntntIdx(std::vector<sal_uLong> &rSaveArr,
             SwPosition* pPos = 0;
             switch( aSave.GetType() )
             {
-            case 0x8000:
-            {
-                MarkBase* pMark = dynamic_cast<MarkBase*>(pMarkAccess->getAllMarksBegin()[aSave.GetCount()].get());
-                if (pMark)
-                {
-                    SwPosition aNewPos(pMark->GetMarkPos());
-                    aNewPos.nNode = rNd;
-                    aNewPos.nContent.Assign(pCNd, std::min(aSave.GetContent(), nLen));
-                    pMark->SetMarkPos(aNewPos);
-                }
-            }
-            break;
-            case 0x8001:
-            {
-                MarkBase* pMark = dynamic_cast<MarkBase*>(pMarkAccess->getAllMarksBegin()[aSave.GetCount()].get());
-                if (pMark)
-                {
-                    SwPosition aNewPos(pMark->GetOtherMarkPos());
-                    aNewPos.nNode = rNd;
-                    aNewPos.nContent.Assign(pCNd, std::min(aSave.GetContent(), nLen));
-                    pMark->SetOtherMarkPos(aNewPos);
-                }
-            }
-            break;
             case 0x1001:
                 pPos = (SwPosition*)rRedlTbl[ aSave.GetCount() ]->GetPoint();
                 break;
commit fb171e3886c0c28c61f1e1960f7b427644a501fe
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Wed Jun 11 14:21:55 2014 +0200

    add second Restore function for CntntIdxStore
    
    Change-Id: I2d4c92d0927bce13b03a6f235e14812ed1d0bd54

diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx
index 69b14e0..5fef4b7 100644
--- a/sw/source/core/doc/docbm.cxx
+++ b/sw/source/core/doc/docbm.cxx
@@ -2083,12 +2083,14 @@ namespace
         }
         virtual void Restore(SwNode& rNd, sal_Int32 nLen, sal_Int32 nCorrLen) SAL_OVERRIDE
         {
+            RestoreBkmksLen(rNd, nLen, nCorrLen);
             return _RestoreCntntIdx(m_aSaveArr, rNd, nLen, nCorrLen);
         }
         virtual ~CntntIdxStoreImpl(){};
         private:
             inline void SaveBkmks(SwDoc* pDoc, sal_uLong nNode, sal_Int32 nCntnt);
             inline void RestoreBkmks(SwDoc* pDoc, sal_uLong nNode, sal_Int32 nOffset);
+            inline void RestoreBkmksLen(SwNode& rNd, sal_uLong nLen, sal_Int32 nCorrLen);
     };
 }
 
@@ -2161,6 +2163,42 @@ void CntntIdxStoreImpl::RestoreBkmks(SwDoc* pDoc, sal_uLong nNode, sal_Int32 nOf
     }
 }
 
+void CntntIdxStoreImpl::RestoreBkmksLen(SwNode& rNd, sal_uLong nLen, sal_Int32 nCorrLen)
+{
+    const SwDoc* pDoc = rNd.GetDoc();
+    IDocumentMarkAccess* const pMarkAccess = const_cast<IDocumentMarkAccess*>(pDoc->getIDocumentMarkAccess());
+    SwCntntNode* pCNd = (SwCntntNode*)rNd.GetCntntNode();
+    for(
+        std::vector<BkmkEntry>::const_iterator pEntry = m_aBkmkEntries.begin();
+        pEntry != m_aBkmkEntries.end();
+        ++pEntry)
+    {
+        if( !pEntry->m_nCntnt >= nCorrLen )
+        {
+            if(pEntry->m_bOther)
+            {
+                if (MarkBase* pMark = dynamic_cast<MarkBase*>(pMarkAccess->getAllMarksBegin()[pEntry->m_nBkmkIdx].get()))
+                {
+                    SwPosition aNewPos(pMark->GetOtherMarkPos());
+                    aNewPos.nNode = *pCNd;
+                    aNewPos.nContent.Assign(pCNd, ::std::min(pEntry->m_nCntnt, static_cast<sal_Int32>(nLen)));
+                    pMark->SetOtherMarkPos(aNewPos);
+                }
+            }
+            else
+            {
+                if (MarkBase* pMark = dynamic_cast<MarkBase*>(pMarkAccess->getAllMarksBegin()[pEntry->m_nBkmkIdx].get()))
+                {
+                    SwPosition aNewPos(pMark->GetMarkPos());
+                    aNewPos.nNode = *pCNd;
+                    aNewPos.nContent.Assign(pCNd, ::std::min(pEntry->m_nCntnt, static_cast<sal_Int32>(nLen)));
+                    pMark->SetMarkPos(aNewPos);
+                }
+            }
+        }
+    }
+}
+
 namespace sw { namespace mark {
     boost::shared_ptr<CntntIdxStore> CntntIdxStore::Create()
     {
commit 64c31cc7e4c713ca580c6d37b9605bac49083326
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Wed Jun 11 13:26:40 2014 +0200

    code conventions, while we are at it
    
    Change-Id: I118aa2cb8747775d8c778cf49248c7f3ef68d6a2

diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx
index 8dd3841..69b14e0 100644
--- a/sw/source/core/doc/docbm.cxx
+++ b/sw/source/core/doc/docbm.cxx
@@ -2060,30 +2060,30 @@ namespace
     };
     struct CntntIdxStoreImpl : sw::mark::CntntIdxStore
     {
-        std::vector<sal_uLong> aSaveArr;
-        std::vector<BkmkEntry> aBkmkEntries;
+        std::vector<sal_uLong> m_aSaveArr;
+        std::vector<BkmkEntry> m_aBkmkEntries;
         virtual void Clear() SAL_OVERRIDE
         {
-            aBkmkEntries.clear();
-            aSaveArr.clear();
+            m_aBkmkEntries.clear();
+            m_aSaveArr.clear();
         }
         virtual bool Empty() SAL_OVERRIDE
         {
-            return aBkmkEntries.empty() && aSaveArr.empty();
+            return m_aBkmkEntries.empty() && m_aSaveArr.empty();
         }
         virtual void Save(SwDoc* pDoc, sal_uLong nNode, sal_Int32 nCntnt, sal_uInt8 nSaveFly=0) SAL_OVERRIDE
         {
             SaveBkmks(pDoc, nNode, nCntnt);
-            return _SaveCntntIdx(pDoc, nNode, nCntnt, aSaveArr, nSaveFly);
+            return _SaveCntntIdx(pDoc, nNode, nCntnt, m_aSaveArr, nSaveFly);
         }
         virtual void Restore(SwDoc* pDoc, sal_uLong nNode, sal_Int32 nOffset=0, bool bAuto = false) SAL_OVERRIDE
         {
             RestoreBkmks(pDoc, nNode, nOffset);
-            return _RestoreCntntIdx(pDoc, aSaveArr, nNode, nOffset, bAuto);
+            return _RestoreCntntIdx(pDoc, m_aSaveArr, nNode, nOffset, bAuto);
         }
         virtual void Restore(SwNode& rNd, sal_Int32 nLen, sal_Int32 nCorrLen) SAL_OVERRIDE
         {
-            return _RestoreCntntIdx(aSaveArr, rNd, nLen, nCorrLen);
+            return _RestoreCntntIdx(m_aSaveArr, rNd, nLen, nCorrLen);
         }
         virtual ~CntntIdxStoreImpl(){};
         private:
@@ -2109,7 +2109,7 @@ void CntntIdxStoreImpl::SaveBkmks(SwDoc* pDoc, sal_uLong nNode, sal_Int32 nCntnt
             if(pBkmk->GetMarkPos().nContent.GetIndex() < nCntnt)
             {
                 const BkmkEntry aEntry = { ppBkmk - pMarkAccess->getAllMarksBegin(), false, pBkmk->GetMarkPos().nContent.GetIndex() };
-                aBkmkEntries.push_back(aEntry);
+                m_aBkmkEntries.push_back(aEntry);
             }
             else // if a bookmark position is equal nCntnt, the other position
                 bMarkPosEqual = true; // has to decide if it is added to the array
@@ -2121,10 +2121,10 @@ void CntntIdxStoreImpl::SaveBkmks(SwDoc* pDoc, sal_uLong nNode, sal_Int32 nCntnt
             if(bMarkPosEqual)
             { // the other position is before, the (main) position is equal
                 const BkmkEntry aEntry = { ppBkmk - pMarkAccess->getAllMarksBegin(), false, pBkmk->GetMarkPos().nContent.GetIndex() };
-                aBkmkEntries.push_back(aEntry);
+                m_aBkmkEntries.push_back(aEntry);
             }
             const BkmkEntry aEntry = { ppBkmk - pMarkAccess->getAllMarksBegin(), true, pBkmk->GetOtherMarkPos().nContent.GetIndex() };
-            aBkmkEntries.push_back(aEntry);
+            m_aBkmkEntries.push_back(aEntry);
         }
     }
 }
@@ -2134,8 +2134,8 @@ void CntntIdxStoreImpl::RestoreBkmks(SwDoc* pDoc, sal_uLong nNode, sal_Int32 nOf
     IDocumentMarkAccess* const pMarkAccess = pDoc->getIDocumentMarkAccess();
     SwCntntNode* pCNd = pDoc->GetNodes()[ nNode ]->GetCntntNode();
     for(
-        std::vector<BkmkEntry>::const_iterator pEntry = aBkmkEntries.begin();
-        pEntry != aBkmkEntries.end();
+        std::vector<BkmkEntry>::const_iterator pEntry = m_aBkmkEntries.begin();
+        pEntry != m_aBkmkEntries.end();
         ++pEntry)
     {
         if(pEntry->m_bOther)
commit bd60aba1973ee1ace725273edadbe06861f38e33
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Wed Jun 11 13:14:09 2014 +0200

    refactor bookmark moves
    
    Change-Id: I13924d40ca1c31f56440b98d9a1829963cdd3e1a

diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx
index 676b669..8dd3841 100644
--- a/sw/source/core/doc/docbm.cxx
+++ b/sw/source/core/doc/docbm.cxx
@@ -2052,23 +2052,33 @@ void _RestoreCntntIdx(std::vector<sal_uLong> &rSaveArr,
 
 namespace
 {
+    struct BkmkEntry
+    {
+        long int m_nBkmkIdx;
+        bool m_bOther;
+        sal_Int32 m_nCntnt;
+    };
     struct CntntIdxStoreImpl : sw::mark::CntntIdxStore
     {
         std::vector<sal_uLong> aSaveArr;
+        std::vector<BkmkEntry> aBkmkEntries;
         virtual void Clear() SAL_OVERRIDE
         {
+            aBkmkEntries.clear();
             aSaveArr.clear();
         }
         virtual bool Empty() SAL_OVERRIDE
         {
-            return aSaveArr.empty();
+            return aBkmkEntries.empty() && aSaveArr.empty();
         }
         virtual void Save(SwDoc* pDoc, sal_uLong nNode, sal_Int32 nCntnt, sal_uInt8 nSaveFly=0) SAL_OVERRIDE
         {
+            SaveBkmks(pDoc, nNode, nCntnt);
             return _SaveCntntIdx(pDoc, nNode, nCntnt, aSaveArr, nSaveFly);
         }
         virtual void Restore(SwDoc* pDoc, sal_uLong nNode, sal_Int32 nOffset=0, bool bAuto = false) SAL_OVERRIDE
         {
+            RestoreBkmks(pDoc, nNode, nOffset);
             return _RestoreCntntIdx(pDoc, aSaveArr, nNode, nOffset, bAuto);
         }
         virtual void Restore(SwNode& rNd, sal_Int32 nLen, sal_Int32 nCorrLen) SAL_OVERRIDE
@@ -2076,9 +2086,81 @@ namespace
             return _RestoreCntntIdx(aSaveArr, rNd, nLen, nCorrLen);
         }
         virtual ~CntntIdxStoreImpl(){};
+        private:
+            inline void SaveBkmks(SwDoc* pDoc, sal_uLong nNode, sal_Int32 nCntnt);
+            inline void RestoreBkmks(SwDoc* pDoc, sal_uLong nNode, sal_Int32 nOffset);
     };
 }
 
+void CntntIdxStoreImpl::SaveBkmks(SwDoc* pDoc, sal_uLong nNode, sal_Int32 nCntnt)
+{
+    IDocumentMarkAccess* const pMarkAccess = pDoc->getIDocumentMarkAccess();
+    const IDocumentMarkAccess::const_iterator_t ppBkmkEnd = pMarkAccess->getAllMarksEnd();
+    for(
+        IDocumentMarkAccess::const_iterator_t ppBkmk = pMarkAccess->getAllMarksBegin();
+        ppBkmk != ppBkmkEnd;
+        ++ppBkmk)
+    {
+        const ::sw::mark::IMark* pBkmk = ppBkmk->get();
+        bool bMarkPosEqual = false;
+        if(pBkmk->GetMarkPos().nNode.GetIndex() == nNode
+            && pBkmk->GetMarkPos().nContent.GetIndex() <= nCntnt)
+        {
+            if(pBkmk->GetMarkPos().nContent.GetIndex() < nCntnt)
+            {
+                const BkmkEntry aEntry = { ppBkmk - pMarkAccess->getAllMarksBegin(), false, pBkmk->GetMarkPos().nContent.GetIndex() };
+                aBkmkEntries.push_back(aEntry);
+            }
+            else // if a bookmark position is equal nCntnt, the other position
+                bMarkPosEqual = true; // has to decide if it is added to the array
+        }
+        if(pBkmk->IsExpanded()
+            && pBkmk->GetOtherMarkPos().nNode.GetIndex() == nNode
+            && pBkmk->GetOtherMarkPos().nContent.GetIndex() <= nCntnt)
+        {
+            if(bMarkPosEqual)
+            { // the other position is before, the (main) position is equal
+                const BkmkEntry aEntry = { ppBkmk - pMarkAccess->getAllMarksBegin(), false, pBkmk->GetMarkPos().nContent.GetIndex() };
+                aBkmkEntries.push_back(aEntry);
+            }
+            const BkmkEntry aEntry = { ppBkmk - pMarkAccess->getAllMarksBegin(), true, pBkmk->GetOtherMarkPos().nContent.GetIndex() };
+            aBkmkEntries.push_back(aEntry);
+        }
+    }
+}
+
+void CntntIdxStoreImpl::RestoreBkmks(SwDoc* pDoc, sal_uLong nNode, sal_Int32 nOffset)
+{
+    IDocumentMarkAccess* const pMarkAccess = pDoc->getIDocumentMarkAccess();
+    SwCntntNode* pCNd = pDoc->GetNodes()[ nNode ]->GetCntntNode();
+    for(
+        std::vector<BkmkEntry>::const_iterator pEntry = aBkmkEntries.begin();
+        pEntry != aBkmkEntries.end();
+        ++pEntry)
+    {
+        if(pEntry->m_bOther)
+        {
+            if (MarkBase* pMark = dynamic_cast<MarkBase*>(pMarkAccess->getAllMarksBegin()[pEntry->m_nBkmkIdx].get()))
+            {
+                SwPosition aNewPos(pMark->GetOtherMarkPos());
+                aNewPos.nNode = *pCNd;
+                aNewPos.nContent.Assign(pCNd, pEntry->m_nCntnt + nOffset);
+                pMark->SetOtherMarkPos(aNewPos);
+            }
+        }
+        else
+        {
+            if (MarkBase* pMark = dynamic_cast<MarkBase*>(pMarkAccess->getAllMarksBegin()[pEntry->m_nBkmkIdx].get()))
+            {
+                SwPosition aNewPos(pMark->GetMarkPos());
+                aNewPos.nNode = *pCNd;
+                aNewPos.nContent.Assign(pCNd, pEntry->m_nCntnt + nOffset);
+                pMark->SetMarkPos(aNewPos);
+            }
+        }
+    }
+}
+
 namespace sw { namespace mark {
     boost::shared_ptr<CntntIdxStore> CntntIdxStore::Create()
     {


More information about the Libreoffice-commits mailing list