diff options
-rw-r--r-- | sw/qa/extras/ww8export/data/tdf147861_customField.doc | bin | 0 -> 19968 bytes | |||
-rw-r--r-- | sw/qa/extras/ww8export/ww8export3.cxx | 19 | ||||
-rw-r--r-- | sw/source/filter/ww8/ww8par5.cxx | 13 |
3 files changed, 30 insertions, 2 deletions
diff --git a/sw/qa/extras/ww8export/data/tdf147861_customField.doc b/sw/qa/extras/ww8export/data/tdf147861_customField.doc Binary files differnew file mode 100644 index 000000000000..f18d65f4059e --- /dev/null +++ b/sw/qa/extras/ww8export/data/tdf147861_customField.doc diff --git a/sw/qa/extras/ww8export/ww8export3.cxx b/sw/qa/extras/ww8export/ww8export3.cxx index 0ae023416cc5..7f0132dcbc4e 100644 --- a/sw/qa/extras/ww8export/ww8export3.cxx +++ b/sw/qa/extras/ww8export/ww8export3.cxx @@ -17,6 +17,7 @@ #include <com/sun/star/graphic/XGraphic.hpp> #include <com/sun/star/table/ShadowFormat.hpp> #include <com/sun/star/text/XFormField.hpp> +#include <com/sun/star/text/XTextField.hpp> #include <com/sun/star/text/XTextTable.hpp> #include <com/sun/star/text/XTextTablesSupplier.hpp> #include <com/sun/star/text/WritingMode2.hpp> @@ -99,6 +100,24 @@ DECLARE_WW8EXPORT_TEST(testTdf100961_fixedDateTime, "tdf100961_fixedDateTime.doc CPPUNIT_ASSERT_EQUAL(sal_uInt16(8), datetime.Seconds); } +DECLARE_WW8EXPORT_TEST(testTdf147861_customField, "tdf147861_customField.doc") +{ + // These should each be specific values, not a shared DocProperty + getParagraph(1, "CustomEditedTitle"); // edited + getParagraph(2, " INSERT Custom Title here"); // matches current DocProperty + getParagraph(3, "My Title"); // edited + + if (mbExported) + return; + + // Verify that these are fields, and not just plain text + uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + auto xFieldsAccess(xTextFieldsSupplier->getTextFields()); + uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); + uno::Reference<text::XTextField> xField(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("CustomEditedTitle"), xField->getPresentation(false)); +} + DECLARE_WW8EXPORT_TEST(testTdf138345_paraCharHighlight, "tdf138345_paraCharHighlight.doc") { uno::Reference<beans::XPropertySet> xRun(getRun(getParagraph(9), 1, "A side benefit is that "), uno::UNO_QUERY_THROW); diff --git a/sw/source/filter/ww8/ww8par5.cxx b/sw/source/filter/ww8/ww8par5.cxx index a7075b66e949..66b08888416b 100644 --- a/sw/source/filter/ww8/ww8par5.cxx +++ b/sw/source/filter/ww8/ww8par5.cxx @@ -1645,8 +1645,17 @@ eF_ResT SwWW8ImplReader::Read_F_DocInfo( WW8FieldDesc* pF, OUString& rStr ) if( !bFieldFound ) { - SwDocInfoField aField( static_cast<SwDocInfoFieldType*>( - m_rDoc.getIDocumentFieldsAccess().GetSysFieldType( SwFieldIds::DocInfo )), DI_CUSTOM|nReg, aDocProperty, GetFieldResult( pF ) ); + // 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. + // 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. + 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)); return eF_ResT::OK; |