summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sw/qa/extras/globalfilter/globalfilter.cxx10
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport12.cxx4
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport13.cxx4
-rw-r--r--sw/qa/extras/ooxmlimport/ooxmlimport.cxx2
-rw-r--r--sw/qa/extras/ww8export/ww8export3.cxx4
-rw-r--r--sw/source/core/crsr/bookmrk.cxx95
-rw-r--r--sw/source/core/inc/bookmrk.hxx3
7 files changed, 108 insertions, 14 deletions
diff --git a/sw/qa/extras/globalfilter/globalfilter.cxx b/sw/qa/extras/globalfilter/globalfilter.cxx
index 356e017ebb55..4c47c284fc59 100644
--- a/sw/qa/extras/globalfilter/globalfilter.cxx
+++ b/sw/qa/extras/globalfilter/globalfilter.cxx
@@ -1320,7 +1320,7 @@ void Test::testDateFormField()
CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), OUString("06/12/19"), sCurrentDate);
CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), sal_uLong(9), pFieldmark->GetMarkStart().nNode.GetIndex());
- CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), sal_Int32(19), pFieldmark->GetMarkStart().nContent.GetIndex());
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), sal_Int32(20), pFieldmark->GetMarkStart().nContent.GetIndex());
}
else if (nIndex == 2) // The third one has special format
{
@@ -1329,7 +1329,7 @@ void Test::testDateFormField()
CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), OUString("2019. febr. 12."), sCurrentDate);
CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), sal_uLong(9), pFieldmark->GetMarkStart().nNode.GetIndex());
- CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), sal_Int32(38), pFieldmark->GetMarkStart().nContent.GetIndex());
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), sal_Int32(40), pFieldmark->GetMarkStart().nContent.GetIndex());
}
else if (nIndex == 3) // The fourth one has placeholder text
@@ -1339,7 +1339,7 @@ void Test::testDateFormField()
CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), OUString("[select date]"), sCurrentDate);
CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), sal_uLong(9), pFieldmark->GetMarkStart().nNode.GetIndex());
- CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), sal_Int32(59), pFieldmark->GetMarkStart().nContent.GetIndex());
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), sal_Int32(62), pFieldmark->GetMarkStart().nContent.GetIndex());
}
else // The last one is really empty
@@ -1349,7 +1349,7 @@ void Test::testDateFormField()
CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), OUString(""), sCurrentDate);
CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), sal_uLong(9), pFieldmark->GetMarkStart().nNode.GetIndex());
- CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), sal_Int32(78), pFieldmark->GetMarkStart().nContent.GetIndex());
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), sal_Int32(82), pFieldmark->GetMarkStart().nContent.GetIndex());
}
++nIndex;
@@ -1396,7 +1396,7 @@ void Test::testDateFormFieldCharacterFormatting()
CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), pFieldmark);
CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), OUString(ODF_FORMDATE), pFieldmark->GetFieldname());
CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), sal_Int32(0), pFieldmark->GetMarkStart().nContent.GetIndex());
- CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), sal_Int32(10), pFieldmark->GetMarkEnd().nContent.GetIndex());
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), sal_Int32(11), pFieldmark->GetMarkEnd().nContent.GetIndex());
// We have one date field, first half of the field has bold character weight and second part has red character color
CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), awt::FontWeight::BOLD, getProperty<float>(getRun(getParagraph(1), 2), "CharWeight"));
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx
index de66fe780b8b..c48efcb95cc0 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx
@@ -714,7 +714,7 @@ DECLARE_OOXMLEXPORT_TEST(testTdf79435_legacyInputFields, "tdf79435_legacyInputFi
CPPUNIT_ASSERT_EQUAL(OUString("currentDate"), sTmp);
xFormField
- = getProperty<uno::Reference<text::XFormField>>(getRun(getParagraph(7), 6), "Bookmark");
+ = getProperty<uno::Reference<text::XFormField>>(getRun(getParagraph(7), 7), "Bookmark");
xParameters.set(xFormField->getParameters());
xParameters->getByName("Type") >>= sTmp;
CPPUNIT_ASSERT_EQUAL(OUString("currentTime"), sTmp);
@@ -726,7 +726,7 @@ DECLARE_OOXMLEXPORT_TEST(testTdf79435_legacyInputFields, "tdf79435_legacyInputFi
CPPUNIT_ASSERT_EQUAL(OUString("number"), sTmp);
xFormField
- = getProperty<uno::Reference<text::XFormField>>(getRun(getParagraph(8), 6), "Bookmark");
+ = getProperty<uno::Reference<text::XFormField>>(getRun(getParagraph(8), 7), "Bookmark");
xParameters.set(xFormField->getParameters());
xParameters->getByName("Type") >>= sTmp;
CPPUNIT_ASSERT_EQUAL(OUString("date"), sTmp);
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
index 59556249cfb5..1b28445ca828 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
@@ -687,7 +687,7 @@ DECLARE_OOXMLEXPORT_TEST(testInvalidDateFormField, "invalid_date_form_field.docx
CPPUNIT_ASSERT_EQUAL(OUString("2019.06.34"), sCurrentDate);
CPPUNIT_ASSERT_EQUAL(sal_uLong(9), pFieldmark->GetMarkStart().nNode.GetIndex());
- CPPUNIT_ASSERT_EQUAL(sal_Int32(14), pFieldmark->GetMarkStart().nContent.GetIndex());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(15), pFieldmark->GetMarkStart().nContent.GetIndex());
}
else // The third one has wrong local
{
@@ -696,7 +696,7 @@ DECLARE_OOXMLEXPORT_TEST(testInvalidDateFormField, "invalid_date_form_field.docx
CPPUNIT_ASSERT_EQUAL(OUString("2019.06.11"), sCurrentDate);
CPPUNIT_ASSERT_EQUAL(sal_uLong(9), pFieldmark->GetMarkStart().nNode.GetIndex());
- CPPUNIT_ASSERT_EQUAL(sal_Int32(33), pFieldmark->GetMarkStart().nContent.GetIndex());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(35), pFieldmark->GetMarkStart().nContent.GetIndex());
}
++nIndex;
}
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index 1f151b363002..26b0b56eacae 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -869,7 +869,7 @@ DECLARE_OOXMLIMPORT_TEST(testTdf99135, "tdf99135.docx")
DECLARE_OOXMLIMPORT_TEST(testTdf85523, "tdf85523.docx")
{
- auto xTextField = getProperty< uno::Reference<beans::XPropertySet> >(getRun(getParagraph(1), 6), "TextField");
+ auto xTextField = getProperty< uno::Reference<beans::XPropertySet> >(getRun(getParagraph(1), 7), "TextField");
auto xText = getProperty< uno::Reference<text::XText> >(xTextField, "TextRange");
// This was "commentX": an unexpected extra char was added at the comment end.
getParagraphOfText(1, xText, "comment");
diff --git a/sw/qa/extras/ww8export/ww8export3.cxx b/sw/qa/extras/ww8export/ww8export3.cxx
index 468021617630..2e92346ea04b 100644
--- a/sw/qa/extras/ww8export/ww8export3.cxx
+++ b/sw/qa/extras/ww8export/ww8export3.cxx
@@ -125,7 +125,7 @@ DECLARE_WW8EXPORT_TEST(testTdf79435_legacyInputFields, "tdf79435_legacyInputFiel
xParameters->getByName("Type") >>= sTmp;
CPPUNIT_ASSERT_EQUAL(OUString("currentDate"), sTmp);
- xFormField = getProperty< uno::Reference<text::XFormField> >(getRun(getParagraph(7), 6), "Bookmark");
+ xFormField = getProperty< uno::Reference<text::XFormField> >(getRun(getParagraph(7), 7), "Bookmark");
xParameters.set(xFormField->getParameters());
xParameters->getByName("Type") >>= sTmp;
CPPUNIT_ASSERT_EQUAL(OUString("currentTime"), sTmp);
@@ -135,7 +135,7 @@ DECLARE_WW8EXPORT_TEST(testTdf79435_legacyInputFields, "tdf79435_legacyInputFiel
xParameters->getByName("Type") >>= sTmp;
CPPUNIT_ASSERT_EQUAL(OUString("number"), sTmp);
- xFormField = getProperty< uno::Reference<text::XFormField> >(getRun(getParagraph(8), 6), "Bookmark");
+ xFormField = getProperty< uno::Reference<text::XFormField> >(getRun(getParagraph(8), 7), "Bookmark");
xParameters.set(xFormField->getParameters());
xParameters->getByName("Type") >>= sTmp;
CPPUNIT_ASSERT_EQUAL(OUString("date"), sTmp);
diff --git a/sw/source/core/crsr/bookmrk.cxx b/sw/source/core/crsr/bookmrk.cxx
index 118942ce87f1..c74abc61935f 100644
--- a/sw/source/core/crsr/bookmrk.cxx
+++ b/sw/source/core/crsr/bookmrk.cxx
@@ -44,6 +44,74 @@ using namespace ::sw::mark;
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
+namespace sw { namespace mark
+{
+
+ SwPosition FindFieldSep(IFieldmark const& rMark)
+ {
+ SwPosition const& rStartPos(rMark.GetMarkStart());
+ SwPosition const& rEndPos(rMark.GetMarkEnd());
+ SwNodes const& rNodes(rStartPos.nNode.GetNodes());
+ sal_uLong const nStartNode(rStartPos.nNode.GetIndex());
+ sal_uLong const nEndNode(rEndPos.nNode.GetIndex());
+ int nFields(0);
+ boost::optional<SwPosition> ret;
+ for (sal_uLong n = nEndNode; nStartNode <= n; --n)
+ {
+ SwNode *const pNode(rNodes[n]);
+ if (pNode->IsTextNode())
+ {
+ SwTextNode & rTextNode(*pNode->GetTextNode());
+ sal_Int32 const nStart(n == nStartNode
+ ? rStartPos.nContent.GetIndex() + 1
+ : 0);
+ sal_Int32 const nEnd(n == nEndNode
+ // subtract 1 to ignore the end char
+ ? rEndPos.nContent.GetIndex() - 1
+ : rTextNode.Len());
+ for (sal_Int32 i = nEnd; nStart < i; --i)
+ {
+ const sal_Unicode c(rTextNode.GetText()[i - 1]);
+ switch (c)
+ {
+ case CH_TXT_ATR_FIELDSTART:
+ --nFields;
+ assert(0 <= nFields);
+ break;
+ case CH_TXT_ATR_FIELDEND:
+ ++nFields;
+ // fields in field result could happen by manual
+ // editing, although the field update deletes them
+ break;
+ case CH_TXT_ATR_FIELDSEP:
+ if (nFields == 0)
+ {
+ assert(!ret); // one per field
+ ret = SwPosition(rTextNode, i - 1);
+#ifndef DBG_UTIL
+ return *ret;
+#endif
+ }
+ break;
+ }
+ }
+ }
+ else if (pNode->IsEndNode())
+ {
+ assert(nStartNode <= pNode->StartOfSectionIndex());
+ // fieldmark cannot overlap node section
+ n = pNode->StartOfSectionIndex();
+ }
+ else
+ {
+ assert(pNode->IsNoTextNode());
+ }
+ }
+ assert(ret); // must have found it
+ return *ret;
+ }
+} } // namespace sw::mark
+
namespace
{
void lcl_FixPosition(SwPosition& rPos)
@@ -76,6 +144,8 @@ namespace
{
SwPosition const& rStart(pField->GetMarkStart());
assert(rStart.nNode.GetNode().GetTextNode()->GetText()[rStart.nContent.GetIndex()] == aStartMark); (void) rStart; (void) aStartMark;
+ SwPosition const sepPos(sw::mark::FindFieldSep(*pField));
+ assert(sepPos.nNode.GetNode().GetTextNode()->GetText()[sepPos.nContent.GetIndex()] == CH_TXT_ATR_FIELDSEP); (void) sepPos;
}
SwPosition const& rEnd(pField->GetMarkEnd());
assert(rEnd.nNode.GetNode().GetTextNode()->GetText()[rEnd.nContent.GetIndex() - 1] == aEndMark); (void) rEnd;
@@ -97,6 +167,11 @@ namespace
// do not manipulate via reference directly but call SetMarkStartPos
// which works even if start and end pos were the same
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;
+ io_pDoc->getIDocumentContentOperations().InsertString(aStartPaM, OUString(CH_TXT_ATR_FIELDSEP));
+ ++rEnd.nContent;
}
SwPosition& rEnd = pField->GetMarkEnd();
@@ -106,6 +181,7 @@ namespace
io_pDoc->getIDocumentContentOperations().InsertString(aEndPaM, OUString(aEndMark));
++rEnd.nContent;
}
+ lcl_AssertFieldMarksSet(pField, aStartMark, aEndMark);
io_pDoc->GetIDocumentUndoRedo().EndUndo(SwUndoId::UI_REPLACE, nullptr);
};
@@ -123,7 +199,10 @@ namespace
if (aEndMark != CH_TXT_ATR_FORMELEMENT)
{
(void) pStartTextNode;
+ // check this before start / end because of the +1 / -1 ...
+ SwPosition const sepPos(sw::mark::FindFieldSep(*pField));
io_pDoc->GetDocumentContentOperationsManager().DeleteDummyChar(rStart, aStartMark);
+ io_pDoc->GetDocumentContentOperationsManager().DeleteDummyChar(sepPos, CH_TXT_ATR_FIELDSEP);
}
const SwPosition& rEnd = pField->GetMarkEnd();
@@ -609,8 +688,14 @@ namespace sw { namespace mark
OUString DateFieldmark::GetContent() const
{
const SwTextNode* const pTextNode = GetMarkEnd().nNode.GetNode().GetTextNode();
- const sal_Int32 nStart(GetMarkStart().nContent.GetIndex());
+ SwPosition const sepPos(sw::mark::FindFieldSep(*this));
+#if 0
+ const sal_Int32 nStart(sepPos.nContent.GetIndex());
const sal_Int32 nEnd (GetMarkEnd().nContent.GetIndex());
+#else
+ const sal_Int32 nStart(GetMarkStart().nContent.GetIndex());
+ const sal_Int32 nEnd (sepPos.nContent.GetIndex() + 1);
+#endif
OUString sContent;
if(nStart + 1 < pTextNode->GetText().getLength() && nEnd <= pTextNode->GetText().getLength() &&
@@ -625,8 +710,14 @@ namespace sw { namespace mark
return;
const SwTextNode* const pTextNode = GetMarkEnd().nNode.GetNode().GetTextNode();
- const sal_Int32 nStart(GetMarkStart().nContent.GetIndex());
+ SwPosition const sepPos(sw::mark::FindFieldSep(*this));
+#if 0
+ const sal_Int32 nStart(sepPos.nContent.GetIndex());
const sal_Int32 nEnd (GetMarkEnd().nContent.GetIndex());
+#else
+ const sal_Int32 nStart(GetMarkStart().nContent.GetIndex());
+ const sal_Int32 nEnd (sepPos.nContent.GetIndex() + 1);
+#endif
if(nStart + 1 < pTextNode->GetText().getLength() && nEnd <= pTextNode->GetText().getLength() &&
nEnd > nStart + 2)
diff --git a/sw/source/core/inc/bookmrk.hxx b/sw/source/core/inc/bookmrk.hxx
index 4f273cd4d373..87860603aad7 100644
--- a/sw/source/core/inc/bookmrk.hxx
+++ b/sw/source/core/inc/bookmrk.hxx
@@ -336,6 +336,9 @@ namespace sw {
SwRect m_aPaintAreaStart;
SwRect m_aPaintAreaEnd;
};
+
+ /// return position of the CH_TXT_ATR_FIELDSEP for rMark
+ SwPosition FindFieldSep(IFieldmark const& rMark);
}
}
#endif