diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-05-11 19:19:57 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-05-12 15:33:25 +0200 |
commit | fdcce774409e47b452910d44fcb8a00b1131985c (patch) | |
tree | dd7a74be13468a551d05e3da473b1f626d46fb98 | |
parent | 8be73da2284ffe963a464b4c65db4f2ff5d7f09f (diff) |
use more concrete UNO types in sw/
as preparation for getting rid of some dynamic_casts
Change-Id: I78728325b916af3ec6303f7c8eaf3b8b94cfd74c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151691
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | sw/inc/unoframe.hxx | 8 | ||||
-rw-r--r-- | sw/inc/unoredline.hxx | 13 | ||||
-rw-r--r-- | sw/inc/unotbl.hxx | 8 | ||||
-rw-r--r-- | sw/inc/unotext.hxx | 11 | ||||
-rw-r--r-- | sw/inc/unotextbodyhf.hxx | 20 | ||||
-rw-r--r-- | sw/source/core/inc/unofootnote.hxx | 11 | ||||
-rw-r--r-- | sw/source/core/unocore/unocontentcontrol.cxx | 23 | ||||
-rw-r--r-- | sw/source/core/unocore/unoframe.cxx | 23 | ||||
-rw-r--r-- | sw/source/core/unocore/unoftn.cxx | 25 | ||||
-rw-r--r-- | sw/source/core/unocore/unoobj2.cxx | 17 | ||||
-rw-r--r-- | sw/source/core/unocore/unoredline.cxx | 20 | ||||
-rw-r--r-- | sw/source/core/unocore/unorefmk.cxx | 29 | ||||
-rw-r--r-- | sw/source/core/unocore/unotbl.cxx | 19 | ||||
-rw-r--r-- | sw/source/core/unocore/unotext.cxx | 119 |
14 files changed, 136 insertions, 210 deletions
diff --git a/sw/inc/unoframe.hxx b/sw/inc/unoframe.hxx index 7c62cc7ba2a5..9bd1c03b8b7f 100644 --- a/sw/inc/unoframe.hxx +++ b/sw/inc/unoframe.hxx @@ -174,9 +174,6 @@ class SAL_DLLPUBLIC_RTTI SwXTextFrame final : public SwXTextFrameBaseClass, virtual const SwStartNode *GetStartNode() const override; - virtual css::uno::Reference< css::text::XTextCursor > - CreateCursor() override; - virtual ~SwXTextFrame() override; SwXTextFrame(SwDoc *pDoc); @@ -201,8 +198,9 @@ public: virtual SW_DLLPUBLIC css::uno::Reference< css::text::XText > SAL_CALL getText() override; //XText - virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursor() override; - virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursorByRange(const css::uno::Reference< css::text::XTextRange > & aTextPosition) override; + virtual rtl::Reference< SwXTextCursor > createXTextCursor() override; + virtual rtl::Reference< SwXTextCursor > createXTextCursorByRange( + const ::css::uno::Reference< ::css::text::XTextRange >& aTextPosition ) override; //XEnumerationAccess - frueher XParagraphEnumerationAccess virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override; diff --git a/sw/inc/unoredline.hxx b/sw/inc/unoredline.hxx index 3a7273a199d7..b0c2dc41cfab 100644 --- a/sw/inc/unoredline.hxx +++ b/sw/inc/unoredline.hxx @@ -39,9 +39,6 @@ class SwXRedlineText final : SwNodeIndex m_aNodeIndex; virtual const SwStartNode *GetStartNode() const override; - virtual css::uno::Reference< css::text::XTextCursor > - CreateCursor() override; - public: SwXRedlineText(SwDoc* pDoc, const SwNodeIndex& aNodeIndex); @@ -53,8 +50,9 @@ public: virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) override; //XText - virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursor() override; - virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursorByRange(const css::uno::Reference< css::text::XTextRange > & aTextPosition) override; + virtual rtl::Reference< SwXTextCursor > createXTextCursor() override; + virtual rtl::Reference< SwXTextCursor > createXTextCursorByRange( + const ::css::uno::Reference< ::css::text::XTextRange >& aTextPosition ) override; //XEnumerationAccess virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override; @@ -86,8 +84,9 @@ public: virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) override; //XText - virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursor() override; - virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursorByRange(const css::uno::Reference< css::text::XTextRange > & aTextPosition) override; + virtual rtl::Reference< SwXTextCursor > createXTextCursor() override; + virtual rtl::Reference< SwXTextCursor > createXTextCursorByRange( + const ::css::uno::Reference< ::css::text::XTextRange >& aTextPosition ) override; //XPropertySet virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override; diff --git a/sw/inc/unotbl.hxx b/sw/inc/unotbl.hxx index d7074b5919bf..323a4f7b8e79 100644 --- a/sw/inc/unotbl.hxx +++ b/sw/inc/unotbl.hxx @@ -77,9 +77,6 @@ class SwXCell final : public SwXCellBaseClass, virtual const SwStartNode *GetStartNode() const override; - virtual css::uno::Reference< css::text::XTextCursor > - CreateCursor() override; - bool IsValid() const; virtual ~SwXCell() override; @@ -110,8 +107,9 @@ public: virtual sal_Int32 SAL_CALL getError( ) override; //XText - virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursor() override; - virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursorByRange(const css::uno::Reference< css::text::XTextRange > & aTextPosition) override; + virtual rtl::Reference< SwXTextCursor > createXTextCursor() override; + virtual rtl::Reference< SwXTextCursor > createXTextCursorByRange( + const ::css::uno::Reference< ::css::text::XTextRange >& aTextPosition ) override; virtual void SAL_CALL setString(const OUString& aString) override; //XPropertySet diff --git a/sw/inc/unotext.hxx b/sw/inc/unotext.hxx index ddd16012d225..7429d9f4cb66 100644 --- a/sw/inc/unotext.hxx +++ b/sw/inc/unotext.hxx @@ -40,6 +40,7 @@ namespace com::sun::star { class SwDoc; class SwStartNode; class SwPaM; +class SwXTextCursor; class SAL_DLLPUBLIC_RTTI SwXText : public css::lang::XTypeProvider @@ -82,10 +83,6 @@ public: const SwDoc* GetDoc() const; SwDoc* GetDoc(); - /// @throws css::uno::RuntimeException - virtual css::uno::Reference< css::text::XTextCursor > - CreateCursor(); - // XInterface virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& rType) override; @@ -131,6 +128,12 @@ public: virtual void SAL_CALL insertControlCharacter( const css::uno::Reference< css::text::XTextRange > & xRange, sal_Int16 nControlCharacter, sal_Bool bAbsorb) override; + virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursorByRange( + const ::css::uno::Reference< ::css::text::XTextRange >& aTextPosition ) override final; + virtual rtl::Reference< SwXTextCursor > createXTextCursorByRange( + const ::css::uno::Reference< ::css::text::XTextRange >& aTextPosition ) = 0; + virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursor() override final; + virtual rtl::Reference< SwXTextCursor > createXTextCursor() = 0; // XText virtual void SAL_CALL insertTextContent( diff --git a/sw/inc/unotextbodyhf.hxx b/sw/inc/unotextbodyhf.hxx index 3debaf4796cf..8e10e22a68fb 100644 --- a/sw/inc/unotextbodyhf.hxx +++ b/sw/inc/unotextbodyhf.hxx @@ -79,11 +79,9 @@ public: rtl::Reference< SwXParagraphEnumeration > createParagraphEnumeration(); // XSimpleText - virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL - createTextCursor() override; - virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL - createTextCursorByRange( - const css::uno::Reference< css::text::XTextRange > & xTextPosition) override; + virtual rtl::Reference< SwXTextCursor > createXTextCursor() override; + virtual rtl::Reference< SwXTextCursor > createXTextCursorByRange( + const ::css::uno::Reference< ::css::text::XTextRange >& aTextPosition ) override; }; @@ -100,8 +98,6 @@ class SwXHeadFootText final ::sw::UnoImplPtr<Impl> m_pImpl; virtual const SwStartNode *GetStartNode() const override; - virtual css::uno::Reference< css::text::XTextCursor > - CreateCursor() override; virtual ~SwXHeadFootText() override; @@ -112,7 +108,7 @@ public: static css::uno::Reference< css::text::XText > CreateXHeadFootText(SwFrameFormat & rHeadFootFormat, const bool bIsHeader); - css::uno::Reference<css::text::XTextCursor> CreateTextCursor(const bool bIgnoreTables = false); + rtl::Reference< SwXTextCursor > CreateTextCursor(const bool bIgnoreTables = false); // XInterface virtual css::uno::Any SAL_CALL queryInterface( @@ -142,11 +138,9 @@ public: createEnumeration() override; // XSimpleText - virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL - createTextCursor() override; - virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL - createTextCursorByRange( - const css::uno::Reference< css::text::XTextRange > & xTextPosition) override; + virtual rtl::Reference< SwXTextCursor > createXTextCursor() override; + virtual rtl::Reference< SwXTextCursor > createXTextCursorByRange( + const ::css::uno::Reference< ::css::text::XTextRange >& aTextPosition ) override; }; diff --git a/sw/source/core/inc/unofootnote.hxx b/sw/source/core/inc/unofootnote.hxx index b10a3555674c..23f22bee2cd3 100644 --- a/sw/source/core/inc/unofootnote.hxx +++ b/sw/source/core/inc/unofootnote.hxx @@ -50,8 +50,6 @@ class SwXFootnote final virtual const SwStartNode *GetStartNode() const override; - virtual css::uno::Reference< css::text::XTextCursor > CreateCursor() override; - virtual ~SwXFootnote() override; SwXFootnote(SwDoc & rDoc, SwFormatFootnote & rFormat); @@ -128,12 +126,9 @@ public: virtual void SAL_CALL setLabel(const OUString& rLabel) override; // XSimpleText - virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL - createTextCursor() override; - virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL - createTextCursorByRange( - const css::uno::Reference< css::text::XTextRange > & xTextPosition) override; - + virtual rtl::Reference< SwXTextCursor > createXTextCursor() override; + virtual rtl::Reference< SwXTextCursor > createXTextCursorByRange( + const ::css::uno::Reference< ::css::text::XTextRange >& aTextPosition ) override; }; #endif // INCLUDED_SW_SOURCE_CORE_INC_UNOFOOTNOTE_HXX diff --git a/sw/source/core/unocore/unocontentcontrol.cxx b/sw/source/core/unocore/unocontentcontrol.cxx index 256c39eab526..fa610f256523 100644 --- a/sw/source/core/unocore/unocontentcontrol.cxx +++ b/sw/source/core/unocore/unocontentcontrol.cxx @@ -53,7 +53,6 @@ private: protected: const SwStartNode* GetStartNode() const override; - uno::Reference<text::XTextCursor> CreateCursor() override; public: SwXContentControlText(SwDoc& rDoc, SwXContentControl& rContentControl); @@ -69,9 +68,9 @@ public: uno::Sequence<sal_Int8> SAL_CALL getImplementationId() override; // XText - uno::Reference<text::XTextCursor> SAL_CALL createTextCursor() override; - uno::Reference<text::XTextCursor> SAL_CALL - createTextCursorByRange(const uno::Reference<text::XTextRange>& xTextPosition) override; + virtual rtl::Reference<SwXTextCursor> createXTextCursor() override; + virtual rtl::Reference<SwXTextCursor> createXTextCursorByRange( + const ::css::uno::Reference<::css::text::XTextRange>& aTextPosition) override; }; } @@ -96,9 +95,9 @@ void SwXContentControlText::PrepareForAttach(uno::Reference<text::XTextRange>& x *rPam.GetPoint(), (rPam.HasMark()) ? rPam.GetMark() : nullptr)); } -uno::Reference<text::XTextCursor> SwXContentControlText::CreateCursor() +rtl::Reference<SwXTextCursor> SwXContentControlText::createXTextCursor() { - uno::Reference<text::XTextCursor> xRet; + rtl::Reference<SwXTextCursor> xRet; if (IsValid()) { SwTextNode* pTextNode; @@ -109,8 +108,8 @@ uno::Reference<text::XTextCursor> SwXContentControlText::CreateCursor() if (bSuccess) { SwPosition aPos(*pTextNode, nContentControlStart); - xRet = static_cast<text::XWordCursor*>( - new SwXTextCursor(*GetDoc(), &m_rContentControl, CursorType::ContentControl, aPos)); + xRet = new SwXTextCursor(*GetDoc(), &m_rContentControl, CursorType::ContentControl, + aPos); } } return xRet; @@ -122,15 +121,11 @@ uno::Sequence<sal_Int8> SAL_CALL SwXContentControlText::getImplementationId() } // XText -uno::Reference<text::XTextCursor> SAL_CALL SwXContentControlText::createTextCursor() -{ - return CreateCursor(); -} -uno::Reference<text::XTextCursor> SAL_CALL SwXContentControlText::createTextCursorByRange( +rtl::Reference<SwXTextCursor> SwXContentControlText::createXTextCursorByRange( const uno::Reference<text::XTextRange>& xTextPosition) { - const uno::Reference<text::XTextCursor> xCursor(CreateCursor()); + const rtl::Reference<SwXTextCursor> xCursor(createXTextCursor()); xCursor->gotoRange(xTextPosition, false); return xCursor; } diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx index ff9e06e93219..930976fdf88e 100644 --- a/sw/source/core/unocore/unoframe.cxx +++ b/sw/source/core/unocore/unoframe.cxx @@ -3290,15 +3290,8 @@ const SwStartNode *SwXTextFrame::GetStartNode() const return pSttNd; } -uno::Reference< text::XTextCursor > -SwXTextFrame::CreateCursor() +rtl::Reference<SwXTextCursor> SwXTextFrame::createXTextCursor() { - return createTextCursor(); -} - -uno::Reference< text::XTextCursor > SwXTextFrame::createTextCursor() -{ - SolarMutexGuard aGuard; SwFrameFormat* pFormat = GetFrameFormat(); if(!pFormat) throw uno::RuntimeException(); @@ -3327,13 +3320,12 @@ uno::Reference< text::XTextCursor > SwXTextFrame::createTextCursor() throw aExcept; } - return static_cast<text::XWordCursor*>(new SwXTextCursor( - *pFormat->GetDoc(), this, CursorType::Frame, *aPam.GetPoint())); + return new SwXTextCursor( + *pFormat->GetDoc(), this, CursorType::Frame, *aPam.GetPoint()); } -uno::Reference< text::XTextCursor > SwXTextFrame::createTextCursorByRange(const uno::Reference< text::XTextRange > & aTextPosition) +rtl::Reference< SwXTextCursor > SwXTextFrame::createXTextCursorByRange(const uno::Reference< text::XTextRange > & aTextPosition) { - SolarMutexGuard aGuard; SwFrameFormat* pFormat = GetFrameFormat(); if (!pFormat) throw uno::RuntimeException(); @@ -3341,13 +3333,12 @@ uno::Reference< text::XTextCursor > SwXTextFrame::createTextCursorByRange(const if (!::sw::XTextRangeToSwPaM(aPam, aTextPosition)) throw uno::RuntimeException(); - uno::Reference<text::XTextCursor> aRef; + rtl::Reference< SwXTextCursor > aRef; SwNode& rNode = pFormat->GetContent().GetContentIdx()->GetNode(); if(aPam.GetPointNode().FindFlyStartNode() == rNode.FindFlyStartNode()) { - aRef = static_cast<text::XWordCursor*>( - new SwXTextCursor(*pFormat->GetDoc(), this, CursorType::Frame, - *aPam.GetPoint(), aPam.GetMark())); + aRef = new SwXTextCursor(*pFormat->GetDoc(), this, CursorType::Frame, + *aPam.GetPoint(), aPam.GetMark()); } return aRef; diff --git a/sw/source/core/unocore/unoftn.cxx b/sw/source/core/unocore/unoftn.cxx index c4ff75fec2f8..ef04f1f62d30 100644 --- a/sw/source/core/unocore/unoftn.cxx +++ b/sw/source/core/unocore/unoftn.cxx @@ -386,17 +386,9 @@ const SwStartNode *SwXFootnote::GetStartNode() const return nullptr; } -uno::Reference< text::XTextCursor > -SwXFootnote::CreateCursor() +rtl::Reference< SwXTextCursor > +SwXFootnote::createXTextCursor() { - return createTextCursor(); -} - -uno::Reference< text::XTextCursor > SAL_CALL -SwXFootnote::createTextCursor() -{ - SolarMutexGuard aGuard; - SwFormatFootnote const& rFormat( m_pImpl->GetFootnoteFormatOrThrow() ); SwTextFootnote const*const pTextFootnote = rFormat.GetTextFootnote(); @@ -405,15 +397,13 @@ SwXFootnote::createTextCursor() new SwXTextCursor(*GetDoc(), this, CursorType::Footnote, aPos); auto& rUnoCursor(pXCursor->GetCursor()); rUnoCursor.Move(fnMoveForward, GoInNode); - return static_cast<text::XWordCursor*>(pXCursor.get()); + return pXCursor; } -uno::Reference< text::XTextCursor > SAL_CALL -SwXFootnote::createTextCursorByRange( +rtl::Reference< SwXTextCursor > +SwXFootnote::createXTextCursorByRange( const uno::Reference< text::XTextRange > & xTextPosition) { - SolarMutexGuard aGuard; - SwFormatFootnote const& rFormat( m_pImpl->GetFootnoteFormatOrThrow() ); SwUnoInternalPaM aPam(*GetDoc()); @@ -431,10 +421,9 @@ SwXFootnote::createTextCursorByRange( throw uno::RuntimeException(); } - const uno::Reference< text::XTextCursor > xRet = - static_cast<text::XWordCursor*>( + const rtl::Reference< SwXTextCursor > xRet = new SwXTextCursor(*GetDoc(), this, CursorType::Footnote, - *aPam.GetPoint(), aPam.GetMark())); + *aPam.GetPoint(), aPam.GetMark()); return xRet; } diff --git a/sw/source/core/unocore/unoobj2.cxx b/sw/source/core/unocore/unoobj2.cxx index c07c78237e92..cff5963ede62 100644 --- a/sw/source/core/unocore/unoobj2.cxx +++ b/sw/source/core/unocore/unoobj2.cxx @@ -39,6 +39,7 @@ #include <textboxhelper.hxx> #include <ndtxt.hxx> #include <unocrsr.hxx> +#include <unotextcursor.hxx> #include <swundo.hxx> #include <rootfrm.hxx> #include <ftnidx.hxx> @@ -1101,26 +1102,24 @@ bool XTextRangeToSwPaM( SwUnoInternalPaM & rToFill, // if it's a text then create a temporary cursor there and re-use // the pCursor variable // #i108489#: Reference in outside scope to keep cursor alive - uno::Reference< text::XTextCursor > xTextCursor; + rtl::Reference< SwXTextCursor > xTextCursor; if (pHeadText) { // if it is a header / footer text, and eMode == TextRangeMode::AllowTableNode // then set the cursor to the beginning of the text // if it is started with a table then set into the table - xTextCursor.set(pHeadText->CreateTextCursor(true)); + xTextCursor = pHeadText->CreateTextCursor(true); xTextCursor->gotoEnd(true); - pCursor = dynamic_cast<OTextCursorHelper*>(xTextCursor.get()); - assert(pCursor && "cant must succeed"); + pCursor = xTextCursor.get(); pCursor->GetPaM()->Normalize(); } - else - if (pText) + else if (pText) { - xTextCursor.set( pText->CreateCursor() ); + xTextCursor = pText->createXTextCursor(); xTextCursor->gotoEnd(true); - pCursor = dynamic_cast<OTextCursorHelper*>(xTextCursor.get()); - assert(pCursor && "cant must succeed"); + pCursor = xTextCursor.get(); } + if(pRange && &pRange->GetDoc() == &rToFill.GetDoc()) { bRet = pRange->GetPositions(rToFill, eMode); diff --git a/sw/source/core/unocore/unoredline.cxx b/sw/source/core/unocore/unoredline.cxx index c32180a9bf71..3fdf15a0c9a0 100644 --- a/sw/source/core/unocore/unoredline.cxx +++ b/sw/source/core/unocore/unoredline.cxx @@ -90,12 +90,7 @@ uno::Sequence<sal_Int8> SwXRedlineText::getImplementationId() return css::uno::Sequence<sal_Int8>(); } -uno::Reference<text::XTextCursor> SwXRedlineText::CreateCursor() -{ - return createTextCursor(); -} - -uno::Reference<text::XTextCursor> SwXRedlineText::createTextCursor() +rtl::Reference< SwXTextCursor > SwXRedlineText::createXTextCursor() { SolarMutexGuard aGuard; @@ -131,13 +126,13 @@ uno::Reference<text::XTextCursor> SwXRedlineText::createTextCursor() throw aExcept; } - return static_cast<text::XWordCursor*>(pXCursor.get()); + return pXCursor; } -uno::Reference<text::XTextCursor> SwXRedlineText::createTextCursorByRange( +rtl::Reference< SwXTextCursor > SwXRedlineText::createXTextCursorByRange( const uno::Reference<text::XTextRange> & aTextRange) { - uno::Reference<text::XTextCursor> xCursor = createTextCursor(); + rtl::Reference< SwXTextCursor > xCursor = createXTextCursor(); xCursor->gotoRange(aTextRange->getStart(), false); xCursor->gotoRange(aTextRange->getEnd(), true); return xCursor; @@ -525,9 +520,8 @@ sal_Bool SwXRedline::hasElements( ) return nullptr != m_pRedline->GetContentIdx(); } -uno::Reference< text::XTextCursor > SwXRedline::createTextCursor() +rtl::Reference< SwXTextCursor > SwXRedline::createXTextCursor() { - SolarMutexGuard aGuard; if(!m_pDoc) throw uno::RuntimeException(); @@ -552,10 +546,10 @@ uno::Reference< text::XTextCursor > SwXRedline::createTextCursor() pTableNode = pCont->FindTableNode(); } - return static_cast<text::XWordCursor*>(pXCursor.get()); + return pXCursor; } -uno::Reference< text::XTextCursor > SwXRedline::createTextCursorByRange( +rtl::Reference< SwXTextCursor > SwXRedline::createXTextCursorByRange( const uno::Reference< text::XTextRange > & /*aTextPosition*/) { throw uno::RuntimeException(); diff --git a/sw/source/core/unocore/unorefmk.cxx b/sw/source/core/unocore/unorefmk.cxx index 30bfaa430646..20d3b7d323d1 100644 --- a/sw/source/core/unocore/unorefmk.cxx +++ b/sw/source/core/unocore/unorefmk.cxx @@ -485,8 +485,6 @@ private: protected: virtual const SwStartNode *GetStartNode() const override; - virtual uno::Reference< text::XTextCursor > - CreateCursor() override; public: SwXMetaText(SwDoc & rDoc, SwXMeta & rMeta); @@ -503,12 +501,9 @@ public: getImplementationId() override; // XText - virtual uno::Reference< text::XTextCursor > SAL_CALL - createTextCursor() override; - virtual uno::Reference< text::XTextCursor > SAL_CALL - createTextCursorByRange( - const uno::Reference< text::XTextRange > & xTextPosition) override; - + virtual rtl::Reference< SwXTextCursor > createXTextCursor() override; + virtual rtl::Reference< SwXTextCursor > createXTextCursorByRange( + const ::css::uno::Reference< ::css::text::XTextRange >& aTextPosition ) override; }; } @@ -540,9 +535,9 @@ bool SwXMetaText::CheckForOwnMemberMeta(const SwPaM & rPam, const bool bAbsorb) return m_rMeta.CheckForOwnMemberMeta(rPam, bAbsorb); } -uno::Reference< text::XTextCursor > SwXMetaText::CreateCursor() +rtl::Reference< SwXTextCursor > SwXMetaText::createXTextCursor() { - uno::Reference< text::XTextCursor > xRet; + rtl::Reference< SwXTextCursor > xRet; if (IsValid()) { SwTextNode * pTextNode; @@ -553,8 +548,7 @@ uno::Reference< text::XTextCursor > SwXMetaText::CreateCursor() if (bSuccess) { SwPosition aPos(*pTextNode, nMetaStart); - xRet = static_cast<text::XWordCursor*>( - new SwXTextCursor(*GetDoc(), &m_rMeta, CursorType::Meta, aPos)); + xRet = new SwXTextCursor(*GetDoc(), &m_rMeta, CursorType::Meta, aPos); } } return xRet; @@ -567,17 +561,12 @@ SwXMetaText::getImplementationId() } // XText -uno::Reference< text::XTextCursor > SAL_CALL -SwXMetaText::createTextCursor() -{ - return CreateCursor(); -} -uno::Reference< text::XTextCursor > SAL_CALL -SwXMetaText::createTextCursorByRange( +rtl::Reference< SwXTextCursor > +SwXMetaText::createXTextCursorByRange( const uno::Reference<text::XTextRange> & xTextPosition) { - const uno::Reference<text::XTextCursor> xCursor( CreateCursor() ); + const rtl::Reference< SwXTextCursor > xCursor( createXTextCursor() ); xCursor->gotoRange(xTextPosition, false); return xCursor; } diff --git a/sw/source/core/unocore/unotbl.cxx b/sw/source/core/unocore/unotbl.cxx index 85c69f7637e7..66e43fb1828e 100644 --- a/sw/source/core/unocore/unotbl.cxx +++ b/sw/source/core/unocore/unotbl.cxx @@ -785,12 +785,6 @@ const SwStartNode *SwXCell::GetStartNode() const return pSttNd; } -uno::Reference< text::XTextCursor > -SwXCell::CreateCursor() -{ - return createTextCursor(); -} - bool SwXCell::IsValid() const { // FIXME: this is now a const method, to make SwXText::IsValid invisible @@ -901,9 +895,8 @@ sal_Int32 SwXCell::getError() return sal_Int32(sContent == SwViewShell::GetShellRes()->aCalc_Error); } -uno::Reference<text::XTextCursor> SwXCell::createTextCursor() +rtl::Reference< SwXTextCursor > SwXCell::createXTextCursor() { - SolarMutexGuard aGuard; if(!m_pStartNode && !IsValid()) throw uno::RuntimeException(); const SwStartNode* pSttNd = m_pStartNode ? m_pStartNode : m_pBox->GetSttNd(); @@ -912,12 +905,11 @@ uno::Reference<text::XTextCursor> SwXCell::createTextCursor() new SwXTextCursor(*GetDoc(), this, CursorType::TableText, aPos); auto& rUnoCursor(pXCursor->GetCursor()); rUnoCursor.Move(fnMoveForward, GoInNode); - return static_cast<text::XWordCursor*>(pXCursor.get()); + return pXCursor; } -uno::Reference<text::XTextCursor> SwXCell::createTextCursorByRange(const uno::Reference< text::XTextRange > & xTextPosition) +rtl::Reference<SwXTextCursor> SwXCell::createXTextCursorByRange(const uno::Reference< text::XTextRange > & xTextPosition) { - SolarMutexGuard aGuard; SwUnoInternalPaM aPam(*GetDoc()); if((!m_pStartNode && !IsValid()) || !::sw::XTextRangeToSwPaM(aPam, xTextPosition)) throw uno::RuntimeException(); @@ -928,9 +920,8 @@ uno::Reference<text::XTextCursor> SwXCell::createTextCursorByRange(const uno::Re p1 = p1->StartOfSectionNode(); if( p1 != pSttNd ) return nullptr; - return static_cast<text::XWordCursor*>( - new SwXTextCursor(*GetDoc(), this, CursorType::TableText, - *aPam.GetPoint(), aPam.GetMark())); + return new SwXTextCursor(*GetDoc(), this, CursorType::TableText, + *aPam.GetPoint(), aPam.GetMark()); } uno::Reference< beans::XPropertySetInfo > SwXCell::getPropertySetInfo() diff --git a/sw/source/core/unocore/unotext.cxx b/sw/source/core/unocore/unotext.cxx index 6d6ce3cb866d..b506b3a26183 100644 --- a/sw/source/core/unocore/unotext.cxx +++ b/sw/source/core/unocore/unotext.cxx @@ -175,21 +175,41 @@ const SwStartNode *SwXText::GetStartNode() const return GetDoc()->GetNodes().GetEndOfContent().StartOfSectionNode(); } -uno::Reference< text::XTextCursor > -SwXText::CreateCursor() +uno::Reference< text::XTextCursor > SAL_CALL SwXText::createTextCursor() { - uno::Reference< text::XTextCursor > xRet; + SolarMutexGuard aGuard; + rtl::Reference<SwXTextCursor> xCursor = createXTextCursor(); + if (!xCursor.is()) + { + uno::RuntimeException aRuntime; + aRuntime.Message = cInvalidObject; + throw aRuntime; + } + return static_cast<text::XWordCursor*>(xCursor.get()); +} + +rtl::Reference< SwXTextCursor > +SwXText::createXTextCursor() +{ + rtl::Reference< SwXTextCursor > xRet; if(IsValid()) { SwNode& rNode = GetDoc()->GetNodes().GetEndOfContent(); SwPosition aPos(rNode); - xRet = static_cast<text::XWordCursor*>( - new SwXTextCursor(*GetDoc(), this, m_pImpl->m_eType, aPos)); + xRet = new SwXTextCursor(*GetDoc(), this, m_pImpl->m_eType, aPos); xRet->gotoStart(false); } return xRet; } +css::uno::Reference< css::text::XTextCursor > SAL_CALL SwXText::createTextCursorByRange( + const ::css::uno::Reference< ::css::text::XTextRange >& aTextPosition ) +{ + SolarMutexGuard aGuard; + return static_cast<text::XWordCursor*>(createXTextCursorByRange(aTextPosition).get()); +} + + uno::Any SAL_CALL SwXText::queryInterface(const uno::Type& rType) { @@ -839,7 +859,7 @@ SwXText::getStart() { SolarMutexGuard aGuard; - const uno::Reference< text::XTextCursor > xRef = CreateCursor(); + const rtl::Reference< SwXTextCursor > xRef = createXTextCursor(); if(!xRef.is()) { uno::RuntimeException aRuntime; @@ -847,7 +867,7 @@ SwXText::getStart() throw aRuntime; } xRef->gotoStart(false); - return xRef; + return static_cast<text::XWordCursor*>(xRef.get()); } uno::Reference< text::XTextRange > SAL_CALL @@ -855,7 +875,7 @@ SwXText::getEnd() { SolarMutexGuard aGuard; - const uno::Reference< text::XTextCursor > xRef = CreateCursor(); + const rtl::Reference< SwXTextCursor > xRef = createXTextCursor(); if(!xRef.is()) { uno::RuntimeException aRuntime; @@ -863,14 +883,14 @@ SwXText::getEnd() throw aRuntime; } xRef->gotoEnd(false); - return xRef; + return static_cast<text::XWordCursor*>(xRef.get()); } OUString SAL_CALL SwXText::getString() { SolarMutexGuard aGuard; - const uno::Reference< text::XTextCursor > xRet = CreateCursor(); + const rtl::Reference< SwXTextCursor > xRet = createXTextCursor(); if(!xRet.is()) { SAL_WARN("sw.uno", "cursor was not created in getString() call. Returning empty string."); @@ -932,7 +952,7 @@ SwXText::setString(const OUString& rString) } } - const uno::Reference< text::XTextCursor > xRet = CreateCursor(); + const rtl::Reference< SwXTextCursor > xRet = createXTextCursor(); if(!xRet.is()) { GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::END, nullptr); @@ -951,13 +971,9 @@ SwXText::setString(const OUString& rString) bool SwXText::Impl::CheckForOwnMember( const SwPaM & rPaM) { - const uno::Reference<text::XTextCursor> xOwnCursor(m_rThis.CreateCursor()); - - OTextCursorHelper *const pOwnCursor = - dynamic_cast<OTextCursorHelper*>(xOwnCursor.get()); - assert(pOwnCursor && "OTextCursorHelper::getUnoTunnelId() ???"); + const rtl::Reference< SwXTextCursor > xOwnCursor(m_rThis.createXTextCursor()); const SwStartNode* pOwnStartNode = - pOwnCursor->GetPaM()->GetPointNode().StartOfSectionNode(); + xOwnCursor->GetPaM()->GetPointNode().StartOfSectionNode(); SwStartNodeType eSearchNodeType = SwNormalStartNode; switch (m_eType) { @@ -1318,15 +1334,14 @@ SwXText::insertTextPortion( throw uno::RuntimeException(); } uno::Reference< text::XTextRange > xRet; - const uno::Reference<text::XTextCursor> xTextCursor = createTextCursorByRange(xInsertPosition); - SwXTextCursor *const pTextCursor = dynamic_cast<SwXTextCursor*>(xTextCursor.get()); + const rtl::Reference<SwXTextCursor> xTextCursor = createXTextCursorByRange(xInsertPosition); bool bIllegalException = false; bool bRuntimeException = false; OUString sMessage; m_pImpl->m_pDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSERT, nullptr); - auto& rCursor(pTextCursor->GetCursor()); + auto& rCursor(xTextCursor->GetCursor()); m_pImpl->m_pDoc->DontExpandFormat( *rCursor.Start() ); if (!rText.isEmpty()) @@ -1764,24 +1779,22 @@ SwXText::convertToTextFrame( xRet = xNewFrame; if (bParaBeforeInserted || bParaAfterInserted) { - const uno::Reference<text::XTextCursor> xFrameTextCursor = - rNewFrame.createTextCursor(); - SwXTextCursor *const pFrameCursor = - dynamic_cast<SwXTextCursor*>(xFrameTextCursor.get()); + const rtl::Reference<SwXTextCursor> xFrameTextCursor = + rNewFrame.createXTextCursor(); if (bParaBeforeInserted) { // todo: remove paragraph before frame - m_pImpl->m_pDoc->getIDocumentContentOperations().DelFullPara(*pFrameCursor->GetPaM()); + m_pImpl->m_pDoc->getIDocumentContentOperations().DelFullPara(*xFrameTextCursor->GetPaM()); } if (bParaAfterInserted) { xFrameTextCursor->gotoEnd(false); if (!bParaBeforeInserted) - m_pImpl->m_pDoc->getIDocumentContentOperations().DelFullPara(*pFrameCursor->GetPaM()); + m_pImpl->m_pDoc->getIDocumentContentOperations().DelFullPara(*xFrameTextCursor->GetPaM()); else { // In case the frame has a table only, the cursor points to the end of the first cell of the table. - SwPaM aPaM(*pFrameCursor->GetPaM()->GetPointNode().FindSttNodeByType(SwFlyStartNode)->EndOfSectionNode()); + SwPaM aPaM(*xFrameTextCursor->GetPaM()->GetPointNode().FindSttNodeByType(SwFlyStartNode)->EndOfSectionNode()); // Now we have the end of the frame -- the node before that will be the paragraph we want to remove. aPaM.GetPoint()->Adjust(SwNodeOffset(-1)); m_pImpl->m_pDoc->getIDocumentContentOperations().DelFullPara(aPaM); @@ -2459,28 +2472,16 @@ rtl::Reference<SwXTextCursor> SwXBodyText::CreateTextCursor(const bool bIgnoreTa return new SwXTextCursor(*GetDoc(), this, CursorType::Body, *aPam.GetPoint()); } -uno::Reference< text::XTextCursor > SAL_CALL -SwXBodyText::createTextCursor() +rtl::Reference< SwXTextCursor > +SwXBodyText::createXTextCursor() { - SolarMutexGuard aGuard; - - const uno::Reference< text::XTextCursor > xRef = - static_cast<text::XWordCursor*>(CreateTextCursor().get()); - if (!xRef.is()) - { - uno::RuntimeException aRuntime; - aRuntime.Message = cInvalidObject; - throw aRuntime; - } - return xRef; + return CreateTextCursor(); } -uno::Reference< text::XTextCursor > SAL_CALL -SwXBodyText::createTextCursorByRange( +rtl::Reference< SwXTextCursor > +SwXBodyText::createXTextCursorByRange( const uno::Reference< text::XTextRange > & xTextPosition) { - SolarMutexGuard aGuard; - if(!IsValid()) { uno::RuntimeException aRuntime; @@ -2488,7 +2489,7 @@ SwXBodyText::createTextCursorByRange( throw aRuntime; } - uno::Reference< text::XTextCursor > aRef; + rtl::Reference< SwXTextCursor > aRef; SwUnoInternalPaM aPam(*GetDoc()); if (::sw::XTextRangeToSwPaM(aPam, xTextPosition)) { @@ -2507,9 +2508,8 @@ SwXBodyText::createTextCursorByRange( if(p1 == p2) { - aRef = static_cast<text::XWordCursor*>( - new SwXTextCursor(*GetDoc(), this, CursorType::Body, - *aPam.GetPoint(), aPam.GetMark())); + aRef = new SwXTextCursor(*GetDoc(), this, CursorType::Body, + *aPam.GetPoint(), aPam.GetMark()); } } if(!aRef.is()) @@ -2656,11 +2656,6 @@ const SwStartNode* SwXHeadFootText::GetStartNode() const return pSttNd; } -uno::Reference<text::XTextCursor> SwXHeadFootText::CreateCursor() -{ - return createTextCursor(); -} - uno::Sequence<uno::Type> SAL_CALL SwXHeadFootText::getTypes() { return ::comphelper::concatSequences( @@ -2681,10 +2676,8 @@ uno::Any SAL_CALL SwXHeadFootText::queryInterface(const uno::Type& rType) : ret; } -uno::Reference<text::XTextCursor> SwXHeadFootText::CreateTextCursor(const bool bIgnoreTables) +rtl::Reference<SwXTextCursor> SwXHeadFootText::CreateTextCursor(const bool bIgnoreTables) { - SolarMutexGuard aGuard; - SwFrameFormat & rHeadFootFormat( m_pImpl->GetHeadFootFormatOrThrow() ); const SwFormatContent& rFlyContent = rHeadFootFormat.GetContent(); @@ -2719,19 +2712,18 @@ uno::Reference<text::XTextCursor> SwXHeadFootText::CreateTextCursor(const bool b aExcept.Message = "no text available"; throw aExcept; } - return static_cast<text::XWordCursor*>(pXCursor.get()); + return pXCursor; } -uno::Reference<text::XTextCursor> SAL_CALL -SwXHeadFootText::createTextCursor() +rtl::Reference< SwXTextCursor > +SwXHeadFootText::createXTextCursor() { return CreateTextCursor(false); } -uno::Reference<text::XTextCursor> SAL_CALL SwXHeadFootText::createTextCursorByRange( +rtl::Reference<SwXTextCursor> SwXHeadFootText::createXTextCursorByRange( const uno::Reference<text::XTextRange>& xTextPosition) { - SolarMutexGuard aGuard; SwFrameFormat& rHeadFootFormat( m_pImpl->GetHeadFootFormatOrThrow() ); SwUnoInternalPaM aPam(*GetDoc()); @@ -2752,12 +2744,11 @@ uno::Reference<text::XTextCursor> SAL_CALL SwXHeadFootText::createTextCursorByRa (m_pImpl->m_bIsHeader) ? SwHeaderStartNode : SwFooterStartNode); if (p1 == pOwnStartNode) { - return static_cast<text::XWordCursor*>( - new SwXTextCursor( + return new SwXTextCursor( *GetDoc(), this, (m_pImpl->m_bIsHeader) ? CursorType::Header : CursorType::Footer, - *aPam.GetPoint(), aPam.GetMark())); + *aPam.GetPoint(), aPam.GetMark()); } return nullptr; } |