fix memory leak with orphaned controls created on the fly
This commit is contained in:
@@ -149,7 +149,8 @@ void OInterfaceContainer::impl_addVbEvents_nolck_nothrow( const sal_Int32 i_nIn
|
|||||||
xProps->getPropertyValue( OUString("DefaultControl") ) >>= sServiceName;
|
xProps->getPropertyValue( OUString("DefaultControl") ) >>= sServiceName;
|
||||||
|
|
||||||
Reference< ooo::vba::XVBAToOOEventDescGen > xDescSupplier( m_xServiceFactory->createInstance( OUString("ooo.vba.VBAToOOEventDesc") ), UNO_QUERY_THROW );
|
Reference< ooo::vba::XVBAToOOEventDescGen > xDescSupplier( m_xServiceFactory->createInstance( OUString("ooo.vba.VBAToOOEventDesc") ), UNO_QUERY_THROW );
|
||||||
Sequence< ScriptEventDescriptor > vbaEvents = xDescSupplier->getEventDescriptions( m_xServiceFactory->createInstance( sServiceName ), sCodeName );
|
Sequence< ScriptEventDescriptor > vbaEvents = xDescSupplier->getEventDescriptions( sServiceName , sCodeName );
|
||||||
|
|
||||||
// register the vba script events
|
// register the vba script events
|
||||||
m_xEventAttacher->registerScriptEvents( i_nIndex, vbaEvents );
|
m_xEventAttacher->registerScriptEvents( i_nIndex, vbaEvents );
|
||||||
}
|
}
|
||||||
|
@@ -24,7 +24,7 @@
|
|||||||
module ooo { module vba {
|
module ooo { module vba {
|
||||||
interface XVBAToOOEventDescGen : com::sun::star::uno::XInterface
|
interface XVBAToOOEventDescGen : com::sun::star::uno::XInterface
|
||||||
{
|
{
|
||||||
sequence< com::sun::star::script::ScriptEventDescriptor > getEventDescriptions( [in] com::sun::star::uno::XInterface xControl, [in] string sCodeName );
|
sequence< com::sun::star::script::ScriptEventDescriptor > getEventDescriptions( [in] string controlServiceName, [in] string sCodeName );
|
||||||
com::sun::star::script::XScriptEventsSupplier getEventSupplier( [in] com::sun::star::uno::XInterface xControl, [in] string sCodeName );
|
com::sun::star::script::XScriptEventsSupplier getEventSupplier( [in] com::sun::star::uno::XInterface xControl, [in] string sCodeName );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -314,11 +314,14 @@ class ScriptEventHelper
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ScriptEventHelper( const Reference< XInterface >& xControl );
|
ScriptEventHelper( const Reference< XInterface >& xControl );
|
||||||
|
ScriptEventHelper( const OUString& sCntrlServiceName );
|
||||||
|
~ScriptEventHelper();
|
||||||
Sequence< ScriptEventDescriptor > createEvents( const OUString& sCodeName );
|
Sequence< ScriptEventDescriptor > createEvents( const OUString& sCodeName );
|
||||||
Sequence< OUString > getEventListeners();
|
Sequence< OUString > getEventListeners();
|
||||||
private:
|
private:
|
||||||
Reference< XComponentContext > m_xCtx;
|
Reference< XComponentContext > m_xCtx;
|
||||||
Reference< XInterface > m_xControl;
|
Reference< XInterface > m_xControl;
|
||||||
|
bool m_bDispose;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@@ -363,11 +366,36 @@ eventMethodToDescriptor( const OUString& rEventMethod, ScriptEventDescriptor& ev
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptEventHelper::ScriptEventHelper( const Reference< XInterface >& xControl ):
|
ScriptEventHelper::ScriptEventHelper( const Reference< XInterface >& xControl ) :
|
||||||
m_xCtx( comphelper::getProcessComponentContext() ),
|
m_xCtx( comphelper::getProcessComponentContext() ),
|
||||||
m_xControl( xControl )
|
m_xControl( xControl ),
|
||||||
|
m_bDispose( false )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
ScriptEventHelper::ScriptEventHelper( const OUString& sCntrlServiceName ) :
|
||||||
|
m_xCtx( comphelper::getProcessComponentContext() ),
|
||||||
|
m_bDispose( true )
|
||||||
|
{
|
||||||
|
m_xControl.set( m_xCtx->getServiceManager()->createInstanceWithContext( sCntrlServiceName, m_xCtx ), uno::UNO_QUERY );
|
||||||
|
}
|
||||||
|
|
||||||
|
ScriptEventHelper::~ScriptEventHelper()
|
||||||
|
{
|
||||||
|
// dispose control ( and remove any associated event registrations )
|
||||||
|
if ( m_bDispose )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
uno::Reference< lang::XComponent > xComp( m_xControl, uno::UNO_QUERY_THROW );
|
||||||
|
xComp->dispose();
|
||||||
|
}
|
||||||
|
// destructor can't throw
|
||||||
|
catch( uno::Exception& )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Sequence< OUString >
|
Sequence< OUString >
|
||||||
ScriptEventHelper::getEventListeners()
|
ScriptEventHelper::getEventListeners()
|
||||||
{
|
{
|
||||||
@@ -1002,7 +1030,7 @@ public:
|
|||||||
VBAToOOEventDescGen( const Reference< XComponentContext >& rxContext );
|
VBAToOOEventDescGen( const Reference< XComponentContext >& rxContext );
|
||||||
|
|
||||||
// XVBAToOOEventDescGen
|
// XVBAToOOEventDescGen
|
||||||
virtual Sequence< ScriptEventDescriptor > SAL_CALL getEventDescriptions( const Reference< XInterface >& control, const OUString& sCodeName ) throw (RuntimeException);
|
virtual Sequence< ScriptEventDescriptor > SAL_CALL getEventDescriptions( const OUString& sCtrlServiceName, const OUString& sCodeName ) throw (RuntimeException);
|
||||||
virtual Reference< XScriptEventsSupplier > SAL_CALL getEventSupplier( const Reference< XInterface >& xControl, const OUString& sCodeName ) throw (::com::sun::star::uno::RuntimeException);
|
virtual Reference< XScriptEventsSupplier > SAL_CALL getEventSupplier( const Reference< XInterface >& xControl, const OUString& sCodeName ) throw (::com::sun::star::uno::RuntimeException);
|
||||||
private:
|
private:
|
||||||
Reference< XComponentContext > m_xContext;
|
Reference< XComponentContext > m_xContext;
|
||||||
@@ -1012,9 +1040,9 @@ private:
|
|||||||
VBAToOOEventDescGen::VBAToOOEventDescGen( const Reference< XComponentContext >& rxContext ):m_xContext( rxContext ) {}
|
VBAToOOEventDescGen::VBAToOOEventDescGen( const Reference< XComponentContext >& rxContext ):m_xContext( rxContext ) {}
|
||||||
|
|
||||||
Sequence< ScriptEventDescriptor > SAL_CALL
|
Sequence< ScriptEventDescriptor > SAL_CALL
|
||||||
VBAToOOEventDescGen::getEventDescriptions( const Reference< XInterface >& xControl, const OUString& sCodeName ) throw (RuntimeException)
|
VBAToOOEventDescGen::getEventDescriptions( const OUString& sCntrlServiceName, const OUString& sCodeName ) throw (RuntimeException)
|
||||||
{
|
{
|
||||||
ScriptEventHelper evntHelper( xControl );
|
ScriptEventHelper evntHelper( sCntrlServiceName );
|
||||||
return evntHelper.createEvents( sCodeName );
|
return evntHelper.createEvents( sCodeName );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user