summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-10-26 10:03:04 +0200
committerMiklos Vajna <vmiklos@collabora.com>2022-10-26 15:34:30 +0200
commit23272c0cfe01d0719572bc80733833f6f8c09f24 (patch)
tree7c20093a1d6a8b524dfb6587c47ca90147601fd2 /sw
parent3005bd3793e76f8c010a9e774cfb508de406a3d1 (diff)
sw content controls: enable data binding for date
The document had a 2022 date in document.xml, but had a 2012 date in data binding. Writer used to show 2022, while Word picks 2012. Data binding for dates were disabled in commit de90c192cb8f1f03a4028493d8bfe9a127a76b2a (sw content controls, plain text: enable DOCX filter with data binding, 2022-09-19), because the formatting of those date timestamps were missing, so it was better to just not update them from data binding, temporarily. Fix the problem by adding a new read-only DateString property on SwXContentControl, this way the import filter can set not only the timestamp but the formatted date as well. This shares the SwContentControl::GetDateString() code with the UI, which already had the need in the past to turn a timestamp into a date string, based on a provided language and date format. (cherry picked from commit 58002ab85d992c7ac44d8bb4d135246b67aa5cc7) Conflicts: sw/source/core/unocore/unomap1.cxx Change-Id: I842a9483a675f895129a9854caec347be6b6b84e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141867 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw')
-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
4 files changed, 17 insertions, 3 deletions
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 }
};