diff options
Diffstat (limited to 'scripting/source/basprov')
-rw-r--r-- | scripting/source/basprov/baslibnode.cxx | 148 | ||||
-rw-r--r-- | scripting/source/basprov/baslibnode.hxx | 87 | ||||
-rw-r--r-- | scripting/source/basprov/basmethnode.cxx | 358 | ||||
-rw-r--r-- | scripting/source/basprov/basmethnode.hxx | 132 | ||||
-rw-r--r-- | scripting/source/basprov/basmodnode.cxx | 153 | ||||
-rw-r--r-- | scripting/source/basprov/basmodnode.hxx | 81 | ||||
-rw-r--r-- | scripting/source/basprov/basprov.component | 37 | ||||
-rw-r--r-- | scripting/source/basprov/basprov.cxx | 599 | ||||
-rw-r--r-- | scripting/source/basprov/basprov.hxx | 115 | ||||
-rw-r--r-- | scripting/source/basprov/basprov.xml | 50 | ||||
-rw-r--r-- | scripting/source/basprov/basscript.cxx | 248 | ||||
-rw-r--r-- | scripting/source/basprov/basscript.hxx | 93 | ||||
-rw-r--r-- | scripting/source/basprov/makefile.mk | 82 |
13 files changed, 2183 insertions, 0 deletions
diff --git a/scripting/source/basprov/baslibnode.cxx b/scripting/source/basprov/baslibnode.cxx new file mode 100644 index 000000000000..d955d75cca4a --- /dev/null +++ b/scripting/source/basprov/baslibnode.cxx @@ -0,0 +1,148 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_scripting.hxx" +#include "baslibnode.hxx" +#include "basmodnode.hxx" +#include <com/sun/star/script/browse/BrowseNodeTypes.hpp> +#include <vos/mutex.hxx> +#include <vcl/svapp.hxx> +#include <basic/basmgr.hxx> +#include <basic/sbstar.hxx> + + +using namespace ::com::sun::star; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::script; + + +//......................................................................... +namespace basprov +{ +//......................................................................... + + // ============================================================================= + // BasicLibraryNodeImpl + // ============================================================================= + + BasicLibraryNodeImpl::BasicLibraryNodeImpl( const Reference< XComponentContext >& rxContext, + const ::rtl::OUString& sScriptingContext, BasicManager* pBasicManager, + const Reference< script::XLibraryContainer >& xLibContainer, const ::rtl::OUString& sLibName, bool isAppScript ) + :m_xContext( rxContext ) + ,m_sScriptingContext( sScriptingContext ) + ,m_pBasicManager( pBasicManager ) + ,m_xLibContainer( xLibContainer ) + ,m_sLibName( sLibName ) + ,m_bIsAppScript( isAppScript ) + { + if ( m_xLibContainer.is() ) + { + Any aElement = m_xLibContainer->getByName( m_sLibName ); + aElement >>= m_xLibrary; + } + } + + // ----------------------------------------------------------------------------- + + BasicLibraryNodeImpl::~BasicLibraryNodeImpl() + { + } + + // ----------------------------------------------------------------------------- + // XBrowseNode + // ----------------------------------------------------------------------------- + + ::rtl::OUString BasicLibraryNodeImpl::getName( ) throw (RuntimeException) + { + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + + return m_sLibName; + } + + // ----------------------------------------------------------------------------- + + Sequence< Reference< browse::XBrowseNode > > BasicLibraryNodeImpl::getChildNodes( ) throw (RuntimeException) + { + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + + Sequence< Reference< browse::XBrowseNode > > aChildNodes; + + if ( m_xLibContainer.is() && m_xLibContainer->hasByName( m_sLibName ) && !m_xLibContainer->isLibraryLoaded( m_sLibName ) ) + m_xLibContainer->loadLibrary( m_sLibName ); + + if ( m_pBasicManager ) + { + StarBASIC* pBasic = m_pBasicManager->GetLib( m_sLibName ); + if ( pBasic && m_xLibrary.is() ) + { + Sequence< ::rtl::OUString > aNames = m_xLibrary->getElementNames(); + sal_Int32 nCount = aNames.getLength(); + const ::rtl::OUString* pNames = aNames.getConstArray(); + aChildNodes.realloc( nCount ); + Reference< browse::XBrowseNode >* pChildNodes = aChildNodes.getArray(); + + for ( sal_Int32 i = 0 ; i < nCount ; ++i ) + { + SbModule* pModule = pBasic->FindModule( pNames[i] ); + if ( pModule ) + pChildNodes[i] = static_cast< browse::XBrowseNode* >( new BasicModuleNodeImpl( m_xContext, m_sScriptingContext, pModule, m_bIsAppScript ) ); + } + } + } + + return aChildNodes; + } + + // ----------------------------------------------------------------------------- + + sal_Bool BasicLibraryNodeImpl::hasChildNodes( ) throw (RuntimeException) + { + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + + sal_Bool bReturn = sal_False; + if ( m_xLibrary.is() ) + bReturn = m_xLibrary->hasElements(); + + return bReturn; + } + + // ----------------------------------------------------------------------------- + + sal_Int16 BasicLibraryNodeImpl::getType( ) throw (RuntimeException) + { + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + + return browse::BrowseNodeTypes::CONTAINER; + } + + // ----------------------------------------------------------------------------- + +//......................................................................... +} // namespace basprov +//......................................................................... diff --git a/scripting/source/basprov/baslibnode.hxx b/scripting/source/basprov/baslibnode.hxx new file mode 100644 index 000000000000..8843f4121306 --- /dev/null +++ b/scripting/source/basprov/baslibnode.hxx @@ -0,0 +1,87 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef SCRIPTING_BASLIBNODE_HXX +#define SCRIPTING_BASLIBNODE_HXX + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/script/XLibraryContainer.hpp> +#include <com/sun/star/script/browse/XBrowseNode.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <cppuhelper/implbase1.hxx> + +class BasicManager; + + +//......................................................................... +namespace basprov +{ +//......................................................................... + + // ---------------------------------------------------- + // class BasicLibraryNodeImpl + // ---------------------------------------------------- + + typedef ::cppu::WeakImplHelper1< + ::com::sun::star::script::browse::XBrowseNode > BasicLibraryNodeImpl_BASE; + + + class BasicLibraryNodeImpl : public BasicLibraryNodeImpl_BASE + { + private: + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext; + ::rtl::OUString m_sScriptingContext; + BasicManager* m_pBasicManager; + ::com::sun::star::uno::Reference< ::com::sun::star::script::XLibraryContainer > m_xLibContainer; + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > m_xLibrary; + ::rtl::OUString m_sLibName; + bool m_bIsAppScript; + + public: + BasicLibraryNodeImpl( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext, + const ::rtl::OUString& sScriptingContext, + BasicManager* pBasicManager, + const ::com::sun::star::uno::Reference< ::com::sun::star::script::XLibraryContainer >& xLibContainer, + const ::rtl::OUString& sLibName, bool isAppScript=true ); + virtual ~BasicLibraryNodeImpl(); + + // XBrowseNode + virtual ::rtl::OUString SAL_CALL getName( ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::script::browse::XBrowseNode > > SAL_CALL getChildNodes( ) + throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL hasChildNodes( ) + throw (::com::sun::star::uno::RuntimeException); + virtual sal_Int16 SAL_CALL getType( ) + throw (::com::sun::star::uno::RuntimeException); + }; + +//......................................................................... +} // namespace basprov +//......................................................................... + +#endif // SCRIPTING_BASLIBNODE_HXX diff --git a/scripting/source/basprov/basmethnode.cxx b/scripting/source/basprov/basmethnode.cxx new file mode 100644 index 000000000000..f27b612ce9cb --- /dev/null +++ b/scripting/source/basprov/basmethnode.cxx @@ -0,0 +1,358 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_scripting.hxx" +#include "basmethnode.hxx" +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/frame/XDesktop.hpp> +#include <com/sun/star/frame/XDispatchHelper.hpp> +#include <com/sun/star/frame/XDispatchProvider.hpp> +#include <com/sun/star/lang/XMultiComponentFactory.hpp> +#include <com/sun/star/script/browse/BrowseNodeTypes.hpp> +#include <vos/mutex.hxx> +#include <vcl/svapp.hxx> +#include <basic/sbstar.hxx> +#include <basic/sbmeth.hxx> +#include <basic/sbmod.hxx> + +#include <util/MiscUtils.hxx> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::comphelper; +using namespace ::com::sun::star::script; +using namespace ::sf_misc; + +#define BASPROV_PROPERTY_ID_URI 1 +#define BASPROV_PROPERTY_ID_EDITABLE 2 + +#define BASPROV_PROPERTY_URI ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URI" ) ) +#define BASPROV_PROPERTY_EDITABLE ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Editable" ) ) + +#define BASPROV_DEFAULT_ATTRIBS() PropertyAttribute::BOUND | PropertyAttribute::TRANSIENT | PropertyAttribute::READONLY + + +//......................................................................... +namespace basprov +{ +//......................................................................... + + // ============================================================================= + // BasicMethodNodeImpl + // ============================================================================= + + BasicMethodNodeImpl::BasicMethodNodeImpl( const Reference< XComponentContext >& rxContext, + const ::rtl::OUString& sScriptingContext, SbMethod* pMethod, bool isAppScript ) + : ::scripting_helper::OBroadcastHelperHolder( m_aMutex ) + ,OPropertyContainer( GetBroadcastHelper() ) + ,m_xContext( rxContext ) + ,m_sScriptingContext( sScriptingContext ) + ,m_pMethod( pMethod ) + ,m_bIsAppScript( isAppScript ) + ,m_bEditable( sal_True ) + { + if ( m_pMethod ) + { + SbModule* pModule = m_pMethod->GetModule(); + if ( pModule ) + { + StarBASIC* pBasic = static_cast< StarBASIC* >( pModule->GetParent() ); + if ( pBasic ) + { + m_sURI = ::rtl::OUString::createFromAscii( "vnd.sun.star.script:" ); + m_sURI += pBasic->GetName(); + m_sURI += ::rtl::OUString::createFromAscii( "." ); + m_sURI += pModule->GetName(); + m_sURI += ::rtl::OUString::createFromAscii( "." ); + m_sURI += m_pMethod->GetName(); + m_sURI += ::rtl::OUString::createFromAscii( "?language=Basic&location=" ); + if ( m_bIsAppScript ) + m_sURI += ::rtl::OUString::createFromAscii( "application" ); + else + m_sURI += ::rtl::OUString::createFromAscii( "document" ); + } + } + } + + registerProperty( BASPROV_PROPERTY_URI, BASPROV_PROPERTY_ID_URI, BASPROV_DEFAULT_ATTRIBS(), &m_sURI, ::getCppuType( &m_sURI ) ); + registerProperty( BASPROV_PROPERTY_EDITABLE, BASPROV_PROPERTY_ID_EDITABLE, BASPROV_DEFAULT_ATTRIBS(), &m_bEditable, ::getCppuType( &m_bEditable ) ); + } + + // ----------------------------------------------------------------------------- + + BasicMethodNodeImpl::~BasicMethodNodeImpl() + { + } + + // ----------------------------------------------------------------------------- + // XInterface + // ----------------------------------------------------------------------------- + + IMPLEMENT_FORWARD_XINTERFACE2( BasicMethodNodeImpl, BasicMethodNodeImpl_BASE, OPropertyContainer ) + + // ----------------------------------------------------------------------------- + // XTypeProvider + // ----------------------------------------------------------------------------- + + IMPLEMENT_FORWARD_XTYPEPROVIDER2( BasicMethodNodeImpl, BasicMethodNodeImpl_BASE, OPropertyContainer ) + + // ----------------------------------------------------------------------------- + // XBrowseNode + // ----------------------------------------------------------------------------- + + ::rtl::OUString BasicMethodNodeImpl::getName( ) throw (RuntimeException) + { + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + + ::rtl::OUString sMethodName; + if ( m_pMethod ) + sMethodName = m_pMethod->GetName(); + + return sMethodName; + } + + // ----------------------------------------------------------------------------- + + Sequence< Reference< browse::XBrowseNode > > BasicMethodNodeImpl::getChildNodes( ) throw (RuntimeException) + { + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + + return Sequence< Reference< browse::XBrowseNode > >(); + } + + // ----------------------------------------------------------------------------- + + sal_Bool BasicMethodNodeImpl::hasChildNodes( ) throw (RuntimeException) + { + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + + return sal_False; + } + + // ----------------------------------------------------------------------------- + + sal_Int16 BasicMethodNodeImpl::getType( ) throw (RuntimeException) + { + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + + return browse::BrowseNodeTypes::SCRIPT; + } + + // ----------------------------------------------------------------------------- + // OPropertySetHelper + // ----------------------------------------------------------------------------- + + ::cppu::IPropertyArrayHelper& BasicMethodNodeImpl::getInfoHelper( ) + { + return *getArrayHelper(); + } + + // ----------------------------------------------------------------------------- + // OPropertyArrayUsageHelper + // ----------------------------------------------------------------------------- + + ::cppu::IPropertyArrayHelper* BasicMethodNodeImpl::createArrayHelper( ) const + { + Sequence< Property > aProps; + describeProperties( aProps ); + return new ::cppu::OPropertyArrayHelper( aProps ); + } + + // ----------------------------------------------------------------------------- + // XPropertySet + // ----------------------------------------------------------------------------- + + Reference< XPropertySetInfo > BasicMethodNodeImpl::getPropertySetInfo( ) throw (RuntimeException) + { + Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; + } + + // ----------------------------------------------------------------------------- + // XInvocation + // ----------------------------------------------------------------------------- + + Reference< XIntrospectionAccess > BasicMethodNodeImpl::getIntrospection( ) throw (RuntimeException) + { + return Reference< XIntrospectionAccess >(); + } + + // ----------------------------------------------------------------------------- + + Any BasicMethodNodeImpl::invoke( const ::rtl::OUString& aFunctionName, const Sequence< Any >& aParams, + Sequence< sal_Int16 >& aOutParamIndex, Sequence< Any >& aOutParam ) + throw (IllegalArgumentException, script::CannotConvertException, + reflection::InvocationTargetException, RuntimeException) + { + (void)aParams; + (void)aOutParamIndex; + (void)aOutParam; + + if ( aFunctionName == BASPROV_PROPERTY_EDITABLE ) + { + ::rtl::OUString sDocURL, sLibName, sModName; + USHORT nLine1 = 0, nLine2; + + if ( !m_bIsAppScript ) + { + Reference< frame::XModel > xModel = MiscUtils::tDocUrlToModel( m_sScriptingContext ); + + if ( xModel.is() ) + { + sDocURL = xModel->getURL(); + if ( sDocURL.getLength() == 0 ) + { + Sequence < PropertyValue > aProps = xModel->getArgs(); + sal_Int32 nProps = aProps.getLength(); + const PropertyValue* pProps = aProps.getConstArray(); + for ( sal_Int32 i = 0; i < nProps; ++i ) + { + // TODO: according to MBA the property 'Title' may change in future + if ( pProps[i].Name == ::rtl::OUString::createFromAscii( "Title" ) ) + { + pProps[i].Value >>= sDocURL; + break; + } + } + } + } + } + + if ( m_pMethod ) + { + m_pMethod->GetLineRange( nLine1, nLine2 ); + SbModule* pModule = m_pMethod->GetModule(); + if ( pModule ) + { + sModName = pModule->GetName(); + StarBASIC* pBasic = static_cast< StarBASIC* >( pModule->GetParent() ); + if ( pBasic ) + sLibName = pBasic->GetName(); + } + } + + if ( m_xContext.is() ) + { + Reference< XMultiComponentFactory > xSMgr( m_xContext->getServiceManager() ); + + if ( xSMgr.is() ) + { + Reference< frame::XDesktop > xDesktop( xSMgr->createInstanceWithContext( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ) ), m_xContext ), UNO_QUERY ); + + if ( xDesktop.is() ) + { + Reference < frame::XDispatchProvider > xProv( xDesktop->getCurrentFrame(), UNO_QUERY ); + + if ( xProv.is() ) + { + Reference< frame::XDispatchHelper > xHelper( xSMgr->createInstanceWithContext( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.DispatchHelper" ) ), m_xContext ), UNO_QUERY ); + + if ( xHelper.is() ) + { + Sequence < PropertyValue > aArgs(7); + aArgs[0].Name = ::rtl::OUString::createFromAscii( "Document" ); + aArgs[0].Value <<= sDocURL; + aArgs[1].Name = ::rtl::OUString::createFromAscii( "LibName" ); + aArgs[1].Value <<= sLibName; + aArgs[2].Name = ::rtl::OUString::createFromAscii( "Name" ); + aArgs[2].Value <<= sModName; + aArgs[3].Name = ::rtl::OUString::createFromAscii( "Type" ); + aArgs[3].Value <<= ::rtl::OUString::createFromAscii( "Module" ); + aArgs[4].Name = ::rtl::OUString::createFromAscii( "Line" ); + aArgs[4].Value <<= static_cast< sal_uInt32 >( nLine1 ); + xHelper->executeDispatch( xProv, ::rtl::OUString::createFromAscii( ".uno:BasicIDEAppear" ), ::rtl::OUString(), 0, aArgs ); + } + } + } + } + } + } + else + { + throw IllegalArgumentException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicMethodNodeImpl::invoke: function name not supported!" ) ), + Reference< XInterface >(), 1 ); + } + + return Any(); + } + + // ----------------------------------------------------------------------------- + + void BasicMethodNodeImpl::setValue( const ::rtl::OUString& aPropertyName, const Any& aValue ) + throw (UnknownPropertyException, script::CannotConvertException, + reflection::InvocationTargetException, RuntimeException) + { + (void)aPropertyName; + (void)aValue; + + throw UnknownPropertyException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicMethodNodeImpl::setValue: property name is unknown!" ) ), + Reference< XInterface >() ); + } + + // ----------------------------------------------------------------------------- + + Any BasicMethodNodeImpl::getValue( const ::rtl::OUString& aPropertyName ) throw (UnknownPropertyException, RuntimeException) + { + (void)aPropertyName; + + throw UnknownPropertyException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicMethodNodeImpl::getValue: property name is unknown!" ) ), + Reference< XInterface >() ); + } + + // ----------------------------------------------------------------------------- + + sal_Bool BasicMethodNodeImpl::hasMethod( const ::rtl::OUString& aName ) throw (RuntimeException) + { + sal_Bool bReturn = sal_False; + if ( aName == BASPROV_PROPERTY_EDITABLE ) + bReturn = sal_True; + + return bReturn; + } + + // ----------------------------------------------------------------------------- + + sal_Bool BasicMethodNodeImpl::hasProperty( const ::rtl::OUString& aName ) throw (RuntimeException) + { + (void)aName; + + return sal_False; + } + + // ----------------------------------------------------------------------------- + +//......................................................................... +} // namespace basprov +//......................................................................... diff --git a/scripting/source/basprov/basmethnode.hxx b/scripting/source/basprov/basmethnode.hxx new file mode 100644 index 000000000000..cd4f587c884f --- /dev/null +++ b/scripting/source/basprov/basmethnode.hxx @@ -0,0 +1,132 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef SCRIPTING_BASMETHNODE_HXX +#define SCRIPTING_BASMETHNODE_HXX + +#include "bcholder.hxx" +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/script/XInvocation.hpp> +#include <com/sun/star/script/browse/XBrowseNode.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <comphelper/proparrhlp.hxx> +#include <comphelper/propertycontainer.hxx> +#include <comphelper/uno3.hxx> +#include <cppuhelper/implbase2.hxx> + + +class SbMethod; + + +//......................................................................... +namespace basprov +{ +//......................................................................... + + // ---------------------------------------------------- + // class BasicMethodNodeImpl + // ---------------------------------------------------- + + typedef ::cppu::WeakImplHelper2< + ::com::sun::star::script::browse::XBrowseNode, + ::com::sun::star::script::XInvocation > BasicMethodNodeImpl_BASE; + + class BasicMethodNodeImpl : public BasicMethodNodeImpl_BASE, + public ::scripting_helper::OMutexHolder, + public ::scripting_helper::OBroadcastHelperHolder, + public ::comphelper::OPropertyContainer, + public ::comphelper::OPropertyArrayUsageHelper< BasicMethodNodeImpl > + { + private: + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext; + ::rtl::OUString m_sScriptingContext; + SbMethod* m_pMethod; + bool m_bIsAppScript; + + // properties + ::rtl::OUString m_sURI; + sal_Bool m_bEditable; + + protected: + // OPropertySetHelper + virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper( ); + + // OPropertyArrayUsageHelper + virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const; + + public: + BasicMethodNodeImpl( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext, + const ::rtl::OUString& sScriptingContext, + SbMethod* pMethod, bool isAppScript = true ); + virtual ~BasicMethodNodeImpl(); + + // XInterface + DECLARE_XINTERFACE() + + // XTypeProvider + DECLARE_XTYPEPROVIDER() + + // XBrowseNode + virtual ::rtl::OUString SAL_CALL getName( ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::script::browse::XBrowseNode > > SAL_CALL getChildNodes( ) + throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL hasChildNodes( ) + throw (::com::sun::star::uno::RuntimeException); + virtual sal_Int16 SAL_CALL getType( ) + throw (::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); + + // XInvocation + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XIntrospectionAccess > SAL_CALL getIntrospection( ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Any SAL_CALL invoke( + const ::rtl::OUString& aFunctionName, + const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aParams, + ::com::sun::star::uno::Sequence< sal_Int16 >& aOutParamIndex, + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aOutParam ) + throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::script::CannotConvertException, + ::com::sun::star::reflection::InvocationTargetException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) + throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::script::CannotConvertException, + ::com::sun::star::reflection::InvocationTargetException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Any SAL_CALL getValue( const ::rtl::OUString& aPropertyName ) + throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL hasMethod( const ::rtl::OUString& aName ) + throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL hasProperty( const ::rtl::OUString& aName ) + throw (::com::sun::star::uno::RuntimeException); + }; + +//......................................................................... +} // namespace basprov +//......................................................................... + +#endif // SCRIPTING_BASMETHNODE_HXX diff --git a/scripting/source/basprov/basmodnode.cxx b/scripting/source/basprov/basmodnode.cxx new file mode 100644 index 000000000000..fe6ed69fccab --- /dev/null +++ b/scripting/source/basprov/basmodnode.cxx @@ -0,0 +1,153 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_scripting.hxx" +#include "basmodnode.hxx" +#include "basmethnode.hxx" +#include <com/sun/star/script/browse/BrowseNodeTypes.hpp> +#include <vos/mutex.hxx> +#include <vcl/svapp.hxx> +#include <basic/sbx.hxx> +#include <basic/sbstar.hxx> +#include <basic/sbmod.hxx> +#include <basic/sbmeth.hxx> + + +using namespace ::com::sun::star; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::script; + + +//......................................................................... +namespace basprov +{ +//......................................................................... + + // ============================================================================= + // BasicModuleNodeImpl + // ============================================================================= + + BasicModuleNodeImpl::BasicModuleNodeImpl( const Reference< XComponentContext >& rxContext, + const ::rtl::OUString& sScriptingContext, SbModule* pModule, bool isAppScript ) + :m_xContext( rxContext ) + ,m_sScriptingContext( sScriptingContext ) + ,m_pModule( pModule ) + ,m_bIsAppScript( isAppScript ) + { + } + + // ----------------------------------------------------------------------------- + + BasicModuleNodeImpl::~BasicModuleNodeImpl() + { + } + + // ----------------------------------------------------------------------------- + // XBrowseNode + // ----------------------------------------------------------------------------- + + ::rtl::OUString BasicModuleNodeImpl::getName( ) throw (RuntimeException) + { + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + + ::rtl::OUString sModuleName; + if ( m_pModule ) + sModuleName = m_pModule->GetName(); + + return sModuleName; + } + + // ----------------------------------------------------------------------------- + + Sequence< Reference< browse::XBrowseNode > > BasicModuleNodeImpl::getChildNodes( ) throw (RuntimeException) + { + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + + Sequence< Reference< browse::XBrowseNode > > aChildNodes; + + if ( m_pModule ) + { + SbxArray* pMethods = m_pModule->GetMethods(); + if ( pMethods ) + { + sal_Int32 nCount = pMethods->Count(); + sal_Int32 nRealCount = 0; + for ( sal_Int32 i = 0; i < nCount; ++i ) + { + SbMethod* pMethod = static_cast< SbMethod* >( pMethods->Get( static_cast< USHORT >( i ) ) ); + if ( pMethod && !pMethod->IsHidden() ) + ++nRealCount; + } + aChildNodes.realloc( nRealCount ); + Reference< browse::XBrowseNode >* pChildNodes = aChildNodes.getArray(); + + sal_Int32 iTarget = 0; + for ( sal_Int32 i = 0; i < nCount; ++i ) + { + SbMethod* pMethod = static_cast< SbMethod* >( pMethods->Get( static_cast< USHORT >( i ) ) ); + if ( pMethod && !pMethod->IsHidden() ) + pChildNodes[iTarget++] = static_cast< browse::XBrowseNode* >( new BasicMethodNodeImpl( m_xContext, m_sScriptingContext, pMethod, m_bIsAppScript ) ); + } + } + } + + return aChildNodes; + } + + // ----------------------------------------------------------------------------- + + sal_Bool BasicModuleNodeImpl::hasChildNodes( ) throw (RuntimeException) + { + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + + sal_Bool bReturn = sal_False; + if ( m_pModule ) + { + SbxArray* pMethods = m_pModule->GetMethods(); + if ( pMethods && pMethods->Count() > 0 ) + bReturn = sal_True; + } + + return bReturn; + } + + // ----------------------------------------------------------------------------- + + sal_Int16 BasicModuleNodeImpl::getType( ) throw (RuntimeException) + { + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + + return browse::BrowseNodeTypes::CONTAINER; + } + + // ----------------------------------------------------------------------------- + +//......................................................................... +} // namespace basprov +//......................................................................... diff --git a/scripting/source/basprov/basmodnode.hxx b/scripting/source/basprov/basmodnode.hxx new file mode 100644 index 000000000000..6f3ef3263e51 --- /dev/null +++ b/scripting/source/basprov/basmodnode.hxx @@ -0,0 +1,81 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef SCRIPTING_BASMODNODE_HXX +#define SCRIPTING_BASMODNODE_HXX + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/script/browse/XBrowseNode.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <cppuhelper/implbase1.hxx> + +class SbModule; + + +//......................................................................... +namespace basprov +{ +//......................................................................... + + // ---------------------------------------------------- + // class BasicModuleNodeImpl + // ---------------------------------------------------- + + typedef ::cppu::WeakImplHelper1< + ::com::sun::star::script::browse::XBrowseNode > BasicModuleNodeImpl_BASE; + + + class BasicModuleNodeImpl : public BasicModuleNodeImpl_BASE + { + private: + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext; + ::rtl::OUString m_sScriptingContext; + SbModule* m_pModule; + bool m_bIsAppScript; + + public: + BasicModuleNodeImpl( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext, + const ::rtl::OUString& sScriptingContext, + SbModule* pModule, bool isAppScript = true ); + virtual ~BasicModuleNodeImpl(); + + // XBrowseNode + virtual ::rtl::OUString SAL_CALL getName( ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::script::browse::XBrowseNode > > SAL_CALL getChildNodes( ) + throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL hasChildNodes( ) + throw (::com::sun::star::uno::RuntimeException); + virtual sal_Int16 SAL_CALL getType( ) + throw (::com::sun::star::uno::RuntimeException); + }; + +//......................................................................... +} // namespace basprov +//......................................................................... + +#endif // SCRIPTING_BASMODNODE_HXX diff --git a/scripting/source/basprov/basprov.component b/scripting/source/basprov/basprov.component new file mode 100644 index 000000000000..528ab6544e1e --- /dev/null +++ b/scripting/source/basprov/basprov.component @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!--********************************************************************** +* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2000, 2010 Oracle and/or its affiliates. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* OpenOffice.org is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 3 +* only, as published by the Free Software Foundation. +* +* OpenOffice.org is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License version 3 for more details +* (a copy is included in the LICENSE file that accompanied this code). +* +* You should have received a copy of the GNU Lesser General Public License +* version 3 along with OpenOffice.org. If not, see +* <http://www.openoffice.org/license.html> +* for a copy of the LGPLv3 License. +* +**********************************************************************--> + +<component loader="com.sun.star.loader.SharedLibrary" + xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="com.sun.star.comp.scripting.ScriptProviderForBasic"> + <service name="com.sun.star.script.browse.BrowseNode"/> + <service name="com.sun.star.script.provider.LanguageScriptProvider"/> + <service name="com.sun.star.script.provider.ScriptProvider"/> + <service name="com.sun.star.script.provider.ScriptProviderForBasic"/> + </implementation> +</component> diff --git a/scripting/source/basprov/basprov.cxx b/scripting/source/basprov/basprov.cxx new file mode 100644 index 000000000000..ed6c9d7e6a5b --- /dev/null +++ b/scripting/source/basprov/basprov.cxx @@ -0,0 +1,599 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_scripting.hxx" +#include "basprov.hxx" +#include "basscript.hxx" +#include "baslibnode.hxx" +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/script/browse/BrowseNodeTypes.hpp> +#include <com/sun/star/script/provider/ScriptFrameworkErrorType.hpp> +#include <com/sun/star/document/XEmbeddedScripts.hpp> + +#ifndef _CPPUHELPER_IMPLEMENTATIONENTRY_HXX_ +#include <cppuhelper/implementationentry.hxx> +#endif +#include <rtl/uri.hxx> +#include <osl/process.h> +#include <osl/file.hxx> +#include <vos/mutex.hxx> +#include <vcl/svapp.hxx> +#include <basic/sbx.hxx> +#include <basic/basmgr.hxx> +#include <basic/basicmanagerrepository.hxx> +#include <basic/sbstar.hxx> +#include <basic/sbmod.hxx> +#include <basic/sbmeth.hxx> +#include <sfx2/app.hxx> +#include <sfx2/objsh.hxx> + +#include <com/sun/star/util/XMacroExpander.hpp> +#include <com/sun/star/script/XLibraryContainer2.hpp> +#include <com/sun/star/uri/XUriReference.hpp> +#include <com/sun/star/uri/XUriReferenceFactory.hpp> +#include <com/sun/star/uri/XVndSunStarScriptUrl.hpp> + +#include <util/util.hxx> +#include <util/MiscUtils.hxx> + + +using namespace ::com::sun::star; +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 ::sf_misc; + +//......................................................................... +namespace basprov +{ +//......................................................................... + + // ============================================================================= + // component operations + // ============================================================================= + + static ::rtl::OUString getImplementationName_BasicProviderImpl() + { + static ::rtl::OUString* pImplName = 0; + if ( !pImplName ) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if ( !pImplName ) + { + static ::rtl::OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.scripting.ScriptProviderForBasic" ) ); + pImplName = &aImplName; + } + } + return *pImplName; + } + + // ----------------------------------------------------------------------------- + + static Sequence< ::rtl::OUString > getSupportedServiceNames_BasicProviderImpl() + { + static Sequence< ::rtl::OUString >* pNames = 0; + if ( !pNames ) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if ( !pNames ) + { + static Sequence< ::rtl::OUString > aNames(4); + aNames.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.script.provider.ScriptProviderForBasic" ) ); + aNames.getArray()[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.script.provider.LanguageScriptProvider" ) ); + aNames.getArray()[2] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.script.provider.ScriptProvider" ) ); + aNames.getArray()[3] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.script.browse.BrowseNode" ) ); + pNames = &aNames; + } + } + return *pNames; + } + + // ============================================================================= + // BasicProviderImpl + // ============================================================================= + + BasicProviderImpl::BasicProviderImpl( const Reference< XComponentContext >& xContext ) + :m_pAppBasicManager( 0 ) + ,m_pDocBasicManager( 0 ) + ,m_xLibContainerApp( 0 ) + ,m_xLibContainerDoc( 0 ) + ,m_xContext( xContext ) + ,m_bIsAppScriptCtx( true ) + ,m_bIsUserCtx(true) + { + } + + // ----------------------------------------------------------------------------- + + BasicProviderImpl::~BasicProviderImpl() + { + } + + // ----------------------------------------------------------------------------- + + bool BasicProviderImpl::isLibraryShared( const Reference< script::XLibraryContainer >& rxLibContainer, const ::rtl::OUString& rLibName ) + { + bool bIsShared = false; + + Reference< script::XLibraryContainer2 > xLibContainer( rxLibContainer, UNO_QUERY ); + if ( xLibContainer.is() && xLibContainer->hasByName( rLibName ) && xLibContainer->isLibraryLink( rLibName ) ) + { + ::rtl::OUString aFileURL; + if ( m_xContext.is() ) + { + Reference< uri::XUriReferenceFactory > xUriFac; + Reference< lang::XMultiComponentFactory > xSMgr( m_xContext->getServiceManager() ); + if ( xSMgr.is() ) + { + xUriFac.set( xSMgr->createInstanceWithContext( ::rtl::OUString::createFromAscii( + "com.sun.star.uri.UriReferenceFactory" ), m_xContext ), UNO_QUERY ); + } + + if ( xUriFac.is() ) + { + ::rtl::OUString aLinkURL( xLibContainer->getLibraryLinkURL( rLibName ) ); + Reference< uri::XUriReference > xUriRef( xUriFac->parse( aLinkURL ), UNO_QUERY ); + + if ( xUriRef.is() ) + { + ::rtl::OUString aScheme = xUriRef->getScheme(); + if ( aScheme.equalsIgnoreAsciiCaseAscii( "file" ) ) + { + aFileURL = aLinkURL; + } + else if ( aScheme.equalsIgnoreAsciiCaseAscii( "vnd.sun.star.pkg" ) ) + { + ::rtl::OUString aAuthority = xUriRef->getAuthority(); + if ( aAuthority.matchIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "vnd.sun.star.expand:" ) ) ) + { + ::rtl::OUString aDecodedURL( aAuthority.copy( sizeof ( "vnd.sun.star.expand:" ) - 1 ) ); + aDecodedURL = ::rtl::Uri::decode( aDecodedURL, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 ); + Reference<util::XMacroExpander> xMacroExpander( + m_xContext->getValueByName( + ::rtl::OUString::createFromAscii( "/singletons/com.sun.star.util.theMacroExpander" ) ), + UNO_QUERY ); + if ( xMacroExpander.is() ) + aFileURL = xMacroExpander->expandMacros( aDecodedURL ); + } + } + } + } + } + + if ( aFileURL.getLength() ) + { + osl::DirectoryItem aFileItem; + osl::FileStatus aFileStatus( FileStatusMask_FileURL ); + OSL_VERIFY( osl::DirectoryItem::get( aFileURL, aFileItem ) == osl::FileBase::E_None ); + OSL_VERIFY( aFileItem.getFileStatus( aFileStatus ) == osl::FileBase::E_None ); + ::rtl::OUString aCanonicalFileURL( aFileStatus.getFileURL() ); + + ::rtl::OUString aSearchURL1( RTL_CONSTASCII_USTRINGPARAM( "share/basic" ) ); + ::rtl::OUString aSearchURL2( RTL_CONSTASCII_USTRINGPARAM( "share/uno_packages" ) ); + if( aCanonicalFileURL.indexOf( aSearchURL1 ) != -1 || aCanonicalFileURL.indexOf( aSearchURL2 ) != -1 ) + bIsShared = true; + } + } + + return bIsShared; + } + + // ----------------------------------------------------------------------------- + // XServiceInfo + // ----------------------------------------------------------------------------- + + ::rtl::OUString BasicProviderImpl::getImplementationName( ) throw (RuntimeException) + { + return getImplementationName_BasicProviderImpl(); + } + + // ----------------------------------------------------------------------------- + + sal_Bool BasicProviderImpl::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException) + { + Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() ); + const ::rtl::OUString* pNames = aNames.getConstArray(); + const ::rtl::OUString* pEnd = pNames + aNames.getLength(); + for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames ) + ; + + return pNames != pEnd; + } + + // ----------------------------------------------------------------------------- + + Sequence< ::rtl::OUString > BasicProviderImpl::getSupportedServiceNames( ) throw (RuntimeException) + { + return getSupportedServiceNames_BasicProviderImpl(); + } + + // ----------------------------------------------------------------------------- + // XInitialization + // ----------------------------------------------------------------------------- + + void BasicProviderImpl::initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException) + { + // TODO + + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + + if ( aArguments.getLength() != 1 ) + { + throw IllegalArgumentException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicProviderImpl::initialize: incorrect argument count." ) ), + *this, + 1 + ); + } + + Reference< frame::XModel > xModel; + + m_xInvocationContext.set( aArguments[0], UNO_QUERY );; + if ( m_xInvocationContext.is() ) + { + xModel.set( m_xInvocationContext->getScriptContainer(), UNO_QUERY ); + if ( !xModel.is() ) + { + throw IllegalArgumentException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicProviderImpl::initialize: unable to determine the document model from the script invocation context." ) ), + *this, + 1 + ); + } + } + else + { + if ( !( aArguments[0] >>= m_sScriptingContext ) ) + { + throw IllegalArgumentException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicProviderImpl::initialize: incorrect argument type " ) ).concat( aArguments[0].getValueTypeName() ), + *this, + 1 + ); + } + + ::rtl::OUString sDoc = OUSTR("vnd.sun.star.tdoc"); + if ( m_sScriptingContext.indexOf( sDoc ) == 0 ) + { + xModel = MiscUtils::tDocUrlToModel( m_sScriptingContext ); + // TODO: use ScriptingContantsPool for SCRIPTING_DOC_REF + } + } + + if ( xModel.is() ) + { + Reference< XEmbeddedScripts > xDocumentScripts( xModel, UNO_QUERY ); + if ( xDocumentScripts.is() ) + { + m_pDocBasicManager = ::basic::BasicManagerRepository::getDocumentBasicManager( xModel ); + m_xLibContainerDoc.set( xDocumentScripts->getBasicLibraries(), UNO_QUERY ); + OSL_ENSURE( m_pDocBasicManager && m_xLibContainerDoc.is(), + "BasicProviderImpl::initialize: invalid BasicManager, or invalid script container!" ); + } + m_bIsAppScriptCtx = false; + } + else + { + // Provider has been created with application context for user + // or share + if ( !m_sScriptingContext.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "user" ) ) ) + { + m_bIsUserCtx = false; + } + else + { + /* + throw RuntimeException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicProviderImpl::initialize: no scripting context!" ) ), + Reference< XInterface >() ); + */ + } + } + + // TODO + if ( !m_pAppBasicManager ) + m_pAppBasicManager = SFX_APP()->GetBasicManager(); + + if ( !m_xLibContainerApp.is() ) + m_xLibContainerApp = Reference< script::XLibraryContainer >( SFX_APP()->GetBasicContainer(), UNO_QUERY ); + } + + // ----------------------------------------------------------------------------- + + // XScriptProvider + // ----------------------------------------------------------------------------- + + Reference < provider::XScript > BasicProviderImpl::getScript( const ::rtl::OUString& scriptURI ) + throw ( provider::ScriptFrameworkErrorException, RuntimeException) + { + // TODO + + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + + Reference< provider::XScript > xScript; + Reference< lang::XMultiComponentFactory > xMcFac ( m_xContext->getServiceManager() ); + Reference< uri::XUriReferenceFactory > xFac ( + xMcFac->createInstanceWithContext( rtl::OUString::createFromAscii( + "com.sun.star.uri.UriReferenceFactory"), m_xContext ) , UNO_QUERY ); + + if ( !xFac.is() ) + { + throw provider::ScriptFrameworkErrorException( + OUSTR( "Failed to instantiate UriReferenceFactory" ), Reference< XInterface >(), + scriptURI, OUSTR("Basic"), + provider::ScriptFrameworkErrorType::UNKNOWN ); + } + + Reference< uri::XUriReference > uriRef( + xFac->parse( scriptURI ), UNO_QUERY ); + + Reference < uri::XVndSunStarScriptUrl > sfUri( uriRef, UNO_QUERY ); + + if ( !uriRef.is() || !sfUri.is() ) + { + ::rtl::OUString errorMsg = ::rtl::OUString::createFromAscii( "BasicProviderImpl::getScript: failed to parse URI: " ); + errorMsg = errorMsg.concat( scriptURI ); + throw provider::ScriptFrameworkErrorException( + errorMsg, Reference< XInterface >(), + scriptURI, OUSTR("Basic"), + provider::ScriptFrameworkErrorType::MALFORMED_URL ); + } + + + ::rtl::OUString aDescription = sfUri->getName(); + ::rtl::OUString aLocation = sfUri->getParameter( + ::rtl::OUString::createFromAscii( "location" ) ); + + sal_Int32 nIndex = 0; + ::rtl::OUString aLibrary = aDescription.getToken( 0, (sal_Unicode)'.', nIndex ); + ::rtl::OUString aModule; + if ( nIndex != -1 ) + aModule = aDescription.getToken( 0, (sal_Unicode)'.', nIndex ); + ::rtl::OUString aMethod; + if ( nIndex != -1 ) + aMethod = aDescription.getToken( 0, (sal_Unicode)'.', nIndex ); + + 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 ) + { + StarBASIC* pBasic = pBasicMgr->GetLib( aLibrary ); + if ( !pBasic ) + { + USHORT nId = pBasicMgr->GetLibId( aLibrary ); + if ( nId != LIB_NOTFOUND ) + { + pBasicMgr->LoadLib( nId ); + pBasic = pBasicMgr->GetLib( aLibrary ); + } + } + if ( pBasic ) + { + SbModule* pModule = pBasic->FindModule( aModule ); + if ( pModule ) + { + SbxArray* pMethods = pModule->GetMethods(); + if ( pMethods ) + { + SbMethod* pMethod = static_cast< SbMethod* >( pMethods->Find( aMethod, SbxCLASS_METHOD ) ); + if ( pMethod && !pMethod->IsHidden() ) + { + if ( m_pDocBasicManager == pBasicMgr ) + xScript = new BasicScriptImpl( aDescription, pMethod, *m_pDocBasicManager, m_xInvocationContext ); + else + xScript = new BasicScriptImpl( aDescription, pMethod ); + } + } + } + } + } + } + + if ( !xScript.is() ) + { + ::rtl::OUStringBuffer aMessage; + aMessage.appendAscii( "The following Basic script could not be found:\n" ); + aMessage.appendAscii( "library: '" ).append( aLibrary ).appendAscii( "'\n" ); + aMessage.appendAscii( "module: '" ).append( aModule ).appendAscii( "'\n" ); + aMessage.appendAscii( "method: '" ).append( aMethod ).appendAscii( "'\n" ); + aMessage.appendAscii( "location: '" ).append( aLocation ).appendAscii( "'\n" ); + throw provider::ScriptFrameworkErrorException( + aMessage.makeStringAndClear(), + Reference< XInterface >(), + scriptURI, OUSTR("Basic"), + provider::ScriptFrameworkErrorType::NO_SUCH_SCRIPT ); + } + + return xScript; + } + + // ----------------------------------------------------------------------------- + // XBrowseNode + // ----------------------------------------------------------------------------- + + ::rtl::OUString BasicProviderImpl::getName( ) throw (RuntimeException) + { + // TODO + + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + + return ::rtl::OUString::createFromAscii( "Basic" ); + } + + // ----------------------------------------------------------------------------- + + Sequence< Reference< browse::XBrowseNode > > BasicProviderImpl::getChildNodes( ) throw (RuntimeException) + { + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + + Reference< script::XLibraryContainer > xLibContainer; + BasicManager* pBasicManager = NULL; + + if ( m_bIsAppScriptCtx ) + { + xLibContainer = m_xLibContainerApp; + pBasicManager = m_pAppBasicManager; + } + else + { + xLibContainer = m_xLibContainerDoc; + pBasicManager = m_pDocBasicManager; + } + + Sequence< Reference< browse::XBrowseNode > > aChildNodes; + + if ( pBasicManager && xLibContainer.is() ) + { + Sequence< ::rtl::OUString > aLibNames = xLibContainer->getElementNames(); + sal_Int32 nLibCount = aLibNames.getLength(); + const ::rtl::OUString* pLibNames = aLibNames.getConstArray(); + aChildNodes.realloc( nLibCount ); + Reference< browse::XBrowseNode >* pChildNodes = aChildNodes.getArray(); + sal_Int32 childsFound = 0; + + for ( sal_Int32 i = 0 ; i < nLibCount ; ++i ) + { + bool bCreate = false; + if ( m_bIsAppScriptCtx ) + { + bool bShared = isLibraryShared( xLibContainer, pLibNames[i] ); + if ( ( m_bIsUserCtx && !bShared ) || ( !m_bIsUserCtx && bShared ) ) + bCreate = true; + } + else + { + bCreate = true; + } + if ( bCreate ) + { + pChildNodes[childsFound++] = static_cast< browse::XBrowseNode* >( new BasicLibraryNodeImpl( + m_xContext, m_sScriptingContext, pBasicManager, xLibContainer, pLibNames[i], m_bIsAppScriptCtx ) ); + } + } + + if ( childsFound != nLibCount ) + aChildNodes.realloc( childsFound ); + } + + return aChildNodes; + } + + // ----------------------------------------------------------------------------- + + sal_Bool BasicProviderImpl::hasChildNodes( ) throw (RuntimeException) + { + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + + sal_Bool bReturn = sal_False; + Reference< script::XLibraryContainer > xLibContainer; + if ( m_bIsAppScriptCtx ) + { + xLibContainer = m_xLibContainerApp; + } + else + { + xLibContainer = m_xLibContainerDoc; + } + if ( xLibContainer.is() ) + bReturn = xLibContainer->hasElements(); + + return bReturn; + } + + // ----------------------------------------------------------------------------- + + sal_Int16 BasicProviderImpl::getType( ) throw (RuntimeException) + { + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + + return browse::BrowseNodeTypes::CONTAINER; + } + + // ============================================================================= + // component operations + // ============================================================================= + + static Reference< XInterface > SAL_CALL create_BasicProviderImpl( + Reference< XComponentContext > const & xContext ) + SAL_THROW( () ) + { + return static_cast< lang::XTypeProvider * >( new BasicProviderImpl( xContext ) ); + } + + // ----------------------------------------------------------------------------- + + static struct ::cppu::ImplementationEntry s_component_entries [] = + { + { + create_BasicProviderImpl, getImplementationName_BasicProviderImpl, + getSupportedServiceNames_BasicProviderImpl, ::cppu::createSingleComponentFactory, + 0, 0 + }, + { 0, 0, 0, 0, 0, 0 } + }; + + // ----------------------------------------------------------------------------- + +//......................................................................... +} // namespace basprov +//......................................................................... + + +// ============================================================================= +// component exports +// ============================================================================= + +extern "C" +{ + SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment( + const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv ) + { + (void)ppEnv; + + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; + } + + SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory( + const sal_Char * pImplName, lang::XMultiServiceFactory * pServiceManager, + registry::XRegistryKey * pRegistryKey ) + { + return ::cppu::component_getFactoryHelper( + pImplName, pServiceManager, pRegistryKey, ::basprov::s_component_entries ); + } +} diff --git a/scripting/source/basprov/basprov.hxx b/scripting/source/basprov/basprov.hxx new file mode 100644 index 000000000000..6cef4488fb43 --- /dev/null +++ b/scripting/source/basprov/basprov.hxx @@ -0,0 +1,115 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef SCRIPTING_BASPROV_HXX +#define SCRIPTING_BASPROV_HXX + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/script/XLibraryContainer.hpp> +#include <com/sun/star/script/browse/XBrowseNode.hpp> +#include <com/sun/star/script/provider/XScriptProvider.hpp> +#include <com/sun/star/document/XScriptInvocationContext.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <cppuhelper/implbase4.hxx> + +class BasicManager; + + +//......................................................................... +namespace basprov +{ +//......................................................................... + + // ---------------------------------------------------- + // class BasicProviderImpl + // ---------------------------------------------------- + + typedef ::cppu::WeakImplHelper4< + ::com::sun::star::lang::XServiceInfo, + ::com::sun::star::lang::XInitialization, + ::com::sun::star::script::provider::XScriptProvider, + ::com::sun::star::script::browse::XBrowseNode > BasicProviderImpl_BASE; + + + class BasicProviderImpl : public BasicProviderImpl_BASE + { + private: + BasicManager* m_pAppBasicManager; + BasicManager* m_pDocBasicManager; + ::com::sun::star::uno::Reference< ::com::sun::star::script::XLibraryContainer > m_xLibContainerApp; + ::com::sun::star::uno::Reference< ::com::sun::star::script::XLibraryContainer > m_xLibContainerDoc; + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext; + ::com::sun::star::uno::Reference< ::com::sun::star::document::XScriptInvocationContext > m_xInvocationContext; + ::rtl::OUString m_sScriptingContext; + bool m_bIsAppScriptCtx; + bool m_bIsUserCtx; + ::rtl::OUString m_sCtxLocation; + + bool isLibraryShared( + const ::com::sun::star::uno::Reference< ::com::sun::star::script::XLibraryContainer >& rxLibContainer, + const ::rtl::OUString& rLibName ); + + public: + BasicProviderImpl( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext ); + virtual ~BasicProviderImpl(); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName( ) + throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) + throw (::com::sun::star::uno::RuntimeException); + + // XInitialization + virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) + throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); + + // XScriptProvider + virtual ::com::sun::star::uno::Reference < ::com::sun::star::script::provider::XScript > SAL_CALL getScript( + const ::rtl::OUString& scriptURI ) + throw ( ::com::sun::star::script::provider::ScriptFrameworkErrorException, ::com::sun::star::uno::RuntimeException); + + // XBrowseNode + virtual ::rtl::OUString SAL_CALL getName( ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::script::browse::XBrowseNode > > SAL_CALL getChildNodes( ) + throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL hasChildNodes( ) + throw (::com::sun::star::uno::RuntimeException); + virtual sal_Int16 SAL_CALL getType( ) + throw (::com::sun::star::uno::RuntimeException); + }; + +//......................................................................... +} // namespace basprov +//......................................................................... + +#endif // SCRIPTING_BASPROV_HXX diff --git a/scripting/source/basprov/basprov.xml b/scripting/source/basprov/basprov.xml new file mode 100644 index 000000000000..0ae341cce157 --- /dev/null +++ b/scripting/source/basprov/basprov.xml @@ -0,0 +1,50 @@ +<?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>basprov</module-name> + + <component-description> + <author>Thomas Benisch</author> + <name>com.sun.star.comp.scripting.ScriptProviderForBasic</name> + <description>script provider for Basic</description> + <loader-name>com.sun.star.loader.SharedLibrary</loader-name> + <language>c++</language> + <status value="drafts"/> + <supported-service>com.sun.star.script.provider.ScriptProviderForBasic</supported-service> + <type>com.sun.star.beans.XPropertySet</type> + <type>com.sun.star.frame.XModel</type> + <type>com.sun.star.lang.IllegalArgumentException</type> + <type>com.sun.star.lang.XInitialization</type> + <type>com.sun.star.lang.XServiceInfo</type> + <type>com.sun.star.reflection.InvocationTargetException</type> + <type>com.sun.star.script.CannotConvertException</type> + <type>com.sun.star.uno.Exception</type> + <type>com.sun.star.uno.RuntimeException</type> + <type>com.sun.star.uno.XComponentContext</type> + <type>com.sun.star.script.browse.BrowseNodeTypes</type> + <type>com.sun.star.script.browse.XBrowseNode</type> + <type>com.sun.star.script.provider.XScript</type> + <type>com.sun.star.script.provider.XScriptProvider</type> + <type> com.sun.star.uri.XUriReference </type> + <type> com.sun.star.uri.XUriReferenceFactory </type> + <type> com.sun.star.uri.XVndSunStarScriptUrl </type> + </component-description> + + <project-build-dependency>sfx2</project-build-dependency> + <project-build-dependency>basic</project-build-dependency> + <project-build-dependency>svtools</project-build-dependency> + <project-build-dependency>tools</project-build-dependency> + <project-build-dependency>cppuhelper</project-build-dependency> + <project-build-dependency>cppu</project-build-dependency> + <project-build-dependency>sal</project-build-dependency> + + <runtime-module-dependency>sfx2</runtime-module-dependency> + <runtime-module-dependency>sb</runtime-module-dependency> + <runtime-module-dependency>svt</runtime-module-dependency> + <runtime-module-dependency>tl</runtime-module-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> diff --git a/scripting/source/basprov/basscript.cxx b/scripting/source/basprov/basscript.cxx new file mode 100644 index 000000000000..24bba1e7bff6 --- /dev/null +++ b/scripting/source/basprov/basscript.cxx @@ -0,0 +1,248 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_scripting.hxx" +#include "basscript.hxx" +#include <vos/mutex.hxx> +#include <vcl/svapp.hxx> +#include <basic/sbx.hxx> +#include <basic/sbstar.hxx> +#include <basic/sbmod.hxx> +#include <basic/sbmeth.hxx> +#include <basic/basmgr.hxx> +#include <com/sun/star/script/provider/ScriptFrameworkErrorType.hpp> + +#include <map> + + +using namespace ::com::sun::star; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::script; +using namespace ::com::sun::star::document; + +extern ::com::sun::star::uno::Any sbxToUnoValue( SbxVariable* pVar ); +extern void unoToSbxValue( SbxVariable* pVar, const ::com::sun::star::uno::Any& aValue ); + + +//......................................................................... +namespace basprov +{ +//......................................................................... + + typedef ::std::map< sal_Int16, Any, ::std::less< sal_Int16 > > OutParamMap; + + // ============================================================================= + // BasicScriptImpl + // ============================================================================= + + // ----------------------------------------------------------------------------- + + BasicScriptImpl::BasicScriptImpl( const ::rtl::OUString& funcName, SbMethodRef xMethod ) + :m_xMethod( xMethod ) + ,m_funcName( funcName ) + ,m_documentBasicManager( NULL ) + ,m_xDocumentScriptContext() + { + } + + // ----------------------------------------------------------------------------- + + BasicScriptImpl::BasicScriptImpl( const ::rtl::OUString& funcName, SbMethodRef xMethod, + BasicManager& documentBasicManager, const Reference< XScriptInvocationContext >& documentScriptContext ) + :m_xMethod( xMethod ) + ,m_funcName( funcName ) + ,m_documentBasicManager( &documentBasicManager ) + ,m_xDocumentScriptContext( documentScriptContext ) + { + StartListening( *m_documentBasicManager ); + } + + // ----------------------------------------------------------------------------- + BasicScriptImpl::~BasicScriptImpl() + { + if ( m_documentBasicManager ) + EndListening( *m_documentBasicManager ); + } + + // ----------------------------------------------------------------------------- + // SfxListener + // ----------------------------------------------------------------------------- + void BasicScriptImpl::Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) + { + if ( &rBC != m_documentBasicManager ) + { + OSL_ENSURE( false, "BasicScriptImpl::Notify: where does this come from?" ); + // not interested in + return; + } + const SfxSimpleHint* pSimpleHint = PTR_CAST( SfxSimpleHint, &rHint ); + if ( pSimpleHint && ( pSimpleHint->GetId() == SFX_HINT_DYING ) ) + { + m_documentBasicManager = NULL; + EndListening( rBC ); // prevent multiple notifications + } + } + + // ----------------------------------------------------------------------------- + // XScript + // ----------------------------------------------------------------------------- + + Any BasicScriptImpl::invoke( const Sequence< Any >& aParams, Sequence< sal_Int16 >& aOutParamIndex, Sequence< Any >& aOutParam ) + throw ( provider::ScriptFrameworkErrorException, reflection::InvocationTargetException, uno::RuntimeException) + { + // TODO: throw CannotConvertException + // TODO: check length of aOutParamIndex, aOutParam + + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + + Any aReturn; + + if ( m_xMethod ) + { + // check if compiled + SbModule* pModule = static_cast< SbModule* >( m_xMethod->GetParent() ); + if ( pModule && !pModule->IsCompiled() ) + pModule->Compile(); + + // check number of parameters + sal_Int32 nParamsCount = aParams.getLength(); + SbxInfo* pInfo = m_xMethod->GetInfo(); + if ( pInfo ) + { + sal_Int32 nSbxOptional = 0; + USHORT n = 1; + for ( const SbxParamInfo* pParamInfo = pInfo->GetParam( n ); pParamInfo; pParamInfo = pInfo->GetParam( ++n ) ) + { + if ( ( pParamInfo->nFlags & SBX_OPTIONAL ) != 0 ) + ++nSbxOptional; + else + nSbxOptional = 0; + } + sal_Int32 nSbxCount = n - 1; + if ( nParamsCount < nSbxCount - nSbxOptional ) + { + throw provider::ScriptFrameworkErrorException( + ::rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( + "wrong number of parameters!" ) ), + Reference< XInterface >(), + m_funcName, + ::rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( "Basic" ) ), + provider::ScriptFrameworkErrorType::NO_SUCH_SCRIPT ); + } + } + + // set parameters + SbxArrayRef xSbxParams; + if ( nParamsCount > 0 ) + { + xSbxParams = new SbxArray; + const Any* pParams = aParams.getConstArray(); + for ( sal_Int32 i = 0; i < nParamsCount; ++i ) + { + SbxVariableRef xSbxVar = new SbxVariable( SbxVARIANT ); + unoToSbxValue( static_cast< SbxVariable* >( xSbxVar ), pParams[i] ); + xSbxParams->Put( xSbxVar, static_cast< USHORT >( i ) + 1 ); + + // Enable passing by ref + if ( xSbxVar->GetType() != SbxVARIANT ) + xSbxVar->SetFlag( SBX_FIXED ); + } + } + if ( xSbxParams.Is() ) + m_xMethod->SetParameters( xSbxParams ); + + // call method + SbxVariableRef xReturn = new SbxVariable; + ErrCode nErr = SbxERR_OK; + { + // if it's a document-based script, temporarily reset ThisComponent to the script invocation context + Any aOldThisComponent; + if ( m_documentBasicManager && m_xDocumentScriptContext.is() ) + aOldThisComponent = m_documentBasicManager->SetGlobalUNOConstant( "ThisComponent", makeAny( m_xDocumentScriptContext ) ); + + nErr = m_xMethod->Call( xReturn ); + + if ( m_documentBasicManager && m_xDocumentScriptContext.is() ) + m_documentBasicManager->SetGlobalUNOConstant( "ThisComponent", aOldThisComponent ); + } + if ( nErr != SbxERR_OK ) + { + // TODO: throw InvocationTargetException ? + } + + // get output parameters + if ( xSbxParams.Is() ) + { + SbxInfo* pInfo_ = m_xMethod->GetInfo(); + if ( pInfo_ ) + { + OutParamMap aOutParamMap; + for ( USHORT n = 1, nCount = xSbxParams->Count(); n < nCount; ++n ) + { + const SbxParamInfo* pParamInfo = pInfo_->GetParam( n ); + if ( pParamInfo && ( pParamInfo->eType & SbxBYREF ) != 0 ) + { + SbxVariable* pVar = xSbxParams->Get( n ); + if ( pVar ) + { + SbxVariableRef xVar = pVar; + aOutParamMap.insert( OutParamMap::value_type( n - 1, sbxToUnoValue( xVar ) ) ); + } + } + } + sal_Int32 nOutParamCount = aOutParamMap.size(); + aOutParamIndex.realloc( nOutParamCount ); + aOutParam.realloc( nOutParamCount ); + sal_Int16* pOutParamIndex = aOutParamIndex.getArray(); + Any* pOutParam = aOutParam.getArray(); + for ( OutParamMap::iterator aIt = aOutParamMap.begin(); aIt != aOutParamMap.end(); ++aIt, ++pOutParamIndex, ++pOutParam ) + { + *pOutParamIndex = aIt->first; + *pOutParam = aIt->second; + } + } + } + + // get return value + aReturn = sbxToUnoValue( xReturn ); + + // reset parameters + m_xMethod->SetParameters( NULL ); + } + + return aReturn; + } + + // ----------------------------------------------------------------------------- + +//......................................................................... +} // namespace basprov +//......................................................................... diff --git a/scripting/source/basprov/basscript.hxx b/scripting/source/basprov/basscript.hxx new file mode 100644 index 000000000000..772a9166cde3 --- /dev/null +++ b/scripting/source/basprov/basscript.hxx @@ -0,0 +1,93 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef SCRIPTING_BASSCRIPT_HXX +#define SCRIPTING_BASSCRIPT_HXX + +#include <com/sun/star/script/provider/XScript.hpp> +#include <com/sun/star/document/XScriptInvocationContext.hpp> +#include <cppuhelper/implbase1.hxx> +#include <basic/sbmeth.hxx> +#include <svl/lstner.hxx> + + +class BasicManager; + +//......................................................................... +namespace basprov +{ +//......................................................................... + + // ---------------------------------------------------- + // class BasicScriptImpl + // ---------------------------------------------------- + + typedef ::cppu::WeakImplHelper1< + ::com::sun::star::script::provider::XScript > BasicScriptImpl_BASE; + + + class BasicScriptImpl : public BasicScriptImpl_BASE, public SfxListener + { + private: + SbMethodRef m_xMethod; + ::rtl::OUString m_funcName; + BasicManager* m_documentBasicManager; + ::com::sun::star::uno::Reference< ::com::sun::star::document::XScriptInvocationContext > + m_xDocumentScriptContext; + + public: + BasicScriptImpl( + const ::rtl::OUString& funcName, + SbMethodRef xMethod + ); + BasicScriptImpl( + const ::rtl::OUString& funcName, + SbMethodRef xMethod, + BasicManager& documentBasicManager, + const ::com::sun::star::uno::Reference< ::com::sun::star::document::XScriptInvocationContext >& documentScriptContext + ); + virtual ~BasicScriptImpl(); + + // XScript + virtual ::com::sun::star::uno::Any SAL_CALL invoke( + const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aParams, + ::com::sun::star::uno::Sequence< sal_Int16 >& aOutParamIndex, + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aOutParam ) + throw ( + ::com::sun::star::script::provider::ScriptFrameworkErrorException, + ::com::sun::star::reflection::InvocationTargetException, + ::com::sun::star::uno::RuntimeException ); + + // SfxListener + virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ); + }; + +//......................................................................... +} // namespace basprov +//......................................................................... + +#endif // SCRIPTING_BASSCRIPT_HXX diff --git a/scripting/source/basprov/makefile.mk b/scripting/source/basprov/makefile.mk new file mode 100644 index 000000000000..bde15f95d5a4 --- /dev/null +++ b/scripting/source/basprov/makefile.mk @@ -0,0 +1,82 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=scripting +TARGET=basprov +ENABLE_EXCEPTIONS=TRUE +VISIBILITY_HIDDEN=TRUE +COMP1TYPELIST=$(TARGET) + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk +DLLPRE = + +# ------------------------------------------------------------------ + +SLOFILES= \ + $(SLO)$/basprov.obj \ + $(SLO)$/basscript.obj \ + $(SLO)$/baslibnode.obj \ + $(SLO)$/basmodnode.obj \ + $(SLO)$/basmethnode.obj + +SHL1TARGET= $(TARGET)$(DLLPOSTFIX).uno +SHL1IMPLIB= i$(TARGET) + +SHL1VERSIONMAP=$(SOLARENV)/src/component.map +SHL1DEF=$(MISC)$/$(SHL1TARGET).def +DEF1NAME=$(SHL1TARGET) + +SHL1STDLIBS= \ + $(SFX2LIB) \ + $(BASICLIB) \ + $(VCLLIB) \ + $(SVLLIB) \ + $(TOOLSLIB) \ + $(UCBHELPERLIB) \ + $(COMPHELPERLIB) \ + $(CPPUHELPERLIB) \ + $(CPPULIB) \ + $(SALLIB) + +SHL1DEPN= +SHL1LIBS=$(SLB)$/$(TARGET).lib + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + +ALLTAR : $(MISC)/basprov.component + +$(MISC)/basprov.component .ERRREMOVE : $(SOLARENV)/bin/createcomponent.xslt \ + basprov.component + $(XSLTPROC) --nonet --stringparam uri \ + '$(COMPONENTPREFIX_BASIS_NATIVE)$(SHL1TARGETN:f)' -o $@ \ + $(SOLARENV)/bin/createcomponent.xslt basprov.component |