dbaccess/source/core/dataaccess/documentdefinition.cxx | 13 vcl/inc/dndlistenercontainer.hxx | 10 vcl/source/window/dndlistenercontainer.cxx | 419 +++++++---------- 3 files changed, 204 insertions(+), 238 deletions(-)
New commits: commit db02d2e1a74973cfb467c2f5bb12845bfdf37302 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Sun Mar 5 15:58:01 2023 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Mon Mar 6 06:43:02 2023 +0000 BaseMutex->std::mutex in DNDListenerContainer Change-Id: I0e7bb629eb4d52ddd43774a2c1a5133d6f265d23 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148278 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/vcl/inc/dndlistenercontainer.hxx b/vcl/inc/dndlistenercontainer.hxx index 870cc05dfacb..5a2f0571ca7a 100644 --- a/vcl/inc/dndlistenercontainer.hxx +++ b/vcl/inc/dndlistenercontainer.hxx @@ -26,7 +26,8 @@ #include <com/sun/star/datatransfer/dnd/XDropTargetDragContext.hpp> #include <com/sun/star/datatransfer/dnd/XDropTargetDropContext.hpp> #include <cppuhelper/compbase.hxx> -#include <cppuhelper/basemutex.hxx> +#include <comphelper/compbase.hxx> +#include <comphelper/interfacecontainer4.hxx> #include <vcl/unohelp2.hxx> @@ -53,8 +54,8 @@ public: virtual void SAL_CALL rejectDrag() override; }; -class DNDListenerContainer final : public cppu::BaseMutex, - public ::cppu::WeakComponentImplHelper< +class DNDListenerContainer final : + public ::comphelper::WeakComponentImplHelper< css::datatransfer::dnd::XDragGestureRecognizer, css::datatransfer::dnd::XDropTargetDragContext, css::datatransfer::dnd::XDropTargetDropContext, @@ -62,7 +63,8 @@ class DNDListenerContainer final : public cppu::BaseMutex, { bool m_bActive; sal_Int8 m_nDefaultActions; - + comphelper::OInterfaceContainerHelper4<css::datatransfer::dnd::XDragGestureListener> maDragGestureListeners; + comphelper::OInterfaceContainerHelper4<css::datatransfer::dnd::XDropTargetListener> maDropTargetListeners; css::uno::Reference< css::datatransfer::dnd::XDropTargetDragContext > m_xDropTargetDragContext; css::uno::Reference< css::datatransfer::dnd::XDropTargetDropContext > m_xDropTargetDropContext; diff --git a/vcl/source/window/dndlistenercontainer.cxx b/vcl/source/window/dndlistenercontainer.cxx index d3147aac5288..fdc7c40c810e 100644 --- a/vcl/source/window/dndlistenercontainer.cxx +++ b/vcl/source/window/dndlistenercontainer.cxx @@ -25,7 +25,6 @@ using namespace ::com::sun::star::datatransfer; using namespace ::com::sun::star::datatransfer::dnd; DNDListenerContainer::DNDListenerContainer( sal_Int8 nDefaultActions ) - : WeakComponentImplHelper< XDragGestureRecognizer, XDropTargetDragContext, XDropTargetDropContext, XDropTarget >(m_aMutex) { m_bActive = true; m_nDefaultActions = nDefaultActions; @@ -37,12 +36,14 @@ DNDListenerContainer::~DNDListenerContainer() void SAL_CALL DNDListenerContainer::addDragGestureListener( const Reference< XDragGestureListener >& dgl ) { - rBHelper.addListener( cppu::UnoType<XDragGestureListener>::get(), dgl ); + std::unique_lock g(m_aMutex); + maDragGestureListeners.addInterface( g, dgl ); } void SAL_CALL DNDListenerContainer::removeDragGestureListener( const Reference< XDragGestureListener >& dgl ) { - rBHelper.removeListener( cppu::UnoType<XDragGestureListener>::get(), dgl ); + std::unique_lock g(m_aMutex); + maDragGestureListeners.removeInterface( g, dgl ); } void SAL_CALL DNDListenerContainer::resetRecognizer( ) @@ -51,12 +52,14 @@ void SAL_CALL DNDListenerContainer::resetRecognizer( ) void SAL_CALL DNDListenerContainer::addDropTargetListener( const Reference< XDropTargetListener >& dtl ) { - rBHelper.addListener( cppu::UnoType<XDropTargetListener>::get(), dtl ); + std::unique_lock g(m_aMutex); + maDropTargetListeners.addInterface( g, dtl ); } void SAL_CALL DNDListenerContainer::removeDropTargetListener( const Reference< XDropTargetListener >& dtl ) { - rBHelper.removeListener( cppu::UnoType<XDropTargetListener>::get(), dtl ); + std::unique_lock g(m_aMutex); + maDropTargetListeners.removeInterface( g, dtl ); } sal_Bool SAL_CALL DNDListenerContainer::isActive( ) @@ -83,65 +86,57 @@ sal_uInt32 DNDListenerContainer::fireDropEvent( const Reference< XDropTargetDrop sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions, const Reference< XTransferable >& transferable ) { - sal_uInt32 nRet = 0; + std::unique_lock g(m_aMutex); + if (!m_bActive || maDropTargetListeners.getLength(g) == 0) + return 0; - // fire DropTargetDropEvent on all XDropTargetListeners - OInterfaceContainerHelper *pContainer = rBHelper.getContainer( cppu::UnoType<XDropTargetListener>::get()); + sal_uInt32 nRet = 0; - if( pContainer && m_bActive ) - { - OInterfaceIteratorHelper aIterator( *pContainer ); + comphelper::OInterfaceIteratorHelper4 aIterator( g, maDropTargetListeners ); - // remember context to use in own context methods - m_xDropTargetDropContext = context; + // remember context to use in own context methods + m_xDropTargetDropContext = context; - // do not construct the event before you are sure at least one listener is registered - DropTargetDropEvent aEvent( static_cast < XDropTarget * > (this), 0, - static_cast < XDropTargetDropContext * > (this), dropAction, - locationX, locationY, sourceActions, transferable ); + // do not construct the event before you are sure at least one listener is registered + DropTargetDropEvent aEvent( static_cast < XDropTarget * > (this), 0, + static_cast < XDropTargetDropContext * > (this), dropAction, + locationX, locationY, sourceActions, transferable ); - while (aIterator.hasMoreElements()) + while (aIterator.hasMoreElements()) + { + Reference< XDropTargetListener > xListener( aIterator.next() ); + try { - // FIXME: this can be simplified as soon as the Iterator has a remove method - Reference< XInterface > xElement( aIterator.next() ); - - try - { - // this may result in a runtime exception - Reference < XDropTargetListener > xListener( xElement, UNO_QUERY ); - - if( xListener.is() ) - { - // fire drop until the first one has accepted - if( m_xDropTargetDropContext.is() ) - xListener->drop( aEvent ); - else - { - DropTargetEvent aDTEvent( static_cast < XDropTarget * > (this), 0 ); - xListener->dragExit( aDTEvent ); - } - - nRet++; - } - } - catch (const RuntimeException&) + g.unlock(); + // fire drop until the first one has accepted + if( m_xDropTargetDropContext.is() ) + xListener->drop( aEvent ); + else { - pContainer->removeInterface( xElement ); + DropTargetEvent aDTEvent( static_cast < XDropTarget * > (this), 0 ); + xListener->dragExit( aDTEvent ); } - } - // if context still valid, then reject drop - if( m_xDropTargetDropContext.is() ) + g.lock(); + nRet++; + } + catch (const RuntimeException&) { - m_xDropTargetDropContext.clear(); + aIterator.remove( g ); + } + } - try - { - context->rejectDrop(); - } - catch (const RuntimeException&) - { - } + // if context still valid, then reject drop + if( m_xDropTargetDropContext.is() ) + { + m_xDropTargetDropContext.clear(); + + try + { + context->rejectDrop(); + } + catch (const RuntimeException&) + { } } @@ -150,38 +145,30 @@ sal_uInt32 DNDListenerContainer::fireDropEvent( const Reference< XDropTargetDrop sal_uInt32 DNDListenerContainer::fireDragExitEvent() { - sal_uInt32 nRet = 0; + std::unique_lock g(m_aMutex); + if (!m_bActive || maDropTargetListeners.getLength(g) == 0) + return 0; - // fire DropTargetDropEvent on all XDropTargetListeners - OInterfaceContainerHelper *pContainer = rBHelper.getContainer( cppu::UnoType<XDropTargetListener>::get()); + sal_uInt32 nRet = 0; - if( pContainer && m_bActive ) - { - OInterfaceIteratorHelper aIterator( *pContainer ); + comphelper::OInterfaceIteratorHelper4 aIterator( g, maDropTargetListeners ); - // do not construct the event before you are sure at least one listener is registered - DropTargetEvent aEvent( static_cast < XDropTarget * > (this), 0 ); + // do not construct the event before you are sure at least one listener is registered + DropTargetEvent aEvent( static_cast < XDropTarget * > (this), 0 ); - while (aIterator.hasMoreElements()) + while (aIterator.hasMoreElements()) + { + Reference< XDropTargetListener > xListener( aIterator.next() ); + try { - // FIXME: this can be simplified as soon as the Iterator has a remove method - Reference< XInterface > xElement( aIterator.next() ); - - try - { - // this may result in a runtime exception - Reference < XDropTargetListener > xListener( xElement, UNO_QUERY ); - - if( xListener.is() ) - { - xListener->dragExit( aEvent ); - nRet++; - } - } - catch (const RuntimeException&) - { - pContainer->removeInterface( xElement ); - } + g.unlock(); + xListener->dragExit( aEvent ); + nRet++; + g.lock(); + } + catch (const RuntimeException&) + { + aIterator.remove( g ); } } @@ -191,58 +178,54 @@ sal_uInt32 DNDListenerContainer::fireDragExitEvent() sal_uInt32 DNDListenerContainer::fireDragOverEvent( const Reference< XDropTargetDragContext >& context, sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions ) { + std::unique_lock g(m_aMutex); + if (!m_bActive || maDropTargetListeners.getLength(g) == 0) + return 0; + sal_uInt32 nRet = 0; // fire DropTargetDropEvent on all XDropTargetListeners - OInterfaceContainerHelper *pContainer = rBHelper.getContainer( cppu::UnoType<XDropTargetListener>::get()); - if( pContainer && m_bActive ) - { - OInterfaceIteratorHelper aIterator( *pContainer ); + comphelper::OInterfaceIteratorHelper4 aIterator( g, maDropTargetListeners ); - // remember context to use in own context methods - m_xDropTargetDragContext = context; + // remember context to use in own context methods + m_xDropTargetDragContext = context; - // do not construct the event before you are sure at least one listener is registered - DropTargetDragEvent aEvent( static_cast < XDropTarget * > (this), 0, - static_cast < XDropTargetDragContext * > (this), - dropAction, locationX, locationY, sourceActions ); + // do not construct the event before you are sure at least one listener is registered + DropTargetDragEvent aEvent( static_cast < XDropTarget * > (this), 0, + static_cast < XDropTargetDragContext * > (this), + dropAction, locationX, locationY, sourceActions ); - while (aIterator.hasMoreElements()) + while (aIterator.hasMoreElements()) + { + Reference< XDropTargetListener > xListener( aIterator.next() ); + try { - // FIXME: this can be simplified as soon as the Iterator has a remove method - Reference< XInterface > xElement( aIterator.next() ); - - try + if( m_xDropTargetDragContext.is() ) { - // this may result in a runtime exception - Reference < XDropTargetListener > xListener( xElement, UNO_QUERY ); - - if( xListener.is() ) - { - if( m_xDropTargetDragContext.is() ) - xListener->dragOver( aEvent ); - nRet++; - } - } - catch (const RuntimeException&) - { - pContainer->removeInterface( xElement ); + g.unlock(); + xListener->dragOver( aEvent ); + g.lock(); } + nRet++; } - - // if context still valid, then reject drag - if( m_xDropTargetDragContext.is() ) + catch (const RuntimeException&) { - m_xDropTargetDragContext.clear(); + aIterator.remove(g); + } + } - try - { - context->rejectDrag(); - } - catch (const RuntimeException&) - { - } + // if context still valid, then reject drag + if( m_xDropTargetDragContext.is() ) + { + m_xDropTargetDragContext.clear(); + + try + { + context->rejectDrag(); + } + catch (const RuntimeException&) + { } } @@ -253,58 +236,52 @@ sal_uInt32 DNDListenerContainer::fireDragEnterEvent( const Reference< XDropTarge sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions, const Sequence< DataFlavor >& dataFlavors ) { - sal_uInt32 nRet = 0; + std::unique_lock g(m_aMutex); + if (!m_bActive || maDropTargetListeners.getLength(g) == 0) + return 0; - // fire DropTargetDropEvent on all XDropTargetListeners - OInterfaceContainerHelper *pContainer = rBHelper.getContainer( cppu::UnoType<XDropTargetListener>::get()); + sal_uInt32 nRet = 0; - if( pContainer && m_bActive ) - { - OInterfaceIteratorHelper aIterator( *pContainer ); + comphelper::OInterfaceIteratorHelper4 aIterator( g, maDropTargetListeners ); - // remember context to use in own context methods - m_xDropTargetDragContext = context; + // remember context to use in own context methods + m_xDropTargetDragContext = context; - // do not construct the event before you are sure at least one listener is registered - DropTargetDragEnterEvent aEvent( static_cast < XDropTarget * > (this), 0, - static_cast < XDropTargetDragContext * > (this), - dropAction, locationX, locationY, sourceActions, dataFlavors ); + // do not construct the event before you are sure at least one listener is registered + DropTargetDragEnterEvent aEvent( static_cast < XDropTarget * > (this), 0, + static_cast < XDropTargetDragContext * > (this), + dropAction, locationX, locationY, sourceActions, dataFlavors ); - while (aIterator.hasMoreElements()) + while (aIterator.hasMoreElements()) + { + Reference< XDropTargetListener > xListener( aIterator.next() ); + try { - // FIXME: this can be simplified as soon as the Iterator has a remove method - Reference< XInterface > xElement( aIterator.next() ); - - try - { - // this may result in a runtime exception - Reference < XDropTargetListener > xListener( xElement, UNO_QUERY ); - - if( xListener.is() ) - { - if( m_xDropTargetDragContext.is() ) - xListener->dragEnter( aEvent ); - nRet++; - } - } - catch (const RuntimeException&) + if( m_xDropTargetDragContext.is() ) { - pContainer->removeInterface( xElement ); + g.unlock(); + xListener->dragEnter( aEvent ); + g.lock(); } + nRet++; } - - // if context still valid, then reject drag - if( m_xDropTargetDragContext.is() ) + catch (const RuntimeException&) { - m_xDropTargetDragContext.clear(); + aIterator.remove( g ); + } + } - try - { - context->rejectDrag(); - } - catch (const RuntimeException&) - { - } + // if context still valid, then reject drag + if( m_xDropTargetDragContext.is() ) + { + m_xDropTargetDragContext.clear(); + + try + { + context->rejectDrag(); + } + catch (const RuntimeException&) + { } } @@ -314,58 +291,54 @@ sal_uInt32 DNDListenerContainer::fireDragEnterEvent( const Reference< XDropTarge sal_uInt32 DNDListenerContainer::fireDropActionChangedEvent( const Reference< XDropTargetDragContext >& context, sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions ) { + std::unique_lock g(m_aMutex); + if (!m_bActive || maDropTargetListeners.getLength(g) == 0) + return 0; + sal_uInt32 nRet = 0; // fire DropTargetDropEvent on all XDropTargetListeners - OInterfaceContainerHelper *pContainer = rBHelper.getContainer( cppu::UnoType<XDropTargetListener>::get()); - if( pContainer && m_bActive ) - { - OInterfaceIteratorHelper aIterator( *pContainer ); + comphelper::OInterfaceIteratorHelper4 aIterator( g, maDropTargetListeners ); - // remember context to use in own context methods - m_xDropTargetDragContext = context; + // remember context to use in own context methods + m_xDropTargetDragContext = context; - // do not construct the event before you are sure at least one listener is registered - DropTargetDragEvent aEvent( static_cast < XDropTarget * > (this), 0, - static_cast < XDropTargetDragContext * > (this), - dropAction, locationX, locationY, sourceActions ); + // do not construct the event before you are sure at least one listener is registered + DropTargetDragEvent aEvent( static_cast < XDropTarget * > (this), 0, + static_cast < XDropTargetDragContext * > (this), + dropAction, locationX, locationY, sourceActions ); - while (aIterator.hasMoreElements()) + while (aIterator.hasMoreElements()) + { + Reference< XDropTargetListener > xListener( aIterator.next() ); + try { - // FIXME: this can be simplified as soon as the Iterator has a remove method - Reference< XInterface > xElement( aIterator.next() ); - - try - { - // this may result in a runtime exception - Reference < XDropTargetListener > xListener( xElement, UNO_QUERY ); - - if( xListener.is() ) - { - if( m_xDropTargetDragContext.is() ) - xListener->dropActionChanged( aEvent ); - nRet++; - } - } - catch (const RuntimeException&) + if( m_xDropTargetDragContext.is() ) { - pContainer->removeInterface( xElement ); + g.unlock(); + xListener->dropActionChanged( aEvent ); + g.lock(); } + nRet++; } - - // if context still valid, then reject drag - if( m_xDropTargetDragContext.is() ) + catch (const RuntimeException&) { - m_xDropTargetDragContext.clear(); + aIterator.remove( g ); + } + } - try - { - context->rejectDrag(); - } - catch (const RuntimeException&) - { - } + // if context still valid, then reject drag + if( m_xDropTargetDragContext.is() ) + { + m_xDropTargetDragContext.clear(); + + try + { + context->rejectDrag(); + } + catch (const RuntimeException&) + { } } @@ -375,39 +348,31 @@ sal_uInt32 DNDListenerContainer::fireDropActionChangedEvent( const Reference< XD sal_uInt32 DNDListenerContainer::fireDragGestureEvent( sal_Int8 dragAction, sal_Int32 dragOriginX, sal_Int32 dragOriginY, const Reference< XDragSource >& dragSource, const Any& triggerEvent ) { + std::unique_lock g(m_aMutex); + if (maDragGestureListeners.getLength(g) == 0) + return 0; + sal_uInt32 nRet = 0; - // fire DropTargetDropEvent on all XDropTargetListeners - OInterfaceContainerHelper *pContainer = rBHelper.getContainer( cppu::UnoType<XDragGestureListener>::get()); + comphelper::OInterfaceIteratorHelper4 aIterator( g, maDragGestureListeners ); - if( pContainer ) - { - OInterfaceIteratorHelper aIterator( *pContainer ); + // do not construct the event before you are sure at least one listener is registered + DragGestureEvent aEvent( static_cast < XDragGestureRecognizer * > (this), dragAction, + dragOriginX, dragOriginY, dragSource, triggerEvent ); - // do not construct the event before you are sure at least one listener is registered - DragGestureEvent aEvent( static_cast < XDragGestureRecognizer * > (this), dragAction, - dragOriginX, dragOriginY, dragSource, triggerEvent ); - - while( aIterator.hasMoreElements() ) + while( aIterator.hasMoreElements() ) + { + Reference< XDragGestureListener > xListener( aIterator.next() ); + try { - // FIXME: this can be simplified as soon as the Iterator has a remove method - Reference< XInterface > xElement( aIterator.next() ); - - try - { - // this may result in a runtime exception - Reference < XDragGestureListener > xListener( xElement, UNO_QUERY ); - - if( xListener.is() ) - { - xListener->dragGestureRecognized( aEvent ); - nRet++; - } - } - catch (const RuntimeException&) - { - pContainer->removeInterface( xElement ); - } + g.unlock(); + xListener->dragGestureRecognized( aEvent ); + g.lock(); + nRet++; + } + catch (const RuntimeException&) + { + aIterator.remove( g ); } } commit 974b837030185e71bb5c817cf0faf409682a432d Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Sun Mar 5 15:20:30 2023 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Mon Mar 6 06:42:52 2023 +0000 BaseMutex->std::mutex in OEmbedObjectHolder Change-Id: I0c05556e1d2585b48068094627be3e58a2640340 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148275 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/dbaccess/source/core/dataaccess/documentdefinition.cxx b/dbaccess/source/core/dataaccess/documentdefinition.cxx index dbbb7eb94ecc..28152e6c3b9a 100644 --- a/dbaccess/source/core/dataaccess/documentdefinition.cxx +++ b/dbaccess/source/core/dataaccess/documentdefinition.cxx @@ -23,6 +23,7 @@ #include <sdbcoretools.hxx> #include <comphelper/diagnose_ex.hxx> #include <osl/diagnose.h> +#include <comphelper/compbase.hxx> #include <comphelper/sequence.hxx> #include <comphelper/namedvaluecollection.hxx> #include <comphelper/classids.hxx> @@ -147,22 +148,20 @@ namespace dbaccess } // OEmbedObjectHolder - typedef ::cppu::WeakComponentImplHelper< embed::XStateChangeListener > TEmbedObjectHolder; + typedef ::comphelper::WeakComponentImplHelper< embed::XStateChangeListener > TEmbedObjectHolder; namespace { - class OEmbedObjectHolder : public ::cppu::BaseMutex - ,public TEmbedObjectHolder + class OEmbedObjectHolder : public TEmbedObjectHolder { Reference< XEmbeddedObject > m_xBroadCaster; ODocumentDefinition* m_pDefinition; bool m_bInStateChange; protected: - virtual void SAL_CALL disposing() override; + virtual void disposing(std::unique_lock<std::mutex>& rGuard) override; public: OEmbedObjectHolder(const Reference< XEmbeddedObject >& _xBroadCaster,ODocumentDefinition* _pDefinition) - : TEmbedObjectHolder(m_aMutex) - ,m_xBroadCaster(_xBroadCaster) + : m_xBroadCaster(_xBroadCaster) ,m_pDefinition(_pDefinition) ,m_bInStateChange(false) { @@ -181,7 +180,7 @@ namespace dbaccess } - void SAL_CALL OEmbedObjectHolder::disposing() + void OEmbedObjectHolder::disposing(std::unique_lock<std::mutex>& /*rGuard*/) { if ( m_xBroadCaster.is() ) m_xBroadCaster->removeStateChangeListener(this);