Kaydet (Commit) 00ef2d50 authored tarafından Andreas Bregas's avatar Andreas Bregas

#i102261# OLE control event handler support

üst 4dc94a51
...@@ -41,8 +41,8 @@ ...@@ -41,8 +41,8 @@
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 sLibModName, [in] sequence< string > handlerExts ); sequence< com::sun::star::script::ScriptEventDescriptor > getEventDescriptions( [in] com::sun::star::uno::XInterface xControl, [in] string sCodeName );
com::sun::star::script::XScriptEventsSupplier getEventSupplier( [in] com::sun::star::uno::XInterface xControl ); com::sun::star::script::XScriptEventsSupplier getEventSupplier( [in] com::sun::star::uno::XInterface xControl, [in] string sCodeName );
}; };
}; }; }; };
......
tc scripting : bridges rdbmaker vcl xmlscript basic sfx2 rhino BSH:beanshell javaunohelper NULL tc scripting : oovbaapi bridges rdbmaker vcl xmlscript basic sfx2 rhino BSH:beanshell javaunohelper NULL
tc scripting usr1 - all tc1_mkout NULL tc scripting usr1 - all tc1_mkout NULL
tc scripting\inc nmake - all tc1_inc NULL tc scripting\inc nmake - all tc1_inc NULL
tc scripting\source\provider nmake - all tc1_scriptingprovider tc1_inc NULL tc scripting\source\provider nmake - all tc1_scriptingprovider tc1_inc NULL
tc scripting\source\basprov nmake - all tc1_scriptingbasprov tc1_inc NULL tc scripting\source\basprov nmake - all tc1_scriptingbasprov tc1_inc NULL
tc scripting\source\vbaevents nmake - all tc1_scriptingvbaevents tc1_inc NULL
tc scripting\source\dlgprov nmake - all tc1_scriptingdlgprov tc1_inc NULL tc scripting\source\dlgprov nmake - all tc1_scriptingdlgprov tc1_inc NULL
tc scripting\source\stringresource nmake - all tc1_scriptingstringresource tc1_inc NULL tc scripting\source\stringresource nmake - all tc1_scriptingstringresource tc1_inc NULL
tc scripting\source\pyprov nmake - all tc1_scriptingpyprov tc1_inc NULL tc scripting\source\pyprov nmake - all tc1_scriptingpyprov tc1_inc NULL
...@@ -10,4 +11,4 @@ tc scripting\source\protocolhandler nmake - all tc1_scriptingprotocolhandler t ...@@ -10,4 +11,4 @@ tc scripting\source\protocolhandler nmake - all tc1_scriptingprotocolhandler t
tc scripting\java nmake - all tc1_scriptingjava tc1_scriptingprovider tc1_scriptingprotocolhandler NULL tc scripting\java nmake - all tc1_scriptingjava tc1_scriptingprovider tc1_scriptingprotocolhandler NULL
tc scripting\examples\java nmake - all tc1_scriptingexamplesjava tc1_scriptingjava NULL tc scripting\examples\java nmake - all tc1_scriptingexamplesjava tc1_scriptingjava NULL
tc scripting\examples nmake - all tc1_scriptingexamples tc1_scriptingexamplesjava tc1_inc NULL tc scripting\examples nmake - all tc1_scriptingexamples tc1_scriptingexamplesjava tc1_inc NULL
tc scripting\util nmake - all tc1_scriptingutil tc1_scriptingprovider tc1_scriptingprotocolhandler tc1_scriptingbasprov tc1_scriptingstringresource tc1_scriptingpyprov tc1_scriptingjava tc1_scriptingexamplesjava tc1_scriptingexamples NULL tc scripting\util nmake - all tc1_scriptingutil tc1_scriptingprovider tc1_scriptingprotocolhandler tc1_scriptingbasprov tc1_scriptingstringresource tc1_scriptingvbaevents tc1_scriptingpyprov tc1_scriptingjava tc1_scriptingexamplesjava tc1_scriptingexamples NULL
...@@ -121,18 +121,20 @@ namespace dlgprov ...@@ -121,18 +121,20 @@ namespace dlgprov
DialogVBAScriptListenerImpl::DialogVBAScriptListenerImpl( const Reference< XComponentContext >& rxContext, const Reference< awt::XControl >& rxControl, const Reference< frame::XModel >& xModel ) : DialogScriptListenerImpl( rxContext ) DialogVBAScriptListenerImpl::DialogVBAScriptListenerImpl( const Reference< XComponentContext >& rxContext, const Reference< awt::XControl >& rxControl, const Reference< frame::XModel >& xModel ) : DialogScriptListenerImpl( rxContext )
{ {
Reference< XMultiComponentFactory > xSMgr( m_xContext->getServiceManager() ); Reference< XMultiComponentFactory > xSMgr( m_xContext->getServiceManager() );
Sequence< Any > args(1);
if ( xSMgr.is() ) if ( xSMgr.is() )
{ {
Sequence< Any > args(1);
args[0] <<= xModel; args[0] <<= xModel;
mxListener = Reference< XScriptListener >( xSMgr->createInstanceWithArgumentsAndContext( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.EventListener" ) ), args, m_xContext ), UNO_QUERY ); mxListener = Reference< XScriptListener >( xSMgr->createInstanceWithArgumentsAndContext( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.EventListener" ) ), args, m_xContext ), UNO_QUERY );
} }
if ( rxControl.is() ) if ( rxControl.is() )
{ {
Reference< XPropertySet > xProps( rxControl->getModel(), UNO_QUERY );
try try
{ {
Reference< XPropertySet > xProps( rxControl->getModel(), UNO_QUERY_THROW );
xProps->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name") ) ) >>= msDialogCodeName; xProps->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name") ) ) >>= msDialogCodeName;
xProps.set( mxListener, UNO_QUERY_THROW );
xProps->setPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Model") ), args[ 0 ] );
} }
catch ( Exception& ) {} catch ( Exception& ) {}
} }
...@@ -193,7 +195,7 @@ namespace dlgprov ...@@ -193,7 +195,7 @@ namespace dlgprov
return it->second; return it->second;
} }
#ifdef FAKE_VBA_EVENT_SUPPORT #ifdef FAKE_VBA_EVENT_SUPPORT
Reference< XScriptEventsSupplier > DialogEventsAttacherImpl::getFakeVbaEventsSupplier( const Reference< XControl >& xControl ) Reference< XScriptEventsSupplier > DialogEventsAttacherImpl::getFakeVbaEventsSupplier( const Reference< XControl >& xControl, rtl::OUString& sControlName )
{ {
Reference< XScriptEventsSupplier > xEventsSupplier; Reference< XScriptEventsSupplier > xEventsSupplier;
Reference< XMultiComponentFactory > xSMgr( m_xContext->getServiceManager() ); Reference< XMultiComponentFactory > xSMgr( m_xContext->getServiceManager() );
...@@ -201,7 +203,7 @@ namespace dlgprov ...@@ -201,7 +203,7 @@ namespace dlgprov
{ {
Reference< ooo::vba::XVBAToOOEventDescGen > xVBAToOOEvtDesc( xSMgr->createInstanceWithContext( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAToOOEventDesc" ) ), m_xContext ), UNO_QUERY ); Reference< ooo::vba::XVBAToOOEventDescGen > xVBAToOOEvtDesc( xSMgr->createInstanceWithContext( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAToOOEventDesc" ) ), m_xContext ), UNO_QUERY );
if ( xVBAToOOEvtDesc.is() ) if ( xVBAToOOEvtDesc.is() )
xEventsSupplier.set( xVBAToOOEvtDesc->getEventSupplier( xControl ), UNO_QUERY ); xEventsSupplier.set( xVBAToOOEvtDesc->getEventSupplier( xControl, sControlName ), UNO_QUERY );
} }
return xEventsSupplier; return xEventsSupplier;
...@@ -324,6 +326,20 @@ namespace dlgprov ...@@ -324,6 +326,20 @@ namespace dlgprov
// go over all objects // go over all objects
const Reference< XInterface >* pObjects = Objects.getConstArray(); const Reference< XInterface >* pObjects = Objects.getConstArray();
sal_Int32 nObjCount = Objects.getLength(); sal_Int32 nObjCount = Objects.getLength();
#ifdef FAKE_VBA_EVENT_SUPPORT
Reference< awt::XControl > xDlgControl( Objects[ nObjCount - 1 ], uno::UNO_QUERY ); // last object is the dialog
rtl::OUString sDialogCodeName;
if ( xDlgControl.is() )
{
Reference< XPropertySet > xProps( xDlgControl->getModel(), UNO_QUERY );
try
{
xProps->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name") ) ) >>= sDialogCodeName;
}
catch( Exception& ){}
}
#endif
for ( sal_Int32 i = 0; i < nObjCount; ++i ) for ( sal_Int32 i = 0; i < nObjCount; ++i )
{ {
// We know that we have to do with instances of XControl. // We know that we have to do with instances of XControl.
...@@ -338,7 +354,7 @@ namespace dlgprov ...@@ -338,7 +354,7 @@ namespace dlgprov
Reference< XScriptEventsSupplier > xEventsSupplier( xControlModel, UNO_QUERY ); Reference< XScriptEventsSupplier > xEventsSupplier( xControlModel, UNO_QUERY );
attachEventsToControl( xControl, xEventsSupplier, Helper ); attachEventsToControl( xControl, xEventsSupplier, Helper );
#ifdef FAKE_VBA_EVENT_SUPPORT #ifdef FAKE_VBA_EVENT_SUPPORT
xEventsSupplier.set( getFakeVbaEventsSupplier( xControl ) ); xEventsSupplier.set( getFakeVbaEventsSupplier( xControl, sDialogCodeName ) );
attachEventsToControl( xControl, xEventsSupplier, Helper ); attachEventsToControl( xControl, xEventsSupplier, Helper );
#endif #endif
} }
......
...@@ -46,6 +46,9 @@ ...@@ -46,6 +46,9 @@
#include <com/sun/star/script/XScriptEventsSupplier.hpp> #include <com/sun/star/script/XScriptEventsSupplier.hpp>
#include <hash_map> #include <hash_map>
#define FAKE_VBA_EVENT_SUPPORT 1
//......................................................................... //.........................................................................
namespace dlgprov namespace dlgprov
{ {
...@@ -71,7 +74,7 @@ namespace dlgprov ...@@ -71,7 +74,7 @@ namespace dlgprov
::com::sun::star::uno::Reference< ::com::sun::star::script::XEventAttacher > m_xEventAttacher; ::com::sun::star::uno::Reference< ::com::sun::star::script::XEventAttacher > m_xEventAttacher;
::com::sun::star::uno::Reference< ::com::sun::star::script::XScriptListener > getScriptListenerForKey( const rtl::OUString& sScriptName ) throw ( ::com::sun::star::uno::RuntimeException ); ::com::sun::star::uno::Reference< ::com::sun::star::script::XScriptListener > getScriptListenerForKey( const rtl::OUString& sScriptName ) throw ( ::com::sun::star::uno::RuntimeException );
#ifdef FAKE_VBA_EVENT_SUPPORT #ifdef FAKE_VBA_EVENT_SUPPORT
::com::sun::star::uno::Reference< ::com::sun::star::script::XScriptEventsSupplier > getFakeVbaEventsSupplier( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl>& xControl ); ::com::sun::star::uno::Reference< ::com::sun::star::script::XScriptEventsSupplier > getFakeVbaEventsSupplier( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl>& xControl, rtl::OUString& sCodeName );
#endif #endif
void SAL_CALL attachEventsToControl( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl>& xControl, const ::com::sun::star::uno::Reference< ::com::sun::star::script::XScriptEventsSupplier >& events, const ::com::sun::star::uno::Any& Helper ); void SAL_CALL attachEventsToControl( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl>& xControl, const ::com::sun::star::uno::Reference< ::com::sun::star::script::XScriptEventsSupplier >& events, const ::com::sun::star::uno::Any& Helper );
public: public:
......
This diff is collapsed.
PRJ=..$/..
PRJNAME=scripting
TARGET=vbaevents
.IF "$(ENABLE_VBA)"!="YES"
dummy:
@echo "not building vbaevents..."
.ENDIF
VISIBILITY_HIDDEN=TRUE
NO_BSYMBOLIC= TRUE
ENABLE_EXCEPTIONS=TRUE
COMP1TYPELIST=$(TARGET)
COMPRDB=$(SOLARBINDIR)$/types.rdb
# --- Settings -----------------------------------------------------
.INCLUDE : settings.mk
DLLPRE =
# ------------------------------------------------------------------
#.INCLUDE : ..$/cppumaker.mk
SLOFILES= \
$(SLO)$/service.obj \
$(SLO)$/eventhelper.obj
SHL1TARGET= $(TARGET)$(DLLPOSTFIX).uno
SHL1IMPLIB= i$(TARGET)
SHL1VERSIONMAP=$(TARGET).map
SHL1DEF=$(MISC)$/$(SHL1TARGET).def
DEF1NAME=$(SHL1TARGET)
SHL1STDLIBS= \
$(CPPUHELPERLIB) \
$(BASICLIB) \
$(COMPHELPERLIB) \
$(SFXLIB) \
$(CPPULIB) \
$(TOOLSLIB) \
$(SALLIB)
SHL1DEPN=
SHL1LIBS=$(SLB)$/$(TARGET).lib
# --- Targets ------------------------------------------------------
.INCLUDE : target.mk
# ------------------------------------------------------------------
ALLTAR : \
$(MISC)$/$(TARGET).don \
$(SLOTARGET)
$(MISC)$/$(TARGET).don : $(SOLARBINDIR)$/oovbaapi.rdb
+$(CPPUMAKER) -O$(OUT)$/inc -BUCR $(SOLARBINDIR)$/oovbaapi.rdb -X$(SOLARBINDIR)$/types.rdb && echo > $@
echo $@
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_scripting.hxx"
#include "cppuhelper/implementationentry.hxx"
#include "com/sun/star/lang/XMultiServiceFactory.hpp"
#include "com/sun/star/registry/XRegistryKey.hpp"
// =============================================================================
// component exports
// =============================================================================
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
namespace evtlstner
{
// =============================================================================
// component operations
// =============================================================================
uno::Reference< XInterface > SAL_CALL create(
Reference< XComponentContext > const & xContext )
SAL_THROW( () );
// -----------------------------------------------------------------------------
::rtl::OUString SAL_CALL getImplementationName();
Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames();
Reference<XInterface> SAL_CALL create(
Sequence<Any> const &, Reference<XComponentContext> const & );
} // end evtlstner
namespace ooevtdescgen
{
// =============================================================================
// component operations
// =============================================================================
uno::Reference< XInterface > SAL_CALL create(
Reference< XComponentContext > const & xContext )
SAL_THROW( () );
// -----------------------------------------------------------------------------
::rtl::OUString SAL_CALL getImplementationName();
Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames();
Reference<XInterface> SAL_CALL create(
Sequence<Any> const &, Reference<XComponentContext> const & );
} // end ooevtdescgen
// =============================================================================
const ::cppu::ImplementationEntry s_component_entries [] =
{
{
::evtlstner::create, ::evtlstner::getImplementationName,
::evtlstner::getSupportedServiceNames,
::cppu::createSingleComponentFactory,
0, 0
},
{
::ooevtdescgen::create, ::ooevtdescgen::getImplementationName,
::ooevtdescgen::getSupportedServiceNames,
::cppu::createSingleComponentFactory,
0, 0
},
{ 0, 0, 0, 0, 0, 0 }
};
extern "C"
{
void SAL_CALL component_getImplementationEnvironment(
const sal_Char ** ppEnvTypeName, uno_Environment ** )
{
OSL_TRACE("In component_getImplementationEnv");
*ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
}
sal_Bool SAL_CALL component_writeInfo(
lang::XMultiServiceFactory * pServiceManager, registry::XRegistryKey * pRegistryKey )
{
OSL_TRACE("In component_writeInfo");
if ( ::cppu::component_writeInfoHelper(
pServiceManager, pRegistryKey, s_component_entries ) )
return sal_True;
return sal_False;
}
void * SAL_CALL component_getFactory(
const sal_Char * pImplName, lang::XMultiServiceFactory * pServiceManager,
registry::XRegistryKey * pRegistryKey )
{
OSL_TRACE("In component_getFactory");
return ::cppu::component_getFactoryHelper(
pImplName, pServiceManager, pRegistryKey, s_component_entries );
}
}
OOO_1.1 {
global:
component_getImplementationEnvironment;
component_getFactory;
component_writeInfo;
local:
*;
};
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module-description PUBLIC "-//StarOffice//DTD ComponentDescription 1.0//EN" "module-description.dtd">
<module-description xmlns:xlink="http://www.w3.org/1999/xlink">
<module-name>vbaevents</module-name>
<component-description>
<author>Noel Power </author>
<name>ooo.vba.EventListener</name>
<description>Event listener to handle ooo events and to translate them to calls to basic macros ala Button_Click etc.</description>
<loader-name>com.sun.star.loader.SharedLibrary</loader-name>
<language>c++</language>
<status value="drafts"/>
<supported-service>ooo.vba.EventListener</supported-service>
<type>com.sun.star.uno.XComponentContext</type>
</component-description>
<project-build-dependency>cppuhelper</project-build-dependency>
<project-build-dependency>cppu</project-build-dependency>
<project-build-dependency>sal</project-build-dependency>
<runtime-module-dependency>cppuhelper3$(COM)</runtime-module-dependency>
<runtime-module-dependency>cppu3</runtime-module-dependency>
<runtime-module-dependency>sal3</runtime-module-dependency>
</module-description>
...@@ -236,6 +236,11 @@ namespace svxform ...@@ -236,6 +236,11 @@ namespace svxform
void SAL_CALL FormScriptListener::firing( const ScriptEvent& _rEvent ) throw (RuntimeException) void SAL_CALL FormScriptListener::firing( const ScriptEvent& _rEvent ) throw (RuntimeException)
{ {
::osl::ClearableMutexGuard aGuard( m_aMutex ); ::osl::ClearableMutexGuard aGuard( m_aMutex );
static const ::rtl::OUString vbaInterOp =
::rtl::OUString::createFromAscii("VBAInterop");
if ( _rEvent.ScriptType.equals(vbaInterOp) )
return; // not handled here
if ( impl_isDisposed_nothrow() ) if ( impl_isDisposed_nothrow() )
return; return;
......
...@@ -105,6 +105,7 @@ ...@@ -105,6 +105,7 @@
#include <comphelper/uno3.hxx> #include <comphelper/uno3.hxx>
#include <connectivity/dbexception.hxx> #include <connectivity/dbexception.hxx>
#include <comphelper/extract.hxx> #include <comphelper/extract.hxx>
#include <comphelper/evtmethodhelper.hxx>
#include <cppuhelper/typeprovider.hxx> #include <cppuhelper/typeprovider.hxx>
#include <algorithm> #include <algorithm>
...@@ -718,36 +719,6 @@ sal_Int16 getControlTypeByObject(const Reference< ::com::sun::star::lang::XServi ...@@ -718,36 +719,6 @@ sal_Int16 getControlTypeByObject(const Reference< ::com::sun::star::lang::XServi
} }
return ::rtl::OUString(); return ::rtl::OUString();
} }
//------------------------------------------------------------------------------
Sequence< ::rtl::OUString> getEventMethods(const Type& type)
{
typelib_InterfaceTypeDescription *pType=0;
type.getDescription( (typelib_TypeDescription**)&pType);
if(!pType)
return Sequence< ::rtl::OUString>();
Sequence< ::rtl::OUString> aNames(pType->nMembers);
::rtl::OUString* pNames = aNames.getArray();
for(sal_Int32 i=0;i<pType->nMembers;i++,++pNames)
{
// the decription reference
typelib_TypeDescriptionReference* pMemberDescriptionReference = pType->ppMembers[i];
// the description for the reference
typelib_TypeDescription* pMemberDescription = NULL;
typelib_typedescriptionreference_getDescription(&pMemberDescription, pMemberDescriptionReference);
if (pMemberDescription)
{
typelib_InterfaceMemberTypeDescription* pRealMemberDescription =
reinterpret_cast<typelib_InterfaceMemberTypeDescription*>(pMemberDescription);
*pNames = pRealMemberDescription->pMemberName;
}
}
typelib_typedescription_release( (typelib_TypeDescription *)pType );
return aNames;
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void TransferEventScripts(const Reference< ::com::sun::star::awt::XControlModel>& xModel, const Reference< ::com::sun::star::awt::XControl>& xControl, void TransferEventScripts(const Reference< ::com::sun::star::awt::XControlModel>& xModel, const Reference< ::com::sun::star::awt::XControl>& xControl,
const Sequence< ::com::sun::star::script::ScriptEventDescriptor>& rTransferIfAvailable) const Sequence< ::com::sun::star::script::ScriptEventDescriptor>& rTransferIfAvailable)
...@@ -821,7 +792,8 @@ void TransferEventScripts(const Reference< ::com::sun::star::awt::XControlModel> ...@@ -821,7 +792,8 @@ void TransferEventScripts(const Reference< ::com::sun::star::awt::XControlModel>
continue; continue;
// now check the methods // now check the methods
Sequence< ::rtl::OUString> aMethodsNames = getEventMethods(*pCurrentListeners); Sequence< ::rtl::OUString> aMethodsNames = ::comphelper::getEventMethodsForType(*pCurrentListeners);
const ::rtl::OUString* pMethodsNames = aMethodsNames.getConstArray(); const ::rtl::OUString* pMethodsNames = aMethodsNames.getConstArray();
for (k=0; k<aMethodsNames.getLength(); ++k, ++pMethodsNames) for (k=0; k<aMethodsNames.getLength(); ++k, ++pMethodsNames)
{ {
......
...@@ -86,6 +86,90 @@ using namespace ::com::sun::star::reflection; ...@@ -86,6 +86,90 @@ using namespace ::com::sun::star::reflection;
using namespace ::com::sun::star::form::binding; using namespace ::com::sun::star::form::binding;
using namespace ::svxform; using namespace ::svxform;
#include <com/sun/star/script/XScriptListener.hdl>
#include <comphelper/processfactory.hxx>
#include <cppuhelper/implbase1.hxx>
typedef cppu::WeakImplHelper1< XScriptListener > ScriptEventListener_BASE;
class ScriptEventListenerWrapper : public ScriptEventListener_BASE
{
public:
ScriptEventListenerWrapper( FmFormModel& _rModel) throw ( RuntimeException ) : pModel(&_rModel)
{
Reference < XPropertySet > xProps(
::comphelper::getProcessServiceFactory(), UNO_QUERY );
if ( xProps.is() )
{
Reference< XComponentContext > xCtx( xProps->getPropertyValue(
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), UNO_QUERY );
if ( xCtx.is() )
{
Reference< XMultiComponentFactory > xMFac(
xCtx->getServiceManager(), UNO_QUERY );
if ( xMFac.is() )
{
m_vbaListener.set( xMFac->createInstanceWithContext(
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
"ooo.vba.EventListener" ) ), xCtx ),
UNO_QUERY_THROW );
}
}
}
}
// XEventListener
virtual void SAL_CALL disposing(const EventObject& ) throw( RuntimeException ){}
// XScriptListener
virtual void SAL_CALL firing(const ScriptEvent& evt) throw(RuntimeException)
{
setModel();
if ( m_vbaListener.is() )
{
m_vbaListener->firing( evt );
}
}
virtual Any SAL_CALL approveFiring(const ScriptEvent& evt) throw( com::sun::star::reflection::InvocationTargetException, RuntimeException)
{
setModel();
if ( m_vbaListener.is() )
{
return m_vbaListener->approveFiring( evt );
}
return Any();
}
private:
void setModel()
{
Reference< XPropertySet > xProps( m_vbaListener, UNO_QUERY );
if ( xProps.is() )
{
try
{
SfxObjectShellRef xObjSh = pModel->GetObjectShell();
if ( xObjSh.Is() && m_vbaListener.is() )
{
Any aVal;
aVal <<= xObjSh->GetModel();
xProps->setPropertyValue(
::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Model" ) ),
aVal );
}
}
catch( Exception& )
{
//swallow any errors
}
}
}
FmFormModel* pModel;
Reference< XScriptListener > m_vbaListener;
};
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// some helper structs for caching property infos // some helper structs for caching property infos
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -128,6 +212,13 @@ FmXUndoEnvironment::FmXUndoEnvironment(FmFormModel& _rModel) ...@@ -128,6 +212,13 @@ FmXUndoEnvironment::FmXUndoEnvironment(FmFormModel& _rModel)
,m_bDisposed( false ) ,m_bDisposed( false )
{ {
DBG_CTOR(FmXUndoEnvironment,NULL); DBG_CTOR(FmXUndoEnvironment,NULL);
try
{
m_vbaListener = new ScriptEventListenerWrapper( _rModel );
}
catch( Exception& )
{
}
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -752,9 +843,17 @@ void FmXUndoEnvironment::switchListening( const Reference< XIndexContainer >& _r ...@@ -752,9 +843,17 @@ void FmXUndoEnvironment::switchListening( const Reference< XIndexContainer >& _r
if ( xManager.is() ) if ( xManager.is() )
{ {
if ( _bStartListening ) if ( _bStartListening )
{
m_pScriptingEnv->registerEventAttacherManager( xManager ); m_pScriptingEnv->registerEventAttacherManager( xManager );
if ( m_vbaListener.is() )
xManager->addScriptListener( m_vbaListener );
}
else else
{
m_pScriptingEnv->revokeEventAttacherManager( xManager ); m_pScriptingEnv->revokeEventAttacherManager( xManager );
if ( m_vbaListener.is() )
xManager->removeScriptListener( m_vbaListener );
}
} }
// also handle all children of this element // also handle all children of this element
......
...@@ -43,6 +43,10 @@ ENABLE_EXCEPTIONS=TRUE ...@@ -43,6 +43,10 @@ ENABLE_EXCEPTIONS=TRUE
# --- Files -------------------------------------------------------- # --- Files --------------------------------------------------------
.IF "$(ENABLE_VBA)"=="YES"
CDEFS+=-DENABLE_VBA
.ENDIF
SRS1NAME=form SRS1NAME=form
SRC1FILES= \ SRC1FILES= \
fmexpl.src \ fmexpl.src \
......
...@@ -213,7 +213,7 @@ private: ...@@ -213,7 +213,7 @@ private:
void switchListening( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer >& _rxContainer, bool _bStartListening ) SAL_THROW(()); void switchListening( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer >& _rxContainer, bool _bStartListening ) SAL_THROW(());
void switchListening( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxObject, bool _bStartListening ) SAL_THROW(()); void switchListening( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxObject, bool _bStartListening ) SAL_THROW(());
::com::sun::star::uno::Reference< com::sun::star::script::XScriptListener > m_vbaListener;
public: public:
// Methoden zur Zuordnung von Controls zu Forms, // Methoden zur Zuordnung von Controls zu Forms,
// werden von der Seite und der UndoUmgebung genutzt // werden von der Seite und der UndoUmgebung genutzt
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment