LCOV - code coverage report
Current view: top level - svx/source/form - fmscriptingenv.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 103 147 70.1 %
Date: 2012-08-25 Functions: 26 32 81.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 106 285 37.2 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "fmscriptingenv.hxx"
      30                 :            : #include "svx/fmmodel.hxx"
      31                 :            : 
      32                 :            : #include <com/sun/star/lang/IllegalArgumentException.hpp>
      33                 :            : #include <com/sun/star/script/XScriptListener.hpp>
      34                 :            : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
      35                 :            : #include <com/sun/star/reflection/XInterfaceMethodTypeDescription.hpp>
      36                 :            : #include <com/sun/star/lang/DisposedException.hpp>
      37                 :            : #include <com/sun/star/lang/EventObject.hpp>
      38                 :            : #include <com/sun/star/awt/XControl.hpp>
      39                 :            : 
      40                 :            : #include <tools/diagnose_ex.h>
      41                 :            : #include <cppuhelper/implbase1.hxx>
      42                 :            : #include <comphelper/implementationreference.hxx>
      43                 :            : #include <comphelper/componentcontext.hxx>
      44                 :            : #include <comphelper/processfactory.hxx>
      45                 :            : #include <vcl/svapp.hxx>
      46                 :            : #include <osl/mutex.hxx>
      47                 :            : #include <sfx2/objsh.hxx>
      48                 :            : #include <sfx2/app.hxx>
      49                 :            : #include <basic/basmgr.hxx>
      50                 :            : 
      51                 :            : #include <boost/shared_ptr.hpp>
      52                 :            : 
      53                 :            : //........................................................................
      54                 :            : namespace svxform
      55                 :            : {
      56                 :            : //........................................................................
      57                 :            : 
      58                 :            :     /** === begin UNO using === **/
      59                 :            :     using ::com::sun::star::uno::Reference;
      60                 :            :     using ::com::sun::star::script::XEventAttacherManager;
      61                 :            :     using ::com::sun::star::lang::IllegalArgumentException;
      62                 :            :     using ::com::sun::star::script::XScriptListener;
      63                 :            :     using ::com::sun::star::script::ScriptEvent;
      64                 :            :     using ::com::sun::star::uno::RuntimeException;
      65                 :            :     using ::com::sun::star::lang::EventObject;
      66                 :            :     using ::com::sun::star::reflection::InvocationTargetException;
      67                 :            :     using ::com::sun::star::uno::Any;
      68                 :            :     using ::com::sun::star::container::XHierarchicalNameAccess;
      69                 :            :     using ::com::sun::star::reflection::XInterfaceMethodTypeDescription;
      70                 :            :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      71                 :            :     using ::com::sun::star::lang::DisposedException;
      72                 :            :     using ::com::sun::star::uno::RuntimeException;
      73                 :            :     using ::com::sun::star::uno::Exception;
      74                 :            :     using ::com::sun::star::uno::Sequence;
      75                 :            :     using ::com::sun::star::uno::XInterface;
      76                 :            :     using ::com::sun::star::lang::EventObject;
      77                 :            :     using ::com::sun::star::awt::XControl;
      78                 :            :     using ::com::sun::star::beans::XPropertySet;
      79                 :            :     /** === end UNO using === **/
      80                 :            : 
      81                 :            :     class FormScriptingEnvironment;
      82                 :            : 
      83                 :            :     //====================================================================
      84                 :            :     //= FormScriptListener
      85                 :            :     //====================================================================
      86                 :            :     typedef ::cppu::WeakImplHelper1 <   XScriptListener
      87                 :            :                                     >   FormScriptListener_Base;
      88                 :            : 
      89                 :            :     /** implements the XScriptListener interface, is used by FormScriptingEnvironment
      90                 :            :     */
      91                 :            :     class FormScriptListener    :public FormScriptListener_Base
      92                 :            :     {
      93                 :            :     private:
      94                 :            :         ::osl::Mutex m_aMutex;
      95                 :            :         FormScriptingEnvironment *m_pScriptExecutor;
      96                 :            : 
      97                 :            :     public:
      98                 :            :         FormScriptListener( FormScriptingEnvironment * pScriptExecutor );
      99                 :            : 
     100                 :            :         // XScriptListener
     101                 :            :         virtual void SAL_CALL firing( const ScriptEvent& aEvent ) throw (RuntimeException);
     102                 :            :         virtual Any SAL_CALL approveFiring( const ScriptEvent& aEvent ) throw (InvocationTargetException, RuntimeException);
     103                 :            :         // XEventListener
     104                 :            :         virtual void SAL_CALL disposing( const EventObject& Source ) throw (RuntimeException);
     105                 :            : 
     106                 :            :         // lifetime control
     107                 :            :         void SAL_CALL dispose();
     108                 :            : 
     109                 :            :     protected:
     110                 :            :         ~FormScriptListener();
     111                 :            : 
     112                 :            :     private:
     113                 :            :         /** determines whether calling a given method at a given listener interface can be done asynchronously
     114                 :            : 
     115                 :            :             @param _rListenerType
     116                 :            :                 the name of the UNO type whose method is to be checked
     117                 :            :             @param _rMethodName
     118                 :            :                 the name of the method at the interface determined by _rListenerType
     119                 :            : 
     120                 :            :             @return
     121                 :            :                 <TRUE/> if and only if the method is declared <code>oneway</code>, i.e. can be called asynchronously
     122                 :            :         */
     123                 :            :         bool    impl_allowAsynchronousCall_nothrow( const ::rtl::OUString& _rListenerType, const ::rtl::OUString& _rMethodName ) const;
     124                 :            : 
     125                 :            :         /** determines whether the instance is already disposed
     126                 :            :         */
     127                 :          4 :         bool    impl_isDisposed_nothrow() const { return !m_pScriptExecutor; }
     128                 :            : 
     129                 :            :         /** fires the given script event in a thread-safe manner
     130                 :            : 
     131                 :            :             This methods calls our script executor's doFireScriptEvent, with previously releasing the given mutex guard,
     132                 :            :             but ensuring that our script executor is not deleted between this release and the actual call.
     133                 :            : 
     134                 :            :             @param _rGuard
     135                 :            :                 a clearable guard to our mutex. Must be the only active guard to our mutex.
     136                 :            :             @param _rEvent
     137                 :            :                 the event to fire
     138                 :            :             @param _pSyncronousResult
     139                 :            :                 a place to take a possible result of the script call.
     140                 :            : 
     141                 :            :             @precond
     142                 :            :                 m_pScriptExecutor is not <NULL/>.
     143                 :            :         */
     144                 :            :         void    impl_doFireScriptEvent_nothrow( ::osl::ClearableMutexGuard& _rGuard, const ScriptEvent& _rEvent, Any* _pSyncronousResult );
     145                 :            : 
     146                 :            :     private:
     147                 :            :         DECL_LINK( OnAsyncScriptEvent, ScriptEvent* );
     148                 :            :     };
     149                 :            : 
     150                 :            :     //====================================================================
     151                 :            :     //= FormScriptingEnvironment
     152                 :            :     //====================================================================
     153                 :            :     class FormScriptingEnvironment : public IFormScriptingEnvironment
     154                 :            :     {
     155                 :            :     private:
     156                 :            :         typedef ::comphelper::ImplementationReference< FormScriptListener, XScriptListener >    ListenerImplementation;
     157                 :            : 
     158                 :            :     private:
     159                 :            :         ::osl::Mutex            m_aMutex;
     160                 :            :         oslInterlockedCount     m_refCount;
     161                 :            :         ListenerImplementation  m_pScriptListener;
     162                 :            :         FmFormModel&            m_rFormModel;
     163                 :            :         bool                    m_bDisposed;
     164                 :            : 
     165                 :            :     public:
     166                 :            :         FormScriptingEnvironment( FmFormModel& _rModel );
     167                 :            :         virtual ~FormScriptingEnvironment();
     168                 :            : 
     169                 :            :         // callback for FormScriptListener
     170                 :            :         void doFireScriptEvent( const ScriptEvent& _rEvent, Any* _pSyncronousResult );
     171                 :            : 
     172                 :            :         // IFormScriptingEnvironment
     173                 :            :         virtual void registerEventAttacherManager( const Reference< XEventAttacherManager >& _rxManager );
     174                 :            :         virtual void revokeEventAttacherManager( const Reference< XEventAttacherManager >& _rxManager );
     175                 :            :         virtual void dispose();
     176                 :            : 
     177                 :            :         // IReference
     178                 :            :         virtual oslInterlockedCount SAL_CALL acquire();
     179                 :            :         virtual oslInterlockedCount SAL_CALL release();
     180                 :            : 
     181                 :            :     private:
     182                 :            :         void impl_registerOrRevoke_throw( const Reference< XEventAttacherManager >& _rxManager, bool _bRegister );
     183                 :            : 
     184                 :            :     private:
     185                 :            :         FormScriptingEnvironment();                                                 // never implemented
     186                 :            :         FormScriptingEnvironment( const FormScriptingEnvironment& );                // never implemented
     187                 :            :         FormScriptingEnvironment& operator=( const FormScriptingEnvironment& );     // never implemented
     188                 :            :     };
     189                 :            : 
     190                 :            :     //====================================================================
     191                 :            :     //= FormScriptListener
     192                 :            :     //====================================================================
     193                 :            :     //--------------------------------------------------------------------
     194                 :       1886 :     FormScriptListener::FormScriptListener( FormScriptingEnvironment* pScriptExecutor )
     195         [ +  - ]:       1886 :         :m_pScriptExecutor( pScriptExecutor )
     196                 :            :     {
     197                 :       1886 :     }
     198                 :            : 
     199                 :            :     //--------------------------------------------------------------------
     200         [ +  - ]:       1781 :     FormScriptListener::~FormScriptListener()
     201                 :            :     {
     202         [ -  + ]:       3562 :     }
     203                 :            : 
     204                 :            :     //--------------------------------------------------------------------
     205                 :          2 :     bool FormScriptListener::impl_allowAsynchronousCall_nothrow( const ::rtl::OUString& _rListenerType, const ::rtl::OUString& _rMethodName ) const
     206                 :            :     {
     207                 :          2 :         bool bAllowAsynchronousCall = false;
     208                 :            :         try
     209                 :            :         {
     210 [ +  - ][ +  - ]:          2 :             ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
     211 [ +  - ][ +  - ]:          2 :             Reference< XHierarchicalNameAccess > xTypeDescriptions( aContext.getSingleton( "com.sun.star.reflection.theTypeDescriptionManager" ), UNO_QUERY_THROW );
     212                 :            : 
     213                 :          2 :             ::rtl::OUString sMethodDescription( _rListenerType );
     214         [ +  - ]:          2 :             sMethodDescription += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "::" ));
     215                 :          2 :             sMethodDescription += _rMethodName;
     216                 :            : 
     217 [ +  - ][ +  - ]:          2 :             Reference< XInterfaceMethodTypeDescription > xMethod( xTypeDescriptions->getByHierarchicalName( sMethodDescription ), UNO_QUERY_THROW );
                 [ +  - ]
     218 [ +  - ][ +  - ]:          2 :             bAllowAsynchronousCall = xMethod->isOneway();
         [ #  # ][ +  - ]
     219                 :            :         }
     220                 :          0 :         catch( const Exception& )
     221                 :            :         {
     222                 :            :             DBG_UNHANDLED_EXCEPTION();
     223                 :            :         }
     224                 :          2 :         return bAllowAsynchronousCall;
     225                 :            :     }
     226                 :            : 
     227                 :            :     //--------------------------------------------------------------------
     228                 :          2 :     void FormScriptListener::impl_doFireScriptEvent_nothrow( ::osl::ClearableMutexGuard& _rGuard, const ScriptEvent& _rEvent, Any* _pSyncronousResult )
     229                 :            :     {
     230                 :            :         OSL_PRECOND( m_pScriptExecutor, "FormScriptListener::impl_doFireScriptEvent_nothrow: this will crash!" );
     231                 :            : 
     232                 :          2 :         _rGuard.clear();
     233                 :          2 :         m_pScriptExecutor->doFireScriptEvent( _rEvent, _pSyncronousResult );
     234                 :          2 :     }
     235                 :            : 
     236                 :            :     //--------------------------------------------------------------------
     237                 :          2 :     void SAL_CALL FormScriptListener::firing( const ScriptEvent& _rEvent ) throw (RuntimeException)
     238                 :            :     {
     239         [ +  - ]:          2 :         ::osl::ClearableMutexGuard aGuard( m_aMutex );
     240 [ +  - ][ +  - ]:          2 :        static const ::rtl::OUString vbaInterOp( RTL_CONSTASCII_USTRINGPARAM("VBAInterop") );
         [ +  - ][ #  # ]
     241         [ -  + ]:          2 :        if ( _rEvent.ScriptType.equals(vbaInterOp) )
     242                 :            :            return; // not handled here
     243                 :            : 
     244         [ -  + ]:          2 :         if ( impl_isDisposed_nothrow() )
     245                 :            :             return;
     246                 :            : 
     247 [ +  - ][ -  + ]:          2 :         if ( !impl_allowAsynchronousCall_nothrow( _rEvent.ListenerType.getTypeName(), _rEvent.MethodName ) )
     248                 :            :         {
     249         [ #  # ]:          0 :             impl_doFireScriptEvent_nothrow( aGuard, _rEvent, NULL );
     250                 :            :             return;
     251                 :            :         }
     252                 :            : 
     253                 :          2 :         acquire();
     254 [ +  - ][ +  - ]:          2 :         Application::PostUserEvent( LINK( this, FormScriptListener, OnAsyncScriptEvent ), new ScriptEvent( _rEvent ) );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     255                 :            :     }
     256                 :            : 
     257                 :            :     //--------------------------------------------------------------------
     258                 :          0 :     Any SAL_CALL FormScriptListener::approveFiring( const ScriptEvent& _rEvent ) throw (InvocationTargetException, RuntimeException)
     259                 :            :     {
     260                 :          0 :         Any aResult;
     261                 :            : 
     262         [ #  # ]:          0 :         ::osl::ClearableMutexGuard aGuard( m_aMutex );
     263         [ #  # ]:          0 :         if ( !impl_isDisposed_nothrow() )
     264         [ #  # ]:          0 :             impl_doFireScriptEvent_nothrow( aGuard, _rEvent, &aResult );
     265                 :            : 
     266         [ #  # ]:          0 :         return aResult;
     267                 :            :     }
     268                 :            : 
     269                 :            :     //--------------------------------------------------------------------
     270                 :          0 :     void SAL_CALL FormScriptListener::disposing( const EventObject& /*Source*/ ) throw (RuntimeException)
     271                 :            :     {
     272                 :            :         // not interested in
     273                 :          0 :     }
     274                 :            : 
     275                 :            :     //--------------------------------------------------------------------
     276                 :          0 :     void SAL_CALL FormScriptListener::dispose()
     277                 :            :     {
     278         [ #  # ]:          0 :         ::osl::MutexGuard aGuard( m_aMutex );
     279         [ #  # ]:          0 :         m_pScriptExecutor = NULL;
     280                 :          0 :     }
     281                 :            : 
     282                 :            :     //--------------------------------------------------------------------
     283                 :          2 :     IMPL_LINK( FormScriptListener, OnAsyncScriptEvent, ScriptEvent*, _pEvent )
     284                 :            :     {
     285                 :            :         OSL_PRECOND( _pEvent != NULL, "FormScriptListener::OnAsyncScriptEvent: invalid event!" );
     286         [ -  + ]:          2 :         if ( !_pEvent )
     287                 :          0 :             return 1L;
     288                 :            : 
     289                 :            :         {
     290         [ +  - ]:          2 :             ::osl::ClearableMutexGuard aGuard( m_aMutex );
     291                 :            : 
     292         [ +  - ]:          2 :             if ( !impl_isDisposed_nothrow() )
     293 [ +  - ][ +  - ]:          2 :                 impl_doFireScriptEvent_nothrow( aGuard, *_pEvent, NULL );
     294                 :            :         }
     295                 :            : 
     296         [ +  - ]:          2 :         delete _pEvent;
     297                 :            :         // we acquired ourself immediately before posting the event
     298                 :          2 :         release();
     299                 :          2 :         return 0L;
     300                 :            :     }
     301                 :            : 
     302                 :            :     //====================================================================
     303                 :            :     //= FormScriptingEnvironment
     304                 :            :     //====================================================================
     305                 :            :     //--------------------------------------------------------------------
     306                 :       1886 :     FormScriptingEnvironment::FormScriptingEnvironment( FmFormModel& _rModel )
     307                 :            :         :m_refCount( 0 )
     308                 :            :         ,m_pScriptListener( NULL )
     309                 :            :         ,m_rFormModel( _rModel )
     310 [ +  - ][ +  - ]:       1886 :         ,m_bDisposed( false )
     311                 :            :     {
     312 [ +  - ][ +  - ]:       1886 :         m_pScriptListener = ListenerImplementation( new FormScriptListener( this ) );
         [ +  - ][ +  - ]
     313                 :            :         // note that this is a cyclic reference between the FormScriptListener and the FormScriptingEnvironment
     314                 :            :         // This cycle is broken up when our instance is disposed.
     315                 :       1886 :     }
     316                 :            : 
     317                 :            :     //--------------------------------------------------------------------
     318 [ +  - ][ +  - ]:       1781 :     FormScriptingEnvironment::~FormScriptingEnvironment()
     319                 :            :     {
     320         [ -  + ]:       3562 :     }
     321                 :            : 
     322                 :            :     //--------------------------------------------------------------------
     323                 :       1240 :     void FormScriptingEnvironment::impl_registerOrRevoke_throw( const Reference< XEventAttacherManager >& _rxManager, bool _bRegister )
     324                 :            :     {
     325         [ +  - ]:       1240 :         ::osl::MutexGuard aGuard( m_aMutex );
     326                 :            : 
     327         [ -  + ]:       1240 :         if ( !_rxManager.is() )
     328         [ #  # ]:          0 :             throw IllegalArgumentException();
     329         [ -  + ]:       1240 :         if ( m_bDisposed )
     330         [ #  # ]:          0 :             throw DisposedException();
     331                 :            : 
     332                 :            :         try
     333                 :            :         {
     334         [ +  + ]:       1240 :             if ( _bRegister )
     335 [ +  - ][ +  - ]:        628 :                 _rxManager->addScriptListener( m_pScriptListener.getRef() );
                 [ +  - ]
     336                 :            :             else
     337 [ +  - ][ +  - ]:        612 :                 _rxManager->removeScriptListener( m_pScriptListener.getRef() );
                 [ +  - ]
     338                 :            :         }
     339      [ #  #  # ]:          0 :         catch( const RuntimeException& ) { throw; }
     340         [ #  # ]:          0 :         catch( const Exception& )
     341                 :            :         {
     342                 :            :             DBG_UNHANDLED_EXCEPTION();
     343         [ +  - ]:       1240 :         }
     344                 :       1240 :     }
     345                 :            : 
     346                 :            :     //--------------------------------------------------------------------
     347                 :        628 :     void FormScriptingEnvironment::registerEventAttacherManager( const Reference< XEventAttacherManager >& _rxManager )
     348                 :            :     {
     349                 :        628 :         impl_registerOrRevoke_throw( _rxManager, true );
     350                 :        628 :     }
     351                 :            : 
     352                 :            :     //--------------------------------------------------------------------
     353                 :        612 :     void FormScriptingEnvironment::revokeEventAttacherManager( const Reference< XEventAttacherManager >& _rxManager )
     354                 :            :     {
     355                 :        612 :         impl_registerOrRevoke_throw( _rxManager, false );
     356                 :        612 :     }
     357                 :            : 
     358                 :            :     //--------------------------------------------------------------------
     359                 :       1886 :     oslInterlockedCount SAL_CALL FormScriptingEnvironment::acquire()
     360                 :            :     {
     361                 :       1886 :         return osl_incrementInterlockedCount( &m_refCount );
     362                 :            :     }
     363                 :            : 
     364                 :            :     //--------------------------------------------------------------------
     365                 :       1781 :     oslInterlockedCount SAL_CALL FormScriptingEnvironment::release()
     366                 :            :     {
     367         [ +  - ]:       1781 :         if ( 0 == osl_decrementInterlockedCount( &m_refCount ) )
     368                 :            :         {
     369         [ +  - ]:       1781 :            delete this;
     370                 :       1781 :            return 0;
     371                 :            :         }
     372                 :       1781 :         return m_refCount;
     373                 :            :     }
     374                 :            : 
     375                 :            :     //--------------------------------------------------------------------
     376                 :       1781 :     IFormScriptingEnvironment::~IFormScriptingEnvironment()
     377                 :            :     {
     378         [ -  + ]:       1781 :     }
     379                 :            : 
     380                 :            :     //--------------------------------------------------------------------
     381                 :            :     namespace
     382                 :            :     {
     383                 :            :         //................................................................
     384                 :            :         //. NewStyleUNOScript
     385                 :            :         //................................................................
     386                 :          2 :         class SAL_NO_VTABLE IScript
     387                 :            :         {
     388                 :            :         public:
     389                 :            :             virtual void invoke( const Sequence< Any >& _rArguments, Any& _rSynchronousResult ) = 0;
     390                 :            : 
     391         [ -  + ]:          2 :             virtual ~IScript() { }
     392                 :            :         };
     393                 :            :         typedef ::boost::shared_ptr< IScript >  PScript;
     394                 :            : 
     395                 :            :         //................................................................
     396                 :            :         //. NewStyleUNOScript
     397                 :            :         //................................................................
     398         [ -  + ]:          4 :         class NewStyleUNOScript : public IScript
     399                 :            :         {
     400                 :            :             SfxObjectShell&         m_rObjectShell;
     401                 :            :             const ::rtl::OUString   m_sScriptCode;
     402                 :            : 
     403                 :            :         public:
     404                 :          2 :             NewStyleUNOScript( SfxObjectShell& _rObjectShell, const ::rtl::OUString& _rScriptCode )
     405                 :            :                 :m_rObjectShell( _rObjectShell )
     406                 :          2 :                 ,m_sScriptCode( _rScriptCode )
     407                 :            :             {
     408                 :          2 :             }
     409                 :            : 
     410                 :            :             // IScript
     411                 :            :             virtual void invoke( const Sequence< Any >& _rArguments, Any& _rSynchronousResult );
     412                 :            :         };
     413                 :            : 
     414                 :            :         //................................................................
     415                 :          2 :         void NewStyleUNOScript::invoke( const Sequence< Any >& _rArguments, Any& _rSynchronousResult )
     416                 :            :         {
     417         [ +  - ]:          2 :             Sequence< sal_Int16 > aOutArgsIndex;
     418         [ +  - ]:          2 :             Sequence< Any > aOutArgs;
     419         [ +  - ]:          2 :             EventObject aEvent;
     420                 :          2 :             Any aCaller;
     421 [ +  - ][ +  - ]:          2 :             if ( ( _rArguments.getLength() > 0 ) && ( _rArguments[ 0 ] >>= aEvent ) )
         [ +  - ][ +  - ]
     422                 :            :             {
     423                 :            :                 try
     424                 :            :                 {
     425         [ +  - ]:          2 :                     Reference< XControl > xControl( aEvent.Source, UNO_QUERY_THROW );
     426 [ +  - ][ +  - ]:          2 :                     Reference< XPropertySet > xProps( xControl->getModel(), UNO_QUERY_THROW );
                 [ +  - ]
     427 [ +  - ][ +  - ]:          2 :                     aCaller = xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Name") ) );
         [ #  # ][ +  - ]
     428                 :            :                 }
     429         [ #  # ]:          0 :                 catch( Exception& ) {}
     430                 :            :             }
     431 [ +  - ][ +  - ]:          2 :             m_rObjectShell.CallXScript( m_sScriptCode, _rArguments, _rSynchronousResult, aOutArgsIndex, aOutArgs, true, aCaller.hasValue() ? &aCaller : 0 );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     432                 :          2 :         }
     433                 :            :     }
     434                 :            : 
     435                 :            :     //--------------------------------------------------------------------
     436                 :          2 :     void FormScriptingEnvironment::doFireScriptEvent( const ScriptEvent& _rEvent, Any* _pSyncronousResult )
     437                 :            :     {
     438                 :            : #ifdef DISABLE_SCRIPTING
     439                 :            :         (void) _rEvent;
     440                 :            :         (void) _pSyncronousResult;
     441                 :            : #else
     442         [ +  - ]:          2 :         SolarMutexClearableGuard aSolarGuard;
     443         [ +  - ]:          2 :         ::osl::ClearableMutexGuard aGuard( m_aMutex );
     444                 :            : 
     445         [ -  + ]:          2 :         if ( m_bDisposed )
     446                 :            :             return;
     447                 :            : 
     448                 :            :         // SfxObjectShellRef is good here since the model controls the lifetime of the object
     449                 :          2 :         SfxObjectShellRef xObjectShell = m_rFormModel.GetObjectShell();
     450         [ -  + ]:          2 :         if( !xObjectShell.Is() )
     451                 :            :             return;
     452                 :            : 
     453                 :            :         // the script to execute
     454         [ +  - ]:          2 :         PScript pScript;
     455                 :            : 
     456         [ +  - ]:          2 :         if ( _rEvent.ScriptType != "StarBasic" )
     457                 :            :         {
     458 [ +  - ][ +  - ]:          2 :             pScript.reset( new NewStyleUNOScript( *xObjectShell, _rEvent.ScriptCode ) );
     459                 :            :         }
     460                 :            :         else
     461                 :            :         {
     462                 :          0 :             ::rtl::OUString sScriptCode = _rEvent.ScriptCode;
     463                 :          0 :             ::rtl::OUString sMacroLocation;
     464                 :            : 
     465                 :            :             // is there a location in the script name ("application" or "document")?
     466                 :          0 :             sal_Int32 nPrefixLen = sScriptCode.indexOf( ':' );
     467                 :            :             DBG_ASSERT( 0 <= nPrefixLen, "FormScriptingEnvironment::doFireScriptEvent: Basic script name in old format encountered!" );
     468                 :            : 
     469         [ #  # ]:          0 :             if ( 0 <= nPrefixLen )
     470                 :            :             {
     471                 :            :                 // and it has such a prefix
     472                 :          0 :                 sMacroLocation = sScriptCode.copy( 0, nPrefixLen );
     473                 :            :                 DBG_ASSERT( 0 == sMacroLocation.compareToAscii( "document" )
     474                 :            :                         ||  0 == sMacroLocation.compareToAscii( "application" ),
     475                 :            :                         "FormScriptingEnvironment::doFireScriptEvent: invalid (unknown) prefix!" );
     476                 :            : 
     477                 :            :                 // strip the prefix: the SfxObjectShell::CallScript knows nothing about such prefixes
     478                 :          0 :                 sScriptCode = sScriptCode.copy( nPrefixLen + 1 );
     479                 :            :             }
     480                 :            : 
     481         [ #  # ]:          0 :             if ( sMacroLocation.isEmpty() )
     482                 :            :             {
     483                 :            :                 // legacy format: use the app-wide Basic, if it has a respective method, otherwise fall back to the doc's Basic
     484 [ #  # ][ #  # ]:          0 :                 if ( SFX_APP()->GetBasicManager()->HasMacro( sScriptCode ) )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     485         [ #  # ]:          0 :                     sMacroLocation = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application" ) );
     486                 :            :                 else
     487         [ #  # ]:          0 :                     sMacroLocation = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "document" ) );
     488                 :            :             }
     489                 :            : 
     490                 :          0 :             ::rtl::OUStringBuffer aScriptURI;
     491         [ #  # ]:          0 :             aScriptURI.appendAscii( "vnd.sun.star.script:" );
     492         [ #  # ]:          0 :             aScriptURI.append( sScriptCode );
     493         [ #  # ]:          0 :             aScriptURI.appendAscii( "?language=Basic" );
     494         [ #  # ]:          0 :             aScriptURI.appendAscii( "&location=" );
     495         [ #  # ]:          0 :             aScriptURI.append( sMacroLocation );
     496                 :            : 
     497         [ #  # ]:          0 :             const ::rtl::OUString sScriptURI( aScriptURI.makeStringAndClear() );
     498 [ #  # ][ #  # ]:          0 :             pScript.reset( new NewStyleUNOScript( *xObjectShell, sScriptURI ) );
     499                 :            :         }
     500                 :            : 
     501                 :            :         OSL_ENSURE( pScript.get(), "FormScriptingEnvironment::doFireScriptEvent: no script to execute!" );
     502         [ -  + ]:          2 :         if ( !pScript.get() )
     503                 :            :             // this is an internal error in the above code
     504         [ #  # ]:          0 :             throw RuntimeException();
     505                 :            : 
     506         [ +  - ]:          2 :         aGuard.clear();
     507         [ +  - ]:          2 :         aSolarGuard.clear();
     508                 :            : 
     509                 :          2 :         Any aIgnoreResult;
     510 [ +  - ][ +  - ]:          2 :         pScript->invoke( _rEvent.Arguments, _pSyncronousResult ? *_pSyncronousResult : aIgnoreResult );
     511         [ +  - ]:          2 :         pScript.reset();
     512                 :            : 
     513                 :            :         {
     514                 :            :             // object shells are not thread safe, so guard the destruction
     515         [ +  - ]:          2 :             SolarMutexGuard aSolarGuarsReset;
     516 [ +  - ][ +  - ]:          2 :             xObjectShell = NULL;
     517 [ +  - ][ +  - ]:          2 :         }
         [ -  + ][ +  - ]
         [ -  + ][ +  - ]
                 [ +  - ]
     518                 :            : #endif
     519                 :            :     }
     520                 :            : 
     521                 :            :     //--------------------------------------------------------------------
     522                 :          0 :     void FormScriptingEnvironment::dispose()
     523                 :            :     {
     524         [ #  # ]:          0 :         ::osl::MutexGuard aGuard( m_aMutex );
     525                 :          0 :         m_bDisposed = true;
     526 [ #  # ][ #  # ]:          0 :         m_pScriptListener->dispose();
     527                 :          0 :     }
     528                 :            : 
     529                 :            :     //--------------------------------------------------------------------
     530                 :       1886 :     PFormScriptingEnvironment createDefaultFormScriptingEnvironment( FmFormModel& _rModel )
     531                 :            :     {
     532         [ +  - ]:       1886 :         return new FormScriptingEnvironment( _rModel );
     533                 :            :     }
     534                 :            : 
     535                 :            : //........................................................................
     536                 :            : } // namespace svxform
     537                 :            : //........................................................................
     538                 :            : 
     539                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10