LCOV - code coverage report
Current view: top level - basic/source/classes - eventatt.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 253 0.0 %
Date: 2012-08-25 Functions: 0 11 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 617 0.0 %

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

Generated by: LCOV version 1.10