diff options
author | Bjoern Michaelsen <bjoern.michaelsen@canonical.com> | 2015-05-31 00:35:26 +0200 |
---|---|---|
committer | Bjoern Michaelsen <bjoern.michaelsen@canonical.com> | 2015-06-08 18:46:53 +0200 |
commit | 3169a41f38db473327e7af68823525d56993b9be (patch) | |
tree | 435c27a48cdb4a90068a90fe3ed9ce4ea1741307 | |
parent | 45464a78a92e40863e419611dc47723c23293d51 (diff) |
use ABC instead of Pimpl for SwXParagraphEnumeration
- abstract base class reduces boilerplate
- Pimpl is pointless here
Change-Id: I191dc0fecd25937f41fd724355e88c04da89db61
-rw-r--r-- | sw/inc/unoparagraph.hxx | 46 | ||||
-rw-r--r-- | sw/source/core/unocore/unoframe.cxx | 2 | ||||
-rw-r--r-- | sw/source/core/unocore/unoftn.cxx | 2 | ||||
-rw-r--r-- | sw/source/core/unocore/unoobj.cxx | 2 | ||||
-rw-r--r-- | sw/source/core/unocore/unoobj2.cxx | 98 | ||||
-rw-r--r-- | sw/source/core/unocore/unoredline.cxx | 4 | ||||
-rw-r--r-- | sw/source/core/unocore/unotbl.cxx | 2 | ||||
-rw-r--r-- | sw/source/core/unocore/unotext.cxx | 5 |
8 files changed, 64 insertions, 97 deletions
diff --git a/sw/inc/unoparagraph.hxx b/sw/inc/unoparagraph.hxx index 0c8d87e7734b..e0a2f18d85da 100644 --- a/sw/inc/unoparagraph.hxx +++ b/sw/inc/unoparagraph.hxx @@ -302,46 +302,16 @@ public: }; -class SwXParagraphEnumeration + +struct SwXParagraphEnumeration : public SwSimpleEnumeration_Base { - -private: - - class Impl; - ::sw::UnoImplPtr<Impl> m_pImpl; - - virtual ~SwXParagraphEnumeration(); - -public: - - /// takes ownership of cursor - SwXParagraphEnumeration( - ::com::sun::star::uno::Reference< ::com::sun::star::text::XText > - const & xParent, - std::shared_ptr<SwUnoCrsr> pCursor, - const CursorType eType, - SwStartNode const*const pStartNode = 0, - SwTable const*const pTable = 0); - - // XServiceInfo - virtual OUString SAL_CALL getImplementationName() - throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; - virtual sal_Bool SAL_CALL supportsService( - const OUString& rServiceName) - throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; - virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL - getSupportedServiceNames() - throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; - - // XEnumeration - virtual sal_Bool SAL_CALL hasMoreElements() - throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; - virtual ::com::sun::star::uno::Any SAL_CALL nextElement() - throw (::com::sun::star::container::NoSuchElementException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; - + static SwXParagraphEnumeration* Create( + ::com::sun::star::uno::Reference< ::com::sun::star::text::XText > const & xParent, + std::shared_ptr<SwUnoCrsr> pCursor, + const CursorType eType, + SwStartNode const*const pStartNode = 0, + SwTable const*const pTable = 0); }; #endif // INCLUDED_SW_INC_UNOPARAGRAPH_HXX diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx index 9a58928b88d7..c39ccd302c58 100644 --- a/sw/source/core/unocore/unoframe.cxx +++ b/sw/source/core/unocore/unoframe.cxx @@ -3287,7 +3287,7 @@ uno::Reference< container::XEnumeration > SwXTextFrame::createEnumeration() thr SwPosition aPos(pFormat->GetContent().GetContentIdx()->GetNode()); auto pUnoCursor(GetDoc()->CreateUnoCrsr(aPos, false)); pUnoCursor->Move(fnMoveForward, fnGoNode); - return new SwXParagraphEnumeration(this, pUnoCursor, CURSOR_FRAME); + return SwXParagraphEnumeration::Create(this, pUnoCursor, CURSOR_FRAME); } uno::Type SwXTextFrame::getElementType() throw( uno::RuntimeException, std::exception ) diff --git a/sw/source/core/unocore/unoftn.cxx b/sw/source/core/unocore/unoftn.cxx index 827d4fbdd83f..6ef75b28422f 100644 --- a/sw/source/core/unocore/unoftn.cxx +++ b/sw/source/core/unocore/unoftn.cxx @@ -480,7 +480,7 @@ SwXFootnote::createEnumeration() throw (uno::RuntimeException, std::exception) SwPosition aPos( *pTextFootnote->GetStartNode() ); auto pUnoCursor(GetDoc()->CreateUnoCrsr(aPos, false)); pUnoCursor->Move(fnMoveForward, fnGoNode); - return new SwXParagraphEnumeration(this, pUnoCursor, CURSOR_FOOTNOTE); + return SwXParagraphEnumeration::Create(this, pUnoCursor, CURSOR_FOOTNOTE); } uno::Type SAL_CALL SwXFootnote::getElementType() throw (uno::RuntimeException, std::exception) diff --git a/sw/source/core/unocore/unoobj.cxx b/sw/source/core/unocore/unoobj.cxx index 726e3c9213fe..8b4a73753d38 100644 --- a/sw/source/core/unocore/unoobj.cxx +++ b/sw/source/core/unocore/unoobj.cxx @@ -3030,7 +3030,7 @@ SwXTextCursor::createEnumeration() throw (uno::RuntimeException, std::exception) : 0); SwTable const*const pTable( (pStartNode) ? & pStartNode->GetTable() : 0 ); - return new SwXParagraphEnumeration(pParentText, pNewCrsr, eSetType, pStartNode, pTable); + return SwXParagraphEnumeration::Create(pParentText, pNewCrsr, eSetType, pStartNode, pTable); } uno::Type SAL_CALL diff --git a/sw/source/core/unocore/unoobj2.cxx b/sw/source/core/unocore/unoobj2.cxx index 96efb390d080..d1cf9aec9434 100644 --- a/sw/source/core/unocore/unoobj2.cxx +++ b/sw/source/core/unocore/unoobj2.cxx @@ -409,24 +409,24 @@ void SwUnoCursorHelper::GetCrsrAttr(SwPaM & rPam, } } -struct SwXParagraphEnumeration::Impl +struct SwXParagraphEnumerationImpl SAL_FINAL : public SwXParagraphEnumeration { - uno::Reference< text::XText > const m_xParentText; - const CursorType m_eCursorType; + uno::Reference< text::XText > const m_xParentText; + const CursorType m_eCursorType; /// Start node of the cell _or_ table the enumeration belongs to. /// Used to restrict the movement of the UNO cursor to the cell and its /// embedded tables. SwStartNode const*const m_pOwnStartNode; - SwTable const*const m_pOwnTable; - const sal_uLong m_nEndIndex; - sal_Int32 m_nFirstParaStart; - sal_Int32 m_nLastParaEnd; - bool m_bFirstParagraph; - uno::Reference< text::XTextContent > m_xNextPara; - //UnoCursorPointerWithClientModify m_pCrsr; + SwTable const*const m_pOwnTable; + const sal_uLong m_nEndIndex; + sal_Int32 m_nFirstParaStart; + sal_Int32 m_nLastParaEnd; + bool m_bFirstParagraph; + uno::Reference< text::XTextContent > m_xNextPara; sw::UnoCursorPointer m_pCrsr; - Impl( uno::Reference< text::XText > const& xParent, + SwXParagraphEnumerationImpl( + uno::Reference< text::XText > const& xParent, ::std::shared_ptr<SwUnoCrsr> pCursor, const CursorType eType, SwStartNode const*const pStartNode, SwTable const*const pTable) @@ -461,59 +461,62 @@ struct SwXParagraphEnumeration::Impl } } - virtual ~Impl() { - m_pCrsr.reset(nullptr); + virtual ~SwXParagraphEnumerationImpl() + { m_pCrsr.reset(nullptr); } + virtual void SAL_CALL release() throw () SAL_OVERRIDE + { + SolarMutexGuard g; + OWeakObject::release(); } - SwUnoCrsr* GetCursor() { - return &(*m_pCrsr); - } + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; + virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; + virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; + // XEnumeration + virtual sal_Bool SAL_CALL hasMoreElements() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; + virtual ::com::sun::star::uno::Any SAL_CALL nextElement() throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; + + SwUnoCrsr* GetCursor() + { return &(*m_pCrsr); } uno::Reference< text::XTextContent > NextElement_Impl() - throw (container::NoSuchElementException, lang::WrappedTargetException, - uno::RuntimeException); + throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException); }; -SwXParagraphEnumeration::SwXParagraphEnumeration( - uno::Reference< text::XText > const& xParent, - ::std::shared_ptr<SwUnoCrsr> pCursor, - const CursorType eType, - SwStartNode const*const pStartNode, SwTable const*const pTable) - : m_pImpl( new SwXParagraphEnumeration::Impl(xParent, pCursor, eType, - pStartNode, pTable) ) -{ -} - -SwXParagraphEnumeration::~SwXParagraphEnumeration() +SwXParagraphEnumeration* SwXParagraphEnumeration::Create( + uno::Reference< text::XText > const& xParent, + ::std::shared_ptr<SwUnoCrsr> pCursor, + const CursorType eType, + SwStartNode const*const pStartNode, + SwTable const*const pTable) { + return new SwXParagraphEnumerationImpl(xParent, pCursor, eType, pStartNode, pTable); } OUString SAL_CALL -SwXParagraphEnumeration::getImplementationName() throw (uno::RuntimeException, std::exception) +SwXParagraphEnumerationImpl::getImplementationName() throw (uno::RuntimeException, std::exception) { return OUString("SwXParagraphEnumeration"); } sal_Bool SAL_CALL -SwXParagraphEnumeration::supportsService(const OUString& rServiceName) -throw (uno::RuntimeException, std::exception) +SwXParagraphEnumerationImpl::supportsService(const OUString& rServiceName) throw (uno::RuntimeException, std::exception) { return cppu::supportsService(this, rServiceName); } uno::Sequence< OUString > SAL_CALL -SwXParagraphEnumeration::getSupportedServiceNames() -throw (uno::RuntimeException, std::exception) +SwXParagraphEnumerationImpl::getSupportedServiceNames() throw (uno::RuntimeException, std::exception) { return {"com.sun.star.text.ParagraphEnumeration"}; } sal_Bool SAL_CALL -SwXParagraphEnumeration::hasMoreElements() throw (uno::RuntimeException, std::exception) +SwXParagraphEnumerationImpl::hasMoreElements() throw (uno::RuntimeException, std::exception) { SolarMutexGuard aGuard; - - return m_pImpl->m_bFirstParagraph || m_pImpl->m_xNextPara.is(); + return m_bFirstParagraph || m_xNextPara.is(); } //!! compare to SwShellTableCrsr::FillRects() in viscrs.cxx @@ -551,9 +554,7 @@ lcl_CursorIsInSection( } uno::Reference< text::XTextContent > -SwXParagraphEnumeration::Impl::NextElement_Impl() -throw (container::NoSuchElementException, lang::WrappedTargetException, - uno::RuntimeException) +SwXParagraphEnumerationImpl::NextElement_Impl() throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) { SwUnoCrsr *const pUnoCrsr = GetCursor(); if (!pUnoCrsr) @@ -650,23 +651,20 @@ throw (container::NoSuchElementException, lang::WrappedTargetException, return xRef; } -uno::Any SAL_CALL SwXParagraphEnumeration::nextElement() -throw (container::NoSuchElementException, lang::WrappedTargetException, - uno::RuntimeException, std::exception) +uno::Any SAL_CALL SwXParagraphEnumerationImpl::nextElement() throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception) { SolarMutexGuard aGuard; - - if (m_pImpl->m_bFirstParagraph) + if (m_bFirstParagraph) { - m_pImpl->m_xNextPara = m_pImpl->NextElement_Impl(); - m_pImpl->m_bFirstParagraph = false; + m_xNextPara = NextElement_Impl(); + m_bFirstParagraph = false; } - const uno::Reference< text::XTextContent > xRef = m_pImpl->m_xNextPara; + const uno::Reference< text::XTextContent > xRef = m_xNextPara; if (!xRef.is()) { throw container::NoSuchElementException(); } - m_pImpl->m_xNextPara = m_pImpl->NextElement_Impl(); + m_xNextPara = NextElement_Impl(); uno::Any aRet; aRet <<= xRef; @@ -1279,7 +1277,7 @@ SwXTextRange::createEnumeration() throw (uno::RuntimeException, std::exception) const CursorType eSetType = (RANGE_IN_CELL == m_pImpl->m_eRangePosition) ? CURSOR_SELECTION_IN_TABLE : CURSOR_SELECTION; - return new SwXParagraphEnumeration(m_pImpl->m_xParentText, pNewCrsr, eSetType); + return SwXParagraphEnumeration::Create(m_pImpl->m_xParentText, pNewCrsr, eSetType); } uno::Type SAL_CALL SwXTextRange::getElementType() throw (uno::RuntimeException, std::exception) diff --git a/sw/source/core/unocore/unoredline.cxx b/sw/source/core/unocore/unoredline.cxx index 2183994f8eda..23954447767f 100644 --- a/sw/source/core/unocore/unoredline.cxx +++ b/sw/source/core/unocore/unoredline.cxx @@ -162,7 +162,7 @@ uno::Reference<container::XEnumeration> SwXRedlineText::createEnumeration() SwPaM aPam(aNodeIndex); aPam.Move(fnMoveForward, fnGoNode); auto pUnoCursor(GetDoc()->CreateUnoCrsr(*aPam.Start(), false)); - return new SwXParagraphEnumeration(this, pUnoCursor, CURSOR_REDLINE); + return SwXParagraphEnumeration::Create(this, pUnoCursor, CURSOR_REDLINE); } uno::Type SwXRedlineText::getElementType( ) throw(uno::RuntimeException, std::exception) @@ -539,7 +539,7 @@ uno::Reference< container::XEnumeration > SwXRedline::createEnumeration() throw SwPaM aPam(*pNodeIndex); aPam.Move(fnMoveForward, fnGoNode); auto pUnoCursor(GetDoc()->CreateUnoCrsr(*aPam.Start(), false)); - return new SwXParagraphEnumeration(this, pUnoCursor, CURSOR_REDLINE); + return SwXParagraphEnumeration::Create(this, pUnoCursor, CURSOR_REDLINE); } uno::Type SwXRedline::getElementType( ) throw(uno::RuntimeException, std::exception) diff --git a/sw/source/core/unocore/unotbl.cxx b/sw/source/core/unocore/unotbl.cxx index 3bcbdce084bf..0a1cd0483446 100644 --- a/sw/source/core/unocore/unotbl.cxx +++ b/sw/source/core/unocore/unotbl.cxx @@ -1117,7 +1117,7 @@ uno::Reference<container::XEnumeration> SwXCell::createEnumeration() throw( uno: // remember table and start node for later travelling // (used in export of tables in tables) SwTable const*const pTable(&pSttNd->FindTableNode()->GetTable()); - return new SwXParagraphEnumeration(this, pUnoCursor, CURSOR_TBLTEXT, pSttNd, pTable); + return SwXParagraphEnumeration::Create(this, pUnoCursor, CURSOR_TBLTEXT, pSttNd, pTable); } uno::Type SAL_CALL SwXCell::getElementType() throw( uno::RuntimeException, std::exception ) diff --git a/sw/source/core/unocore/unotext.cxx b/sw/source/core/unocore/unotext.cxx index 5f08022be390..8baa445f63fd 100644 --- a/sw/source/core/unocore/unotext.cxx +++ b/sw/source/core/unocore/unotext.cxx @@ -2566,7 +2566,7 @@ throw (uno::RuntimeException, std::exception) SwPosition aPos(rNode); auto pUnoCursor(GetDoc()->CreateUnoCrsr(aPos, false)); pUnoCursor->Move(fnMoveBackward, fnGoDoc); - return new SwXParagraphEnumeration(this, pUnoCursor, CURSOR_BODY); + return SwXParagraphEnumeration::Create(this, pUnoCursor, CURSOR_BODY); } uno::Type SAL_CALL @@ -2828,8 +2828,7 @@ throw (uno::RuntimeException, std::exception) SwPosition aPos(rNode); auto pUnoCursor(GetDoc()->CreateUnoCrsr(aPos, false)); pUnoCursor->Move(fnMoveForward, fnGoNode); - return new SwXParagraphEnumeration(this, pUnoCursor, - (m_pImpl->m_bIsHeader) ? CURSOR_HEADER : CURSOR_FOOTER); + return SwXParagraphEnumeration::Create(this, pUnoCursor, (m_pImpl->m_bIsHeader) ? CURSOR_HEADER : CURSOR_FOOTER); } uno::Type SAL_CALL |