summaryrefslogtreecommitdiff
path: root/writerfilter/source/dmapper
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2020-11-12 11:53:22 +0100
committerMiklos Vajna <vmiklos@collabora.com>2020-11-12 18:49:54 +0100
commit6b15b6a6ab294e1d4a3a4bfb5ac81630aa08015c (patch)
treed0f70bebfb8d933521def48f80221bcd29cd512c /writerfilter/source/dmapper
parente4dbf6f6b9fde8d2e4843028c309d62245d78031 (diff)
DOCX import: fix lost cached result inside an IF field
This builds on top of commit d09336fbdceaafd9320466b660a2b32a07dcc16a (tdf#125038 DOCX import: fix lost MERGEFIELD result inside an IF field, 2019-10-31), and extends it for more cases. We know that DOCVARIABLE, FORMULA and IF fields inside an IF fields is not something Writer is capable of, so make sure we keep the cached result. Change-Id: I20004f97c2073309c33594e5da6f8ba89ba278ba Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105639 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'writerfilter/source/dmapper')
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.cxx46
1 files changed, 33 insertions, 13 deletions
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 08fe93e46a42..0a7ae26d937e 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -205,7 +205,14 @@ static FieldContextPtr GetParentFieldContext(const std::deque<FieldContextPtr>&
/// Decides if the pInner field inside pOuter is allowed in Writer core, depending on their type.
static bool IsFieldNestingAllowed(const FieldContextPtr& pOuter, const FieldContextPtr& pInner)
{
- if (!pOuter->GetFieldId())
+ std::optional<FieldId> oOuterFieldId = pOuter->GetFieldId();
+ if (!oOuterFieldId && pOuter->GetCommand().startsWith(" IF "))
+ {
+ // This will be FIELD_IF once the command is closed.
+ oOuterFieldId = FIELD_IF;
+ }
+
+ if (!oOuterFieldId)
{
return true;
}
@@ -215,12 +222,15 @@ static bool IsFieldNestingAllowed(const FieldContextPtr& pOuter, const FieldCont
return true;
}
- switch (*pOuter->GetFieldId())
+ switch (*oOuterFieldId)
{
case FIELD_IF:
{
switch (*pInner->GetFieldId())
{
+ case FIELD_DOCVARIABLE:
+ case FIELD_FORMULA:
+ case FIELD_IF:
case FIELD_MERGEFIELD:
{
return false;
@@ -5404,12 +5414,16 @@ void DomainMapper_Impl::CloseFieldCommand()
break;
case FIELD_DOCVARIABLE :
{
- //create a user field and type
- uno::Reference< beans::XPropertySet > xMaster =
- FindOrCreateFieldMaster("com.sun.star.text.FieldMaster.User", sFirstParam);
- uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW );
- xDependentField->attachTextFieldMaster( xMaster );
- m_bSetUserFieldContent = true;
+ if (bCreateField)
+ {
+ //create a user field and type
+ uno::Reference<beans::XPropertySet> xMaster = FindOrCreateFieldMaster(
+ "com.sun.star.text.FieldMaster.User", sFirstParam);
+ uno::Reference<text::XDependentTextField> xDependentField(
+ xFieldInterface, uno::UNO_QUERY_THROW);
+ xDependentField->attachTextFieldMaster(xMaster);
+ m_bSetUserFieldContent = true;
+ }
}
break;
case FIELD_EDITTIME :
@@ -5480,7 +5494,10 @@ void DomainMapper_Impl::CloseFieldCommand()
break;
case FIELD_FILESIZE : break;
case FIELD_FORMULA :
- handleFieldFormula(pContext, xFieldProperties);
+ if (bCreateField)
+ {
+ handleFieldFormula(pContext, xFieldProperties);
+ }
break;
case FIELD_FORMCHECKBOX :
case FIELD_FORMDROPDOWN :
@@ -6031,8 +6048,8 @@ bool DomainMapper_Impl::IsFieldResultAsString()
{
if (!IsFieldNestingAllowed(pOuter, m_aFieldStack.back()))
{
- // Child field has no backing SwField, but the parent has: append is still possible.
- bRet = pOuter->GetTextField().is();
+ // If nesting is not allowed, then the result can only be a string.
+ bRet = true;
}
}
}
@@ -6052,8 +6069,11 @@ void DomainMapper_Impl::AppendFieldResult(OUString const& rString)
{
if (!IsFieldNestingAllowed(pOuter, pContext))
{
- // Child can't host the field result, forward to parent.
- pOuter->AppendResult(rString);
+ if (pOuter->IsCommandCompleted())
+ {
+ // Child can't host the field result, forward to parent's result.
+ pOuter->AppendResult(rString);
+ }
return;
}
}