diff options
Diffstat (limited to 'sw/source/filter/ww8')
-rw-r--r-- | sw/source/filter/ww8/wrtw8nds.cxx | 41 | ||||
-rw-r--r-- | sw/source/filter/ww8/ww8par.cxx | 43 | ||||
-rw-r--r-- | sw/source/filter/ww8/ww8par5.cxx | 30 |
3 files changed, 72 insertions, 42 deletions
diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx index 68437c9529..e33e8708f4 100644 --- a/sw/source/filter/ww8/wrtw8nds.cxx +++ b/sw/source/filter/ww8/wrtw8nds.cxx @@ -2658,33 +2658,36 @@ void MSWordExportBase::OutputTextNode( SwTextNode& rNode ) assert(pFieldmark); - if (pFieldmark->GetFieldname() == ODF_FORMDATE) + if (pFieldmark) { - if(GetExportFormat() == MSWordExportBase::ExportFormat::DOCX) // supported by DOCX only + if (pFieldmark->GetFieldname() == ODF_FORMDATE) { - OutputField( nullptr, ww::eFORMDATE, OUString(), FieldFlags::Close ); + if(GetExportFormat() == MSWordExportBase::ExportFormat::DOCX) // supported by DOCX only + { + OutputField( nullptr, ww::eFORMDATE, OUString(), FieldFlags::Close ); + } } - } - else - { - ww::eField eFieldId = lcl_getFieldId( pFieldmark ); - if (pFieldmark->GetFieldname() == ODF_UNHANDLED) + else { - IFieldmark::parameter_map_t::const_iterator it = pFieldmark->GetParameters()->find( ODF_ID_PARAM ); - if ( it != pFieldmark->GetParameters()->end() ) + ww::eField eFieldId = lcl_getFieldId( pFieldmark ); + if (pFieldmark->GetFieldname() == ODF_UNHANDLED) { - OUString sFieldId; - it->second >>= sFieldId; - eFieldId = static_cast<ww::eField>(sFieldId.toInt32()); + IFieldmark::parameter_map_t::const_iterator it = pFieldmark->GetParameters()->find( ODF_ID_PARAM ); + if ( it != pFieldmark->GetParameters()->end() ) + { + OUString sFieldId; + it->second >>= sFieldId; + eFieldId = static_cast<ww::eField>(sFieldId.toInt32()); + } } - } - OutputField( nullptr, eFieldId, OUString(), FieldFlags::Close ); + OutputField( nullptr, eFieldId, OUString(), FieldFlags::Close ); - if (pFieldmark->GetFieldname() == ODF_FORMTEXT - && GetExportFormat() != MSWordExportBase::ExportFormat::DOCX ) - { - AppendBookmark( pFieldmark->GetName() ); + if (pFieldmark->GetFieldname() == ODF_FORMTEXT + && GetExportFormat() != MSWordExportBase::ExportFormat::DOCX ) + { + AppendBookmark( pFieldmark->GetName() ); + } } } } diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx index 10ccaa4878..976a68b88a 100644 --- a/sw/source/filter/ww8/ww8par.cxx +++ b/sw/source/filter/ww8/ww8par.cxx @@ -27,6 +27,7 @@ #include <com/sun/star/frame/XModel.hpp> #include <com/sun/star/packages/XPackageEncryption.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/text/XTextFieldsSupplier.hpp> #include <i18nlangtag/languagetag.hxx> @@ -4808,27 +4809,35 @@ void SwWW8ImplReader::ReadDocVars() aDocVarStrings, &aDocVarStringIds, &aDocValueStrings); if (m_bVer67) return; - uno::Reference<document::XDocumentPropertiesSupplier> xDPS( - m_pDocShell->GetModel(), uno::UNO_QUERY_THROW); - uno::Reference<document::XDocumentProperties> xDocProps( - xDPS->getDocumentProperties()); - OSL_ENSURE(xDocProps.is(), "DocumentProperties is null"); - uno::Reference<beans::XPropertyContainer> xUserDefinedProps = - xDocProps->getUserDefinedProperties(); - OSL_ENSURE(xUserDefinedProps.is(), "UserDefinedProperties is null"); - - for(size_t i=0; i<aDocVarStrings.size(); i++) + uno::Reference< text::XTextFieldsSupplier > xFieldsSupplier(m_pDocShell->GetModel(), uno::UNO_QUERY_THROW); + uno::Reference<css::lang::XMultiServiceFactory> xTextFactory(m_pDocShell->GetModel(), uno::UNO_QUERY); + uno::Reference< container::XNameAccess > xFieldMasterAccess = xFieldsSupplier->getTextFieldMasters(); + for(size_t i = 0; i < aDocVarStrings.size(); i++) { const OUString &rName = aDocVarStrings[i]; uno::Any aValue; - aValue <<= rName; - try { - xUserDefinedProps->addProperty( rName, - beans::PropertyAttribute::REMOVABLE, - aValue ); - } catch (const uno::Exception &) { - // ignore + if (aDocValueStrings.size() > i) + { + OUString value = aDocValueStrings[i]; + value = value.replaceAll("\r\n", "\n"); + value = value.replaceAll("\r", "\n"); + aValue <<= value; + } + + uno::Reference< beans::XPropertySet > xMaster; + OUString sFieldMasterService("com.sun.star.text.FieldMaster.User." + rName); + + // Find or create Field Master + if (xFieldMasterAccess->hasByName(sFieldMasterService)) + { + xMaster.set(xFieldMasterAccess->getByName(sFieldMasterService), uno::UNO_QUERY_THROW); + } + else + { + xMaster.set(xTextFactory->createInstance("com.sun.star.text.FieldMaster.User"), uno::UNO_QUERY_THROW); + xMaster->setPropertyValue("Name", uno::Any(rName)); } + xMaster->setPropertyValue("Content", aValue); } } diff --git a/sw/source/filter/ww8/ww8par5.cxx b/sw/source/filter/ww8/ww8par5.cxx index c87c33dde0..6750fa21ae 100644 --- a/sw/source/filter/ww8/ww8par5.cxx +++ b/sw/source/filter/ww8/ww8par5.cxx @@ -58,6 +58,7 @@ #include <IDocumentState.hxx> #include <flddat.hxx> #include <docufld.hxx> +#include <usrfld.hxx> #include <reffld.hxx> #include <IMark.hxx> #include <expfld.hxx> @@ -1831,12 +1832,29 @@ eF_ResT SwWW8ImplReader::Read_F_DocInfo( WW8FieldDesc* pF, OUString& rStr ) aData = aData.replaceAll("\"", ""); } - const auto pType(static_cast<SwDocInfoFieldType*>( - m_rDoc.getIDocumentFieldsAccess().GetSysFieldType(SwFieldIds::DocInfo))); - SwDocInfoField aField(pType, nSub|nReg, aData, GetFieldResult(pF), nFormat); - if (bDateTime) - ForceFieldLanguage(aField, nLang); - m_rDoc.getIDocumentContentOperations().InsertPoolItem(*m_pPaM, SwFormatField(aField)); + bool bDone = false; + if (DI_CUSTOM == nSub) + { + const auto pType(static_cast<SwUserFieldType*>( + m_rDoc.getIDocumentFieldsAccess().GetFieldType(SwFieldIds::User, aData, false))); + if (pType) + { + SwUserField aField(pType, 0, nFormat); + if (bDateTime) + ForceFieldLanguage(aField, nLang); + m_rDoc.getIDocumentContentOperations().InsertPoolItem(*m_pPaM, SwFormatField(aField)); + bDone = true; + } + } + if (!bDone) + { + const auto pType(static_cast<SwDocInfoFieldType*>( + m_rDoc.getIDocumentFieldsAccess().GetSysFieldType(SwFieldIds::DocInfo))); + SwDocInfoField aField(pType, nSub|nReg, aData, GetFieldResult(pF), nFormat); + if (bDateTime) + ForceFieldLanguage(aField, nLang); + m_rDoc.getIDocumentContentOperations().InsertPoolItem(*m_pPaM, SwFormatField(aField)); + } return eF_ResT::OK; } |