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

Generated by: LCOV version 1.10