sw/inc/unotxdoc.hxx                                  |    3 
 sw/source/core/inc/unoidx.hxx                        |    9 --
 sw/source/core/inc/unosection.hxx                    |   16 +++
 sw/source/core/unocore/unosect.cxx                   |    2 
 sw/source/uibase/uno/unotxdoc.cxx                    |   11 ++
 sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx |   80 ++++++++-----------
 sw/source/writerfilter/dmapper/DomainMapper_Impl.hxx |   16 ++-
 7 files changed, 81 insertions(+), 56 deletions(-)

New commits:
commit 0ad257a6f314aa6e916042b4a5f58683f46f4c13
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Mon Aug 5 08:03:16 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Aug 13 22:10:38 2024 +0200

    use more concrete UNO type in writerfilter
    
    Change-Id: I9c4a71b1a32bf42ea54ca9f108ee22d4eabc205c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171470
    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 4329019af918..f5f61ef9242a 100644
--- a/sw/inc/unotxdoc.hxx
+++ b/sw/inc/unotxdoc.hxx
@@ -120,6 +120,7 @@ class SwXContentControl;
 class SwXTextEmbeddedObject;
 class SvXMLEmbeddedObjectHelper;
 class SwXFieldmark;
+class SwXSection;
 class SwXFieldMaster;
 namespace com::sun::star::container { class XNameContainer; }
 namespace com::sun::star::frame { class XController; }
@@ -530,6 +531,8 @@ public:
     rtl::Reference<SwXFieldMaster> createFieldMaster(std::u16string_view 
sServiceName);
     rtl::Reference<SwXTextField> createTextField(std::u16string_view 
sServiceName);
     rtl::Reference<SwXFieldmark> createFieldmark(std::u16string_view 
sServiceName);
+    /// returns either SwXDocumentIndex or SwXTextSection
+    rtl::Reference<SwXSection> createSection(std::u16string_view rObjectType);
     rtl::Reference<SwXDocumentSettings> createDocumentSettings();
     rtl::Reference<SwXTextDefaults> createTextDefaults();
     rtl::Reference<SwXBookmark> createBookmark();
diff --git a/sw/source/core/inc/unoidx.hxx b/sw/source/core/inc/unoidx.hxx
index 89bdfc390bfe..00049859376a 100644
--- a/sw/source/core/inc/unoidx.hxx
+++ b/sw/source/core/inc/unoidx.hxx
@@ -32,6 +32,8 @@
 
 #include <toxe.hxx>
 #include <unobaseclass.hxx>
+#include "unosection.hxx"
+#include <swdllapi.h>
 
 class SwDoc;
 class SwTOXBaseSection;
@@ -39,15 +41,12 @@ class SwTOXMark;
 class SwTOXType;
 
 typedef ::cppu::ImplInheritanceHelper
-<   ::sfx2::MetadatableMixin
-,   css::lang::XServiceInfo
-,   css::beans::XPropertySet
-,   css::container::XNamed
+<   SwXSection
 ,   css::util::XRefreshable
 ,   css::text::XDocumentIndex
 > SwXDocumentIndex_Base;
 
-class SwXDocumentIndex final
+class SW_DLLPUBLIC SwXDocumentIndex final
     : public SwXDocumentIndex_Base
 {
 
diff --git a/sw/source/core/inc/unosection.hxx 
b/sw/source/core/inc/unosection.hxx
index 209b905e162a..2f33556212ee 100644
--- a/sw/source/core/inc/unosection.hxx
+++ b/sw/source/core/inc/unosection.hxx
@@ -39,9 +39,23 @@ typedef ::cppu::ImplInheritanceHelper
 <   ::sfx2::MetadatableMixin
 ,   css::lang::XServiceInfo
 ,   css::beans::XPropertySet
+,   css::container::XNamed
+,   css::text::XTextContent
+> SwXSection_Base;
+
+/// Base class for SwXTextSection and SwXDocumentIndex
+class SW_DLLPUBLIC SwXSection
+    : public SwXSection_Base
+{
+public:
+    ~SwXSection();
+};
+
+
+typedef ::cppu::ImplInheritanceHelper
+<   SwXSection
 ,   css::beans::XPropertyState
 ,   css::beans::XMultiPropertySet
-,   css::container::XNamed
 ,   css::text::XTextSection
 > SwXTextSection_Base;
 
diff --git a/sw/source/core/unocore/unosect.cxx 
b/sw/source/core/unocore/unosect.cxx
index db754dba86a4..779013032727 100644
--- a/sw/source/core/unocore/unosect.cxx
+++ b/sw/source/core/unocore/unosect.cxx
@@ -216,6 +216,8 @@ SwXTextSection::CreateXTextSection(
     return xSection;
 }
 
+SwXSection::~SwXSection() {}
+
 SwXTextSection::SwXTextSection(
         SwSectionFormat *const pFormat, const bool bIndexHeader)
     : m_pImpl( new SwXTextSection::Impl(*this, pFormat, bIndexHeader) )
diff --git a/sw/source/uibase/uno/unotxdoc.cxx 
b/sw/source/uibase/uno/unotxdoc.cxx
index 7365585a7fce..e963b890bbfd 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -1678,6 +1678,17 @@ rtl::Reference<SwXFieldmark> 
SwXTextDocument::createFieldmark(
     return xTextField;
 }
 
+rtl::Reference< SwXSection > 
SwXTextDocument::createSection(std::u16string_view rObjectType)
+{
+    SolarMutexGuard aGuard;
+    ThrowIfInvalid();
+    const SwServiceType nType = 
SwXServiceProvider::GetProviderType(rObjectType);
+    assert(nType != SwServiceType::Invalid);
+    auto xTmp = SwXServiceProvider::MakeInstance(nType, GetDocOrThrow());
+    assert(!xTmp || dynamic_cast<SwXDocumentIndex*>(xTmp.get()) || 
dynamic_cast<SwXTextSection*>(xTmp.get()));
+    return dynamic_cast<SwXSection*>(xTmp.get());
+}
+
 rtl::Reference<SwXFieldMaster> SwXTextDocument::createFieldMaster(
     std::u16string_view rServiceName)
 {
diff --git a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx 
b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx
index 74465d781ec2..2895c4cdd167 100644
--- a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx
+++ b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx
@@ -7023,8 +7023,8 @@ OUString DomainMapper_Impl::extractTocTitle()
     return OUString();
 }
 
-css::uno::Reference<css::beans::XPropertySet>
-DomainMapper_Impl::StartIndexSectionChecked(const OUString& sServiceName)
+rtl::Reference<SwXSection>
+DomainMapper_Impl::StartIndexSectionChecked(std::u16string_view sServiceName)
 {
     if (m_StreamStateStack.top().bParaChanged)
     {
@@ -7233,7 +7233,7 @@ void DomainMapper_Impl::handleToc
 
     const OUString aTocTitle = extractTocTitle();
 
-    uno::Reference<beans::XPropertySet> xTOC;
+    rtl::Reference<SwXSection> xTOC;
 
     if (m_xTextDocument && ! m_aTextAppendStack.empty())
     {
@@ -7264,7 +7264,7 @@ void DomainMapper_Impl::handleToc
             m_xTOCMarkerCursor = xText->createTextCursor();
 
             // create header of the TOC with the TOC title inside
-            createSectionForRange(m_StreamStateStack.top().xSdtEntryStart, 
xTextRangeEndOfTocHeader, u"com.sun.star.text.IndexHeaderSection"_ustr, true);
+            createSectionForRange(m_StreamStateStack.top().xSdtEntryStart, 
xTextRangeEndOfTocHeader, u"com.sun.star.text.IndexHeaderSection", true);
         }
     }
 
@@ -7443,54 +7443,49 @@ void DomainMapper_Impl::handleToc
     }
 }
 
-uno::Reference<beans::XPropertySet> DomainMapper_Impl::createSectionForRange(
+rtl::Reference<SwXSection> DomainMapper_Impl::createSectionForRange(
     uno::Reference< css::text::XTextRange > xStart,
     uno::Reference< css::text::XTextRange > xEnd,
-    const OUString & sObjectType,
+    std::u16string_view sObjectType,
     bool stepLeft)
 {
     if (!xStart.is())
-        return uno::Reference<beans::XPropertySet>();
+        return {};
     if (!xEnd.is())
-        return uno::Reference<beans::XPropertySet>();
+        return {};
 
-    uno::Reference< beans::XPropertySet > xRet;
     if (m_aTextAppendStack.empty())
-        return xRet;
+        return {};
     uno::Reference< text::XTextAppend >  xTextAppend = 
m_aTextAppendStack.top().xTextAppend;
-    if(xTextAppend.is())
+    if(!xTextAppend)
+        return {};
+    rtl::Reference< SwXSection > xSection;
+    try
     {
-        try
-        {
-            uno::Reference< text::XParagraphCursor > xCursor(
-                xTextAppend->createTextCursorByRange( xStart ), 
uno::UNO_QUERY_THROW);
-            //the cursor has been moved to the end of the paragraph because of 
the appendTextPortion() calls
-            xCursor->gotoStartOfParagraph( false );
-            xCursor->gotoRange( xEnd, true );
-            //the paragraph after this new section is already inserted
-            if (stepLeft)
-                xCursor->goLeft(1, true);
-            uno::Reference< text::XTextContent > xSection( 
m_xTextDocument->createInstance(sObjectType), uno::UNO_QUERY_THROW );
-            try
-            {
-                xSection->attach( uno::Reference< text::XTextRange >( xCursor, 
uno::UNO_QUERY_THROW) );
-            }
-            catch(const uno::Exception&)
-            {
-            }
-            xRet.set(xSection, uno::UNO_QUERY );
-        }
-        catch(const uno::Exception&)
-        {
-        }
+        uno::Reference< text::XParagraphCursor > xCursor(
+            xTextAppend->createTextCursorByRange( xStart ), uno::UNO_QUERY );
+        if(!xCursor)
+            return {};
+        //the cursor has been moved to the end of the paragraph because of the 
appendTextPortion() calls
+        xCursor->gotoStartOfParagraph( false );
+        xCursor->gotoRange( xEnd, true );
+        //the paragraph after this new section is already inserted
+        if (stepLeft)
+            xCursor->goLeft(1, true);
+        xSection = m_xTextDocument->createSection(sObjectType);
+        if (!xSection)
+            return {};
+        xSection->attach( xCursor );
     }
-
-    return xRet;
+    catch(const uno::Exception&)
+    {
+    }
+    return xSection;
 }
 
 void DomainMapper_Impl::handleBibliography
     (const FieldContextPtr& pContext,
-    const OUString & sTOCServiceName)
+    std::u16string_view sTOCServiceName)
 {
     if (m_aTextAppendStack.empty())
     {
@@ -7510,8 +7505,7 @@ void DomainMapper_Impl::handleBibliography
     pContext->SetTOC( xTOC );
     m_StreamStateStack.top().bParaHadField = false;
 
-    uno::Reference< text::XTextContent > xToInsert( xTOC, uno::UNO_QUERY );
-    appendTextContent(xToInsert, uno::Sequence< beans::PropertyValue >() );
+    appendTextContent(xTOC, uno::Sequence< beans::PropertyValue >() );
 }
 
 void DomainMapper_Impl::handleIndex
@@ -7553,8 +7547,7 @@ void DomainMapper_Impl::handleIndex
     pContext->SetTOC( xTOC );
     m_StreamStateStack.top().bParaHadField = false;
 
-    uno::Reference< text::XTextContent > xToInsert( xTOC, uno::UNO_QUERY );
-    appendTextContent(xToInsert, uno::Sequence< beans::PropertyValue >() );
+    appendTextContent(xTOC, uno::Sequence< beans::PropertyValue >() );
 
     if( lcl_FindInCommand( pContext->GetCommand(), 'c', sValue ))
     {
@@ -8871,8 +8864,7 @@ void DomainMapper_Impl::PopFieldContext()
         {
             try
             {
-                uno::Reference< text::XTextContent > xToInsert( 
pContext->GetTOC(), uno::UNO_QUERY );
-                if( xToInsert.is() )
+                if( pContext->GetTOC().is() )
                 {
                     if (m_bStartedTOC || m_bStartIndex || m_bStartBibliography)
                     {
@@ -8913,7 +8905,7 @@ void DomainMapper_Impl::PopFieldContext()
                 }
                 else
                 {
-                    xToInsert.set(pContext->GetTC(), uno::UNO_QUERY);
+                    uno::Reference< text::XTextContent > 
xToInsert(pContext->GetTC(), uno::UNO_QUERY);
                     if (!xToInsert.is() && !IsInTOC() && !m_bStartIndex && 
!m_bStartBibliography)
                         xToInsert = pContext->GetTextField();
                     if (xToInsert.is() && !IsInTOC() && !m_bStartIndex && 
!m_bStartBibliography)
diff --git a/sw/source/writerfilter/dmapper/DomainMapper_Impl.hxx 
b/sw/source/writerfilter/dmapper/DomainMapper_Impl.hxx
index de95d961fe5e..109cc2723c7c 100644
--- a/sw/source/writerfilter/dmapper/DomainMapper_Impl.hxx
+++ b/sw/source/writerfilter/dmapper/DomainMapper_Impl.hxx
@@ -53,6 +53,7 @@
 #include "FFDataHandler.hxx"
 #include "SmartTagHandler.hxx"
 #include "FormControlHelper.hxx"
+#include <unoidx.hxx>
 #include <unobookmark.hxx>
 #include <map>
 
@@ -312,7 +313,7 @@ private:
 
     css::uno::Reference<css::text::XTextField> m_xTextField;
     rtl::Reference<SwXFieldmark> m_xFormField;
-    css::uno::Reference<css::beans::XPropertySet> m_xTOC;
+    rtl::Reference<SwXSection> m_xTOC;
     css::uno::Reference<css::beans::XPropertySet> m_xTC; // TOX entry
     css::uno::Reference<css::beans::XPropertySet> m_xCustomField;
 
@@ -362,8 +363,8 @@ public:
     const rtl::Reference<SwXFieldmark>& GetFormField() const { return 
m_xFormField;}
     void SetFormField(rtl::Reference<SwXFieldmark> const& xFormField) { 
m_xFormField = xFormField;}
 
-    void SetTOC(css::uno::Reference<css::beans::XPropertySet> const& xTOC) { 
m_xTOC = xTOC; }
-    const css::uno::Reference<css::beans::XPropertySet>& GetTOC() const { 
return m_xTOC; }
+    void SetTOC(rtl::Reference<SwXSection> const& xTOC) { m_xTOC = xTOC; }
+    const rtl::Reference<SwXSection>& GetTOC() const { return m_xTOC; }
 
     void SetTC(css::uno::Reference<css::beans::XPropertySet> const& xTC) { 
m_xTC = xTC; }
     const css::uno::Reference<css::beans::XPropertySet>& GetTC() const { 
return m_xTC; }
@@ -1012,7 +1013,7 @@ public:
 
     void handleBibliography
         (const FieldContextPtr& pContext,
-        const OUString & sTOCServiceName);
+        std::u16string_view sTOCServiceName);
     /// The field command has to be closed (cFieldSep appeared).
     void CloseFieldCommand();
     //the _current_ fields require a string type result while TOCs accept 
richt results
@@ -1027,7 +1028,10 @@ public:
 
     /// Returns title of the TOC placed in paragraph(s) before TOC field 
inside STD-frame
     OUString extractTocTitle();
-    css::uno::Reference<css::beans::XPropertySet> 
createSectionForRange(css::uno::Reference< css::text::XTextRange > xStart, 
css::uno::Reference< css::text::XTextRange > xEnd, const OUString & 
sObjectType, bool stepLeft);
+    rtl::Reference<SwXSection> createSectionForRange(
+            css::uno::Reference< css::text::XTextRange > xStart,
+            css::uno::Reference< css::text::XTextRange > xEnd,
+            std::u16string_view sObjectType, bool stepLeft);
 
     void SetBookmarkName( const OUString& rBookmarkName );
     void StartOrEndBookmark( const OUString& rId );
@@ -1275,7 +1279,7 @@ public:
 private:
     void PushPageHeaderFooter(PagePartType ePagePartType, PageType eType);
     // Start a new index section; if needed, finish current paragraph
-    css::uno::Reference<css::beans::XPropertySet> 
StartIndexSectionChecked(const OUString& sServiceName);
+    rtl::Reference<SwXSection> StartIndexSectionChecked(std::u16string_view 
sServiceName);
     std::vector<css::uno::Reference< css::drawing::XShape > > 
m_vTextFramesForChaining ;
     /// SAXException was seen so document will be abandoned
     bool m_bSaxError;

Reply via email to