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

Generated by: LCOV version 1.11