sw/source/filter/ww8/docxattributeoutput.cxx | 5 +-- sw/source/filter/ww8/docxexport.cxx | 36 +++++++++----------------- sw/source/filter/ww8/docxexportfilter.cxx | 27 +++++++------------ sw/source/filter/ww8/docxtablestyleexport.cxx | 3 +- sw/source/filter/ww8/wrtww8.cxx | 5 ++- sw/source/filter/ww8/wrtww8.hxx | 2 + 6 files changed, 34 insertions(+), 44 deletions(-)
New commits: commit 62ccbbbc3fdc9c07e84a13b3872db9ff3d842610 Author: Caolán McNamara <caolan.mcnam...@collabora.com> AuthorDate: Sun Feb 9 21:37:00 2025 +0000 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Tue Feb 11 15:24:11 2025 +0100 cut down the amount of GetBaseModel querying Change-Id: Ib7007a223373232006b8c4261778748b6fe3bf97 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181409 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index da96e47b0611..2e4b2367c064 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -4879,7 +4879,7 @@ DocxStringTokenMap const aExceptionTokens[] = { void DocxAttributeOutput::LatentStyles() { // Do we have latent styles available? - uno::Reference<beans::XPropertySet> xPropertySet(m_rExport.m_rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW); + rtl::Reference<SwXTextDocument> xPropertySet(m_rExport.m_xTextDoc); uno::Sequence<beans::PropertyValue> aInteropGrabBag; xPropertySet->getPropertyValue("InteropGrabBag") >>= aInteropGrabBag; uno::Sequence<beans::PropertyValue> aLatentStyles; @@ -5870,9 +5870,8 @@ void DocxAttributeOutput::WriteOLE( SwOLENode& rNode, const Size& rSize, const S OSL_ASSERT(pFlyFrameFormat); // get interoperability information about embedded objects - uno::Reference< beans::XPropertySet > xPropSet( m_rExport.m_rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW ); 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 fe0b86381369..d6cd3522b6df 100644 --- a/sw/source/filter/ww8/docxexport.cxx +++ b/sw/source/filter/ww8/docxexport.cxx @@ -1228,15 +1228,13 @@ void DocxExport::WriteSettings() m_pAttrOutput->WriteFootnoteEndnotePr( pFS, XML_endnotePr, m_rDoc.GetEndNoteInfo(), XML_endnote ); // Has themeFontLang information - rtl::Reference< SwXTextDocument > xPropSet( pDocShell->GetXTextDocument() ); - 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() ) { @@ -1245,7 +1243,7 @@ void DocxExport::WriteSettings() if ( xPropSetInfo->hasPropertyByName( "RedlineProtectionKey" ) ) { uno::Sequence<sal_Int8> aKey; - xPropSet->getPropertyValue( "RedlineProtectionKey" ) >>= aKey; + m_xTextDoc->getPropertyValue( "RedlineProtectionKey" ) >>= aKey; bool bHasRedlineProtectionKey = aKey.hasElements(); bHasDummyRedlineProtectionKey = aKey.getLength() == 1 && aKey[0] == 1; if ( bHasRedlineProtectionKey && !bHasDummyRedlineProtectionKey ) @@ -1275,7 +1273,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 : std::as_const(propList) ) { @@ -1502,9 +1500,7 @@ void DocxExport::WriteTheme() // See OOXMLDocumentImpl::resolveGlossaryStream void DocxExport::WriteGlossary() { - rtl::Reference< SwXTextDocument > xPropSet( m_rDoc.GetDocShell()->GetXTextDocument() ); - - 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; @@ -1512,7 +1508,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 : std::as_const(propList) ) { @@ -1663,16 +1659,14 @@ static void lcl_UpdateXmlValues(const SdtData& sdtData, const uno::Reference<css void DocxExport::WriteCustomXml() { - rtl::Reference< SwXTextDocument > xPropSet( m_rDoc.GetDocShell()->GetXTextDocument() ); - - 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)) @@ -1762,11 +1756,10 @@ void DocxExport::WriteCustomXml() void DocxExport::WriteVBA() { - rtl::Reference<SwXTextDocument> xStorageBasedDocument(m_rDoc.GetDocShell()->GetXTextDocument()); - if (!xStorageBasedDocument.is()) + if (!m_xTextDoc) return; - uno::Reference<embed::XStorage> xDocumentStorage = xStorageBasedDocument->getDocumentStorage(); + uno::Reference<embed::XStorage> xDocumentStorage = m_xTextDoc->getDocumentStorage(); OUString aMacrosName("_MS_VBA_Macros"); if (!xDocumentStorage.is() || !xDocumentStorage->hasByName(aMacrosName)) return; @@ -1821,16 +1814,14 @@ void DocxExport::WriteVBA() void DocxExport::WriteEmbeddings() { - rtl::Reference< SwXTextDocument > xPropSet( m_rDoc.GetDocShell()->GetXTextDocument() ); - - 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)) @@ -2071,12 +2062,11 @@ sal_Int32 DocxExport::WriteOutliner(const OutlinerParaObject& rParaObj, sal_uInt sal_Int32 DocxExport::getWordCompatibilityModeFromGrabBag() const { sal_Int32 nWordCompatibilityMode = -1; - rtl::Reference< SwXTextDocument > xPropSet(m_rDoc.GetDocShell()->GetXTextDocument()); - uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo(); + uno::Reference< beans::XPropertySetInfo > xPropSetInfo = m_xTextDoc->getPropertySetInfo(); 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; for (const auto& rProp : std::as_const(propList)) { diff --git a/sw/source/filter/ww8/docxexportfilter.cxx b/sw/source/filter/ww8/docxexportfilter.cxx index 04a5d015050f..d3793101e819 100644 --- a/sw/source/filter/ww8/docxexportfilter.cxx +++ b/sw/source/filter/ww8/docxexportfilter.cxx @@ -73,23 +73,18 @@ bool DocxExportFilter::exportDocument() // Check whether application is in headless mode if (!Application::IsHeadlessModeEnabled()) { - uno::Reference<document::XStorageBasedDocument> xStorageBasedDocument( - pDoc->GetDocShell()->GetBaseModel(), uno::UNO_QUERY); - if (xStorageBasedDocument.is()) + uno::Reference<embed::XStorage> xDocumentStorage = + pTextDoc->getDocumentStorage(); + if (xDocumentStorage.is() && xDocumentStorage->hasByName(u"_MS_VBA_Macros"_ustr)) { - 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/docxtablestyleexport.cxx b/sw/source/filter/ww8/docxtablestyleexport.cxx index 46a052e0c724..c8ffe328dfeb 100644 --- a/sw/source/filter/ww8/docxtablestyleexport.cxx +++ b/sw/source/filter/ww8/docxtablestyleexport.cxx @@ -11,6 +11,7 @@ #include "docxhelper.hxx" #include <doc.hxx> #include <docsh.hxx> +#include <unotxdoc.hxx> #include <oox/token/tokens.hxx> #include <comphelper/sequenceashashmap.hxx> #include <sax/fastattribs.hxx> @@ -125,7 +126,7 @@ void DocxTableStyleExport::TableStyles(sal_Int32 nCountStylesToWrite) { // Do we have table styles from InteropGrabBag available? uno::Reference<beans::XPropertySet> xPropertySet( - m_pImpl->getDoc().GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW); + m_pImpl->getDoc().GetDocShell()->GetXTextDocument()); uno::Sequence<beans::PropertyValue> aInteropGrabBag; xPropertySet->getPropertyValue("InteropGrabBag") >>= aInteropGrabBag; uno::Sequence<beans::PropertyValue> aTableStyles; diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx index e2a7cf4d67d9..e9780b175ad2 100644 --- a/sw/source/filter/ww8/wrtww8.cxx +++ b/sw/source/filter/ww8/wrtww8.cxx @@ -3974,7 +3974,10 @@ MSWordExportBase::MSWordExportBase( SwDoc& rDocument, std::shared_ptr<SwUnoCurso , m_pOrigPam(pOriginalPam) { if (SwDocShell* pShell = rDocument.GetDocShell()) - m_bHasBailsMetaData = SwRDFHelper::hasMetadataGraph(pShell->GetXTextDocument(), u"urn:bails"_ustr); + { + m_xTextDoc = pShell->GetXTextDocument(); + 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 a6dff3d7aad3..8723d576d16a 100644 --- a/sw/source/filter/ww8/wrtww8.hxx +++ b/sw/source/filter/ww8/wrtww8.hxx @@ -39,6 +39,7 @@ #include "WW8TableInfo.hxx" #include <calbck.hxx> #include <IDocumentRedlineAccess.hxx> +#include <unotxdoc.hxx> #include <vcl/graph.hxx> @@ -576,6 +577,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;