From dbc7fc7587008b376f28605264f45f967680e4ff Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Mon, 18 Feb 2019 13:39:17 +0200 Subject: use unique_ptr in OComponentEventThread and simplify - by passing in a std::unique_ptr to addEvent we avoid the need to have a virtual clone method Change-Id: Ie425476a3158c7a66e399c2a9f33d2612dab5cbb Reviewed-on: https://gerrit.libreoffice.org/67962 Tested-by: Jenkins Reviewed-by: Noel Grandin --- forms/source/component/DatabaseForm.cxx | 15 ++------------- forms/source/component/EventThread.cxx | 12 +++++------- forms/source/component/EventThread.hxx | 9 +++------ forms/source/component/ImageButton.cxx | 2 +- forms/source/component/clickableimage.cxx | 7 ------- forms/source/component/clickableimage.hxx | 5 +---- 6 files changed, 12 insertions(+), 38 deletions(-) (limited to 'forms/source') diff --git a/forms/source/component/DatabaseForm.cxx b/forms/source/component/DatabaseForm.cxx index ab58fae4ddf6..18d96af1364a 100644 --- a/forms/source/component/DatabaseForm.cxx +++ b/forms/source/component/DatabaseForm.cxx @@ -134,9 +134,6 @@ class OFormSubmitResetThread: public OComponentEventThread { protected: - // duplicate an event with respect to its type - virtual EventObject *cloneEvent( const EventObject *pEvt ) const override; - // process an event. while processing the mutex isn't locked, and pCompImpl // is made sure to remain valid virtual void processEvent( ::cppu::OComponentHelper* _pCompImpl, @@ -150,13 +147,6 @@ public: }; -EventObject* OFormSubmitResetThread::cloneEvent( - const EventObject *pEvt ) const -{ - return new css::awt::MouseEvent( *static_cast(pEvt) ); -} - - void OFormSubmitResetThread::processEvent( ::cppu::OComponentHelper* pCompImpl, const EventObject *_pEvt, @@ -1908,8 +1898,7 @@ void SAL_CALL ODatabaseForm::reset() m_pThread = new OFormSubmitResetThread(this); m_pThread->create(); } - EventObject aEvt; - m_pThread->addEvent(&aEvt); + m_pThread->addEvent(std::make_unique()); } else { @@ -2078,7 +2067,7 @@ void SAL_CALL ODatabaseForm::submit( const Reference& Control, m_pThread = new OFormSubmitResetThread(this); m_pThread->create(); } - m_pThread->addEvent(&MouseEvt, Control, true); + m_pThread->addEvent(std::make_unique(MouseEvt), Control, true); } else { diff --git a/forms/source/component/EventThread.cxx b/forms/source/component/EventThread.cxx index e252fcc1d03f..84b9b4798b83 100644 --- a/forms/source/component/EventThread.cxx +++ b/forms/source/component/EventThread.cxx @@ -71,8 +71,6 @@ Any SAL_CALL OComponentEventThread::queryInterface(const Type& _rType) void OComponentEventThread::impl_clearEventQueue() { - for ( auto& rEvent : m_aEvents ) - delete rEvent; m_aEvents.clear(); m_aControls.clear(); m_aFlags.clear(); @@ -101,20 +99,20 @@ void OComponentEventThread::disposing( const EventObject& evt ) } } -void OComponentEventThread::addEvent( const EventObject* _pEvt ) +void OComponentEventThread::addEvent( std::unique_ptr _pEvt ) { Reference xTmp; - addEvent( _pEvt, xTmp ); + addEvent( std::move(_pEvt), xTmp ); } -void OComponentEventThread::addEvent( const EventObject* _pEvt, +void OComponentEventThread::addEvent( std::unique_ptr _pEvt, const Reference& rControl, bool bFlag ) { ::osl::MutexGuard aGuard( m_aMutex ); // Put data into the queue - m_aEvents.push_back( cloneEvent( _pEvt ) ); + m_aEvents.push_back( std::move( _pEvt ) ); Reference xWeakControl(rControl, UNO_QUERY); Reference xControlAdapter = xWeakControl.is() ? xWeakControl->queryAdapter() : Reference(); @@ -152,7 +150,7 @@ void OComponentEventThread::run() rtl::Reference<::cppu::OComponentHelper> xComp = m_xComp; ThreadEvents::iterator firstEvent( m_aEvents.begin() ); - std::unique_ptr pEvt(*firstEvent); + std::unique_ptr pEvt = std::move(*firstEvent); m_aEvents.erase( firstEvent ); ThreadObjects::iterator firstControl( m_aControls.begin() ); diff --git a/forms/source/component/EventThread.hxx b/forms/source/component/EventThread.hxx index efb9e20fc4dc..363bf94acc6e 100644 --- a/forms/source/component/EventThread.hxx +++ b/forms/source/component/EventThread.hxx @@ -48,7 +48,7 @@ class OComponentEventThread ,public css::lang::XEventListener ,public ::cppu::OWeakObject { - typedef std::vector ThreadEvents; + typedef std::vector> ThreadEvents; typedef std::vector< css::uno::Reference< css::uno::XAdapter> > ThreadObjects; ::osl::Mutex m_aMutex; @@ -66,9 +66,6 @@ protected: virtual void SAL_CALL onTerminated() override; - // The following method is called to duplicate the Event while respecting its type. - virtual css::lang::EventObject* cloneEvent(const css::lang::EventObject* _pEvt) const = 0; - // Edit an Event: // The mutex is not locked, but pCompImpl stays valid in any case. // pEvt can be a derrived type, namely the one that cloneEvent returns. @@ -88,8 +85,8 @@ public: explicit OComponentEventThread(::cppu::OComponentHelper* pCompImpl); virtual ~OComponentEventThread() override; - void addEvent( const css::lang::EventObject* _pEvt ); - void addEvent( const css::lang::EventObject* _pEvt, const css::uno::Reference< css::awt::XControl>& rControl, + void addEvent( std::unique_ptr _pEvt ); + void addEvent( std::unique_ptr _pEvt, const css::uno::Reference< css::awt::XControl>& rControl, bool bFlag = false ); // css::lang::XEventListener diff --git a/forms/source/component/ImageButton.cxx b/forms/source/component/ImageButton.cxx index 74092fba5e1c..d0b62fb4017f 100644 --- a/forms/source/component/ImageButton.cxx +++ b/forms/source/component/ImageButton.cxx @@ -195,7 +195,7 @@ void OImageButtonControl::mousePressed(const awt::MouseEvent& e) { // if there are listeners, start the action in an own thread, to not allow // them to block us here (we're in the application's main thread) - getImageProducerThread()->OComponentEventThread::addEvent( &e ); + getImageProducerThread()->OComponentEventThread::addEvent( std::make_unique(e) ); } else { diff --git a/forms/source/component/clickableimage.cxx b/forms/source/component/clickableimage.cxx index 36637975e9ba..d5cae9c185e1 100644 --- a/forms/source/component/clickableimage.cxx +++ b/forms/source/component/clickableimage.cxx @@ -842,13 +842,6 @@ namespace frm // OImageProducerThread_Impl - - EventObject* OImageProducerThread_Impl::cloneEvent( const EventObject* _pEvt ) const - { - return new EventObject( *_pEvt ); - } - - void OImageProducerThread_Impl::processEvent( ::cppu::OComponentHelper *pCompImpl, const EventObject* pEvt, const Reference&, diff --git a/forms/source/component/clickableimage.hxx b/forms/source/component/clickableimage.hxx index 346ae094212b..01ec960600c4 100644 --- a/forms/source/component/clickableimage.hxx +++ b/forms/source/component/clickableimage.hxx @@ -255,9 +255,6 @@ namespace frm { protected: - // This method was called to duplicate the Event by taking its type into account - virtual css::lang::EventObject* cloneEvent( const css::lang::EventObject* _pEvt ) const override; - // Process an Event. // The mutex is not locked, pCompImpl stays valid in any case virtual void processEvent( ::cppu::OComponentHelper *pCompImpl, @@ -270,7 +267,7 @@ namespace frm OComponentEventThread( pControl ) {} - void addEvent() { css::lang::EventObject aEvt; OComponentEventThread::addEvent( &aEvt ); } + void addEvent() { OComponentEventThread::addEvent( std::make_unique() ); } protected: using OComponentEventThread::addEvent; -- cgit