summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--offapi/com/sun/star/text/ContentControl.idl10
-rw-r--r--sw/inc/unoprnms.hxx1
-rw-r--r--sw/source/core/txtnode/attrcontentcontrol.cxx11
-rw-r--r--sw/source/core/unocore/unocontentcontrol.cxx7
-rw-r--r--sw/source/core/unocore/unomap1.cxx1
-rw-r--r--writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx23
-rw-r--r--writerfilter/qa/cppunittests/dmapper/data/content-control-date-data-binding.docxbin0 -> 33834 bytes
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.cxx18
8 files changed, 64 insertions, 7 deletions
diff --git a/offapi/com/sun/star/text/ContentControl.idl b/offapi/com/sun/star/text/ContentControl.idl
index 8f390665c2b3..ae8a0e1a9396 100644
--- a/offapi/com/sun/star/text/ContentControl.idl
+++ b/offapi/com/sun/star/text/ContentControl.idl
@@ -100,17 +100,23 @@ service ContentControl
*/
[optional, property] boolean ComboBox;
- /** The alias: just remembered.
+ /** The alias: kind of a human-readable title / description, show up on the UI.
@since LibreOffice 7.5
*/
[optional, property] string Alias;
- /** The tag: just remembered.
+ /** The tag: similar to Alias, but is meant to be machine-readable.
@since LibreOffice 7.5
*/
[optional, property] string Tag;
+
+ /** The formatted date string, based on DateFormat, DateLanguage and CurrentDate.
+
+ @since LibreOffice 7.5
+ */
+ [optional, property, readonly] string DateString;
};
diff --git a/sw/inc/unoprnms.hxx b/sw/inc/unoprnms.hxx
index 4f952b733ad7..64fe359f7ac7 100644
--- a/sw/inc/unoprnms.hxx
+++ b/sw/inc/unoprnms.hxx
@@ -889,6 +889,7 @@
#define UNO_NAME_COLOR "Color"
#define UNO_NAME_ALIAS "Alias"
#define UNO_NAME_TAG "Tag"
+#define UNO_NAME_DATE_STRING "DateString"
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/txtnode/attrcontentcontrol.cxx b/sw/source/core/txtnode/attrcontentcontrol.cxx
index 399b954ea08f..dc451ca927e4 100644
--- a/sw/source/core/txtnode/attrcontentcontrol.cxx
+++ b/sw/source/core/txtnode/attrcontentcontrol.cxx
@@ -234,9 +234,14 @@ OUString SwContentControl::GetDateString() const
const Color* pColor = nullptr;
OUString aFormatted;
- if (!m_oSelectedDate)
+ double fSelectedDate = 0;
+ if (m_oSelectedDate)
{
- return OUString();
+ fSelectedDate = *m_oSelectedDate;
+ }
+ else
+ {
+ fSelectedDate = GetCurrentDateValue();
}
if (nFormat == NUMBERFORMAT_ENTRY_NOT_FOUND)
@@ -244,7 +249,7 @@ OUString SwContentControl::GetDateString() const
return OUString();
}
- pNumberFormatter->GetOutputString(*m_oSelectedDate, nFormat, aFormatted, &pColor, false);
+ pNumberFormatter->GetOutputString(fSelectedDate, nFormat, aFormatted, &pColor, false);
return aFormatted;
}
diff --git a/sw/source/core/unocore/unocontentcontrol.cxx b/sw/source/core/unocore/unocontentcontrol.cxx
index 994c5db7346a..0e19b7e57f41 100644
--- a/sw/source/core/unocore/unocontentcontrol.cxx
+++ b/sw/source/core/unocore/unocontentcontrol.cxx
@@ -1231,6 +1231,13 @@ uno::Any SAL_CALL SwXContentControl::getPropertyValue(const OUString& rPropertyN
aRet <<= m_pImpl->m_pContentControl->GetTag();
}
}
+ else if (rPropertyName == UNO_NAME_DATE_STRING)
+ {
+ if (!m_pImpl->m_bIsDescriptor)
+ {
+ aRet <<= m_pImpl->m_pContentControl->GetDateString();
+ }
+ }
else
{
throw beans::UnknownPropertyException();
diff --git a/sw/source/core/unocore/unomap1.cxx b/sw/source/core/unocore/unomap1.cxx
index 6f563fe69d94..05563ca34116 100644
--- a/sw/source/core/unocore/unomap1.cxx
+++ b/sw/source/core/unocore/unomap1.cxx
@@ -1046,6 +1046,7 @@ const SfxItemPropertyMapEntry* SwUnoPropertyMapProvider::GetContentControlProper
{ u"" UNO_NAME_COLOR, 0, cppu::UnoType<OUString>::get(), PROPERTY_NONE, 0 },
{ u"" UNO_NAME_ALIAS, 0, cppu::UnoType<OUString>::get(), PROPERTY_NONE, 0 },
{ u"" UNO_NAME_TAG, 0, cppu::UnoType<OUString>::get(), PROPERTY_NONE, 0 },
+ { u"" UNO_NAME_DATE_STRING, 0, cppu::UnoType<OUString>::get(), PropertyAttribute::READONLY, 0 },
{ u"", 0, css::uno::Type(), 0, 0 }
};
diff --git a/writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx b/writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx
index 3012ab8d0e2f..4c6b2b979def 100644
--- a/writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx
@@ -318,6 +318,29 @@ CPPUNIT_TEST_FIXTURE(Test, testClearingBreak)
// SwLineBreakClear::ALL
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(3), eClear);
}
+
+CPPUNIT_TEST_FIXTURE(Test, testContentControlDateDataBinding)
+{
+ // Given a document with date content control and data binding, data binding date is 2012,
+ // in-document date is 2022:
+ OUString aURL
+ = m_directories.getURLFromSrc(DATA_DIRECTORY) + "content-control-date-data-binding.docx";
+
+ // When loading that file:
+ getComponent() = loadFromDesktop(aURL);
+
+ // Then make sure that the date is from the data binding, not from document.xml:
+ uno::Reference<text::XTextDocument> xTextDocument(getComponent(), uno::UNO_QUERY);
+ uno::Reference<text::XText> xText = xTextDocument->getText();
+ uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xText, uno::UNO_QUERY);
+ uno::Reference<container::XEnumeration> xParagraphs = xParaEnumAccess->createEnumeration();
+ uno::Reference<text::XTextRange> xParagraph(xParagraphs->nextElement(), uno::UNO_QUERY);
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 4/26/2012
+ // - Actual : 4/26/2022
+ // i.e. the date was from document.xml, which is considered outdated.
+ CPPUNIT_ASSERT_EQUAL(OUString("4/26/2012"), xParagraph->getString());
+}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/qa/cppunittests/dmapper/data/content-control-date-data-binding.docx b/writerfilter/qa/cppunittests/dmapper/data/content-control-date-data-binding.docx
new file mode 100644
index 000000000000..9ad644ef642c
--- /dev/null
+++ b/writerfilter/qa/cppunittests/dmapper/data/content-control-date-data-binding.docx
Binary files differ
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 2f7cc6ca619a..ada74256cfc0 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -888,7 +888,7 @@ void DomainMapper_Impl::PopSdt()
xCursor->gotoRange(xEnd, /*bExpand=*/true);
std::optional<OUString> oData = m_pSdtHelper->getValueFromDataBinding();
- if (oData.has_value() && m_pSdtHelper->getControlType() != SdtControlType::datePicker)
+ if (oData.has_value())
{
// Data binding has a value for us, prefer that over the in-document value.
xCursor->setString(*oData);
@@ -986,6 +986,7 @@ void DomainMapper_Impl::PopSdt()
xContentControlProps->setPropertyValue("Picture", uno::Any(true));
}
+ bool bDateFromDataBinding = false;
if (m_pSdtHelper->getControlType() == SdtControlType::datePicker)
{
xContentControlProps->setPropertyValue("Date", uno::Any(true));
@@ -994,8 +995,14 @@ void DomainMapper_Impl::PopSdt()
uno::Any(aDateFormat.replaceAll("'", "\"")));
xContentControlProps->setPropertyValue("DateLanguage",
uno::Any(m_pSdtHelper->getLocale().makeStringAndClear()));
+ OUString aCurrentDate = m_pSdtHelper->getDate().makeStringAndClear();
+ if (oData.has_value())
+ {
+ aCurrentDate = *oData;
+ bDateFromDataBinding = true;
+ }
xContentControlProps->setPropertyValue("CurrentDate",
- uno::Any(m_pSdtHelper->getDate().makeStringAndClear()));
+ uno::Any(aCurrentDate));
}
if (m_pSdtHelper->getControlType() == SdtControlType::plainText)
@@ -1005,6 +1012,13 @@ void DomainMapper_Impl::PopSdt()
xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true);
+ if (bDateFromDataBinding)
+ {
+ OUString aDateString;
+ xContentControlProps->getPropertyValue("DateString") >>= aDateString;
+ xCursor->setString(aDateString);
+ }
+
m_pSdtHelper->clear();
}