summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorJacobo Aragunde Pérez <jaragunde@igalia.com>2014-03-10 17:53:44 +0100
committerJacobo Aragunde Pérez <jaragunde@igalia.com>2014-03-10 22:36:17 +0100
commite172825b535da17c1a1d70ee1caebf43c933f39a (patch)
tree180fd5f85c2344bcb935e34c92aaeaef34ca9e1d /sw
parente8e4ba0b68f717b19e4766bcaf4d14486bb11c8b (diff)
ooxml: preserve dateFormat for unchanged date controls
When saving a date control in a docx document, we were overwriting its date format with "dd/MM/yyyy" because it's tricky to support all the possible combinations. Nonetheless, there is no need to overwrite it if the date in the control remains unchanged during edition. We preserve the original date of the control, its date format and the formatted date string on import, and we compare the date in the control with the original one on export to check if we can write the old values or we have to re-generate them. Only in case the date has changed the format will be reset to "dd/MM/yyyy". We had to add an InteropGrabBag field to the XControlShape because it didn't have one, unlike other shapes. Unit tests were modified to check that the dateFormat field is preserved unchanged. Change-Id: I01e5c990e90ff190b5a6d7ea3853e049ff24ef0a
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/ooxmlexport/data/date-control.docxbin21367 -> 20936 bytes
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport.cxx3
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.cxx34
3 files changed, 34 insertions, 3 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/date-control.docx b/sw/qa/extras/ooxmlexport/data/date-control.docx
index 0563d56aac35..fdf229913702 100644
--- a/sw/qa/extras/ooxmlexport/data/date-control.docx
+++ b/sw/qa/extras/ooxmlexport/data/date-control.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index 80189af85323..957dfbe9430d 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -2963,7 +2963,8 @@ DECLARE_OOXMLEXPORT_TEST(testDateControl, "date-control.docx")
if (!pXmlDoc)
return;
assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:date", "fullDate", "2014-03-05T00:00:00Z");
- assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtContent/w:r/w:t", "05/03/2014");
+ assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:date/w:dateFormat", "val", "dddd, dd' de 'MMMM' de 'yyyy");
+ assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtContent/w:r/w:t", "miércoles, 05 de marzo de 2014");
// check imported control
uno::Reference<drawing::XControlShape> xControl(getShape(1), uno::UNO_QUERY);
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 294927108bc3..a233c2317adc 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -3599,6 +3599,25 @@ void DocxAttributeOutput::WritePostponedFormControl(const SdrObject* pObject)
{
// gather component properties
+ Date aOriginalDate(Date::EMPTY);
+ OUString sOriginalContent, sDateFormat;
+ uno::Sequence<beans::PropertyValue> aGrabBag;
+ uno::Reference<beans::XPropertySet> xShapePropertySet(pFormObj->getUnoShape(), uno::UNO_QUERY);
+ if (xShapePropertySet->getPropertyValue(UNO_NAME_MISC_OBJ_INTEROPGRABBAG) >>= aGrabBag)
+ for (sal_Int32 i=0; i < aGrabBag.getLength(); ++i)
+ if (aGrabBag[i].Name == "DateFormat")
+ aGrabBag[i].Value >>= sDateFormat;
+ else if (aGrabBag[i].Name == "OriginalContent")
+ aGrabBag[i].Value >>= sOriginalContent;
+ else if (aGrabBag[i].Name == "OriginalDate")
+ {
+ css::util::Date aUNODate;
+ aGrabBag[i].Value >>= aUNODate;
+ aOriginalDate.SetDay(aUNODate.Day);
+ aOriginalDate.SetMonth(aUNODate.Month);
+ aOriginalDate.SetYear(aUNODate.Year);
+ }
+
uno::Reference<beans::XPropertySet> xPropertySet(xControlModel, uno::UNO_QUERY);
OString sDate;
@@ -3610,7 +3629,17 @@ void DocxAttributeOutput::WritePostponedFormControl(const SdrObject* pObject)
bHasDate = true;
Date aDate(aUNODate.Day, aUNODate.Month, aUNODate.Year);
sDate = DateToOString(aDate);
- aContentText = OUString::createFromAscii(DateToDDMMYYYYOString(aDate).getStr());
+
+ if (aOriginalDate == aDate)
+ {
+ aContentText = sOriginalContent;
+ // sDateFormat was extracted from the grab bag
+ }
+ else
+ {
+ aContentText = OUString::createFromAscii(DateToDDMMYYYYOString(aDate).getStr());
+ sDateFormat = "dd/MM/yyyy";
+ }
}
else
aContentText = xPropertySet->getPropertyValue("HelpText").get<OUString>();
@@ -3628,7 +3657,8 @@ void DocxAttributeOutput::WritePostponedFormControl(const SdrObject* pObject)
m_pSerializer->startElementNS(XML_w, XML_date, FSEND);
m_pSerializer->singleElementNS(XML_w, XML_dateFormat,
- FSNS(XML_w, XML_val), "dd/MM/yyyy", //TODO: hardwired
+ FSNS(XML_w, XML_val),
+ rtl::OUStringToOString( sDateFormat, RTL_TEXTENCODING_UTF8 ).getStr(),
FSEND);
m_pSerializer->singleElementNS(XML_w, XML_lid,
FSNS(XML_w, XML_val), "en-US", //TODO: hardwired