summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2015-01-30 15:34:30 +0000
committerMiklos Vajna <vmiklos@collabora.co.uk>2015-02-06 21:46:11 +0000
commitff424e420116b2123b62f7869af25d7caec65288 (patch)
tree7da60d95e89ed5cc94100e70027d9cdacf374fcd
parent772be81db70570801a0b6b5de53319f21e1ff60e (diff)
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@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 (cherry picked from commit a5a20187c3a5e5956492f932c49501f9547e4915) Reviewed-on: https://gerrit.libreoffice.org/14260 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Tested-by: Miklos Vajna <vmiklos@collabora.co.uk>
-rw-r--r--sw/inc/docary.hxx1
-rw-r--r--sw/inc/redline.hxx12
-rw-r--r--sw/source/core/doc/DocumentRedlineManager.cxx40
-rw-r--r--sw/source/core/doc/docredln.cxx56
-rw-r--r--sw/source/core/undo/unredln.cxx2
5 files changed, 55 insertions, 56 deletions
diff --git a/sw/inc/docary.hxx b/sw/inc/docary.hxx
index 2f388b1f65e7..ec2c5bce0d5a 100644
--- a/sw/inc/docary.hxx
+++ b/sw/inc/docary.hxx
@@ -209,6 +209,7 @@ public:
using _SwRedlineTbl::size;
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 38058d4448a3..79a1ad6d1c87 100644
--- a/sw/inc/redline.hxx
+++ b/sw/inc/redline.hxx
@@ -190,8 +190,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 );
@@ -261,10 +261,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 24d0bdc4e69c..873b4d60d975 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 e42cbe3e9b38..91a2b58dc66c 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 )
@@ -899,23 +901,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 )
{
@@ -928,12 +930,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
@@ -947,7 +949,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();
@@ -959,7 +961,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
@@ -968,7 +970,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;
@@ -983,7 +985,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();
@@ -1004,14 +1006,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
@@ -1241,7 +1243,7 @@ void SwRangeRedline::CopyToSection()
}
}
-void SwRangeRedline::DelCopyOfSection()
+void SwRangeRedline::DelCopyOfSection(size_t nMyPos)
{
if( pCntntSect )
{
@@ -1288,7 +1290,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; )
{
@@ -1329,16 +1331,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;
@@ -1350,14 +1349,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;
}
}
@@ -1369,14 +1366,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;
}
}
@@ -1451,13 +1446,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 621454ea01dc..8afcde2b12e5 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);
}
{