tdf#117280: derive SfxEvents_Impl from css::document::XDocumentEventListener
It abused XEventListener, and created a DocumentEvent object from
the incomplete data passed to notifyEvent in EventObject. That way,
the data initially created for the document event (in Supplement)
was lost on the way.
Change-Id: I409611482ce2323a3192c68f3525f450a9395815
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126090
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
(cherry picked from commit 28eef82cb16faef0b8ddc9912560efb779baa9f9)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126093
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
diff --git a/sfx2/source/inc/eventsupplier.hxx b/sfx2/source/inc/eventsupplier.hxx
index af3d5bf..0bbd11e 100644
--- a/sfx2/source/inc/eventsupplier.hxx
+++ b/sfx2/source/inc/eventsupplier.hxx
@@ -24,8 +24,8 @@
#include <com/sun/star/document/DocumentEvent.hpp>
#include <com/sun/star/container/XNameReplace.hpp>
#include <com/sun/star/document/XEventListener.hpp>
#include <com/sun/star/document/XEventBroadcaster.hpp>
#include <com/sun/star/document/XDocumentEventListener.hpp>
#include <com/sun/star/document/XDocumentEventBroadcaster.hpp>
#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/uno/Type.hxx>
#include <cppuhelper/implbase.hxx>
@@ -40,17 +40,17 @@ class SfxObjectShell;
class SvxMacro;
class SfxEvents_Impl final : public ::cppu::WeakImplHelper< css::container::XNameReplace, css::document::XEventListener >
class SfxEvents_Impl final : public ::cppu::WeakImplHelper< css::container::XNameReplace, css::document::XDocumentEventListener >
{
css::uno::Sequence< OUString > maEventNames;
std::vector< css::uno::Any > maEventData;
css::uno::Reference< css::document::XEventBroadcaster > mxBroadcaster;
css::uno::Reference< css::document::XDocumentEventBroadcaster > mxBroadcaster;
::osl::Mutex maMutex;
SfxObjectShell *mpObjShell;
public:
SfxEvents_Impl( SfxObjectShell* pShell,
css::uno::Reference< css::document::XEventBroadcaster > const & xBroadcaster );
css::uno::Reference< css::document::XDocumentEventBroadcaster > const & xBroadcaster );
virtual ~SfxEvents_Impl() override;
// --- XNameReplace ---
@@ -65,8 +65,8 @@ public:
virtual css::uno::Type SAL_CALL getElementType() override;
virtual sal_Bool SAL_CALL hasElements() override;
// --- ::document::XEventListener ---
virtual void SAL_CALL notifyEvent( const css::document::EventObject& aEvent ) override;
// --- ::document::XDocumentEventListener ---
virtual void SAL_CALL documentEventOccured(const css::document::DocumentEvent& aEvent) override;
// --- ::lang::XEventListener ---
virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
diff --git a/sfx2/source/notify/eventsupplier.cxx b/sfx2/source/notify/eventsupplier.cxx
index 00135b2..08699ca 100644
--- a/sfx2/source/notify/eventsupplier.cxx
+++ b/sfx2/source/notify/eventsupplier.cxx
@@ -280,7 +280,7 @@ void SfxEvents_Impl::Execute( uno::Any const & aEventData, const document::Docum
// --- ::document::XEventListener ---
void SAL_CALL SfxEvents_Impl::notifyEvent( const document::EventObject& aEvent )
void SAL_CALL SfxEvents_Impl::documentEventOccured( const document::DocumentEvent& aEvent )
{
::osl::ClearableMutexGuard aGuard( maMutex );
@@ -292,7 +292,7 @@ void SAL_CALL SfxEvents_Impl::notifyEvent( const document::EventObject& aEvent )
uno::Any aEventData = maEventData[ nIndex ];
aGuard.clear();
Execute( aEventData, document::DocumentEvent(aEvent.Source, aEvent.EventName, nullptr, uno::Any()), mpObjShell );
Execute( aEventData, aEvent, mpObjShell );
}
@@ -304,14 +304,14 @@ void SAL_CALL SfxEvents_Impl::disposing( const lang::EventObject& /*Source*/ )
if ( mxBroadcaster.is() )
{
mxBroadcaster->removeEventListener( this );
mxBroadcaster->removeDocumentEventListener( this );
mxBroadcaster = nullptr;
}
}
SfxEvents_Impl::SfxEvents_Impl( SfxObjectShell* pShell,
uno::Reference< document::XEventBroadcaster > const & xBroadcaster )
uno::Reference< document::XDocumentEventBroadcaster > const & xBroadcaster )
{
// get the list of supported events and store it
if ( pShell )
@@ -325,7 +325,7 @@ SfxEvents_Impl::SfxEvents_Impl( SfxObjectShell* pShell,
mxBroadcaster = xBroadcaster;
if ( mxBroadcaster.is() )
mxBroadcaster->addEventListener( this );
mxBroadcaster->addDocumentEventListener( this );
}