LCOV - code coverage report
Current view: top level - basic/source/inc - sbunoobj.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 24 53 45.3 %
Date: 2015-06-13 12:38:46 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 <unordered_map>
      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        1241 : class StructRefInfo
      45             : {
      46             :     com::sun::star::uno::Any& maAny;
      47             :     css::uno::Type maType;
      48             :     sal_Int32 mnPos;
      49             : public:
      50         845 :     StructRefInfo( com::sun::star::uno::Any& aAny, css::uno::Type const & rType, sal_Int32 nPos ) : maAny( aAny ), maType( rType ), mnPos( nPos ) {}
      51             : 
      52         677 :     sal_Int32 getPos() const { return mnPos; }
      53         197 :     css::uno::Type getType() const { return maType; }
      54             :     OUString getTypeName() const;
      55         677 :     com::sun::star::uno::Any& getRootAnyRef() { return maAny; };
      56             : 
      57             :     com::sun::star::uno::TypeClass getTypeClass() const;
      58             : 
      59             :     void* getInst();
      60         126 :     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        3018 :         bool operator() (const OUString& rProp, const OUString& rOtherProp ) const
      71             :         {
      72        3018 :             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           7 :     StructRefInfo getStructInfo() { return maMemberInfo; }
      88             :     SbUnoStructRefObject( const OUString& aName_, const StructRefInfo& rMemberInfo );
      89             :     virtual ~SbUnoStructRefObject();
      90             : 
      91             :     // override Find 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()
      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             : 
     103             : class SbUnoObject: public SbxObject
     104             : {
     105             :     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XIntrospectionAccess > mxUnoAccess;
     106             :     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMaterialHolder > mxMaterialHolder;
     107             :     ::com::sun::star::uno::Reference< ::com::sun::star::script::XInvocation > mxInvocation;
     108             :     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XExactName > mxExactName;
     109             :     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XExactName > mxExactNameInvocation;
     110             :     bool bNeedIntrospection;
     111             :     bool bNativeCOMObject;
     112             :     ::com::sun::star::uno::Any maTmpUnoObj; // Only to save obj for doIntrospection!
     113             :     ::boost::shared_ptr< SbUnoStructRefObject > maStructInfo;
     114             :     // help method to establish the dbg_-properties
     115             :     void implCreateDbgProperties();
     116             : 
     117             :     // help method to establish all properties and methods
     118             :     // (on the on-demand-mechanism required for the dbg_-properties)
     119             :     void implCreateAll();
     120             : 
     121             : public:
     122             :     static bool getDefaultPropName( SbUnoObject* pUnoObj, OUString& sDfltProp );
     123             :     TYPEINFO_OVERRIDE();
     124             :     SbUnoObject( const OUString& aName_, const ::com::sun::star::uno::Any& aUnoObj_ );
     125             :     virtual ~SbUnoObject();
     126             : 
     127             :     // #76470 do introspection on demand
     128             :     void doIntrospection();
     129             : 
     130             :     // override Find to support e. g. NameAccess
     131             :     virtual SbxVariable* Find( const OUString&, SbxClassType ) SAL_OVERRIDE;
     132             : 
     133             :     // Force creation of all properties for debugging
     134           0 :     void createAllProperties()
     135           0 :         { implCreateAll(); }
     136             : 
     137             :     // give out value
     138             :     ::com::sun::star::uno::Any getUnoAny();
     139           0 :     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XIntrospectionAccess > getIntrospectionAccess()    { return mxUnoAccess; }
     140           0 :     ::com::sun::star::uno::Reference< ::com::sun::star::script::XInvocation > getInvocation()         { return mxInvocation; }
     141             : 
     142             :     void SFX_NOTIFY( SfxBroadcaster&, const TypeId&, const SfxHint& rHint, const TypeId& ) SAL_OVERRIDE;
     143             : 
     144           0 :     bool isNativeCOMObject()
     145           0 :         { return bNativeCOMObject; }
     146             : };
     147             : typedef tools::SvRef<SbUnoObject> SbUnoObjectRef;
     148             : 
     149             : // #67781 delete return values of the uno-methods
     150             : void clearUnoMethods();
     151             : void clearUnoMethodsForBasic( StarBASIC* pBasic );
     152             : 
     153             : class SbUnoMethod : public SbxMethod
     154             : {
     155             :     friend class SbUnoObject;
     156             :     friend void clearUnoMethods();
     157             :     friend void clearUnoMethodsForBasic( StarBASIC* pBasic );
     158             : 
     159             :     ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlMethod > m_xUnoMethod;
     160             :     ::com::sun::star::uno::Sequence< ::com::sun::star::reflection::ParamInfo >* pParamInfoSeq;
     161             : 
     162             :     // #67781 reference to the previous and the next method in the method list
     163             :     SbUnoMethod* pPrev;
     164             :     SbUnoMethod* pNext;
     165             : 
     166             :     bool mbInvocation;       // Method is based on invocation
     167             :     bool mbDirectInvocation; // Method should be used with XDirectInvocation interface
     168             : 
     169             : public:
     170             :     TYPEINFO_OVERRIDE();
     171             : 
     172             :     SbUnoMethod( const OUString& aName_, SbxDataType eSbxType, ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlMethod > xUnoMethod_,
     173             :         bool bInvocation,
     174             :         bool bDirect = false );
     175             :     virtual ~SbUnoMethod();
     176             :     virtual SbxInfo* GetInfo() SAL_OVERRIDE;
     177             : 
     178             :     const ::com::sun::star::uno::Sequence< ::com::sun::star::reflection::ParamInfo >& getParamInfos();
     179             : 
     180        2668 :     bool isInvocationBased()
     181        2668 :         { return mbInvocation; }
     182             :     bool needsDirectInvocation()
     183             :         { return mbDirectInvocation; }
     184             : };
     185             : 
     186             : 
     187             : 
     188             : class SbUnoProperty : public SbxProperty
     189             : {
     190             :     friend class SbUnoObject;
     191             :     friend class SbUnoStructRefObject;
     192             : 
     193             :     ::com::sun::star::beans::Property aUnoProp;
     194             :     sal_Int32 nId;
     195             : 
     196             :     bool mbInvocation;      // Property is based on invocation
     197             :     SbxDataType mRealType;
     198             :     virtual ~SbUnoProperty();
     199             :     bool mbUnoStruct;
     200             :     SbUnoProperty( const SbUnoProperty&) SAL_DELETED_FUNCTION;
     201             :     SbUnoProperty& operator = ( const SbUnoProperty&) SAL_DELETED_FUNCTION;
     202             : public:
     203             : 
     204             :     TYPEINFO_OVERRIDE();
     205             :     SbUnoProperty( const OUString& aName_, SbxDataType eSbxType, SbxDataType eRealSbxType,
     206             :         const ::com::sun::star::beans::Property& aUnoProp_, sal_Int32 nId_, bool bInvocation, bool bUnoStruct );
     207             : 
     208          49 :     bool isUnoStruct() { return mbUnoStruct; }
     209        2611 :     bool isInvocationBased()
     210        2611 :         { return mbInvocation; }
     211           0 :     SbxDataType getRealType() { return mRealType; }
     212             : };
     213             : 
     214             : // factory class to create uno-structs per DIM AS NEW
     215         315 : class SbUnoFactory : public SbxFactory
     216             : {
     217             : public:
     218             :     virtual SbxBase* Create( sal_uInt16 nSbxId, sal_uInt32 = SBXCR_SBX ) SAL_OVERRIDE;
     219             :     virtual SbxObject* CreateObject( const OUString& ) SAL_OVERRIDE;
     220             : };
     221             : 
     222             : // wrapper for an uno-class
     223          20 : class SbUnoClass : public SbxObject
     224             : {
     225             :     const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlClass >   m_xClass;
     226             : 
     227             : public:
     228             :     TYPEINFO_OVERRIDE();
     229           9 :     SbUnoClass( const OUString& aName_ )
     230           9 :         : SbxObject( aName_ )
     231           9 :     {}
     232           1 :     SbUnoClass( const OUString& aName_, const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlClass >& xClass_ )
     233             :         : SbxObject( aName_ )
     234           1 :         , m_xClass( xClass_ )
     235           1 :     {}
     236             : 
     237             : 
     238             :     virtual SbxVariable* Find( const OUString&, SbxClassType ) SAL_OVERRIDE;
     239             : 
     240             : 
     241           0 :     const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlClass >& getUnoClass() { return m_xClass; }
     242             : 
     243             : };
     244             : 
     245             : 
     246             : // function to find a global identifier in
     247             : // the UnoScope and to wrap it for Sbx
     248             : SbUnoClass* findUnoClass( const OUString& rName );
     249             : 
     250             : 
     251             : // Wrapper for UNO Service
     252           0 : class SbUnoService : public SbxObject
     253             : {
     254             :     const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XServiceTypeDescription2 > m_xServiceTypeDesc;
     255             :     bool m_bNeedsInit;
     256             : 
     257             : public:
     258             :     TYPEINFO_OVERRIDE();
     259           0 :     SbUnoService( const OUString& aName_,
     260             :         const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XServiceTypeDescription2 >& xServiceTypeDesc )
     261             :             : SbxObject( aName_ )
     262             :             , m_xServiceTypeDesc( xServiceTypeDesc )
     263           0 :             , m_bNeedsInit( true )
     264           0 :     {}
     265             : 
     266             :     virtual SbxVariable* Find( const OUString&, SbxClassType ) SAL_OVERRIDE;
     267             : 
     268             :     void SFX_NOTIFY( SfxBroadcaster&, const TypeId&, const SfxHint& rHint, const TypeId& ) SAL_OVERRIDE;
     269             : };
     270             : 
     271             : SbUnoService* findUnoService( const OUString& rName );
     272             : 
     273             : 
     274             : void clearUnoServiceCtors();
     275             : 
     276             : class SbUnoServiceCtor : public SbxMethod
     277             : {
     278             :     friend class SbUnoService;
     279             :     friend void clearUnoServiceCtors();
     280             : 
     281             :     ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XServiceConstructorDescription > m_xServiceCtorDesc;
     282             : 
     283             :     SbUnoServiceCtor* pNext;
     284             : 
     285             : public:
     286             :     TYPEINFO_OVERRIDE();
     287             : 
     288             :     SbUnoServiceCtor( const OUString& aName_, ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XServiceConstructorDescription > xServiceCtorDesc );
     289             :     virtual ~SbUnoServiceCtor();
     290             :     virtual SbxInfo* GetInfo() SAL_OVERRIDE;
     291             : 
     292           0 :     ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XServiceConstructorDescription > getServiceCtorDesc()
     293           0 :         { return m_xServiceCtorDesc; }
     294             : };
     295             : 
     296             : 
     297             : // Wrapper for UNO Singleton
     298           0 : class SbUnoSingleton : public SbxObject
     299             : {
     300             :     const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XSingletonTypeDescription >   m_xSingletonTypeDesc;
     301             : 
     302             : public:
     303             :     TYPEINFO_OVERRIDE();
     304             :     SbUnoSingleton( const OUString& aName_,
     305             :         const ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XSingletonTypeDescription >& xSingletonTypeDesc );
     306             : 
     307             :     void SFX_NOTIFY( SfxBroadcaster&, const TypeId&, const SfxHint& rHint, const TypeId& ) SAL_OVERRIDE;
     308             : };
     309             : 
     310             : SbUnoSingleton* findUnoSingleton( const OUString& rName );
     311             : 
     312             : 
     313             : // #105565 Special Object to wrap a strongly typed Uno Any
     314           0 : class SbUnoAnyObject: public SbxObject
     315             : {
     316             :     ::com::sun::star::uno::Any     mVal;
     317             : 
     318             : public:
     319           0 :     SbUnoAnyObject( const ::com::sun::star::uno::Any& rVal )
     320             :         : SbxObject( OUString() )
     321           0 :         , mVal( rVal )
     322           0 :     {}
     323             : 
     324           0 :     const ::com::sun::star::uno::Any& getValue()
     325           0 :         { return mVal; }
     326             : 
     327             :     TYPEINFO_OVERRIDE();
     328             : };
     329             : 
     330             : 
     331             : // #112509 Special SbxArray to transport named parameters for calls
     332             : // to OLEAutomation objects through the UNO OLE automation bridge
     333             : 
     334           0 : class AutomationNamedArgsSbxArray : public SbxArray
     335             : {
     336             :     ::com::sun::star::uno::Sequence< OUString >      maNameSeq;
     337             : public:
     338             :     TYPEINFO_OVERRIDE();
     339           0 :     AutomationNamedArgsSbxArray( sal_Int32 nSeqSize )
     340           0 :         : maNameSeq( nSeqSize )
     341           0 :     {}
     342             : 
     343           0 :     ::com::sun::star::uno::Sequence< OUString >& getNames()
     344           0 :         { return maNameSeq; }
     345             : };
     346             : 
     347             : 
     348             : class StarBASIC;
     349             : 
     350             : // Impl-methods for RTL
     351             : void RTL_Impl_CreateUnoStruct( StarBASIC* pBasic, SbxArray& rPar, bool bWrite );
     352             : void RTL_Impl_CreateUnoService( StarBASIC* pBasic, SbxArray& rPar, bool bWrite );
     353             : void RTL_Impl_CreateUnoServiceWithArguments( StarBASIC* pBasic, SbxArray& rPar, bool bWrite );
     354             : void RTL_Impl_CreateUnoValue( StarBASIC* pBasic, SbxArray& rPar, bool bWrite );
     355             : void RTL_Impl_GetProcessServiceManager( StarBASIC* pBasic, SbxArray& rPar, bool bWrite );
     356             : void RTL_Impl_HasInterfaces( StarBASIC* pBasic, SbxArray& rPar, bool bWrite );
     357             : void RTL_Impl_IsUnoStruct( StarBASIC* pBasic, SbxArray& rPar, bool bWrite );
     358             : void RTL_Impl_EqualUnoObjects( StarBASIC* pBasic, SbxArray& rPar, bool bWrite );
     359             : void RTL_Impl_GetDefaultContext( StarBASIC* pBasic, SbxArray& rPar, bool bWrite );
     360             : 
     361             : void disposeComVariablesForBasic( StarBASIC* pBasic );
     362             : void clearNativeObjectWrapperVector();
     363             : 
     364             : 
     365             : 
     366             : // #118116 Collection object
     367             : 
     368             : class BasicCollection : public SbxObject
     369             : {
     370             :     friend class SbiRuntime;
     371             :     SbxArrayRef xItemArray;
     372             :     static SbxInfoRef xAddInfo;
     373             :     static SbxInfoRef xItemInfo;
     374             : 
     375             :     void Initialize();
     376             :     virtual ~BasicCollection();
     377             :     virtual void SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType,
     378             :                              const SfxHint& rHint, const TypeId& rHintType ) SAL_OVERRIDE;
     379             :     sal_Int32 implGetIndex( SbxVariable* pIndexVar );
     380             :     sal_Int32 implGetIndexForName( const OUString& rName );
     381             :     void CollAdd( SbxArray* pPar_ );
     382             :     void CollItem( SbxArray* pPar_ );
     383             :     void CollRemove( SbxArray* pPar_ );
     384             : 
     385             : public:
     386             :     TYPEINFO_OVERRIDE();
     387             :     BasicCollection( const OUString& rClassname );
     388             :     virtual SbxVariable* Find( const OUString&, SbxClassType ) SAL_OVERRIDE;
     389             :     virtual void Clear() SAL_OVERRIDE;
     390             : };
     391             : 
     392             : typedef std::unordered_map< OUString, ::com::sun::star::uno::Any, OUStringHash, ::std::equal_to< OUString > > VBAConstantsHash;
     393             : 
     394             : typedef std::vector< OUString > VBAConstantsVector;
     395             : 
     396           2 : class VBAConstantHelper
     397             : {
     398             : private:
     399             : 
     400             :     VBAConstantsVector aConstCache;
     401             :     VBAConstantsHash aConstHash;
     402             :     bool isInited;
     403           2 :     VBAConstantHelper():isInited( false ) {}
     404             :     VBAConstantHelper(const VBAConstantHelper&) SAL_DELETED_FUNCTION;
     405             :     void init();
     406             : public:
     407             :     static VBAConstantHelper& instance();
     408             :     SbxVariable* getVBAConstant( const OUString& rName );
     409             :     bool isVBAConstantType( const OUString& rName );
     410             : };
     411             : 
     412             : SbxVariable* getDefaultProp( SbxVariable* pRef );
     413             : 
     414             : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > createComListener( const ::com::sun::star::uno::Any& aControlAny,
     415             :                                                                                          const OUString& aVBAType,
     416             :                                                                                          const OUString& aPrefix,
     417             :                                                                                          SbxObjectRef xScopeObj );
     418             : 
     419             : bool checkUnoObjectType( SbUnoObject* refVal, const OUString& aClass );
     420             : 
     421             : SbUnoObject* createOLEObject_Impl( const OUString& aType );
     422             : 
     423             : // #55226 ship additional information
     424             : bool handleToStringForCOMObjects( SbxObject* pObj, SbxValue* pVal );
     425             : 
     426             : void registerComListenerVariableForBasic( SbxVariable* pVar, StarBASIC* pBasic );
     427             : 
     428             : #endif
     429             : 
     430             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11