summaryrefslogtreecommitdiff
path: root/writerfilter
diff options
context:
space:
mode:
authorTamás Zolnai <tamas.zolnai@collabora.com>2019-07-02 21:09:25 +0200
committerTamás Zolnai <tamas.zolnai@collabora.com>2019-07-17 11:39:59 +0200
commit7ec865fd82237ce40a1933240a2bd62e85a8651e (patch)
tree93390586fe18b7618dfa4c51a11f8bfd8b5937a4 /writerfilter
parent82f7f044581e2651675e061db1b1ce592b44a298 (diff)
MSForms: DOCX import of text-based date field
* Before the date content control was imported as LO specific date form control, but now I changed it to be imported into the compatible text-based date field. * Also removed the things stored in the grabbag, which are useless now. * Disabled some unit tests, I'll update them for the new field in other patches. Reviewed-on: https://gerrit.libreoffice.org/75447 Reviewed-by: Tamás Zolnai <tamas.zolnai@collabora.com> Tested-by: Tamás Zolnai <tamas.zolnai@collabora.com> (cherry picked from commit df4fe4504f6d966d1d92433862dc1baf2ba008d4) Change-Id: Ide8f4b27ec6b2dbb182abb4180229736bf9c434f
Diffstat (limited to 'writerfilter')
-rw-r--r--writerfilter/source/dmapper/DomainMapper.cxx21
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.cxx4
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.hxx1
-rw-r--r--writerfilter/source/dmapper/SdtHelper.cxx112
-rw-r--r--writerfilter/source/dmapper/SdtHelper.hxx2
5 files changed, 44 insertions, 96 deletions
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index 6d0384f7cae6..b136e8f2f298 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -1018,6 +1018,8 @@ void DomainMapper::lcl_attribute(Id nName, Value & val)
if (!m_pImpl->m_pSdtHelper->getDropDownItems().empty())
m_pImpl->m_pSdtHelper->createDropDownControl();
+ else if (m_pImpl->m_pSdtHelper->validateDateFormat() && !IsInHeaderFooter())
+ m_pImpl->m_pSdtHelper->createDateContentControl();
break;
case NS_ooxml::LN_CT_SdtListItem_displayText:
// TODO handle when this is != value
@@ -2408,16 +2410,7 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, const PropertyMapPtr& rContext )
break;
case NS_ooxml::LN_CT_SdtPr_date:
{
- if (!IsInHeaderFooter())
- resolveSprmProps(*this, rSprm);
- else
- {
- OUString sName = "ooxml:CT_SdtPr_date";
- enableInteropGrabBag(sName);
- resolveSprmProps(*this, rSprm);
- m_pImpl->m_pSdtHelper->appendToInteropGrabBag(getInteropGrabBag());
- m_pImpl->disableInteropGrabBag();
- }
+ resolveSprmProps(*this, rSprm);
}
break;
case NS_ooxml::LN_CT_SdtDate_dateFormat:
@@ -3204,12 +3197,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->validateDateFormat() && !IsInHeaderFooter())
{
- /*
- * Here we assume w:sdt only contains a single text token. We need to
- * create the control early, as in Writer, it's part of the cell, but
- * in OOXML, the sdt contains the cell.
- */
- m_pImpl->m_pSdtHelper->createDateControl(sText, getInteropGrabBag());
+ // date field is imported, we don't need the corresponding date text
return;
}
else if (!m_pImpl->m_pSdtHelper->isInteropGrabBagEmpty())
@@ -3226,7 +3214,6 @@ void DomainMapper::lcl_utext(const sal_uInt8 * data_, size_t len)
m_pImpl->m_pSdtHelper->containedInInteropGrabBag("ooxml:CT_SdtPr_text") ||
m_pImpl->m_pSdtHelper->containedInInteropGrabBag("ooxml:CT_SdtPr_dataBinding") ||
m_pImpl->m_pSdtHelper->containedInInteropGrabBag("ooxml:CT_SdtPr_citation") ||
- m_pImpl->m_pSdtHelper->containedInInteropGrabBag("ooxml:CT_SdtPr_date") ||
(m_pImpl->m_pSdtHelper->containedInInteropGrabBag("ooxml:CT_SdtPr_id") &&
m_pImpl->m_pSdtHelper->getInteropGrabBagSize() == 1)) && !m_pImpl->m_pSdtHelper->isOutsideAParagraph())
{
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index b0114eac21e0..235b07e241e2 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -617,6 +617,10 @@ PropertyMapPtr DomainMapper_Impl::GetTopContextOfType(ContextType eId)
return pRet;
}
+bool DomainMapper_Impl::HasTopText() const
+{
+ return !m_aTextAppendStack.empty();
+}
uno::Reference< text::XTextAppend > const & DomainMapper_Impl::GetTopTextAppend()
{
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index ad73aa03e6dd..9c342e4492a4 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -666,6 +666,7 @@ public:
}
PropertyMapPtr GetTopContextOfType(ContextType eId);
+ bool HasTopText() const;
css::uno::Reference<css::text::XTextAppend> const & GetTopTextAppend();
FieldContextPtr const & GetTopFieldContext();
diff --git a/writerfilter/source/dmapper/SdtHelper.cxx b/writerfilter/source/dmapper/SdtHelper.cxx
index 2f68af8a491e..c76984755106 100644
--- a/writerfilter/source/dmapper/SdtHelper.cxx
+++ b/writerfilter/source/dmapper/SdtHelper.cxx
@@ -20,30 +20,11 @@
#include <vcl/svapp.hxx>
#include <unotools/datetime.hxx>
#include <comphelper/sequence.hxx>
+#include <xmloff/odffields.hxx>
#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
@@ -114,71 +95,46 @@ void SdtHelper::createDropDownControl()
bool SdtHelper::validateDateFormat()
{
- bool bRet = !m_sDate.isEmpty() || getUNODateFormat(m_sDateFormat.toString()) != -1;
- if (!bRet)
- m_sDateFormat.setLength(0);
- return bRet;
+ return !m_sDateFormat.toString().isEmpty() && !m_sLocale.toString().isEmpty();
}
-void SdtHelper::createDateControl(OUString const& rContentText, const beans::PropertyValue& rCharFormat)
+void SdtHelper::createDateContentControl()
{
- uno::Reference<awt::XControlModel> xControlModel;
- try
+ uno::Reference<text::XTextCursor> xCrsr;
+ if(m_rDM_Impl.HasTopText())
{
- xControlModel.set(m_rDM_Impl.GetTextFactory()->createInstance("com.sun.star.form.component.DateField"), uno::UNO_QUERY_THROW);
+ uno::Reference<text::XTextAppend> xTextAppend = m_rDM_Impl.GetTopTextAppend();
+ if (xTextAppend.is())
+ xCrsr = xTextAppend->createTextCursorByRange(xTextAppend->getEnd());
}
- catch (css::uno::RuntimeException&)
+ if (xCrsr.is())
{
- throw;
+ uno::Reference< uno::XInterface > xFieldInterface;
+ xFieldInterface = m_rDM_Impl.GetTextFactory()->createInstance("com.sun.star.text.FormFieldmark");
+ uno::Reference< text::XFormField > xFormField( xFieldInterface, uno::UNO_QUERY );
+ uno::Reference< text::XTextContent > xToInsert(xFormField, uno::UNO_QUERY);
+ if ( xFormField.is() && xToInsert.is() )
+ {
+ xCrsr->gotoEnd(true);
+ xToInsert->attach( uno::Reference< text::XTextRange >( xCrsr, uno::UNO_QUERY_THROW ));
+ xFormField->setFieldType(ODF_FORMDATE);
+ uno::Reference<container::XNameContainer> xNameCont = xFormField->getParameters();
+ if(xNameCont.is())
+ {
+ xNameCont->insertByName(ODF_FORMDATE_DATEFORMAT, uno::makeAny(m_sDateFormat.makeStringAndClear()));
+ xNameCont->insertByName(ODF_FORMDATE_DATEFORMAT_LANGUAGE, uno::makeAny(m_sLocale.makeStringAndClear()));
+ OUString sDate = m_sDate.makeStringAndClear();
+ if(!sDate.isEmpty())
+ {
+ // Remove time part of the full date
+ sal_Int32 nTimeSep = sDate.indexOf("T");
+ if(nTimeSep != -1)
+ sDate = sDate.copy(0, nTimeSep);
+ xNameCont->insertByName(ODF_FORMDATE_CURRENTDATE, uno::makeAny(sDate));
+ }
+ }
+ }
}
- catch (css::uno::Exception& e)
- {
- css::uno::Any a(cppu::getCaughtException());
- throw css::lang::WrappedTargetRuntimeException("wrapped " + a.getValueTypeName() + ": " + e.Message, css::uno::Reference<css::uno::XInterface>(), a);
- }
- uno::Reference<beans::XPropertySet> xPropertySet(
- xControlModel, uno::UNO_QUERY_THROW);
-
- xPropertySet->setPropertyValue("Dropdown", uno::makeAny(true));
-
- // See com/sun/star/awt/UnoControlDateFieldModel.idl, DateFormat; sadly there are no constants
- OUString sDateFormat = m_sDateFormat.makeStringAndClear();
- 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;
- util::DateTime aDateTime;
- if (utl::ISO8601parseDateTime(m_sDate.makeStringAndClear(), aDateTime))
- {
- utl::extractDate(aDateTime, aDate);
- xPropertySet->setPropertyValue("Date", uno::makeAny(aDate));
- }
- else
- xPropertySet->setPropertyValue("HelpText", uno::makeAny(rContentText.trim()));
-
- // append date format to grab bag
- comphelper::SequenceAsHashMap aGrabBag;
- aGrabBag["OriginalDate"] <<= aDate;
- aGrabBag["OriginalContent"] <<= rContentText;
- aGrabBag["DateFormat"] <<= sDateFormat;
- aGrabBag["Locale"] <<= m_sLocale.makeStringAndClear();
- aGrabBag["CharFormat"] = rCharFormat.Value;
- // merge in properties like ooxml:CT_SdtPr_alias and friends.
- aGrabBag.update(comphelper::SequenceAsHashMap(comphelper::containerToSequence(m_aGrabBag)));
- // and empty the property list, so they won't end up on the next sdt as well
- m_aGrabBag.clear();
-
- std::vector<OUString> aItems;
- createControlShape(lcl_getOptimalWidth(m_rDM_Impl.GetStyleSheetTable(), rContentText, aItems), xControlModel, aGrabBag.getAsConstPropertyValueList());
}
void SdtHelper::createControlShape(awt::Size aSize, uno::Reference<awt::XControlModel> const& xControlModel, const uno::Sequence<beans::PropertyValue>& rGrabBag)
diff --git a/writerfilter/source/dmapper/SdtHelper.hxx b/writerfilter/source/dmapper/SdtHelper.hxx
index 91f005f9d544..01abd4117adb 100644
--- a/writerfilter/source/dmapper/SdtHelper.hxx
+++ b/writerfilter/source/dmapper/SdtHelper.hxx
@@ -114,7 +114,7 @@ public:
/// Create drop-down control from w:sdt's w:dropDownList.
void createDropDownControl();
/// Create date control from w:sdt's w:date.
- void createDateControl(OUString const& rContentText, const css::beans::PropertyValue& rCharFormat);
+ void createDateContentControl();
void appendToInteropGrabBag(const css::beans::PropertyValue& rValue);
css::uno::Sequence<css::beans::PropertyValue> getInteropGrabBagAndClear();