LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/scripting/source/basprov - basmethnode.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 110 0.9 %
Date: 2013-07-09 Functions: 2 23 8.7 %
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             : #include "basmethnode.hxx"
      21             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      22             : #include <com/sun/star/frame/DispatchHelper.hpp>
      23             : #include <com/sun/star/frame/Desktop.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            OUString( "URI"  )
      47             : #define BASPROV_PROPERTY_EDITABLE       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 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( 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 = OUString("vnd.sun.star.script:");
      80           0 :                     m_sURI += pBasic->GetName();
      81           0 :                     m_sURI += OUString(".");
      82           0 :                     m_sURI += pModule->GetName();
      83           0 :                     m_sURI += OUString(".");
      84           0 :                     m_sURI += m_pMethod->GetName();
      85           0 :                     m_sURI += OUString("?language=Basic&location=");
      86           0 :                     if ( m_bIsAppScript )
      87           0 :                         m_sURI += OUString("application");
      88             :                     else
      89           0 :                         m_sURI += 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 :     OUString BasicMethodNodeImpl::getName(  ) throw (RuntimeException)
     121             :     {
     122           0 :         SolarMutexGuard aGuard;
     123             : 
     124           0 :         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 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 :             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< frame::XDesktop2 > xDesktop = frame::Desktop::create( m_xContext );
     254             : 
     255           0 :                 Reference < frame::XDispatchProvider > xProv( xDesktop->getCurrentFrame(), UNO_QUERY );
     256             : 
     257           0 :                 if ( xProv.is() )
     258             :                 {
     259           0 :                     Reference< frame::XDispatchHelper > xHelper( frame::DispatchHelper::create( m_xContext ) );
     260             : 
     261           0 :                     Sequence < PropertyValue > aArgs(7);
     262           0 :                     aArgs[0].Name = OUString("Document");
     263           0 :                     aArgs[0].Value <<= sDocURL;
     264           0 :                     aArgs[1].Name = OUString("LibName");
     265           0 :                     aArgs[1].Value <<= sLibName;
     266           0 :                     aArgs[2].Name = OUString("Name");
     267           0 :                     aArgs[2].Value <<= sModName;
     268           0 :                     aArgs[3].Name = OUString("Type");
     269           0 :                     aArgs[3].Value <<= OUString("Module");
     270           0 :                     aArgs[4].Name = OUString("Line");
     271           0 :                     aArgs[4].Value <<= static_cast< sal_uInt32 >( nLine1 );
     272           0 :                     xHelper->executeDispatch( xProv, OUString(".uno:BasicIDEAppear"), OUString(), 0, aArgs );
     273           0 :                 }
     274           0 :             }
     275             :         }
     276             :         else
     277             :         {
     278             :             throw IllegalArgumentException(
     279             :                 OUString( "BasicMethodNodeImpl::invoke: function name not supported!"  ),
     280           0 :                 Reference< XInterface >(), 1 );
     281             :         }
     282             : 
     283           0 :         return Any();
     284             :     }
     285             : 
     286             :     // -----------------------------------------------------------------------------
     287             : 
     288           0 :     void BasicMethodNodeImpl::setValue( const OUString& aPropertyName, const Any& aValue )
     289             :         throw (UnknownPropertyException, script::CannotConvertException,
     290             :                reflection::InvocationTargetException, RuntimeException)
     291             :     {
     292             :         (void)aPropertyName;
     293             :         (void)aValue;
     294             : 
     295             :         throw UnknownPropertyException(
     296             :             OUString( "BasicMethodNodeImpl::setValue: property name is unknown!"  ),
     297           0 :             Reference< XInterface >() );
     298             :     }
     299             : 
     300             :     // -----------------------------------------------------------------------------
     301             : 
     302           0 :     Any BasicMethodNodeImpl::getValue( const OUString& aPropertyName ) throw (UnknownPropertyException, RuntimeException)
     303             :     {
     304             :         (void)aPropertyName;
     305             : 
     306             :         throw UnknownPropertyException(
     307             :             OUString( "BasicMethodNodeImpl::getValue: property name is unknown!"  ),
     308           0 :             Reference< XInterface >() );
     309             :     }
     310             : 
     311             :     // -----------------------------------------------------------------------------
     312             : 
     313           0 :     sal_Bool BasicMethodNodeImpl::hasMethod( const OUString& aName ) throw (RuntimeException)
     314             :     {
     315           0 :         sal_Bool bReturn = sal_False;
     316           0 :         if ( aName == BASPROV_PROPERTY_EDITABLE )
     317           0 :             bReturn = sal_True;
     318             : 
     319           0 :         return bReturn;
     320             :     }
     321             : 
     322             :     // -----------------------------------------------------------------------------
     323             : 
     324           0 :     sal_Bool BasicMethodNodeImpl::hasProperty( const OUString& aName ) throw (RuntimeException)
     325             :     {
     326             :         (void)aName;
     327             : 
     328           0 :         return sal_False;
     329             :     }
     330             : 
     331             :     // -----------------------------------------------------------------------------
     332             : 
     333             : //.........................................................................
     334          12 : }   // namespace basprov
     335             : //.........................................................................
     336             : 
     337             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10