Kaydet (Commit) 736d19c4 authored tarafından Bjoern Michaelsen's avatar Bjoern Michaelsen

use ABC instead of Pimpl for SwXTextRanges

- abstract base class reduces boilerplate
- Pimpl is pointless here, except for SolarMutex, which is handled by
  overriding release

Change-Id: I55df9b20c9b0a78412535f2cca37e04ddaccb5cf
üst f14a3a04
...@@ -263,54 +263,11 @@ typedef ::cppu::WeakImplHelper ...@@ -263,54 +263,11 @@ typedef ::cppu::WeakImplHelper
, ::com::sun::star::container::XIndexAccess , ::com::sun::star::container::XIndexAccess
> SwXTextRanges_Base; > SwXTextRanges_Base;
class SwXTextRanges struct SwXTextRanges : public SwXTextRanges_Base
: public SwXTextRanges_Base
{ {
virtual SwUnoCrsr* GetCursor() =0;
private: static SwXTextRanges* Create(SwPaM* const pCrsr);
class Impl;
::sw::UnoImplPtr<Impl> m_pImpl;
virtual ~SwXTextRanges();
public:
SwXTextRanges(SwPaM *const pCrsr);
const SwUnoCrsr* GetCursor() const;
static const ::com::sun::star::uno::Sequence< sal_Int8 >& getUnoTunnelId(); static const ::com::sun::star::uno::Sequence< sal_Int8 >& getUnoTunnelId();
// XUnoTunnel
virtual sal_Int64 SAL_CALL getSomething(
const ::com::sun::star::uno::Sequence< sal_Int8 >& rIdentifier)
throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
// 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;
// XElementAccess
virtual ::com::sun::star::uno::Type SAL_CALL getElementType()
throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
virtual sal_Bool SAL_CALL hasElements()
throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
// XIndexAccess
virtual sal_Int32 SAL_CALL getCount()
throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
virtual ::com::sun::star::uno::Any SAL_CALL getByIndex(sal_Int32 nIndex)
throw (::com::sun::star::lang::IndexOutOfBoundsException,
::com::sun::star::lang::WrappedTargetException,
::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
}; };
#endif // INCLUDED_SW_INC_UNOTEXTRANGE_HXX #endif // INCLUDED_SW_INC_UNOTEXTRANGE_HXX
......
...@@ -173,7 +173,7 @@ void GetSelectableFromAny(uno::Reference<uno::XInterface> const& xIfc, ...@@ -173,7 +173,7 @@ void GetSelectableFromAny(uno::Reference<uno::XInterface> const& xIfc,
return; return;
} }
SwXTextRanges *const pRanges( SwXTextRanges* const pRanges(
::sw::UnoTunnelGetImplementation<SwXTextRanges>(xTunnel)); ::sw::UnoTunnelGetImplementation<SwXTextRanges>(xTunnel));
if (pRanges) if (pRanges)
{ {
......
...@@ -1466,13 +1466,25 @@ throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception) ...@@ -1466,13 +1466,25 @@ throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
SwUnoCursorHelper::makeRedline( aPaM, rRedlineType, rRedlineProperties ); SwUnoCursorHelper::makeRedline( aPaM, rRedlineType, rRedlineProperties );
} }
class SwXTextRanges::Impl struct SwXTextRangesImpl SAL_FINAL : public SwXTextRanges
{ {
public:
::std::vector< uno::Reference< text::XTextRange > > m_Ranges;
sw::UnoCursorPointer m_pUnoCursor;
explicit Impl(SwPaM *const pPaM) // XUnoTunnel
virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rIdentifier) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
// 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;
// XElementAccess
virtual ::com::sun::star::uno::Type SAL_CALL getElementType() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
virtual sal_Bool SAL_CALL hasElements() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
// XIndexAccess
virtual sal_Int32 SAL_CALL getCount() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
virtual ::com::sun::star::uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
SwXTextRangesImpl(SwPaM *const pPaM)
{ {
if (pPaM) if (pPaM)
{ {
...@@ -1481,13 +1493,19 @@ public: ...@@ -1481,13 +1493,19 @@ public:
} }
MakeRanges(); MakeRanges();
} }
virtual void SAL_CALL release() throw () SAL_OVERRIDE
SwUnoCrsr* GetCursor() {
{ return &(*m_pUnoCursor); } SolarMutexGuard g;
OWeakObject::release();
}
virtual SwUnoCrsr* GetCursor() SAL_OVERRIDE
{ return &(*m_pUnoCursor); };
void MakeRanges(); void MakeRanges();
::std::vector< uno::Reference< text::XTextRange > > m_Ranges;
sw::UnoCursorPointer m_pUnoCursor;
}; };
void SwXTextRanges::Impl::MakeRanges() void SwXTextRangesImpl::MakeRanges()
{ {
if (GetCursor()) if (GetCursor())
{ {
...@@ -1505,19 +1523,8 @@ void SwXTextRanges::Impl::MakeRanges() ...@@ -1505,19 +1523,8 @@ void SwXTextRanges::Impl::MakeRanges()
} }
} }
const SwUnoCrsr* SwXTextRanges::GetCursor() const SwXTextRanges* SwXTextRanges::Create(SwPaM *const pPaM)
{ { return new SwXTextRangesImpl(pPaM); }
return m_pImpl->GetCursor();
}
SwXTextRanges::SwXTextRanges(SwPaM *const pPaM)
: m_pImpl( new SwXTextRanges::Impl(pPaM) )
{
}
SwXTextRanges::~SwXTextRanges()
{
}
namespace namespace
{ {
...@@ -1525,13 +1532,11 @@ namespace ...@@ -1525,13 +1532,11 @@ namespace
} }
const uno::Sequence< sal_Int8 > & SwXTextRanges::getUnoTunnelId() const uno::Sequence< sal_Int8 > & SwXTextRanges::getUnoTunnelId()
{ { return theSwXTextRangesUnoTunnelId::get().getSeq(); }
return theSwXTextRangesUnoTunnelId::get().getSeq();
}
sal_Int64 SAL_CALL sal_Int64 SAL_CALL
SwXTextRanges::getSomething(const uno::Sequence< sal_Int8 >& rId) SwXTextRangesImpl::getSomething(const uno::Sequence< sal_Int8 >& rId)
throw (uno::RuntimeException, std::exception) throw (uno::RuntimeException, std::exception)
{ {
return ::sw::UnoTunnelImpl<SwXTextRanges>(rId, this); return ::sw::UnoTunnelImpl<SwXTextRanges>(rId, this);
} }
...@@ -1541,63 +1546,46 @@ throw (uno::RuntimeException, std::exception) ...@@ -1541,63 +1546,46 @@ throw (uno::RuntimeException, std::exception)
* Up to the first access to a text position, only a SwCursor is stored. * Up to the first access to a text position, only a SwCursor is stored.
* Afterwards, an array with uno::Reference<XTextPosition> will be created. * Afterwards, an array with uno::Reference<XTextPosition> will be created.
*/ */
OUString SAL_CALL OUString SAL_CALL SwXTextRangesImpl::getImplementationName()
SwXTextRanges::getImplementationName() throw (uno::RuntimeException, std::exception) throw (uno::RuntimeException, std::exception)
{ {
return OUString("SwXTextRanges"); return OUString("SwXTextRanges");
} }
static char const*const g_ServicesTextRanges[] = sal_Bool SAL_CALL SwXTextRangesImpl::supportsService(const OUString& rServiceName)
{ throw (uno::RuntimeException, std::exception)
"com.sun.star.text.TextRanges",
};
static const size_t g_nServicesTextRanges(
sizeof(g_ServicesTextRanges)/sizeof(g_ServicesTextRanges[0]));
sal_Bool SAL_CALL SwXTextRanges::supportsService(const OUString& rServiceName)
throw (uno::RuntimeException, std::exception)
{ {
return cppu::supportsService(this, rServiceName); return cppu::supportsService(this, rServiceName);
} }
uno::Sequence< OUString > SAL_CALL uno::Sequence< OUString > SAL_CALL SwXTextRangesImpl::getSupportedServiceNames()
SwXTextRanges::getSupportedServiceNames() throw (uno::RuntimeException, std::exception) throw (uno::RuntimeException, std::exception)
{ {
return ::sw::GetSupportedServiceNamesImpl( return { "com.sun.star.text.TextRanges" };
g_nServicesTextRanges, g_ServicesTextRanges);
} }
sal_Int32 SAL_CALL SwXTextRanges::getCount() throw (uno::RuntimeException, std::exception) sal_Int32 SAL_CALL SwXTextRangesImpl::getCount()
throw (uno::RuntimeException, std::exception)
{ {
SolarMutexGuard aGuard; SolarMutexGuard aGuard;
return static_cast<sal_Int32>(m_Ranges.size());
return static_cast<sal_Int32>(m_pImpl->m_Ranges.size());
} }
uno::Any SAL_CALL SwXTextRanges::getByIndex(sal_Int32 nIndex) uno::Any SAL_CALL SwXTextRangesImpl::getByIndex(sal_Int32 nIndex) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException,
uno::RuntimeException, std::exception)
{ {
SolarMutexGuard aGuard; SolarMutexGuard aGuard;
if ((nIndex < 0) || (static_cast<size_t>(nIndex) >= m_Ranges.size()))
if ((nIndex < 0) ||
(static_cast<size_t>(nIndex) >= m_pImpl->m_Ranges.size()))
{
throw lang::IndexOutOfBoundsException(); throw lang::IndexOutOfBoundsException();
}
uno::Any ret; uno::Any ret;
ret <<= (m_pImpl->m_Ranges.at(nIndex)); ret <<= (m_Ranges.at(nIndex));
return ret; return ret;
} }
uno::Type SAL_CALL uno::Type SAL_CALL
SwXTextRanges::getElementType() throw (uno::RuntimeException, std::exception) SwXTextRangesImpl::getElementType() throw (uno::RuntimeException, std::exception)
{ { return cppu::UnoType<text::XTextRange>::get(); }
return cppu::UnoType<text::XTextRange>::get();
}
sal_Bool SAL_CALL SwXTextRanges::hasElements() throw (uno::RuntimeException, std::exception) sal_Bool SAL_CALL SwXTextRangesImpl::hasElements() throw (uno::RuntimeException, std::exception)
{ {
// no mutex necessary: getCount() does locking // no mutex necessary: getCount() does locking
return getCount() > 0; return getCount() > 0;
......
...@@ -942,7 +942,7 @@ Reference< XIndexAccess > ...@@ -942,7 +942,7 @@ Reference< XIndexAccess >
if(!pResultCrsr) if(!pResultCrsr)
throw RuntimeException(); throw RuntimeException();
Reference< XIndexAccess > xRet; Reference< XIndexAccess > xRet;
xRet = new SwXTextRanges( (nResult) ? pResultCrsr.get() : 0 ); xRet = SwXTextRanges::Create( (nResult) ? pResultCrsr.get() : nullptr );
return xRet; return xRet;
} }
......
...@@ -352,7 +352,7 @@ uno::Any SwXTextView::getSelection() ...@@ -352,7 +352,7 @@ uno::Any SwXTextView::getSelection()
case SHELL_MODE_TABLE_LIST_TEXT: case SHELL_MODE_TABLE_LIST_TEXT:
case SHELL_MODE_TEXT : case SHELL_MODE_TEXT :
{ {
uno::Reference< container::XIndexAccess > xPos = new SwXTextRanges(rSh.GetCrsr()); uno::Reference< container::XIndexAccess > xPos = SwXTextRanges::Create(rSh.GetCrsr());
aRef = uno::Reference< uno::XInterface >(xPos, uno::UNO_QUERY); aRef = uno::Reference< uno::XInterface >(xPos, uno::UNO_QUERY);
} }
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment