summaryrefslogtreecommitdiff
path: root/forms
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2019-02-18 13:39:17 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2019-02-18 14:52:28 +0100
commitdbc7fc7587008b376f28605264f45f967680e4ff (patch)
treed47c5946ed4c66a3b5f96cfe1e59f7050d1ac9f9 /forms
parentc70f5f32e2537639c7ad7e6e63fb760fd7a4ed90 (diff)
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 <noel.grandin@collabora.co.uk>
Diffstat (limited to 'forms')
-rw-r--r--forms/source/component/DatabaseForm.cxx15
-rw-r--r--forms/source/component/EventThread.cxx12
-rw-r--r--forms/source/component/EventThread.hxx9
-rw-r--r--forms/source/component/ImageButton.cxx2
-rw-r--r--forms/source/component/clickableimage.cxx7
-rw-r--r--forms/source/component/clickableimage.hxx5
6 files changed, 12 insertions, 38 deletions
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<const css::awt::MouseEvent *>(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<EventObject>());
}
else
{
@@ -2078,7 +2067,7 @@ void SAL_CALL ODatabaseForm::submit( const Reference<XControl>& Control,
m_pThread = new OFormSubmitResetThread(this);
m_pThread->create();
}
- m_pThread->addEvent(&MouseEvt, Control, true);
+ m_pThread->addEvent(std::make_unique<css::awt::MouseEvent>(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<EventObject> _pEvt )
{
Reference<XControl> xTmp;
- addEvent( _pEvt, xTmp );
+ addEvent( std::move(_pEvt), xTmp );
}
-void OComponentEventThread::addEvent( const EventObject* _pEvt,
+void OComponentEventThread::addEvent( std::unique_ptr<EventObject> _pEvt,
const Reference<XControl>& 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<XWeak> xWeakControl(rControl, UNO_QUERY);
Reference<XAdapter> xControlAdapter = xWeakControl.is() ? xWeakControl->queryAdapter() : Reference<XAdapter>();
@@ -152,7 +150,7 @@ void OComponentEventThread::run()
rtl::Reference<::cppu::OComponentHelper> xComp = m_xComp;
ThreadEvents::iterator firstEvent( m_aEvents.begin() );
- std::unique_ptr<EventObject> pEvt(*firstEvent);
+ std::unique_ptr<EventObject> 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<css::lang::EventObject*> ThreadEvents;
+ typedef std::vector<std::unique_ptr<css::lang::EventObject>> 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<css::lang::EventObject> _pEvt );
+ void addEvent( std::unique_ptr<css::lang::EventObject> _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<awt::MouseEvent>(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<XControl>&,
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<css::lang::EventObject>() ); }
protected:
using OComponentEventThread::addEvent;