toolkit/source/controls/tree/treedatamodel.cxx |   31 ++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 6 deletions(-)

New commits:
commit 9abe8ee067e6c00f19d8a13346d53c4641c27166
Author:     Stephan Bergmann <sberg...@redhat.com>
AuthorDate: Thu Dec 1 15:16:32 2022 +0100
Commit:     Stephan Bergmann <sberg...@redhat.com>
CommitDate: Thu Dec 22 13:07:49 2022 +0000

    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 <sberg...@redhat.com>

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 *

Reply via email to