diff options
author | Caolán McNamara <caolanm@redhat.com> | 2015-01-30 15:34:30 +0000 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-02-06 21:46:11 +0000 |
commit | ff424e420116b2123b62f7869af25d7caec65288 (patch) | |
tree | 7da60d95e89ed5cc94100e70027d9cdacf374fcd /sw/source/core/doc/docredln.cxx | |
parent | 772be81db70570801a0b6b5de53319f21e1ff60e (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>
Diffstat (limited to 'sw/source/core/doc/docredln.cxx')
-rw-r--r-- | sw/source/core/doc/docredln.cxx | 56 |
1 files changed, 22 insertions, 34 deletions
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(); |