sw/inc/IDocumentMarkAccess.hxx | 6 +++-- sw/qa/extras/ww8export/ww8export2.cxx | 2 - sw/source/core/crsr/annotationmark.cxx | 3 +- sw/source/core/crsr/bookmrk.cxx | 35 +++++++++++++++++++++++---------- sw/source/core/doc/docbm.cxx | 15 +++++++++----- sw/source/core/inc/MarkManager.hxx | 6 +++-- sw/source/core/inc/annotationmark.hxx | 2 - sw/source/core/inc/bookmrk.hxx | 10 ++++----- sw/source/filter/ww8/ww8par5.cxx | 6 +++-- 9 files changed, 56 insertions(+), 29 deletions(-)
New commits: commit 7f2e61f884949ab27bcb7e1a02ece9a5cb4354b9 Author: Michael Stahl <[email protected]> AuthorDate: Fri Oct 11 14:55:53 2019 +0200 Commit: Michael Stahl <[email protected]> CommitDate: Wed Oct 23 13:00:23 2019 +0200 sw: WW8: fix the separator position WW8 inserts the fieldmark at the end of the result, so separator should be at the start; writerfilter inserts fieldmark at the end of command so separator should be at the end. Change-Id: I44c9811139a34f529c553dd2fd46fdaccd554732 Reviewed-on: https://gerrit.libreoffice.org/80674 Tested-by: Jenkins Reviewed-by: Michael Stahl <[email protected]> diff --git a/sw/qa/extras/ww8export/ww8export2.cxx b/sw/qa/extras/ww8export/ww8export2.cxx index 43c3252953f5..b2523b822370 100644 --- a/sw/qa/extras/ww8export/ww8export2.cxx +++ b/sw/qa/extras/ww8export/ww8export2.cxx @@ -312,7 +312,7 @@ DECLARE_WW8EXPORT_TEST(testTdf104334, "tdf104334.doc") // This failed with a container::NoSuchElementException: STYLEREF was // mapped to SwChapterField, and the field result was "This is a Heading 1" // instead of just "1". - CPPUNIT_ASSERT_EQUAL(OUString("1"), getRun(getParagraph(2), 3)->getString()); + CPPUNIT_ASSERT_EQUAL(OUString("1"), getRun(getParagraph(2), 4)->getString()); } DECLARE_WW8EXPORT_TEST(testTdf108072, "tdf108072.doc") diff --git a/sw/source/filter/ww8/ww8par5.cxx b/sw/source/filter/ww8/ww8par5.cxx index 1c27d73c3021..1ddbb49c3823 100644 --- a/sw/source/filter/ww8/ww8par5.cxx +++ b/sw/source/filter/ww8/ww8par5.cxx @@ -541,7 +541,8 @@ sal_uInt16 SwWW8ImplReader::End_Field() SwPaM aFieldPam( m_aFieldStack.back().GetPtNode(), m_aFieldStack.back().GetPtContent(), aEndPos.nNode, aEndPos.nContent.GetIndex()); IDocumentMarkAccess* pMarksAccess = m_rDoc.getIDocumentMarkAccess( ); IFieldmark *pFieldmark = pMarksAccess->makeFieldBookmark( - aFieldPam, m_aFieldStack.back().GetBookmarkName(), ODF_FORMTEXT ); + aFieldPam, m_aFieldStack.back().GetBookmarkName(), ODF_FORMTEXT, + aFieldPam.Start() /*same pos as start!*/ ); OSL_ENSURE(pFieldmark!=nullptr, "hmmm; why was the bookmark not created?"); if (pFieldmark!=nullptr) { // adapt redline positions to inserted field mark start @@ -640,7 +641,8 @@ sal_uInt16 SwWW8ImplReader::End_Field() IFieldmark* pFieldmark = pMarksAccess->makeFieldBookmark( aFieldPam, m_aFieldStack.back().GetBookmarkName(), - ODF_UNHANDLED ); + ODF_UNHANDLED, + aFieldPam.Start() /*same pos as start!*/ ); if ( pFieldmark ) { // adapt redline positions to inserted field mark start commit 1332cf210803215857b81e8ca9c029aa3d6c49c2 Author: Michael Stahl <[email protected]> AuthorDate: Fri Oct 11 14:48:12 2019 +0200 Commit: Michael Stahl <[email protected]> CommitDate: Wed Oct 23 13:00:02 2019 +0200 sw: add CH_TXT_ATR_FIELDSEP position parameter when inserting Different callers want it at the end, at the start, or in the case of Undo it can even be in an arbitrary position... (except if it is ensured that the field command is deleted before the fieldmark?). So let's just pass in SwPosition and be flexible, if it is missing it will be before the end as before. Change-Id: Ibec222f633bdaf66abd1540027d0f5c75988c738 Reviewed-on: https://gerrit.libreoffice.org/80673 Tested-by: Jenkins Reviewed-by: Michael Stahl <[email protected]> diff --git a/sw/inc/IDocumentMarkAccess.hxx b/sw/inc/IDocumentMarkAccess.hxx index a8dacbcbd7e4..1e2db2436a61 100644 --- a/sw/inc/IDocumentMarkAccess.hxx +++ b/sw/inc/IDocumentMarkAccess.hxx @@ -132,11 +132,13 @@ class IDocumentMarkAccess */ virtual ::sw::mark::IMark* makeMark(const SwPaM& rPaM, const OUString& rProposedName, - MarkType eMark, ::sw::mark::InsertMode eMode) = 0; + MarkType eMark, ::sw::mark::InsertMode eMode, + SwPosition const* pSepPos = nullptr) = 0; virtual sw::mark::IFieldmark* makeFieldBookmark( const SwPaM& rPaM, const OUString& rName, - const OUString& rType) = 0; + const OUString& rType, + SwPosition const* pSepPos = nullptr) = 0; virtual sw::mark::IFieldmark* makeNoTextFieldBookmark( const SwPaM& rPaM, const OUString& rName, const OUString& rType) = 0; diff --git a/sw/source/core/crsr/annotationmark.cxx b/sw/source/core/crsr/annotationmark.cxx index 9741f276906e..ea11fad3d2cc 100644 --- a/sw/source/core/crsr/annotationmark.cxx +++ b/sw/source/core/crsr/annotationmark.cxx @@ -48,7 +48,8 @@ namespace sw { namespace mark { } - void AnnotationMark::InitDoc(SwDoc* const io_pDoc, sw::mark::InsertMode const) + void AnnotationMark::InitDoc(SwDoc* const io_pDoc, + sw::mark::InsertMode const, SwPosition const*const) { SwTextNode *pTextNode = GetMarkEnd().nNode.GetNode().GetTextNode(); assert(pTextNode); diff --git a/sw/source/core/crsr/bookmrk.cxx b/sw/source/core/crsr/bookmrk.cxx index c74abc61935f..ba43b2158bd4 100644 --- a/sw/source/core/crsr/bookmrk.cxx +++ b/sw/source/core/crsr/bookmrk.cxx @@ -154,7 +154,8 @@ namespace void lcl_SetFieldMarks(Fieldmark* const pField, SwDoc* const io_pDoc, const sal_Unicode aStartMark, - const sal_Unicode aEndMark) + const sal_Unicode aEndMark, + SwPosition const*const pSepPos) { io_pDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::UI_REPLACE, nullptr); @@ -169,9 +170,18 @@ namespace pField->SetMarkStartPos( start ); SwPosition& rEnd = pField->GetMarkEnd(); // note: retrieve after // setting start, because if start==end it can go stale, see SetMarkPos() - *aStartPaM.GetPoint() = rEnd; + assert(pSepPos == nullptr || (start < *pSepPos && *pSepPos <= rEnd)); + *aStartPaM.GetPoint() = pSepPos ? *pSepPos : rEnd; io_pDoc->getIDocumentContentOperations().InsertString(aStartPaM, OUString(CH_TXT_ATR_FIELDSEP)); - ++rEnd.nContent; + if (!pSepPos || rEnd < *pSepPos) + { // rEnd is not moved automatically if it's same as insert pos + ++rEnd.nContent; + } + assert(pSepPos == nullptr || (start < *pSepPos && *pSepPos <= rEnd)); + } + else + { + assert(pSepPos == nullptr); } SwPosition& rEnd = pField->GetMarkEnd(); @@ -363,7 +373,8 @@ namespace sw { namespace mark m_aName = rName; } - void Bookmark::InitDoc(SwDoc* const io_pDoc, sw::mark::InsertMode const) + void Bookmark::InitDoc(SwDoc* const io_pDoc, + sw::mark::InsertMode const, SwPosition const*const) { if (io_pDoc->GetIDocumentUndoRedo().DoesUndo()) { @@ -485,11 +496,12 @@ namespace sw { namespace mark m_aName = rName; } - void TextFieldmark::InitDoc(SwDoc* const io_pDoc, sw::mark::InsertMode const eMode) + void TextFieldmark::InitDoc(SwDoc* const io_pDoc, + sw::mark::InsertMode const eMode, SwPosition const*const pSepPos) { if (eMode == sw::mark::InsertMode::New) { - lcl_SetFieldMarks(this, io_pDoc, CH_TXT_ATR_FIELDSTART, CH_TXT_ATR_FIELDEND); + lcl_SetFieldMarks(this, io_pDoc, CH_TXT_ATR_FIELDSTART, CH_TXT_ATR_FIELDEND, pSepPos); } else { @@ -506,11 +518,13 @@ namespace sw { namespace mark : Fieldmark(rPaM) { } - void NonTextFieldmark::InitDoc(SwDoc* const io_pDoc, sw::mark::InsertMode const eMode) + void NonTextFieldmark::InitDoc(SwDoc* const io_pDoc, + sw::mark::InsertMode const eMode, SwPosition const*const pSepPos) { + assert(pSepPos == nullptr); if (eMode == sw::mark::InsertMode::New) { - lcl_SetFieldMarks(this, io_pDoc, CH_TXT_ATR_FIELDSTART, CH_TXT_ATR_FORMELEMENT); + lcl_SetFieldMarks(this, io_pDoc, CH_TXT_ATR_FIELDSTART, CH_TXT_ATR_FORMELEMENT, pSepPos); // For some reason the end mark is moved from 1 by the Insert: // we don't want this for checkboxes @@ -625,13 +639,14 @@ namespace sw { namespace mark { } - void DateFieldmark::InitDoc(SwDoc* const io_pDoc, sw::mark::InsertMode eMode) + void DateFieldmark::InitDoc(SwDoc* const io_pDoc, + sw::mark::InsertMode eMode, SwPosition const*const pSepPos) { m_pNumberFormatter = io_pDoc->GetNumberFormatter(); m_pDocumentContentOperationsManager = &io_pDoc->GetDocumentContentOperationsManager(); if (eMode == sw::mark::InsertMode::New) { - lcl_SetFieldMarks(this, io_pDoc, CH_TXT_ATR_FIELDSTART, CH_TXT_ATR_FIELDEND); + lcl_SetFieldMarks(this, io_pDoc, CH_TXT_ATR_FIELDSTART, CH_TXT_ATR_FIELDEND, pSepPos); } else { diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx index e385f5445abd..4f13bea2d79f 100644 --- a/sw/source/core/doc/docbm.cxx +++ b/sw/source/core/doc/docbm.cxx @@ -544,7 +544,8 @@ namespace sw { namespace mark ::sw::mark::IMark* MarkManager::makeMark(const SwPaM& rPaM, const OUString& rName, const IDocumentMarkAccess::MarkType eType, - sw::mark::InsertMode const eMode) + sw::mark::InsertMode const eMode, + SwPosition const*const pSepPos) { #if OSL_DEBUG_LEVEL > 0 { @@ -642,7 +643,7 @@ namespace sw { namespace mark // no special array for these break; } - pMark->InitDoc(m_pDoc, eMode); + pMark->InitDoc(m_pDoc, eMode, pSepPos); SAL_INFO("sw.core", "--- makeType ---"); SAL_INFO("sw.core", "Marks"); lcl_DebugMarks(m_vAllMarks); @@ -657,8 +658,10 @@ namespace sw { namespace mark ::sw::mark::IFieldmark* MarkManager::makeFieldBookmark( const SwPaM& rPaM, const OUString& rName, - const OUString& rType ) + const OUString& rType, + SwPosition const*const pSepPos) { + // Disable undo, because we handle it using SwUndoInsTextFieldmark bool bUndoIsEnabled = m_pDoc->GetIDocumentUndoRedo().DoesUndo(); m_pDoc->GetIDocumentUndoRedo().DoUndo(false); @@ -668,13 +671,15 @@ namespace sw { namespace mark { pMark = makeMark(rPaM, rName, IDocumentMarkAccess::MarkType::DATE_FIELDMARK, - sw::mark::InsertMode::New); + sw::mark::InsertMode::New, + pSepPos); } else { pMark = makeMark(rPaM, rName, IDocumentMarkAccess::MarkType::TEXT_FIELDMARK, - sw::mark::InsertMode::New); + sw::mark::InsertMode::New, + pSepPos); } sw::mark::IFieldmark* pFieldMark = dynamic_cast<sw::mark::IFieldmark*>( pMark ); if (pFieldMark) diff --git a/sw/source/core/inc/MarkManager.hxx b/sw/source/core/inc/MarkManager.hxx index 120149ccc039..edf8121836b6 100644 --- a/sw/source/core/inc/MarkManager.hxx +++ b/sw/source/core/inc/MarkManager.hxx @@ -41,11 +41,13 @@ namespace sw { // IDocumentMarkAccess virtual ::sw::mark::IMark* makeMark(const SwPaM& rPaM, const OUString& rName, IDocumentMarkAccess::MarkType eMark, - sw::mark::InsertMode eMode) override; + sw::mark::InsertMode eMode, + SwPosition const* pSepPos = nullptr) override; virtual sw::mark::IFieldmark* makeFieldBookmark( const SwPaM& rPaM, const OUString& rName, - const OUString& rType) override; + const OUString& rType, + SwPosition const* pSepPos = nullptr) override; virtual sw::mark::IFieldmark* makeNoTextFieldBookmark( const SwPaM& rPaM, const OUString& rName, const OUString& rType) override; diff --git a/sw/source/core/inc/annotationmark.hxx b/sw/source/core/inc/annotationmark.hxx index a74470b6704a..8cf1590ca310 100644 --- a/sw/source/core/inc/annotationmark.hxx +++ b/sw/source/core/inc/annotationmark.hxx @@ -36,7 +36,7 @@ namespace sw { namespace mark virtual ~AnnotationMark() override; - virtual void InitDoc(SwDoc* const io_Doc, sw::mark::InsertMode eMode) override; + virtual void InitDoc(SwDoc* const io_Doc, sw::mark::InsertMode eMode, SwPosition const* pSepPos) override; const SwFormatField* GetAnnotationFormatField() const; }; diff --git a/sw/source/core/inc/bookmrk.hxx b/sw/source/core/inc/bookmrk.hxx index 87860603aad7..cd0e154185db 100644 --- a/sw/source/core/inc/bookmrk.hxx +++ b/sw/source/core/inc/bookmrk.hxx @@ -99,7 +99,7 @@ namespace sw { m_pPos1.swap(m_pPos2); } - virtual void InitDoc(SwDoc* const, sw::mark::InsertMode) + virtual void InitDoc(SwDoc* const, sw::mark::InsertMode, SwPosition const*) { } @@ -166,7 +166,7 @@ namespace sw { Bookmark(const SwPaM& rPaM, const vcl::KeyCode& rCode, const OUString& rName); - virtual void InitDoc(SwDoc* const io_Doc, sw::mark::InsertMode eMode) override; + virtual void InitDoc(SwDoc* const io_Doc, sw::mark::InsertMode eMode, SwPosition const* pSepPos) override; virtual void DeregisterFromDoc(SwDoc* const io_pDoc) override; @@ -244,7 +244,7 @@ namespace sw { { public: TextFieldmark(const SwPaM& rPaM, const OUString& rName); - virtual void InitDoc(SwDoc* const io_pDoc, sw::mark::InsertMode eMode) override; + virtual void InitDoc(SwDoc* const io_pDoc, sw::mark::InsertMode eMode, SwPosition const* pSepPos) override; virtual void ReleaseDoc(SwDoc* const pDoc) override; }; @@ -254,7 +254,7 @@ namespace sw { { public: NonTextFieldmark(const SwPaM& rPaM); - virtual void InitDoc(SwDoc* const io_pDoc, sw::mark::InsertMode eMode) override; + virtual void InitDoc(SwDoc* const io_pDoc, sw::mark::InsertMode eMode, SwPosition const* pSepPos) override; virtual void ReleaseDoc(SwDoc* const pDoc) override; }; @@ -311,7 +311,7 @@ namespace sw { DateFieldmark(const SwPaM& rPaM); virtual ~DateFieldmark() override; - virtual void InitDoc(SwDoc* const io_pDoc, sw::mark::InsertMode eMode) override; + virtual void InitDoc(SwDoc* const io_pDoc, sw::mark::InsertMode eMode, SwPosition const* pSepPos) override; virtual void ReleaseDoc(SwDoc* const pDoc) override; virtual void ShowButton(SwEditWin* pEditWin) override; _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
