sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx |   17 ++++++++---------
 sw/source/writerfilter/dmapper/DomainMapper_Impl.hxx |    7 ++++---
 sw/source/writerfilter/dmapper/FormControlHelper.cxx |   12 +++++-------
 sw/source/writerfilter/dmapper/FormControlHelper.hxx |    3 ++-
 4 files changed, 19 insertions(+), 20 deletions(-)

New commits:
commit 9612789609a74980447cd0309404cecb125374c3
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Tue Aug 6 22:50:11 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Aug 8 15:51:40 2024 +0200

    use more concrete UNO type in writerfilter
    
    Change-Id: I46e94d5329cab5922e4a254277d47519076744ec
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171603
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx 
b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx
index c7453308ed50..60b43c3a2ce5 100644
--- a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx
+++ b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx
@@ -7575,11 +7575,10 @@ void DomainMapper_Impl::handleIndex
 }
 
 static auto InsertFieldmark(std::stack<TextAppendContext> & rTextAppendStack,
-        uno::Reference<text::XFormField> const& xFormField,
+        rtl::Reference<SwXFieldmark> const& xFormField,
         uno::Reference<text::XTextRange> const& xStartRange,
         std::optional<FieldId> const oFieldId) -> void
 {
-    uno::Reference<text::XTextContent> const xTextContent(xFormField, 
uno::UNO_QUERY_THROW);
     uno::Reference<text::XTextAppend> const& 
xTextAppend(rTextAppendStack.top().xTextAppend);
     uno::Reference<text::XTextCursor> const xCursor =
         xTextAppend->createTextCursorByRange(xStartRange);
@@ -7599,7 +7598,7 @@ static auto InsertFieldmark(std::stack<TextAppendContext> 
& rTextAppendStack,
     {
         xCursor->gotoEnd(true);
     }
-    xTextAppend->insertTextContent(xCursor, xTextContent, true);
+    xTextAppend->insertTextContent(xCursor, 
static_cast<SwXBookmark*>(xFormField.get()), true);
     if (oFieldId
         && (oFieldId == FIELD_FORMCHECKBOX || oFieldId == FIELD_FORMDROPDOWN))
     {
@@ -7610,7 +7609,7 @@ static auto InsertFieldmark(std::stack<TextAppendContext> 
& rTextAppendStack,
     // FAIL: AppendTextNode() ignores the content index!
     // plan B: insert a spurious paragraph break now and join
     //         it in PopFieldContext()!
-    xCursor->gotoRange(xTextContent->getAnchor()->getEnd(), false);
+    xCursor->gotoRange(xFormField->getAnchor()->getEnd(), false);
     xCursor->goLeft(1, false); // skip CH_TXT_ATR_FIELDEND
     xTextAppend->insertControlCharacter(xCursor, 
text::ControlCharacter::PARAGRAPH_BREAK, false);
     xCursor->goLeft(1, false); // back to previous paragraph
@@ -7956,7 +7955,7 @@ void DomainMapper_Impl::CloseFieldCommand()
 
                                                     m_xTextDocument, 
pFFDataHandler));
                             pContext->setFormControlHelper(pFormControlHelper);
-                            if ( xFieldmark )
+                            if ( xFieldmark.is() )
                             {
                                 if ( pFFDataHandler && 
!pFFDataHandler->getName().isEmpty() )
                                     xFieldmark->setName(  
pFFDataHandler->getName() );
@@ -8564,7 +8563,7 @@ void DomainMapper_Impl::CloseFieldCommand()
             {
                 rtl::Reference<SwXBookmark> xFieldInterface = 
m_xTextDocument->createFieldmark();
 
-                uno::Reference<text::XFormField> const 
xFormField(static_cast<cppu::OWeakObject*>(xFieldInterface.get()), 
uno::UNO_QUERY);
+                rtl::Reference<SwXFieldmark> xFormField = 
dynamic_cast<SwXFieldmark*>(xFieldInterface.get());
                 InsertFieldmark(m_aTextAppendStack, xFormField, 
pContext->GetStartRange(),
                         pContext->GetFieldId());
                 xFormField->setFieldType(ODF_UNHANDLED);
@@ -8946,10 +8945,10 @@ void DomainMapper_Impl::PopFieldContext()
                             // input, so it makes sense to do the same 
(tdf#152200)
                             if (xCrsr.is())
                             {
-                                uno::Reference< text::XFormField > 
xFormField(pContext->GetFormField());
+                                rtl::Reference< SwXFieldmark > 
xFormField(pContext->GetFormField());
                                 if (pFormControlHelper->hasFFDataHandler())
                                 {
-                                    xToInsert.set(xFormField, uno::UNO_QUERY);
+                                    xToInsert = 
static_cast<SwXBookmark*>(xFormField.get());
                                     if (xFormField.is() && xToInsert.is())
                                     {
                                         PopFieldmark(m_aTextAppendStack, xCrsr,
@@ -8965,7 +8964,7 @@ void DomainMapper_Impl::PopFieldContext()
                                 {
                                     PopFieldmark(m_aTextAppendStack, xCrsr,
                                         pContext->GetFieldId());
-                                    
uno::Reference<lang::XComponent>(xFormField, uno::UNO_QUERY_THROW)->dispose(); 
// presumably invalid?
+                                    xFormField->dispose(); // presumably 
invalid?
                                 }
                             }
                         }
diff --git a/sw/source/writerfilter/dmapper/DomainMapper_Impl.hxx 
b/sw/source/writerfilter/dmapper/DomainMapper_Impl.hxx
index af3f7bd419a1..3d74d76667c7 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 <unobookmark.hxx>
 #include <map>
 
 class SwXTextDocument;
@@ -303,7 +304,7 @@ public:
 private:
 
     css::uno::Reference<css::text::XTextField> m_xTextField;
-    css::uno::Reference<css::text::XFormField> m_xFormField;
+    rtl::Reference<SwXFieldmark> m_xFormField;
     css::uno::Reference<css::beans::XPropertySet> m_xTOC;
     css::uno::Reference<css::beans::XPropertySet> m_xTC; // TOX entry
     css::uno::Reference<css::beans::XPropertySet> m_xCustomField;
@@ -351,8 +352,8 @@ public:
     void SetCustomField(css::uno::Reference<css::beans::XPropertySet> const& 
xCustomField) { m_xCustomField = xCustomField; }
     const css::uno::Reference<css::text::XTextField>& GetTextField() const { 
return m_xTextField;}
     void SetTextField(css::uno::Reference<css::text::XTextField> const& 
xTextField);
-    const css::uno::Reference<css::text::XFormField>& GetFormField() const { 
return m_xFormField;}
-    void SetFormField(css::uno::Reference<css::text::XFormField> const& 
xFormField) { m_xFormField = xFormField;}
+    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; }
diff --git a/sw/source/writerfilter/dmapper/FormControlHelper.cxx 
b/sw/source/writerfilter/dmapper/FormControlHelper.cxx
index adcda594a6ba..1055de840867 100644
--- a/sw/source/writerfilter/dmapper/FormControlHelper.cxx
+++ b/sw/source/writerfilter/dmapper/FormControlHelper.cxx
@@ -43,6 +43,7 @@
 #include <comphelper/diagnose_ex.hxx>
 #include <rtl/ref.hxx>
 #include <unotxdoc.hxx>
+#include <unobookmark.hxx>
 
 namespace writerfilter::dmapper {
 
@@ -189,7 +190,7 @@ bool 
FormControlHelper::createCheckbox(uno::Reference<text::XTextRange> const& x
     return true;
 }
 
-void FormControlHelper::processField(uno::Reference<text::XFormField> const& 
xFormField)
+void FormControlHelper::processField(rtl::Reference<SwXFieldmark> const& 
xFormField)
 {
     // Set field type first before adding parameters.
     if (m_pImpl->m_eFieldId == FIELD_FORMTEXT )
@@ -206,8 +207,7 @@ void 
FormControlHelper::processField(uno::Reference<text::XFormField> const& xFo
     }
 
     uno::Reference<container::XNameContainer> xNameCont = 
xFormField->getParameters();
-    uno::Reference<container::XNamed> xNamed( xFormField, uno::UNO_QUERY );
-    if ( !(m_pFFData && xNamed.is() && xNameCont.is()) )
+    if ( !(m_pFFData && xNameCont.is()) )
         return;
 
     OUString sTmp = m_pFFData->getEntryMacro();
@@ -231,7 +231,7 @@ void 
FormControlHelper::processField(uno::Reference<text::XFormField> const& xFo
         try
         {
             if ( !sTmp.isEmpty() )
-                xNamed->setName( sTmp );
+                xFormField->setName( sTmp );
         }
         catch ( uno::Exception& )
         {
@@ -258,11 +258,9 @@ void 
FormControlHelper::processField(uno::Reference<text::XFormField> const& xFo
     }
     else if (m_pImpl->m_eFieldId == FIELD_FORMCHECKBOX )
     {
-        uno::Reference<beans::XPropertySet> xPropSet(xFormField, 
uno::UNO_QUERY);
         uno::Any aAny;
         aAny <<= m_pFFData->getCheckboxChecked();
-        if ( xPropSet.is() )
-            xPropSet->setPropertyValue(u"Checked"_ustr, aAny);
+        xFormField->setPropertyValue(u"Checked"_ustr, aAny);
     }
     else if (m_pImpl->m_eFieldId == FIELD_FORMDROPDOWN )
     {
diff --git a/sw/source/writerfilter/dmapper/FormControlHelper.hxx 
b/sw/source/writerfilter/dmapper/FormControlHelper.hxx
index 6b0f39dd5ab1..2f1395b6b7ed 100644
--- a/sw/source/writerfilter/dmapper/FormControlHelper.hxx
+++ b/sw/source/writerfilter/dmapper/FormControlHelper.hxx
@@ -26,6 +26,7 @@
 #include <rtl/ref.hxx>
 
 class SwXTextDocument;
+class SwXFieldmark;
 
 namespace writerfilter::dmapper
 {
@@ -38,7 +39,7 @@ public:
     ~FormControlHelper() override;
 
     void insertControl(css::uno::Reference<css::text::XTextRange> const& 
xTextRange);
-    void processField(css::uno::Reference<css::text::XFormField> const& 
xFormField);
+    void processField(rtl::Reference<SwXFieldmark> const& xFormField);
     bool hasFFDataHandler() const { return (m_pFFData != nullptr); }
 
 private:

Reply via email to