summaryrefslogtreecommitdiff
path: root/writerfilter
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2018-11-12 23:01:12 +0100
committerMiklos Vajna <vmiklos@collabora.com>2018-11-13 09:02:40 +0100
commit3583f7a1256c901199574c8373443038e28813f0 (patch)
tree23999c317424583a7c574feaa8f3575d944da881 /writerfilter
parent630b5db9a10cd49d24d5e563374bd68f1fe670f5 (diff)
tdf#121203 DOCX import: fix loss of free-form text in date control
Date SDT from DOCX is imported as date control since commit 3ec2d26dc2017ac4a27483febfc63328632f352d (bnc#779630 initial DOCX import of w:sdt's w:date, 2013-04-30). One detail I missed there is our date control is strict: it doesn't allow free-form text. However, DOCX date SDT has an optional ISO date, but the actual value can be free-form text. This means that importing free-form text without an ISO date is lost on import. Fix the data loss by restricting the creation of the date control: only do this if we recognize the date format or in case we have an ISO date. Otherwise just show the free-form text to avoid data loss. Change-Id: I8125bdc749954a6a1c496de74b6682744adb7680 Reviewed-on: https://gerrit.libreoffice.org/63311 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'writerfilter')
-rw-r--r--writerfilter/source/dmapper/DomainMapper.cxx2
-rw-r--r--writerfilter/source/dmapper/SdtHelper.cxx41
-rw-r--r--writerfilter/source/dmapper/SdtHelper.hxx4
3 files changed, 41 insertions, 6 deletions
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index 16158a46fabf..5e9bed49044a 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -3202,7 +3202,7 @@ void DomainMapper::lcl_utext(const sal_uInt8 * data_, size_t len)
}
}
// Form controls are not allowed in headers / footers; see sw::DocumentContentOperationsManager::InsertDrawObj()
- else if (!m_pImpl->m_pSdtHelper->getDateFormat().isEmpty() && !IsInHeaderFooter())
+ else if (m_pImpl->m_pSdtHelper->validateDateFormat() && !IsInHeaderFooter())
{
/*
* Here we assume w:sdt only contains a single text token. We need to
diff --git a/writerfilter/source/dmapper/SdtHelper.cxx b/writerfilter/source/dmapper/SdtHelper.cxx
index f8d0200a1074..cccebf1d260c 100644
--- a/writerfilter/source/dmapper/SdtHelper.cxx
+++ b/writerfilter/source/dmapper/SdtHelper.cxx
@@ -24,6 +24,26 @@
#include "DomainMapper_Impl.hxx"
#include "StyleSheetTable.hxx"
+namespace
+{
+/// Maps OOXML <w:dateFormat> values to UNO date format values.
+sal_Int16 getUNODateFormat(const OUString& rDateFormat)
+{
+ // See com/sun/star/awt/UnoControlDateFieldModel.idl, DateFormat; sadly
+ // there are no constants.
+ sal_Int16 nDateFormat = -1;
+
+ if (rDateFormat == "M/d/yyyy" || rDateFormat == "M.d.yyyy")
+ // MMDDYYYY
+ nDateFormat = 8;
+ else if (rDateFormat == "dd/MM/yyyy")
+ // DDMMYYYY
+ nDateFormat = 7;
+
+ return nDateFormat;
+}
+}
+
namespace writerfilter
{
namespace dmapper
@@ -92,6 +112,14 @@ void SdtHelper::createDropDownControl()
m_aDropDownItems.clear();
}
+bool SdtHelper::validateDateFormat()
+{
+ bool bRet = !m_sDate.isEmpty() || getUNODateFormat(m_sDateFormat.toString()) != -1;
+ if (!bRet)
+ m_sDateFormat.setLength(0);
+ return bRet;
+}
+
void SdtHelper::createDateControl(OUString const& rContentText, const beans::PropertyValue& rCharFormat)
{
uno::Reference<awt::XControlModel> xControlModel;
@@ -114,14 +142,17 @@ void SdtHelper::createDateControl(OUString const& rContentText, const beans::Pro
xPropertySet->setPropertyValue("Dropdown", uno::makeAny(true));
// See com/sun/star/awt/UnoControlDateFieldModel.idl, DateFormat; sadly there are no constants
- sal_Int16 nDateFormat = 0;
OUString sDateFormat = m_sDateFormat.makeStringAndClear();
- if (sDateFormat == "M/d/yyyy" || sDateFormat == "M.d.yyyy")
- // Approximate with MM.dd.yyy
- nDateFormat = 8;
- else
+ sal_Int16 nDateFormat = getUNODateFormat(sDateFormat);
+ if (nDateFormat == -1)
+ {
// Set default format, so at least the date picker is created.
SAL_WARN("writerfilter", "unhandled w:dateFormat value");
+ if (m_sDate.isEmpty())
+ return;
+ else
+ nDateFormat = 0;
+ }
xPropertySet->setPropertyValue("DateFormat", uno::makeAny(nDateFormat));
util::Date aDate;
diff --git a/writerfilter/source/dmapper/SdtHelper.hxx b/writerfilter/source/dmapper/SdtHelper.hxx
index 48fa71d73c41..91f005f9d544 100644
--- a/writerfilter/source/dmapper/SdtHelper.hxx
+++ b/writerfilter/source/dmapper/SdtHelper.hxx
@@ -87,6 +87,10 @@ public:
{
return m_sDateFormat;
}
+
+ /// Decides if we have enough information to create a date control.
+ bool validateDateFormat();
+
OUStringBuffer& getLocale()
{
return m_sLocale;