summaryrefslogtreecommitdiff
path: root/sw/source/filter/ww8/ww8par5.cxx
diff options
context:
space:
mode:
authorJustin Luth <justin_luth@sil.org>2022-03-11 14:55:00 +0200
committerMiklos Vajna <vmiklos@collabora.com>2022-03-24 13:20:38 +0100
commitf5c2085e70c40370a790868d4683133a41e6599d (patch)
tree15f26dc094d0b9a3bcd108ff68baa33995d5d93d /sw/source/filter/ww8/ww8par5.cxx
parent8a7d0e8a811da83265c383630cc48af57f96dc49 (diff)
tdf#147861 ww8import: solve TODO: not fixed-field if equal
Do not mark the field as "fixed" if the displayed string matches the internal variable. This allows changing the variable within LO and having the field update to reflect that change, which is the way that these fields are supposed to work (although in MS Word they only update manually via F9 which is why some needed to be fixed in the first place). Change-Id: Id359cbf0b48e63bddab3e45871326988467d7ddb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131414 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw/source/filter/ww8/ww8par5.cxx')
-rw-r--r--sw/source/filter/ww8/ww8par5.cxx23
1 files changed, 20 insertions, 3 deletions
diff --git a/sw/source/filter/ww8/ww8par5.cxx b/sw/source/filter/ww8/ww8par5.cxx
index 66b08888416b..a78fa37f2e45 100644
--- a/sw/source/filter/ww8/ww8par5.cxx
+++ b/sw/source/filter/ww8/ww8par5.cxx
@@ -1650,13 +1650,30 @@ eF_ResT SwWW8ImplReader::Read_F_DocInfo( WW8FieldDesc* pF, OUString& rStr )
// 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.
- // TODO: If the field already matches the DocProperty, no need to mark as fixed.
// TODO: Extend LO to allow a linked field that doesn't automatically update.
+ IDocumentContentOperations& rIDCO(m_rDoc.getIDocumentContentOperations());
const auto pType(static_cast<SwDocInfoFieldType*>(
m_rDoc.getIDocumentFieldsAccess().GetSysFieldType(SwFieldIds::DocInfo)));
const OUString sDisplayed = GetFieldResult(pF);
- SwDocInfoField aField(pType, DI_CUSTOM | DI_SUB_FIXED | nReg, aDocProperty, sDisplayed);
- m_rDoc.getIDocumentContentOperations().InsertPoolItem(*m_pPaM, SwFormatField(aField));
+ SwDocInfoField aField(pType, DI_CUSTOM | nReg, aDocProperty);
+
+ // If text already matches the DocProperty var, then safe to treat as refreshable field.
+ OUString sVariable = aField.ExpandField(/*bCache=*/false, nullptr);
+ if (sDisplayed.getLength() != sVariable.getLength())
+ {
+ sal_Int32 nLen = sVariable.indexOf('\x0');
+ if (nLen >= 0)
+ sVariable = sVariable.copy(0, nLen);
+ }
+ if (sDisplayed == sVariable)
+ rIDCO.InsertPoolItem(*m_pPaM, SwFormatField(aField));
+ else
+ {
+ // They don't match, so use a fixed field to prevent LO from altering the contents.
+ SwDocInfoField aFixedField(pType, DI_CUSTOM | DI_SUB_FIXED | nReg, aDocProperty,
+ sDisplayed);
+ rIDCO.InsertPoolItem(*m_pPaM, SwFormatField(aFixedField));
+ }
return eF_ResT::OK;
}