diff options
author | Oliver-Rainer Wittmann <orw@apache.org> | 2014-03-04 12:35:01 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2014-03-04 20:31:05 +0000 |
commit | 14f124a5ef5c32bad765265d5a3f05290ccc6149 (patch) | |
tree | 75e7b9386a3475d4ec926585205c2713a2452f1a | |
parent | 41bd5a3bc80b670040884b835db4c425ab990a46 (diff) |
Resolves: #i124338# assure sorted mark containers...
when updating <SwIndex> instances due to inserted characters
(cherry picked from commit 770c0e6b910129710b4be5cb9e9bae39bfa6bd5a)
Conflicts:
sw/source/core/bastyp/index.cxx
sw/source/core/crsr/bookmrk.cxx
sw/source/core/doc/docbm.cxx
sw/source/core/inc/bookmrk.hxx
sw/source/core/inc/crossrefbookmark.hxx
Change-Id: Ie4531c3b33aff0a7f3d139ee81a21c3823474f84
-rw-r--r-- | sw/inc/IDocumentMarkAccess.hxx | 2 | ||||
-rw-r--r-- | sw/source/core/bastyp/index.cxx | 7 | ||||
-rw-r--r-- | sw/source/core/crsr/bookmrk.cxx | 69 | ||||
-rw-r--r-- | sw/source/core/doc/docbm.cxx | 69 | ||||
-rw-r--r-- | sw/source/core/inc/MarkManager.hxx | 2 | ||||
-rw-r--r-- | sw/source/core/inc/bookmrk.hxx | 4 | ||||
-rw-r--r-- | sw/source/core/inc/crossrefbookmark.hxx | 1 | ||||
-rw-r--r-- | sw/source/core/txtnode/ndtxt.cxx | 6 |
8 files changed, 119 insertions, 41 deletions
diff --git a/sw/inc/IDocumentMarkAccess.hxx b/sw/inc/IDocumentMarkAccess.hxx index 784b45f2e922..8d59cbf24b8b 100644 --- a/sw/inc/IDocumentMarkAccess.hxx +++ b/sw/inc/IDocumentMarkAccess.hxx @@ -194,6 +194,8 @@ class IDocumentMarkAccess */ virtual void clearAllMarks() =0; + virtual void assureSortedMarkContainers() const = 0; + /** returns a STL-like random access iterator to the begin of the sequence of marks. */ virtual const_iterator_t getAllMarksBegin() const =0; diff --git a/sw/source/core/bastyp/index.cxx b/sw/source/core/bastyp/index.cxx index 120d1193fc0c..4f3f0456f0fa 100644 --- a/sw/source/core/bastyp/index.cxx +++ b/sw/source/core/bastyp/index.cxx @@ -223,8 +223,11 @@ SwIndexReg::~SwIndexReg() assert(!m_pFirst && !m_pLast); // There are still indices registered } -void SwIndexReg::Update( SwIndex const & rIdx, const sal_Int32 nDiff, - const bool bNeg, const bool /* argument is only used in derived class*/ ) +void SwIndexReg::Update( + SwIndex const & rIdx, + const sal_Int32 nDiff, + const bool bNeg, + const bool /* argument is only used in derived class*/ ) { SwIndex* pStt = const_cast<SwIndex*>(&rIdx); const sal_Int32 nNewVal = rIdx.m_nIndex; diff --git a/sw/source/core/crsr/bookmrk.cxx b/sw/source/core/crsr/bookmrk.cxx index f09895aa2d30..1fb0b051732e 100644 --- a/sw/source/core/crsr/bookmrk.cxx +++ b/sw/source/core/crsr/bookmrk.cxx @@ -64,31 +64,32 @@ namespace const sal_Unicode aStartMark, const sal_Unicode aEndMark) { - SwPosition& rStart = pField->GetMarkStart(); - SwPosition& rEnd = pField->GetMarkEnd(); + io_pDoc->GetIDocumentUndoRedo().StartUndo(UNDO_UI_REPLACE, NULL); - SwTxtNode const*const pStartTxtNode = - rStart.nNode.GetNode().GetTxtNode(); - SwTxtNode const*const pEndTxtNode = rEnd.nNode.GetNode().GetTxtNode(); + SwPosition rStart = pField->GetMarkStart(); + SwTxtNode const*const pStartTxtNode = rStart.nNode.GetNode().GetTxtNode(); const sal_Unicode ch_start = ( rStart.nContent.GetIndex() >= pStartTxtNode->GetTxt().getLength() ) ? 0 : pStartTxtNode->GetTxt()[rStart.nContent.GetIndex()]; - const sal_Int32 nEndPos = ( rEnd == rStart || rEnd.nContent.GetIndex() == 0 ) ? - rEnd.nContent.GetIndex() : rEnd.nContent.GetIndex() - 1; - const sal_Unicode ch_end = nEndPos >= pEndTxtNode->GetTxt().getLength() ? 0 : pEndTxtNode->GetTxt()[nEndPos]; - SwPaM aStartPaM(rStart); - SwPaM aEndPaM(rEnd); - - io_pDoc->GetIDocumentUndoRedo().StartUndo(UNDO_UI_REPLACE, NULL); if( ( ch_start != aStartMark ) && ( aEndMark != CH_TXT_ATR_FORMELEMENT ) ) { + SwPaM aStartPaM(rStart); io_pDoc->InsertString(aStartPaM, OUString(aStartMark)); rStart.nContent--; + pField->SetMarkStartPos( rStart ); } + + SwPosition& rEnd = pField->GetMarkEnd(); + SwTxtNode const*const pEndTxtNode = rEnd.nNode.GetNode().GetTxtNode(); + const sal_Int32 nEndPos = ( rEnd == rStart || rEnd.nContent.GetIndex() == 0 ) ? + rEnd.nContent.GetIndex() : rEnd.nContent.GetIndex() - 1; + const sal_Unicode ch_end = nEndPos >= pEndTxtNode->GetTxt().getLength() ? 0 : pEndTxtNode->GetTxt()[nEndPos]; if ( aEndMark && ( ch_end != aEndMark ) ) { + SwPaM aEndPaM(rEnd); io_pDoc->InsertString(aEndPaM, OUString(aEndMark)); rEnd.nContent++; } + io_pDoc->GetIDocumentUndoRedo().EndUndo(UNDO_UI_REPLACE, NULL); }; @@ -97,31 +98,33 @@ namespace const sal_Unicode aStartMark, const sal_Unicode aEndMark) { - SwPosition& rStart = pField->GetMarkStart(); - SwPosition& rEnd = pField->GetMarkEnd(); - SwTxtNode const*const pStartTxtNode = - rStart.nNode.GetNode().GetTxtNode(); - SwTxtNode const*const pEndTxtNode = rEnd.nNode.GetNode().GetTxtNode(); + io_pDoc->GetIDocumentUndoRedo().StartUndo(UNDO_UI_REPLACE, NULL); + + const SwPosition& rStart = pField->GetMarkStart(); + SwTxtNode const*const pStartTxtNode = rStart.nNode.GetNode().GetTxtNode(); const sal_Unicode ch_start = pStartTxtNode->GetTxt()[rStart.nContent.GetIndex()]; - const sal_Int32 nEndPos = ( rEnd == rStart || rEnd.nContent.GetIndex() == 0 ) ? - rEnd.nContent.GetIndex() : rEnd.nContent.GetIndex() - 1; - const sal_Unicode ch_end = pEndTxtNode->GetTxt()[nEndPos]; - SwPaM aStartPaM(rStart); - SwPaM aEndPaM(rEnd); - io_pDoc->GetIDocumentUndoRedo().StartUndo(UNDO_UI_REPLACE, NULL); + if( ch_start == aStartMark ) { SwPaM aStart(rStart, rStart); aStart.End()->nContent++; io_pDoc->DeleteRange(aStart); } + + const SwPosition& rEnd = pField->GetMarkEnd(); + SwTxtNode const*const pEndTxtNode = rEnd.nNode.GetNode().GetTxtNode(); + const sal_Int32 nEndPos = ( rEnd == rStart || rEnd.nContent.GetIndex() == 0 ) + ? rEnd.nContent.GetIndex() + : rEnd.nContent.GetIndex() - 1; + const sal_Unicode ch_end = pEndTxtNode->GetTxt()[nEndPos]; if ( ch_end == aEndMark ) { SwPaM aEnd(rEnd, rEnd); aEnd.Start()->nContent--; io_pDoc->DeleteRange(aEnd); } + io_pDoc->GetIDocumentUndoRedo().EndUndo(UNDO_UI_REPLACE, NULL); }; } @@ -308,6 +311,22 @@ namespace sw { namespace mark SetOtherMarkPos(GetMarkPos()); } + void Fieldmark::SetMarkStartPos( const SwPosition& rNewStartPos ) + { + if ( GetMarkPos( ) <= GetOtherMarkPos( ) ) + return SetMarkPos( rNewStartPos ); + else + return SetOtherMarkPos( rNewStartPos ); + } + + void Fieldmark::SetMarkEndPos( const SwPosition& rNewEndPos ) + { + if ( GetMarkPos( ) <= GetOtherMarkPos( ) ) + return SetOtherMarkPos( rNewEndPos ); + else + return SetMarkPos( rNewEndPos ); + } + OUString Fieldmark::ToString( ) const { return "Fieldmark: ( Name, Type, [ Nd1, Id1 ], [ Nd2, Id2 ] ): ( " + m_aName + ", " @@ -349,7 +368,9 @@ namespace sw { namespace mark // For some reason the end mark is moved from 1 by the Insert: we don't // want this for checkboxes - this->GetMarkEnd( ).nContent--; + SwPosition aNewEndPos = this->GetMarkEnd(); + aNewEndPos.nContent--; + SetMarkEndPos( aNewEndPos ); } void CheckboxFieldmark::ReleaseDoc(SwDoc* const pDoc) diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx index 3cb4dffd4483..d9722362278b 100644 --- a/sw/source/core/doc/docbm.cxx +++ b/sw/source/core/doc/docbm.cxx @@ -828,16 +828,26 @@ namespace sw { namespace mark case IDocumentMarkAccess::BOOKMARK: case IDocumentMarkAccess::CROSSREF_HEADING_BOOKMARK: case IDocumentMarkAccess::CROSSREF_NUMITEM_BOOKMARK: - // if(dynamic_cast<IBookmark*>) { IDocumentMarkAccess::iterator_t ppBookmark = lcl_FindMark(m_vBookmarks, *ppMark); - OSL_ENSURE(ppBookmark != m_vBookmarks.end(), - "<MarkManager::deleteMark(..)>" - " - Bookmark not found."); - m_vBookmarks.erase(ppBookmark); + if ( ppBookmark != m_vBookmarks.end() ) + { + m_vBookmarks.erase(ppBookmark); + } + else + { + OSL_ENSURE( false, "<MarkManager::deleteMark(..)> - Bookmark not found in Bookmark container."); + } ppBookmark = lcl_FindMark(m_vCommonMarks, *ppMark); - m_vCommonMarks.erase(ppBookmark); + if ( ppBookmark != m_vCommonMarks.end() ) + { + m_vCommonMarks.erase(ppBookmark); + } + else + { + OSL_ENSURE( false, "<MarkManager::deleteMark(..)> - Bookmark not found in common mark container."); + } } break; @@ -845,22 +855,39 @@ namespace sw { namespace mark case IDocumentMarkAccess::CHECKBOX_FIELDMARK: { IDocumentMarkAccess::iterator_t ppFieldmark = lcl_FindMark(m_vFieldmarks, *ppMark); - OSL_ENSURE(ppFieldmark != m_vFieldmarks.end(), - "<MarkManager::deleteMark(..)>" - " - Bookmark not found."); - m_vFieldmarks.erase(ppFieldmark); - ret.reset(new LazyFieldmarkDeleter(*ppMark, m_pDoc)); + if ( ppFieldmark != m_vFieldmarks.end() ) + { + m_vFieldmarks.erase(ppFieldmark); + ret.reset(new LazyFieldmarkDeleter(*ppMark, m_pDoc)); + } + else + { + OSL_ENSURE( false, "<MarkManager::deleteMark(..)> - Fieldmark not found in Fieldmark container."); + } ppFieldmark = lcl_FindMark(m_vCommonMarks, *ppMark); - m_vCommonMarks.erase(ppFieldmark); + if ( ppFieldmark != m_vCommonMarks.end() ) + { + m_vCommonMarks.erase(ppFieldmark); + } + else + { + OSL_ENSURE( false, "<MarkManager::deleteMark(..)> - Fieldmark not found in common mark container."); + } } break; case IDocumentMarkAccess::ANNOTATIONMARK: { IDocumentMarkAccess::iterator_t ppAnnotationMark = lcl_FindMark(m_vAnnotationMarks, *ppMark); - OSL_ENSURE( ppAnnotationMark != m_vAnnotationMarks.end(), "<MarkManager::deleteMark(..)> - Annotation Mark not found." ); - m_vAnnotationMarks.erase(ppAnnotationMark); + if ( ppAnnotationMark != m_vAnnotationMarks.end() ) + { + m_vAnnotationMarks.erase(ppAnnotationMark); + } + else + { + OSL_ENSURE( false, "<MarkManager::deleteMark(..)> - Annotation Mark not found in Annotation Mark container."); + } } break; @@ -869,7 +896,14 @@ namespace sw { namespace mark case IDocumentMarkAccess::UNO_BOOKMARK: { IDocumentMarkAccess::iterator_t ppOtherMark = lcl_FindMark(m_vCommonMarks, *ppMark); - m_vCommonMarks.erase(ppOtherMark); + if ( ppOtherMark != m_vCommonMarks.end() ) + { + m_vCommonMarks.erase(ppOtherMark); + } + else + { + OSL_ENSURE( false, "<MarkManager::deleteMark(..)> - Navigator Reminder, DDE Mark or Uno Makr not found in common mark container."); + } } break; } @@ -1052,6 +1086,11 @@ namespace sw { namespace mark return sTmp; } + void MarkManager::assureSortedMarkContainers() const + { + const_cast< MarkManager* >(this)->sortMarks(); + } + void MarkManager::sortSubsetMarks() { sort(m_vCommonMarks.begin(), m_vCommonMarks.end(), &lcl_MarkOrderingByStart); diff --git a/sw/source/core/inc/MarkManager.hxx b/sw/source/core/inc/MarkManager.hxx index 549d06b016a0..ed4afd7b6ad9 100644 --- a/sw/source/core/inc/MarkManager.hxx +++ b/sw/source/core/inc/MarkManager.hxx @@ -95,6 +95,8 @@ namespace sw { virtual sal_Int32 getAnnotationMarksCount() const; virtual const_iterator_t findAnnotationMark( const ::rtl::OUString& rName ) const; + virtual void assureSortedMarkContainers() const; + private: // make names OUString getUniqueMarkName(const OUString& rName) const; diff --git a/sw/source/core/inc/bookmrk.hxx b/sw/source/core/inc/bookmrk.hxx index 761842fe8da7..9df8878743cc 100644 --- a/sw/source/core/inc/bookmrk.hxx +++ b/sw/source/core/inc/bookmrk.hxx @@ -47,6 +47,7 @@ namespace sw { : virtual public IMark { public: + //getters virtual SwPosition& GetMarkPos() const { return *m_pPos1; } virtual const OUString& GetName() const @@ -215,6 +216,9 @@ namespace sw { virtual void ReleaseDoc(SwDoc* const) = 0; + void SetMarkStartPos( const SwPosition& rNewStartPos ); + void SetMarkEndPos( const SwPosition& rNewEndPos ); + virtual void Invalidate(); virtual OUString ToString() const; diff --git a/sw/source/core/inc/crossrefbookmark.hxx b/sw/source/core/inc/crossrefbookmark.hxx index fa4777b1c826..79212d38b06c 100644 --- a/sw/source/core/inc/crossrefbookmark.hxx +++ b/sw/source/core/inc/crossrefbookmark.hxx @@ -36,6 +36,7 @@ namespace sw { const OUString& rShortName, const OUString& rPrefix); + // getters virtual SwPosition& GetOtherMarkPos() const; virtual SwPosition& GetMarkStart() const { return *m_pPos1; } diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx index 92d70da86bc9..a82bda201b9e 100644 --- a/sw/source/core/txtnode/ndtxt.cxx +++ b/sw/source/core/txtnode/ndtxt.cxx @@ -1014,6 +1014,7 @@ void SwTxtNode::Update( } } + bool bSortMarks = false; SwIndexReg aTmpIdxReg; if ( !bNegative && !bDelete ) { @@ -1072,6 +1073,7 @@ void SwTxtNode::Update( rPos.GetIndex() == rIdx.GetIndex() ) { rIdx.Assign( &aTmpIdxReg, rIdx.GetIndex() ); + bSortMarks = true; } } } @@ -1090,6 +1092,10 @@ void SwTxtNode::Update( } aTmpIdxReg.MoveTo( *this ); + if ( bSortMarks ) + { + getIDocumentMarkAccess()->assureSortedMarkContainers(); + } } void SwTxtNode::_ChgTxtCollUpdateNum( const SwTxtFmtColl *pOldColl, |