sw/inc/unoframe.hxx                      |   11 +----------
 sw/inc/unotbl.hxx                        |    7 +------
 sw/inc/unotext.hxx                       |    8 --------
 sw/source/core/inc/unofootnote.hxx       |   10 +---------
 sw/source/core/unocore/unocrsrhelper.cxx |    6 ++----
 sw/source/core/unocore/unodraw.cxx       |    4 ++--
 sw/source/core/unocore/unoframe.cxx      |   23 +----------------------
 sw/source/core/unocore/unoftn.cxx        |   13 -------------
 sw/source/core/unocore/unoobj.cxx        |    2 +-
 sw/source/core/unocore/unoobj2.cxx       |    2 +-
 sw/source/core/unocore/unotbl.cxx        |   11 -----------
 sw/source/core/unocore/unotext.cxx       |   26 +-------------------------
 sw/source/filter/xml/xmlexp.cxx          |    4 +---
 sw/source/filter/xml/xmlimp.cxx          |    4 +---
 sw/source/filter/xml/xmltexte.cxx        |    4 +---
 sw/source/filter/xml/xmltexti.cxx        |    4 +---
 sw/source/uibase/uno/unoatxt.cxx         |    4 ++--
 17 files changed, 17 insertions(+), 126 deletions(-)

New commits:
commit 4dac12efdce4f5cd83fd78a901186c68f020b7fa
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Jan 18 10:40:34 2023 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Jan 19 10:44:06 2023 +0000

    XUnoTunnel->dynamic_cast for SwXFrame
    
    Change-Id: I48fd10781e7f09b37b6b0000f68456e8194e6d7a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145761
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/inc/unoframe.hxx b/sw/inc/unoframe.hxx
index e87cb87e0675..7c62cc7ba2a5 100644
--- a/sw/inc/unoframe.hxx
+++ b/sw/inc/unoframe.hxx
@@ -45,10 +45,9 @@ class SfxItemPropertySet;
 namespace com::sun::star::frame { class XModel; }
 
 class BaseFrameProperties_Impl;
-class SAL_DLLPUBLIC_RTTI SwXFrame : public cppu::WeakImplHelper
+class SAL_DLLPUBLIC_RTTI SAL_LOPLUGIN_ANNOTATE("crosscast") SwXFrame : public 
cppu::WeakImplHelper
 <
     css::lang::XServiceInfo,
-    css::lang::XUnoTunnel,
     css::beans::XPropertySet,
     css::beans::XPropertyState,
     css::drawing::XShape,
@@ -97,11 +96,6 @@ protected:
     CreateXFrame(SwDoc & rDoc, SwFrameFormat *const pFrameFormat);
 
 public:
-    static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId();
-
-    //XUnoTunnel
-    virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< 
sal_Int8 >& aIdentifier ) override;
-
 
     //XNamed
     virtual OUString SAL_CALL getName() override;
@@ -234,9 +228,6 @@ public:
     // XEventsSupplier
     virtual css::uno::Reference< css::container::XNameReplace > SAL_CALL 
getEvents(  ) override;
 
-    //XUnoTunnel
-    virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< 
sal_Int8 >& aIdentifier ) override;
-
     //XPropertySet
     virtual SW_DLLPUBLIC css::uno::Any SAL_CALL getPropertyValue( const 
OUString& PropertyName ) override;
     using SwXFrame::setPropertyValue;
diff --git a/sw/inc/unotbl.hxx b/sw/inc/unotbl.hxx
index 160d29290d8d..4bd7e2efe118 100644
--- a/sw/inc/unotbl.hxx
+++ b/sw/inc/unotbl.hxx
@@ -20,6 +20,7 @@
 #ifndef INCLUDED_SW_INC_UNOTBL_HXX
 #define INCLUDED_SW_INC_UNOTBL_HXX
 
+#include <com/sun/star/lang/XUnoTunnel.hpp>
 #include <com/sun/star/container/XNamed.hpp>
 #include <com/sun/star/container/XEnumerationAccess.hpp>
 #include <com/sun/star/util/XSortable.hpp>
@@ -89,12 +90,6 @@ public:
     SwXCell(SwFrameFormat* pTableFormat, SwTableBox* pBox, size_t nPos);
     SwXCell(SwFrameFormat* pTableFormat, const SwStartNode& rStartNode); // 
XML import interface
 
-
-    static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId();
-
-    //XUnoTunnel
-    virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< 
sal_Int8 >& aIdentifier ) override;
-
     virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType 
) override;
     virtual void SAL_CALL acquire(  ) noexcept override;
     virtual void SAL_CALL release(  ) noexcept override;
diff --git a/sw/inc/unotext.hxx b/sw/inc/unotext.hxx
index 8bc221b7fa63..ddd16012d225 100644
--- a/sw/inc/unotext.hxx
+++ b/sw/inc/unotext.hxx
@@ -20,7 +20,6 @@
 #ifndef INCLUDED_SW_INC_UNOTEXT_HXX
 #define INCLUDED_SW_INC_UNOTEXT_HXX
 
-#include <com/sun/star/lang/XUnoTunnel.hpp>
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/text/XTextCopy.hpp>
 #include <com/sun/star/text/XTextRangeCompare.hpp>
@@ -44,7 +43,6 @@ class SwPaM;
 
 class SAL_DLLPUBLIC_RTTI SwXText
     : public css::lang::XTypeProvider
-    , public css::lang::XUnoTunnel
     , public css::beans::XPropertySet
     , public css::text::XTextAppendAndConvert
     , public css::text::XTextCopy
@@ -96,12 +94,6 @@ public:
     virtual css::uno::Sequence< css::uno::Type >
         SAL_CALL getTypes() override;
 
-    static const css::uno::Sequence< sal_Int8 >& getUnoTunnelId();
-
-    // XUnoTunnel
-    virtual sal_Int64 SAL_CALL getSomething(
-            const css::uno::Sequence< sal_Int8 >& rIdentifier) override;
-
     // XPropertySet
     virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL
         getPropertySetInfo() override;
diff --git a/sw/source/core/inc/unofootnote.hxx 
b/sw/source/core/inc/unofootnote.hxx
index 0303ee12335b..b10a3555674c 100644
--- a/sw/source/core/inc/unofootnote.hxx
+++ b/sw/source/core/inc/unofootnote.hxx
@@ -20,7 +20,6 @@
 #ifndef INCLUDED_SW_SOURCE_CORE_INC_UNOFOOTNOTE_HXX
 #define INCLUDED_SW_SOURCE_CORE_INC_UNOFOOTNOTE_HXX
 
-#include <com/sun/star/lang/XUnoTunnel.hpp>
 #include <com/sun/star/lang/XServiceInfo.hpp>
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/container/XEnumerationAccess.hpp>
@@ -34,8 +33,7 @@ class SwDoc;
 class SwFormatFootnote;
 
 typedef ::cppu::WeakImplHelper
-<   css::lang::XUnoTunnel
-,   css::lang::XServiceInfo
+<   css::lang::XServiceInfo
 ,   css::beans::XPropertySet
 ,   css::container::XEnumerationAccess
 ,   css::text::XFootnote
@@ -77,12 +75,6 @@ public:
     virtual css::uno::Sequence< sal_Int8 > SAL_CALL
         getImplementationId() override;
 
-    static const css::uno::Sequence< sal_Int8 >& getUnoTunnelId();
-
-    // XUnoTunnel
-    virtual sal_Int64 SAL_CALL getSomething(
-            const css::uno::Sequence< sal_Int8 >& rIdentifier) override;
-
     // XServiceInfo
     virtual OUString SAL_CALL getImplementationName() override;
     virtual sal_Bool SAL_CALL supportsService(
diff --git a/sw/source/core/unocore/unocrsrhelper.cxx 
b/sw/source/core/unocore/unocrsrhelper.cxx
index db63dfb52848..18e8ddb54dd6 100644
--- a/sw/source/core/unocore/unocrsrhelper.cxx
+++ b/sw/source/core/unocore/unocrsrhelper.cxx
@@ -191,8 +191,7 @@ void GetSelectableFromAny(uno::Reference<uno::XInterface> 
const& xIfc,
 
     // check these before Range to prevent misinterpretation of text frames
     // and cells also implement XTextRange
-    SwXFrame *const pFrame(
-        comphelper::getFromUnoTunnel<SwXFrame>(xTunnel));
+    SwXFrame *const pFrame = dynamic_cast<SwXFrame*>(xIfc.get());
     if (pFrame)
     {
         const SwFrameFormat *const pFrameFormat(pFrame->GetFrameFormat());
@@ -215,8 +214,7 @@ void GetSelectableFromAny(uno::Reference<uno::XInterface> 
const& xIfc,
         return;
     }
 
-    SwXCell *const pCell(
-        comphelper::getFromUnoTunnel<SwXCell>(xTunnel));
+    SwXCell *const pCell = dynamic_cast<SwXCell*>(xIfc.get());
     if (pCell)
     {
         SwFrameFormat *const pFrameFormat(pCell->GetFrameFormat());
diff --git a/sw/source/core/unocore/unodraw.cxx 
b/sw/source/core/unocore/unodraw.cxx
index 068f18fd08ae..76355ce44a9e 100644
--- a/sw/source/core/unocore/unodraw.cxx
+++ b/sw/source/core/unocore/unodraw.cxx
@@ -999,7 +999,7 @@ void SwXShape::setPropertyValue(const OUString& 
rPropertyName, const uno::Any& a
                 uno::Reference<text::XTextFrame> xFrame;
                 if(aValue >>= xFrame)
                 {
-                    SwXFrame* pFrame = 
comphelper::getFromUnoTunnel<SwXFrame>(xFrame);
+                    SwXFrame* pFrame = dynamic_cast<SwXFrame*>(xFrame.get());
                     if(pFrame && pFrame->GetFrameFormat() &&
                         pFrame->GetFrameFormat()->GetDoc() == pDoc)
                     {
@@ -2005,7 +2005,7 @@ void SwXShape::attach(const uno::Reference< 
text::XTextRange > & xTextRange)
     uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY);
     if (auto pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel))
         pDoc = &pRange->GetDoc();
-    else if (auto pText = comphelper::getFromUnoTunnel<SwXText>(xRangeTunnel))
+    else if (auto pText = dynamic_cast<SwXText*>(xTextRange.get()))
         pDoc = pText->GetDoc();
     else if (auto pCursor = dynamic_cast<OTextCursorHelper*>(xTextRange.get()))
         pDoc = pCursor->GetDoc();
diff --git a/sw/source/core/unocore/unoframe.cxx 
b/sw/source/core/unocore/unoframe.cxx
index e8a884623663..b81ba90f40d9 100644
--- a/sw/source/core/unocore/unoframe.cxx
+++ b/sw/source/core/unocore/unoframe.cxx
@@ -1166,18 +1166,6 @@ public:
     ::comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> 
m_EventListeners;
 };
 
-const ::uno::Sequence< sal_Int8 > & SwXFrame::getUnoTunnelId()
-{
-    static const comphelper::UnoIdInit theSwXFrameUnoTunnelId;
-    return theSwXFrameUnoTunnelId.getSeq();
-}
-
-sal_Int64 SAL_CALL SwXFrame::getSomething( const ::uno::Sequence< sal_Int8 >& 
rId )
-{
-    return comphelper::getSomethingImpl(rId, this);
-}
-
-
 OUString SwXFrame::getImplementationName()
 {
     return "SwXFrame";
@@ -1740,7 +1728,7 @@ void SwXFrame::setPropertyValue(const OUString& 
rPropertyName, const ::uno::Any&
             uno::Reference<text::XTextFrame> xFrame;
             if(aValue >>= xFrame)
             {
-                SwXFrame* pFrame = 
comphelper::getFromUnoTunnel<SwXFrame>(xFrame);
+                SwXFrame* pFrame = dynamic_cast<SwXFrame*>(xFrame.get());
                 if(pFrame && this != pFrame && pFrame->GetFrameFormat() && 
pFrame->GetFrameFormat()->GetDoc() == pDoc)
                 {
                     SfxItemSetFixed<RES_FRMATR_BEGIN, RES_FRMATR_END - 1> 
aSet( pDoc->GetAttrPool() );
@@ -3424,15 +3412,6 @@ uno::Reference<container::XNameReplace > SAL_CALL 
SwXTextFrame::getEvents()
     return new SwFrameEventDescriptor( *this );
 }
 
-sal_Int64 SAL_CALL SwXTextFrame::getSomething( const uno::Sequence< sal_Int8 
>& rId )
-{
-    sal_Int64 nRet = SwXFrame::getSomething( rId );
-    if( !nRet )
-        nRet = SwXText::getSomething( rId );
-
-    return nRet;
-}
-
 ::uno::Any SwXTextFrame::getPropertyValue(const OUString& rPropertyName)
 {
     SolarMutexGuard aGuard;
diff --git a/sw/source/core/unocore/unoftn.cxx 
b/sw/source/core/unocore/unoftn.cxx
index 484db986d2ff..f27b8aa5ca80 100644
--- a/sw/source/core/unocore/unoftn.cxx
+++ b/sw/source/core/unocore/unoftn.cxx
@@ -163,19 +163,6 @@ SwXFootnote::CreateXFootnote(SwDoc & rDoc, 
SwFormatFootnote *const pFootnoteForm
     return xNote;
 }
 
-const uno::Sequence< sal_Int8 > & SwXFootnote::getUnoTunnelId()
-{
-    static const comphelper::UnoIdInit theSwXFootnoteUnoTunnelId;
-    return theSwXFootnoteUnoTunnelId.getSeq();
-}
-
-sal_Int64 SAL_CALL
-SwXFootnote::getSomething(const uno::Sequence< sal_Int8 >& rId)
-{
-    const sal_Int64 nRet( comphelper::getSomethingImpl<SwXFootnote>(rId, this) 
);
-    return nRet ? nRet : SwXText::getSomething(rId);
-}
-
 OUString SAL_CALL
 SwXFootnote::getImplementationName()
 {
diff --git a/sw/source/core/unocore/unoobj.cxx 
b/sw/source/core/unocore/unoobj.cxx
index 3ec3f1d7012b..4d50250341bf 100644
--- a/sw/source/core/unocore/unoobj.cxx
+++ b/sw/source/core/unocore/unoobj.cxx
@@ -3082,7 +3082,7 @@ SwXTextCursor::createEnumeration()
 
     SwUnoCursor & rUnoCursor( GetCursorOrThrow() );
 
-    SwXText* pParentText = 
comphelper::getFromUnoTunnel<SwXText>(m_xParentText);
+    SwXText* pParentText = dynamic_cast<SwXText*>(m_xParentText.get());
     OSL_ENSURE(pParentText, "parent is not a SwXText");
     if (!pParentText)
     {
diff --git a/sw/source/core/unocore/unoobj2.cxx 
b/sw/source/core/unocore/unoobj2.cxx
index e85df86d26c8..a40e92a92cec 100644
--- a/sw/source/core/unocore/unoobj2.cxx
+++ b/sw/source/core/unocore/unoobj2.cxx
@@ -1110,7 +1110,7 @@ bool XTextRangeToSwPaM( SwUnoInternalPaM & rToFill,
     SwXTextRange* pRange = 
comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel);
     OTextCursorHelper* pCursor = 
dynamic_cast<OTextCursorHelper*>(xTextRange.get());
     SwXTextPortion* pPortion = 
comphelper::getFromUnoTunnel<SwXTextPortion>(xRangeTunnel);
-    SwXText* pText = comphelper::getFromUnoTunnel<SwXText>(xRangeTunnel);
+    SwXText* pText = dynamic_cast<SwXText*>(xTextRange.get());
     SwXParagraph* pPara = 
comphelper::getFromUnoTunnel<SwXParagraph>(xRangeTunnel);
     SwXHeadFootText* pHeadText
         = eMode == TextRangeMode::AllowTableNode ? 
dynamic_cast<SwXHeadFootText*>(pText) : nullptr;
diff --git a/sw/source/core/unocore/unotbl.cxx 
b/sw/source/core/unocore/unotbl.cxx
index 5858975d6cf5..12de30955116 100644
--- a/sw/source/core/unocore/unotbl.cxx
+++ b/sw/source/core/unocore/unotbl.cxx
@@ -743,17 +743,6 @@ SwXCell::~SwXCell()
     EndListeningAll();
 }
 
-const uno::Sequence< sal_Int8 > & SwXCell::getUnoTunnelId()
-{
-    static const comphelper::UnoIdInit theSwXCellUnoTunnelId;
-    return theSwXCellUnoTunnelId.getSeq();
-}
-
-sal_Int64 SAL_CALL SwXCell::getSomething( const uno::Sequence< sal_Int8 >& rId 
)
-{
-    return comphelper::getSomethingImpl(rId, this, 
comphelper::FallbackToGetSomethingOf<SwXText>{});
-}
-
 uno::Sequence< uno::Type > SAL_CALL SwXCell::getTypes(  )
 {
     return comphelper::concatSequences(
diff --git a/sw/source/core/unocore/unotext.cxx 
b/sw/source/core/unocore/unotext.cxx
index c14829af6261..b38c14c9e5fe 100644
--- a/sw/source/core/unocore/unotext.cxx
+++ b/sw/source/core/unocore/unotext.cxx
@@ -198,10 +198,6 @@ SwXText::queryInterface(const uno::Type& rType)
     {
         aRet <<= uno::Reference< text::XText >(this);
     }
-    else if (rType == cppu::UnoType<lang::XUnoTunnel>::get())
-    {
-        aRet <<= uno::Reference< lang::XUnoTunnel >(this);
-    }
     else if (rType == cppu::UnoType<text::XSimpleText>::get())
     {
         aRet <<= uno::Reference< text::XSimpleText >(this);
@@ -579,12 +575,6 @@ SwXText::insertTextContent(
     // instead are "overlaid"
     const uno::Reference<lang::XUnoTunnel> xContentTunnel(xContent,
             uno::UNO_QUERY);
-    if (!xContentTunnel.is())
-    {
-        lang::IllegalArgumentException aArgException;
-        aArgException.Message = "text content does not support 
lang::XUnoTunnel";
-        throw aArgException;
-    }
     SwXDocumentIndexMark *const pDocumentIndexMark =
         comphelper::getFromUnoTunnel<SwXDocumentIndexMark>(xContentTunnel);
     SwXTextSection *const pSection =
@@ -1214,18 +1204,6 @@ namespace
 {
 }
 
-const uno::Sequence< sal_Int8 > & SwXText::getUnoTunnelId()
-{
-    static const comphelper::UnoIdInit theSwXTextUnoTunnelId;
-    return theSwXTextUnoTunnelId.getSeq();
-}
-
-sal_Int64 SAL_CALL
-SwXText::getSomething(const uno::Sequence< sal_Int8 >& rId)
-{
-    return comphelper::getSomethingImpl<SwXText>(rId, this);
-}
-
 uno::Reference< text::XTextRange > SAL_CALL
 SwXText::finishParagraph(
         const uno::Sequence< beans::PropertyValue > & rProperties)
@@ -2357,9 +2335,7 @@ SwXText::copyText(
 {
     SolarMutexGuard aGuard;
 
-    uno::Reference<lang::XUnoTunnel> const xSourceTunnel(xSource,
-        uno::UNO_QUERY);
-    SwXText const* const 
pSource(comphelper::getFromUnoTunnel<SwXText>(xSourceTunnel));
+    SwXText const* const pSource(dynamic_cast<SwXText*>(xSource.get()));
 
     uno::Reference< text::XText > const xText(xSource, uno::UNO_QUERY_THROW);
     uno::Reference< text::XTextCursor > const xCursor =
diff --git a/sw/source/filter/xml/xmlexp.cxx b/sw/source/filter/xml/xmlexp.cxx
index 8edb4f520785..ff8cc2ed2c49 100644
--- a/sw/source/filter/xml/xmlexp.cxx
+++ b/sw/source/filter/xml/xmlexp.cxx
@@ -520,9 +520,7 @@ SwDoc* SwXMLExport::getDoc()
     }
 
     Reference < XText > xText = xTextDoc->getText();
-    Reference<XUnoTunnel> xTextTunnel( xText, UNO_QUERY);
-    assert( xTextTunnel.is());
-    SwXText* pText = comphelper::getFromUnoTunnel<SwXText>(xTextTunnel);
+    SwXText* pText = dynamic_cast<SwXText*>(xText.get());
     assert( pText != nullptr );
     m_pDoc = pText->GetDoc();
     assert( m_pDoc != nullptr );
diff --git a/sw/source/filter/xml/xmlimp.cxx b/sw/source/filter/xml/xmlimp.cxx
index 9233886fe0b8..44c890eb3df8 100644
--- a/sw/source/filter/xml/xmlimp.cxx
+++ b/sw/source/filter/xml/xmlimp.cxx
@@ -1656,9 +1656,7 @@ SwDoc* SwXMLImport::getDoc()
         return m_pDoc;
     Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
     Reference < XText > xText = xTextDoc->getText();
-    Reference<XUnoTunnel> xTextTunnel( xText, UNO_QUERY);
-    assert( xTextTunnel.is());
-    SwXText* pText = comphelper::getFromUnoTunnel<SwXText>(xTextTunnel);
+    SwXText* pText = dynamic_cast<SwXText*>(xText.get());
     assert( pText != nullptr );
     m_pDoc = pText->GetDoc();
     assert( m_pDoc != nullptr );
diff --git a/sw/source/filter/xml/xmltexte.cxx 
b/sw/source/filter/xml/xmltexte.cxx
index 2fd9e9c40376..3161d416797c 100644
--- a/sw/source/filter/xml/xmltexte.cxx
+++ b/sw/source/filter/xml/xmltexte.cxx
@@ -68,9 +68,7 @@ enum SvEmbeddedObjectTypes
 SwNoTextNode *SwXMLTextParagraphExport::GetNoTextNode(
     const Reference < XPropertySet >& rPropSet )
 {
-    Reference<XUnoTunnel> xCursorTunnel( rPropSet, UNO_QUERY );
-    assert(xCursorTunnel.is() && "missing XUnoTunnel for embedded");
-    SwXFrame* pFrame = comphelper::getFromUnoTunnel<SwXFrame>(xCursorTunnel);
+    SwXFrame* pFrame = dynamic_cast<SwXFrame*>(rPropSet.get());
     assert(pFrame && "SwXFrame missing");
     SwFrameFormat *pFrameFormat = pFrame->GetFrameFormat();
     const SwFormatContent& rContent = pFrameFormat->GetContent();
diff --git a/sw/source/filter/xml/xmltexti.cxx 
b/sw/source/filter/xml/xmltexti.cxx
index 0464c0f26a83..f64fceeaea1f 100644
--- a/sw/source/filter/xml/xmltexti.cxx
+++ b/sw/source/filter/xml/xmltexti.cxx
@@ -872,9 +872,7 @@ void SwXMLTextImportHelper::endAppletOrPlugin(
     // this method will modify the document directly -> lock SolarMutex
     SolarMutexGuard aGuard;
 
-    uno::Reference<XUnoTunnel> xCursorTunnel( rPropSet, UNO_QUERY );
-    assert(xCursorTunnel.is() && "missing XUnoTunnel for embedded");
-    SwXFrame* pFrame = comphelper::getFromUnoTunnel<SwXFrame>(xCursorTunnel);
+    SwXFrame* pFrame = dynamic_cast<SwXFrame*>(rPropSet.get());
     OSL_ENSURE( pFrame, "SwXFrame missing" );
     SwFrameFormat *pFrameFormat = pFrame->GetFrameFormat();
     const SwFormatContent& rContent = pFrameFormat->GetContent();
diff --git a/sw/source/uibase/uno/unoatxt.cxx b/sw/source/uibase/uno/unoatxt.cxx
index 651ecf173cbe..f1358df6b4d8 100644
--- a/sw/source/uibase/uno/unoatxt.cxx
+++ b/sw/source/uibase/uno/unoatxt.cxx
@@ -848,13 +848,13 @@ void SwXAutoTextEntry::applyTo(const uno::Reference< 
text::XTextRange > & xTextR
         // This means that we would reflect any changes which were done to the 
AutoText by foreign instances
         // in the meantime
 
-    // The reference to xTmp is needed during the whole call, likely because 
it could be a
+    // The reference to xKeepAlive is needed during the whole call, likely 
because it could be a
     // different object, not xTextRange itself, and the reference guards it 
from preliminary death
     uno::Reference<text::XTextRange> xKeepAlive( xTextRange );
     uno::Reference<lang::XUnoTunnel> xTunnel( xTextRange, uno::UNO_QUERY);
     SwXTextRange* pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xTunnel);
     OTextCursorHelper* pCursor = 
dynamic_cast<OTextCursorHelper*>(xKeepAlive.get());
-    SwXText *pText = comphelper::getFromUnoTunnel<SwXText>(xTunnel);
+    SwXText *pText = dynamic_cast<SwXText*>(xTextRange.get());
 
     SwDoc* pDoc = nullptr;
     if (pRange)

Reply via email to