LCOV - code coverage report
Current view: top level - basic/source/inc - sbunoobj.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 24 53 45.3 %
Date: 2014-11-03 Functions: 21 42 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : #ifndef INCLUDED_BASIC_SOURCE_INC_SBUNOOBJ_HXX
      20             : #define INCLUDED_BASIC_SOURCE_INC_SBUNOOBJ_HXX
      21             : 
      22             : #include <basic/sbxobj.hxx>
      23             : #include <basic/sbxmeth.hxx>
      24             : #include <basic/sbxprop.hxx>
      25             : #include <basic/sbxfac.hxx>
      26             : #include <basic/sbx.hxx>
      27             : #include <com/sun/star/beans/XMaterialHolder.hpp>
      28             : #include <com/sun/star/beans/XExactName.hpp>
      29             : #include <com/sun/star/beans/XIntrospectionAccess.hpp>
      30             : #include <com/sun/star/beans/XIntrospection.hpp>
      31             : #include <com/sun/star/lang/XComponent.hpp>
      32             : #include <com/sun/star/script/XInvocation.hpp>
      33             : #include <com/sun/star/reflection/XIdlClass.hpp>
      34             : #include <com/sun/star/reflection/XServiceTypeDescription2.hpp>
      35             : #include <com/sun/star/reflection/XSingletonTypeDescription.hpp>
      36             : #include <rtl/ustring.hxx>
      37             : #include <boost/unordered_map.hpp>
      38             : #include <vector>
      39             : #include <map>
      40             : #include <boost/shared_ptr.hpp>
      41             : 
      42             : void registerComponentToBeDisposedForBasic( css::uno::Reference< css::lang::XComponent > xComponent, StarBASIC* pBasic );
      43             : 
      44        2482 : class StructRefInfo
      45             : {
      46             :     com::sun::star::uno::Any& maAny;
      47             :     css::uno::Type maType;
      48             :     sal_Int32 mnPos;
      49             : public:
      50        1690 :     StructRefInfo( com::sun::star::uno::Any& aAny, css::uno::Type const & rType, sal_Int32 nPos ) : maAny( aAny ), maType( rType ), mnPos( nPos ) {}
      51             : 
      52        1354 :     sal_Int32 getPos() const { return mnPos; }
      53         394 :     css::uno::Type getType() const { return maType; }
      54             :     OUString getTypeName() const;
      55        1354 :     com::sun::star::uno::Any& getRootAnyRef() { return maAny; };
      56             : 
      57             :     com::sun::star::uno::TypeClass getTypeClass() const;
      58             : 
      59             :     void* getInst();
      60         252 :     bool isEmpty() { return (mnPos == -1); }
      61             : 
      62             :     ::com::sun::star::uno::Any getValue();
      63             :     bool setValue( const ::com::sun::star::uno::Any& );
      64             : };
      65             : 
      66             : class SbUnoStructRefObject: public SbxObject
      67             : {
      68             :     struct caseLessComp
      69             :     {
      70        6036 :         bool operator() (const OUString& rProp, const OUString& rOtherProp ) const
      71             :         {
      72        6036 :             return rProp.toAsciiUpperCase().compareTo( rOtherProp.toAsciiUpperCase() ) < 0;
      73             :         }
      74             :     };
      75             :     typedef ::std::map< OUString, StructRefInfo*, caseLessComp > StructFieldInfo;
      76             :     StructFieldInfo maFields;
      77             :     StructRefInfo maMemberInfo;
      78             :     bool mbMemberCacheInit;
      79             :     void implCreateAll();
      80             :     void implCreateDbgProperties();
      81             :     void initMemberCache();
      82             :     OUString Impl_DumpProperties();
      83             :     OUString getDbgObjectName();
      84             : public:
      85             :     TYPEINFO_OVERRIDE();
      86             :     StructRefInfo getStructMember( const OUString& rMember );
      87          14 :     StructRefInfo getStructInfo() { return maMemberInfo; }
      88             :     SbUnoStructRefObject( const OUString& aName_, const StructRefInfo& rMemberInfo );
      89             :     virtual ~SbUnoStructRefObject();
      90             : 
      91             :     // Find overloaded to support e. g. NameAccess
      92             :     virtual SbxVariable* Find( const OUString&, SbxClassType ) SAL_OVERRIDE;
      93             : 
      94             :     // Force creation of all properties for debugging
      95           0 :     void createAllProperties( void  )
      96           0 :         { implCreateAll(); }
      97             : 
      98             :     // give out value
      99             :     ::com::sun::star::uno::Any getUnoAny();
     100             :     void SFX_NOTIFY( SfxBroadcaster&, const TypeId&, const SfxHint& rHint, const TypeId& ) SAL_OVERRIDE;
     101             : };
     102             : typedef tools::SvRef<SbUnoStructRefObject> SbUnoStructRefObjectRef;
     103             : 
     104             : class SbUnoObject: public SbxObject
     105             : {
     106             :     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XIntrospectionAccess > mxUnoAccess;
     107             :     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMaterialHolder > mxMaterialHolder;
     108             :     ::com::sun::star::uno::Reference< ::com::sun::star::script::XInvocation > mxInvocation;
     109             :     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XExactName > mxExactName;
     110             :     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XExactName > mxExactNameInvocation;
     111             :     bool bNeedIntrospection;
     112             :     bool bNativeCOMObject;
     113             :     ::com::sun::star::uno::Any maTmpUnoObj; // Only to save obj for doIntrospection!
     114             :     ::boost::shared_ptr< SbUnoStructRefObject > maStructInfo;
     115             :     // help method to establish the dbg_-properties
     116             :     void implCreateDbgProperties( void );
     117             : 
     118             :     // help method to establish all properties and methods
     119             :     // (on the on-demand-mechanism required for the dbg_-properties)
     120             :     void implCreateAll( void );
     121             : 
     122             : public:
     123             :     static bool getDefaultPropName( SbUnoObject* pUnoObj, OUString& sDfltProp );
     124             :     TYPEINFO_OVERRIDE();
     125             :     SbUnoObject( const OUString& aName_, const ::com::sun::star::uno::Any& aUnoObj_ );
     126             :     virtual ~SbUnoObject();
     127             : 
     128             :     // #76470 do introspection on demand
     129             :     void doIntrospection( void );
     130             : 
     131             :     // Find overloaded to support e. g. NameAccess
     132             :     virtual SbxVariable* Find( const OUString&, SbxClassType ) SAL_OVERRIDE;
     133             : 
     134             :     // Force creation of all properties for debugging
     135           0 :     void createAllProperties( void  )
     136           0 :         { implCreateAll(); }
     137             : 
     138             :     // give out value
     139             :     ::com::sun::star::uno::Any getUnoAny( void );
     140           0 :     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XIntrospectionAccess > getIntrospectionAccess( void )    { return mxUnoAccess; }
     141           0 :     ::com::sun::star::uno::Reference< ::com::sun::star::script::XInvocation > getInvocation( void )         { return mxInvocation; }
     142             : 
     143             :     void SFX_NOTIFY( SfxBroadcaster&, const TypeId&, const SfxHint& rHint, const TypeId& ) SAL_OVERRIDE;
     144             : 
     145           0 :     bool isNativeCOMObject( void )
     146           0 :         { return bNativeCOMObject; }
     147             : };
     148             : typedef tools::SvRef<SbUnoObject> SbUnoObjectRef;
     149             : 
     150             : // #67781 delete return values of the uno-methods
     151             : void clearUnoMethods( void );
     152             : void clearUnoMethodsForBasic( StarBASIC* pBasic );
     153             : 
     154             : class SbUnoMethod : public SbxMethod
     155             : {
     156             :     friend class SbUnoObject;
     157             :     friend void clearUnoMethods( void );
     158             :     friend void clearUnoMethodsForBasic( StarBASIC* pBasic );
     159             : 
     160             :     ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlMethod > m_xUnoMethod;
     161             :     ::com::sun::star::uno::Sequence< ::com::sun::star::reflection::ParamInfo >* pParamInfoSeq;
     162             : 
     163             :     // #67781 reference to the previous and the next method in the method list
     164             :     SbUnoMethod* pPrev;
     165             :     SbUnoMethod* pNext;
     166             : 
     167             :     bool mbInvocation;       // Method is based on invocation
     168             :     bool mbDirectInvocation; // Method should be used with XDirectInvocation interface
     169             : 
     170             : public:
     171             :     TYPEINFO_OVERRIDE();
     172             : 
     173             :     SbUnoMethod( const OUString& aName_, SbxDataType eSbxType, ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlMethod > xUnoMethod_,
     174             :         bool bInvocation,
     175             :         bool bDirect = false );
     176             :     virtual ~SbUnoMethod();
     177             :     virtual SbxInfo* GetInfo() SAL_OVERRIDE;
     178             : 
     179             :     const ::com::sun::star::uno::Sequence< ::com::sun::star::reflection::ParamInfo >& getParamInfos( void );
     180             : 
     181        4214 :     bool isInvocationBased( void )
     182        4214 :         { return mbInvocation; }
     183             :     bool needsDirectInvocation( void )
     184             :         { return mbDirectInvocation; }
     185             : };
     186             : 
     187             : 
     188             : 
     189             : class SbUnoProperty : public SbxProperty
     190             : {
     191             :     friend class SbUnoObject;
     192             :     friend class SbUnoStructRefObject;
     193             : 
     194             :     ::com::sun::star::beans::Property aUnoProp;
     195             :     sal_Int32 nId;
     196             : 
     197             :     bool mbInvocation;      // Property is based on invocation
     198             :     SbxDataType mRealType;
     199             :     virtual ~SbUnoProperty();
     200             :     bool mbUnoStruct;
     201             :     SbUnoProperty( const SbUnoProperty&);
     202             :     SbUnoProperty& operator = ( const SbUnoProperty&);
     203             : public:
     204             : 
     205             :     TYPEINFO_OVERRIDE();
     206             :     SbUnoProperty( const OUString& aName_, SbxDataType eSbxType, SbxDataType eRealSbxType,
     207             :         const ::com::sun::star::beans::Property& aUnoProp_, sal_Int32 nId_, bool bInvocation, bool bUnoStruct );
     208             : 
     209          98 :     bool isUnoStruct() { return mbUnoStruct; }
     210        4484 :     bool isInvocationBased( void )
     211        4484 :         { return mbInvocation; }
     212           0 :     SbxDataType getRealType() { return mRealType; }
     213             : };
     214             : 
     215             : // factory class to create uno-structs per DIM AS NEW
     216         506 : class SbUnoFactory : public SbxFactory
     217             : {
     218             : public:
     219             :     virtual SbxBase* Create( sal_uInt16 nSbxId, sal_uInt32 = SBXCR_SBX ) SAL_OVERRIDE;
     220             :     virtual SbxObject* CreateObject( const OUString& ) SAL_OVERRIDE;
     221             : };
     222             : 
     223             : // wrapper for an uno-class
     224          40 : class SbUnoClass : public SbxObject
     225             : {
     226             :     const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlClass >   m_xClass;
     227             : 
     228             : public:
     229             :     TYPEINFO_OVERRIDE();
     230          18 :     SbUnoClass( const OUString& aName_ )
     231          18 :         : SbxObject( aName_ )
     232          18 :     {}
     233           2 :     SbUnoClass( const OUString& aName_, const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlClass >& xClass_ )
     234             :         : SbxObject( aName_ )
     235           2 :         , m_xClass( xClass_ )
     236           2 :     {}
     237             : 
     238             : 
     239             :     virtual SbxVariable* Find( const OUString&, SbxClassType ) SAL_OVERRIDE;
     240             : 
     241             : 
     242           0 :     const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlClass >& getUnoClass( void ) { return m_xClass; }
     243             : 
     244             : };
     245             : typedef tools::SvRef<SbUnoClass> SbUnoClassRef;
     246             : 
     247             : 
     248             : // function to find a global identifier in
     249             : // the UnoScope and to wrap it for Sbx
     250             : SbUnoClass* findUnoClass( const OUString& rName );
     251             : 
     252             : 
     253             : // Wrapper for UNO Service
     254           0 : class SbUnoService : public SbxObject
     255             : {
     256             :     const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XServiceTypeDescription2 > m_xServiceTypeDesc;
     257             :     bool m_bNeedsInit;
     258             : 
     259             : public:
     260             :     TYPEINFO_OVERRIDE();
     261           0 :     SbUnoService( const OUString& aName_,
     262             :         const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XServiceTypeDescription2 >& xServiceTypeDesc )
     263             :             : SbxObject( aName_ )
     264             :             , m_xServiceTypeDesc( xServiceTypeDesc )
     265           0 :             , m_bNeedsInit( true )
     266           0 :     {}
     267             : 
     268             :     virtual SbxVariable* Find( const OUString&, SbxClassType ) SAL_OVERRIDE;
     269             : 
     270             :     void SFX_NOTIFY( SfxBroadcaster&, const TypeId&, const SfxHint& rHint, const TypeId& ) SAL_OVERRIDE;
     271             : };
     272             : typedef tools::SvRef<SbUnoService> SbUnoServiceRef;
     273             : 
     274             : SbUnoService* findUnoService( const OUString& rName );
     275             : 
     276             : 
     277             : void clearUnoServiceCtors( void );
     278             : 
     279             : class SbUnoServiceCtor : public SbxMethod
     280             : {
     281             :     friend class SbUnoService;
     282             :     friend void clearUnoServiceCtors( void );
     283             : 
     284             :     ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XServiceConstructorDescription > m_xServiceCtorDesc;
     285             : 
     286             :     SbUnoServiceCtor* pNext;
     287             : 
     288             : public:
     289             :     TYPEINFO_OVERRIDE();
     290             : 
     291             :     SbUnoServiceCtor( const OUString& aName_, ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XServiceConstructorDescription > xServiceCtorDesc );
     292             :     virtual ~SbUnoServiceCtor();
     293             :     virtual SbxInfo* GetInfo() SAL_OVERRIDE;
     294             : 
     295           0 :     ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XServiceConstructorDescription > getServiceCtorDesc( void )
     296           0 :         { return m_xServiceCtorDesc; }
     297             : };
     298             : 
     299             : 
     300             : // Wrapper for UNO Singleton
     301           0 : class SbUnoSingleton : public SbxObject
     302             : {
     303             :     const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XSingletonTypeDescription >   m_xSingletonTypeDesc;
     304             : 
     305             : public:
     306             :     TYPEINFO_OVERRIDE();
     307             :     SbUnoSingleton( const OUString& aName_,
     308             :         const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XSingletonTypeDescription >& xSingletonTypeDesc );
     309             : 
     310             :     void SFX_NOTIFY( SfxBroadcaster&, const TypeId&, const SfxHint& rHint, const TypeId& ) SAL_OVERRIDE;
     311             : };
     312             : typedef tools::SvRef<SbUnoSingleton> SbUnoSingletonRef;
     313             : 
     314             : SbUnoSingleton* findUnoSingleton( const OUString& rName );
     315             : 
     316             : 
     317             : // #105565 Special Object to wrap a strongly typed Uno Any
     318           0 : class SbUnoAnyObject: public SbxObject
     319             : {
     320             :     ::com::sun::star::uno::Any     mVal;
     321             : 
     322             : public:
     323           0 :     SbUnoAnyObject( const ::com::sun::star::uno::Any& rVal )
     324             :         : SbxObject( OUString() )
     325           0 :         , mVal( rVal )
     326           0 :     {}
     327             : 
     328           0 :     const ::com::sun::star::uno::Any& getValue( void )
     329           0 :         { return mVal; }
     330             : 
     331             :     TYPEINFO_OVERRIDE();
     332             : };
     333             : 
     334             : 
     335             : // #112509 Special SbxArray to transport named parameters for calls
     336             : // to OLEAutomation objects through the UNO OLE automation bridge
     337             : 
     338           0 : class AutomationNamedArgsSbxArray : public SbxArray
     339             : {
     340             :     ::com::sun::star::uno::Sequence< OUString >      maNameSeq;
     341             : public:
     342             :     TYPEINFO_OVERRIDE();
     343           0 :     AutomationNamedArgsSbxArray( sal_Int32 nSeqSize )
     344           0 :         : maNameSeq( nSeqSize )
     345           0 :     {}
     346             : 
     347           0 :     ::com::sun::star::uno::Sequence< OUString >& getNames( void )
     348           0 :         { return maNameSeq; }
     349             : };
     350             : 
     351             : 
     352             : class StarBASIC;
     353             : 
     354             : // Impl-methods for RTL
     355             : void RTL_Impl_CreateUnoStruct( StarBASIC* pBasic, SbxArray& rPar, bool bWrite );
     356             : void RTL_Impl_CreateUnoService( StarBASIC* pBasic, SbxArray& rPar, bool bWrite );
     357             : void RTL_Impl_CreateUnoServiceWithArguments( StarBASIC* pBasic, SbxArray& rPar, bool bWrite );
     358             : void RTL_Impl_CreateUnoValue( StarBASIC* pBasic, SbxArray& rPar, bool bWrite );
     359             : void RTL_Impl_GetProcessServiceManager( StarBASIC* pBasic, SbxArray& rPar, bool bWrite );
     360             : void RTL_Impl_HasInterfaces( StarBASIC* pBasic, SbxArray& rPar, bool bWrite );
     361             : void RTL_Impl_IsUnoStruct( StarBASIC* pBasic, SbxArray& rPar, bool bWrite );
     362             : void RTL_Impl_EqualUnoObjects( StarBASIC* pBasic, SbxArray& rPar, bool bWrite );
     363             : void RTL_Impl_GetDefaultContext( StarBASIC* pBasic, SbxArray& rPar, bool bWrite );
     364             : 
     365             : void disposeComVariablesForBasic( StarBASIC* pBasic );
     366             : void clearNativeObjectWrapperVector( void );
     367             : 
     368             : 
     369             : 
     370             : // #118116 Collection object
     371             : 
     372             : class BasicCollection : public SbxObject
     373             : {
     374             :     friend class SbiRuntime;
     375             :     SbxArrayRef xItemArray;
     376             :     static SbxInfoRef xAddInfo;
     377             :     static SbxInfoRef xItemInfo;
     378             : 
     379             :     void Initialize();
     380             :     virtual ~BasicCollection();
     381             :     virtual void SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType,
     382             :                              const SfxHint& rHint, const TypeId& rHintType ) SAL_OVERRIDE;
     383             :     sal_Int32 implGetIndex( SbxVariable* pIndexVar );
     384             :     sal_Int32 implGetIndexForName( const OUString& rName );
     385             :     void CollAdd( SbxArray* pPar_ );
     386             :     void CollItem( SbxArray* pPar_ );
     387             :     void CollRemove( SbxArray* pPar_ );
     388             : 
     389             : public:
     390             :     TYPEINFO_OVERRIDE();
     391             :     BasicCollection( const OUString& rClassname );
     392             :     virtual SbxVariable* Find( const OUString&, SbxClassType ) SAL_OVERRIDE;
     393             :     virtual void Clear() SAL_OVERRIDE;
     394             : };
     395             : 
     396             : typedef boost::unordered_map< OUString, ::com::sun::star::uno::Any, OUStringHash, ::std::equal_to< OUString > > VBAConstantsHash;
     397             : 
     398             : typedef std::vector< OUString > VBAConstantsVector;
     399             : 
     400           4 : class VBAConstantHelper
     401             : {
     402             : private:
     403             : 
     404             :     VBAConstantsVector aConstCache;
     405             :     VBAConstantsHash aConstHash;
     406             :     bool isInited;
     407           4 :     VBAConstantHelper():isInited( false ) {}
     408             :     VBAConstantHelper(const VBAConstantHelper&);
     409             :     void init();
     410             : public:
     411             :     static VBAConstantHelper& instance();
     412             :     SbxVariable* getVBAConstant( const OUString& rName );
     413             :     bool isVBAConstantType( const OUString& rName );
     414             : };
     415             : 
     416             : SbxVariable* getDefaultProp( SbxVariable* pRef );
     417             : 
     418             : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > createComListener( const ::com::sun::star::uno::Any& aControlAny,
     419             :                                                                                          const OUString& aVBAType,
     420             :                                                                                          const OUString& aPrefix,
     421             :                                                                                          SbxObjectRef xScopeObj );
     422             : 
     423             : bool checkUnoObjectType( SbUnoObject* refVal, const OUString& aClass );
     424             : 
     425             : SbUnoObject* createOLEObject_Impl( const OUString& aType );
     426             : 
     427             : // #55226 ship additional information
     428             : bool handleToStringForCOMObjects( SbxObject* pObj, SbxValue* pVal );
     429             : 
     430             : void registerComListenerVariableForBasic( SbxVariable* pVar, StarBASIC* pBasic );
     431             : 
     432             : #endif
     433             : 
     434             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10