summaryrefslogtreecommitdiff
path: root/scripting
diff options
context:
space:
mode:
authorOliver Bolte <obo@openoffice.org>2006-07-14 06:09:20 +0000
committerOliver Bolte <obo@openoffice.org>2006-07-14 06:09:20 +0000
commit797e69c3fa9683a07a31096b426a6095eb9d955b (patch)
treea1d688b066bb3a01c8f6cca106aa1642fe47298c /scripting
parent5162d047e2ff42bd6322bb955d1d2a30df402f52 (diff)
INTEGRATION: CWS ab28 (1.8.2); FILE MERGED
2006/07/12 08:44:16 ab 1.8.2.1: #i66948# XDialogProvider2 support
Diffstat (limited to 'scripting')
-rw-r--r--scripting/source/dlgprov/dlgevtatt.cxx159
1 files changed, 143 insertions, 16 deletions
diff --git a/scripting/source/dlgprov/dlgevtatt.cxx b/scripting/source/dlgprov/dlgevtatt.cxx
index 11dc5b66de16..d1dacd38b36a 100644
--- a/scripting/source/dlgprov/dlgevtatt.cxx
+++ b/scripting/source/dlgprov/dlgevtatt.cxx
@@ -4,9 +4,9 @@
*
* $RCSfile: dlgevtatt.cxx,v $
*
- * $Revision: 1.8 $
+ * $Revision: 1.9 $
*
- * last change: $Author: hr $ $Date: 2006-06-19 10:18:49 $
+ * last change: $Author: obo $ $Date: 2006-07-14 07:09:20 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
@@ -40,10 +40,22 @@
#ifndef SCRIPTING_DLGPROV_HXX
#include "dlgprov.hxx"
#endif
+#ifndef _SFX_HRC
+#include <sfx2/sfx.hrc>
+#endif
+#ifndef _SFXAPP_HXX
+#include <sfx2/app.hxx>
+#endif
+#ifndef _MSGBOX_HXX //autogen
+#include <vcl/msgbox.hxx>
+#endif
#ifndef _COM_SUN_STAR_AWT_XCONTROL_HPP_
#include <com/sun/star/awt/XControl.hpp>
#endif
+#ifndef _COM_SUN_STAR_AWT_XDIALOGEVENTHANDLER_HPP_
+#include <com/sun/star/awt/XDialogEventHandler.hpp>
+#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
#include <com/sun/star/beans/XPropertySet.hpp>
#endif
@@ -62,6 +74,18 @@
#ifndef _COM_SUN_STAR_SCRIPT_PROVIDER_XSCRIPTPROVIDERSUPPLIER_HPP_
#include <com/sun/star/script/provider/XScriptProviderSupplier.hpp>
#endif
+#ifndef _COM_SUN_STAR_LANG_NOSUCHMETHODEXCEPTION_HPP_
+#include <com/sun/star/lang/NoSuchMethodException.hpp>
+#endif
+#ifndef _COM_SUN_STAR_REFLECTION_XIDLMETHOD_HPP_
+#include <com/sun/star/reflection/XIdlMethod.hpp>
+#endif
+#ifndef _COM_SUN_STAR_BEANS_METHODCONCEPT_HPP_
+#include <com/sun/star/beans/MethodConcept.hpp>
+#endif
+#ifndef _COM_SUN_STAR_BEANS_XMATERIALHOLDER_HPP_
+#include <com/sun/star/beans/XMaterialHolder.hpp>
+#endif
using namespace ::com::sun::star;
@@ -71,6 +95,7 @@ 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;
//.........................................................................
@@ -239,7 +264,6 @@ namespace dlgprov
aScriptEvent.MethodName = Event.MethodName;
aScriptEvent.Arguments = Event.Arguments;
aScriptEvent.Helper = Event.Helper;
- aScriptEvent.Arguments = Event.Arguments;
aScriptEvent.ScriptType = m_sScriptType;
aScriptEvent.ScriptCode = m_sScriptCode;
@@ -289,9 +313,15 @@ namespace dlgprov
// =============================================================================
DialogScriptListenerImpl::DialogScriptListenerImpl( const Reference< XComponentContext >& rxContext,
- const Reference< ::com::sun::star::frame::XModel >& rxModel )
+ const Reference< ::com::sun::star::frame::XModel >& rxModel,
+ const Reference< ::com::sun::star::awt::XDialog >& rxDialog,
+ const Reference< ::com::sun::star::uno::XInterface >& rxHandler,
+ const Reference< ::com::sun::star::beans::XIntrospectionAccess >& rxIntrospectionAccess )
:m_xContext( rxContext )
,m_xModel( rxModel )
+ ,m_xDialog( rxDialog )
+ ,m_xHandler( rxHandler )
+ ,m_xIntrospectionAccess( rxIntrospectionAccess )
{
}
@@ -305,25 +335,37 @@ namespace dlgprov
void DialogScriptListenerImpl::firing_impl( const ScriptEvent& aScriptEvent, Any* pRet )
{
+ static ::rtl::OUString aVndSunStarUNO =
+ ::rtl::OUString::createFromAscii( "vnd.sun.star.UNO:" );
+
::rtl::OUString sScriptURL;
::rtl::OUString sScriptCode( aScriptEvent.ScriptCode );
- if ( aScriptEvent.ScriptType.compareToAscii( "StarBasic" ) == 0 )
+ bool bUNO = (sScriptCode.indexOf( aVndSunStarUNO ) == 0);
+ if( bUNO )
{
- // 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 );
- }
+ handleUnoScript( aScriptEvent, pRet );
+ return;
}
else
{
- // scripting framework script: ScriptCode contains scriptURL
- sScriptURL = sScriptCode;
+ 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 );
+ }
+ }
+ else
+ {
+ // scripting framework script: ScriptCode contains scriptURL
+ sScriptURL = sScriptCode;
+ }
}
try
@@ -389,6 +431,91 @@ namespace dlgprov
}
}
+ void DialogScriptListenerImpl::handleUnoScript( 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];
+
+ Reference< XDialogEventHandler > xDialogEventHandler( m_xHandler, UNO_QUERY );
+ bool bHandled = false;
+ if( xDialogEventHandler.is() )
+ {
+ bHandled = xDialogEventHandler->callHandlerMethod( m_xDialog, 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();
+ pArgs[0] <<= m_xDialog;
+ pArgs[1] = aEventObject;
+ aRet = rxMethod->invoke( aHandlerObject, Args );
+ bHandled = true;
+ }
+ }
+ catch( com::sun::star::lang::IllegalArgumentException& e )
+ {}
+ catch( com::sun::star::lang::NoSuchMethodException& e )
+ {}
+ catch( com::sun::star::reflection::InvocationTargetException& e )
+ {}
+ }
+
+ 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
// -----------------------------------------------------------------------------