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

Caolán McNamara caolanm at redhat.com
Fri Jan 30 09:07:50 PST 2015


 sw/inc/docary.hxx                             |    1 
 sw/inc/redline.hxx                            |   12 ++---
 sw/source/core/doc/DocumentRedlineManager.cxx |   40 +++++++++++-------
 sw/source/core/doc/docredln.cxx               |   56 ++++++++++----------------
 sw/source/core/txtnode/ndtxt.cxx              |    2 
 sw/source/core/undo/unredln.cxx               |    2 
 6 files changed, 56 insertions(+), 57 deletions(-)

New commits:
commit 793b2b865e9ea898ddec45ef40658a7a8cace8f1
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Fri Jan 30 16:10:15 2015 +0000

    WaE: silence -Werror=unused-variable
    
    Change-Id: Ie3a2b81ea986dcfaa402030c99ad1314bdc562ac

diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index cb5c1e1..18da646 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -1062,7 +1062,7 @@ void SwTxtNode::Update(
                 // the unused position must not be on a SwTxtNode
                 bool const isOneUsed(&pRedl->GetBound(true) == pRedl->GetPoint());
                 assert(!pRedl->GetBound(!isOneUsed).nNode.GetNode().IsTxtNode());
-                assert(!pRedl->GetBound(!isOneUsed).nContent.GetIdxReg());
+                assert(!pRedl->GetBound(!isOneUsed).nContent.GetIdxReg()); (void)isOneUsed;
             }
         }
 
commit a5a20187c3a5e5956492f932c49501f9547e4915
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Fri Jan 30 15:34:30 2015 +0000

    During DocumentRedlineManager::SetRedlineMode the array becomes unsorted
    
    so GetPos cannot be used safely, so pass down the known index
    of the redline and propogate it everywhere the redline goes
    
    This reverts
    
    commit 36e158ce7a0effb130936ba4598a193102faa6a1
    Author: Caolán McNamara <caolanm at redhat.com>
    Date:   Mon Jan 19 12:09:17 2015 +0000
    
        if we change the keys we have to resort based on the new keys
    
    which tried to keep the table sorted, but thats no use because
    DocumentRedlineManager::SetRedlineMode loops over by index
    so sorting the table during the process busts that.
    
    Taking a copy of the entries and looping over that shows another
    gadzillion problems.
    
    So try this approach instead.
    
    I imagine it should be possible to calculate the correct
    current index of pRedl in DocumentRedlineManager::AppendRedline
    but for now assume that we are sorted correctly at that
    point and can use GetPos
    
    Change-Id: If092dce185e3b36fd256db390132358cba155847

diff --git a/sw/inc/docary.hxx b/sw/inc/docary.hxx
index fba92fb..8b36d6a 100644
--- a/sw/inc/docary.hxx
+++ b/sw/inc/docary.hxx
@@ -232,6 +232,7 @@ public:
     using _SwRedlineTbl::size_type;
     using _SwRedlineTbl::operator[];
     using _SwRedlineTbl::empty;
+    using _SwRedlineTbl::Resort;
 };
 
 /// Table that holds 'extra' redlines, such as 'table row insert\delete', 'paragraph moves' etc...
diff --git a/sw/inc/redline.hxx b/sw/inc/redline.hxx
index 17bc9b7..6ff3358 100644
--- a/sw/inc/redline.hxx
+++ b/sw/inc/redline.hxx
@@ -189,8 +189,8 @@ class SW_DLLPUBLIC SwRangeRedline : public SwPaM
 
     void MoveToSection();
     void CopyToSection();
-    void DelCopyOfSection();
-    void MoveFromSection();
+    void DelCopyOfSection(size_t nMyPos);
+    void MoveFromSection(size_t nMyPos);
 
 public:
     SwRangeRedline( RedlineType_t eType, const SwPaM& rPam );
@@ -260,10 +260,10 @@ public:
     // hide the Del-Redlines via Copy and Delete.
     // Otherwise at Move the attribution would be handled incorrectly.
     // All other callers must always give 0.
-    void CallDisplayFunc( sal_uInt16 nLoop = 0 );
-    void Show( sal_uInt16 nLoop = 0 );
-    void Hide( sal_uInt16 nLoop = 0 );
-    void ShowOriginal( sal_uInt16 nLoop = 0 );
+    void CallDisplayFunc(sal_uInt16 nLoop, size_t nMyPos);
+    void Show(sal_uInt16 nLoop , size_t nMyPos);
+    void Hide(sal_uInt16 nLoop , size_t nMyPos);
+    void ShowOriginal(sal_uInt16 nLoop, size_t nMyPos);
 
     /// Calculates the intersection with text node number nNdIdx.
     void CalcStartEnd(sal_uLong nNdIdx, sal_Int32& rStart, sal_Int32& rEnd) const;
diff --git a/sw/source/core/doc/DocumentRedlineManager.cxx b/sw/source/core/doc/DocumentRedlineManager.cxx
index 24d0bdc..873b4d6 100644
--- a/sw/source/core/doc/DocumentRedlineManager.cxx
+++ b/sw/source/core/doc/DocumentRedlineManager.cxx
@@ -606,7 +606,7 @@ void DocumentRedlineManager::SetRedlineMode( RedlineMode_t eMode )
             bool bSaveInXMLImportFlag = m_rDoc.IsInXMLImport();
             m_rDoc.SetInXMLImport( false );
             // and then hide/display everything
-            void (SwRangeRedline::*pFnc)( sal_uInt16 ) = 0;
+            void (SwRangeRedline::*pFnc)(sal_uInt16, size_t) = 0;
 
             switch( nsRedlineMode_t::REDLINE_SHOW_MASK & eMode )
             {
@@ -628,10 +628,17 @@ void DocumentRedlineManager::SetRedlineMode( RedlineMode_t eMode )
 
             _CHECK_REDLINE( *this )
 
-            if( pFnc )
-                for( sal_uInt16 nLoop = 1; nLoop <= 2; ++nLoop )
-                    for( sal_uInt16 i = 0; i < mpRedlineTbl->size(); ++i )
-                        ((*mpRedlineTbl)[ i ]->*pFnc)( nLoop );
+            if (pFnc)
+            {
+                for (sal_uInt16 nLoop = 1; nLoop <= 2; ++nLoop)
+                    for (size_t i = 0; i < mpRedlineTbl->size(); ++i)
+                        ((*mpRedlineTbl)[i]->*pFnc)(nLoop, i);
+
+                //SwRangeRedline::MoveFromSection routinely changes
+                //the keys that mpRedlineTbl is sorted by
+                mpRedlineTbl->Resort();
+            }
+
             _CHECK_REDLINE( *this )
             m_rDoc.SetInXMLImport( bSaveInXMLImportFlag );
         }
@@ -1123,8 +1130,8 @@ bool DocumentRedlineManager::AppendRedline( SwRangeRedline* pNewRedl, bool bCall
                                 // Before we can merge, we make it visible!
                                 // We insert temporarily so that pNew is
                                 // also dealt with when moving the indices.
-                                mpRedlineTbl->Insert( pNewRedl );
-                                pRedl->Show();
+                                mpRedlineTbl->Insert(pNewRedl);
+                                pRedl->Show(0, mpRedlineTbl->GetPos(pRedl));
                                 mpRedlineTbl->Remove( pNewRedl );
                                 pRStt = pRedl->Start();
                                 pREnd = pRedl->End();
@@ -1301,7 +1308,9 @@ bool DocumentRedlineManager::AppendRedline( SwRangeRedline* pNewRedl, bool bCall
                                 pRedl->PushData( *pNewRedl );
                                 delete pNewRedl, pNewRedl = 0;
                                 if( IsHideChanges( meRedlineMode ))
-                                    pRedl->Hide();
+                                {
+                                    pRedl->Hide(0, mpRedlineTbl->GetPos(pRedl));
+                                }
                                 bCompress = true;
                             }
                             break;
@@ -1364,8 +1373,8 @@ bool DocumentRedlineManager::AppendRedline( SwRangeRedline* pNewRedl, bool bCall
                                     pNewRedl->SetEnd( *pRStt, pEnd );
                                     if( IsHideChanges( meRedlineMode ))
                                     {
-                                        mpRedlineTbl->Insert( pNewRedl );
-                                        pRedl->Hide();
+                                        mpRedlineTbl->Insert(pNewRedl);
+                                        pRedl->Hide(0, mpRedlineTbl->GetPos(pRedl));
                                         mpRedlineTbl->Remove( pNewRedl );
                                     }
                                 }
@@ -1393,7 +1402,7 @@ bool DocumentRedlineManager::AppendRedline( SwRangeRedline* pNewRedl, bool bCall
                                     if( IsHideChanges( meRedlineMode ))
                                     {
                                         mpRedlineTbl->Insert( pNewRedl );
-                                        pRedl->Hide();
+                                        pRedl->Hide(0, mpRedlineTbl->GetPos(pRedl));
                                         mpRedlineTbl->Remove( pNewRedl );
                                     }
                                 }
@@ -1764,7 +1773,7 @@ void DocumentRedlineManager::CompressRedlines()
 {
     _CHECK_REDLINE( *this )
 
-    void (SwRangeRedline::*pFnc)(sal_uInt16) = 0;
+    void (SwRangeRedline::*pFnc)(sal_uInt16, size_t) = 0;
     switch( nsRedlineMode_t::REDLINE_SHOW_MASK & meRedlineMode )
     {
     case nsRedlineMode_t::REDLINE_SHOW_INSERT | nsRedlineMode_t::REDLINE_SHOW_DELETE:
@@ -1792,14 +1801,15 @@ void DocumentRedlineManager::CompressRedlines()
             !pCurEnd->nNode.GetNode().StartOfSectionNode()->IsTableNode() )
         {
             // we then can merge them
-            pPrev->Show();
-            pCur->Show();
+            size_t nPrevIndex = n-1;
+            pPrev->Show(0, nPrevIndex);
+            pCur->Show(0, n);
 
             pPrev->SetEnd( *pCur->End() );
             mpRedlineTbl->DeleteAndDestroy( n );
             --n;
             if( pFnc )
-                (pPrev->*pFnc)(0);
+                (pPrev->*pFnc)(0, nPrevIndex);
         }
     }
     _CHECK_REDLINE( *this )
diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx
index 3898d0e..7e8c9e5 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -273,8 +273,10 @@ bool SwRedlineTbl::Insert( SwRangeRedline* p, bool bIns )
     bool bRet = false;
     if( p->HasValidRange() )
     {
-        bRet = insert( p ).second;
-        p->CallDisplayFunc();
+        std::pair<_SwRedlineTbl::const_iterator, bool> rv = insert( p );
+        size_t nP = rv.first - begin();
+        bRet = rv.second;
+        p->CallDisplayFunc(0, nP);
     }
     else if( bIns )
         bRet = InsertWithValidRanges( p );
@@ -293,7 +295,7 @@ bool SwRedlineTbl::Insert( SwRangeRedline* p, sal_uInt16& rP, bool bIns )
         std::pair<_SwRedlineTbl::const_iterator, bool> rv = insert( p );
         rP = rv.first - begin();
         bRet = rv.second;
-        p->CallDisplayFunc();
+        p->CallDisplayFunc(0, rP);
     }
     else if( bIns )
         bRet = InsertWithValidRanges( p, &rP );
@@ -395,7 +397,7 @@ bool SwRedlineTbl::InsertWithValidRanges( SwRangeRedline* p, sal_uInt16* pInsPos
                 pNew->HasValidRange() &&
                 Insert( pNew, nInsPos ) )
             {
-                pNew->CallDisplayFunc();
+                pNew->CallDisplayFunc(0, nInsPos);
                 bAnyIns = true;
                 pNew = 0;
                 if( pInsPos && *pInsPos < nInsPos )
@@ -893,23 +895,23 @@ bool SwRangeRedline::HasValidRange() const
     return false;
 }
 
-void SwRangeRedline::CallDisplayFunc( sal_uInt16 nLoop )
+void SwRangeRedline::CallDisplayFunc(sal_uInt16 nLoop, size_t nMyPos)
 {
     switch( nsRedlineMode_t::REDLINE_SHOW_MASK & GetDoc()->getIDocumentRedlineAccess().GetRedlineMode() )
     {
     case nsRedlineMode_t::REDLINE_SHOW_INSERT | nsRedlineMode_t::REDLINE_SHOW_DELETE:
-        Show( nLoop );
+        Show(nLoop, nMyPos);
         break;
     case nsRedlineMode_t::REDLINE_SHOW_INSERT:
-        Hide( nLoop );
+        Hide(nLoop, nMyPos);
         break;
     case nsRedlineMode_t::REDLINE_SHOW_DELETE:
-        ShowOriginal( nLoop );
+        ShowOriginal(nLoop, nMyPos);
         break;
     }
 }
 
-void SwRangeRedline::Show( sal_uInt16 nLoop )
+void SwRangeRedline::Show(sal_uInt16 nLoop, size_t nMyPos)
 {
     if( 1 <= nLoop )
     {
@@ -922,12 +924,12 @@ void SwRangeRedline::Show( sal_uInt16 nLoop )
         {
         case nsRedlineType_t::REDLINE_INSERT:           // Content has been inserted
             bIsVisible = true;
-            MoveFromSection();
+            MoveFromSection(nMyPos);
             break;
 
         case nsRedlineType_t::REDLINE_DELETE:           // Content has been deleted
             bIsVisible = true;
-            MoveFromSection();
+            MoveFromSection(nMyPos);
             break;
 
         case nsRedlineType_t::REDLINE_FORMAT:           // Attributes have been applied
@@ -941,7 +943,7 @@ void SwRangeRedline::Show( sal_uInt16 nLoop )
     }
 }
 
-void SwRangeRedline::Hide( sal_uInt16 nLoop )
+void SwRangeRedline::Hide(sal_uInt16 nLoop, size_t nMyPos)
 {
     SwDoc* pDoc = GetDoc();
     RedlineMode_t eOld = pDoc->getIDocumentRedlineAccess().GetRedlineMode();
@@ -953,7 +955,7 @@ void SwRangeRedline::Hide( sal_uInt16 nLoop )
     case nsRedlineType_t::REDLINE_INSERT:           // Content has been inserted
         bIsVisible = true;
         if( 1 <= nLoop )
-            MoveFromSection();
+            MoveFromSection(nMyPos);
         break;
 
     case nsRedlineType_t::REDLINE_DELETE:           // Content has been deleted
@@ -962,7 +964,7 @@ void SwRangeRedline::Hide( sal_uInt16 nLoop )
         {
         case 0: MoveToSection();    break;
         case 1: CopyToSection();    break;
-        case 2: DelCopyOfSection(); break;
+        case 2: DelCopyOfSection(nMyPos); break;
         }
         break;
 
@@ -977,7 +979,7 @@ void SwRangeRedline::Hide( sal_uInt16 nLoop )
     pDoc->getIDocumentRedlineAccess().SetRedlineMode_intern( eOld );
 }
 
-void SwRangeRedline::ShowOriginal( sal_uInt16 nLoop )
+void SwRangeRedline::ShowOriginal(sal_uInt16 nLoop, size_t nMyPos)
 {
     SwDoc* pDoc = GetDoc();
     RedlineMode_t eOld = pDoc->getIDocumentRedlineAccess().GetRedlineMode();
@@ -998,14 +1000,14 @@ void SwRangeRedline::ShowOriginal( sal_uInt16 nLoop )
         {
         case 0: MoveToSection();    break;
         case 1: CopyToSection();    break;
-        case 2: DelCopyOfSection(); break;
+        case 2: DelCopyOfSection(nMyPos); break;
         }
         break;
 
     case nsRedlineType_t::REDLINE_DELETE:           // Inhalt wurde eingefuegt
         bIsVisible = true;
         if( 1 <= nLoop )
-            MoveFromSection();
+            MoveFromSection(nMyPos);
         break;
 
     case nsRedlineType_t::REDLINE_FORMAT:           // Attributes have been applied
@@ -1235,7 +1237,7 @@ void SwRangeRedline::CopyToSection()
     }
 }
 
-void SwRangeRedline::DelCopyOfSection()
+void SwRangeRedline::DelCopyOfSection(size_t nMyPos)
 {
     if( pCntntSect )
     {
@@ -1282,7 +1284,7 @@ void SwRangeRedline::DelCopyOfSection()
                 // bDelLastPara condition above), only redlines before the
                 // current ones can be affected.
                 const SwRedlineTbl& rTbl = pDoc->getIDocumentRedlineAccess().GetRedlineTbl();
-                sal_uInt16 n = rTbl.GetPos( this );
+                sal_uInt16 n = nMyPos;
                 OSL_ENSURE( n != USHRT_MAX, "How strange. We don't exist!" );
                 for( bool bBreak = false; !bBreak && n > 0; )
                 {
@@ -1323,16 +1325,13 @@ void SwRangeRedline::DelCopyOfSection()
     }
 }
 
-void SwRangeRedline::MoveFromSection()
+void SwRangeRedline::MoveFromSection(size_t nMyPos)
 {
     if( pCntntSect )
     {
         SwDoc* pDoc = GetDoc();
         const SwRedlineTbl& rTbl = pDoc->getIDocumentRedlineAccess().GetRedlineTbl();
         std::vector<SwPosition*> aBeforeArr, aBehindArr;
-        typedef std::map<sal_uInt16, SwRangeRedline*> IndexAndRange;
-        IndexAndRange aIndexAndRangeMap;
-        sal_uInt16 nMyPos = rTbl.GetPos( this );
         OSL_ENSURE( this, "this is not in the array?" );
         bool bBreak = false;
         sal_uInt16 n;
@@ -1344,14 +1343,12 @@ void SwRangeRedline::MoveFromSection()
             {
                 SwRangeRedline* pRedl = rTbl[n];
                 aBehindArr.push_back(&pRedl->GetBound(true));
-                aIndexAndRangeMap.insert(std::make_pair(n, pRedl));
                 bBreak = false;
             }
             if( rTbl[ n ]->GetBound(false) == *GetPoint() )
             {
                 SwRangeRedline* pRedl = rTbl[n];
                 aBehindArr.push_back(&pRedl->GetBound(false));
-                aIndexAndRangeMap.insert(std::make_pair(n, pRedl));
                 bBreak = false;
             }
         }
@@ -1363,14 +1360,12 @@ void SwRangeRedline::MoveFromSection()
             {
                 SwRangeRedline* pRedl = rTbl[n];
                 aBeforeArr.push_back(&pRedl->GetBound(true));
-                aIndexAndRangeMap.insert(std::make_pair(n, pRedl));
                 bBreak = false;
             }
             if( rTbl[ n ]->GetBound(false) == *GetPoint() )
             {
                 SwRangeRedline* pRedl = rTbl[n];
                 aBeforeArr.push_back(&pRedl->GetBound(false));
-                aIndexAndRangeMap.insert(std::make_pair(n, pRedl));
                 bBreak = false;
             }
         }
@@ -1445,13 +1440,6 @@ void SwRangeRedline::MoveFromSection()
             *aBeforeArr[ n ] = *Start();
         for( n = 0; n < aBehindArr.size(); ++n )
             *aBehindArr[ n ] = *End();
-        SwRedlineTbl& rResortTbl = const_cast<SwRedlineTbl&>(rTbl);
-        for (auto& a : aIndexAndRangeMap)
-        {
-            // re-insert
-            rResortTbl.Remove(a.first);
-            rResortTbl.Insert(a.second);
-        }
     }
     else
         InvalidateRange();
diff --git a/sw/source/core/undo/unredln.cxx b/sw/source/core/undo/unredln.cxx
index 95548c7e..a842272 100644
--- a/sw/source/core/undo/unredln.cxx
+++ b/sw/source/core/undo/unredln.cxx
@@ -242,7 +242,7 @@ void SwUndoRedlineSort::UndoRedlineImpl(SwDoc & rDoc, SwPaM & rPam)
         OSL_ENSURE( USHRT_MAX != nFnd && nFnd+1 < (sal_uInt16)rDoc.getIDocumentRedlineAccess().GetRedlineTbl().size(),
                     "could not find an Insert object" );
         ++nFnd;
-        rDoc.getIDocumentRedlineAccess().GetRedlineTbl()[nFnd]->Show( 1 );
+        rDoc.getIDocumentRedlineAccess().GetRedlineTbl()[nFnd]->Show(1, nFnd);
     }
 
     {


More information about the Libreoffice-commits mailing list