diff options
author | Tamás Zolnai <tamas.zolnai@collabora.com> | 2019-07-01 12:20:45 +0200 |
---|---|---|
committer | Tamás Zolnai <tamas.zolnai@collabora.com> | 2019-07-12 07:05:04 +0200 |
commit | 6fd9987ae650bb2f0dd40aec95662a75c9a85598 (patch) | |
tree | e8f5b24785fe41beb5805ec5293cbe299430db8d | |
parent | a50d82eca96d04b4cea1ea2c7b3610bf9ed951f0 (diff) |
MSForms: DOCX filter: handle export of empty date from control
* It's converted to date content control which is imported as text-based
date control.
* By now, we don't need to set a dummy text for empty date.
Change-Id: I29b2a72e3ae2722c1d765c4fcb9bd13052619372
Reviewed-on: https://gerrit.libreoffice.org/75458
Reviewed-by: Tamás Zolnai <tamas.zolnai@collabora.com>
Tested-by: Tamás Zolnai <tamas.zolnai@collabora.com>
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport13.cxx | 57 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.cxx | 2 |
2 files changed, 42 insertions, 17 deletions
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx index 4512bf04c4eb..3a0d1924c4c8 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx @@ -157,24 +157,51 @@ DECLARE_OOXMLEXPORT_TEST(tdf123912_protectedForm, "tdf123912_protectedForm.odt") CPPUNIT_ASSERT_EQUAL_MESSAGE("Section1 is protected", false, getProperty<bool>(xSect, "IsProtected")); } -/*DECLARE_OOXMLEXPORT_TEST(testDateControl, "empty-date-control.odt") +DECLARE_OOXMLEXPORT_TEST(testDateControl, "empty-date-control.odt") { - // Check that we did not lost the date control - uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xDraws->getCount()); - uno::Reference<drawing::XControlShape> xControl(getShape(1), uno::UNO_QUERY); - CPPUNIT_ASSERT(xControl->getControl().is()); + // Check that we exported the empty date control correctly + // Date form field is converted to date content control. + if (!mbExported) + return ; - // check XML - xmlDocPtr pXmlDoc = parseExport("word/document.xml"); - if (!pXmlDoc) - return; + SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc(); + IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess(); + + + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pMarkAccess->getAllMarksCount()); + ::sw::mark::IFieldmark* pFieldmark = dynamic_cast<::sw::mark::IFieldmark*>(*pMarkAccess->getAllMarksBegin()); + + CPPUNIT_ASSERT(pFieldmark); + CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMDATE), pFieldmark->GetFieldname()); - // We need to export date format and a dummy character (" ") for empty date control - assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:date/w:dateFormat", "val", "dd/MM/yyyy"); - assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtContent/w:r/w:t", u" "); -}*/ + 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; + } + + CPPUNIT_ASSERT_EQUAL(OUString("dd/MM/yyyy"), sDateFormat); + CPPUNIT_ASSERT_EQUAL(OUString("en-US"), sLang); + CPPUNIT_ASSERT_EQUAL(OUString(""), sCurrentDate); +} DECLARE_OOXMLEXPORT_TEST(testTdf121867, "tdf121867.odt") { diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 68d2e120bf5b..024e29182209 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -5220,8 +5220,6 @@ void DocxAttributeOutput::WritePostponedFormControl(const SdrObject* pObject) else { aContentText = xPropertySet->getPropertyValue("HelpText").get<OUString>(); - if(aContentText.isEmpty()) - aContentText = " "; // Need to write out something to have it imported by MS Word if(sDateFormat.isEmpty()) sDateFormat = "dd/MM/yyyy"; // Need to set date format even if there is no date set } |