summaryrefslogtreecommitdiff
path: root/writerfilter
diff options
context:
space:
mode:
authorJustin Luth <justin_luth@sil.org>2022-03-12 11:11:01 +0200
committerMiklos Vajna <vmiklos@collabora.com>2022-03-25 13:48:12 +0100
commitc4cb1d1dd581a5f120d9cf8b1d4274ec38f3eabe (patch)
tree084536944b7ae889d555077e4a3f71ed75bc863a /writerfilter
parent1fdd27398006baa03c2e45b4ca2412b74ef7ee62 (diff)
tdf#147861 writerfilter: use GetFieldResult, not current DocProperty
Import DOCX and RTF DocProperty fields as "fixed" if the displayed text does not match the File - Properties - Custom variable's content. Otherwise LO will automatically update the field and show the wrong contents (because MS Word requires the user to manually refresh via F9). Change-Id: Id5d3d0794e81b13465c5e824f1e994f563e62c1c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131415 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'writerfilter')
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.cxx25
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.hxx4
2 files changed, 28 insertions, 1 deletions
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index a4d59a8b7fdb..a3d6a4f69498 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -4792,6 +4792,11 @@ void FieldContext::SetTextField(uno::Reference<text::XTextField> const& xTextFie
m_xTextField = xTextField;
}
+void FieldContext::CacheVariableValue(const uno::Any& rAny)
+{
+ rAny >>= m_sVariableValue;
+}
+
void FieldContext::AppendCommand(std::u16string_view rPart)
{
m_sCommand += rPart;
@@ -5425,6 +5430,9 @@ void DomainMapper_Impl::handleAuthor
}
}
}
+ else
+ pContext->CacheVariableValue(xUserDefinedProps->getPropertyValue(rFirstParam));
+
OUString sServiceName("com.sun.star.text.TextField.");
bool bIsCustomField = false;
if(sFieldServiceName.isEmpty())
@@ -7044,7 +7052,22 @@ void DomainMapper_Impl::SetFieldResult(OUString const& rResult)
getPropertyName(bHasContent && sValue.isEmpty()? PROP_CONTENT : PROP_CURRENT_PRESENTATION),
uno::makeAny( rResult ));
- if (xServiceInfo->supportsService(
+ // LO always automatically updates a DocInfo field from the File-Properties-Custom Prop
+ // while MS Word requires the user to manually refresh the field (with F9).
+ // In other words, Word lets the field to be out of sync with the controlling variable.
+ // Marking as FIXEDFLD solves the automatic replacement problem, but of course prevents
+ // Writer from making any changes, even on an F9 refresh.
+ OUString sVariable = pContext->GetVariableValue();
+ if (rResult.getLength() != sVariable.getLength())
+ {
+ sal_Int32 nLen = sVariable.indexOf('\x0');
+ if (nLen >= 0)
+ sVariable = sVariable.copy(0, nLen);
+ }
+ bool bCustomFixedField = rResult != sVariable &&
+ xServiceInfo->supportsService("com.sun.star.text.TextField.DocInfo.Custom");
+
+ if (bCustomFixedField || xServiceInfo->supportsService(
"com.sun.star.text.TextField.DocInfo.CreateDateTime"))
{
// Creation time is const, don't try to update it.
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index 869d0cdf1ece..f6c3f637de5d 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -176,6 +176,7 @@ class FieldContext : public virtual SvRefBase
OUString m_sCommand;
OUString m_sResult;
+ OUString m_sVariableValue;
std::optional<FieldId> m_eFieldId;
bool m_bFieldLocked;
@@ -211,6 +212,9 @@ public:
void AppendResult(std::u16string_view rResult) { m_sResult += rResult; }
const OUString& GetResult() const { return m_sResult; }
+ void CacheVariableValue(const css::uno::Any& rAny);
+ const OUString& GetVariableValue() { return m_sVariableValue; }
+
void SetCommandCompleted() { m_bFieldCommandCompleted = true; }
bool IsCommandCompleted() const { return m_bFieldCommandCompleted; }