diff options
author | Jacobo Aragunde Pérez <jaragunde@igalia.com> | 2014-03-10 17:53:44 +0100 |
---|---|---|
committer | Jacobo Aragunde Pérez <jaragunde@igalia.com> | 2014-03-10 22:36:17 +0100 |
commit | e172825b535da17c1a1d70ee1caebf43c933f39a (patch) | |
tree | 180fd5f85c2344bcb935e34c92aaeaef34ca9e1d /writerfilter | |
parent | e8e4ba0b68f717b19e4766bcaf4d14486bb11c8b (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 'writerfilter')
-rw-r--r-- | writerfilter/source/dmapper/SdtHelper.cxx | 20 | ||||
-rw-r--r-- | writerfilter/source/dmapper/SdtHelper.hxx | 2 |
2 files changed, 21 insertions, 1 deletions
diff --git a/writerfilter/source/dmapper/SdtHelper.cxx b/writerfilter/source/dmapper/SdtHelper.cxx index 63b726aad03c..29ccf477bb2b 100644 --- a/writerfilter/source/dmapper/SdtHelper.cxx +++ b/writerfilter/source/dmapper/SdtHelper.cxx @@ -12,6 +12,7 @@ #include <com/sun/star/drawing/XControlShape.hpp> #include <com/sun/star/text/VertOrientation.hpp> +#include <editeng/unoprnms.hxx> #include <vcl/outdev.hxx> #include <vcl/svapp.hxx> #include <unotools/datetime.hxx> @@ -120,12 +121,26 @@ void SdtHelper::createDateControl(OUString& rContentText) else xPropertySet->setPropertyValue("HelpText", uno::makeAny(rContentText)); + // append date format to grab bag + uno::Sequence<beans::PropertyValue> aGrabBag(3); + aGrabBag[0].Name = "OriginalDate"; + aGrabBag[0].Value = uno::makeAny(aDate); + aGrabBag[1].Name = "OriginalContent"; + aGrabBag[1].Value = uno::makeAny(rContentText); + aGrabBag[2].Name = "DateFormat"; + aGrabBag[2].Value = uno::makeAny(sDateFormat); + std::vector<OUString> aItems; - createControlShape(lcl_getOptimalWidth(m_rDM_Impl.GetStyleSheetTable(), rContentText, aItems), xControlModel); + createControlShape(lcl_getOptimalWidth(m_rDM_Impl.GetStyleSheetTable(), rContentText, aItems), xControlModel, aGrabBag); } void SdtHelper::createControlShape(awt::Size aSize, uno::Reference<awt::XControlModel> xControlModel) { + createControlShape(aSize, xControlModel, uno::Sequence<beans::PropertyValue>()); +} + +void SdtHelper::createControlShape(awt::Size aSize, uno::Reference<awt::XControlModel> xControlModel, uno::Sequence<beans::PropertyValue> rGrabBag) +{ uno::Reference<drawing::XControlShape> xControlShape(m_rDM_Impl.GetTextFactory()->createInstance("com.sun.star.drawing.ControlShape"), uno::UNO_QUERY); xControlShape->setSize(aSize); xControlShape->setControl(xControlModel); @@ -133,6 +148,9 @@ void SdtHelper::createControlShape(awt::Size aSize, uno::Reference<awt::XControl uno::Reference<beans::XPropertySet> xPropertySet(xControlShape, uno::UNO_QUERY); xPropertySet->setPropertyValue("VertOrient", uno::makeAny(text::VertOrientation::CENTER)); + if(rGrabBag.hasElements()) + xPropertySet->setPropertyValue(UNO_NAME_MISC_OBJ_INTEROPGRABBAG, uno::makeAny(rGrabBag)); + uno::Reference<text::XTextContent> xTextContent(xControlShape, uno::UNO_QUERY); m_rDM_Impl.appendTextContent(xTextContent, uno::Sequence< beans::PropertyValue >()); m_bHasElements = true; diff --git a/writerfilter/source/dmapper/SdtHelper.hxx b/writerfilter/source/dmapper/SdtHelper.hxx index e91d9b747901..8d89deabbd8c 100644 --- a/writerfilter/source/dmapper/SdtHelper.hxx +++ b/writerfilter/source/dmapper/SdtHelper.hxx @@ -60,6 +60,8 @@ class SdtHelper /// Create and append the drawing::XControlShape, containing the various models. void createControlShape(com::sun::star::awt::Size aSize, com::sun::star::uno::Reference<com::sun::star::awt::XControlModel>); + void createControlShape(com::sun::star::awt::Size aSize, com::sun::star::uno::Reference<com::sun::star::awt::XControlModel>, + com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> rGrabBag); public: SdtHelper(DomainMapper_Impl& rDM_Impl); virtual ~SdtHelper(); |