diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-08-20 17:03:13 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-08-23 15:11:27 +0200 |
commit | ec940941e0bd7db15c5cf7d43df82226e0d849dc (patch) | |
tree | a876a500dfa6a32bc8b284b3b07525480ba60765 /sw | |
parent | 1d524bc7a331e8381e88cfd1b6dea4678ad32514 (diff) |
tdf#119388 add new UNO listener/broadcaster
so that we only need to fire each event to the exact shape that wants
it, instead of spamming all the shapes.
Takes deleting a column from 20s to 10s for me.
Note that none of the broadcasters are calling disposing(EventObject),
so I did not make XShapeEventListener extend lang::XEventListener.
If a memory leak regression points at this commit, possibly I
missed something.
Change-Id: I2b8db08247d3e0203d41faf77491368168994e4d
Reviewed-on: https://gerrit.libreoffice.org/77857
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/core/access/accmap.cxx | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/sw/source/core/access/accmap.cxx b/sw/source/core/access/accmap.cxx index cb5709c54901..b5f2c615961b 100644 --- a/sw/source/core/access/accmap.cxx +++ b/sw/source/core/access/accmap.cxx @@ -62,7 +62,7 @@ #include <com/sun/star/accessibility/AccessibleStateType.hpp> #include <com/sun/star/accessibility/AccessibleRole.hpp> #include <com/sun/star/beans/XPropertySet.hpp> -#include <com/sun/star/document/XEventBroadcaster.hpp> +#include <com/sun/star/document/XShapeEventBroadcaster.hpp> #include <cppuhelper/implbase.hxx> #include <comphelper/interfacecontainer2.hxx> #include <pagepreviewlayout.hxx> @@ -126,10 +126,11 @@ public: }; class SwDrawModellListener_Impl : public SfxListener, - public ::cppu::WeakImplHelper< document::XEventBroadcaster > + public ::cppu::WeakImplHelper< document::XShapeEventBroadcaster > { mutable ::osl::Mutex maListenerMutex; ::comphelper::OInterfaceContainerHelper2 maEventListeners; + std::unordered_map<css::uno::Reference< css::drawing::XShape >, css::uno::Reference< css::document::XShapeEventListener >> maShapeListeners; SdrModel *mpDrawModel; protected: virtual ~SwDrawModellListener_Impl() override; @@ -137,8 +138,12 @@ protected: public: explicit SwDrawModellListener_Impl( SdrModel *pDrawModel ); + // css::document::XEventBroadcaster virtual void SAL_CALL addEventListener( const uno::Reference< document::XEventListener >& xListener ) override; virtual void SAL_CALL removeEventListener( const uno::Reference< document::XEventListener >& xListener ) override; + // css::document::XShapeEventBroadcaster + virtual void SAL_CALL addShapeEventListener( const css::uno::Reference< css::drawing::XShape >& xShape, const css::uno::Reference< css::document::XShapeEventListener >& xListener ) override; + virtual void SAL_CALL removeShapeEventListener( const css::uno::Reference< css::drawing::XShape >& xShape, const css::uno::Reference< css::document::XShapeEventListener >& xListener ) override; virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override; void Dispose(); @@ -166,6 +171,30 @@ void SAL_CALL SwDrawModellListener_Impl::removeEventListener( const uno::Referen maEventListeners.removeInterface( xListener ); } +void SAL_CALL SwDrawModellListener_Impl::addShapeEventListener( + const css::uno::Reference< css::drawing::XShape >& xShape, + const uno::Reference< document::XShapeEventListener >& xListener ) +{ + osl::MutexGuard aGuard(maListenerMutex); + auto rv = maShapeListeners.emplace(xShape, xListener); + assert(rv.second && "duplicate listener?"); + (void)rv; +} + +void SAL_CALL SwDrawModellListener_Impl::removeShapeEventListener( + const css::uno::Reference< css::drawing::XShape >& xShape, + const uno::Reference< document::XShapeEventListener >& xListener ) +{ + osl::MutexGuard aGuard(maListenerMutex); + auto it = maShapeListeners.find(xShape); + if (it != maShapeListeners.end()) + { + assert(it->second == xListener); + (void)xListener; + maShapeListeners.erase(it); + } +} + void SwDrawModellListener_Impl::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) { @@ -204,6 +233,17 @@ void SwDrawModellListener_Impl::Notify( SfxBroadcaster& /*rBC*/, TOOLS_WARN_EXCEPTION("sw.a11y", "Runtime exception caught while notifying shape"); } } + + // right now, we're only handling the specific event necessary to fix this performance problem + if (pSdrHint->GetKind() == SdrHintKind::ObjectChange) + { + auto pSdrObject = const_cast<SdrObject*>(pSdrHint->GetObject()); + uno::Reference<drawing::XShape> xShape(pSdrObject->getUnoShape(), uno::UNO_QUERY); + osl::MutexGuard aGuard(maListenerMutex); + auto it = maShapeListeners.find(xShape); + if (it != maShapeListeners.end()) + it->second->notifyShapeEvent(aEvent); + } } void SwDrawModellListener_Impl::Dispose() @@ -247,7 +287,7 @@ public: maInfo.SetSdrView( pMap->GetShell()->GetDrawView() ); maInfo.SetDevice( pMap->GetShell()->GetWin() ); maInfo.SetViewForwarder( pMap ); - uno::Reference < document::XEventBroadcaster > xModelBroadcaster = + uno::Reference < document::XShapeEventBroadcaster > xModelBroadcaster = new SwDrawModellListener_Impl( pMap->GetShell()->getIDocumentDrawModelAccess().GetOrCreateDrawModel() ); maInfo.SetModelBroadcaster( xModelBroadcaster ); |