summaryrefslogtreecommitdiff
path: root/scripting
diff options
context:
space:
mode:
authorNoel Power <noel.power@novell.com>2010-10-06 10:16:27 +0100
committerNoel Power <noel.power@novell.com>2010-10-06 10:16:27 +0100
commitd4fc699a7eb1fe8738c4cd49d4f2a71462f54536 (patch)
treeccc79edc7297561316b183df5e21d3af498e25fc /scripting
parent2fbd515c917918fdccd68369b29d1d237682fce3 (diff)
initial commit for vba blob ( not including container_control stuff )
Diffstat (limited to 'scripting')
-rw-r--r--scripting/source/basprov/basprov.cxx37
-rw-r--r--scripting/source/basprov/basscript.cxx72
-rw-r--r--scripting/source/basprov/basscript.hxx29
-rw-r--r--scripting/source/dlgprov/dlgevtatt.cxx22
-rw-r--r--scripting/source/dlgprov/dlgevtatt.hxx2
-rw-r--r--scripting/source/dlgprov/dlgprov.cxx22
-rw-r--r--scripting/source/dlgprov/dlgprov.hxx6
-rw-r--r--scripting/source/vbaevents/eventhelper.cxx287
-rw-r--r--scripting/source/vbaevents/makefile.mk1
9 files changed, 397 insertions, 81 deletions
diff --git a/scripting/source/basprov/basprov.cxx b/scripting/source/basprov/basprov.cxx
index f02394e11d..4bad69f0f8 100644
--- a/scripting/source/basprov/basprov.cxx
+++ b/scripting/source/basprov/basprov.cxx
@@ -371,7 +371,33 @@ namespace basprov
::rtl::OUString::createFromAscii( "location" ) );
sal_Int32 nIndex = 0;
- ::rtl::OUString aLibrary = aDescription.getToken( 0, (sal_Unicode)'.', nIndex );
+ // In some strange circumstances the Library name can have an
+ // apparantly illegal '.' in it ( in imported VBA )
+
+ BasicManager* pBasicMgr = NULL;
+ if ( aLocation.equals( ::rtl::OUString::createFromAscii("document") ) )
+ {
+ pBasicMgr = m_pDocBasicManager;
+ }
+ else if ( aLocation.equals( ::rtl::OUString::createFromAscii("application") ) )
+ {
+ pBasicMgr = m_pAppBasicManager;
+ }
+ rtl::OUString sProjectName;
+ if ( pBasicMgr )
+ sProjectName = pBasicMgr->GetName();
+
+ ::rtl::OUString aLibrary;
+ if ( sProjectName.getLength() && aDescription.match( sProjectName ) )
+ {
+ OSL_TRACE("LibraryName %s is part of the url %s",
+ rtl::OUStringToOString( sProjectName, RTL_TEXTENCODING_UTF8 ).getStr(),
+ rtl::OUStringToOString( aDescription, RTL_TEXTENCODING_UTF8 ).getStr() );
+ aLibrary = sProjectName;
+ nIndex = sProjectName.getLength() + 1;
+ }
+ else
+ aLibrary = aDescription.getToken( 0, (sal_Unicode)'.', nIndex );
::rtl::OUString aModule;
if ( nIndex != -1 )
aModule = aDescription.getToken( 0, (sal_Unicode)'.', nIndex );
@@ -381,15 +407,6 @@ namespace basprov
if ( aLibrary.getLength() != 0 && aModule.getLength() != 0 && aMethod.getLength() != 0 && aLocation.getLength() != 0 )
{
- BasicManager* pBasicMgr = NULL;
- if ( aLocation.equals( ::rtl::OUString::createFromAscii("document") ) )
- {
- pBasicMgr = m_pDocBasicManager;
- }
- else if ( aLocation.equals( ::rtl::OUString::createFromAscii("application") ) )
- {
- pBasicMgr = m_pAppBasicManager;
- }
if ( pBasicMgr )
{
diff --git a/scripting/source/basprov/basscript.cxx b/scripting/source/basprov/basscript.cxx
index 620e249362..e99a346500 100644
--- a/scripting/source/basprov/basscript.cxx
+++ b/scripting/source/basprov/basscript.cxx
@@ -36,7 +36,10 @@
#include <basic/sbmeth.hxx>
#include <basic/basmgr.hxx>
#include <com/sun/star/script/provider/ScriptFrameworkErrorType.hpp>
-
+#include "bcholder.hxx"
+#include <comphelper/proparrhlp.hxx>
+#include <comphelper/propertycontainer.hxx>
+#include <com/sun/star/beans/PropertyAttribute.hpp>
#include <map>
@@ -45,6 +48,7 @@ using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::script;
using namespace ::com::sun::star::document;
+using namespace ::com::sun::star::beans;
extern ::com::sun::star::uno::Any sbxToUnoValue( SbxVariable* pVar );
extern void unoToSbxValue( SbxVariable* pVar, const ::com::sun::star::uno::Any& aValue );
@@ -54,6 +58,10 @@ extern void unoToSbxValue( SbxVariable* pVar, const ::com::sun::star::uno::Any&
namespace basprov
{
//.........................................................................
+#define BASSCRIPT_PROPERTY_ID_CALLER 1
+#define BASSCRIPT_PROPERTY_CALLER ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Caller" ) )
+
+#define BASSCRIPT_DEFAULT_ATTRIBS() PropertyAttribute::BOUND | PropertyAttribute::TRANSIENT
typedef ::std::map< sal_Int16, Any, ::std::less< sal_Int16 > > OutParamMap;
@@ -64,22 +72,28 @@ namespace basprov
// -----------------------------------------------------------------------------
BasicScriptImpl::BasicScriptImpl( const ::rtl::OUString& funcName, SbMethodRef xMethod )
- :m_xMethod( xMethod )
+ : ::scripting_helper::OBroadcastHelperHolder( m_aMutex )
+ ,OPropertyContainer( GetBroadcastHelper() )
+ ,m_xMethod( xMethod )
,m_funcName( funcName )
,m_documentBasicManager( NULL )
,m_xDocumentScriptContext()
{
+ registerProperty( BASSCRIPT_PROPERTY_CALLER, BASSCRIPT_PROPERTY_ID_CALLER, BASSCRIPT_DEFAULT_ATTRIBS(), &m_caller, ::getCppuType( &m_caller ) );
}
// -----------------------------------------------------------------------------
BasicScriptImpl::BasicScriptImpl( const ::rtl::OUString& funcName, SbMethodRef xMethod,
- BasicManager& documentBasicManager, const Reference< XScriptInvocationContext >& documentScriptContext )
- :m_xMethod( xMethod )
+ BasicManager& documentBasicManager, const Reference< XScriptInvocationContext >& documentScriptContext ) : ::scripting_helper::OBroadcastHelperHolder( m_aMutex )
+ ,OPropertyContainer( GetBroadcastHelper() )
+ ,m_xMethod( xMethod )
,m_funcName( funcName )
,m_documentBasicManager( &documentBasicManager )
,m_xDocumentScriptContext( documentScriptContext )
{
+ //
+ registerProperty( BASSCRIPT_PROPERTY_CALLER, BASSCRIPT_PROPERTY_ID_CALLER, BASSCRIPT_DEFAULT_ATTRIBS(), &m_caller, ::getCppuType( &m_caller ) );
}
// -----------------------------------------------------------------------------
@@ -88,6 +102,48 @@ namespace basprov
}
// -----------------------------------------------------------------------------
+ // XInterface
+ // -----------------------------------------------------------------------------
+
+ IMPLEMENT_FORWARD_XINTERFACE2( BasicScriptImpl, BasicScriptImpl_BASE, OPropertyContainer )
+
+ // -----------------------------------------------------------------------------
+ // XTypeProvider
+ // -----------------------------------------------------------------------------
+
+ IMPLEMENT_FORWARD_XTYPEPROVIDER2( BasicScriptImpl, BasicScriptImpl_BASE, OPropertyContainer )
+
+ // -----------------------------------------------------------------------------
+ // OPropertySetHelper
+ // -----------------------------------------------------------------------------
+
+ ::cppu::IPropertyArrayHelper& BasicScriptImpl::getInfoHelper( )
+ {
+ return *getArrayHelper();
+ }
+
+ // -----------------------------------------------------------------------------
+ // OPropertyArrayUsageHelper
+ // -----------------------------------------------------------------------------
+
+ ::cppu::IPropertyArrayHelper* BasicScriptImpl::createArrayHelper( ) const
+ {
+ Sequence< Property > aProps;
+ describeProperties( aProps );
+ return new ::cppu::OPropertyArrayHelper( aProps );
+ }
+
+ // -----------------------------------------------------------------------------
+ // XPropertySet
+ // -----------------------------------------------------------------------------
+
+ Reference< XPropertySetInfo > BasicScriptImpl::getPropertySetInfo( ) throw (RuntimeException)
+ {
+ Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
+ return xInfo;
+ }
+
+ // -----------------------------------------------------------------------------
// XScript
// -----------------------------------------------------------------------------
@@ -166,8 +222,14 @@ namespace basprov
if ( m_documentBasicManager && m_xDocumentScriptContext.is() )
aOldThisComponent = m_documentBasicManager->SetGlobalUNOConstant( "ThisComponent", makeAny( m_xDocumentScriptContext ) );
+ if ( m_caller.getLength() && m_caller[ 0 ].hasValue() )
+ {
+ SbxVariableRef xCallerVar = new SbxVariable( SbxVARIANT );
+ unoToSbxValue( static_cast< SbxVariable* >( xCallerVar ), m_caller[ 0 ] );
+ nErr = m_xMethod->Call( xReturn, xCallerVar );
+ }
+ else
nErr = m_xMethod->Call( xReturn );
-
if ( m_documentBasicManager && m_xDocumentScriptContext.is() )
m_documentBasicManager->SetGlobalUNOConstant( "ThisComponent", aOldThisComponent );
}
diff --git a/scripting/source/basprov/basscript.hxx b/scripting/source/basprov/basscript.hxx
index a524c186b2..12ac0a08eb 100644
--- a/scripting/source/basprov/basscript.hxx
+++ b/scripting/source/basprov/basscript.hxx
@@ -28,12 +28,14 @@
#ifndef SCRIPTING_BASSCRIPT_HXX
#define SCRIPTING_BASSCRIPT_HXX
+#include "bcholder.hxx"
#include <com/sun/star/script/provider/XScript.hpp>
#include <com/sun/star/document/XScriptInvocationContext.hpp>
#include <cppuhelper/implbase1.hxx>
+#include <comphelper/proparrhlp.hxx>
+#include <comphelper/propertycontainer.hxx>
#include <basic/sbmeth.hxx>
-
class BasicManager;
//.........................................................................
@@ -49,7 +51,11 @@ namespace basprov
::com::sun::star::script::provider::XScript > BasicScriptImpl_BASE;
- class BasicScriptImpl : public BasicScriptImpl_BASE
+ class BasicScriptImpl : public BasicScriptImpl_BASE,
+ public ::scripting_helper::OMutexHolder,
+ public ::scripting_helper::OBroadcastHelperHolder,
+ public ::comphelper::OPropertyContainer,
+ public ::comphelper::OPropertyArrayUsageHelper< BasicScriptImpl >
{
private:
SbMethodRef m_xMethod;
@@ -57,6 +63,16 @@ namespace basprov
BasicManager* m_documentBasicManager;
::com::sun::star::uno::Reference< ::com::sun::star::document::XScriptInvocationContext >
m_xDocumentScriptContext;
+ // hack, OPropertyContainer doesn't allow you to define a property of unknown
+ // type ( I guess because an Any can't contain an Any... I've always wondered why?
+ // as its not unusual to do that in corba )
+ ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > m_caller;
+ protected:
+ // OPropertySetHelper
+ virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper( );
+
+ // OPropertyArrayUsageHelper
+ virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
public:
BasicScriptImpl(
@@ -71,6 +87,12 @@ namespace basprov
);
virtual ~BasicScriptImpl();
+ // XInterface
+ DECLARE_XINTERFACE()
+
+ // XTypeProvider
+ DECLARE_XTYPEPROVIDER()
+
// XScript
virtual ::com::sun::star::uno::Any SAL_CALL invoke(
const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aParams,
@@ -80,6 +102,9 @@ namespace basprov
::com::sun::star::script::provider::ScriptFrameworkErrorException,
::com::sun::star::reflection::InvocationTargetException,
::com::sun::star::uno::RuntimeException );
+ // XPropertySet
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( )
+ throw (::com::sun::star::uno::RuntimeException);
};
//.........................................................................
diff --git a/scripting/source/dlgprov/dlgevtatt.cxx b/scripting/source/dlgprov/dlgevtatt.cxx
index 11a101454e..2d8c853e91 100644
--- a/scripting/source/dlgprov/dlgevtatt.cxx
+++ b/scripting/source/dlgprov/dlgevtatt.cxx
@@ -108,13 +108,14 @@ namespace dlgprov
{
protected:
rtl::OUString msDialogCodeName;
+ rtl::OUString msDialogLibName;
Reference< script::XScriptListener > mxListener;
virtual void firing_impl( const script::ScriptEvent& aScriptEvent, uno::Any* pRet );
public:
- DialogVBAScriptListenerImpl( const Reference< XComponentContext >& rxContext, const Reference< awt::XControl >& rxControl, const Reference< frame::XModel >& xModel );
+ DialogVBAScriptListenerImpl( const Reference< XComponentContext >& rxContext, const Reference< awt::XControl >& rxControl, const Reference< frame::XModel >& xModel, const rtl::OUString& sDialogLibName );
};
- 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, const rtl::OUString& sDialogLibName ) : DialogScriptListenerImpl( rxContext ), msDialogLibName( sDialogLibName )
{
Reference< XMultiComponentFactory > xSMgr( m_xContext->getServiceManager() );
Sequence< Any > args(1);
@@ -145,7 +146,7 @@ namespace dlgprov
if ( aScriptEvent.ScriptType.equals( rtl::OUString::createFromAscii("VBAInterop") ) && mxListener.is() )
{
ScriptEvent aScriptEventCopy( aScriptEvent );
- aScriptEventCopy.ScriptCode = msDialogCodeName;
+ aScriptEventCopy.ScriptCode = msDialogLibName.concat( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "." ) ) ).concat( msDialogCodeName );
try
{
mxListener->firing( aScriptEventCopy );
@@ -163,7 +164,7 @@ namespace dlgprov
// DialogEventsAttacherImpl
// =============================================================================
- DialogEventsAttacherImpl::DialogEventsAttacherImpl( const Reference< XComponentContext >& rxContext, const Reference< frame::XModel >& rxModel, const Reference< awt::XControl >& rxControl, const Reference< XInterface >& rxHandler, const Reference< beans::XIntrospectionAccess >& rxIntrospect, bool bProviderMode, const Reference< script::XScriptListener >& rxRTLListener )
+ DialogEventsAttacherImpl::DialogEventsAttacherImpl( const Reference< XComponentContext >& rxContext, const Reference< frame::XModel >& rxModel, const Reference< awt::XControl >& rxControl, const Reference< XInterface >& rxHandler, const Reference< beans::XIntrospectionAccess >& rxIntrospect, bool bProviderMode, const Reference< script::XScriptListener >& rxRTLListener, const rtl::OUString& sDialogLibName )
:mbUseFakeVBAEvents( false ), m_xContext( rxContext )
{
// key listeners by protocol when ScriptType = 'Script'
@@ -186,11 +187,11 @@ namespace dlgprov
{
pFoundShell = reinterpret_cast<SfxObjectShell*>( xObjShellTunnel->getSomething(SfxObjectShell::getUnoTunnelId()));
if ( pFoundShell )
- mbUseFakeVBAEvents = ooo::vba::isAlienExcelDoc( *pFoundShell );
+ mbUseFakeVBAEvents = ooo::vba::isAlienExcelDoc( *pFoundShell ) || ooo::vba::isAlienWordDoc( *pFoundShell ) ;
}
}
if ( mbUseFakeVBAEvents )
- listernersForTypes[ rtl::OUString::createFromAscii("VBAInterop") ] = new DialogVBAScriptListenerImpl( rxContext, rxControl, rxModel );
+ listernersForTypes[ rtl::OUString::createFromAscii("VBAInterop") ] = new DialogVBAScriptListenerImpl( rxContext, rxControl, rxModel, sDialogLibName );
}
// -----------------------------------------------------------------------------
@@ -217,6 +218,7 @@ namespace dlgprov
Reference< ooo::vba::XVBAToOOEventDescGen > xVBAToOOEvtDesc( xSMgr->createInstanceWithContext( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAToOOEventDesc" ) ), m_xContext ), UNO_QUERY );
if ( xVBAToOOEvtDesc.is() )
xEventsSupplier.set( xVBAToOOEvtDesc->getEventSupplier( xControl, sControlName ), UNO_QUERY );
+
}
return xEventsSupplier;
}
@@ -409,7 +411,7 @@ namespace dlgprov
void DialogAllListenerImpl::firing( const AllEventObject& Event ) throw ( RuntimeException )
{
- ::osl::MutexGuard aGuard( getMutex() );
+ //::osl::MutexGuard aGuard( getMutex() );
firing_impl( Event, NULL );
}
@@ -419,7 +421,7 @@ namespace dlgprov
Any DialogAllListenerImpl::approveFiring( const AllEventObject& Event )
throw ( reflection::InvocationTargetException, RuntimeException )
{
- ::osl::MutexGuard aGuard( getMutex() );
+ //::osl::MutexGuard aGuard( getMutex() );
Any aReturn;
firing_impl( Event, &aReturn );
@@ -655,7 +657,7 @@ namespace dlgprov
void DialogScriptListenerImpl::firing( const ScriptEvent& aScriptEvent ) throw ( RuntimeException )
{
- ::osl::MutexGuard aGuard( getMutex() );
+ //::osl::MutexGuard aGuard( getMutex() );
firing_impl( aScriptEvent, NULL );
}
@@ -665,7 +667,7 @@ namespace dlgprov
Any DialogScriptListenerImpl::approveFiring( const ScriptEvent& aScriptEvent )
throw ( reflection::InvocationTargetException, RuntimeException )
{
- ::osl::MutexGuard aGuard( getMutex() );
+ //::osl::MutexGuard aGuard( getMutex() );
Any aReturn;
firing_impl( aScriptEvent, &aReturn );
diff --git a/scripting/source/dlgprov/dlgevtatt.hxx b/scripting/source/dlgprov/dlgevtatt.hxx
index c76ee093da..0df79b2db5 100644
--- a/scripting/source/dlgprov/dlgevtatt.hxx
+++ b/scripting/source/dlgprov/dlgevtatt.hxx
@@ -78,7 +78,7 @@ namespace dlgprov
const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xHandler,
const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XIntrospectionAccess >& xIntrospect,
bool bProviderMode,
- const ::com::sun::star::uno::Reference< ::com::sun::star::script::XScriptListener >& xRTLListener );
+ const ::com::sun::star::uno::Reference< ::com::sun::star::script::XScriptListener >& xRTLListener ,const rtl::OUString& sDialogLibName );
virtual ~DialogEventsAttacherImpl();
// XScriptEventsAttacher
diff --git a/scripting/source/dlgprov/dlgprov.cxx b/scripting/source/dlgprov/dlgprov.cxx
index e9e12993c4..49b0b5f182 100644
--- a/scripting/source/dlgprov/dlgprov.cxx
+++ b/scripting/source/dlgprov/dlgprov.cxx
@@ -189,7 +189,15 @@ static ::rtl::OUString aResourceResolverPropName = ::rtl::OUString::createFromAs
Reference< beans::XPropertySet > xDlgPropSet( xDialogModel, UNO_QUERY );
xDlgPropSet->setPropertyValue( aDlgSrcUrlPropName, aDialogSourceURL );
- ::xmlscript::importDialogModel( xInput, xDialogModel, m_xContext );
+ // #TODO we really need to detect the source of the Dialog, is it
+ // located in the document or not. m_xModel need not be the location of
+ // the dialog. E.g. if the dialog was created from basic ( then we just
+ // can't tell where its from )
+ // If we are happy to always substitute the form model for the awt
+ // one then maybe the presence of a document model is enough to trigger
+ // swapping out the models ( or perhaps we only want to do this
+ // for vba mode ) there are a number of feasible and valid possibilities
+ ::xmlscript::importDialogModel( xInput, xDialogModel, m_xContext, m_xModel );
// Set resource property
if( xStringResourceManager.is() )
{
@@ -403,6 +411,7 @@ static ::rtl::OUString aResourceResolverPropName = ::rtl::OUString::createFromAs
if ( xISP.is() )
xInput = xISP->createInputStream();
+ msDialogLibName = sLibName;
}
// import dialog model
@@ -520,7 +529,7 @@ static ::rtl::OUString aResourceResolverPropName = ::rtl::OUString::createFromAs
const Reference< XControl >& rxControl,
const Reference< XInterface >& rxHandler,
const Reference< XIntrospectionAccess >& rxIntrospectionAccess,
- bool bDialogProviderMode )
+ bool bDialogProviderMode, const rtl::OUString& sDialogLibName )
{
if ( rxControl.is() )
{
@@ -544,7 +553,7 @@ static ::rtl::OUString aResourceResolverPropName = ::rtl::OUString::createFromAs
Reference< XScriptEventsAttacher > xScriptEventsAttacher = new DialogEventsAttacherImpl
( m_xContext, m_xModel, rxControl, rxHandler, rxIntrospectionAccess,
- bDialogProviderMode, ( m_BasicInfo.get() ? m_BasicInfo->mxBasicRTLListener : NULL ) );
+ bDialogProviderMode, ( m_BasicInfo.get() ? m_BasicInfo->mxBasicRTLListener : NULL ), msDialogLibName );
Any aHelper;
xScriptEventsAttacher->attachEvents( aObjects, Reference< XScriptListener >(), aHelper );
@@ -649,7 +658,10 @@ static ::rtl::OUString aResourceResolverPropName = ::rtl::OUString::createFromAs
aArguments[0] >>= m_xModel;
m_BasicInfo.reset( new BasicRTLParams() );
m_BasicInfo->mxInput.set( aArguments[ 1 ], UNO_QUERY_THROW );
- m_BasicInfo->mxDlgLib.set( aArguments[ 2 ], UNO_QUERY_THROW );
+ // allow null mxDlgLib, a document dialog instantiated from
+ // from application basic is unable to provide ( or find ) it's
+ // Library
+ aArguments[ 2 ] >>= m_BasicInfo->mxDlgLib;
// leave the possibility to optionally allow the old dialog creation
// to use the new XScriptListener ( which converts the old style macro
// to a SF url )
@@ -733,7 +745,7 @@ static ::rtl::OUString aResourceResolverPropName = ::rtl::OUString::createFromAs
{
//xDialog = Reference< XDialog >( xCtrl, UNO_QUERY );
Reference< XIntrospectionAccess > xIntrospectionAccess = inspectHandler( xHandler );
- attachControlEvents( xCtrl, xHandler, xIntrospectionAccess, bDialogProviderMode );
+ attachControlEvents( xCtrl, xHandler, xIntrospectionAccess, bDialogProviderMode, msDialogLibName );
}
}
diff --git a/scripting/source/dlgprov/dlgprov.hxx b/scripting/source/dlgprov/dlgprov.hxx
index 82faef2f86..e2aba36b32 100644
--- a/scripting/source/dlgprov/dlgprov.hxx
+++ b/scripting/source/dlgprov/dlgprov.hxx
@@ -81,9 +81,9 @@ namespace dlgprov
::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext;
::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > m_xModel;
-
+ rtl::OUString msDialogLibName;
::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > createDialogModel( const ::rtl::OUString& sURL );
-
+
::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl > createDialogControl(
const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >& rxDialogModel,
const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >& xParent );
@@ -91,7 +91,7 @@ namespace dlgprov
void attachControlEvents( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& rxControlContainer,
const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rxHandler,
const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XIntrospectionAccess >& rxIntrospectionAccess,
- bool bDialogProviderMode );
+ bool bDialogProviderMode, const rtl::OUString& );
::com::sun::star::uno::Reference< ::com::sun::star::beans::XIntrospectionAccess > inspectHandler(
const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rxHandler );
// helper methods
diff --git a/scripting/source/vbaevents/eventhelper.cxx b/scripting/source/vbaevents/eventhelper.cxx
index 6975fba08e..703357dd47 100644
--- a/scripting/source/vbaevents/eventhelper.cxx
+++ b/scripting/source/vbaevents/eventhelper.cxx
@@ -46,12 +46,17 @@
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XInitialization.hpp>
+#include <com/sun/star/util/XCloseListener.hpp>
+#include <com/sun/star/util/XCloseBroadcaster.hpp>
+
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/script/XLibraryContainer.hpp>
#include <com/sun/star/script/ScriptEventDescriptor.hpp>
#include <com/sun/star/script/provider/XScriptProviderSupplier.hpp>
+#include <com/sun/star/container/XNamed.hpp>
+
#include <com/sun/star/drawing/XControlShape.hpp>
#include <com/sun/star/awt/XControl.hpp>
@@ -62,8 +67,9 @@
#include <com/sun/star/awt/XTextComponent.hpp> //liuchen 2009-6-5
#include <com/sun/star/awt/XComboBox.hpp> //liuchen 2009-6-18
#include <com/sun/star/awt/XRadioButton.hpp> //liuchen 2009-7-30
+#include <com/sun/star/awt/XListBox.hpp>
-#include <msforms/ReturnInteger.hpp>
+#include "vbamsformreturntypes.hxx"
#include <sfx2/objsh.hxx>
#include <basic/sbstar.hxx>
@@ -71,6 +77,7 @@
#include <basic/sbmeth.hxx>
#include <basic/sbmod.hxx>
#include <basic/sbx.hxx>
+#include <filter/msfilter/msvbahelper.hxx>
@@ -82,12 +89,21 @@
#include <com/sun/star/lang/XMultiComponentFactory.hpp>
#include <com/sun/star/script/XScriptListener.hpp>
#include <cppuhelper/implbase1.hxx>
+#include <cppuhelper/implbase3.hxx>
#include <cppuhelper/implbase2.hxx>
#include <comphelper/evtmethodhelper.hxx>
#include <set>
#include <list>
#include <hash_map>
+#define ASYNC 0
+
+// primitive support for asynchronous handling of
+// events from controls ( all event will be processed asynchronously
+// in the application thread )
+#if ASYNC
+#include <vcl/svapp.hxx>
+#endif
using namespace ::com::sun::star;
using namespace ::com::sun::star::script;
@@ -189,6 +205,14 @@ bool isMouseEventOk( awt::MouseEvent& evt, const Sequence< Any >& params )
return true;
}
+bool isFocusEventOk( awt::FocusEvent& evt, const Sequence< Any >& params )
+{
+ if ( !( params.getLength() > 0 ) ||
+ !( params[ 0 ] >>= evt ) )
+ return false;
+ return true;
+}
+
Sequence< Any > ooMouseEvtToVBADblClick( const Sequence< Any >& params )
{
Sequence< Any > translatedParams;
@@ -232,9 +256,14 @@ Sequence< Any > ooKeyPressedToVBAKeyPressed( const Sequence< Any >& params )
translatedParams.realloc(1);
- msforms::ReturnInteger keyCode;
- keyCode.Value = evt.KeyCode;
- translatedParams[0] <<= keyCode;
+ //The VBA events such as ComboBox_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) may cause an error because
+ //the original input parameter data structure -- msforms::ReturnInteger -- is a struct, it cannot support default value.
+ //So the newly defined VbaReturnIntege class is used here to support default value.
+ VbaReturnInteger* pKeyCode = new VbaReturnInteger();
+ pKeyCode->Value = evt.KeyChar;
+ ::uno::Reference< msforms::XReturnInteger > xInteger =
+ static_cast< ::uno::Reference< msforms::XReturnInteger > > (pKeyCode);
+ translatedParams[0] <<= xInteger;
return translatedParams;
}
@@ -248,16 +277,38 @@ Sequence< Any > ooKeyPressedToVBAKeyUpDown( const Sequence< Any >& params )
translatedParams.realloc(2);
- msforms::ReturnInteger keyCode;
- sal_Int8 shift = sal::static_int_cast<sal_Int8>( evt.Modifiers );
-
- // #TODO check whether values from OOO conform to values generated from vba
- keyCode.Value = evt.KeyCode;
- translatedParams[0] <<= keyCode;
+ //The VBA events such as ComboBox_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) may cause an error because
+ //the original input parameter data structure -- msforms::ReturnInteger -- is a struct, it cannot support default value.
+ //So the newly defined VbaReturnIntege class is used here to support default value.
+ VbaReturnInteger* pKeyCode = new VbaReturnInteger();
+ sal_Int8 shift = evt.Modifiers;
+
+ pKeyCode->Value = evt.KeyChar;
+ ::uno::Reference< msforms::XReturnInteger > xInteger = static_cast< ::uno::Reference< msforms::XReturnInteger > > (pKeyCode);
+ translatedParams[0] <<= xInteger;
translatedParams[1] <<= shift;
return translatedParams;
}
+Sequence< Any > ooFocusLostToVBAExit( const Sequence< Any >& params )
+{
+ Sequence< Any > translatedParams;
+ awt::FocusEvent evt;
+
+ if ( !isFocusEventOk( evt, params ) )
+ return Sequence< Any >();
+
+ translatedParams.realloc(1);
+
+ VbaReturnBoolean* pCancel = new VbaReturnBoolean();
+
+ ::uno::Reference< msforms::XReturnBoolean > xBoolean=
+ static_cast< ::uno::Reference< msforms::XReturnBoolean > > (pCancel);
+ translatedParams[0] <<= xBoolean;
+ return translatedParams;
+}
+
+
typedef Sequence< Any > (*Translator)(const Sequence< Any >&);
//liuchen 2009-6-23
@@ -287,6 +338,7 @@ bool ApproveAll(const ScriptEvent& evt, void* pPara); //allow all types of contr
bool ApproveType(const ScriptEvent& evt, void* pPara); //certain types of controls should execute the event, those types are given by pPara
bool DenyType(const ScriptEvent& evt, void* pPara); //certain types of controls should not execute the event, those types are given by pPara
bool DenyMouseDrag(const ScriptEvent& evt, void* pPara); //used for VBA MouseMove event when "Shift" key is pressed
+bool DenyKeys(const ScriptEvent& evt, void* pPara); //For some keys, press them will cause Symphony keyPressed event, but will not cause any events in Excel, so deny these key events
struct TypeList
{
@@ -294,28 +346,30 @@ struct TypeList
int nListLength;
};
-Type typeXFixedText = GET_TYPE(awt::XFixedText)
-Type typeXTextComponent = GET_TYPE(awt::XTextComponent)
-Type typeXComboBox = GET_TYPE(awt::XComboBox)
-Type typeXRadioButton = GET_TYPE(awt::XRadioButton)
+Type typeXFixedText = GET_TYPE(awt::XFixedText);
+Type typeXTextComponent = GET_TYPE(awt::XTextComponent);
+Type typeXComboBox = GET_TYPE(awt::XComboBox);
+Type typeXRadioButton = GET_TYPE(awt::XRadioButton);
+Type typeXListBox = GET_TYPE(awt::XListBox);
TypeList fixedTextList = {&typeXFixedText, 1};
TypeList textCompList = {&typeXTextComponent, 1};
TypeList radioButtonList = {&typeXRadioButton, 1};
TypeList comboBoxList = {&typeXComboBox, 1};
+TypeList listBoxList = {&typeXListBox, 1};
//this array stores the OO event to VBA event translation info
static TranslatePropMap aTranslatePropMap_Impl[] =
{
+ { MAP_CHAR_LEN("actionPerformed"), { MAP_CHAR_LEN("_Change"), NULL, DenyType, (void*)(&radioButtonList) } }, //liuchen 2009-7-30, OptionalButton_Change event is not the same as OptionalButton_Click event
// actionPerformed ooo event
{ MAP_CHAR_LEN("actionPerformed"), { MAP_CHAR_LEN("_Click"), NULL, ApproveAll, NULL } },
- { MAP_CHAR_LEN("actionPerformed"), { MAP_CHAR_LEN("_Change"), NULL, DenyType, (void*)(&radioButtonList) } }, //liuchen 2009-7-30, OptionalButton_Change event is not the same as OptionalButton_Click event
-
+ { MAP_CHAR_LEN("itemStateChanged"), { MAP_CHAR_LEN("_Change"), NULL, ApproveType, (void*)(&radioButtonList) } }, //liuchen 2009-7-30, OptionalButton_Change event should be triggered when the button state is changed
// itemStateChanged ooo event
{ MAP_CHAR_LEN("itemStateChanged"), { MAP_CHAR_LEN("_Click"), NULL, ApproveType, (void*)(&comboBoxList) } }, //liuchen, add to support VBA ComboBox_Click event
- { MAP_CHAR_LEN("itemStateChanged"), { MAP_CHAR_LEN("_Change"), NULL, ApproveType, (void*)(&radioButtonList) } }, //liuchen 2009-7-30, OptionalButton_Change event should be triggered when the button state is changed
+ { MAP_CHAR_LEN("itemStateChanged"), { MAP_CHAR_LEN("_Click"), NULL, ApproveType, (void*)(&listBoxList) } },
// changed ooo event
{ MAP_CHAR_LEN("changed"), { MAP_CHAR_LEN("_Change"), NULL, ApproveAll, NULL } },
@@ -324,7 +378,7 @@ static TranslatePropMap aTranslatePropMap_Impl[] =
// focusLost ooo event
{ MAP_CHAR_LEN("focusLost"), { MAP_CHAR_LEN("_LostFocus"), NULL, ApproveAll, NULL } },
- { MAP_CHAR_LEN("focusLost"), { MAP_CHAR_LEN("_Exit"), NULL, ApproveType, (void*)(&textCompList) } }, //liuchen, add to support VBA TextBox_Exit event
+ { MAP_CHAR_LEN("focusLost"), { MAP_CHAR_LEN("_Exit"), ooFocusLostToVBAExit, ApproveType, (void*)(&textCompList) } }, //liuchen, add to support VBA TextBox_Exit event
// adjustmentValueChanged ooo event
{ MAP_CHAR_LEN("adjustmentValueChanged"), { MAP_CHAR_LEN("_Scroll"), NULL, ApproveAll, NULL } },
@@ -349,8 +403,8 @@ static TranslatePropMap aTranslatePropMap_Impl[] =
{ MAP_CHAR_LEN("mouseDragged"), { MAP_CHAR_LEN("_MouseMove"), ooMouseEvtToVBAMouseEvt, DenyMouseDrag, NULL } }, //liuchen, add to support VBA MouseMove event when the "Shift" key is pressed
// keyPressed ooo event
- { MAP_CHAR_LEN("keyPressed"), { MAP_CHAR_LEN("_KeyDown"), ooKeyPressedToVBAKeyPressed, ApproveAll, NULL } },
- { MAP_CHAR_LEN("keyPressed"), { MAP_CHAR_LEN("_KeyPress"), ooKeyPressedToVBAKeyPressed, ApproveAll, NULL } }
+ { MAP_CHAR_LEN("keyPressed"), { MAP_CHAR_LEN("_KeyDown"), ooKeyPressedToVBAKeyUpDown, ApproveAll, NULL } },
+ { MAP_CHAR_LEN("keyPressed"), { MAP_CHAR_LEN("_KeyPress"), ooKeyPressedToVBAKeyUpDown, DenyKeys, NULL } }
};
EventInfoHash& getEventTransInfo()
@@ -632,7 +686,7 @@ private:
Reference< container::XNameContainer > m_xNameContainer;
};
-typedef ::cppu::WeakImplHelper2< XScriptListener, lang::XInitialization > EventListener_BASE;
+typedef ::cppu::WeakImplHelper3< XScriptListener, util::XCloseListener, lang::XInitialization > EventListener_BASE;
#define EVENTLSTNR_PROPERTY_ID_MODEL 1
#define EVENTLSTNR_PROPERTY_MODEL ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Model" ) )
@@ -653,6 +707,9 @@ public:
// XScriptListener
virtual void SAL_CALL firing(const ScriptEvent& evt) throw(RuntimeException);
virtual Any SAL_CALL approveFiring(const ScriptEvent& evt) throw(reflection::InvocationTargetException, RuntimeException);
+ // XCloseListener
+ virtual void SAL_CALL queryClosing( const lang::EventObject& Source, ::sal_Bool GetsOwnership ) throw (util::CloseVetoException, uno::RuntimeException);
+ virtual void SAL_CALL notifyClosing( const lang::EventObject& Source ) throw (uno::RuntimeException);
// XPropertySet
virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw (::com::sun::star::uno::RuntimeException);
// XInitialization
@@ -664,6 +721,25 @@ public:
DECLARE_XTYPEPROVIDER()
virtual void SAL_CALL setFastPropertyValue( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
{
+ if ( nHandle == EVENTLSTNR_PROPERTY_ID_MODEL )
+ {
+ uno::Reference< frame::XModel > xModel( rValue, uno::UNO_QUERY );
+ if( xModel != m_xModel)
+ {
+ // Remove the listener from the old XCloseBroadcaster.
+ uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster( m_xModel, uno::UNO_QUERY );
+ if (xCloseBroadcaster.is())
+ {
+ xCloseBroadcaster->removeCloseListener( this );
+ }
+ // Add the listener into the new XCloseBroadcaster.
+ xCloseBroadcaster = uno::Reference< util::XCloseBroadcaster >( xModel, uno::UNO_QUERY );
+ if (xCloseBroadcaster.is())
+ {
+ xCloseBroadcaster->addCloseListener( this );
+ }
+ }
+ }
OPropertyContainer::setFastPropertyValue( nHandle, rValue );
if ( nHandle == EVENTLSTNR_PROPERTY_ID_MODEL )
setShellFromModel();
@@ -677,17 +753,21 @@ protected:
virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
private:
+#if ASYNC
+ DECL_LINK( OnAsyncScriptEvent, ScriptEvent* );
+#endif
void setShellFromModel();
void firing_Impl( const ScriptEvent& evt, Any *pSyncRet=NULL ) throw( RuntimeException );
Reference< XComponentContext > m_xContext;
Reference< frame::XModel > m_xModel;
SfxObjectShell* mpShell;
+ sal_Bool m_bDocClosed;
};
EventListener::EventListener( const Reference< XComponentContext >& rxContext ) :
-OPropertyContainer(GetBroadcastHelper()), m_xContext( rxContext ), mpShell( 0 )
+OPropertyContainer(GetBroadcastHelper()), m_xContext( rxContext ), m_bDocClosed(sal_False), mpShell( 0 )
{
registerProperty( EVENTLSTNR_PROPERTY_MODEL, EVENTLSTNR_PROPERTY_ID_MODEL,
beans::PropertyAttribute::TRANSIENT, &m_xModel, ::getCppuType( &m_xModel ) );
@@ -722,9 +802,39 @@ EventListener::disposing(const lang::EventObject&) throw( RuntimeException )
void SAL_CALL
EventListener::firing(const ScriptEvent& evt) throw(RuntimeException)
{
+#if ASYNC
+ // needs some logic to check if the event handler is oneway or not
+ // if not oneway then firing_Impl otherwise... as below
+ acquire();
+ Application::PostUserEvent( LINK( this, EventListener, OnAsyncScriptEvent ), new ScriptEvent( evt ) );
+#else
firing_Impl( evt );
+#endif
}
+#if ASYNC
+IMPL_LINK( EventListener, OnAsyncScriptEvent, ScriptEvent*, _pEvent )
+{
+ if ( !_pEvent )
+ return 1L;
+
+ {
+ // #FIXME if we enable ASYNC we probably need something like
+ // below
+ //::osl::ClearableMutexGuard aGuard( m_aMutex );
+
+ //if ( !impl_isDisposed_nothrow() )
+ // impl_doFireScriptEvent_nothrow( aGuard, *_pEvent, NULL );
+ firing_Impl( *_pEvent, NULL );
+ }
+
+ delete _pEvent;
+ // we acquired ourself immediately before posting the event
+ release();
+ return 0L;
+ }
+#endif
+
Any SAL_CALL
EventListener::approveFiring(const ScriptEvent& evt) throw(reflection::InvocationTargetException, RuntimeException)
{
@@ -733,6 +843,24 @@ EventListener::approveFiring(const ScriptEvent& evt) throw(reflection::Invocatio
return ret;
}
+// XCloseListener
+void SAL_CALL
+EventListener::queryClosing( const lang::EventObject& Source, ::sal_Bool GetsOwnership ) throw (util::CloseVetoException, uno::RuntimeException)
+{
+ //Nothing to do
+}
+
+void SAL_CALL
+EventListener::notifyClosing( const lang::EventObject& Source ) throw (uno::RuntimeException)
+{
+ m_bDocClosed = sal_True;
+ uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster( m_xModel, uno::UNO_QUERY );
+ if (xCloseBroadcaster.is())
+ {
+ xCloseBroadcaster->removeCloseListener( this );
+ }
+}
+
// XInitialization
void SAL_CALL
EventListener::initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException)
@@ -835,13 +963,28 @@ bool DenyMouseDrag(const ScriptEvent& evt, void* )
}
}
+//For some keys, press them will cause Symphony keyPressed event, but will not cause any events in Excel, so deny these key events
+bool DenyKeys(const ScriptEvent& evt, void* /*pPara*/)
+{
+ awt::KeyEvent aEvent;
+ evt.Arguments[ 0 ] >>= aEvent;
+ if (aEvent.KeyChar == 0 || aEvent.KeyChar == 8)
+ {
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+}
+
//liuchen 2009-6-23
// EventListener
void
-EventListener::firing_Impl(const ScriptEvent& evt, Any* /*pRet*/ ) throw(RuntimeException)
+EventListener::firing_Impl(const ScriptEvent& evt, Any* pRet ) throw(RuntimeException)
{
OSL_TRACE("EventListener::firing_Impl( FAKE VBA_EVENTS )");
static const ::rtl::OUString vbaInterOp =
@@ -852,18 +995,46 @@ EventListener::firing_Impl(const ScriptEvent& evt, Any* /*pRet*/ ) throw(Runtime
return;
lang::EventObject aEvent;
evt.Arguments[ 0 ] >>= aEvent;
+ OSL_TRACE("evt.MethodName is %s", rtl::OUStringToOString( evt.MethodName, RTL_TEXTENCODING_UTF8 ).getStr() );
OSL_TRACE("Argument[0] is %s", rtl::OUStringToOString( comphelper::anyToString( evt.Arguments[0] ), RTL_TEXTENCODING_UTF8 ).getStr() );
OSL_TRACE("Getting Control");
- uno::Reference< awt::XControl > xControl( aEvent.Source, uno::UNO_QUERY_THROW );
- OSL_TRACE("Getting properties");
- uno::Reference< beans::XPropertySet > xProps( xControl->getModel(), uno::UNO_QUERY_THROW );
-
rtl::OUString sName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("UserForm") );
OSL_TRACE("Getting Name");
uno::Reference< awt::XDialog > xDlg( aEvent.Source, uno::UNO_QUERY );
if ( !xDlg.is() )
- xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Name") ) ) >>= sName;
+ {
+ OSL_TRACE("Getting Control");
+ // evt.Source is
+ // a) Dialog
+ // b) xShapeControl ( from api (sheet control) )
+ // c) eventmanager ( I guess )
+ // d) vba control ( from api also )
+ uno::Reference< drawing::XControlShape > xCntrlShape( evt.Source, uno::UNO_QUERY );
+ uno::Reference< awt::XControl > xControl( aEvent.Source, uno::UNO_QUERY );
+ if ( xCntrlShape.is() )
+ {
+ // for sheet controls ( that fire from the api ) we don't
+ // have the real control ( thats only available from the view )
+ // api code creates just a control instance that is transferred
+ // via aEvent.Arguments[ 0 ] that control though has no
+ // info like name etc.
+ uno::Reference< drawing::XControlShape > xCntrlShape( evt.Source, UNO_QUERY_THROW );
+ OSL_TRACE("Got control shape");
+ uno::Reference< container::XNamed > xName( xCntrlShape->getControl(), uno::UNO_QUERY_THROW );
+ OSL_TRACE("Got xnamed ");
+ sName = xName->getName();
+ }
+ else
+ {
+ // Userform control ( fired from the api or from event manager )
+ uno::Reference< beans::XPropertySet > xProps;
+ OSL_TRACE("Getting properties");
+ xProps.set( xControl->getModel(), uno::UNO_QUERY_THROW );
+ xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Name") ) ) >>= sName;
+ }
+
+ }
//dumpEvent( evt );
EventInfoHash& infos = getEventTransInfo();
EventInfoHash::const_iterator eventInfo_it = infos.find( evt.MethodName );
@@ -885,20 +1056,49 @@ EventListener::firing_Impl(const ScriptEvent& evt, Any* /*pRet*/ ) throw(Runtime
std::list< TranslateInfo >::const_iterator txInfo =
eventInfo_it->second.begin();
std::list< TranslateInfo >::const_iterator txInfo_end = eventInfo_it->second.end();
- rtl::OUString sMacroLoc = rtl::OUString::createFromAscii("Standard.").concat( evt.ScriptCode ).concat( rtl::OUString::createFromAscii(".") );
StarBASIC* pBasic = mpShell->GetBasic();
- SbModule* pModule = pBasic->FindModule( evt.ScriptCode );
- for ( ; pModule && txInfo != txInfo_end; ++txInfo )
+ BasicManager* pBasicManager = mpShell->GetBasicManager();
+ rtl::OUString sProject;
+ rtl::OUString sScriptCode( evt.ScriptCode );
+ // dialogs pass their own library, presence of Dot determines that
+ if ( sScriptCode.indexOf( '.' ) == -1 )
+ {
+ //'Project' is a better default but I want to force failures
+ //rtl::OUString sMacroLoc = rtl::OUString::createFromAscii("Project");
+ sProject = rtl::OUString::createFromAscii("Standard");
+
+ if ( pBasicManager->GetName().Len() > 0 )
+ sProject = pBasicManager->GetName();
+ }
+ else
+ {
+ sal_Int32 nIndex = sScriptCode.indexOf( '.' );
+ sProject = sScriptCode.copy( 0, nIndex );
+ sScriptCode = sScriptCode.copy( nIndex + 1 );
+ }
+ rtl::OUString sMacroLoc = sProject;
+ sMacroLoc = sMacroLoc.concat( rtl::OUString::createFromAscii(".") );
+ sMacroLoc = sMacroLoc.concat( sScriptCode ).concat( rtl::OUString::createFromAscii(".") );
+
+ OSL_TRACE("sMacroLoc is %s", rtl::OUStringToOString( sMacroLoc, RTL_TEXTENCODING_UTF8 ).getStr() );
+ for ( ; txInfo != txInfo_end; ++txInfo )
{
+ // If the document is closed, we should not execute macro.
+ if (m_bDocClosed)
+ {
+ break;
+ }
+
+ rtl::OUString sTemp = sName.concat( (*txInfo).sVBAName );
// see if we have a match for the handlerextension
// where ScriptCode is methodname_handlerextension
- rtl::OUString sTemp = sName.concat( (*txInfo).sVBAName );
+ rtl::OUString sToResolve = sMacroLoc.concat( sTemp );
OSL_TRACE("*** trying to invoke %s ",
- rtl::OUStringToOString( sTemp, RTL_TEXTENCODING_UTF8 ).getStr() );
- SbMethod* pMeth = static_cast< SbMethod* >( pModule->Find( sTemp, SbxCLASS_METHOD ) );
- if ( pMeth )
+ rtl::OUStringToOString( sToResolve, RTL_TEXTENCODING_UTF8 ).getStr() );
+ ooo::vba::VBAMacroResolvedInfo aMacroResolvedInfo = ooo::vba::resolveVBAMacro( mpShell, sToResolve );
+ if ( aMacroResolvedInfo.IsResolved() )
{
//liuchen 2009-6-8
if (! txInfo->ApproveRule(evt, txInfo->pPara) )
@@ -916,24 +1116,21 @@ EventListener::firing_Impl(const ScriptEvent& evt, Any* /*pRet*/ ) throw(Runtime
{
// call basic event handlers for event
- static rtl::OUString part1 = rtl::OUString::createFromAscii( "vnd.sun.star.script:");
- static rtl::OUString part2 = rtl::OUString::createFromAscii("?language=Basic&location=document");
-
// create script url
- rtl::OUString url = part1 + sMacroLoc + sTemp + part2;
+ rtl::OUString url = aMacroResolvedInfo.ResolvedMacro();
- OSL_TRACE("script url = %s",
+ OSL_TRACE("resolved script = %s",
rtl::OUStringToOString( url,
RTL_TEXTENCODING_UTF8 ).getStr() );
- Sequence< sal_Int16 > aOutArgsIndex;
- Sequence< Any > aOutArgs;
try
{
- if ( mpShell )
+ uno::Any aDummyCaller = uno::makeAny( rtl::OUString::createFromAscii("Error") );
+ if ( pRet )
+ ooo::vba::executeMacro( mpShell, url, aArguments, *pRet, aDummyCaller );
+ else
{
uno::Any aRet;
- mpShell->CallXScript( url,
- aArguments, aRet, aOutArgsIndex, aOutArgs, false );
+ ooo::vba::executeMacro( mpShell, url, aArguments, aRet, aDummyCaller );
}
}
catch ( uno::Exception& e )
diff --git a/scripting/source/vbaevents/makefile.mk b/scripting/source/vbaevents/makefile.mk
index 1946c61d1e..a36789805a 100644
--- a/scripting/source/vbaevents/makefile.mk
+++ b/scripting/source/vbaevents/makefile.mk
@@ -69,6 +69,7 @@ SHL1STDLIBS= \
$(BASICLIB) \
$(COMPHELPERLIB) \
$(SFXLIB) \
+ $(MSFILTERLIB) \
$(CPPULIB) \
$(TOOLSLIB) \
$(SALLIB)