summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamás Zolnai <tamas.zolnai@collabora.com>2019-06-21 17:56:30 +0200
committerTamás Zolnai <tamas.zolnai@collabora.com>2019-07-17 11:39:59 +0200
commit4c63e35fc028e2c5b6a8e7bd524aa94afd76405f (patch)
tree94bab01091b92672059ddf024c17163615b36e50
parent54c9f435270fe9df0efb1c2cf70caf901a3c6827 (diff)
MSForms: ODF import / export of text-based date field
Reviewed-on: https://gerrit.libreoffice.org/75445 Tested-by: Jenkins Reviewed-by: Tamás Zolnai <tamas.zolnai@collabora.com> (cherry picked from commit 46a59d10dbbe3cb9bb9962df93e5a79a5318dcfd) Change-Id: Ib535f1ce065a7f298fcccf95e82d1ffab4d1e1e2
-rw-r--r--sw/qa/extras/globalfilter/data/date_form_field.odtbin0 -> 8652 bytes
-rw-r--r--sw/qa/extras/globalfilter/globalfilter.cxx97
-rw-r--r--sw/source/core/doc/docbm.cxx6
-rw-r--r--xmloff/source/text/XMLTextMarkImportContext.cxx5
4 files changed, 104 insertions, 4 deletions
diff --git a/sw/qa/extras/globalfilter/data/date_form_field.odt b/sw/qa/extras/globalfilter/data/date_form_field.odt
new file mode 100644
index 000000000000..8e15793c2d59
--- /dev/null
+++ b/sw/qa/extras/globalfilter/data/date_form_field.odt
Binary files differ
diff --git a/sw/qa/extras/globalfilter/globalfilter.cxx b/sw/qa/extras/globalfilter/globalfilter.cxx
index fd55bc0dc747..a0230d7e7040 100644
--- a/sw/qa/extras/globalfilter/globalfilter.cxx
+++ b/sw/qa/extras/globalfilter/globalfilter.cxx
@@ -52,6 +52,7 @@ public:
void testTextFormField();
void testCheckBoxFormField();
void testDropDownFormField();
+ void testDateFormField();
CPPUNIT_TEST_SUITE(Test);
CPPUNIT_TEST(testEmbeddedGraphicRoundtrip);
@@ -70,6 +71,7 @@ public:
CPPUNIT_TEST(testTextFormField);
CPPUNIT_TEST(testCheckBoxFormField);
CPPUNIT_TEST(testDropDownFormField);
+ CPPUNIT_TEST(testDateFormField);
CPPUNIT_TEST_SUITE_END();
};
@@ -1240,6 +1242,101 @@ void Test::testDropDownFormField()
}
}
+void Test::testDateFormField()
+{
+ const OUString aFilterNames[] = {
+ "writer8",
+ //"MS Word 97",
+ //"Office Open XML Text",
+ };
+
+ for (const OUString& rFilterName : aFilterNames)
+ {
+ if (mxComponent.is())
+ mxComponent->dispose();
+ mxComponent = loadFromDesktop(m_directories.getURLFromSrc("/sw/qa/extras/globalfilter/data/date_form_field.odt"), "com.sun.star.text.TextDocument");
+
+ const OString sFailedMessage = OString("Failed on filter: ") + rFilterName.toUtf8();
+
+ // Export the document and import again for a check
+ uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
+ utl::MediaDescriptor aMediaDescriptor;
+ aMediaDescriptor["FilterName"] <<= rFilterName;
+ utl::TempFile aTempFile;
+ aTempFile.EnableKillingFile();
+ xStorable->storeToURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
+ uno::Reference< lang::XComponent > xComponent(xStorable, uno::UNO_QUERY);
+ xComponent->dispose();
+ mxComponent = loadFromDesktop(aTempFile.GetURL(), "com.sun.star.text.TextDocument");
+
+ // Check the document after round trip
+ SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
+ CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), pTextDoc);
+ SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+ IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
+
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), sal_Int32(3), pMarkAccess->getAllMarksCount());
+
+ int nIndex = 0;
+ for(auto aIter = pMarkAccess->getAllMarksBegin(); aIter != pMarkAccess->getAllMarksEnd(); ++aIter)
+ {
+ ::sw::mark::IFieldmark* pFieldmark = dynamic_cast<::sw::mark::IFieldmark*>(aIter->get());
+
+ if(!pFieldmark)
+ continue;
+
+ CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), pFieldmark);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), OUString(ODF_FORMDATE), pFieldmark->GetFieldname());
+
+ // Check date form field's parameters.
+ const sw::mark::IFieldmark::parameter_map_t* const pParameters = pFieldmark->GetParameters();
+ OUString sDateFormat;
+ auto pResult = pParameters->find(ODF_FORMDATE_DATEFORMAT);
+ if (pResult != pParameters->end())
+ {
+ pResult->second >>= sDateFormat;
+ }
+
+ OUString sLang;
+ pResult = pParameters->find(ODF_FORMDATE_DATEFORMAT_LANGUAGE);
+ if (pResult != pParameters->end())
+ {
+ pResult->second >>= sLang;
+ }
+
+ OUString sCurrentDate;
+ pResult = pParameters->find(ODF_FORMDATE_CURRENTDATE);
+ if (pResult != pParameters->end())
+ {
+ pResult->second >>= sCurrentDate;
+ }
+
+ // The first one is empty
+ if(nIndex == 0)
+ {
+
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), OUString("MM/DD/YY"), sDateFormat);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), OUString("en-US"), sLang);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), OUString(""), sCurrentDate);
+ }
+ else if (nIndex == 1) // The second has the default format
+ {
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), OUString("MM/DD/YY"), sDateFormat);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), OUString("en-US"), sLang);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), OUString("2019-06-12"), sCurrentDate);
+ }
+ else // The third one has special format
+ {
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), OUString("[NatNum12 MMMM=abbreviation]YYYY\". \"MMMM D."), sDateFormat);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), OUString("hu-HU"), sLang);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), OUString("2019-06-11"), sCurrentDate);
+ }
+ ++nIndex;
+ }
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), int(3), nIndex);
+ }
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx
index af1524302e43..3c000747d512 100644
--- a/sw/source/core/doc/docbm.cxx
+++ b/sw/source/core/doc/docbm.cxx
@@ -1125,17 +1125,17 @@ namespace sw { namespace mark
bool bActualChange = false;
if(rNewType == ODF_FORMDROPDOWN)
{
- if (dynamic_cast<::sw::mark::CheckboxFieldmark*>(pFieldmark))
+ if (!dynamic_cast<::sw::mark::DropDownFieldmark*>(pFieldmark))
bActualChange = true;
}
else if(rNewType == ODF_FORMCHECKBOX)
{
- if (dynamic_cast<::sw::mark::DropDownFieldmark*>(pFieldmark))
+ if (!dynamic_cast<::sw::mark::CheckboxFieldmark*>(pFieldmark))
bActualChange = true;
}
else if(rNewType == ODF_FORMDATE)
{
- if (dynamic_cast<::sw::mark::DateFieldmark*>(pFieldmark))
+ if (!dynamic_cast<::sw::mark::DateFieldmark*>(pFieldmark))
bActualChange = true;
}
diff --git a/xmloff/source/text/XMLTextMarkImportContext.cxx b/xmloff/source/text/XMLTextMarkImportContext.cxx
index ea00d0aae2cd..a2d6294c0502 100644
--- a/xmloff/source/text/XMLTextMarkImportContext.cxx
+++ b/xmloff/source/text/XMLTextMarkImportContext.cxx
@@ -136,6 +136,8 @@ static const char *lcl_getFormFieldmarkName(OUString const &name)
else if (name == ODF_FORMDROPDOWN ||
name == "ecma.office-open-xml.field.FORMDROPDOWN")
return ODF_FORMDROPDOWN;
+ else if (name == ODF_FORMDATE)
+ return ODF_FORMDATE;
else
return nullptr;
}
@@ -329,7 +331,8 @@ void XMLTextMarkImportContext::EndElement()
OUString const type(m_rHelper.getCurrentFieldType());
fieldmarkTypeName = lcl_getFieldmarkName(type);
if (fieldmarkTypeName == ODF_FORMCHECKBOX ||
- fieldmarkTypeName == ODF_FORMDROPDOWN)
+ fieldmarkTypeName == ODF_FORMDROPDOWN ||
+ fieldmarkTypeName == ODF_FORMDATE)
{ // sw can't handle checkbox with start+end
SAL_INFO("xmloff.text", "invalid fieldmark-start/fieldmark-end ignored");
isInvalid = true;