sw/inc/unotxdoc.hxx | 3 ++ sw/source/core/inc/unosection.hxx | 3 +- sw/source/uibase/uno/unotxdoc.cxx | 15 ++++++++++++++ sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx | 20 ++++++++----------- sw/source/writerfilter/dmapper/DomainMapper_Impl.hxx | 3 +- sw/source/writerfilter/dmapper/PropertyMap.cxx | 9 ++++---- sw/source/writerfilter/dmapper/PropertyMap.hxx | 4 ++- sw/source/writerfilter/dmapper/SdtHelper.cxx | 12 +++++------ 8 files changed, 45 insertions(+), 24 deletions(-)
New commits: commit 14ed2224269426ab68b6591c178c8a0d636e51a8 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Wed Apr 24 14:06:45 2024 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Sun Apr 28 18:57:59 2024 +0200 use more concrete UNO classes in writerfilter (SwXTextSection) Change-Id: I407d165ccdfcb23e2b922701dc9753c72c439cc4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166788 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx index 477f2792912b..9c1e5e39b29c 100644 --- a/sw/inc/unotxdoc.hxx +++ b/sw/inc/unotxdoc.hxx @@ -108,6 +108,7 @@ class SwXRedlines; class SwXDocumentSettings; class SwXTextDefaults; class SwXBookmark; +class SwXTextSection; namespace com::sun::star::container { class XNameContainer; } namespace com::sun::star::frame { class XController; } namespace com::sun::star::lang { struct Locale; } @@ -514,6 +515,7 @@ public: SW_DLLPUBLIC rtl::Reference<SwXTextDefaults> createTextDefaults(); SW_DLLPUBLIC rtl::Reference<SwXBookmark> createBookmark(); SW_DLLPUBLIC rtl::Reference<SwXBookmark> createFieldmark(); + SW_DLLPUBLIC rtl::Reference<SwXTextSection> createTextSection(); }; class SwXLinkTargetSupplier final : public cppu::WeakImplHelper diff --git a/sw/source/core/inc/unosection.hxx b/sw/source/core/inc/unosection.hxx index ec235f03dfae..209b905e162a 100644 --- a/sw/source/core/inc/unosection.hxx +++ b/sw/source/core/inc/unosection.hxx @@ -19,6 +19,7 @@ #pragma once +#include <swdllapi.h> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/beans/XPropertyState.hpp> @@ -44,7 +45,7 @@ typedef ::cppu::ImplInheritanceHelper , css::text::XTextSection > SwXTextSection_Base; -class SwXTextSection final +class SW_DLLPUBLIC SwXTextSection final : public SwXTextSection_Base { diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx index 400d9db8b805..0d5a46f692ef 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -176,6 +176,7 @@ #include <unocontentcontrol.hxx> #include <unoport.hxx> #include <unobookmark.hxx> +#include <unosection.hxx> #include <SwXTextDefaults.hxx> using namespace ::com::sun::star; @@ -1682,6 +1683,13 @@ rtl::Reference< SwXBookmark > SwXTextDocument::createFieldmark() return SwXFieldmark::CreateXFieldmark(GetDocOrThrow(), nullptr); } +rtl::Reference< SwXTextSection > SwXTextDocument::createTextSection() +{ + SolarMutexGuard aGuard; + ThrowIfInvalid(); + return SwXTextSection::CreateXTextSection(nullptr, false); +} + Reference< XInterface > SwXTextDocument::createInstance(const OUString& rServiceName) { return create(rServiceName, nullptr); diff --git a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx index 7f0b57ab483a..241783ab848c 100644 --- a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx +++ b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx @@ -135,6 +135,7 @@ #include <SwXDocumentSettings.hxx> #include <SwXTextDefaults.hxx> #include <unobookmark.hxx> +#include <unosection.hxx> #define REFFLDFLAG_STYLE_FROM_BOTTOM 0xc100 #define REFFLDFLAG_STYLE_HIDE_NON_NUMERICAL 0xc200 @@ -3640,12 +3641,12 @@ static void copyAllProps(const css::uno::Reference<css::uno::XInterface>& from, } } -uno::Reference< beans::XPropertySet > DomainMapper_Impl::appendTextSectionAfter( +rtl::Reference< SwXTextSection > DomainMapper_Impl::appendTextSectionAfter( uno::Reference< text::XTextRange > const & xBefore ) { - uno::Reference< beans::XPropertySet > xRet; + rtl::Reference< SwXTextSection > xSection; if (m_aTextAppendStack.empty()) - return xRet; + return xSection; uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend; if(xTextAppend.is()) { @@ -3672,13 +3673,11 @@ uno::Reference< beans::XPropertySet > DomainMapper_Impl::appendTextSectionAfter( // to the newly appended paragraph, which will be kept in the end. copyAllProps(xEndPara, xNewPara); - uno::Reference< text::XTextContent > xSection( m_xTextDocument->createInstance("com.sun.star.text.TextSection"), uno::UNO_QUERY_THROW ); + xSection = m_xTextDocument->createTextSection(); xSection->attach(xCursor); // Remove the extra paragraph (last inside the section) xEndPara->dispose(); - - xRet.set(xSection, uno::UNO_QUERY ); } catch(const uno::Exception&) { @@ -3686,7 +3685,7 @@ uno::Reference< beans::XPropertySet > DomainMapper_Impl::appendTextSectionAfter( } - return xRet; + return xSection; } void DomainMapper_Impl::appendGlossaryEntry() diff --git a/sw/source/writerfilter/dmapper/DomainMapper_Impl.hxx b/sw/source/writerfilter/dmapper/DomainMapper_Impl.hxx index 6ad54a050505..19f4d2cf0d23 100644 --- a/sw/source/writerfilter/dmapper/DomainMapper_Impl.hxx +++ b/sw/source/writerfilter/dmapper/DomainMapper_Impl.hxx @@ -57,6 +57,7 @@ class SwXTextDocument; class SwXDocumentSettings; +class SwXTextSection; namespace com::sun::star{ namespace awt{ struct Size; @@ -810,7 +811,7 @@ public: void appendOLE( const OUString& rStreamName, const std::shared_ptr<OLEHandler>& pOleHandler ); void appendStarMath( const Value& v); void adjustLastPara(sal_Int8 nAlign); - css::uno::Reference<css::beans::XPropertySet> appendTextSectionAfter(css::uno::Reference<css::text::XTextRange> const & xBefore); + rtl::Reference<SwXTextSection> appendTextSectionAfter(css::uno::Reference<css::text::XTextRange> const & xBefore); /// AutoText import: each entry is placed in the separate section void appendGlossaryEntry(); diff --git a/sw/source/writerfilter/dmapper/PropertyMap.cxx b/sw/source/writerfilter/dmapper/PropertyMap.cxx index b416ca400f6f..fd67ac04cda0 100644 --- a/sw/source/writerfilter/dmapper/PropertyMap.cxx +++ b/sw/source/writerfilter/dmapper/PropertyMap.cxx @@ -65,6 +65,7 @@ #include "PropertyMapHelper.hxx" #include <o3tl/sorted_vector.hxx> #include <o3tl/unit_conversion.hxx> +#include <unosection.hxx> #include <unotxdoc.hxx> #include <utility> @@ -769,7 +770,7 @@ void SectionPropertyMap::ApplySectionProperties( const uno::Reference< beans::XP } } -void SectionPropertyMap::ApplyProtectionProperties( uno::Reference< beans::XPropertySet >& xSection, DomainMapper_Impl& rDM_Impl ) +void SectionPropertyMap::ApplyProtectionProperties( rtl::Reference< SwXTextSection >& xSection, DomainMapper_Impl& rDM_Impl ) { try { @@ -1582,7 +1583,7 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl ) && !rDM_Impl.IsInComments()) { //todo: insert a section or access the already inserted section - uno::Reference< beans::XPropertySet > xSection = + rtl::Reference< SwXTextSection > xSection = rDM_Impl.appendTextSectionAfter( m_xStartingRange ); if ( xSection.is() ) { @@ -1616,7 +1617,7 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl ) auto xTextAppend = rDM_Impl.GetCurrentXText(); uno::Reference<container::XEnumerationAccess> const xCursor( xTextAppend->createTextCursorByRange( - uno::Reference<text::XTextContent>(xSection, uno::UNO_QUERY_THROW)->getAnchor()), + uno::Reference<text::XTextContent>(static_cast<cppu::OWeakObject*>(xSection.get()), uno::UNO_QUERY_THROW)->getAnchor()), uno::UNO_QUERY_THROW); uno::Reference<container::XEnumeration> const xEnum( xCursor->createEnumeration()); @@ -1707,7 +1708,7 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl ) } else if (!rDM_Impl.IsInComments()) { - uno::Reference< beans::XPropertySet > xSection; + rtl::Reference< SwXTextSection > xSection; ApplyProtectionProperties( xSection, rDM_Impl ); //get the properties and create appropriate page styles diff --git a/sw/source/writerfilter/dmapper/PropertyMap.hxx b/sw/source/writerfilter/dmapper/PropertyMap.hxx index 711ef47195a0..6b624e089dad 100644 --- a/sw/source/writerfilter/dmapper/PropertyMap.hxx +++ b/sw/source/writerfilter/dmapper/PropertyMap.hxx @@ -19,6 +19,7 @@ #pragma once #include <rtl/ustring.hxx> +#include <rtl/ref.hxx> #include <tools/ref.hxx> #include <com/sun/star/uno/Sequence.hxx> #include <com/sun/star/text/XText.hpp> @@ -37,6 +38,7 @@ #include <set> #include <deque> +class SwXTextSection; namespace com::sun::star { namespace beans { struct PropertyValue; @@ -320,7 +322,7 @@ private: void ApplySectionProperties( const css::uno::Reference< css::beans::XPropertySet >& xSection, DomainMapper_Impl& rDM_Impl ); /// Check if document is protected. If so, ensure a section exists, and apply its protected value. - void ApplyProtectionProperties( css::uno::Reference< css::beans::XPropertySet >& xSection, DomainMapper_Impl& rDM_Impl ); + void ApplyProtectionProperties( rtl::Reference<SwXTextSection>& xSection, DomainMapper_Impl& rDM_Impl ); css::uno::Reference< css::text::XTextColumns > ApplyColumnProperties(const css::uno::Reference<css::beans::XPropertySet>& xPageStyle, DomainMapper_Impl& rDM_Impl); commit 192f76cbb2718b9d83f4b674a71ddf8d1c467184 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Wed Apr 24 13:57:40 2024 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Sun Apr 28 18:57:52 2024 +0200 use more concrete UNO classes in writerfilter (SwXFieldmark) Change-Id: Ifa90331eadc08e0949c28d09be92d5aed4c8a70f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166787 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx index 6a9b9de6fbe6..477f2792912b 100644 --- a/sw/inc/unotxdoc.hxx +++ b/sw/inc/unotxdoc.hxx @@ -513,6 +513,7 @@ public: SW_DLLPUBLIC rtl::Reference<SwXDocumentSettings> createDocumentSettings(); SW_DLLPUBLIC rtl::Reference<SwXTextDefaults> createTextDefaults(); SW_DLLPUBLIC rtl::Reference<SwXBookmark> createBookmark(); + SW_DLLPUBLIC rtl::Reference<SwXBookmark> createFieldmark(); }; class SwXLinkTargetSupplier final : public cppu::WeakImplHelper diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx index e72cf2a59ec5..400d9db8b805 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -175,6 +175,7 @@ #include <textcontentcontrol.hxx> #include <unocontentcontrol.hxx> #include <unoport.hxx> +#include <unobookmark.hxx> #include <SwXTextDefaults.hxx> using namespace ::com::sun::star; @@ -1674,6 +1675,12 @@ rtl::Reference< SwXBookmark > SwXTextDocument::createBookmark() return SwXBookmark::CreateXBookmark(GetDocOrThrow(), nullptr); } +rtl::Reference< SwXBookmark > SwXTextDocument::createFieldmark() +{ + SolarMutexGuard aGuard; + ThrowIfInvalid(); + return SwXFieldmark::CreateXFieldmark(GetDocOrThrow(), nullptr); +} Reference< XInterface > SwXTextDocument::createInstance(const OUString& rServiceName) { diff --git a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx index 103a836536bc..7f0b57ab483a 100644 --- a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx +++ b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx @@ -7461,8 +7461,6 @@ void DomainMapper_Impl::CloseFieldCommand() try { - uno::Reference< uno::XInterface > xFieldInterface; - const auto& [sType, vArguments, vSwitches]{ splitFieldCommand(pContext->GetCommand()) }; (void)vSwitches; OUString const sFirstParam(vArguments.empty() ? OUString() : vArguments.front()); @@ -7558,6 +7556,7 @@ void DomainMapper_Impl::CloseFieldCommand() bCreateField = false; } + uno::Reference< uno::XInterface > xFieldInterface; if( bCreateField || bCreateEnhancedField ) { //add the service prefix @@ -8347,9 +8346,9 @@ void DomainMapper_Impl::CloseFieldCommand() // Don't waste resources on wrapping shapes inside a fieldmark. if (sType != "SHAPE" && m_xTextDocument && !m_aTextAppendStack.empty()) { - xFieldInterface = m_xTextDocument->createInstance("com.sun.star.text.Fieldmark"); + rtl::Reference<SwXBookmark> xFieldInterface = m_xTextDocument->createFieldmark(); - uno::Reference<text::XFormField> const xFormField(xFieldInterface, uno::UNO_QUERY); + uno::Reference<text::XFormField> const xFormField(static_cast<cppu::OWeakObject*>(xFieldInterface.get()), uno::UNO_QUERY); InsertFieldmark(m_aTextAppendStack, xFormField, pContext->GetStartRange(), pContext->GetFieldId()); xFormField->setFieldType(ODF_UNHANDLED); diff --git a/sw/source/writerfilter/dmapper/SdtHelper.cxx b/sw/source/writerfilter/dmapper/SdtHelper.cxx index 06f3262b767e..db00c79461c0 100644 --- a/sw/source/writerfilter/dmapper/SdtHelper.cxx +++ b/sw/source/writerfilter/dmapper/SdtHelper.cxx @@ -32,6 +32,7 @@ #include <com/sun/star/xml/xpath/XPathException.hpp> #include <com/sun/star/xml/dom/DocumentBuilder.hpp> #include <unotxdoc.hxx> +#include <unobookmark.hxx> namespace writerfilter::dmapper { @@ -473,14 +474,13 @@ void SdtHelper::createDateContentControl() return; } - uno::Reference<uno::XInterface> xFieldInterface - = m_rDM_Impl.GetTextDocument()->createInstance("com.sun.star.text.Fieldmark"); - uno::Reference<text::XFormField> xFormField(xFieldInterface, uno::UNO_QUERY); - uno::Reference<text::XTextContent> xToInsert(xFormField, uno::UNO_QUERY); - if (!(xFormField.is() && xToInsert.is())) + rtl::Reference<SwXBookmark> xFieldmark = m_rDM_Impl.GetTextDocument()->createFieldmark(); + uno::Reference<text::XFormField> xFormField(static_cast<cppu::OWeakObject*>(xFieldmark.get()), + uno::UNO_QUERY); + if (!xFormField) return; - xToInsert->attach(uno::Reference<text::XTextRange>(xCrsr, uno::UNO_QUERY_THROW)); + xFieldmark->attach(uno::Reference<text::XTextRange>(xCrsr, uno::UNO_QUERY_THROW)); xFormField->setFieldType(ODF_FORMDATE); uno::Reference<container::XNameContainer> xNameCont = xFormField->getParameters(); if (xNameCont.is())