[Libreoffice-commits] core.git: Branch 'aoo/trunk' - sw/source
Oliver-Rainer Wittmann
orw at apache.org
Fri Jan 17 00:08:53 PST 2014
sw/source/core/doc/docbm.cxx | 66 +++++++++++++++++++++++++++----------
sw/source/core/inc/MarkManager.hxx | 1
2 files changed, 50 insertions(+), 17 deletions(-)
New commits:
commit 93ab293354bb322a7d57b7eaf21bcd2479453e87
Author: Oliver-Rainer Wittmann <orw at apache.org>
Date: Fri Jan 17 07:28:17 2014 +0000
123480: method <::sw::mark::deleteMarks(..)> - assure sorting of subset mark containers before the intrinsic deletion of marks
diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx
index f87d12e..8201088 100644
--- a/sw/source/core/doc/docbm.cxx
+++ b/sw/source/core/doc/docbm.cxx
@@ -105,7 +105,9 @@ namespace
pMark);
}
- static inline ::std::auto_ptr<SwPosition> lcl_PositionFromCntntNode(SwCntntNode * const pCntntNode, const bool bAtEnd=false)
+ static inline ::std::auto_ptr<SwPosition> lcl_PositionFromCntntNode(
+ SwCntntNode * const pCntntNode,
+ const bool bAtEnd=false)
{
::std::auto_ptr<SwPosition> pResult(new SwPosition(*pCntntNode));
pResult->nContent.Assign(pCntntNode, bAtEnd ? pCntntNode->Len() : 0);
@@ -116,20 +118,30 @@ namespace
// else set it to the begin of the Node after rEnd, if there is one
// else set it to the end of the node before rStt
// else set it to the CntntNode of the Pos outside the Range
- static inline ::std::auto_ptr<SwPosition> lcl_FindExpelPosition(const SwNodeIndex& rStt,
+ static inline ::std::auto_ptr<SwPosition> lcl_FindExpelPosition(
+ const SwNodeIndex& rStt,
const SwNodeIndex& rEnd,
const SwPosition& rOtherPosition)
{
SwCntntNode * pNode = rEnd.GetNode().GetCntntNode();
- SwNodeIndex aStt = SwNodeIndex(rStt);
- SwNodeIndex aEnd = SwNodeIndex(rEnd);
- bool bAtEnd = false;
- if(!pNode)
- pNode = rEnd.GetNodes().GoNext(&aEnd), bAtEnd = false;
- if(!pNode)
- pNode = rStt.GetNodes().GoPrevious(&aStt), bAtEnd = true;
- if(pNode)
- return lcl_PositionFromCntntNode(pNode, bAtEnd);
+ bool bPosAtEndOfNode = false;
+ if ( pNode == NULL)
+ {
+ SwNodeIndex aEnd = SwNodeIndex(rEnd);
+ pNode = rEnd.GetNodes().GoNext( &aEnd );
+ bPosAtEndOfNode = false;
+ }
+ if ( pNode == NULL )
+ {
+ SwNodeIndex aStt = SwNodeIndex(rStt);
+ pNode = rStt.GetNodes().GoPrevious(&aStt);
+ bPosAtEndOfNode = true;
+ }
+ if ( pNode != NULL )
+ {
+ return lcl_PositionFromCntntNode( pNode, bPosAtEndOfNode );
+ }
+
return ::std::auto_ptr<SwPosition>(new SwPosition(rOtherPosition));
};
@@ -648,6 +660,9 @@ namespace sw { namespace mark
::std::vector<const_iterator_t> vMarksToDelete;
bool bIsSortingNeeded = false;
+ // boolean indicating, if at least one mark has been moved while colleting marks for deletion
+ bool bMarksMoved = false;
+
// copy all bookmarks in the move area to a vector storing all position data as offset
// reassignment is performed after the move
for(iterator_t ppMark = m_vAllMarks.begin();
@@ -730,7 +745,8 @@ namespace sw { namespace mark
}
else
{
- pNewPos = lcl_FindExpelPosition( rStt, rEnd, bIsPosInRange ? pMark->GetOtherMarkPos() : pMark->GetMarkPos() );
+ pNewPos =
+ lcl_FindExpelPosition( rStt, rEnd, bIsPosInRange ? pMark->GetOtherMarkPos() : pMark->GetMarkPos() );
}
}
@@ -758,6 +774,7 @@ namespace sw { namespace mark
pMark->SetMarkPos(*pNewPos);
else
pMark->SetOtherMarkPos(*pNewPos);
+ bMarksMoved = true;
// illegal selection? collapse the mark and restore sorting later
bIsSortingNeeded |= lcl_FixCorrectedMark( bIsPosInRange, bIsOtherPosInRange, pMark );
@@ -765,18 +782,28 @@ namespace sw { namespace mark
}
}
+ // If needed, sort mark containers containing subsets of the marks in order to assure sorting.
+ // The sorting is critical for the deletion of a mark as it is searched in these container for deletion.
+ if ( vMarksToDelete.size() > 0 && bMarksMoved )
+ {
+ sortSubsetMarks();
+ }
// we just remembered the iterators to delete, so we do not need to search
// for the shared_ptr<> (the entry in m_vAllMarks) again
// reverse iteration, since erasing an entry invalidates iterators
// behind it (the iterators in vMarksToDelete are sorted)
for ( ::std::vector< const_iterator_t >::reverse_iterator pppMark = vMarksToDelete.rbegin();
- pppMark != vMarksToDelete.rend();
- pppMark++)
+ pppMark != vMarksToDelete.rend();
+ ++pppMark )
{
deleteMark(*pppMark);
}
- if(bIsSortingNeeded)
+
+ if ( bIsSortingNeeded )
+ {
sortMarks();
+ }
+
#if 0
OSL_TRACE("deleteMarks");
lcl_DebugMarks(m_vAllMarks);
@@ -1005,15 +1032,20 @@ namespace sw { namespace mark
return sTmp;
}
- void MarkManager::sortMarks()
+ void MarkManager::sortSubsetMarks()
{
- sort(m_vAllMarks.begin(), m_vAllMarks.end(), &lcl_MarkOrderingByStart);
sort(m_vCommonMarks.begin(), m_vCommonMarks.end(), &lcl_MarkOrderingByStart);
sort(m_vBookmarks.begin(), m_vBookmarks.end(), &lcl_MarkOrderingByStart);
sort(m_vFieldmarks.begin(), m_vFieldmarks.end(), &lcl_MarkOrderingByStart);
sort(m_vAnnotationMarks.begin(), m_vAnnotationMarks.end(), &lcl_MarkOrderingByStart);
}
+ void MarkManager::sortMarks()
+ {
+ sort(m_vAllMarks.begin(), m_vAllMarks.end(), &lcl_MarkOrderingByStart);
+ sortSubsetMarks();
+ }
+
#if OSL_DEBUG_LEVEL > 1
void MarkManager::dumpFieldmarks( ) const
{
diff --git a/sw/source/core/inc/MarkManager.hxx b/sw/source/core/inc/MarkManager.hxx
index 0621140..9004df1 100644
--- a/sw/source/core/inc/MarkManager.hxx
+++ b/sw/source/core/inc/MarkManager.hxx
@@ -99,6 +99,7 @@ namespace sw { namespace mark
// make names
::rtl::OUString getUniqueMarkName(const ::rtl::OUString& rName) const;
void sortMarks();
+ void sortSubsetMarks();
// container for all marks
container_t m_vAllMarks;
More information about the Libreoffice-commits
mailing list