summaryrefslogtreecommitdiff
path: root/toolkit
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2022-12-01 15:16:32 +0100
committerStephan Bergmann <sbergman@redhat.com>2022-12-22 13:07:49 +0000
commit9abe8ee067e6c00f19d8a13346d53c4641c27166 (patch)
tree06cd4b92bbbcdf3b198ffdd023b0ef94752f35ff /toolkit
parent9f3022ceb036f23b4b0994c3e2fbd1001bff225a (diff)
loplugin:unocast (MutableTreeNode)
(See the upcoming commit introducing that loplugin:unocast on why such dynamic_casts from UNO types are dangerous.) Change-Id: I33fc079e2128c678ecc36567c2c5ed75481694c6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144752 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'toolkit')
-rw-r--r--toolkit/source/controls/tree/treedatamodel.cxx31
1 files changed, 25 insertions, 6 deletions
diff --git a/toolkit/source/controls/tree/treedatamodel.cxx b/toolkit/source/controls/tree/treedatamodel.cxx
index 090a6738f517..bf09ff269564 100644
--- a/toolkit/source/controls/tree/treedatamodel.cxx
+++ b/toolkit/source/controls/tree/treedatamodel.cxx
@@ -22,7 +22,9 @@
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
+#include <comphelper/servicehelper.hxx>
#include <cppuhelper/implbase2.hxx>
+#include <cppuhelper/implbase3.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <o3tl/safeint.hxx>
#include <rtl/ref.hxx>
@@ -77,7 +79,8 @@ private:
Reference< XTreeNode > mxRootNode;
};
-class MutableTreeNode: public ::cppu::WeakAggImplHelper2< XMutableTreeNode, XServiceInfo >
+class MutableTreeNode:
+ public ::cppu::WeakAggImplHelper3< XMutableTreeNode, XServiceInfo, css::lang::XUnoTunnel >
{
friend class MutableTreeDataModel;
@@ -118,6 +121,9 @@ public:
virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
+ sal_Int64 SAL_CALL getSomething(css::uno::Sequence<sal_Int8> const & aIdentifier) override;
+ static css::uno::Sequence<sal_Int8> const & getUnoTunnelId();
+
private:
TreeNodeVector maChildren;
Any maDisplayValue;
@@ -177,12 +183,13 @@ void SAL_CALL MutableTreeDataModel::setRoot( const Reference< XMutableTreeNode >
if( mxRootNode.is() )
{
- rtl::Reference< MutableTreeNode > xOldImpl( dynamic_cast< MutableTreeNode* >( mxRootNode.get() ) );
+ rtl::Reference< MutableTreeNode > xOldImpl( comphelper::getFromUnoTunnel< MutableTreeNode >( mxRootNode ) );
if( xOldImpl.is() )
xOldImpl->mbIsInserted = false;
}
- rtl::Reference< MutableTreeNode > xImpl( dynamic_cast< MutableTreeNode* >( xNode.get() ) );
+ rtl::Reference< MutableTreeNode > xImpl(
+ comphelper::getFromUnoTunnel< MutableTreeNode >( xNode ) );
if( !xImpl.is() || xImpl->mbIsInserted )
throw IllegalArgumentException();
@@ -302,7 +309,8 @@ void SAL_CALL MutableTreeNode::setDataValue( const Any& _datavalue )
void SAL_CALL MutableTreeNode::appendChild( const Reference< XMutableTreeNode >& xChildNode )
{
std::unique_lock aGuard( maMutex );
- rtl::Reference< MutableTreeNode > xImpl( dynamic_cast< MutableTreeNode* >( xChildNode.get() ) );
+ rtl::Reference< MutableTreeNode > xImpl(
+ comphelper::getFromUnoTunnel< MutableTreeNode >( xChildNode ) );
if( !xImpl.is() || xImpl->mbIsInserted || (this == xImpl.get()) )
throw IllegalArgumentException();
@@ -321,7 +329,8 @@ void SAL_CALL MutableTreeNode::insertChildByIndex( sal_Int32 nChildIndex, const
if( (nChildIndex < 0) || (o3tl::make_unsigned(nChildIndex) > maChildren.size()) )
throw IndexOutOfBoundsException();
- rtl::Reference< MutableTreeNode > xImpl( dynamic_cast< MutableTreeNode* >( xChildNode.get() ) );
+ rtl::Reference< MutableTreeNode > xImpl(
+ comphelper::getFromUnoTunnel< MutableTreeNode >( xChildNode ) );
if( !xImpl.is() || xImpl->mbIsInserted || (this == xImpl.get()) )
throw IllegalArgumentException();
@@ -451,7 +460,8 @@ sal_Int32 SAL_CALL MutableTreeNode::getIndex( const Reference< XTreeNode >& xNod
{
std::scoped_lock aGuard( maMutex );
- rtl::Reference< MutableTreeNode > xImpl( dynamic_cast< MutableTreeNode* >( xNode.get() ) );
+ rtl::Reference< MutableTreeNode > xImpl(
+ comphelper::getFromUnoTunnel< MutableTreeNode >( xNode ) );
if( xImpl.is() )
{
sal_Int32 nChildCount = maChildren.size();
@@ -511,6 +521,15 @@ Sequence< OUString > SAL_CALL MutableTreeNode::getSupportedServiceNames( )
return aSeq;
}
+sal_Int64 MutableTreeNode::getSomething(css::uno::Sequence<sal_Int8> const & aIdentifier) {
+ return comphelper::getSomethingImpl(aIdentifier, this);
+}
+
+css::uno::Sequence<sal_Int8> const & MutableTreeNode::getUnoTunnelId() {
+ static comphelper::UnoIdInit const id;
+ return id.getSeq();
+}
+
}
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *