xref: /trunk/main/basic/source/classes/eventatt.cxx (revision e1f63238)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_basic.hxx"
26 
27 //#include <stl_queue.h>
28 #include <osl/mutex.hxx>
29 #include <comphelper/processfactory.hxx>
30 
31 
32 #include <com/sun/star/script/XEventAttacher.hpp>
33 #include <com/sun/star/script/XAllListener.hpp>
34 #include <com/sun/star/script/XScriptEventsSupplier.hpp>
35 #include <com/sun/star/script/XScriptEventsAttacher.hpp>
36 #include <com/sun/star/script/ScriptEventDescriptor.hpp>
37 #include <com/sun/star/script/XLibraryContainer.hpp>
38 #include <com/sun/star/beans/XPropertySet.hpp>
39 #include <com/sun/star/container/XNameContainer.hpp>
40 #include <com/sun/star/resource/XStringResourceSupplier.hpp>
41 #include <com/sun/star/resource/XStringResourceManager.hpp>
42 #include <com/sun/star/awt/XControlContainer.hpp>
43 #include <com/sun/star/awt/XControlModel.hpp>
44 #include <com/sun/star/awt/XControl.hpp>
45 #include <com/sun/star/awt/XDialog.hpp>
46 #include <com/sun/star/awt/XWindow.hpp>
47 #include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
48 
49 #include <com/sun/star/script/provider/XScriptProviderSupplier.hpp>
50 #include <com/sun/star/script/provider/XScriptProvider.hpp>
51 #include <com/sun/star/awt/XDialogProvider.hpp>
52 
53 #include <com/sun/star/frame/XModel.hpp>
54 #include <com/sun/star/frame/XDesktop.hpp>
55 #include <com/sun/star/container/XEnumerationAccess.hpp>
56 #include <basic/basicmanagerrepository.hxx>
57 #include <basic/basmgr.hxx>
58 //==================================================================================================
59 
60 #include <xmlscript/xmldlg_imexp.hxx>
61 #include <sbunoobj.hxx>
62 #include <basic/sbstar.hxx>
63 #include <basic/sbmeth.hxx>
64 #include <basic/sbuno.hxx>
65 #include <runtime.hxx>
66 #include <sbintern.hxx>
67 
68 
69 #include <cppuhelper/implbase1.hxx>
70 using namespace ::com::sun::star;
71 using namespace ::com::sun::star::uno;
72 using namespace ::com::sun::star::script;
73 using namespace ::com::sun::star::resource;
74 
75 using namespace ::com::sun::star::uno;
76 using namespace ::com::sun::star::lang;
77 using namespace ::com::sun::star::beans;
78 using namespace ::com::sun::star::script;
79 using namespace ::com::sun::star::container;
80 using namespace ::com::sun::star::reflection;
81 using namespace ::com::sun::star::awt;
82 using namespace ::com::sun::star::io;
83 using namespace ::cppu;
84 using namespace ::osl;
85 
86 
SFURL_firing_impl(const ScriptEvent & aScriptEvent,Any * pRet,const Reference<frame::XModel> & xModel)87 void SFURL_firing_impl( const ScriptEvent& aScriptEvent, Any* pRet, const Reference< frame::XModel >& xModel )
88 {
89         OSL_TRACE("SFURL_firing_impl() processing script url %s",
90             ::rtl::OUStringToOString( aScriptEvent.ScriptCode,
91                 RTL_TEXTENCODING_ASCII_US ).pData->buffer );
92         try
93         {
94             Reference< provider::XScriptProvider > xScriptProvider;
95             if ( xModel.is() )
96             {
97                 Reference< provider::XScriptProviderSupplier > xSupplier( xModel, UNO_QUERY );
98                 OSL_ENSURE( xSupplier.is(), "SFURL_firing_impl: failed to get script provider supplier" );
99                 if ( xSupplier.is() )
100                     xScriptProvider.set( xSupplier->getScriptProvider() );
101             }
102             else
103             {
104                 Reference< XComponentContext > xContext;
105                 Reference< XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), UNO_QUERY );
106                 OSL_ASSERT( xProps.is() );
107                 OSL_VERIFY( xProps->getPropertyValue( ::rtl::OUString::createFromAscii( "DefaultContext" ) ) >>= xContext );
108                 if ( xContext.is() )
109                 {
110                     Reference< provider::XScriptProviderFactory > xFactory(
111                         xContext->getValueByName(
112                         ::rtl::OUString::createFromAscii( "/singletons/com.sun.star.script.provider.theMasterScriptProviderFactory" ) ),
113                         UNO_QUERY );
114                     OSL_ENSURE( xFactory.is(), "SFURL_firing_impl: failed to get master script provider factory" );
115                     if ( xFactory.is() )
116                     {
117                         Any aCtx;
118                         aCtx <<= ::rtl::OUString::createFromAscii( "user" );
119                         xScriptProvider.set( xFactory->createScriptProvider( aCtx ), UNO_QUERY );
120                     }
121                 }
122             }
123 
124             if ( !xScriptProvider.is() )
125             {
126                 OSL_TRACE("SFURL_firing_impl() Failed to create msp");
127                 return;
128             }
129             Sequence< Any > inArgs( 0 );
130             Sequence< Any > outArgs( 0 );
131             Sequence< sal_Int16 > outIndex;
132 
133             // get Arguments for script
134             inArgs = aScriptEvent.Arguments;
135 
136             Reference< provider::XScript > xScript = xScriptProvider->getScript( aScriptEvent.ScriptCode );
137 
138             if ( !xScript.is() )
139             {
140                 OSL_TRACE("SFURL_firing_impl() Failed to obtain XScript");
141                 return;
142             }
143 
144             Any result = xScript->invoke( inArgs, outIndex, outArgs );
145             if ( pRet )
146             {
147                 *pRet = result;
148             }
149         }
150         catch ( RuntimeException& re )
151         {
152             OSL_TRACE("SFURL_firing_impl() Caught RuntimeException reason %s.",
153                 ::rtl::OUStringToOString( re.Message,
154                     RTL_TEXTENCODING_ASCII_US ).pData->buffer );
155         }
156         catch ( Exception& e )
157         {
158             OSL_TRACE("SFURL_firing_impl() Caught Exception reason %s.",
159                 ::rtl::OUStringToOString( e.Message,
160                     RTL_TEXTENCODING_ASCII_US ).pData->buffer );
161         }
162 
163 }
164 
165 
166 class BasicScriptListener_Impl : public WeakImplHelper1< XScriptListener >
167 {
168 	StarBASICRef maBasicRef;
169         Reference< frame::XModel > m_xModel;
170 
171 	virtual void firing_impl(const ScriptEvent& aScriptEvent, Any* pRet);
172 
173 public:
BasicScriptListener_Impl(StarBASIC * pBasic,const Reference<frame::XModel> & xModel)174     BasicScriptListener_Impl( StarBASIC* pBasic, const Reference< frame::XModel >& xModel )
175 		: maBasicRef( pBasic ), m_xModel( xModel ) {}
176 
177     // Methods of XAllListener
178     virtual void SAL_CALL firing(const ScriptEvent& aScriptEvent)
179 		throw( RuntimeException );
180     virtual Any SAL_CALL approveFiring(const ScriptEvent& aScriptEvent)
181 		throw( InvocationTargetException, RuntimeException );
182 
183     // Methods of XEventListener
184     virtual void SAL_CALL disposing(const EventObject& Source)
185 		throw( RuntimeException );
186 };
187 
188 // Methods XAllListener
firing(const ScriptEvent & aScriptEvent)189 void BasicScriptListener_Impl::firing( const ScriptEvent& aScriptEvent ) throw ( RuntimeException )
190 {
191 	firing_impl( aScriptEvent, NULL );
192 }
193 
approveFiring(const ScriptEvent & aScriptEvent)194 Any BasicScriptListener_Impl::approveFiring( const ScriptEvent& aScriptEvent )
195 	throw ( InvocationTargetException, RuntimeException )
196 {
197 	Any aRetAny;
198 	firing_impl( aScriptEvent, &aRetAny );
199 	return aRetAny;
200 }
201 
202 // Methods XEventListener
disposing(const EventObject &)203 void BasicScriptListener_Impl::disposing(const EventObject& ) throw ( RuntimeException )
204 {
205 	// TODO: ???
206 	//vos::OGuard guard( Application::GetSolarMutex() );
207 	//xSbxObj.Clear();
208 }
209 
210 
firing_impl(const ScriptEvent & aScriptEvent,Any * pRet)211 void BasicScriptListener_Impl::firing_impl( const ScriptEvent& aScriptEvent, Any* pRet )
212 {
213 	//Guard< Mutex > aGuard( Mutex::getGlobalMutex() );
214 	//{
215 	if( aScriptEvent.ScriptType.compareToAscii( "StarBasic" ) == 0 )
216 	{
217 		// Full qualified name?
218 		String aMacro( aScriptEvent.ScriptCode );
219 		String aLibName;
220         String aLocation;
221 		if( aMacro.GetTokenCount( '.' ) == 3 )
222 		{
223 			sal_uInt16 nLast = 0;
224 			::rtl::OUString aFullLibName = aMacro.GetToken( 0, '.', nLast );
225 
226             sal_Int32 nIndex = aFullLibName.indexOf( (sal_Unicode)':' );
227             if (nIndex >= 0)
228             {
229                 aLocation = aFullLibName.copy( 0, nIndex );
230                 aLibName = aFullLibName.copy( nIndex + 1 );
231             }
232 
233 			String aModul = aMacro.GetToken( 0, '.', nLast );
234 			aMacro.Erase( 0, nLast );
235 		}
236 
237 		SbxObject* p = maBasicRef;
238 		SbxObject* pParent = p->GetParent();
239         SbxObject* pParentParent = pParent ? pParent->GetParent() : NULL;
240 
241         StarBASICRef xAppStandardBasic;
242         StarBASICRef xDocStandardBasic;
243         if( pParentParent )
244         {
245             // Own basic must be document library
246             xAppStandardBasic = (StarBASIC*)pParentParent;
247             xDocStandardBasic = (StarBASIC*)pParent;
248         }
249         else if( pParent )
250         {
251             String aName = p->GetName();
252             if( aName.EqualsAscii("Standard") )
253             {
254                 // Own basic is doc standard lib
255                 xDocStandardBasic = (StarBASIC*)p;
256             }
257             xAppStandardBasic = (StarBASIC*)pParent;
258         }
259         else
260         {
261             xAppStandardBasic = (StarBASIC*)p;
262         }
263 
264         sal_Bool bSearchLib = true;
265         StarBASICRef xLibSearchBasic;
266         if( aLocation.EqualsAscii("application") )
267             xLibSearchBasic = xAppStandardBasic;
268         else if( aLocation.EqualsAscii("document") )
269             xLibSearchBasic = xDocStandardBasic;
270         else
271             bSearchLib = false;
272 
273         SbxVariable* pMethVar = NULL;
274         // Be still tolerant and make default search if no search basic exists
275         if( bSearchLib && xLibSearchBasic.Is() )
276         {
277             StarBASICRef xLibBasic;
278 	        sal_Int16 nCount = xLibSearchBasic->GetObjects()->Count();
279 	        for( sal_Int16 nObj = -1; nObj < nCount ; nObj++ )
280 	        {
281                 StarBASIC* pBasic;
282                 if( nObj == -1 )
283                 {
284 		            pBasic = (StarBASIC*)xLibSearchBasic;
285                 }
286                 else
287                 {
288 		            SbxVariable* pVar = xLibSearchBasic->GetObjects()->Get( nObj );
289 		            pBasic = PTR_CAST(StarBASIC,pVar);
290                 }
291 		        if( pBasic )
292                 {
293                     String aName = pBasic->GetName();
294                     if( aName == aLibName )
295                     {
296                         // Search only in the lib, not automatically in application basic
297 			            sal_uInt16 nFlags = pBasic->GetFlags();
298 			            pBasic->ResetFlag( SBX_GBLSEARCH );
299 		                pMethVar = pBasic->Find( aMacro, SbxCLASS_DONTCARE );
300 			            pBasic->SetFlags( nFlags );
301                         break;
302                     }
303                 }
304 	        }
305         }
306 
307         // Default: Be tolerant and search everywhere
308 		if( (!pMethVar || !pMethVar->ISA(SbMethod)) && maBasicRef.Is() )
309 			pMethVar = maBasicRef->FindQualified( aMacro, SbxCLASS_DONTCARE );
310 
311 		SbMethod* pMeth = PTR_CAST(SbMethod,pMethVar);
312 		if( !pMeth )
313 		    return;
314 
315 		// Setup parameters
316 		SbxArrayRef xArray;
317 		String aTmp;
318 		sal_Int32 nCnt = aScriptEvent.Arguments.getLength();
319 		if( nCnt )
320 		{
321 			xArray = new SbxArray;
322 			const Any *pArgs = aScriptEvent.Arguments.getConstArray();
323 			for( sal_Int32 i = 0; i < nCnt; i++ )
324 			{
325 				SbxVariableRef xVar = new SbxVariable( SbxVARIANT );
326 				unoToSbxValue( (SbxVariable*)xVar, pArgs[i] );
327 				xArray->Put( xVar, sal::static_int_cast< sal_uInt16 >(i+1) );
328 			}
329 		}
330 
331 		// Call method
332 		SbxVariableRef xValue = pRet ? new SbxVariable : 0;
333 		if( xArray.Is() )
334 			pMeth->SetParameters( xArray );
335 		pMeth->Call( xValue );
336 		if( pRet )
337 			*pRet = sbxToUnoValue( xValue );
338 		pMeth->SetParameters( NULL );
339 	}
340         else // scripting framework script
341         {
342             //callBasic via scripting framework
343             SFURL_firing_impl( aScriptEvent, pRet, m_xModel );
344 
345         }
346 }
347 
implFindDialogLibForDialog(const Any & rDlgAny,SbxObject * pBasic)348 Any implFindDialogLibForDialog( const Any& rDlgAny, SbxObject* pBasic )
349 {
350 	Any aRetDlgLibAny;
351 
352     SbxVariable* pDlgLibContVar = pBasic->Find
353 		(  String::CreateFromAscii("DialogLibraries"), SbxCLASS_OBJECT );
354 	if( pDlgLibContVar && pDlgLibContVar->ISA(SbUnoObject) )
355 	{
356 		SbUnoObject* pDlgLibContUnoObj = (SbUnoObject*)(SbxBase*)pDlgLibContVar;
357 		Any aDlgLibContAny = pDlgLibContUnoObj->getUnoAny();
358 
359 		Reference< XLibraryContainer > xDlgLibContNameAccess( aDlgLibContAny, UNO_QUERY );
360         OSL_ENSURE( xDlgLibContNameAccess.is(), "implFindDialogLibForDialog: no lib container for the given dialog!" );
361 		if( xDlgLibContNameAccess.is() )
362 		{
363 			Sequence< ::rtl::OUString > aLibNames = xDlgLibContNameAccess->getElementNames();
364 			const ::rtl::OUString* pLibNames = aLibNames.getConstArray();
365 			sal_Int32 nLibNameCount = aLibNames.getLength();
366 
367 			for( sal_Int32 iLib = 0 ; iLib < nLibNameCount ; iLib++ )
368 			{
369                 if ( !xDlgLibContNameAccess->isLibraryLoaded( pLibNames[ iLib ] ) )
370                     // if the library isn't loaded, then the dialog cannot originate from this lib
371                     continue;
372 
373 				Any aDlgLibAny = xDlgLibContNameAccess->getByName( pLibNames[ iLib ] );
374 
375 				Reference< XNameAccess > xDlgLibNameAccess( aDlgLibAny, UNO_QUERY );
376                 OSL_ENSURE( xDlgLibNameAccess.is(), "implFindDialogLibForDialog: invalid dialog lib!" );
377 				if( xDlgLibNameAccess.is() )
378 				{
379 					Sequence< ::rtl::OUString > aDlgNames = xDlgLibNameAccess->getElementNames();
380 					const ::rtl::OUString* pDlgNames = aDlgNames.getConstArray();
381 					sal_Int32 nDlgNameCount = aDlgNames.getLength();
382 
383 					for( sal_Int32 iDlg = 0 ; iDlg < nDlgNameCount ; iDlg++ )
384 					{
385 						Any aDlgAny = xDlgLibNameAccess->getByName( pDlgNames[ iDlg ] );
386 						if( aDlgAny == rDlgAny )
387 						{
388 							aRetDlgLibAny = aDlgLibAny;
389 							break;
390 						}
391 					}
392 				}
393 			}
394 		}
395 	}
396 
397 	return aRetDlgLibAny;
398 }
399 
implFindDialogLibForDialogBasic(const Any & aAnyISP,SbxObject * pBasic,StarBASIC * & pFoundBasic)400 Any implFindDialogLibForDialogBasic( const Any& aAnyISP, SbxObject* pBasic, StarBASIC*& pFoundBasic )
401 {
402 	Any aDlgLibAny;
403 	// Find dialog library for dialog, direct access is not possible here
404     StarBASIC* pStartedBasic = (StarBASIC*)pBasic;
405 	SbxObject* pParentBasic = pStartedBasic ? pStartedBasic->GetParent() : NULL;
406 	SbxObject* pParentParentBasic = pParentBasic ? pParentBasic->GetParent() : NULL;
407 
408 	SbxObject* pSearchBasic1 = NULL;
409 	SbxObject* pSearchBasic2 = NULL;
410 	if( pParentParentBasic )
411 	{
412 		pSearchBasic1 = pParentBasic;
413 		pSearchBasic2 = pParentParentBasic;
414 	}
415 	else
416 	{
417 		pSearchBasic1 = pStartedBasic;
418 		pSearchBasic2 = pParentBasic;
419 	}
420 	if( pSearchBasic1 )
421 	{
422 		aDlgLibAny = implFindDialogLibForDialog( aAnyISP, pSearchBasic1 );
423 
424 		if ( aDlgLibAny.hasValue() )
425 			pFoundBasic = (StarBASIC*)pSearchBasic1;
426 
427 		else if( pSearchBasic2 )
428 		{
429 			aDlgLibAny = implFindDialogLibForDialog( aAnyISP, pSearchBasic2 );
430 			if ( aDlgLibAny.hasValue() )
431 				pFoundBasic = (StarBASIC*)pSearchBasic2;
432 		}
433 	}
434 	return aDlgLibAny;
435 }
436 
437 static ::rtl::OUString aDecorationPropName =
438 	::rtl::OUString::createFromAscii( "Decoration" );
439 static ::rtl::OUString aTitlePropName =
440 	::rtl::OUString::createFromAscii( "Title" );
441 
RTL_Impl_CreateUnoDialog(StarBASIC * pBasic,SbxArray & rPar,sal_Bool bWrite)442 void RTL_Impl_CreateUnoDialog( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite )
443 {
444 	static ::rtl::OUString aResourceResolverPropName = ::rtl::OUString::createFromAscii( "ResourceResolver" );
445 
446     (void)pBasic;
447     (void)bWrite;
448 
449 	Reference< XMultiServiceFactory > xMSF( comphelper::getProcessServiceFactory() );
450 	if( !xMSF.is() )
451 		return;
452 
453 	// We need at least 1 parameter
454 	if ( rPar.Count() < 2 )
455 	{
456 		StarBASIC::Error( SbERR_BAD_ARGUMENT );
457 		return;
458     }
459 
460 	// Get dialog
461 	SbxBaseRef pObj = (SbxBase*)rPar.Get( 1 )->GetObject();
462 	if( !(pObj && pObj->ISA(SbUnoObject)) )
463 	{
464 		StarBASIC::Error( SbERR_BAD_ARGUMENT );
465 		return;
466 	}
467 	SbUnoObject* pUnoObj = (SbUnoObject*)(SbxBase*)pObj;
468 	Any aAnyISP = pUnoObj->getUnoAny();
469 	TypeClass eType = aAnyISP.getValueType().getTypeClass();
470 
471 	if( eType != TypeClass_INTERFACE )
472 	{
473 		StarBASIC::Error( SbERR_BAD_ARGUMENT );
474 		return;
475 	}
476 
477 	// Create new uno dialog
478 	Reference< XNameContainer > xDialogModel( xMSF->createInstance
479 		( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDialogModel" ) ) ),
480 			UNO_QUERY );
481 	if( !xDialogModel.is() )
482 		return;
483 
484 	Reference< XInputStreamProvider > xISP;
485 	aAnyISP >>= xISP;
486 	if( !xISP.is() )
487 		return;
488 
489     Reference< XComponentContext > xContext;
490     Reference< XPropertySet > xProps( xMSF, UNO_QUERY );
491     OSL_ASSERT( xProps.is() );
492     OSL_VERIFY( xProps->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xContext );
493 
494 	// Import the DialogModel
495 	Reference< XInputStream > xInput( xISP->createInputStream() );
496 
497 	// i83963 Force decoration
498 	uno::Reference< beans::XPropertySet > xDlgModPropSet( xDialogModel, uno::UNO_QUERY );
499 	if( xDlgModPropSet.is() )
500 	{
501 		bool bDecoration = true;
502 		try
503 		{
504 			Any aDecorationAny = xDlgModPropSet->getPropertyValue( aDecorationPropName );
505 			aDecorationAny >>= bDecoration;
506 			if( !bDecoration )
507 			{
508 				xDlgModPropSet->setPropertyValue( aDecorationPropName, makeAny( true ) );
509 				xDlgModPropSet->setPropertyValue( aTitlePropName, makeAny( ::rtl::OUString() ) );
510 			}
511 		}
512 		catch( UnknownPropertyException& )
513 		{}
514 	}
515 
516     Any aDlgLibAny;
517 	bool bDocDialog = false;
518 	StarBASIC* pFoundBasic = NULL;
519     OSL_TRACE("About to try get a hold of ThisComponent");
520     Reference< frame::XModel > xModel = StarBASIC::GetModelFromBasic( pINST->GetBasic() ) ;
521 		aDlgLibAny = implFindDialogLibForDialogBasic( aAnyISP, pINST->GetBasic(), pFoundBasic );
522 		// If we found the dialog then it belongs to the Search basic
523 		if ( !pFoundBasic )
524 	{
525 			Reference< frame::XDesktop > xDesktop( xMSF->createInstance
526 		( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ) ) ),
527 			UNO_QUERY );
528 			Reference< container::XEnumeration > xModels;
529 			if ( xDesktop.is() )
530 	{
531 				Reference< container::XEnumerationAccess > xComponents( xDesktop->getComponents(), UNO_QUERY );
532 				if ( xComponents.is() )
533 					xModels.set( xComponents->createEnumeration(), UNO_QUERY );
534 				if ( xModels.is() )
535 				{
536 					while ( xModels->hasMoreElements() )
537 					{
538 						Reference< frame::XModel > xNextModel( xModels->nextElement(), UNO_QUERY );
539 						if ( xNextModel.is() )
540 						{
541 							BasicManager* pMgr = basic::BasicManagerRepository::getDocumentBasicManager( xNextModel );
542 							if ( pMgr )
543 								aDlgLibAny = implFindDialogLibForDialogBasic( aAnyISP, pMgr->GetLib(0), pFoundBasic );
544 							if ( aDlgLibAny.hasValue() )
545 	{
546 								bDocDialog = true;
547 								xModel = xNextModel;
548 								break;
549 	}
550 						}
551 					}
552 				}
553 			}
554 		}
555 	if ( pFoundBasic )
556 		bDocDialog = pFoundBasic->IsDocBasic();
557        Reference< XScriptListener > xScriptListener = new BasicScriptListener_Impl( pINST->GetBasic(), xModel );
558 
559 	Sequence< Any > aArgs( 4 );
560 	if( bDocDialog )
561 	   aArgs[ 0 ] <<= xModel;
562     else
563 	   aArgs[ 0 ] <<= uno::Reference< uno::XInterface >();
564 	aArgs[ 1 ] <<= xInput;
565 	aArgs[ 2 ] = aDlgLibAny;
566 	aArgs[ 3 ] <<= xScriptListener;
567 	// Create a "living" Dialog
568         Reference< XControl > xCntrl;
569         try
570         {
571 	    Reference< XDialogProvider >  xDlgProv( xMSF->createInstanceWithArguments( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.scripting.DialogProvider" ) ), aArgs ), UNO_QUERY );
572             xCntrl.set( xDlgProv->createDialog( rtl::OUString() ), UNO_QUERY_THROW );
573            // Add dialog model to dispose vector
574            Reference< XComponent > xDlgComponent( xCntrl->getModel(), UNO_QUERY );
575            pINST->getComponentVector().push_back( xDlgComponent );
576            // need ThisCompoent from calling script
577         }
578         // preserve existing bad behaviour, it's possible... but probably
579         // illegal to open 2 dialogs ( they ARE modal ) when this happens, sometimes
580         // create dialog fails.  So, in this case let's not throw, just leave basic
581         // detect the unset object.
582         catch( uno::Exception& )
583         {
584         }
585 
586 	// Return dialog
587 	Any aRetVal;
588 	aRetVal <<= xCntrl;
589 	SbxVariableRef refVar = rPar.Get(0);
590 	unoToSbxValue( (SbxVariable*)refVar, aRetVal );
591 }
592 
593 
594 //===================================================================
595 
596