update dev300-m58
[ooovba.git] / scripting / source / dlgprov / dlgevtatt.cxx
blob29f815d4fb546e1b881d505b1aa5b8ab2b116c18
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dlgevtatt.cxx,v $
10 * $Revision: 1.15 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_scripting.hxx"
33 #include "dlgevtatt.hxx"
35 #ifndef SCRIPTING_DLGPROV_HXX
36 #include "dlgprov.hxx"
37 #endif
38 #include <sfx2/sfx.hrc>
39 #include <sfx2/app.hxx>
40 #ifndef _MSGBOX_HXX //autogen
41 #include <vcl/msgbox.hxx>
42 #endif
43 #include <com/sun/star/awt/XControl.hpp>
44 #include <com/sun/star/awt/XDialogEventHandler.hpp>
45 #include <com/sun/star/awt/XContainerWindowEventHandler.hpp>
46 #include <com/sun/star/beans/XPropertySet.hpp>
47 #include <com/sun/star/script/ScriptEventDescriptor.hpp>
48 #include <com/sun/star/script/XScriptEventsSupplier.hpp>
49 #include <com/sun/star/script/provider/XScriptProvider.hpp>
50 #include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
51 #include <com/sun/star/script/provider/XScriptProviderSupplier.hpp>
52 #include <com/sun/star/lang/NoSuchMethodException.hpp>
53 #include <com/sun/star/reflection/XIdlMethod.hpp>
54 #include <com/sun/star/beans/MethodConcept.hpp>
55 #include <com/sun/star/beans/XMaterialHolder.hpp>
56 #ifdef FAKE_VBA_EVENT_SUPPORT
57 #include <ooo/vba/XVBAToOOEventDescGen.hpp>
58 #endif
60 using namespace ::com::sun::star;
61 using namespace ::com::sun::star::awt;
62 using namespace ::com::sun::star::beans;
63 using namespace ::com::sun::star::lang;
64 using namespace ::com::sun::star::script;
65 using namespace ::com::sun::star::uno;
66 using namespace ::com::sun::star::script;
67 using namespace ::com::sun::star::reflection;
70 //.........................................................................
71 namespace dlgprov
74 class DialogSFScriptListenerImpl : public DialogScriptListenerImpl
76 protected:
77 Reference< frame::XModel > m_xModel;
78 virtual void firing_impl( const script::ScriptEvent& aScriptEvent, uno::Any* pRet );
79 public:
80 DialogSFScriptListenerImpl( const Reference< XComponentContext >& rxContext, const Reference< frame::XModel >& rxModel ) : DialogScriptListenerImpl( rxContext ), m_xModel( rxModel ) {}
83 class DialogLegacyScriptListenerImpl : public DialogSFScriptListenerImpl
85 protected:
86 virtual void firing_impl( const script::ScriptEvent& aScriptEvent, uno::Any* pRet );
87 public:
88 DialogLegacyScriptListenerImpl( const Reference< XComponentContext >& rxContext, const Reference< frame::XModel >& rxModel ) : DialogSFScriptListenerImpl( rxContext, rxModel ){}
91 class DialogUnoScriptListenerImpl : public DialogSFScriptListenerImpl
93 Reference< awt::XControl > m_xControl;
94 Reference< XInterface > m_xHandler;
95 Reference< beans::XIntrospectionAccess > m_xIntrospectionAccess;
96 bool m_bDialogProviderMode;
98 virtual void firing_impl( const script::ScriptEvent& aScriptEvent, uno::Any* pRet );
100 public:
101 DialogUnoScriptListenerImpl( const Reference< XComponentContext >& rxContext,
102 const Reference< frame::XModel >& rxModel,
103 const Reference< awt::XControl >& rxControl,
104 const Reference< XInterface >& rxHandler,
105 const Reference< beans::XIntrospectionAccess >& rxIntrospectionAccess,
106 bool bDialogProviderMode ); // false: ContainerWindowProvider mode
110 #ifdef FAKE_VBA_EVENT_SUPPORT
111 class DialogVBAScriptListenerImpl : public DialogScriptListenerImpl
113 protected:
114 rtl::OUString msDialogCodeName;
115 rtl::OUString msDialogLibName;
116 Reference< script::XScriptListener > mxListener;
117 virtual void firing_impl( const script::ScriptEvent& aScriptEvent, uno::Any* pRet );
118 public:
119 DialogVBAScriptListenerImpl( const Reference< XComponentContext >& rxContext, const Reference< awt::XControl >& rxControl, const Reference< frame::XModel >& xModel, const rtl::OUString& sDialogLibName );
122 DialogVBAScriptListenerImpl::DialogVBAScriptListenerImpl( const Reference< XComponentContext >& rxContext, const Reference< awt::XControl >& rxControl, const Reference< frame::XModel >& xModel, const rtl::OUString& sDialogLibName ) : DialogScriptListenerImpl( rxContext ), msDialogLibName( sDialogLibName )
124 Reference< XMultiComponentFactory > xSMgr( m_xContext->getServiceManager() );
125 Sequence< Any > args(1);
126 if ( xSMgr.is() )
128 args[0] <<= xModel;
129 mxListener = Reference< XScriptListener >( xSMgr->createInstanceWithArgumentsAndContext( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.EventListener" ) ), args, m_xContext ), UNO_QUERY );
131 if ( rxControl.is() )
135 Reference< XPropertySet > xProps( rxControl->getModel(), UNO_QUERY_THROW );
136 xProps->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name") ) ) >>= msDialogCodeName;
137 xProps.set( mxListener, UNO_QUERY_THROW );
138 xProps->setPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Model") ), args[ 0 ] );
140 catch ( Exception& ) {}
145 void DialogVBAScriptListenerImpl::firing_impl( const script::ScriptEvent& aScriptEvent, uno::Any* )
147 if ( aScriptEvent.ScriptType.equals( rtl::OUString::createFromAscii("VBAInterop") ) && mxListener.is() )
149 ScriptEvent aScriptEventCopy( aScriptEvent );
150 aScriptEventCopy.ScriptCode = msDialogLibName.concat( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "." ) ) ).concat( msDialogCodeName );
153 mxListener->firing( aScriptEventCopy );
155 catch( Exception& ) {}
158 #endif
160 //.........................................................................
162 // =============================================================================
163 // DialogEventsAttacherImpl
164 // =============================================================================
166 DialogEventsAttacherImpl::DialogEventsAttacherImpl( const Reference< XComponentContext >& rxContext, const Reference< frame::XModel >& rxModel, const Reference< awt::XControl >& rxControl, const Reference< XInterface >& rxHandler, const Reference< beans::XIntrospectionAccess >& rxIntrospect, bool bProviderMode, const Reference< script::XScriptListener >& rxRTLListener, const rtl::OUString& sDialogLibName )
167 :m_xContext( rxContext )
169 // key listeners by protocol when ScriptType = 'Script'
170 // otherwise key is the ScriptType e.g. StarBasic
171 if ( rxRTLListener.is() ) // set up handler for RTL_BASIC
172 listernersForTypes[ rtl::OUString::createFromAscii("StarBasic") ] = rxRTLListener;
173 else
174 listernersForTypes[ rtl::OUString::createFromAscii("StarBasic") ] = new DialogLegacyScriptListenerImpl( rxContext, rxModel );
175 // handler for Script & ::rtl::OUString::createFromAscii( "vnd.sun.star.UNO:" )
176 listernersForTypes[ rtl::OUString::createFromAscii("vnd.sun.star.UNO") ] = new DialogUnoScriptListenerImpl( rxContext, rxModel, rxControl, rxHandler, rxIntrospect, bProviderMode );
177 listernersForTypes[ rtl::OUString::createFromAscii("vnd.sun.star.script") ] = new DialogSFScriptListenerImpl( rxContext, rxModel );
178 #ifdef FAKE_VBA_EVENT_SUPPORT
179 listernersForTypes[ rtl::OUString::createFromAscii("VBAInterop") ] = new DialogVBAScriptListenerImpl( rxContext, rxControl, rxModel, sDialogLibName );
180 #endif
183 // -----------------------------------------------------------------------------
185 DialogEventsAttacherImpl::~DialogEventsAttacherImpl()
189 // -----------------------------------------------------------------------------
190 Reference< script::XScriptListener >
191 DialogEventsAttacherImpl::getScriptListenerForKey( const rtl::OUString& sKey ) throw ( RuntimeException )
193 ListenerHash::iterator it = listernersForTypes.find( sKey );
194 if ( it == listernersForTypes.end() )
195 throw RuntimeException(); // more text info here please
196 return it->second;
198 #ifdef FAKE_VBA_EVENT_SUPPORT
199 Reference< XScriptEventsSupplier > DialogEventsAttacherImpl::getFakeVbaEventsSupplier( const Reference< XControl >& xControl, rtl::OUString& sControlName )
201 Reference< XScriptEventsSupplier > xEventsSupplier;
202 Reference< XMultiComponentFactory > xSMgr( m_xContext->getServiceManager() );
203 if ( xSMgr.is() )
205 Reference< ooo::vba::XVBAToOOEventDescGen > xVBAToOOEvtDesc( xSMgr->createInstanceWithContext( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAToOOEventDesc" ) ), m_xContext ), UNO_QUERY );
206 if ( xVBAToOOEvtDesc.is() )
207 xEventsSupplier.set( xVBAToOOEvtDesc->getEventSupplier( xControl, sControlName ), UNO_QUERY );
210 return xEventsSupplier;
212 #endif
214 // -----------------------------------------------------------------------------
215 void SAL_CALL DialogEventsAttacherImpl::attachEventsToControl( const Reference< XControl>& xControl, const Reference< XScriptEventsSupplier >& xEventsSupplier, const Any& Helper )
217 if ( xEventsSupplier.is() )
219 Reference< container::XNameContainer > xEventCont = xEventsSupplier->getEvents();
221 Reference< XControlModel > xControlModel = xControl->getModel();
222 if ( xEventCont.is() )
224 Sequence< ::rtl::OUString > aNames = xEventCont->getElementNames();
225 const ::rtl::OUString* pNames = aNames.getConstArray();
226 sal_Int32 nNameCount = aNames.getLength();
228 for ( sal_Int32 j = 0; j < nNameCount; ++j )
230 ScriptEventDescriptor aDesc;
232 Any aElement = xEventCont->getByName( pNames[ j ] );
233 aElement >>= aDesc;
234 rtl::OUString sKey = aDesc.ScriptType;
235 if ( aDesc.ScriptType.equals( rtl::OUString::createFromAscii("Script" ) ) || aDesc.ScriptType.equals( rtl::OUString::createFromAscii("UNO" ) ) )
237 sal_Int32 nIndex = aDesc.ScriptCode.indexOf( ':' );
238 sKey = aDesc.ScriptCode.copy( 0, nIndex );
240 Reference< XAllListener > xAllListener =
241 new DialogAllListenerImpl( getScriptListenerForKey( sKey ), aDesc.ScriptType, aDesc.ScriptCode );
243 // try first to attach event to the ControlModel
244 bool bSuccess = false;
247 Reference< XEventListener > xListener_ = m_xEventAttacher->attachSingleEventListener(
248 xControlModel, xAllListener, Helper, aDesc.ListenerType,
249 aDesc.AddListenerParam, aDesc.EventMethod );
251 if ( xListener_.is() )
252 bSuccess = true;
254 catch ( IllegalArgumentException& )
257 catch ( IntrospectionException& )
260 catch ( CannotCreateAdapterException& )
263 catch ( ServiceNotRegisteredException& )
269 // if we had no success, try to attach to the control
270 if ( !bSuccess )
272 Reference< XEventListener > xListener_ = m_xEventAttacher->attachSingleEventListener(
273 xControl, xAllListener, Helper, aDesc.ListenerType,
274 aDesc.AddListenerParam, aDesc.EventMethod );
277 catch( IllegalArgumentException& )
280 catch( IntrospectionException& )
283 catch( CannotCreateAdapterException& )
286 catch( ServiceNotRegisteredException& )
294 // -----------------------------------------------------------------------------
295 // XScriptEventsAttacher
296 // -----------------------------------------------------------------------------
298 void SAL_CALL DialogEventsAttacherImpl::attachEvents( const Sequence< Reference< XInterface > >& Objects,
299 const com::sun::star::uno::Reference<com::sun::star::script::XScriptListener>&,
300 const Any& Helper )
301 throw (IllegalArgumentException, IntrospectionException, CannotCreateAdapterException,
302 ServiceNotRegisteredException, RuntimeException)
304 // get EventAttacher
306 ::osl::MutexGuard aGuard( getMutex() );
308 if ( !m_xEventAttacher.is() )
310 Reference< XMultiComponentFactory > xSMgr( m_xContext->getServiceManager() );
311 if ( xSMgr.is() )
313 m_xEventAttacher = Reference< XEventAttacher >( xSMgr->createInstanceWithContext(
314 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.script.EventAttacher" ) ), m_xContext ), UNO_QUERY );
316 if ( !m_xEventAttacher.is() )
317 throw ServiceNotRegisteredException();
319 else
321 throw RuntimeException();
327 // go over all objects
328 const Reference< XInterface >* pObjects = Objects.getConstArray();
329 sal_Int32 nObjCount = Objects.getLength();
330 #ifdef FAKE_VBA_EVENT_SUPPORT
331 Reference< awt::XControl > xDlgControl( Objects[ nObjCount - 1 ], uno::UNO_QUERY ); // last object is the dialog
332 rtl::OUString sDialogCodeName;
333 if ( xDlgControl.is() )
335 Reference< XPropertySet > xProps( xDlgControl->getModel(), UNO_QUERY );
338 xProps->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name") ) ) >>= sDialogCodeName;
340 catch( Exception& ){}
342 #endif
344 for ( sal_Int32 i = 0; i < nObjCount; ++i )
346 // We know that we have to do with instances of XControl.
347 // Otherwise this is not the right implementation for
348 // XScriptEventsAttacher and we have to give up.
349 Reference< XControl > xControl( pObjects[ i ], UNO_QUERY );
350 if ( !xControl.is() )
351 throw IllegalArgumentException();
353 // get XEventsSupplier from control model
354 Reference< XControlModel > xControlModel = xControl->getModel();
355 Reference< XScriptEventsSupplier > xEventsSupplier( xControlModel, UNO_QUERY );
356 attachEventsToControl( xControl, xEventsSupplier, Helper );
357 #ifdef FAKE_VBA_EVENT_SUPPORT
358 xEventsSupplier.set( getFakeVbaEventsSupplier( xControl, sDialogCodeName ) );
359 attachEventsToControl( xControl, xEventsSupplier, Helper );
360 #endif
365 // =============================================================================
366 // DialogAllListenerImpl
367 // =============================================================================
369 DialogAllListenerImpl::DialogAllListenerImpl( const Reference< XScriptListener >& rxListener,
370 const ::rtl::OUString& rScriptType, const ::rtl::OUString& rScriptCode )
371 :m_xScriptListener( rxListener )
372 ,m_sScriptType( rScriptType )
373 ,m_sScriptCode( rScriptCode )
377 // -----------------------------------------------------------------------------
379 DialogAllListenerImpl::~DialogAllListenerImpl()
383 // -----------------------------------------------------------------------------
385 void DialogAllListenerImpl::firing_impl( const AllEventObject& Event, Any* pRet )
387 ScriptEvent aScriptEvent;
388 aScriptEvent.Source = (OWeakObject *)this; // get correct XInterface
389 aScriptEvent.ListenerType = Event.ListenerType;
390 aScriptEvent.MethodName = Event.MethodName;
391 aScriptEvent.Arguments = Event.Arguments;
392 aScriptEvent.Helper = Event.Helper;
393 aScriptEvent.ScriptType = m_sScriptType;
394 aScriptEvent.ScriptCode = m_sScriptCode;
396 if ( m_xScriptListener.is() )
398 if ( pRet )
399 *pRet = m_xScriptListener->approveFiring( aScriptEvent );
400 else
401 m_xScriptListener->firing( aScriptEvent );
405 // -----------------------------------------------------------------------------
406 // XEventListener
407 // -----------------------------------------------------------------------------
409 void DialogAllListenerImpl::disposing(const EventObject& ) throw ( RuntimeException )
413 // -----------------------------------------------------------------------------
414 // XAllListener
415 // -----------------------------------------------------------------------------
417 void DialogAllListenerImpl::firing( const AllEventObject& Event ) throw ( RuntimeException )
419 //::osl::MutexGuard aGuard( getMutex() );
421 firing_impl( Event, NULL );
424 // -----------------------------------------------------------------------------
426 Any DialogAllListenerImpl::approveFiring( const AllEventObject& Event )
427 throw ( reflection::InvocationTargetException, RuntimeException )
429 //::osl::MutexGuard aGuard( getMutex() );
431 Any aReturn;
432 firing_impl( Event, &aReturn );
433 return aReturn;
437 // =============================================================================
438 // DialogScriptListenerImpl
439 // =============================================================================
441 DialogUnoScriptListenerImpl::DialogUnoScriptListenerImpl( const Reference< XComponentContext >& rxContext,
442 const Reference< ::com::sun::star::frame::XModel >& rxModel,
443 const Reference< ::com::sun::star::awt::XControl >& rxControl,
444 const Reference< ::com::sun::star::uno::XInterface >& rxHandler,
445 const Reference< ::com::sun::star::beans::XIntrospectionAccess >& rxIntrospectionAccess,
446 bool bDialogProviderMode )
447 : DialogSFScriptListenerImpl( rxContext, rxModel )
448 ,m_xControl( rxControl )
449 ,m_xHandler( rxHandler )
450 ,m_xIntrospectionAccess( rxIntrospectionAccess )
451 ,m_bDialogProviderMode( bDialogProviderMode )
455 // -----------------------------------------------------------------------------
457 DialogScriptListenerImpl::~DialogScriptListenerImpl()
461 // -----------------------------------------------------------------------------
462 void DialogSFScriptListenerImpl::firing_impl( const ScriptEvent& aScriptEvent, Any* pRet )
466 Reference< provider::XScriptProvider > xScriptProvider;
467 if ( m_xModel.is() )
469 Reference< provider::XScriptProviderSupplier > xSupplier( m_xModel, UNO_QUERY );
470 OSL_ENSURE( xSupplier.is(), "DialogScriptListenerImpl::firing_impl: failed to get script provider supplier" );
471 if ( xSupplier.is() )
472 xScriptProvider.set( xSupplier->getScriptProvider() );
474 else
476 OSL_ASSERT( m_xContext.is() );
477 if ( m_xContext.is() )
479 Reference< provider::XScriptProviderFactory > xFactory(
480 m_xContext->getValueByName(
481 ::rtl::OUString::createFromAscii( "/singletons/com.sun.star.script.provider.theMasterScriptProviderFactory" ) ),
482 UNO_QUERY );
483 OSL_ENSURE( xFactory.is(), "SFURL_firing_impl: failed to get master script provider factory" );
484 if ( xFactory.is() )
486 Any aCtx;
487 aCtx <<= ::rtl::OUString::createFromAscii( "user" );
488 xScriptProvider.set( xFactory->createScriptProvider( aCtx ), UNO_QUERY );
493 OSL_ENSURE( xScriptProvider.is(), "DialogScriptListenerImpl::firing_impl: failed to get script provider" );
495 if ( xScriptProvider.is() )
497 Reference< provider::XScript > xScript = xScriptProvider->getScript( aScriptEvent.ScriptCode );
498 OSL_ENSURE( xScript.is(), "DialogScriptListenerImpl::firing_impl: failed to get script" );
500 if ( xScript.is() )
502 Sequence< Any > aInParams;
503 Sequence< sal_Int16 > aOutParamsIndex;
504 Sequence< Any > aOutParams;
506 // get arguments for script
507 aInParams = aScriptEvent.Arguments;
509 Any aResult = xScript->invoke( aInParams, aOutParamsIndex, aOutParams );
510 if ( pRet )
511 *pRet = aResult;
515 catch ( RuntimeException& e )
517 OSL_TRACE( "DialogScriptListenerImpl::firing_impl: caught RuntimeException reason %s",
518 ::rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).pData->buffer );
520 catch ( Exception& e )
522 OSL_TRACE( "DialogScriptListenerImpl::firing_impl: caught Exception reason %s",
523 ::rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).pData->buffer );
527 void DialogLegacyScriptListenerImpl::firing_impl( const ScriptEvent& aScriptEvent, Any* pRet )
529 ::rtl::OUString sScriptURL;
530 ::rtl::OUString sScriptCode( aScriptEvent.ScriptCode );
532 if ( aScriptEvent.ScriptType.compareToAscii( "StarBasic" ) == 0 )
534 // StarBasic script: convert ScriptCode to scriptURL
535 sal_Int32 nIndex = sScriptCode.indexOf( ':' );
536 if ( nIndex >= 0 && nIndex < sScriptCode.getLength() )
538 sScriptURL = ::rtl::OUString::createFromAscii( "vnd.sun.star.script:" );
539 sScriptURL += sScriptCode.copy( nIndex + 1 );
540 sScriptURL += ::rtl::OUString::createFromAscii( "?language=Basic&location=" );
541 sScriptURL += sScriptCode.copy( 0, nIndex );
543 ScriptEvent aSFScriptEvent( aScriptEvent );
544 aSFScriptEvent.ScriptCode = sScriptURL;
545 DialogSFScriptListenerImpl::firing_impl( aSFScriptEvent, pRet );
549 void DialogUnoScriptListenerImpl::firing_impl( const ScriptEvent& aScriptEvent, Any* pRet )
551 static ::rtl::OUString sUnoURLScheme = ::rtl::OUString::createFromAscii( "vnd.sun.star.UNO:" );
553 ::rtl::OUString sScriptCode( aScriptEvent.ScriptCode );
554 ::rtl::OUString aMethodName = aScriptEvent.ScriptCode.copy( sUnoURLScheme.getLength() );
556 const Any* pArguments = aScriptEvent.Arguments.getConstArray();
557 Any aEventObject = pArguments[0];
559 bool bHandled = false;
560 if( m_xHandler.is() )
562 if( m_bDialogProviderMode )
564 Reference< XDialogEventHandler > xDialogEventHandler( m_xHandler, UNO_QUERY );
565 if( xDialogEventHandler.is() )
567 Reference< XDialog > xDialog( m_xControl, UNO_QUERY );
568 bHandled = xDialogEventHandler->callHandlerMethod( xDialog, aEventObject, aMethodName );
571 else
573 Reference< XContainerWindowEventHandler > xContainerWindowEventHandler( m_xHandler, UNO_QUERY );
574 if( xContainerWindowEventHandler.is() )
576 Reference< XWindow > xWindow( m_xControl, UNO_QUERY );
577 bHandled = xContainerWindowEventHandler->callHandlerMethod( xWindow, aEventObject, aMethodName );
582 Any aRet;
583 if( !bHandled && m_xIntrospectionAccess.is() )
587 // Methode ansprechen
588 const Reference< XIdlMethod >& rxMethod = m_xIntrospectionAccess->
589 getMethod( aMethodName, MethodConcept::ALL - MethodConcept::DANGEROUS );
591 Reference< XMaterialHolder > xMaterialHolder =
592 Reference< XMaterialHolder >::query( m_xIntrospectionAccess );
593 Any aHandlerObject = xMaterialHolder->getMaterial();
595 Sequence< Reference< XIdlClass > > aParamTypeSeq = rxMethod->getParameterTypes();
596 sal_Int32 nParamCount = aParamTypeSeq.getLength();
597 if( nParamCount == 0 )
599 Sequence<Any> args;
600 rxMethod->invoke( aHandlerObject, args );
601 bHandled = true;
603 else if( nParamCount == 2 )
605 // Signature check automatically done by reflection
606 Sequence<Any> Args(2);
607 Any* pArgs = Args.getArray();
608 if( m_bDialogProviderMode )
610 Reference< XDialog > xDialog( m_xControl, UNO_QUERY );
611 pArgs[0] <<= xDialog;
613 else
615 Reference< XWindow > xWindow( m_xControl, UNO_QUERY );
616 pArgs[0] <<= xWindow;
618 pArgs[1] = aEventObject;
619 aRet = rxMethod->invoke( aHandlerObject, Args );
620 bHandled = true;
623 catch( com::sun::star::lang::IllegalArgumentException& )
625 catch( com::sun::star::lang::NoSuchMethodException& )
627 catch( com::sun::star::reflection::InvocationTargetException& )
631 if( bHandled )
633 if( pRet )
634 *pRet = aRet;
636 else
638 ResMgr* pResMgr = SFX_APP()->GetSfxResManager();
639 if( pResMgr )
641 String aRes( ResId(STR_ERRUNOEVENTBINDUNG, *pResMgr) );
642 ::rtl::OUString aQuoteChar( RTL_CONSTASCII_USTRINGPARAM( "\"" ) );
644 ::rtl::OUString aOURes = aRes;
645 sal_Int32 nIndex = aOURes.indexOf( '%' );
647 ::rtl::OUString aOUFinal;
648 aOUFinal += aOURes.copy( 0, nIndex );
649 aOUFinal += aQuoteChar;
650 aOUFinal += aMethodName;
651 aOUFinal += aQuoteChar;
652 aOUFinal += aOURes.copy( nIndex + 2 );
654 ErrorBox( NULL, WinBits( WB_OK ), aOUFinal ).Execute();
659 // -----------------------------------------------------------------------------
660 // XEventListener
661 // -----------------------------------------------------------------------------
663 void DialogScriptListenerImpl::disposing(const EventObject& ) throw ( RuntimeException )
667 // -----------------------------------------------------------------------------
668 // XScriptListener
669 // -----------------------------------------------------------------------------
671 void DialogScriptListenerImpl::firing( const ScriptEvent& aScriptEvent ) throw ( RuntimeException )
673 //::osl::MutexGuard aGuard( getMutex() );
675 firing_impl( aScriptEvent, NULL );
678 // -----------------------------------------------------------------------------
680 Any DialogScriptListenerImpl::approveFiring( const ScriptEvent& aScriptEvent )
681 throw ( reflection::InvocationTargetException, RuntimeException )
683 //::osl::MutexGuard aGuard( getMutex() );
685 Any aReturn;
686 firing_impl( aScriptEvent, &aReturn );
687 return aReturn;
690 // -----------------------------------------------------------------------------
692 //.........................................................................
693 } // namespace dlgprov
694 //.........................................................................