LCOV - code coverage report
Current view: top level - scripting/source/basprov - basmethnode.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 118 0.0 %
Date: 2012-08-25 Functions: 0 21 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 210 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                 :            : #include "basmethnode.hxx"
      21                 :            : #include <com/sun/star/beans/PropertyAttribute.hpp>
      22                 :            : #include <com/sun/star/frame/XDesktop.hpp>
      23                 :            : #include <com/sun/star/frame/XDispatchHelper.hpp>
      24                 :            : #include <com/sun/star/frame/XDispatchProvider.hpp>
      25                 :            : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
      26                 :            : #include <com/sun/star/script/browse/BrowseNodeTypes.hpp>
      27                 :            : #include <osl/mutex.hxx>
      28                 :            : #include <vcl/svapp.hxx>
      29                 :            : #include <basic/sbstar.hxx>
      30                 :            : #include <basic/sbmeth.hxx>
      31                 :            : #include <basic/sbmod.hxx>
      32                 :            : 
      33                 :            : #include <util/MiscUtils.hxx>
      34                 :            : 
      35                 :            : using namespace ::com::sun::star;
      36                 :            : using namespace ::com::sun::star::lang;
      37                 :            : using namespace ::com::sun::star::uno;
      38                 :            : using namespace ::com::sun::star::beans;
      39                 :            : using namespace ::comphelper;
      40                 :            : using namespace ::com::sun::star::script;
      41                 :            : using namespace ::sf_misc;
      42                 :            : 
      43                 :            : #define BASPROV_PROPERTY_ID_URI         1
      44                 :            : #define BASPROV_PROPERTY_ID_EDITABLE    2
      45                 :            : 
      46                 :            : #define BASPROV_PROPERTY_URI            ::rtl::OUString( "URI"  )
      47                 :            : #define BASPROV_PROPERTY_EDITABLE       ::rtl::OUString( "Editable"  )
      48                 :            : 
      49                 :            : #define BASPROV_DEFAULT_ATTRIBS()       PropertyAttribute::BOUND | PropertyAttribute::TRANSIENT | PropertyAttribute::READONLY
      50                 :            : 
      51                 :            : 
      52                 :            : //.........................................................................
      53                 :            : namespace basprov
      54                 :            : {
      55                 :            : //.........................................................................
      56                 :            : 
      57                 :            :     // =============================================================================
      58                 :            :     // BasicMethodNodeImpl
      59                 :            :     // =============================================================================
      60                 :            : 
      61                 :          0 :     BasicMethodNodeImpl::BasicMethodNodeImpl( const Reference< XComponentContext >& rxContext,
      62                 :            :         const ::rtl::OUString& sScriptingContext, SbMethod* pMethod, bool isAppScript )
      63                 :            :         : ::scripting_helper::OBroadcastHelperHolder( m_aMutex )
      64                 :          0 :         ,OPropertyContainer( GetBroadcastHelper() )
      65                 :            :         ,m_xContext( rxContext )
      66                 :            :         ,m_sScriptingContext( sScriptingContext )
      67                 :            :         ,m_pMethod( pMethod )
      68                 :            :         ,m_bIsAppScript( isAppScript )
      69         [ #  # ]:          0 :         ,m_bEditable( sal_True )
           [ #  #  #  # ]
                 [ #  # ]
      70                 :            :     {
      71         [ #  # ]:          0 :         if ( m_pMethod )
      72                 :            :         {
      73                 :          0 :             SbModule* pModule = m_pMethod->GetModule();
      74         [ #  # ]:          0 :             if ( pModule )
      75                 :            :             {
      76         [ #  # ]:          0 :                 StarBASIC* pBasic = static_cast< StarBASIC* >( pModule->GetParent() );
      77         [ #  # ]:          0 :                 if ( pBasic )
      78                 :            :                 {
      79                 :          0 :                     m_sURI = ::rtl::OUString("vnd.sun.star.script:");
      80 [ #  # ][ #  # ]:          0 :                     m_sURI += pBasic->GetName();
      81                 :          0 :                     m_sURI += ::rtl::OUString(".");
      82 [ #  # ][ #  # ]:          0 :                     m_sURI += pModule->GetName();
      83                 :          0 :                     m_sURI += ::rtl::OUString(".");
      84 [ #  # ][ #  # ]:          0 :                     m_sURI += m_pMethod->GetName();
      85                 :          0 :                     m_sURI += ::rtl::OUString("?language=Basic&location=");
      86         [ #  # ]:          0 :                     if ( m_bIsAppScript )
      87                 :          0 :                         m_sURI += ::rtl::OUString("application");
      88                 :            :                     else
      89                 :          0 :                         m_sURI += ::rtl::OUString("document");
      90                 :            :                 }
      91                 :            :             }
      92                 :            :         }
      93                 :            : 
      94 [ #  # ][ #  # ]:          0 :         registerProperty( BASPROV_PROPERTY_URI,      BASPROV_PROPERTY_ID_URI,      BASPROV_DEFAULT_ATTRIBS(), &m_sURI,      ::getCppuType( &m_sURI ) );
      95 [ #  # ][ #  # ]:          0 :         registerProperty( BASPROV_PROPERTY_EDITABLE, BASPROV_PROPERTY_ID_EDITABLE, BASPROV_DEFAULT_ATTRIBS(), &m_bEditable, ::getCppuType( &m_bEditable ) );
      96                 :          0 :     }
      97                 :            : 
      98                 :            :     // -----------------------------------------------------------------------------
      99                 :            : 
     100 [ #  # ][ #  # ]:          0 :     BasicMethodNodeImpl::~BasicMethodNodeImpl()
         [ #  # ][ #  # ]
     101                 :            :     {
     102         [ #  # ]:          0 :     }
     103                 :            : 
     104                 :            :     // -----------------------------------------------------------------------------
     105                 :            :     // XInterface
     106                 :            :     // -----------------------------------------------------------------------------
     107                 :            : 
     108 [ #  # ][ #  # ]:          0 :     IMPLEMENT_FORWARD_XINTERFACE2( BasicMethodNodeImpl, BasicMethodNodeImpl_BASE, OPropertyContainer )
     109                 :            : 
     110                 :            :     // -----------------------------------------------------------------------------
     111                 :            :     // XTypeProvider
     112                 :            :     // -----------------------------------------------------------------------------
     113                 :            : 
     114 [ #  # ][ #  # ]:          0 :     IMPLEMENT_FORWARD_XTYPEPROVIDER2( BasicMethodNodeImpl, BasicMethodNodeImpl_BASE, OPropertyContainer )
                 [ #  # ]
     115                 :            : 
     116                 :            :     // -----------------------------------------------------------------------------
     117                 :            :     // XBrowseNode
     118                 :            :     // -----------------------------------------------------------------------------
     119                 :            : 
     120                 :          0 :     ::rtl::OUString BasicMethodNodeImpl::getName(  ) throw (RuntimeException)
     121                 :            :     {
     122         [ #  # ]:          0 :         SolarMutexGuard aGuard;
     123                 :            : 
     124                 :          0 :         ::rtl::OUString sMethodName;
     125         [ #  # ]:          0 :         if ( m_pMethod )
     126 [ #  # ][ #  # ]:          0 :             sMethodName = m_pMethod->GetName();
     127                 :            : 
     128         [ #  # ]:          0 :         return sMethodName;
     129                 :            :     }
     130                 :            : 
     131                 :            :     // -----------------------------------------------------------------------------
     132                 :            : 
     133                 :          0 :     Sequence< Reference< browse::XBrowseNode > > BasicMethodNodeImpl::getChildNodes(  ) throw (RuntimeException)
     134                 :            :     {
     135         [ #  # ]:          0 :         SolarMutexGuard aGuard;
     136                 :            : 
     137 [ #  # ][ #  # ]:          0 :         return Sequence< Reference< browse::XBrowseNode > >();
     138                 :            :     }
     139                 :            : 
     140                 :            :     // -----------------------------------------------------------------------------
     141                 :            : 
     142                 :          0 :     sal_Bool BasicMethodNodeImpl::hasChildNodes(  ) throw (RuntimeException)
     143                 :            :     {
     144         [ #  # ]:          0 :         SolarMutexGuard aGuard;
     145                 :            : 
     146         [ #  # ]:          0 :         return sal_False;
     147                 :            :     }
     148                 :            : 
     149                 :            :     // -----------------------------------------------------------------------------
     150                 :            : 
     151                 :          0 :     sal_Int16 BasicMethodNodeImpl::getType(  ) throw (RuntimeException)
     152                 :            :     {
     153         [ #  # ]:          0 :         SolarMutexGuard aGuard;
     154                 :            : 
     155         [ #  # ]:          0 :         return browse::BrowseNodeTypes::SCRIPT;
     156                 :            :     }
     157                 :            : 
     158                 :            :     // -----------------------------------------------------------------------------
     159                 :            :     // OPropertySetHelper
     160                 :            :     // -----------------------------------------------------------------------------
     161                 :            : 
     162                 :          0 :     ::cppu::IPropertyArrayHelper& BasicMethodNodeImpl::getInfoHelper(  )
     163                 :            :     {
     164                 :          0 :         return *getArrayHelper();
     165                 :            :     }
     166                 :            : 
     167                 :            :     // -----------------------------------------------------------------------------
     168                 :            :     // OPropertyArrayUsageHelper
     169                 :            :     // -----------------------------------------------------------------------------
     170                 :            : 
     171                 :          0 :     ::cppu::IPropertyArrayHelper* BasicMethodNodeImpl::createArrayHelper(  ) const
     172                 :            :     {
     173         [ #  # ]:          0 :         Sequence< Property > aProps;
     174         [ #  # ]:          0 :         describeProperties( aProps );
     175 [ #  # ][ #  # ]:          0 :         return new ::cppu::OPropertyArrayHelper( aProps );
     176                 :            :     }
     177                 :            : 
     178                 :            :     // -----------------------------------------------------------------------------
     179                 :            :     // XPropertySet
     180                 :            :     // -----------------------------------------------------------------------------
     181                 :            : 
     182                 :          0 :     Reference< XPropertySetInfo > BasicMethodNodeImpl::getPropertySetInfo(  ) throw (RuntimeException)
     183                 :            :     {
     184                 :          0 :         Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
     185                 :          0 :         return xInfo;
     186                 :            :     }
     187                 :            : 
     188                 :            :     // -----------------------------------------------------------------------------
     189                 :            :     // XInvocation
     190                 :            :     // -----------------------------------------------------------------------------
     191                 :            : 
     192                 :          0 :     Reference< XIntrospectionAccess > BasicMethodNodeImpl::getIntrospection(  ) throw (RuntimeException)
     193                 :            :     {
     194                 :          0 :         return Reference< XIntrospectionAccess >();
     195                 :            :     }
     196                 :            : 
     197                 :            :     // -----------------------------------------------------------------------------
     198                 :            : 
     199                 :          0 :     Any BasicMethodNodeImpl::invoke( const ::rtl::OUString& aFunctionName, const Sequence< Any >& aParams,
     200                 :            :         Sequence< sal_Int16 >& aOutParamIndex, Sequence< Any >& aOutParam )
     201                 :            :         throw (IllegalArgumentException, script::CannotConvertException,
     202                 :            :                reflection::InvocationTargetException, RuntimeException)
     203                 :            :     {
     204                 :            :         (void)aParams;
     205                 :            :         (void)aOutParamIndex;
     206                 :            :         (void)aOutParam;
     207                 :            : 
     208         [ #  # ]:          0 :         if ( aFunctionName == BASPROV_PROPERTY_EDITABLE )
     209                 :            :         {
     210                 :          0 :             ::rtl::OUString sDocURL, sLibName, sModName;
     211                 :          0 :             sal_uInt16 nLine1 = 0, nLine2;
     212                 :            : 
     213         [ #  # ]:          0 :             if ( !m_bIsAppScript )
     214                 :            :             {
     215         [ #  # ]:          0 :                 Reference< frame::XModel > xModel = MiscUtils::tDocUrlToModel( m_sScriptingContext );
     216                 :            : 
     217         [ #  # ]:          0 :                 if ( xModel.is() )
     218                 :            :                 {
     219 [ #  # ][ #  # ]:          0 :                     sDocURL = xModel->getURL();
     220         [ #  # ]:          0 :                     if ( sDocURL.isEmpty() )
     221                 :            :                     {
     222 [ #  # ][ #  # ]:          0 :                         Sequence < PropertyValue > aProps = xModel->getArgs();
     223                 :          0 :                         sal_Int32 nProps = aProps.getLength();
     224                 :          0 :                         const PropertyValue* pProps = aProps.getConstArray();
     225         [ #  # ]:          0 :                         for ( sal_Int32 i = 0; i < nProps; ++i )
     226                 :            :                         {
     227                 :            :                             // TODO: according to MBA the property 'Title' may change in future
     228         [ #  # ]:          0 :                             if ( pProps[i].Name == "Title" )
     229                 :            :                             {
     230                 :          0 :                                 pProps[i].Value >>= sDocURL;
     231                 :          0 :                                 break;
     232                 :            :                             }
     233         [ #  # ]:          0 :                         }
     234                 :            :                     }
     235                 :          0 :                 }
     236                 :            :             }
     237                 :            : 
     238         [ #  # ]:          0 :             if ( m_pMethod )
     239                 :            :             {
     240         [ #  # ]:          0 :                 m_pMethod->GetLineRange( nLine1, nLine2 );
     241                 :          0 :                 SbModule* pModule = m_pMethod->GetModule();
     242         [ #  # ]:          0 :                 if ( pModule )
     243                 :            :                 {
     244 [ #  # ][ #  # ]:          0 :                     sModName = pModule->GetName();
     245         [ #  # ]:          0 :                     StarBASIC* pBasic = static_cast< StarBASIC* >( pModule->GetParent() );
     246         [ #  # ]:          0 :                     if ( pBasic )
     247 [ #  # ][ #  # ]:          0 :                         sLibName = pBasic->GetName();
     248                 :            :                 }
     249                 :            :             }
     250                 :            : 
     251         [ #  # ]:          0 :             if ( m_xContext.is() )
     252                 :            :             {
     253 [ #  # ][ #  # ]:          0 :                 Reference< XMultiComponentFactory > xSMgr( m_xContext->getServiceManager() );
     254                 :            : 
     255         [ #  # ]:          0 :                 if ( xSMgr.is() )
     256                 :            :                 {
     257         [ #  # ]:          0 :                     Reference< frame::XDesktop > xDesktop( xSMgr->createInstanceWithContext(
     258 [ #  # ][ #  # ]:          0 :                         ::rtl::OUString( "com.sun.star.frame.Desktop"  ), m_xContext ), UNO_QUERY );
     259                 :            : 
     260         [ #  # ]:          0 :                     if ( xDesktop.is() )
     261                 :            :                     {
     262 [ #  # ][ #  # ]:          0 :                         Reference < frame::XDispatchProvider > xProv( xDesktop->getCurrentFrame(), UNO_QUERY );
                 [ #  # ]
     263                 :            : 
     264         [ #  # ]:          0 :                         if ( xProv.is() )
     265                 :            :                         {
     266         [ #  # ]:          0 :                             Reference< frame::XDispatchHelper > xHelper( xSMgr->createInstanceWithContext(
     267 [ #  # ][ #  # ]:          0 :                                 ::rtl::OUString( "com.sun.star.frame.DispatchHelper"  ), m_xContext ), UNO_QUERY );
     268                 :            : 
     269         [ #  # ]:          0 :                             if ( xHelper.is() )
     270                 :            :                             {
     271         [ #  # ]:          0 :                                 Sequence < PropertyValue > aArgs(7);
     272         [ #  # ]:          0 :                                 aArgs[0].Name = ::rtl::OUString("Document");
     273 [ #  # ][ #  # ]:          0 :                                 aArgs[0].Value <<= sDocURL;
     274         [ #  # ]:          0 :                                 aArgs[1].Name = ::rtl::OUString("LibName");
     275 [ #  # ][ #  # ]:          0 :                                 aArgs[1].Value <<= sLibName;
     276         [ #  # ]:          0 :                                 aArgs[2].Name = ::rtl::OUString("Name");
     277 [ #  # ][ #  # ]:          0 :                                 aArgs[2].Value <<= sModName;
     278         [ #  # ]:          0 :                                 aArgs[3].Name = ::rtl::OUString("Type");
     279 [ #  # ][ #  # ]:          0 :                                 aArgs[3].Value <<= ::rtl::OUString("Module");
     280         [ #  # ]:          0 :                                 aArgs[4].Name = ::rtl::OUString("Line");
     281 [ #  # ][ #  # ]:          0 :                                 aArgs[4].Value <<= static_cast< sal_uInt32 >( nLine1 );
     282 [ #  # ][ #  # ]:          0 :                                 xHelper->executeDispatch( xProv, ::rtl::OUString(".uno:BasicIDEAppear"), ::rtl::OUString(), 0, aArgs );
                 [ #  # ]
     283                 :          0 :                             }
     284                 :          0 :                         }
     285                 :          0 :                     }
     286                 :          0 :                 }
     287                 :          0 :             }
     288                 :            :         }
     289                 :            :         else
     290                 :            :         {
     291                 :            :             throw IllegalArgumentException(
     292                 :            :                 ::rtl::OUString( "BasicMethodNodeImpl::invoke: function name not supported!"  ),
     293         [ #  # ]:          0 :                 Reference< XInterface >(), 1 );
     294                 :            :         }
     295                 :            : 
     296                 :          0 :         return Any();
     297                 :            :     }
     298                 :            : 
     299                 :            :     // -----------------------------------------------------------------------------
     300                 :            : 
     301                 :          0 :     void BasicMethodNodeImpl::setValue( const ::rtl::OUString& aPropertyName, const Any& aValue )
     302                 :            :         throw (UnknownPropertyException, script::CannotConvertException,
     303                 :            :                reflection::InvocationTargetException, RuntimeException)
     304                 :            :     {
     305                 :            :         (void)aPropertyName;
     306                 :            :         (void)aValue;
     307                 :            : 
     308                 :            :         throw UnknownPropertyException(
     309                 :            :             ::rtl::OUString( "BasicMethodNodeImpl::setValue: property name is unknown!"  ),
     310         [ #  # ]:          0 :             Reference< XInterface >() );
     311                 :            :     }
     312                 :            : 
     313                 :            :     // -----------------------------------------------------------------------------
     314                 :            : 
     315                 :          0 :     Any BasicMethodNodeImpl::getValue( const ::rtl::OUString& aPropertyName ) throw (UnknownPropertyException, RuntimeException)
     316                 :            :     {
     317                 :            :         (void)aPropertyName;
     318                 :            : 
     319                 :            :         throw UnknownPropertyException(
     320                 :            :             ::rtl::OUString( "BasicMethodNodeImpl::getValue: property name is unknown!"  ),
     321         [ #  # ]:          0 :             Reference< XInterface >() );
     322                 :            :     }
     323                 :            : 
     324                 :            :     // -----------------------------------------------------------------------------
     325                 :            : 
     326                 :          0 :     sal_Bool BasicMethodNodeImpl::hasMethod( const ::rtl::OUString& aName ) throw (RuntimeException)
     327                 :            :     {
     328                 :          0 :         sal_Bool bReturn = sal_False;
     329         [ #  # ]:          0 :         if ( aName == BASPROV_PROPERTY_EDITABLE )
     330                 :          0 :             bReturn = sal_True;
     331                 :            : 
     332                 :          0 :         return bReturn;
     333                 :            :     }
     334                 :            : 
     335                 :            :     // -----------------------------------------------------------------------------
     336                 :            : 
     337                 :          0 :     sal_Bool BasicMethodNodeImpl::hasProperty( const ::rtl::OUString& aName ) throw (RuntimeException)
     338                 :            :     {
     339                 :            :         (void)aName;
     340                 :            : 
     341                 :          0 :         return sal_False;
     342                 :            :     }
     343                 :            : 
     344                 :            :     // -----------------------------------------------------------------------------
     345                 :            : 
     346                 :            : //.........................................................................
     347                 :            : }   // namespace basprov
     348                 :            : //.........................................................................
     349                 :            : 
     350                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10