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

Generated by: LCOV version 1.10