bump product version to 4.1.6.2
[LibreOffice.git] / sc / inc / addincol.hxx
blob15abd4c7bce5f2416e81dac0f96fd16df34e0906
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef SC_ADDINCOL_HXX
21 #define SC_ADDINCOL_HXX
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>
35 #include "scmatrix.hxx"
37 #include <boost/unordered_map.hpp>
40 class String;
41 class SfxObjectShell;
42 class ScUnoAddInFuncData;
43 class ScFuncDesc;
46 typedef ::boost::unordered_map< OUString, const ScUnoAddInFuncData*, ScStringHashCode, ::std::equal_to< OUString > > ScAddInHashMap;
49 enum ScAddInArgumentType
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>
65 //------------------------------------------------------------------------
67 struct ScAddInArgDesc
69 OUString aInternalName; ///< used to match configuration and reflection information
70 OUString aName;
71 OUString aDescription;
72 ScAddInArgumentType eType;
73 bool bOptional;
76 class ScUnoAddInFuncData
78 public:
79 struct LocalizedName
81 OUString maLocale;
82 OUString maName;
84 LocalizedName( const OUString& rLocale, const OUString& rName )
85 : maLocale( rLocale), maName( rName) { }
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;
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();
114 const OUString& GetOriginalName() const { return aOriginalName; }
115 const OUString& GetLocalName() const { return aLocalName; }
116 const OUString& GetUpperName() const { return aUpperName; }
117 const OUString& GetUpperLocal() const { return aUpperLocal; }
118 const com::sun::star::uno::Reference< com::sun::star::reflection::XIdlMethod>& GetFunction() const
119 { return xFunction; }
120 const com::sun::star::uno::Any& GetObject() const { return aObject; }
121 long GetArgumentCount() const { return nArgCount; }
122 const ScAddInArgDesc* GetArguments() const { return pArgDescs; }
123 long GetCallerPos() const { return nCallerPos; }
124 const OUString& GetDescription() const { return aDescription; }
125 sal_uInt16 GetCategory() const { return nCategory; }
126 const OString GetHelpId() const { return sHelpId; }
128 const ::std::vector< LocalizedName >& GetCompNames() const;
129 bool GetExcelName( LanguageType eDestLang, OUString& rRetExcelName ) const;
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 );
138 //------------------------------------------------------------------------
140 class SC_DLLPUBLIC ScUnoAddInCollection
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;
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 );
159 public:
160 ScUnoAddInCollection();
161 ~ScUnoAddInCollection();
163 /// User enetered name. rUpperName MUST already be upper case!
164 OUString FindFunction( const OUString& rUpperName, bool bLocalFirst );
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 );
171 /** For enumeration in ScCompiler::OpCodeMap::getAvailableMappings().
172 @param nIndex
173 0 <= nIndex < GetFuncCount()
175 const ScUnoAddInFuncData* GetFuncData( long nIndex );
177 void Clear();
179 void LocalizeString( OUString& rName ); ///< modify rName - input: exact name
181 long GetFuncCount();
182 bool FillFunctionDesc( long nFunc, ScFuncDesc& rDesc );
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 );
192 class ScUnoAddInCall
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;
208 void ExecuteCallWithArgs(
209 com::sun::star::uno::Sequence<com::sun::star::uno::Any>& rCallArgs);
211 public:
212 // exact name
213 ScUnoAddInCall( ScUnoAddInCollection& rColl, const OUString& rName,
214 long nParamCount );
215 ~ScUnoAddInCall();
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 );
222 bool ValidParamCount();
223 ScAddInArgumentType GetArgType( long nPos );
224 void SetParam( long nPos, const com::sun::star::uno::Any& rValue );
226 void ExecuteCall();
228 void SetResult( const com::sun::star::uno::Any& rNewRes );
230 sal_uInt16 GetErrCode() const { return nErrCode; }
231 bool HasString() const { return bHasString; }
232 bool HasMatrix() const { return xMatrix.get(); }
233 bool HasVarRes() const { return ( xVarRes.is() ); }
234 double GetValue() const { return fValue; }
235 const OUString& GetString() const { return aString; }
236 ScMatrixRef GetMatrix() const { return xMatrix; }
237 com::sun::star::uno::Reference<com::sun::star::sheet::XVolatileResult>
238 GetVarRes() const { return xVarRes; }
242 #endif
244 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */