Author: orw Date: Fri Jan 17 07:28:17 2014 New Revision: 1559037 URL: http://svn.apache.org/r1559037 Log: 123480: method <::sw::mark::deleteMarks(..)> - assure sorting of subset mark containers before the intrinsic deletion of marks
Modified: openoffice/trunk/main/sw/source/core/doc/docbm.cxx openoffice/trunk/main/sw/source/core/inc/MarkManager.hxx Modified: openoffice/trunk/main/sw/source/core/doc/docbm.cxx URL: http://svn.apache.org/viewvc/openoffice/trunk/main/sw/source/core/doc/docbm.cxx?rev=1559037&r1=1559036&r2=1559037&view=diff ============================================================================== --- openoffice/trunk/main/sw/source/core/doc/docbm.cxx (original) +++ openoffice/trunk/main/sw/source/core/doc/docbm.cxx Fri Jan 17 07:28:17 2014 @@ -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 { Modified: openoffice/trunk/main/sw/source/core/inc/MarkManager.hxx URL: http://svn.apache.org/viewvc/openoffice/trunk/main/sw/source/core/inc/MarkManager.hxx?rev=1559037&r1=1559036&r2=1559037&view=diff ============================================================================== --- openoffice/trunk/main/sw/source/core/inc/MarkManager.hxx (original) +++ openoffice/trunk/main/sw/source/core/inc/MarkManager.hxx Fri Jan 17 07:28:17 2014 @@ -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;