diff options
Diffstat (limited to 'scripting/source/dlgprov')
-rw-r--r-- | scripting/source/dlgprov/dlgevtatt.cxx | 679 | ||||
-rw-r--r-- | scripting/source/dlgprov/dlgevtatt.hxx | 164 | ||||
-rw-r--r-- | scripting/source/dlgprov/dlgprov.cxx | 870 | ||||
-rw-r--r-- | scripting/source/dlgprov/dlgprov.hxx | 157 | ||||
-rw-r--r-- | scripting/source/dlgprov/dlgprov.xml | 58 | ||||
-rw-r--r-- | scripting/source/dlgprov/makefile.mk | 82 |
6 files changed, 2010 insertions, 0 deletions
diff --git a/scripting/source/dlgprov/dlgevtatt.cxx b/scripting/source/dlgprov/dlgevtatt.cxx new file mode 100644 index 000000000000..6c3694ea237d --- /dev/null +++ b/scripting/source/dlgprov/dlgevtatt.cxx @@ -0,0 +1,679 @@ +/************************************************************************* + * + * 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 "dlgevtatt.hxx" + +#include "dlgprov.hxx" + +#include <sfx2/sfx.hrc> +#include <sfx2/app.hxx> +#include <vcl/msgbox.hxx> +#include <tools/diagnose_ex.h> + +#include <com/sun/star/awt/XControl.hpp> +#include <com/sun/star/awt/XDialogEventHandler.hpp> +#include <com/sun/star/awt/XContainerWindowEventHandler.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/script/ScriptEventDescriptor.hpp> +#include <com/sun/star/script/XScriptEventsSupplier.hpp> +#include <com/sun/star/script/provider/XScriptProvider.hpp> +#include <com/sun/star/script/provider/XScriptProviderFactory.hpp> +#include <com/sun/star/script/provider/XScriptProviderSupplier.hpp> +#include <com/sun/star/lang/NoSuchMethodException.hpp> +#include <com/sun/star/reflection/XIdlMethod.hpp> +#include <com/sun/star/beans/MethodConcept.hpp> +#include <com/sun/star/beans/XMaterialHolder.hpp> + +#include <ooo/vba/XVBAToOOEventDescGen.hpp> +#include <com/sun/star/lang/XUnoTunnel.hpp> +#include <vbahelper/vbaaccesshelper.hxx> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::awt; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::script; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::script; +using namespace ::com::sun::star::reflection; + + +//......................................................................... +namespace dlgprov +{ + + class DialogSFScriptListenerImpl : public DialogScriptListenerImpl + { + protected: + Reference< frame::XModel > m_xModel; + virtual void firing_impl( const script::ScriptEvent& aScriptEvent, uno::Any* pRet ); + public: + DialogSFScriptListenerImpl( const Reference< XComponentContext >& rxContext, const Reference< frame::XModel >& rxModel ) : DialogScriptListenerImpl( rxContext ), m_xModel( rxModel ) {} + }; + + class DialogLegacyScriptListenerImpl : public DialogSFScriptListenerImpl + { + protected: + virtual void firing_impl( const script::ScriptEvent& aScriptEvent, uno::Any* pRet ); + public: + DialogLegacyScriptListenerImpl( const Reference< XComponentContext >& rxContext, const Reference< frame::XModel >& rxModel ) : DialogSFScriptListenerImpl( rxContext, rxModel ){} + }; + + class DialogUnoScriptListenerImpl : public DialogSFScriptListenerImpl + { + Reference< awt::XControl > m_xControl; + Reference< XInterface > m_xHandler; + Reference< beans::XIntrospectionAccess > m_xIntrospectionAccess; + bool m_bDialogProviderMode; + + virtual void firing_impl( const script::ScriptEvent& aScriptEvent, uno::Any* pRet ); + + public: + DialogUnoScriptListenerImpl( const Reference< XComponentContext >& rxContext, + const Reference< frame::XModel >& rxModel, + const Reference< awt::XControl >& rxControl, + const Reference< XInterface >& rxHandler, + const Reference< beans::XIntrospectionAccess >& rxIntrospectionAccess, + bool bDialogProviderMode ); // false: ContainerWindowProvider mode + + }; + + class DialogVBAScriptListenerImpl : public DialogScriptListenerImpl + { + protected: + rtl::OUString msDialogCodeName; + 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::DialogVBAScriptListenerImpl( const Reference< XComponentContext >& rxContext, const Reference< awt::XControl >& rxControl, const Reference< frame::XModel >& xModel ) : DialogScriptListenerImpl( rxContext ) + { + Reference< XMultiComponentFactory > xSMgr( m_xContext->getServiceManager() ); + Sequence< Any > args(1); + if ( xSMgr.is() ) + { + args[0] <<= xModel; + mxListener = Reference< XScriptListener >( xSMgr->createInstanceWithArgumentsAndContext( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.EventListener" ) ), args, m_xContext ), UNO_QUERY ); + } + if ( rxControl.is() ) + { + try + { + Reference< XPropertySet > xProps( rxControl->getModel(), UNO_QUERY_THROW ); + xProps->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name") ) ) >>= msDialogCodeName; + xProps.set( mxListener, UNO_QUERY_THROW ); + xProps->setPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Model") ), args[ 0 ] ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + } + + } + + void DialogVBAScriptListenerImpl::firing_impl( const script::ScriptEvent& aScriptEvent, uno::Any* ) + { + if ( aScriptEvent.ScriptType.equals( rtl::OUString::createFromAscii("VBAInterop") ) && mxListener.is() ) + { + ScriptEvent aScriptEventCopy( aScriptEvent ); + aScriptEventCopy.ScriptCode = msDialogCodeName; + try + { + mxListener->firing( aScriptEventCopy ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + } + } + +//......................................................................... + + // ============================================================================= + // 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 ) + :mbUseFakeVBAEvents( false ), m_xContext( rxContext ) + { + // key listeners by protocol when ScriptType = 'Script' + // otherwise key is the ScriptType e.g. StarBasic + if ( rxRTLListener.is() ) // set up handler for RTL_BASIC + listernersForTypes[ rtl::OUString::createFromAscii("StarBasic") ] = rxRTLListener; + else + listernersForTypes[ rtl::OUString::createFromAscii("StarBasic") ] = new DialogLegacyScriptListenerImpl( rxContext, rxModel ); + // handler for Script & ::rtl::OUString::createFromAscii( "vnd.sun.star.UNO:" ) + listernersForTypes[ rtl::OUString::createFromAscii("vnd.sun.star.UNO") ] = new DialogUnoScriptListenerImpl( rxContext, rxModel, rxControl, rxHandler, rxIntrospect, bProviderMode ); + listernersForTypes[ rtl::OUString::createFromAscii("vnd.sun.star.script") ] = new DialogSFScriptListenerImpl( rxContext, rxModel ); + // Note: in a future cws ( npower13_ObjectModule ) it will be possible + // to determine the vba mode from the basiclibrary container, the tunnel hack + // below can then be replaced + SfxObjectShell* pFoundShell = NULL; + if ( rxModel.is() ) + { + uno::Reference< lang::XUnoTunnel > xObjShellTunnel( rxModel, uno::UNO_QUERY ); + if ( xObjShellTunnel.is() ) + { + pFoundShell = reinterpret_cast<SfxObjectShell*>( xObjShellTunnel->getSomething(SfxObjectShell::getUnoTunnelId())); + if ( pFoundShell ) + mbUseFakeVBAEvents = ooo::vba::isAlienExcelDoc( *pFoundShell ); + } + } + if ( mbUseFakeVBAEvents ) + listernersForTypes[ rtl::OUString::createFromAscii("VBAInterop") ] = new DialogVBAScriptListenerImpl( rxContext, rxControl, rxModel ); + } + + // ----------------------------------------------------------------------------- + + DialogEventsAttacherImpl::~DialogEventsAttacherImpl() + { + } + + // ----------------------------------------------------------------------------- + Reference< script::XScriptListener > + DialogEventsAttacherImpl::getScriptListenerForKey( const rtl::OUString& sKey ) throw ( RuntimeException ) + { + ListenerHash::iterator it = listernersForTypes.find( sKey ); + if ( it == listernersForTypes.end() ) + throw RuntimeException(); // more text info here please + return it->second; + } + Reference< XScriptEventsSupplier > DialogEventsAttacherImpl::getFakeVbaEventsSupplier( const Reference< XControl >& xControl, rtl::OUString& sControlName ) + { + Reference< XScriptEventsSupplier > xEventsSupplier; + Reference< XMultiComponentFactory > xSMgr( m_xContext->getServiceManager() ); + if ( xSMgr.is() ) + { + 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; + } + + // ----------------------------------------------------------------------------- + void SAL_CALL DialogEventsAttacherImpl::attachEventsToControl( const Reference< XControl>& xControl, const Reference< XScriptEventsSupplier >& xEventsSupplier, const Any& Helper ) + { + if ( xEventsSupplier.is() ) + { + Reference< container::XNameContainer > xEventCont = xEventsSupplier->getEvents(); + + Reference< XControlModel > xControlModel = xControl->getModel(); + if ( xEventCont.is() ) + { + Sequence< ::rtl::OUString > aNames = xEventCont->getElementNames(); + const ::rtl::OUString* pNames = aNames.getConstArray(); + sal_Int32 nNameCount = aNames.getLength(); + + for ( sal_Int32 j = 0; j < nNameCount; ++j ) + { + ScriptEventDescriptor aDesc; + + Any aElement = xEventCont->getByName( pNames[ j ] ); + aElement >>= aDesc; + rtl::OUString sKey = aDesc.ScriptType; + if ( aDesc.ScriptType.equals( rtl::OUString::createFromAscii("Script" ) ) || aDesc.ScriptType.equals( rtl::OUString::createFromAscii("UNO" ) ) ) + { + sal_Int32 nIndex = aDesc.ScriptCode.indexOf( ':' ); + sKey = aDesc.ScriptCode.copy( 0, nIndex ); + } + Reference< XAllListener > xAllListener = + new DialogAllListenerImpl( getScriptListenerForKey( sKey ), aDesc.ScriptType, aDesc.ScriptCode ); + + // try first to attach event to the ControlModel + bool bSuccess = false; + try + { + Reference< XEventListener > xListener_ = m_xEventAttacher->attachSingleEventListener( + xControlModel, xAllListener, Helper, aDesc.ListenerType, + aDesc.AddListenerParam, aDesc.EventMethod ); + + if ( xListener_.is() ) + bSuccess = true; + } + catch ( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + + try + { + // if we had no success, try to attach to the control + if ( !bSuccess ) + { + Reference< XEventListener > xListener_ = m_xEventAttacher->attachSingleEventListener( + xControl, xAllListener, Helper, aDesc.ListenerType, + aDesc.AddListenerParam, aDesc.EventMethod ); + } + } + catch ( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + } + } + } + } + + // ----------------------------------------------------------------------------- + // XScriptEventsAttacher + // ----------------------------------------------------------------------------- + + void SAL_CALL DialogEventsAttacherImpl::attachEvents( const Sequence< Reference< XInterface > >& Objects, + const com::sun::star::uno::Reference<com::sun::star::script::XScriptListener>&, + const Any& Helper ) + throw (IllegalArgumentException, IntrospectionException, CannotCreateAdapterException, + ServiceNotRegisteredException, RuntimeException) + { + // get EventAttacher + { + ::osl::MutexGuard aGuard( getMutex() ); + + if ( !m_xEventAttacher.is() ) + { + Reference< XMultiComponentFactory > xSMgr( m_xContext->getServiceManager() ); + if ( xSMgr.is() ) + { + m_xEventAttacher = Reference< XEventAttacher >( xSMgr->createInstanceWithContext( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.script.EventAttacher" ) ), m_xContext ), UNO_QUERY ); + + if ( !m_xEventAttacher.is() ) + throw ServiceNotRegisteredException(); + } + else + { + throw RuntimeException(); + } + + } + } + + // go over all objects + const Reference< XInterface >* pObjects = Objects.getConstArray(); + sal_Int32 nObjCount = Objects.getLength(); + Reference< awt::XControl > xDlgControl( Objects[ nObjCount - 1 ], uno::UNO_QUERY ); // last object is the dialog + rtl::OUString sDialogCodeName; + if ( xDlgControl.is() ) + { + Reference< XPropertySet > xProps( xDlgControl->getModel(), UNO_QUERY ); + try + { + xProps->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name") ) ) >>= sDialogCodeName; + } + catch( Exception& ){} + } + + for ( sal_Int32 i = 0; i < nObjCount; ++i ) + { + // We know that we have to do with instances of XControl. + // Otherwise this is not the right implementation for + // XScriptEventsAttacher and we have to give up. + Reference< XControl > xControl( pObjects[ i ], UNO_QUERY ); + if ( !xControl.is() ) + throw IllegalArgumentException(); + + // get XEventsSupplier from control model + Reference< XControlModel > xControlModel = xControl->getModel(); + Reference< XScriptEventsSupplier > xEventsSupplier( xControlModel, UNO_QUERY ); + attachEventsToControl( xControl, xEventsSupplier, Helper ); + if ( mbUseFakeVBAEvents ) + { + xEventsSupplier.set( getFakeVbaEventsSupplier( xControl, sDialogCodeName ) ); + attachEventsToControl( xControl, xEventsSupplier, Helper ); + } + } + } + + + // ============================================================================= + // DialogAllListenerImpl + // ============================================================================= + + DialogAllListenerImpl::DialogAllListenerImpl( const Reference< XScriptListener >& rxListener, + const ::rtl::OUString& rScriptType, const ::rtl::OUString& rScriptCode ) + :m_xScriptListener( rxListener ) + ,m_sScriptType( rScriptType ) + ,m_sScriptCode( rScriptCode ) + { + } + + // ----------------------------------------------------------------------------- + + DialogAllListenerImpl::~DialogAllListenerImpl() + { + } + + // ----------------------------------------------------------------------------- + + void DialogAllListenerImpl::firing_impl( const AllEventObject& Event, Any* pRet ) + { + ScriptEvent aScriptEvent; + aScriptEvent.Source = (OWeakObject *)this; // get correct XInterface + aScriptEvent.ListenerType = Event.ListenerType; + aScriptEvent.MethodName = Event.MethodName; + aScriptEvent.Arguments = Event.Arguments; + aScriptEvent.Helper = Event.Helper; + aScriptEvent.ScriptType = m_sScriptType; + aScriptEvent.ScriptCode = m_sScriptCode; + + if ( m_xScriptListener.is() ) + { + if ( pRet ) + *pRet = m_xScriptListener->approveFiring( aScriptEvent ); + else + m_xScriptListener->firing( aScriptEvent ); + } + } + + // ----------------------------------------------------------------------------- + // XEventListener + // ----------------------------------------------------------------------------- + + void DialogAllListenerImpl::disposing(const EventObject& ) throw ( RuntimeException ) + { + } + + // ----------------------------------------------------------------------------- + // XAllListener + // ----------------------------------------------------------------------------- + + void DialogAllListenerImpl::firing( const AllEventObject& Event ) throw ( RuntimeException ) + { + ::osl::MutexGuard aGuard( getMutex() ); + + firing_impl( Event, NULL ); + } + + // ----------------------------------------------------------------------------- + + Any DialogAllListenerImpl::approveFiring( const AllEventObject& Event ) + throw ( reflection::InvocationTargetException, RuntimeException ) + { + ::osl::MutexGuard aGuard( getMutex() ); + + Any aReturn; + firing_impl( Event, &aReturn ); + return aReturn; + } + + + // ============================================================================= + // DialogScriptListenerImpl + // ============================================================================= + + DialogUnoScriptListenerImpl::DialogUnoScriptListenerImpl( const Reference< XComponentContext >& rxContext, + const Reference< ::com::sun::star::frame::XModel >& rxModel, + const Reference< ::com::sun::star::awt::XControl >& rxControl, + const Reference< ::com::sun::star::uno::XInterface >& rxHandler, + const Reference< ::com::sun::star::beans::XIntrospectionAccess >& rxIntrospectionAccess, + bool bDialogProviderMode ) + : DialogSFScriptListenerImpl( rxContext, rxModel ) + ,m_xControl( rxControl ) + ,m_xHandler( rxHandler ) + ,m_xIntrospectionAccess( rxIntrospectionAccess ) + ,m_bDialogProviderMode( bDialogProviderMode ) + { + } + + // ----------------------------------------------------------------------------- + + DialogScriptListenerImpl::~DialogScriptListenerImpl() + { + } + + // ----------------------------------------------------------------------------- + void DialogSFScriptListenerImpl::firing_impl( const ScriptEvent& aScriptEvent, Any* pRet ) + { + try + { + Reference< provider::XScriptProvider > xScriptProvider; + if ( m_xModel.is() ) + { + Reference< provider::XScriptProviderSupplier > xSupplier( m_xModel, UNO_QUERY ); + OSL_ENSURE( xSupplier.is(), "DialogScriptListenerImpl::firing_impl: failed to get script provider supplier" ); + if ( xSupplier.is() ) + xScriptProvider.set( xSupplier->getScriptProvider() ); + } + else + { + OSL_ASSERT( m_xContext.is() ); + if ( m_xContext.is() ) + { + Reference< provider::XScriptProviderFactory > xFactory( + m_xContext->getValueByName( + ::rtl::OUString::createFromAscii( "/singletons/com.sun.star.script.provider.theMasterScriptProviderFactory" ) ), + UNO_QUERY ); + OSL_ENSURE( xFactory.is(), "SFURL_firing_impl: failed to get master script provider factory" ); + if ( xFactory.is() ) + { + Any aCtx; + aCtx <<= ::rtl::OUString::createFromAscii( "user" ); + xScriptProvider.set( xFactory->createScriptProvider( aCtx ), UNO_QUERY ); + } + } + } + + OSL_ENSURE( xScriptProvider.is(), "DialogScriptListenerImpl::firing_impl: failed to get script provider" ); + + if ( xScriptProvider.is() ) + { + Reference< provider::XScript > xScript = xScriptProvider->getScript( aScriptEvent.ScriptCode ); + OSL_ENSURE( xScript.is(), "DialogScriptListenerImpl::firing_impl: failed to get script" ); + + if ( xScript.is() ) + { + Sequence< Any > aInParams; + Sequence< sal_Int16 > aOutParamsIndex; + Sequence< Any > aOutParams; + + // get arguments for script + aInParams = aScriptEvent.Arguments; + + Any aResult = xScript->invoke( aInParams, aOutParamsIndex, aOutParams ); + if ( pRet ) + *pRet = aResult; + } + } + } + catch ( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + } + + void DialogLegacyScriptListenerImpl::firing_impl( const ScriptEvent& aScriptEvent, Any* pRet ) + { + ::rtl::OUString sScriptURL; + ::rtl::OUString sScriptCode( aScriptEvent.ScriptCode ); + + if ( aScriptEvent.ScriptType.compareToAscii( "StarBasic" ) == 0 ) + { + // StarBasic script: convert ScriptCode to scriptURL + sal_Int32 nIndex = sScriptCode.indexOf( ':' ); + if ( nIndex >= 0 && nIndex < sScriptCode.getLength() ) + { + sScriptURL = ::rtl::OUString::createFromAscii( "vnd.sun.star.script:" ); + sScriptURL += sScriptCode.copy( nIndex + 1 ); + sScriptURL += ::rtl::OUString::createFromAscii( "?language=Basic&location=" ); + sScriptURL += sScriptCode.copy( 0, nIndex ); + } + ScriptEvent aSFScriptEvent( aScriptEvent ); + aSFScriptEvent.ScriptCode = sScriptURL; + DialogSFScriptListenerImpl::firing_impl( aSFScriptEvent, pRet ); + } + } + + void DialogUnoScriptListenerImpl::firing_impl( const ScriptEvent& aScriptEvent, Any* pRet ) + { + static ::rtl::OUString sUnoURLScheme = ::rtl::OUString::createFromAscii( "vnd.sun.star.UNO:" ); + + ::rtl::OUString sScriptCode( aScriptEvent.ScriptCode ); + ::rtl::OUString aMethodName = aScriptEvent.ScriptCode.copy( sUnoURLScheme.getLength() ); + + const Any* pArguments = aScriptEvent.Arguments.getConstArray(); + Any aEventObject = pArguments[0]; + + bool bHandled = false; + if( m_xHandler.is() ) + { + if( m_bDialogProviderMode ) + { + Reference< XDialogEventHandler > xDialogEventHandler( m_xHandler, UNO_QUERY ); + if( xDialogEventHandler.is() ) + { + Reference< XDialog > xDialog( m_xControl, UNO_QUERY ); + bHandled = xDialogEventHandler->callHandlerMethod( xDialog, aEventObject, aMethodName ); + } + } + else + { + Reference< XContainerWindowEventHandler > xContainerWindowEventHandler( m_xHandler, UNO_QUERY ); + if( xContainerWindowEventHandler.is() ) + { + Reference< XWindow > xWindow( m_xControl, UNO_QUERY ); + bHandled = xContainerWindowEventHandler->callHandlerMethod( xWindow, aEventObject, aMethodName ); + } + } + } + + Any aRet; + if( !bHandled && m_xIntrospectionAccess.is() ) + { + try + { + // Methode ansprechen + const Reference< XIdlMethod >& rxMethod = m_xIntrospectionAccess-> + getMethod( aMethodName, MethodConcept::ALL - MethodConcept::DANGEROUS ); + + Reference< XMaterialHolder > xMaterialHolder = + Reference< XMaterialHolder >::query( m_xIntrospectionAccess ); + Any aHandlerObject = xMaterialHolder->getMaterial(); + + Sequence< Reference< XIdlClass > > aParamTypeSeq = rxMethod->getParameterTypes(); + sal_Int32 nParamCount = aParamTypeSeq.getLength(); + if( nParamCount == 0 ) + { + Sequence<Any> args; + rxMethod->invoke( aHandlerObject, args ); + bHandled = true; + } + else if( nParamCount == 2 ) + { + // Signature check automatically done by reflection + Sequence<Any> Args(2); + Any* pArgs = Args.getArray(); + if( m_bDialogProviderMode ) + { + Reference< XDialog > xDialog( m_xControl, UNO_QUERY ); + pArgs[0] <<= xDialog; + } + else + { + Reference< XWindow > xWindow( m_xControl, UNO_QUERY ); + pArgs[0] <<= xWindow; + } + pArgs[1] = aEventObject; + aRet = rxMethod->invoke( aHandlerObject, Args ); + bHandled = true; + } + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + } + + if( bHandled ) + { + if( pRet ) + *pRet = aRet; + } + else + { + ResMgr* pResMgr = SFX_APP()->GetSfxResManager(); + if( pResMgr ) + { + String aRes( ResId(STR_ERRUNOEVENTBINDUNG, *pResMgr) ); + ::rtl::OUString aQuoteChar( RTL_CONSTASCII_USTRINGPARAM( "\"" ) ); + + ::rtl::OUString aOURes = aRes; + sal_Int32 nIndex = aOURes.indexOf( '%' ); + + ::rtl::OUString aOUFinal; + aOUFinal += aOURes.copy( 0, nIndex ); + aOUFinal += aQuoteChar; + aOUFinal += aMethodName; + aOUFinal += aQuoteChar; + aOUFinal += aOURes.copy( nIndex + 2 ); + + ErrorBox( NULL, WinBits( WB_OK ), aOUFinal ).Execute(); + } + } + } + + // ----------------------------------------------------------------------------- + // XEventListener + // ----------------------------------------------------------------------------- + + void DialogScriptListenerImpl::disposing(const EventObject& ) throw ( RuntimeException ) + { + } + + // ----------------------------------------------------------------------------- + // XScriptListener + // ----------------------------------------------------------------------------- + + void DialogScriptListenerImpl::firing( const ScriptEvent& aScriptEvent ) throw ( RuntimeException ) + { + ::osl::MutexGuard aGuard( getMutex() ); + + firing_impl( aScriptEvent, NULL ); + } + + // ----------------------------------------------------------------------------- + + Any DialogScriptListenerImpl::approveFiring( const ScriptEvent& aScriptEvent ) + throw ( reflection::InvocationTargetException, RuntimeException ) + { + ::osl::MutexGuard aGuard( getMutex() ); + + Any aReturn; + firing_impl( aScriptEvent, &aReturn ); + return aReturn; + } + + // ----------------------------------------------------------------------------- + +//......................................................................... +} // namespace dlgprov +//......................................................................... diff --git a/scripting/source/dlgprov/dlgevtatt.hxx b/scripting/source/dlgprov/dlgevtatt.hxx new file mode 100644 index 000000000000..85b0bfcd087d --- /dev/null +++ b/scripting/source/dlgprov/dlgevtatt.hxx @@ -0,0 +1,164 @@ +/************************************************************************* + * + * 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_DLGEVTATT_HXX +#define SCRIPTING_DLGEVTATT_HXX + +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/script/XAllListener.hpp> +#include <com/sun/star/script/XEventAttacher.hpp> +#include <com/sun/star/script/XScriptEventsAttacher.hpp> +#include <com/sun/star/script/XScriptListener.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/awt/XControl.hpp> +#ifndef _COM_SUN_STAR_BEANS_XINTROSPECTION_HPP_ +#include <com/sun/star/beans/XIntrospectionAccess.hpp> +#endif +#include <cppuhelper/implbase1.hxx> + +#include <com/sun/star/script/XScriptEventsSupplier.hpp> + +#include <hash_map> + +//......................................................................... +namespace dlgprov +{ +//......................................................................... + + // ============================================================================= + // class DialogEventsAttacherImpl + // ============================================================================= + typedef std::hash_map< rtl::OUString, + ::com::sun::star::uno::Reference< ::com::sun::star::script::XScriptListener >, + ::rtl::OUStringHash, + ::std::equal_to< ::rtl::OUString > > ListenerHash; + + typedef ::cppu::WeakImplHelper1< + ::com::sun::star::script::XScriptEventsAttacher > DialogEventsAttacherImpl_BASE; + + + class DialogEventsAttacherImpl : public DialogEventsAttacherImpl_BASE + { + private: + bool mbUseFakeVBAEvents; + ListenerHash listernersForTypes; + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext; + ::com::sun::star::uno::Reference< ::com::sun::star::script::XEventAttacher > m_xEventAttacher; + ::com::sun::star::uno::Reference< ::com::sun::star::script::XScriptListener > getScriptListenerForKey( const rtl::OUString& sScriptName ) throw ( ::com::sun::star::uno::RuntimeException ); + ::com::sun::star::uno::Reference< ::com::sun::star::script::XScriptEventsSupplier > getFakeVbaEventsSupplier( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl>& xControl, rtl::OUString& sCodeName ); + void SAL_CALL attachEventsToControl( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl>& xControl, const ::com::sun::star::uno::Reference< ::com::sun::star::script::XScriptEventsSupplier >& events, const ::com::sun::star::uno::Any& Helper ); + public: + DialogEventsAttacherImpl( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xModel, + const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& xControl, + 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 ); + virtual ~DialogEventsAttacherImpl(); + + // XScriptEventsAttacher + virtual void SAL_CALL attachEvents( const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > >& Objects, + const com::sun::star::uno::Reference<com::sun::star::script::XScriptListener>&, + const ::com::sun::star::uno::Any& Helper ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::beans::IntrospectionException, + ::com::sun::star::script::CannotCreateAdapterException, + ::com::sun::star::lang::ServiceNotRegisteredException, + ::com::sun::star::uno::RuntimeException); + }; + + + // ============================================================================= + // class DialogAllListenerImpl + // ============================================================================= + + typedef ::cppu::WeakImplHelper1< + ::com::sun::star::script::XAllListener > DialogAllListenerImpl_BASE; + + + class DialogAllListenerImpl : public DialogAllListenerImpl_BASE + { + private: + ::com::sun::star::uno::Reference< ::com::sun::star::script::XScriptListener > m_xScriptListener; + ::rtl::OUString m_sScriptType; + ::rtl::OUString m_sScriptCode; + + virtual void firing_impl( const ::com::sun::star::script::AllEventObject& Event, ::com::sun::star::uno::Any* pRet ); + + public: + DialogAllListenerImpl( const ::com::sun::star::uno::Reference< ::com::sun::star::script::XScriptListener >& rxListener, + const ::rtl::OUString& rScriptType, const ::rtl::OUString& rScriptCode ); + virtual ~DialogAllListenerImpl(); + + // XEventListener + virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) + throw (::com::sun::star::uno::RuntimeException); + + // XAllListener + virtual void SAL_CALL firing( const ::com::sun::star::script::AllEventObject& Event ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Any SAL_CALL approveFiring( const ::com::sun::star::script::AllEventObject& Event ) + throw (::com::sun::star::reflection::InvocationTargetException, ::com::sun::star::uno::RuntimeException); + }; + + + // ============================================================================= + // class DialogScriptListenerImpl + // ============================================================================= + + typedef ::cppu::WeakImplHelper1< + ::com::sun::star::script::XScriptListener > DialogScriptListenerImpl_BASE; + + + class DialogScriptListenerImpl : public DialogScriptListenerImpl_BASE + { + protected: + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext; + virtual void firing_impl( const ::com::sun::star::script::ScriptEvent& aScriptEvent, ::com::sun::star::uno::Any* pRet ) = 0; + public: + DialogScriptListenerImpl( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext ) : m_xContext( rxContext ) {} + virtual ~DialogScriptListenerImpl(); + + // XEventListener + virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) + throw (::com::sun::star::uno::RuntimeException); + + // XScriptListener + virtual void SAL_CALL firing( const ::com::sun::star::script::ScriptEvent& aScriptEvent ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Any SAL_CALL approveFiring( const ::com::sun::star::script::ScriptEvent& aScriptEvent ) + throw (::com::sun::star::reflection::InvocationTargetException, ::com::sun::star::uno::RuntimeException); + }; + + +//......................................................................... +} // namespace dlgprov +//......................................................................... + +#endif // SCRIPTING_DLGEVT_HXX diff --git a/scripting/source/dlgprov/dlgprov.cxx b/scripting/source/dlgprov/dlgprov.cxx new file mode 100644 index 000000000000..0fc0778c71d9 --- /dev/null +++ b/scripting/source/dlgprov/dlgprov.cxx @@ -0,0 +1,870 @@ +/************************************************************************* + * + * 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 "dlgprov.hxx" +#include "dlgevtatt.hxx" +#include <com/sun/star/awt/XControlContainer.hpp> +#include <com/sun/star/awt/XWindowPeer.hpp> +#include <com/sun/star/io/XInputStreamProvider.hpp> +#include <com/sun/star/lang/XMultiComponentFactory.hpp> +#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> +#include <com/sun/star/script/XLibraryContainer.hpp> +#include <cppuhelper/implementationentry.hxx> +#include <cppuhelper/exc_hlp.hxx> +#include <com/sun/star/beans/XIntrospection.hpp> +#include <com/sun/star/resource/XStringResourceSupplier.hpp> +#include <com/sun/star/resource/XStringResourceManager.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/ucb/XSimpleFileAccess.hpp> +#include <com/sun/star/resource/XStringResourceWithLocation.hpp> +#include <com/sun/star/document/XEmbeddedScripts.hpp> +#include <sfx2/app.hxx> +#include <sfx2/objsh.hxx> +#include <xmlscript/xmldlg_imexp.hxx> +#include <tools/urlobj.hxx> +#include <comphelper/namedvaluecollection.hxx> + +#include <com/sun/star/uri/XUriReference.hpp> +#include <com/sun/star/uri/XUriReferenceFactory.hpp> +#include <com/sun/star/uri/XVndSunStarScriptUrl.hpp> +#include <com/sun/star/uri/XVndSunStarExpandUrl.hpp> +#include <com/sun/star/util/XMacroExpander.hpp> + +#include <util/MiscUtils.hxx> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::awt; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::script; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::document; +using namespace ::sf_misc; + +//......................................................................... +namespace dlgprov +{ +//......................................................................... + +static ::rtl::OUString aResourceResolverPropName = ::rtl::OUString::createFromAscii( "ResourceResolver" ); + // ============================================================================= + // component operations + // ============================================================================= + + static ::rtl::OUString getImplementationName_DialogProviderImpl() + { + 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.DialogProvider" ) ); + pImplName = &aImplName; + } + } + return *pImplName; + } + + // ----------------------------------------------------------------------------- + + static Sequence< ::rtl::OUString > getSupportedServiceNames_DialogProviderImpl() + { + static Sequence< ::rtl::OUString >* pNames = 0; + if ( !pNames ) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if ( !pNames ) + { + static Sequence< ::rtl::OUString > aNames(3); + aNames.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.DialogProvider" ) ); + aNames.getArray()[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.DialogProvider2" ) ); + aNames.getArray()[2] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.ContainerWindowProvider" ) ); + pNames = &aNames; + } + } + return *pNames; + } + + + // ============================================================================= + // mutex + // ============================================================================= + + ::osl::Mutex& getMutex() + { + static ::osl::Mutex* s_pMutex = 0; + if ( !s_pMutex ) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if ( !s_pMutex ) + { + static ::osl::Mutex s_aMutex; + s_pMutex = &s_aMutex; + } + } + return *s_pMutex; + } + + + // ============================================================================= + // DialogProviderImpl + // ============================================================================= + + DialogProviderImpl::DialogProviderImpl( const Reference< XComponentContext >& rxContext ) + :m_xContext( rxContext ) + ,m_xModel( 0 ) + { + } + + // ----------------------------------------------------------------------------- + + DialogProviderImpl::~DialogProviderImpl() + { + } + + // ----------------------------------------------------------------------------- + + Reference< resource::XStringResourceManager > getStringResourceFromDialogLibrary + ( Reference< container::XNameContainer > xDialogLib ) + { + Reference< resource::XStringResourceManager > xStringResourceManager; + if( xDialogLib.is() ) + { + Reference< resource::XStringResourceSupplier > xStringResourceSupplier( xDialogLib, UNO_QUERY ); + if( xStringResourceSupplier.is() ) + { + Reference< resource::XStringResourceResolver > + xStringResourceResolver = xStringResourceSupplier->getStringResource(); + + xStringResourceManager = + Reference< resource::XStringResourceManager >( xStringResourceResolver, UNO_QUERY ); + } + } + return xStringResourceManager; + } + + Reference< container::XNameContainer > DialogProviderImpl::createControlModel() throw ( Exception ) + { + Reference< XMultiComponentFactory > xSMgr_( m_xContext->getServiceManager(), UNO_QUERY_THROW ); + Reference< container::XNameContainer > xControlModel( xSMgr_->createInstanceWithContext( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDialogModel" ) ), m_xContext ), UNO_QUERY_THROW ); + return xControlModel; + } + + Reference< container::XNameContainer > DialogProviderImpl::createDialogModel( + const Reference< io::XInputStream >& xInput, + const Reference< resource::XStringResourceManager >& xStringResourceManager, + const Any &aDialogSourceURL) throw ( Exception ) + { + Reference< container::XNameContainer > xDialogModel( createControlModel() ); + + ::rtl::OUString aDlgSrcUrlPropName( RTL_CONSTASCII_USTRINGPARAM( "DialogSourceURL" ) ); + Reference< beans::XPropertySet > xDlgPropSet( xDialogModel, UNO_QUERY ); + xDlgPropSet->setPropertyValue( aDlgSrcUrlPropName, aDialogSourceURL ); + + ::xmlscript::importDialogModel( xInput, xDialogModel, m_xContext ); + // Set resource property + if( xStringResourceManager.is() ) + { + Reference< beans::XPropertySet > xDlgPSet( xDialogModel, UNO_QUERY ); + Any aStringResourceManagerAny; + aStringResourceManagerAny <<= xStringResourceManager; + xDlgPSet->setPropertyValue( aResourceResolverPropName, aStringResourceManagerAny ); + } + + return xDialogModel; + } + + Reference< XControlModel > DialogProviderImpl::createDialogModelForBasic() throw ( Exception ) + { + if ( !m_BasicInfo.get() ) + // shouln't get here + throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("No information to create dialog" ) ), Reference< XInterface >() ); + Reference< resource::XStringResourceManager > xStringResourceManager = getStringResourceFromDialogLibrary( m_BasicInfo->mxDlgLib ); + + rtl::OUString aURL(RTL_CONSTASCII_USTRINGPARAM("" )); + Any aDialogSourceURL; + aDialogSourceURL <<= aURL; + Reference< XControlModel > xCtrlModel( createDialogModel( m_BasicInfo->mxInput, xStringResourceManager, aDialogSourceURL ), UNO_QUERY_THROW ); + return xCtrlModel; + } + + Reference< XControlModel > DialogProviderImpl::createDialogModel( const ::rtl::OUString& sURL ) + { + + ::rtl::OUString aURL( sURL ); + + // parse URL + // TODO: use URL parsing class + // TODO: decoding of location + Reference< XMultiComponentFactory > xSMgr( m_xContext->getServiceManager(), UNO_QUERY ); + + if ( !xSMgr.is() ) + { + throw RuntimeException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogProviderImpl::getDialogModel: Couldn't instantiate MultiComponent factory" ) ), + Reference< XInterface >() ); + } + + Reference< uri::XUriReferenceFactory > xFac ( + xSMgr->createInstanceWithContext( rtl::OUString::createFromAscii( + "com.sun.star.uri.UriReferenceFactory"), m_xContext ) , UNO_QUERY ); + + if ( !xFac.is() ) + { + throw RuntimeException( + ::rtl::OUString::createFromAscii( "DialogProviderImpl::getDialogModel(), could not instatiate UriReferenceFactory." ), + Reference< XInterface >() ); + } + + // i75778: Support non-script URLs + Reference< io::XInputStream > xInput; + Reference< container::XNameContainer > xDialogLib; + + // Accept file URL to single dialog + bool bSingleDialog = false; + + Reference< util::XMacroExpander > xMacroExpander( + m_xContext->getValueByName( + ::rtl::OUString::createFromAscii( "/singletons/com.sun.star.util.theMacroExpander" ) ), + UNO_QUERY_THROW ); + + Reference< uri::XUriReference > uriRef; + for (;;) + { + uriRef = Reference< uri::XUriReference >( xFac->parse( aURL ), UNO_QUERY ); + if ( !uriRef.is() ) + { + ::rtl::OUString errorMsg = ::rtl::OUString::createFromAscii( "DialogProviderImpl::getDialogModel: failed to parse URI: " ); + errorMsg += aURL; + throw IllegalArgumentException( errorMsg, + Reference< XInterface >(), 1 ); + } + Reference < uri::XVndSunStarExpandUrl > sxUri( uriRef, UNO_QUERY ); + if( !sxUri.is() ) + break; + + aURL = sxUri->expand( xMacroExpander ); + } + + Reference < uri::XVndSunStarScriptUrl > sfUri( uriRef, UNO_QUERY ); + if( !sfUri.is() ) + { + bSingleDialog = true; + + // Try any other URL with SimpleFileAccess + Reference< ::com::sun::star::ucb::XSimpleFileAccess > xSFI = + Reference< ::com::sun::star::ucb::XSimpleFileAccess >( xSMgr->createInstanceWithContext + ( ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ), m_xContext ), UNO_QUERY ); + + try + { + xInput = xSFI->openFileRead( aURL ); + } + catch( Exception& ) + {} + } + else + { + ::rtl::OUString sDescription = sfUri->getName(); + + sal_Int32 nIndex = 0; + + ::rtl::OUString sLibName = sDescription.getToken( 0, (sal_Unicode)'.', nIndex ); + ::rtl::OUString sDlgName; + if ( nIndex != -1 ) + sDlgName = sDescription.getToken( 0, (sal_Unicode)'.', nIndex ); + + ::rtl::OUString sLocation = sfUri->getParameter( + ::rtl::OUString::createFromAscii( "location" ) ); + + + // get dialog library container + // TODO: dialogs in packages + Reference< XLibraryContainer > xLibContainer; + + if ( sLocation == ::rtl::OUString::createFromAscii( "application" ) ) + { + xLibContainer = Reference< XLibraryContainer >( SFX_APP()->GetDialogContainer(), UNO_QUERY ); + } + else if ( sLocation == ::rtl::OUString::createFromAscii( "document" ) ) + { + Reference< XEmbeddedScripts > xDocumentScripts( m_xModel, UNO_QUERY ); + if ( xDocumentScripts.is() ) + { + xLibContainer.set( xDocumentScripts->getDialogLibraries(), UNO_QUERY ); + OSL_ENSURE( xLibContainer.is(), + "DialogProviderImpl::createDialogModel: invalid dialog container!" ); + } + } + else + { + Sequence< ::rtl::OUString > aOpenDocsTdocURLs( MiscUtils::allOpenTDocUrls( m_xContext ) ); + const ::rtl::OUString* pTdocURL = aOpenDocsTdocURLs.getConstArray(); + const ::rtl::OUString* pTdocURLEnd = aOpenDocsTdocURLs.getConstArray() + aOpenDocsTdocURLs.getLength(); + for ( ; pTdocURL != pTdocURLEnd; ++pTdocURL ) + { + Reference< frame::XModel > xModel( MiscUtils::tDocUrlToModel( *pTdocURL ) ); + OSL_ENSURE( xModel.is(), "DialogProviderImpl::createDialogModel: invalid document model!" ); + if ( !xModel.is() ) + continue; + + ::rtl::OUString sDocURL = xModel->getURL(); + if ( sDocURL.getLength() == 0 ) + { + ::comphelper::NamedValueCollection aModelArgs( xModel->getArgs() ); + sDocURL = aModelArgs.getOrDefault( "Title", sDocURL ); + } + + if ( sLocation != sDocURL ) + continue; + + Reference< XEmbeddedScripts > xDocumentScripts( m_xModel, UNO_QUERY ); + if ( !xDocumentScripts.is() ) + continue; + + xLibContainer.set( xDocumentScripts->getDialogLibraries(), UNO_QUERY ); + OSL_ENSURE( xLibContainer.is(), + "DialogProviderImpl::createDialogModel: invalid dialog container!" ); + } + } + + // get input stream provider + Reference< io::XInputStreamProvider > xISP; + if ( xLibContainer.is() ) + { + // load dialog library + if ( !xLibContainer->isLibraryLoaded( sLibName ) ) + xLibContainer->loadLibrary( sLibName ); + + // get dialog library + if ( xLibContainer->hasByName( sLibName ) ) + { + Any aElement = xLibContainer->getByName( sLibName ); + aElement >>= xDialogLib; + } + + if ( xDialogLib.is() ) + { + // get input stream provider + if ( xDialogLib->hasByName( sDlgName ) ) + { + Any aElement = xDialogLib->getByName( sDlgName ); + aElement >>= xISP; + } + + if ( !xISP.is() ) + { + throw IllegalArgumentException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogProviderImpl::getDialogModel: dialog not found!" ) ), + Reference< XInterface >(), 1 ); + } + } + else + { + throw IllegalArgumentException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogProviderImpl::getDialogModel: library not found!" ) ), + Reference< XInterface >(), 1 ); + } + } + else + { + throw IllegalArgumentException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogProviderImpl::getDialog: library container not found!" ) ), + Reference< XInterface >(), 1 ); + } + + if ( xISP.is() ) + xInput = xISP->createInputStream(); + } + + // import dialog model + Reference< XControlModel > xCtrlModel; + if ( xInput.is() && m_xContext.is() ) + { + Reference< resource::XStringResourceManager > xStringResourceManager; + if( bSingleDialog ) + { + INetURLObject aInetObj( aURL ); + ::rtl::OUString aDlgName = aInetObj.GetBase(); + aInetObj.removeSegment(); + ::rtl::OUString aDlgLocation = aInetObj.GetMainURL( INetURLObject::NO_DECODE ); + bool bReadOnly = true; + ::com::sun ::star::lang::Locale aLocale = Application::GetSettings().GetUILocale(); + ::rtl::OUString aComment; + + Sequence<Any> aArgs( 6 ); + aArgs[0] <<= aDlgLocation; + aArgs[1] <<= bReadOnly; + aArgs[2] <<= aLocale; + aArgs[3] <<= aDlgName; + aArgs[4] <<= aComment; + + Reference< task::XInteractionHandler > xDummyHandler; + aArgs[5] <<= xDummyHandler; + Reference< XMultiComponentFactory > xSMgr_( m_xContext->getServiceManager(), UNO_QUERY_THROW ); + // TODO: Ctor + xStringResourceManager = Reference< resource::XStringResourceManager >( xSMgr_->createInstanceWithContext + ( ::rtl::OUString::createFromAscii( "com.sun.star.resource.StringResourceWithLocation" ), + m_xContext ), UNO_QUERY ); + if( xStringResourceManager.is() ) + { + Reference< XInitialization > xInit( xStringResourceManager, UNO_QUERY ); + if( xInit.is() ) + xInit->initialize( aArgs ); + } + } + else if( xDialogLib.is() ) + { + xStringResourceManager = getStringResourceFromDialogLibrary( xDialogLib ); + } + + Any aDialogSourceURLAny; + aDialogSourceURLAny <<= aURL; + + Reference< container::XNameContainer > xDialogModel( createDialogModel( xInput , xStringResourceManager, aDialogSourceURLAny ), UNO_QUERY_THROW); + + xCtrlModel = Reference< XControlModel >( xDialogModel, UNO_QUERY ); + } + return xCtrlModel; + } + + // ----------------------------------------------------------------------------- + + Reference< XControl > DialogProviderImpl::createDialogControl + ( const Reference< XControlModel >& rxDialogModel, const Reference< XWindowPeer >& xParent ) + { + OSL_ENSURE( rxDialogModel.is(), "DialogProviderImpl::getDialogControl: no dialog model" ); + + Reference< XControl > xDialogControl; + + if ( m_xContext.is() ) + { + Reference< XMultiComponentFactory > xSMgr( m_xContext->getServiceManager() ); + + if ( xSMgr.is() ) + { + xDialogControl = Reference< XControl >( xSMgr->createInstanceWithContext( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDialog" ) ), m_xContext ), UNO_QUERY ); + + if ( xDialogControl.is() ) + { + // set the model + if ( rxDialogModel.is() ) + xDialogControl->setModel( rxDialogModel ); + + // set visible + Reference< XWindow > xW( xDialogControl, UNO_QUERY ); + if ( xW.is() ) + xW->setVisible( sal_False ); + + // get the parent of the dialog control + Reference< XWindowPeer > xPeer; + if( xParent.is() ) + { + xPeer = xParent; + } + else if ( m_xModel.is() ) + { + Reference< frame::XController > xController( m_xModel->getCurrentController(), UNO_QUERY ); + if ( xController.is() ) + { + Reference< frame::XFrame > xFrame( xController->getFrame(), UNO_QUERY ); + if ( xFrame.is() ) + xPeer = Reference< XWindowPeer>( xFrame->getContainerWindow(), UNO_QUERY ); + } + } + + // create a peer + Reference< XToolkit> xToolkit( xSMgr->createInstanceWithContext( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.Toolkit" ) ), m_xContext ), UNO_QUERY ); + if ( xToolkit.is() ) + xDialogControl->createPeer( xToolkit, xPeer ); + } + } + } + + return xDialogControl; + } + + // ----------------------------------------------------------------------------- + + void DialogProviderImpl::attachControlEvents( + const Reference< XControl >& rxControl, + const Reference< XInterface >& rxHandler, + const Reference< XIntrospectionAccess >& rxIntrospectionAccess, + bool bDialogProviderMode ) + { + if ( rxControl.is() ) + { + Reference< XControlContainer > xControlContainer( rxControl, UNO_QUERY ); + + if ( xControlContainer.is() ) + { + Sequence< Reference< XControl > > aControls = xControlContainer->getControls(); + const Reference< XControl >* pControls = aControls.getConstArray(); + sal_Int32 nControlCount = aControls.getLength(); + + Sequence< Reference< XInterface > > aObjects( nControlCount + 1 ); + Reference< XInterface >* pObjects = aObjects.getArray(); + for ( sal_Int32 i = 0; i < nControlCount; ++i ) + { + pObjects[i] = Reference< XInterface >( pControls[i], UNO_QUERY ); + } + + // also add the dialog control itself to the sequence + pObjects[nControlCount] = Reference< XInterface >( rxControl, UNO_QUERY ); + + Reference< XScriptEventsAttacher > xScriptEventsAttacher = new DialogEventsAttacherImpl + ( m_xContext, m_xModel, rxControl, rxHandler, rxIntrospectionAccess, + bDialogProviderMode, ( m_BasicInfo.get() ? m_BasicInfo->mxBasicRTLListener : NULL ) ); + + Any aHelper; + xScriptEventsAttacher->attachEvents( aObjects, Reference< XScriptListener >(), aHelper ); + } + } + } + + Reference< XIntrospectionAccess > DialogProviderImpl::inspectHandler( const Reference< XInterface >& rxHandler ) + { + Reference< XIntrospectionAccess > xIntrospectionAccess; + static Reference< XIntrospection > xIntrospection; + + if( !rxHandler.is() ) + return xIntrospectionAccess; + + if( !xIntrospection.is() ) + { + Reference< XMultiComponentFactory > xSMgr( m_xContext->getServiceManager(), UNO_QUERY ); + if ( !xSMgr.is() ) + { + throw RuntimeException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogProviderImpl::getIntrospectionAccess: Couldn't instantiate MultiComponent factory" ) ), + Reference< XInterface >() ); + } + + // Get introspection service + Reference< XInterface > xI = xSMgr->createInstanceWithContext + ( rtl::OUString::createFromAscii("com.sun.star.beans.Introspection"), m_xContext ); + if (xI.is()) + xIntrospection = Reference< XIntrospection >::query( xI ); + } + + if( xIntrospection.is() ) + { + // Do introspection + try + { + Any aHandlerAny; + aHandlerAny <<= rxHandler; + xIntrospectionAccess = xIntrospection->inspect( aHandlerAny ); + } + catch( RuntimeException& ) + { + xIntrospectionAccess.clear(); + } + } + return xIntrospectionAccess; + } + + + // ----------------------------------------------------------------------------- + // XServiceInfo + // ----------------------------------------------------------------------------- + + ::rtl::OUString DialogProviderImpl::getImplementationName( ) throw (RuntimeException) + { + return getImplementationName_DialogProviderImpl(); + } + + // ----------------------------------------------------------------------------- + + sal_Bool DialogProviderImpl::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 > DialogProviderImpl::getSupportedServiceNames( ) throw (RuntimeException) + { + return getSupportedServiceNames_DialogProviderImpl(); + } + + // ----------------------------------------------------------------------------- + // XInitialization + // ----------------------------------------------------------------------------- + + void DialogProviderImpl::initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException) + { + ::osl::MutexGuard aGuard( getMutex() ); + + if ( aArguments.getLength() == 1 ) + { + aArguments[0] >>= m_xModel; + + if ( !m_xModel.is() ) + { + throw RuntimeException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogProviderImpl::initialize: invalid argument format!" ) ), + Reference< XInterface >() ); + } + } + else if ( aArguments.getLength() == 4 ) + { + // call from RTL_Impl_CreateUnoDialog + 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 ); + // 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 ) + m_BasicInfo->mxBasicRTLListener.set( aArguments[ 3 ], UNO_QUERY); + } + else if ( aArguments.getLength() > 4 ) + { + throw RuntimeException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogProviderImpl::initialize: invalid number of arguments!" ) ), + Reference< XInterface >() ); + } + } + + // ----------------------------------------------------------------------------- + // XDialogProvider + // ----------------------------------------------------------------------------- + + static ::rtl::OUString aDecorationPropName = + ::rtl::OUString::createFromAscii( "Decoration" ); + static ::rtl::OUString aTitlePropName = + ::rtl::OUString::createFromAscii( "Title" ); + + Reference < XControl > DialogProviderImpl::createDialogImpl( + const ::rtl::OUString& URL, const Reference< XInterface >& xHandler, + const Reference< XWindowPeer >& xParent, bool bDialogProviderMode ) + throw (IllegalArgumentException, RuntimeException) + { + // if the dialog is located in a document, the document must already be open! + + ::osl::MutexGuard aGuard( getMutex() ); + + + // m_xHandler = xHandler; + + //Reference< XDialog > xDialog; + Reference< XControl > xCtrl; + Reference< XControlModel > xCtrlMod; + try + { + // add support for basic RTL_FUNCTION + if ( m_BasicInfo.get() ) + xCtrlMod = createDialogModelForBasic(); + else + { + OSL_ENSURE( URL.getLength(), "DialogProviderImpl::getDialog: no URL!" ); + xCtrlMod = createDialogModel( URL ); + } + } + catch ( const RuntimeException& ) { throw; } + catch ( const Exception& ) + { + const Any aError( ::cppu::getCaughtException() ); + throw WrappedTargetRuntimeException( ::rtl::OUString(), *this, aError ); + } + if ( xCtrlMod.is() ) + { + // i83963 Force decoration + if( bDialogProviderMode ) + { + uno::Reference< beans::XPropertySet > xDlgModPropSet( xCtrlMod, uno::UNO_QUERY ); + if( xDlgModPropSet.is() ) + { + bool bDecoration = true; + try + { + Any aDecorationAny = xDlgModPropSet->getPropertyValue( aDecorationPropName ); + aDecorationAny >>= bDecoration; + if( !bDecoration ) + { + xDlgModPropSet->setPropertyValue( aDecorationPropName, makeAny( true ) ); + xDlgModPropSet->setPropertyValue( aTitlePropName, makeAny( ::rtl::OUString() ) ); + } + } + catch( UnknownPropertyException& ) + {} + } + } + + xCtrl = Reference< XControl >( createDialogControl( xCtrlMod, xParent ) ); + if ( xCtrl.is() ) + { + //xDialog = Reference< XDialog >( xCtrl, UNO_QUERY ); + Reference< XIntrospectionAccess > xIntrospectionAccess = inspectHandler( xHandler ); + attachControlEvents( xCtrl, xHandler, xIntrospectionAccess, bDialogProviderMode ); + } + } + + return xCtrl; + } + + Reference < XDialog > DialogProviderImpl::createDialog( const ::rtl::OUString& URL ) + throw (IllegalArgumentException, RuntimeException) + { + Reference< XInterface > xDummyHandler; + Reference< XWindowPeer > xDummyPeer; + Reference < XControl > xControl = DialogProviderImpl::createDialogImpl( URL, xDummyHandler, xDummyPeer, true ); + Reference< XDialog > xDialog( xControl, UNO_QUERY ); + return xDialog; + } + + Reference < XDialog > DialogProviderImpl::createDialogWithHandler( + const ::rtl::OUString& URL, const Reference< XInterface >& xHandler ) + throw (IllegalArgumentException, RuntimeException) + { + if( !xHandler.is() ) + { + throw IllegalArgumentException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogProviderImpl::createDialogWithHandler: Invalid xHandler!" ) ), + Reference< XInterface >(), 1 ); + } + Reference< XWindowPeer > xDummyPeer; + Reference < XControl > xControl = DialogProviderImpl::createDialogImpl( URL, xHandler, xDummyPeer, true ); + Reference< XDialog > xDialog( xControl, UNO_QUERY ); + return xDialog; + } + + Reference < XDialog > DialogProviderImpl::createDialogWithArguments( + const ::rtl::OUString& URL, const Sequence< NamedValue >& Arguments ) + throw (IllegalArgumentException, RuntimeException) + { + ::comphelper::NamedValueCollection aArguments( Arguments ); + + Reference< XWindowPeer > xParentPeer; + if ( aArguments.has( "ParentWindow" ) ) + { + const Any aParentWindow( aArguments.get( "ParentWindow" ) ); + if ( !( aParentWindow >>= xParentPeer ) ) + { + const Reference< XControl > xParentControl( aParentWindow, UNO_QUERY ); + if ( xParentControl.is() ) + xParentPeer = xParentControl->getPeer(); + } + } + + const Reference< XInterface > xHandler( aArguments.get( "EventHandler" ), UNO_QUERY ); + + Reference < XControl > xControl = DialogProviderImpl::createDialogImpl( URL, xHandler, xParentPeer, true ); + Reference< XDialog > xDialog( xControl, UNO_QUERY ); + return xDialog; + } + + Reference< XWindow > DialogProviderImpl::createContainerWindow( + const ::rtl::OUString& URL, const ::rtl::OUString& WindowType, + const Reference< XWindowPeer >& xParent, const Reference< XInterface >& xHandler ) + throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) + { + (void)WindowType; // for future use + if( !xParent.is() ) + { + throw IllegalArgumentException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogProviderImpl::createContainerWindow: Invalid xParent!" ) ), + Reference< XInterface >(), 1 ); + } + Reference < XControl > xControl = DialogProviderImpl::createDialogImpl( URL, xHandler, xParent, false ); + Reference< XWindow> xWindow( xControl, UNO_QUERY ); + return xWindow; + } + + + // ============================================================================= + // component operations + // ============================================================================= + + static Reference< XInterface > SAL_CALL create_DialogProviderImpl( + Reference< XComponentContext > const & xContext ) + SAL_THROW( () ) + { + return static_cast< lang::XTypeProvider * >( new DialogProviderImpl( xContext ) ); + } + + // ----------------------------------------------------------------------------- + + static struct ::cppu::ImplementationEntry s_component_entries [] = + { + { + create_DialogProviderImpl, getImplementationName_DialogProviderImpl, + getSupportedServiceNames_DialogProviderImpl, ::cppu::createSingleComponentFactory, + 0, 0 + }, + { 0, 0, 0, 0, 0, 0 } + }; + + // ----------------------------------------------------------------------------- + +//......................................................................... +} // namespace dlgprov +//......................................................................... + + +// ============================================================================= +// component exports +// ============================================================================= + +extern "C" +{ + void SAL_CALL component_getImplementationEnvironment( + const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv ) + { + (void)ppEnv; + + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; + } + + sal_Bool SAL_CALL component_writeInfo( + lang::XMultiServiceFactory * pServiceManager, registry::XRegistryKey * pRegistryKey ) + { + return ::cppu::component_writeInfoHelper( + pServiceManager, pRegistryKey, ::dlgprov::s_component_entries ); + } + + void * SAL_CALL component_getFactory( + const sal_Char * pImplName, lang::XMultiServiceFactory * pServiceManager, + registry::XRegistryKey * pRegistryKey ) + { + return ::cppu::component_getFactoryHelper( + pImplName, pServiceManager, pRegistryKey, ::dlgprov::s_component_entries ); + } +} diff --git a/scripting/source/dlgprov/dlgprov.hxx b/scripting/source/dlgprov/dlgprov.hxx new file mode 100644 index 000000000000..bc15831d2ff1 --- /dev/null +++ b/scripting/source/dlgprov/dlgprov.hxx @@ -0,0 +1,157 @@ +/************************************************************************* + * + * 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_DLGPROV_HXX +#define SCRIPTING_DLGPROV_HXX + +#include <com/sun/star/awt/XControl.hpp> +#include <com/sun/star/awt/XDialog.hpp> +#include <com/sun/star/awt/XDialogProvider2.hpp> +#include <com/sun/star/awt/XContainerWindowProvider.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/script/XScriptEventsAttacher.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/beans/XIntrospectionAccess.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/resource/XStringResourceManager.hpp> + +#include <cppuhelper/implbase4.hxx> +#include <osl/mutex.hxx> +#include <memory> + +//......................................................................... +namespace dlgprov +{ +//......................................................................... + + // ============================================================================= + // mutex + // ============================================================================= + + ::osl::Mutex& getMutex(); + + + // ============================================================================= + // class DialogProviderImpl + // ============================================================================= + + typedef ::cppu::WeakImplHelper4< + ::com::sun::star::lang::XServiceInfo, + ::com::sun::star::lang::XInitialization, + ::com::sun::star::awt::XDialogProvider2, + ::com::sun::star::awt::XContainerWindowProvider > DialogProviderImpl_BASE; + + class DialogProviderImpl : public DialogProviderImpl_BASE + { + private: + struct BasicRTLParams + { + ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > mxInput; + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > mxDlgLib; + ::com::sun::star::uno::Reference< ::com::sun::star::script::XScriptListener > mxBasicRTLListener; + }; + std::auto_ptr< BasicRTLParams > m_BasicInfo; + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext; + ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > m_xModel; + + + ::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 ); + + 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 ); + ::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 + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > createControlModel() throw ( ::com::sun::star::uno::Exception ); + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > createDialogModel( + const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInput, + const ::com::sun::star::uno::Reference< ::com::sun::star::resource::XStringResourceManager >& xStringResourceManager, + const ::com::sun::star::uno::Any &aDialogSourceURL) throw ( ::com::sun::star::uno::Exception ); + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > createDialogModelForBasic() throw ( ::com::sun::star::uno::Exception ); + + // XDialogProvider / XDialogProvider2 impl method + virtual ::com::sun::star::uno::Reference < ::com::sun::star::awt::XControl > SAL_CALL createDialogImpl( + const ::rtl::OUString& URL, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xHandler, + const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >& xParent, + bool bDialogProviderMode ) + throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + + public: + DialogProviderImpl( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext ); + virtual ~DialogProviderImpl(); + + // 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); + + // XDialogProvider + virtual ::com::sun::star::uno::Reference < ::com::sun::star::awt::XDialog > SAL_CALL createDialog( + const ::rtl::OUString& URL ) + throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + + // XDialogProvider2 + virtual ::com::sun::star::uno::Reference < ::com::sun::star::awt::XDialog > SAL_CALL createDialogWithHandler( + const ::rtl::OUString& URL, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xHandler ) + throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + + virtual ::com::sun::star::uno::Reference < ::com::sun::star::awt::XDialog > SAL_CALL createDialogWithArguments( + const ::rtl::OUString& URL, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& Arguments ) + throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + + virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > SAL_CALL createContainerWindow( + const ::rtl::OUString& URL, const ::rtl::OUString& WindowType, + const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >& xParent, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xHandler ) + throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + }; + +//......................................................................... +} // namespace dlgprov +//......................................................................... + +#endif // SCRIPTING_DLGPROV_HXX diff --git a/scripting/source/dlgprov/dlgprov.xml b/scripting/source/dlgprov/dlgprov.xml new file mode 100644 index 000000000000..556cc3fe2253 --- /dev/null +++ b/scripting/source/dlgprov/dlgprov.xml @@ -0,0 +1,58 @@ +<?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>dlgprov</module-name> + + <component-description> + <author>Thomas Benisch</author> + <name>com.sun.star.comp.scripting.DialogProvider</name> + <description>provider for dialogs</description> + <loader-name>com.sun.star.loader.SharedLibrary</loader-name> + <language>c++</language> + <status value="drafts"/> + <supported-service>com.sun.star.awt.DialogProvider</supported-service> + <type>com.sun.star.awt.XControl</type> + <type>com.sun.star.awt.XControlContainer</type> + <type>com.sun.star.awt.XDialog</type> + <type>com.sun.star.awt.XDialogProvider</type> + <type>com.sun.star.awt.XWindowPeer</type> + <type>com.sun.star.beans.XPropertySet</type> + <type>com.sun.star.frame.XModel</type> + <type>com.sun.star.io.XInputStreamProvider</type> + <type>com.sun.star.lang.IllegalArgumentException</type> + <type>com.sun.star.lang.XInitialization</type> + <type>com.sun.star.lang.XMultiComponentFactory</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.script.ScriptEventDescriptor</type> + <type>com.sun.star.script.XAllListener</type> + <type>com.sun.star.script.XEventAttacher</type> + <type>com.sun.star.script.XLibraryContainer</type> + <type>com.sun.star.script.XScriptEventsAttacher</type> + <type>com.sun.star.script.XScriptEventsSupplier</type> + <type>com.sun.star.script.XScriptListener</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.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>xmlscript</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>xcr</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/dlgprov/makefile.mk b/scripting/source/dlgprov/makefile.mk new file mode 100644 index 000000000000..6c8ec298c760 --- /dev/null +++ b/scripting/source/dlgprov/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=dlgprov +ENABLE_EXCEPTIONS=TRUE +COMP1TYPELIST=$(TARGET) + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk +DLLPRE = + +# ------------------------------------------------------------------ + +SLOFILES= \ + $(SLO)$/dlgprov.obj \ + $(SLO)$/dlgevtatt.obj + +SHL1TARGET= $(TARGET)$(DLLPOSTFIX).uno +SHL1IMPLIB= i$(TARGET) + +SHL1VERSIONMAP=$(SOLARENV)/src/component.map +SHL1DEF=$(MISC)$/$(SHL1TARGET).def +DEF1NAME=$(SHL1TARGET) + +SHL1STDLIBS= \ + $(SFX2LIB) \ + $(VCLLIB) \ + $(TOOLSLIB) \ + $(XMLSCRIPTLIB) \ + $(CPPUHELPERLIB) \ + $(COMPHELPERLIB) \ + $(UCBHELPERLIB) \ + $(CPPULIB) \ + $(BASICLIB) \ + $(SALLIB) + +SHL1DEPN= +SHL1LIBS=$(SLB)$/$(TARGET).lib + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + +# ------------------------------------------------------------------ + +ALLTAR : \ + $(MISC)$/$(TARGET).don \ + +$(SLOFILES) : $(MISC)$/$(TARGET).don + +$(MISC)$/$(TARGET).don : $(SOLARBINDIR)$/oovbaapi.rdb + +$(CPPUMAKER) -O$(INCCOM)$/$(TARGET) -BUCR $(SOLARBINDIR)$/oovbaapi.rdb -X$(SOLARBINDIR)$/types.rdb && echo > $@ + echo $@ + |