summaryrefslogtreecommitdiff
path: root/writerfilter
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-09-19 10:01:36 +0200
committerMiklos Vajna <vmiklos@collabora.com>2022-09-19 11:31:05 +0200
commitde90c192cb8f1f03a4028493d8bfe9a127a76b2a (patch)
tree3bc07cac0f62f8d58a3301d1e1cb073926e03b05 /writerfilter
parentb20a64ce05ebf3720dd2d10ccd384020803c2ff2 (diff)
sw content controls, plain text: enable DOCX filter with data binding
- writerfilter/ had explicit code to not map plain text SDT to Writer content controls if it has data bindings specified, lift this limitation and set the value of content control from data binding, like Word does and Writer did it for input fields since b5c616d10bff3213840d4893d13b4493de71fa56 (tdf#104823: support for sdt plain text fields, 2021-11-24) - call DocxExport::AddSdtData() on the export side to do the opposite on export - give up on the idea to export content controls to DOCX by finding the text attribute in SwWW8AttrIter::OutAttrWithRange(): this needs buffering in both directions (need to start the SDT before the start of the run, need to end it after the end of the run), and solving this using marks and merges at a fast-serializer level looks like hacks on top of hacks. To be more specific, CppunitTest_sw_ooxmlexport7's testSdtAndShapeOverlapping seems to be very hard to fix with this design - instead, give not only the start position but also the length of the run to DocxAttributeOutput::EndRun(), which has random access to the doc model and can look up if there is a content control start or end that needs writing at the current position of the XML output, without any buffering, which also means less code - adapt CppunitTest_sw_ooxmlfieldexport's testSdtBeforeField, which didn't like the empty run at the start of content controls, which seems to be harmless otherwise - fix CppunitTest_sw_ooxmlfieldexport CPPUNIT_TEST_NAME=testSdtDateDuplicate by disabling the "set content control value from data binding" logic for date pickers because that logic in writerfilter/ sets the value as-is and it has to consider the requested date format before this can be enabled As a side effect, this gives PDF export for plain text SDTs, even if they have data binding set. CppunitTest_sw_ooxmlfieldexport's testTdf104823 is now updated to ensure that we import such SDTs as Writer content controls. Change-Id: I749a845b5a25454c51066b8ded892682f523b6b4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140134 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'writerfilter')
-rw-r--r--writerfilter/source/dmapper/DomainMapper.cxx15
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.cxx8
-rw-r--r--writerfilter/source/dmapper/SdtHelper.hxx4
3 files changed, 14 insertions, 13 deletions
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index 9fa547675c8a..9286f6261287 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -1111,11 +1111,7 @@ void DomainMapper::lcl_attribute(Id nName, Value & val)
if (m_pImpl->m_pSdtHelper->getControlType() == SdtControlType::plainText)
{
- // The plain text && data binding case needs more work before it can be enabled.
- if (m_pImpl->m_pSdtHelper->GetDataBindingPrefixMapping().isEmpty())
- {
- m_pImpl->PopSdt();
- }
+ m_pImpl->PopSdt();
}
}
@@ -2781,11 +2777,8 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, const PropertyMapPtr& rContext )
m_pImpl->m_pSdtHelper->setControlType(SdtControlType::plainText);
if (m_pImpl->m_pSdtHelper->GetSdtType() == NS_ooxml::LN_CT_SdtRun_sdtContent)
{
- if (m_pImpl->m_pSdtHelper->GetDataBindingPrefixMapping().isEmpty())
- {
- m_pImpl->m_pSdtHelper->getInteropGrabBagAndClear();
- break;
- }
+ m_pImpl->m_pSdtHelper->getInteropGrabBagAndClear();
+ break;
}
enableInteropGrabBag("ooxml:CT_SdtPr_text");
writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
@@ -3786,7 +3779,7 @@ void DomainMapper::lcl_utext(const sal_uInt8 * data_, size_t len)
return;
}
}
- else if ((m_pImpl->m_pSdtHelper->GetSdtType() != NS_ooxml::LN_CT_SdtRun_sdtContent || !m_pImpl->m_pSdtHelper->GetDataBindingPrefixMapping().isEmpty()) && m_pImpl->m_pSdtHelper->getControlType() == SdtControlType::plainText)
+ else if (m_pImpl->m_pSdtHelper->GetSdtType() != NS_ooxml::LN_CT_SdtRun_sdtContent && m_pImpl->m_pSdtHelper->getControlType() == SdtControlType::plainText)
{
m_pImpl->m_pSdtHelper->getSdtTexts().append(sText);
if (bNewLine)
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 8966e096dd59..22c75bfb7800 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -892,6 +892,14 @@ void DomainMapper_Impl::PopSdt()
xCursor->goRight(1, /*bExpand=*/false);
}
xCursor->gotoRange(xEnd, /*bExpand=*/true);
+
+ std::optional<OUString> oData = m_pSdtHelper->getValueFromDataBinding();
+ if (oData.has_value() && m_pSdtHelper->getControlType() != SdtControlType::datePicker)
+ {
+ // Data binding has a value for us, prefer that over the in-document value.
+ xCursor->setString(*oData);
+ }
+
uno::Reference<text::XTextContent> xContentControl(
m_xTextFactory->createInstance("com.sun.star.text.ContentControl"), uno::UNO_QUERY);
uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY);
diff --git a/writerfilter/source/dmapper/SdtHelper.hxx b/writerfilter/source/dmapper/SdtHelper.hxx
index 7be862cd45f4..1db71cdc9a92 100644
--- a/writerfilter/source/dmapper/SdtHelper.hxx
+++ b/writerfilter/source/dmapper/SdtHelper.hxx
@@ -116,8 +116,6 @@ class SdtHelper final : public virtual SvRefBase
css::uno::Reference<css::awt::XControlModel> const& xControlModel,
const css::uno::Sequence<css::beans::PropertyValue>& rGrabBag);
- std::optional<OUString> getValueFromDataBinding();
-
void loadPropertiesXMLs();
/// <w:placeholder>'s <w:docPart w:val="...">.
@@ -204,6 +202,8 @@ public:
void SetColor(const OUString& rColor);
const OUString& GetColor() const;
+
+ std::optional<OUString> getValueFromDataBinding();
};
} // namespace writerfilter::dmapper