summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <Michael.Stahl@cib.de>2019-10-11 14:48:12 +0200
committerMichael Stahl <michael.stahl@cib.de>2019-10-23 13:00:02 +0200
commit1332cf210803215857b81e8ca9c029aa3d6c49c2 (patch)
treedbc0086ba0d5751cc8c23938abdd9432296b24b1
parentffb26b81e1c7ff1d64959200247bb2edd5a569da (diff)
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 <michael.stahl@cib.de>
-rw-r--r--sw/inc/IDocumentMarkAccess.hxx6
-rw-r--r--sw/source/core/crsr/annotationmark.cxx3
-rw-r--r--sw/source/core/crsr/bookmrk.cxx35
-rw-r--r--sw/source/core/doc/docbm.cxx15
-rw-r--r--sw/source/core/inc/MarkManager.hxx6
-rw-r--r--sw/source/core/inc/annotationmark.hxx2
-rw-r--r--sw/source/core/inc/bookmrk.hxx10
7 files changed, 51 insertions, 26 deletions
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;