LCOV - code coverage report
Current view: top level - basic/source/classes - eventatt.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 240 0.0 %
Date: 2014-04-14 Functions: 0 11 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10