1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_scripting.hxx" 30 #include "dlgevtatt.hxx" 31 32 #include "dlgprov.hxx" 33 34 #include <sfx2/sfx.hrc> 35 #include <sfx2/app.hxx> 36 #include <vcl/msgbox.hxx> 37 #include <tools/diagnose_ex.h> 38 39 #include <com/sun/star/awt/XControl.hpp> 40 #include <com/sun/star/awt/XDialogEventHandler.hpp> 41 #include <com/sun/star/awt/XContainerWindowEventHandler.hpp> 42 #include <com/sun/star/beans/XPropertySet.hpp> 43 #include <com/sun/star/script/ScriptEventDescriptor.hpp> 44 #include <com/sun/star/script/XScriptEventsSupplier.hpp> 45 #include <com/sun/star/script/provider/XScriptProvider.hpp> 46 #include <com/sun/star/script/provider/XScriptProviderFactory.hpp> 47 #include <com/sun/star/script/provider/XScriptProviderSupplier.hpp> 48 #include <com/sun/star/script/vba/XVBACompatibility.hpp> 49 #include <com/sun/star/lang/NoSuchMethodException.hpp> 50 #include <com/sun/star/reflection/XIdlMethod.hpp> 51 #include <com/sun/star/beans/MethodConcept.hpp> 52 #include <com/sun/star/beans/XMaterialHolder.hpp> 53 54 #include <ooo/vba/XVBAToOOEventDescGen.hpp> 55 56 using namespace ::com::sun::star; 57 using namespace ::com::sun::star::awt; 58 using namespace ::com::sun::star::beans; 59 using namespace ::com::sun::star::lang; 60 using namespace ::com::sun::star::script; 61 using namespace ::com::sun::star::uno; 62 using namespace ::com::sun::star::script; 63 using namespace ::com::sun::star::reflection; 64 65 66 //......................................................................... 67 namespace dlgprov 68 { 69 70 class DialogSFScriptListenerImpl : public DialogScriptListenerImpl 71 { 72 protected: 73 Reference< frame::XModel > m_xModel; 74 virtual void firing_impl( const script::ScriptEvent& aScriptEvent, uno::Any* pRet ); 75 public: 76 DialogSFScriptListenerImpl( const Reference< XComponentContext >& rxContext, const Reference< frame::XModel >& rxModel ) : DialogScriptListenerImpl( rxContext ), m_xModel( rxModel ) {} 77 }; 78 79 class DialogLegacyScriptListenerImpl : public DialogSFScriptListenerImpl 80 { 81 protected: 82 virtual void firing_impl( const script::ScriptEvent& aScriptEvent, uno::Any* pRet ); 83 public: 84 DialogLegacyScriptListenerImpl( const Reference< XComponentContext >& rxContext, const Reference< frame::XModel >& rxModel ) : DialogSFScriptListenerImpl( rxContext, rxModel ){} 85 }; 86 87 class DialogUnoScriptListenerImpl : public DialogSFScriptListenerImpl 88 { 89 Reference< awt::XControl > m_xControl; 90 Reference< XInterface > m_xHandler; 91 Reference< beans::XIntrospectionAccess > m_xIntrospectionAccess; 92 bool m_bDialogProviderMode; 93 94 virtual void firing_impl( const script::ScriptEvent& aScriptEvent, uno::Any* pRet ); 95 96 public: 97 DialogUnoScriptListenerImpl( const Reference< XComponentContext >& rxContext, 98 const Reference< frame::XModel >& rxModel, 99 const Reference< awt::XControl >& rxControl, 100 const Reference< XInterface >& rxHandler, 101 const Reference< beans::XIntrospectionAccess >& rxIntrospectionAccess, 102 bool bDialogProviderMode ); // false: ContainerWindowProvider mode 103 104 }; 105 106 class DialogVBAScriptListenerImpl : public DialogScriptListenerImpl 107 { 108 protected: 109 rtl::OUString msDialogCodeName; 110 Reference< script::XScriptListener > mxListener; 111 virtual void firing_impl( const script::ScriptEvent& aScriptEvent, uno::Any* pRet ); 112 public: 113 DialogVBAScriptListenerImpl( const Reference< XComponentContext >& rxContext, const Reference< awt::XControl >& rxControl, const Reference< frame::XModel >& xModel ); 114 }; 115 116 DialogVBAScriptListenerImpl::DialogVBAScriptListenerImpl( const Reference< XComponentContext >& rxContext, const Reference< awt::XControl >& rxControl, const Reference< frame::XModel >& xModel ) : DialogScriptListenerImpl( rxContext ) 117 { 118 Reference< XMultiComponentFactory > xSMgr( m_xContext->getServiceManager() ); 119 Sequence< Any > args(1); 120 if ( xSMgr.is() ) 121 { 122 args[0] <<= xModel; 123 mxListener = Reference< XScriptListener >( xSMgr->createInstanceWithArgumentsAndContext( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.EventListener" ) ), args, m_xContext ), UNO_QUERY ); 124 } 125 if ( rxControl.is() ) 126 { 127 try 128 { 129 Reference< XPropertySet > xProps( rxControl->getModel(), UNO_QUERY_THROW ); 130 xProps->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name") ) ) >>= msDialogCodeName; 131 xProps.set( mxListener, UNO_QUERY_THROW ); 132 xProps->setPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Model") ), args[ 0 ] ); 133 } 134 catch( const Exception& ) 135 { 136 DBG_UNHANDLED_EXCEPTION(); 137 } 138 } 139 140 } 141 142 void DialogVBAScriptListenerImpl::firing_impl( const script::ScriptEvent& aScriptEvent, uno::Any* ) 143 { 144 if ( aScriptEvent.ScriptType.equals( rtl::OUString::createFromAscii("VBAInterop") ) && mxListener.is() ) 145 { 146 ScriptEvent aScriptEventCopy( aScriptEvent ); 147 aScriptEventCopy.ScriptCode = msDialogCodeName; 148 try 149 { 150 mxListener->firing( aScriptEventCopy ); 151 } 152 catch( const Exception& ) 153 { 154 DBG_UNHANDLED_EXCEPTION(); 155 } 156 } 157 } 158 159 //......................................................................... 160 161 // ============================================================================= 162 // DialogEventsAttacherImpl 163 // ============================================================================= 164 165 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 ) 166 :mbUseFakeVBAEvents( false ), m_xContext( rxContext ) 167 { 168 // key listeners by protocol when ScriptType = 'Script' 169 // otherwise key is the ScriptType e.g. StarBasic 170 if ( rxRTLListener.is() ) // set up handler for RTL_BASIC 171 listernersForTypes[ rtl::OUString::createFromAscii("StarBasic") ] = rxRTLListener; 172 else 173 listernersForTypes[ rtl::OUString::createFromAscii("StarBasic") ] = new DialogLegacyScriptListenerImpl( rxContext, rxModel ); 174 // handler for Script & ::rtl::OUString::createFromAscii( "vnd.sun.star.UNO:" ) 175 listernersForTypes[ rtl::OUString::createFromAscii("vnd.sun.star.UNO") ] = new DialogUnoScriptListenerImpl( rxContext, rxModel, rxControl, rxHandler, rxIntrospect, bProviderMode ); 176 listernersForTypes[ rtl::OUString::createFromAscii("vnd.sun.star.script") ] = new DialogSFScriptListenerImpl( rxContext, rxModel ); 177 178 // determine the VBA compatibility mode from the Basic library container 179 try 180 { 181 uno::Reference< beans::XPropertySet > xModelProps( rxModel, uno::UNO_QUERY_THROW ); 182 uno::Reference< script::vba::XVBACompatibility > xVBACompat( 183 xModelProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicLibraries" ) ) ), uno::UNO_QUERY_THROW ); 184 mbUseFakeVBAEvents = xVBACompat->getVBACompatibilityMode(); 185 } 186 catch( uno::Exception& ) 187 { 188 } 189 if ( mbUseFakeVBAEvents ) 190 listernersForTypes[ rtl::OUString::createFromAscii("VBAInterop") ] = new DialogVBAScriptListenerImpl( rxContext, rxControl, rxModel ); 191 } 192 193 // ----------------------------------------------------------------------------- 194 195 DialogEventsAttacherImpl::~DialogEventsAttacherImpl() 196 { 197 } 198 199 // ----------------------------------------------------------------------------- 200 Reference< script::XScriptListener > 201 DialogEventsAttacherImpl::getScriptListenerForKey( const rtl::OUString& sKey ) throw ( RuntimeException ) 202 { 203 ListenerHash::iterator it = listernersForTypes.find( sKey ); 204 if ( it == listernersForTypes.end() ) 205 throw RuntimeException(); // more text info here please 206 return it->second; 207 } 208 Reference< XScriptEventsSupplier > DialogEventsAttacherImpl::getFakeVbaEventsSupplier( const Reference< XControl >& xControl, rtl::OUString& sControlName ) 209 { 210 Reference< XScriptEventsSupplier > xEventsSupplier; 211 Reference< XMultiComponentFactory > xSMgr( m_xContext->getServiceManager() ); 212 if ( xSMgr.is() ) 213 { 214 Reference< ooo::vba::XVBAToOOEventDescGen > xVBAToOOEvtDesc( xSMgr->createInstanceWithContext( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAToOOEventDesc" ) ), m_xContext ), UNO_QUERY ); 215 if ( xVBAToOOEvtDesc.is() ) 216 xEventsSupplier.set( xVBAToOOEvtDesc->getEventSupplier( xControl, sControlName ), UNO_QUERY ); 217 } 218 return xEventsSupplier; 219 } 220 221 // ----------------------------------------------------------------------------- 222 void SAL_CALL DialogEventsAttacherImpl::attachEventsToControl( const Reference< XControl>& xControl, const Reference< XScriptEventsSupplier >& xEventsSupplier, const Any& Helper ) 223 { 224 if ( xEventsSupplier.is() ) 225 { 226 Reference< container::XNameContainer > xEventCont = xEventsSupplier->getEvents(); 227 228 Reference< XControlModel > xControlModel = xControl->getModel(); 229 if ( xEventCont.is() ) 230 { 231 Sequence< ::rtl::OUString > aNames = xEventCont->getElementNames(); 232 const ::rtl::OUString* pNames = aNames.getConstArray(); 233 sal_Int32 nNameCount = aNames.getLength(); 234 235 for ( sal_Int32 j = 0; j < nNameCount; ++j ) 236 { 237 ScriptEventDescriptor aDesc; 238 239 Any aElement = xEventCont->getByName( pNames[ j ] ); 240 aElement >>= aDesc; 241 rtl::OUString sKey = aDesc.ScriptType; 242 if ( aDesc.ScriptType.equals( rtl::OUString::createFromAscii("Script" ) ) || aDesc.ScriptType.equals( rtl::OUString::createFromAscii("UNO" ) ) ) 243 { 244 sal_Int32 nIndex = aDesc.ScriptCode.indexOf( ':' ); 245 sKey = aDesc.ScriptCode.copy( 0, nIndex ); 246 } 247 Reference< XAllListener > xAllListener = 248 new DialogAllListenerImpl( getScriptListenerForKey( sKey ), aDesc.ScriptType, aDesc.ScriptCode ); 249 250 // try first to attach event to the ControlModel 251 bool bSuccess = false; 252 try 253 { 254 Reference< XEventListener > xListener_ = m_xEventAttacher->attachSingleEventListener( 255 xControlModel, xAllListener, Helper, aDesc.ListenerType, 256 aDesc.AddListenerParam, aDesc.EventMethod ); 257 258 if ( xListener_.is() ) 259 bSuccess = true; 260 } 261 catch ( const Exception& ) 262 { 263 DBG_UNHANDLED_EXCEPTION(); 264 } 265 266 try 267 { 268 // if we had no success, try to attach to the control 269 if ( !bSuccess ) 270 { 271 Reference< XEventListener > xListener_ = m_xEventAttacher->attachSingleEventListener( 272 xControl, xAllListener, Helper, aDesc.ListenerType, 273 aDesc.AddListenerParam, aDesc.EventMethod ); 274 } 275 } 276 catch ( const Exception& ) 277 { 278 DBG_UNHANDLED_EXCEPTION(); 279 } 280 } 281 } 282 } 283 } 284 285 // ----------------------------------------------------------------------------- 286 // XScriptEventsAttacher 287 // ----------------------------------------------------------------------------- 288 289 void SAL_CALL DialogEventsAttacherImpl::attachEvents( const Sequence< Reference< XInterface > >& Objects, 290 const com::sun::star::uno::Reference<com::sun::star::script::XScriptListener>&, 291 const Any& Helper ) 292 throw (IllegalArgumentException, IntrospectionException, CannotCreateAdapterException, 293 ServiceNotRegisteredException, RuntimeException) 294 { 295 // get EventAttacher 296 { 297 ::osl::MutexGuard aGuard( getMutex() ); 298 299 if ( !m_xEventAttacher.is() ) 300 { 301 Reference< XMultiComponentFactory > xSMgr( m_xContext->getServiceManager() ); 302 if ( xSMgr.is() ) 303 { 304 m_xEventAttacher = Reference< XEventAttacher >( xSMgr->createInstanceWithContext( 305 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.script.EventAttacher" ) ), m_xContext ), UNO_QUERY ); 306 307 if ( !m_xEventAttacher.is() ) 308 throw ServiceNotRegisteredException(); 309 } 310 else 311 { 312 throw RuntimeException(); 313 } 314 315 } 316 } 317 318 // go over all objects 319 const Reference< XInterface >* pObjects = Objects.getConstArray(); 320 sal_Int32 nObjCount = Objects.getLength(); 321 Reference< awt::XControl > xDlgControl( Objects[ nObjCount - 1 ], uno::UNO_QUERY ); // last object is the dialog 322 rtl::OUString sDialogCodeName; 323 if ( xDlgControl.is() ) 324 { 325 Reference< XPropertySet > xProps( xDlgControl->getModel(), UNO_QUERY ); 326 try 327 { 328 xProps->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name") ) ) >>= sDialogCodeName; 329 } 330 catch( Exception& ){} 331 } 332 333 for ( sal_Int32 i = 0; i < nObjCount; ++i ) 334 { 335 // We know that we have to do with instances of XControl. 336 // Otherwise this is not the right implementation for 337 // XScriptEventsAttacher and we have to give up. 338 Reference< XControl > xControl( pObjects[ i ], UNO_QUERY ); 339 if ( !xControl.is() ) 340 throw IllegalArgumentException(); 341 342 // get XEventsSupplier from control model 343 Reference< XControlModel > xControlModel = xControl->getModel(); 344 Reference< XScriptEventsSupplier > xEventsSupplier( xControlModel, UNO_QUERY ); 345 attachEventsToControl( xControl, xEventsSupplier, Helper ); 346 if ( mbUseFakeVBAEvents ) 347 { 348 xEventsSupplier.set( getFakeVbaEventsSupplier( xControl, sDialogCodeName ) ); 349 attachEventsToControl( xControl, xEventsSupplier, Helper ); 350 } 351 } 352 } 353 354 355 // ============================================================================= 356 // DialogAllListenerImpl 357 // ============================================================================= 358 359 DialogAllListenerImpl::DialogAllListenerImpl( const Reference< XScriptListener >& rxListener, 360 const ::rtl::OUString& rScriptType, const ::rtl::OUString& rScriptCode ) 361 :m_xScriptListener( rxListener ) 362 ,m_sScriptType( rScriptType ) 363 ,m_sScriptCode( rScriptCode ) 364 { 365 } 366 367 // ----------------------------------------------------------------------------- 368 369 DialogAllListenerImpl::~DialogAllListenerImpl() 370 { 371 } 372 373 // ----------------------------------------------------------------------------- 374 375 void DialogAllListenerImpl::firing_impl( const AllEventObject& Event, Any* pRet ) 376 { 377 ScriptEvent aScriptEvent; 378 aScriptEvent.Source = (OWeakObject *)this; // get correct XInterface 379 aScriptEvent.ListenerType = Event.ListenerType; 380 aScriptEvent.MethodName = Event.MethodName; 381 aScriptEvent.Arguments = Event.Arguments; 382 aScriptEvent.Helper = Event.Helper; 383 aScriptEvent.ScriptType = m_sScriptType; 384 aScriptEvent.ScriptCode = m_sScriptCode; 385 386 if ( m_xScriptListener.is() ) 387 { 388 if ( pRet ) 389 *pRet = m_xScriptListener->approveFiring( aScriptEvent ); 390 else 391 m_xScriptListener->firing( aScriptEvent ); 392 } 393 } 394 395 // ----------------------------------------------------------------------------- 396 // XEventListener 397 // ----------------------------------------------------------------------------- 398 399 void DialogAllListenerImpl::disposing(const EventObject& ) throw ( RuntimeException ) 400 { 401 } 402 403 // ----------------------------------------------------------------------------- 404 // XAllListener 405 // ----------------------------------------------------------------------------- 406 407 void DialogAllListenerImpl::firing( const AllEventObject& Event ) throw ( RuntimeException ) 408 { 409 ::osl::MutexGuard aGuard( getMutex() ); 410 411 firing_impl( Event, NULL ); 412 } 413 414 // ----------------------------------------------------------------------------- 415 416 Any DialogAllListenerImpl::approveFiring( const AllEventObject& Event ) 417 throw ( reflection::InvocationTargetException, RuntimeException ) 418 { 419 ::osl::MutexGuard aGuard( getMutex() ); 420 421 Any aReturn; 422 firing_impl( Event, &aReturn ); 423 return aReturn; 424 } 425 426 427 // ============================================================================= 428 // DialogScriptListenerImpl 429 // ============================================================================= 430 431 DialogUnoScriptListenerImpl::DialogUnoScriptListenerImpl( const Reference< XComponentContext >& rxContext, 432 const Reference< ::com::sun::star::frame::XModel >& rxModel, 433 const Reference< ::com::sun::star::awt::XControl >& rxControl, 434 const Reference< ::com::sun::star::uno::XInterface >& rxHandler, 435 const Reference< ::com::sun::star::beans::XIntrospectionAccess >& rxIntrospectionAccess, 436 bool bDialogProviderMode ) 437 : DialogSFScriptListenerImpl( rxContext, rxModel ) 438 ,m_xControl( rxControl ) 439 ,m_xHandler( rxHandler ) 440 ,m_xIntrospectionAccess( rxIntrospectionAccess ) 441 ,m_bDialogProviderMode( bDialogProviderMode ) 442 { 443 } 444 445 // ----------------------------------------------------------------------------- 446 447 DialogScriptListenerImpl::~DialogScriptListenerImpl() 448 { 449 } 450 451 // ----------------------------------------------------------------------------- 452 void DialogSFScriptListenerImpl::firing_impl( const ScriptEvent& aScriptEvent, Any* pRet ) 453 { 454 try 455 { 456 Reference< provider::XScriptProvider > xScriptProvider; 457 if ( m_xModel.is() ) 458 { 459 Reference< provider::XScriptProviderSupplier > xSupplier( m_xModel, UNO_QUERY ); 460 OSL_ENSURE( xSupplier.is(), "DialogScriptListenerImpl::firing_impl: failed to get script provider supplier" ); 461 if ( xSupplier.is() ) 462 xScriptProvider.set( xSupplier->getScriptProvider() ); 463 } 464 else 465 { 466 OSL_ASSERT( m_xContext.is() ); 467 if ( m_xContext.is() ) 468 { 469 Reference< provider::XScriptProviderFactory > xFactory( 470 m_xContext->getValueByName( 471 ::rtl::OUString::createFromAscii( "/singletons/com.sun.star.script.provider.theMasterScriptProviderFactory" ) ), 472 UNO_QUERY ); 473 OSL_ENSURE( xFactory.is(), "SFURL_firing_impl: failed to get master script provider factory" ); 474 if ( xFactory.is() ) 475 { 476 Any aCtx; 477 aCtx <<= ::rtl::OUString::createFromAscii( "user" ); 478 xScriptProvider.set( xFactory->createScriptProvider( aCtx ), UNO_QUERY ); 479 } 480 } 481 } 482 483 OSL_ENSURE( xScriptProvider.is(), "DialogScriptListenerImpl::firing_impl: failed to get script provider" ); 484 485 if ( xScriptProvider.is() ) 486 { 487 Reference< provider::XScript > xScript = xScriptProvider->getScript( aScriptEvent.ScriptCode ); 488 OSL_ENSURE( xScript.is(), "DialogScriptListenerImpl::firing_impl: failed to get script" ); 489 490 if ( xScript.is() ) 491 { 492 Sequence< Any > aInParams; 493 Sequence< sal_Int16 > aOutParamsIndex; 494 Sequence< Any > aOutParams; 495 496 // get arguments for script 497 aInParams = aScriptEvent.Arguments; 498 499 Any aResult = xScript->invoke( aInParams, aOutParamsIndex, aOutParams ); 500 if ( pRet ) 501 *pRet = aResult; 502 } 503 } 504 } 505 catch ( const Exception& ) 506 { 507 DBG_UNHANDLED_EXCEPTION(); 508 } 509 } 510 511 void DialogLegacyScriptListenerImpl::firing_impl( const ScriptEvent& aScriptEvent, Any* pRet ) 512 { 513 ::rtl::OUString sScriptURL; 514 ::rtl::OUString sScriptCode( aScriptEvent.ScriptCode ); 515 516 if ( aScriptEvent.ScriptType.compareToAscii( "StarBasic" ) == 0 ) 517 { 518 // StarBasic script: convert ScriptCode to scriptURL 519 sal_Int32 nIndex = sScriptCode.indexOf( ':' ); 520 if ( nIndex >= 0 && nIndex < sScriptCode.getLength() ) 521 { 522 sScriptURL = ::rtl::OUString::createFromAscii( "vnd.sun.star.script:" ); 523 sScriptURL += sScriptCode.copy( nIndex + 1 ); 524 sScriptURL += ::rtl::OUString::createFromAscii( "?language=Basic&location=" ); 525 sScriptURL += sScriptCode.copy( 0, nIndex ); 526 } 527 ScriptEvent aSFScriptEvent( aScriptEvent ); 528 aSFScriptEvent.ScriptCode = sScriptURL; 529 DialogSFScriptListenerImpl::firing_impl( aSFScriptEvent, pRet ); 530 } 531 } 532 533 void DialogUnoScriptListenerImpl::firing_impl( const ScriptEvent& aScriptEvent, Any* pRet ) 534 { 535 static ::rtl::OUString sUnoURLScheme = ::rtl::OUString::createFromAscii( "vnd.sun.star.UNO:" ); 536 537 ::rtl::OUString sScriptCode( aScriptEvent.ScriptCode ); 538 ::rtl::OUString aMethodName = aScriptEvent.ScriptCode.copy( sUnoURLScheme.getLength() ); 539 540 const Any* pArguments = aScriptEvent.Arguments.getConstArray(); 541 Any aEventObject = pArguments[0]; 542 543 bool bHandled = false; 544 if( m_xHandler.is() ) 545 { 546 if( m_bDialogProviderMode ) 547 { 548 Reference< XDialogEventHandler > xDialogEventHandler( m_xHandler, UNO_QUERY ); 549 if( xDialogEventHandler.is() ) 550 { 551 Reference< XDialog > xDialog( m_xControl, UNO_QUERY ); 552 bHandled = xDialogEventHandler->callHandlerMethod( xDialog, aEventObject, aMethodName ); 553 } 554 } 555 else 556 { 557 Reference< XContainerWindowEventHandler > xContainerWindowEventHandler( m_xHandler, UNO_QUERY ); 558 if( xContainerWindowEventHandler.is() ) 559 { 560 Reference< XWindow > xWindow( m_xControl, UNO_QUERY ); 561 bHandled = xContainerWindowEventHandler->callHandlerMethod( xWindow, aEventObject, aMethodName ); 562 } 563 } 564 } 565 566 Any aRet; 567 if( !bHandled && m_xIntrospectionAccess.is() ) 568 { 569 try 570 { 571 // Methode ansprechen 572 const Reference< XIdlMethod >& rxMethod = m_xIntrospectionAccess-> 573 getMethod( aMethodName, MethodConcept::ALL - MethodConcept::DANGEROUS ); 574 575 Reference< XMaterialHolder > xMaterialHolder = 576 Reference< XMaterialHolder >::query( m_xIntrospectionAccess ); 577 Any aHandlerObject = xMaterialHolder->getMaterial(); 578 579 Sequence< Reference< XIdlClass > > aParamTypeSeq = rxMethod->getParameterTypes(); 580 sal_Int32 nParamCount = aParamTypeSeq.getLength(); 581 if( nParamCount == 0 ) 582 { 583 Sequence<Any> args; 584 rxMethod->invoke( aHandlerObject, args ); 585 bHandled = true; 586 } 587 else if( nParamCount == 2 ) 588 { 589 // Signature check automatically done by reflection 590 Sequence<Any> Args(2); 591 Any* pArgs = Args.getArray(); 592 if( m_bDialogProviderMode ) 593 { 594 Reference< XDialog > xDialog( m_xControl, UNO_QUERY ); 595 pArgs[0] <<= xDialog; 596 } 597 else 598 { 599 Reference< XWindow > xWindow( m_xControl, UNO_QUERY ); 600 pArgs[0] <<= xWindow; 601 } 602 pArgs[1] = aEventObject; 603 aRet = rxMethod->invoke( aHandlerObject, Args ); 604 bHandled = true; 605 } 606 } 607 catch( const Exception& ) 608 { 609 DBG_UNHANDLED_EXCEPTION(); 610 } 611 } 612 613 if( bHandled ) 614 { 615 if( pRet ) 616 *pRet = aRet; 617 } 618 else 619 { 620 ResMgr* pResMgr = SFX_APP()->GetSfxResManager(); 621 if( pResMgr ) 622 { 623 String aRes( ResId(STR_ERRUNOEVENTBINDUNG, *pResMgr) ); 624 ::rtl::OUString aQuoteChar( RTL_CONSTASCII_USTRINGPARAM( "\"" ) ); 625 626 ::rtl::OUString aOURes = aRes; 627 sal_Int32 nIndex = aOURes.indexOf( '%' ); 628 629 ::rtl::OUString aOUFinal; 630 aOUFinal += aOURes.copy( 0, nIndex ); 631 aOUFinal += aQuoteChar; 632 aOUFinal += aMethodName; 633 aOUFinal += aQuoteChar; 634 aOUFinal += aOURes.copy( nIndex + 2 ); 635 636 ErrorBox( NULL, WinBits( WB_OK ), aOUFinal ).Execute(); 637 } 638 } 639 } 640 641 // ----------------------------------------------------------------------------- 642 // XEventListener 643 // ----------------------------------------------------------------------------- 644 645 void DialogScriptListenerImpl::disposing(const EventObject& ) throw ( RuntimeException ) 646 { 647 } 648 649 // ----------------------------------------------------------------------------- 650 // XScriptListener 651 // ----------------------------------------------------------------------------- 652 653 void DialogScriptListenerImpl::firing( const ScriptEvent& aScriptEvent ) throw ( RuntimeException ) 654 { 655 ::osl::MutexGuard aGuard( getMutex() ); 656 657 firing_impl( aScriptEvent, NULL ); 658 } 659 660 // ----------------------------------------------------------------------------- 661 662 Any DialogScriptListenerImpl::approveFiring( const ScriptEvent& aScriptEvent ) 663 throw ( reflection::InvocationTargetException, RuntimeException ) 664 { 665 ::osl::MutexGuard aGuard( getMutex() ); 666 667 Any aReturn; 668 firing_impl( aScriptEvent, &aReturn ); 669 return aReturn; 670 } 671 672 // ----------------------------------------------------------------------------- 673 674 //......................................................................... 675 } // namespace dlgprov 676 //......................................................................... 677