sw/source/filter/ww8/docxattributeoutput.cxx | 6 +--- sw/source/filter/ww8/docxexport.cxx | 40 ++++++++------------------- sw/source/filter/ww8/docxexportfilter.cxx | 30 +++++++------------- sw/source/filter/ww8/wrtww8.cxx | 6 ++-- sw/source/filter/ww8/wrtww8.hxx | 2 + 5 files changed, 32 insertions(+), 52 deletions(-)
New commits: commit a8572635aa5f30d9f24bc55f69db85960e0c578b Author: Caolán McNamara <caolan.mcnam...@collabora.com> AuthorDate: Sun Feb 9 21:37:00 2025 +0000 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Mon Feb 10 20:35:41 2025 +0100 cut down the amount of GetBaseModel querying Change-Id: Ib7007a223373232006b8c4261778748b6fe3bf97 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181321 Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> Tested-by: Jenkins diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index fb1e973c0aae..f555a76e081b 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -4935,9 +4935,8 @@ DocxStringTokenMap const aExceptionTokens[] = { void DocxAttributeOutput::LatentStyles() { // Do we have latent styles available? - rtl::Reference<SwXTextDocument> xPropertySet(m_rExport.m_rDoc.GetDocShell()->GetBaseModel()); uno::Sequence<beans::PropertyValue> aInteropGrabBag; - xPropertySet->getPropertyValue(u"InteropGrabBag"_ustr) >>= aInteropGrabBag; + m_rExport.m_xTextDoc->getPropertyValue(u"InteropGrabBag"_ustr) >>= aInteropGrabBag; uno::Sequence<beans::PropertyValue> aLatentStyles; auto pProp = std::find_if(std::cbegin(aInteropGrabBag), std::cend(aInteropGrabBag), [](const beans::PropertyValue& rProp) { return rProp.Name == "latentStyles"; }); @@ -5924,9 +5923,8 @@ void DocxAttributeOutput::WriteOLE( SwOLENode& rNode, const Size& rSize, const S OSL_ASSERT(pFlyFrameFormat); // get interoperability information about embedded objects - rtl::Reference< SwXTextDocument > xPropSet( m_rExport.m_rDoc.GetDocShell()->GetBaseModel() ); uno::Sequence< beans::PropertyValue > aGrabBag, aObjectsInteropList,aObjectInteropAttributes; - xPropSet->getPropertyValue( UNO_NAME_MISC_OBJ_INTEROPGRABBAG ) >>= aGrabBag; + m_rExport.m_xTextDoc->getPropertyValue( UNO_NAME_MISC_OBJ_INTEROPGRABBAG ) >>= aGrabBag; auto pProp = std::find_if(std::cbegin(aGrabBag), std::cend(aGrabBag), [](const beans::PropertyValue& rProp) { return rProp.Name == "EmbeddedObjects"; }); if (pProp != std::cend(aGrabBag)) diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx index 75283447a5c9..b5b6a100f7c2 100644 --- a/sw/source/filter/ww8/docxexport.cxx +++ b/sw/source/filter/ww8/docxexport.cxx @@ -1242,15 +1242,13 @@ void DocxExport::WriteSettings() m_pAttrOutput->WriteFootnoteEndnotePr( pFS, XML_endnotePr, m_rDoc.GetEndNoteInfo(), XML_endnote ); // Has themeFontLang information - rtl::Reference< SwXTextDocument > xPropSet( pDocShell->GetBaseModel() ); - bool bUseGrabBagProtection = false; bool bWriterWantsToProtect = false; bool bWriterWantsToProtectForm = false; bool bWriterWantsToProtectRedline = false; bool bHasDummyRedlineProtectionKey = false; bool bReadOnlyStatusUnchanged = true; - uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo(); + uno::Reference< beans::XPropertySetInfo > xPropSetInfo = m_xTextDoc->getPropertySetInfo(); if ( m_rDoc.getIDocumentSettingAccess().get(DocumentSettingId::PROTECT_FORM) || m_pSections->DocumentIsProtected() ) { @@ -1259,7 +1257,7 @@ void DocxExport::WriteSettings() if ( xPropSetInfo->hasPropertyByName( u"RedlineProtectionKey"_ustr ) ) { uno::Sequence<sal_Int8> aKey; - xPropSet->getPropertyValue( u"RedlineProtectionKey"_ustr ) >>= aKey; + m_xTextDoc->getPropertyValue( u"RedlineProtectionKey"_ustr ) >>= aKey; bool bHasRedlineProtectionKey = aKey.hasElements(); bHasDummyRedlineProtectionKey = aKey.getLength() == 1 && aKey[0] == 1; if ( bHasRedlineProtectionKey && !bHasDummyRedlineProtectionKey ) @@ -1271,7 +1269,7 @@ void DocxExport::WriteSettings() if ( xPropSetInfo->hasPropertyByName( aGrabBagName ) ) { uno::Sequence< beans::PropertyValue > propList; - xPropSet->getPropertyValue( aGrabBagName ) >>= propList; + m_xTextDoc->getPropertyValue( aGrabBagName ) >>= propList; for (const auto& rProp : propList) { @@ -1511,9 +1509,7 @@ void DocxExport::WriteTheme() // See OOXMLDocumentImpl::resolveGlossaryStream void DocxExport::WriteGlossary() { - rtl::Reference< SwXTextDocument > xPropSet( m_rDoc.GetDocShell()->GetBaseModel() ); - - uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo(); + uno::Reference< beans::XPropertySetInfo > xPropSetInfo = m_xTextDoc->getPropertySetInfo(); OUString aName = UNO_NAME_MISC_OBJ_INTEROPGRABBAG; if ( !xPropSetInfo->hasPropertyByName( aName ) ) return; @@ -1521,7 +1517,7 @@ void DocxExport::WriteGlossary() uno::Reference<xml::dom::XDocument> glossaryDocDom; uno::Sequence< uno::Sequence<beans::NamedValue> > glossaryDomList; uno::Sequence< beans::PropertyValue > propList; - xPropSet->getPropertyValue( aName ) >>= propList; + m_xTextDoc->getPropertyValue( aName ) >>= propList; sal_Int32 collectedProperties = 0; for (const auto& rProp : propList) { @@ -1672,16 +1668,14 @@ static void lcl_UpdateXmlValues(const SdtData& sdtData, const uno::Reference<css void DocxExport::WriteCustomXml() { - rtl::Reference< SwXTextDocument > xPropSet( m_rDoc.GetDocShell()->GetBaseModel() ); - - uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo(); + uno::Reference< beans::XPropertySetInfo > xPropSetInfo = m_xTextDoc->getPropertySetInfo(); if ( !xPropSetInfo->hasPropertyByName( UNO_NAME_MISC_OBJ_INTEROPGRABBAG ) ) return; uno::Sequence<uno::Reference<xml::dom::XDocument> > customXmlDomlist; uno::Sequence<uno::Reference<xml::dom::XDocument> > customXmlDomPropslist; uno::Sequence< beans::PropertyValue > propList; - xPropSet->getPropertyValue( UNO_NAME_MISC_OBJ_INTEROPGRABBAG ) >>= propList; + m_xTextDoc->getPropertyValue( UNO_NAME_MISC_OBJ_INTEROPGRABBAG ) >>= propList; auto pProp = std::find_if(std::cbegin(propList), std::cend(propList), [](const beans::PropertyValue& rProp) { return rProp.Name == "OOXCustomXml"; }); if (pProp != std::cend(propList)) @@ -1771,15 +1765,10 @@ void DocxExport::WriteCustomXml() void DocxExport::WriteVBA() { - SwDocShell* pShell = m_rDoc.GetDocShell(); - if (!pShell) - return; - - rtl::Reference<SwXTextDocument> xStorageBasedDocument(pShell->GetBaseModel()); - if (!xStorageBasedDocument.is()) + if (!m_xTextDoc) return; - uno::Reference<embed::XStorage> xDocumentStorage = xStorageBasedDocument->getDocumentStorage(); + uno::Reference<embed::XStorage> xDocumentStorage = m_xTextDoc->getDocumentStorage(); OUString aMacrosName(u"_MS_VBA_Macros"_ustr); if (!xDocumentStorage.is() || !xDocumentStorage->hasByName(aMacrosName)) return; @@ -1838,16 +1827,14 @@ void DocxExport::WriteEmbeddings() if (!pShell) return; - rtl::Reference< SwXTextDocument > xPropSet( pShell->GetBaseModel() ); - - uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo(); + uno::Reference< beans::XPropertySetInfo > xPropSetInfo = m_xTextDoc->getPropertySetInfo(); OUString aName = UNO_NAME_MISC_OBJ_INTEROPGRABBAG; if ( !xPropSetInfo->hasPropertyByName( aName ) ) return; uno::Sequence< beans::PropertyValue > embeddingsList; uno::Sequence< beans::PropertyValue > propList; - xPropSet->getPropertyValue( aName ) >>= propList; + m_xTextDoc->getPropertyValue( aName ) >>= propList; auto pProp = std::find_if(std::cbegin(propList), std::cend(propList), [](const beans::PropertyValue& rProp) { return rProp.Name == "OOXEmbeddings"; }); if (pProp != std::cend(propList)) @@ -2111,13 +2098,12 @@ sal_Int32 DocxExport::getWordCompatibilityMode() * when we no longer care about working with perfect compatibility with older versions of MS Word. */ m_nWordCompatibilityMode = 15; //older versions might not open our files well - rtl::Reference< SwXTextDocument > xPropSet(m_rDoc.GetDocShell()->GetBaseModel()); - uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo(); + uno::Reference< beans::XPropertySetInfo > xPropSetInfo = m_xTextDoc->getPropertySetInfo(); // Round-trip the existing compatibilityMode if (xPropSetInfo->hasPropertyByName(UNO_NAME_MISC_OBJ_INTEROPGRABBAG)) { uno::Sequence< beans::PropertyValue > propList; - xPropSet->getPropertyValue( UNO_NAME_MISC_OBJ_INTEROPGRABBAG ) >>= propList; + m_xTextDoc->getPropertyValue( UNO_NAME_MISC_OBJ_INTEROPGRABBAG ) >>= propList; sal_Int32 nImportedWordCompatbilityMode = -1; for (const auto& rProp : propList) diff --git a/sw/source/filter/ww8/docxexportfilter.cxx b/sw/source/filter/ww8/docxexportfilter.cxx index 2a4630a0a40a..8ea56f2f3661 100644 --- a/sw/source/filter/ww8/docxexportfilter.cxx +++ b/sw/source/filter/ww8/docxexportfilter.cxx @@ -73,26 +73,18 @@ bool DocxExportFilter::exportDocument() // Check whether application is in headless mode if (!Application::IsHeadlessModeEnabled()) { - if (SwDocShell* pShell = pDoc->GetDocShell()) + uno::Reference<embed::XStorage> xDocumentStorage = + pTextDoc->getDocumentStorage(); + if (xDocumentStorage.is() && xDocumentStorage->hasByName(u"_MS_VBA_Macros"_ustr)) { - rtl::Reference<SwXTextDocument> xStorageBasedDocument( - pShell->GetBaseModel()); - if (xStorageBasedDocument.is()) - { - uno::Reference<embed::XStorage> xDocumentStorage = - xStorageBasedDocument->getDocumentStorage(); - if (xDocumentStorage.is() && xDocumentStorage->hasByName(u"_MS_VBA_Macros"_ustr)) - { - // Let user know that macros won't be saved in this format - std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog( - nullptr, - VclMessageType::Warning, VclButtonsType::OkCancel, - SwResId(STR_CANT_SAVE_MACROS)) - ); - if (xBox->run() == RET_CANCEL) - return false; - } - } + // Let user know that macros won't be saved in this format + std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog( + nullptr, + VclMessageType::Warning, VclButtonsType::OkCancel, + SwResId(STR_CANT_SAVE_MACROS)) + ); + if (xBox->run() == RET_CANCEL) + return false; } } } diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx index d13aa46e0b09..f69d32753a59 100644 --- a/sw/source/filter/ww8/wrtww8.cxx +++ b/sw/source/filter/ww8/wrtww8.cxx @@ -121,7 +121,6 @@ #include <fmtwrapinfluenceonobjpos.hxx> #include <officecfg/Office/Common.hxx> #include <fmtanchr.hxx> -#include <unotxdoc.hxx> using namespace css; using namespace sw::util; @@ -3990,7 +3989,10 @@ MSWordExportBase::MSWordExportBase( SwDoc& rDocument, std::shared_ptr<SwUnoCurso , m_pOrigPam(pOriginalPam) { if (SwDocShell* pShell = rDocument.GetDocShell()) - m_bHasBailsMetaData = SwRDFHelper::hasMetadataGraph(pShell->GetBaseModel(), u"urn:bails"_ustr); + { + m_xTextDoc = pShell->GetBaseModel(); + m_bHasBailsMetaData = SwRDFHelper::hasMetadataGraph(m_xTextDoc, u"urn:bails"_ustr); + } } MSWordExportBase::~MSWordExportBase() diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx index b9c524bed3d4..bd116fa83f12 100644 --- a/sw/source/filter/ww8/wrtww8.hxx +++ b/sw/source/filter/ww8/wrtww8.hxx @@ -40,6 +40,7 @@ #include "WW8TableInfo.hxx" #include <calbck.hxx> #include <IDocumentRedlineAccess.hxx> +#include <unotxdoc.hxx> #include <vcl/graph.hxx> @@ -578,6 +579,7 @@ public: bool m_bHasBailsMetaData; // false if there is no urn:bails metadata in the document SwDoc& m_rDoc; + rtl::Reference<SwXTextDocument> m_xTextDoc; SwNodeOffset m_nCurStart, m_nCurEnd; std::shared_ptr<SwUnoCursor> & m_pCurPam; SwPaM *m_pOrigPam;