LCOV - code coverage report
Current view: top level - sc/inc - addincol.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 11 22 50.0 %
Date: 2012-08-25 Functions: 12 23 52.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           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                 :            : #ifndef SC_ADDINCOL_HXX
      30                 :            : #define SC_ADDINCOL_HXX
      31                 :            : 
      32                 :            : #include "global.hxx"
      33                 :            : #include <com/sun/star/sheet/XVolatileResult.hpp>
      34                 :            : #include <com/sun/star/sheet/XAddIn.hpp>
      35                 :            : #include <com/sun/star/sheet/XResultListener.hpp>
      36                 :            : #include <com/sun/star/sheet/ResultEvent.hpp>
      37                 :            : #include <com/sun/star/container/XNameAccess.hpp>
      38                 :            : #include <com/sun/star/reflection/XIdlMethod.hpp>
      39                 :            : #include <com/sun/star/sheet/LocalizedName.hpp>
      40                 :            : #include <i18npool/lang.h>
      41                 :            : #include <rtl/ustring.h>
      42                 :            : #include "scdllapi.h"
      43                 :            : #include <rtl/ustring.hxx>
      44                 :            : 
      45                 :            : #include "scmatrix.hxx"
      46                 :            : 
      47                 :            : #include <boost/unordered_map.hpp>
      48                 :            : 
      49                 :            : 
      50                 :            : class String;
      51                 :            : class SfxObjectShell;
      52                 :            : class ScUnoAddInFuncData;
      53                 :            : class ScFuncDesc;
      54                 :            : 
      55                 :            : 
      56                 :            : typedef ::boost::unordered_map< ::rtl::OUString, const ScUnoAddInFuncData*, ScStringHashCode, ::std::equal_to< ::rtl::OUString > > ScAddInHashMap;
      57                 :            : 
      58                 :            : 
      59                 :            : enum ScAddInArgumentType
      60                 :            : {
      61                 :            :     SC_ADDINARG_NONE,                   // -
      62                 :            :     SC_ADDINARG_INTEGER,                // long
      63                 :            :     SC_ADDINARG_DOUBLE,                 // double
      64                 :            :     SC_ADDINARG_STRING,                 // string
      65                 :            :     SC_ADDINARG_INTEGER_ARRAY,          // sequence<sequence<long>>
      66                 :            :     SC_ADDINARG_DOUBLE_ARRAY,           // sequence<sequence<double>>
      67                 :            :     SC_ADDINARG_STRING_ARRAY,           // sequence<sequence<string>>
      68                 :            :     SC_ADDINARG_MIXED_ARRAY,            // sequence<sequence<any>>
      69                 :            :     SC_ADDINARG_VALUE_OR_ARRAY,         // any
      70                 :            :     SC_ADDINARG_CELLRANGE,              // XCellRange
      71                 :            :     SC_ADDINARG_CALLER,                 // XPropertySet
      72                 :            :     SC_ADDINARG_VARARGS                 // sequence<any>
      73                 :            : };
      74                 :            : 
      75                 :            : //------------------------------------------------------------------------
      76                 :            : 
      77                 :      24794 : struct ScAddInArgDesc
      78                 :            : {
      79                 :            :     ::rtl::OUString         aInternalName;      // used to match configuration and reflection information
      80                 :            :     ::rtl::OUString         aName;
      81                 :            :     ::rtl::OUString         aDescription;
      82                 :            :     ScAddInArgumentType eType;
      83                 :            :     sal_Bool                bOptional;
      84                 :            : };
      85                 :            : 
      86                 :            : class ScUnoAddInFuncData
      87                 :            : {
      88                 :            : private:
      89                 :            :     ::rtl::OUString     aOriginalName;      // kept in formula
      90                 :            :     ::rtl::OUString     aLocalName;         // for display
      91                 :            :     ::rtl::OUString     aUpperName;         // for entering formulas
      92                 :            :     ::rtl::OUString     aUpperLocal;        // for entering formulas
      93                 :            :     ::rtl::OUString     aDescription;
      94                 :            :     com::sun::star::uno::Reference< com::sun::star::reflection::XIdlMethod> xFunction;
      95                 :            :     com::sun::star::uno::Any            aObject;
      96                 :            :     long                nArgCount;
      97                 :            :     ScAddInArgDesc*     pArgDescs;
      98                 :            :     long                nCallerPos;
      99                 :            :     sal_uInt16          nCategory;
     100                 :            :     rtl::OString        sHelpId;
     101                 :            :     mutable com::sun::star::uno::Sequence< com::sun::star::sheet::LocalizedName> aCompNames;
     102                 :            :     mutable sal_Bool        bCompInitialized;
     103                 :            : 
     104                 :            : public:
     105                 :            :                 ScUnoAddInFuncData( const ::rtl::OUString& rNam, const ::rtl::OUString& rLoc,
     106                 :            :                                     const ::rtl::OUString& rDesc,
     107                 :            :                                     sal_uInt16 nCat, const rtl::OString&,
     108                 :            :                                     const com::sun::star::uno::Reference<
     109                 :            :                                         com::sun::star::reflection::XIdlMethod>& rFunc,
     110                 :            :                                     const com::sun::star::uno::Any& rO,
     111                 :            :                                     long nAC, const ScAddInArgDesc* pAD,
     112                 :            :                                     long nCP );
     113                 :            :                 ~ScUnoAddInFuncData();
     114                 :            : 
     115                 :       2725 :     const ::rtl::OUString&  GetOriginalName() const     { return aOriginalName; }
     116                 :          0 :     const ::rtl::OUString&  GetLocalName() const        { return aLocalName; }
     117                 :       2616 :     const ::rtl::OUString&  GetUpperName() const        { return aUpperName; }
     118                 :       1635 :     const ::rtl::OUString&  GetUpperLocal() const       { return aUpperLocal; }
     119                 :        218 :     const com::sun::star::uno::Reference< com::sun::star::reflection::XIdlMethod>&   GetFunction() const
     120                 :        218 :                                                         { return xFunction; }
     121                 :          0 :     const com::sun::star::uno::Any& GetObject() const   { return aObject; }
     122                 :        218 :     long                    GetArgumentCount() const    { return nArgCount; }
     123                 :        218 :     const ScAddInArgDesc*   GetArguments() const        { return pArgDescs; }
     124                 :          0 :     long                    GetCallerPos() const        { return nCallerPos; }
     125                 :        218 :     const ::rtl::OUString&  GetDescription() const      { return aDescription; }
     126                 :        218 :     sal_uInt16              GetCategory() const         { return nCategory; }
     127                 :        218 :     const rtl::OString      GetHelpId() const           { return sHelpId; }
     128                 :            : 
     129                 :            :     const com::sun::star::uno::Sequence< com::sun::star::sheet::LocalizedName>&  GetCompNames() const;
     130                 :            :     sal_Bool                    GetExcelName( LanguageType eDestLang, ::rtl::OUString& rRetExcelName ) const;
     131                 :            : 
     132                 :            :     void    SetFunction( const com::sun::star::uno::Reference< com::sun::star::reflection::XIdlMethod>& rNewFunc,
     133                 :            :                          const com::sun::star::uno::Any& rNewObj );
     134                 :            :     void    SetArguments( long nNewCount, const ScAddInArgDesc* pNewDescs );
     135                 :            :     void    SetCallerPos( long nNewPos );
     136                 :            :     void    SetCompNames( const com::sun::star::uno::Sequence< com::sun::star::sheet::LocalizedName>& rNew );
     137                 :            : };
     138                 :            : 
     139                 :            : //------------------------------------------------------------------------
     140                 :            : 
     141                 :            : class SC_DLLPUBLIC ScUnoAddInCollection
     142                 :            : {
     143                 :            : private:
     144                 :            :     long                    nFuncCount;
     145                 :            :     ScUnoAddInFuncData**    ppFuncData;
     146                 :            :     ScAddInHashMap*         pExactHashMap;      // exact internal name
     147                 :            :     ScAddInHashMap*         pNameHashMap;       // internal name upper
     148                 :            :     ScAddInHashMap*         pLocalHashMap;      // localized name upper
     149                 :            :     sal_Bool                    bInitialized;
     150                 :            : 
     151                 :            :     void        Initialize();
     152                 :            :     void        ReadConfiguration();
     153                 :            :     void        ReadFromAddIn( const com::sun::star::uno::Reference<
     154                 :            :                                 com::sun::star::uno::XInterface>& xInterface );
     155                 :            :     void        UpdateFromAddIn( const com::sun::star::uno::Reference<
     156                 :            :                                   com::sun::star::uno::XInterface>& xInterface,
     157                 :            :                                 const ::rtl::OUString& rServiceName );
     158                 :            :     void        LoadComponent( const ScUnoAddInFuncData& rFuncData );
     159                 :            : 
     160                 :            : public:
     161                 :            :                 ScUnoAddInCollection();
     162                 :            :                 ~ScUnoAddInCollection();
     163                 :            : 
     164                 :            :                         /// User enetered name. rUpperName MUST already be upper case!
     165                 :            :     ::rtl::OUString     FindFunction( const ::rtl::OUString& rUpperName, sal_Bool bLocalFirst );
     166                 :            : 
     167                 :            :                         // rName is the exact Name.
     168                 :            :                         // Only if bComplete is set, the function reference and argument types
     169                 :            :                         // are initialized (component may have to be loaded).
     170                 :            :     const ScUnoAddInFuncData*   GetFuncData( const ::rtl::OUString& rName, bool bComplete = false );
     171                 :            : 
     172                 :            :                         /** For enumeration in ScCompiler::OpCodeMap::getAvailableMappings().
     173                 :            :                             @param nIndex
     174                 :            :                                 0 <= nIndex < GetFuncCount()
     175                 :            :                          */
     176                 :            :     const ScUnoAddInFuncData*   GetFuncData( long nIndex );
     177                 :            : 
     178                 :            :     void                Clear();
     179                 :            : 
     180                 :            :     void                LocalizeString( ::rtl::OUString& rName );    // modify rName - input: exact name
     181                 :            : 
     182                 :            :     long                GetFuncCount();
     183                 :            :     sal_Bool                FillFunctionDesc( long nFunc, ScFuncDesc& rDesc );
     184                 :            : 
     185                 :            :     static sal_Bool         FillFunctionDescFromData( const ScUnoAddInFuncData& rFuncData, ScFuncDesc& rDesc );
     186                 :            : 
     187                 :            :     sal_Bool                GetExcelName( const ::rtl::OUString& rCalcName, LanguageType eDestLang, ::rtl::OUString& rRetExcelName );
     188                 :            :     sal_Bool                GetCalcName( const ::rtl::OUString& rExcelName, ::rtl::OUString& rRetCalcName );
     189                 :            :                                 // both leave rRet... unchanged, if no matching name is found
     190                 :            : };
     191                 :            : 
     192                 :            : 
     193                 :            : class ScUnoAddInCall
     194                 :            : {
     195                 :            : private:
     196                 :            :     const ScUnoAddInFuncData*   pFuncData;
     197                 :            :     com::sun::star::uno::Sequence<com::sun::star::uno::Any>         aArgs;
     198                 :            :     com::sun::star::uno::Sequence<com::sun::star::uno::Any>         aVarArg;
     199                 :            :     com::sun::star::uno::Reference<com::sun::star::uno::XInterface> xCaller;
     200                 :            :     sal_Bool                        bValidCount;
     201                 :            :     // result:
     202                 :            :     sal_uInt16                      nErrCode;
     203                 :            :     sal_Bool                        bHasString;
     204                 :            :     double                      fValue;
     205                 :            :     ::rtl::OUString             aString;
     206                 :            :     ScMatrixRef                 xMatrix;
     207                 :            :     com::sun::star::uno::Reference<com::sun::star::sheet::XVolatileResult> xVarRes;
     208                 :            : 
     209                 :            :     void            ExecuteCallWithArgs(
     210                 :            :                         com::sun::star::uno::Sequence<com::sun::star::uno::Any>& rCallArgs);
     211                 :            : 
     212                 :            : public:
     213                 :            :                     // exact name
     214                 :            :                     ScUnoAddInCall( ScUnoAddInCollection& rColl, const ::rtl::OUString& rName,
     215                 :            :                                     long nParamCount );
     216                 :            :                     ~ScUnoAddInCall();
     217                 :            : 
     218                 :            :     sal_Bool                NeedsCaller() const;
     219                 :            :     void                SetCaller( const com::sun::star::uno::Reference<
     220                 :            :                                     com::sun::star::uno::XInterface>& rInterface );
     221                 :            :     void                SetCallerFromObjectShell( SfxObjectShell* pSh );
     222                 :            : 
     223                 :            :     sal_Bool                ValidParamCount();
     224                 :            :     ScAddInArgumentType GetArgType( long nPos );
     225                 :            :     void                SetParam( long nPos, const com::sun::star::uno::Any& rValue );
     226                 :            : 
     227                 :            :     void                ExecuteCall();
     228                 :            : 
     229                 :            :     void                SetResult( const com::sun::star::uno::Any& rNewRes );
     230                 :            : 
     231                 :          0 :     sal_uInt16              GetErrCode() const      { return nErrCode; }
     232                 :          0 :     sal_Bool                HasString() const       { return bHasString; }
     233                 :          0 :     bool                HasMatrix() const       { return xMatrix.get(); }
     234                 :          0 :     sal_Bool                HasVarRes() const       { return ( xVarRes.is() ); }
     235                 :          0 :     double              GetValue() const        { return fValue; }
     236                 :          0 :     const ::rtl::OUString&       GetString() const       { return aString; }
     237                 :          0 :     ScMatrixRef         GetMatrix() const       { return xMatrix; }
     238                 :            :     com::sun::star::uno::Reference<com::sun::star::sheet::XVolatileResult>
     239                 :          0 :                         GetVarRes() const       { return xVarRes; }
     240                 :            : };
     241                 :            : 
     242                 :            : 
     243                 :            : #endif
     244                 :            : 
     245                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10