Bump version to 4.3-4
[LibreOffice.git] / sc / inc / addincol.hxx
blobc6995ea32a477d9ac399fd4f263dec345cab9f36
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 INCLUDED_SC_INC_ADDINCOL_HXX
21 #define INCLUDED_SC_INC_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 "types.hxx"
37 #include <boost/unordered_map.hpp>
39 class SfxObjectShell;
40 class ScUnoAddInFuncData;
41 class ScFuncDesc;
43 typedef ::boost::unordered_map< OUString, const ScUnoAddInFuncData*, OUStringHash > ScAddInHashMap;
45 enum ScAddInArgumentType
47 SC_ADDINARG_NONE, ///< -
48 SC_ADDINARG_INTEGER, ///< long
49 SC_ADDINARG_DOUBLE, ///< double
50 SC_ADDINARG_STRING, ///< string
51 SC_ADDINARG_INTEGER_ARRAY, ///< sequence<sequence<long>>
52 SC_ADDINARG_DOUBLE_ARRAY, ///< sequence<sequence<double>>
53 SC_ADDINARG_STRING_ARRAY, ///< sequence<sequence<string>>
54 SC_ADDINARG_MIXED_ARRAY, ///< sequence<sequence<any>>
55 SC_ADDINARG_VALUE_OR_ARRAY, ///< any
56 SC_ADDINARG_CELLRANGE, ///< XCellRange
57 SC_ADDINARG_CALLER, ///< XPropertySet
58 SC_ADDINARG_VARARGS ///< sequence<any>
61 struct ScAddInArgDesc
63 OUString aInternalName; ///< used to match configuration and reflection information
64 OUString aName;
65 OUString aDescription;
66 ScAddInArgumentType eType;
67 bool bOptional;
70 class ScUnoAddInFuncData
72 public:
73 struct LocalizedName
75 OUString maLocale;
76 OUString maName;
78 LocalizedName( const OUString& rLocale, const OUString& rName )
79 : maLocale( rLocale), maName( rName) { }
81 private:
82 OUString aOriginalName; ///< kept in formula
83 OUString aLocalName; ///< for display
84 OUString aUpperName; ///< for entering formulas
85 OUString aUpperLocal; ///< for entering formulas
86 OUString aDescription;
87 com::sun::star::uno::Reference< com::sun::star::reflection::XIdlMethod> xFunction;
88 com::sun::star::uno::Any aObject;
89 long nArgCount;
90 ScAddInArgDesc* pArgDescs;
91 long nCallerPos;
92 sal_uInt16 nCategory;
93 OString sHelpId;
94 mutable ::std::vector< LocalizedName > maCompNames;
95 mutable bool bCompInitialized;
97 public:
98 ScUnoAddInFuncData( const OUString& rNam, const OUString& rLoc,
99 const OUString& rDesc,
100 sal_uInt16 nCat, const OString&,
101 const com::sun::star::uno::Reference<
102 com::sun::star::reflection::XIdlMethod>& rFunc,
103 const com::sun::star::uno::Any& rO,
104 long nAC, const ScAddInArgDesc* pAD,
105 long nCP );
106 ~ScUnoAddInFuncData();
108 const OUString& GetOriginalName() const { return aOriginalName; }
109 const OUString& GetLocalName() const { return aLocalName; }
110 const OUString& GetUpperName() const { return aUpperName; }
111 const OUString& GetUpperLocal() const { return aUpperLocal; }
112 const com::sun::star::uno::Reference< com::sun::star::reflection::XIdlMethod>& GetFunction() const
113 { return xFunction; }
114 const com::sun::star::uno::Any& GetObject() const { return aObject; }
115 long GetArgumentCount() const { return nArgCount; }
116 const ScAddInArgDesc* GetArguments() const { return pArgDescs; }
117 long GetCallerPos() const { return nCallerPos; }
118 const OUString& GetDescription() const { return aDescription; }
119 sal_uInt16 GetCategory() const { return nCategory; }
120 const OString GetHelpId() const { return sHelpId; }
122 const ::std::vector< LocalizedName >& GetCompNames() const;
123 bool GetExcelName( LanguageType eDestLang, OUString& rRetExcelName ) const;
125 void SetFunction( const com::sun::star::uno::Reference< com::sun::star::reflection::XIdlMethod>& rNewFunc,
126 const com::sun::star::uno::Any& rNewObj );
127 void SetArguments( long nNewCount, const ScAddInArgDesc* pNewDescs );
128 void SetCallerPos( long nNewPos );
129 void SetCompNames( const ::std::vector< LocalizedName >& rNew );
132 class SC_DLLPUBLIC ScUnoAddInCollection
134 private:
135 long nFuncCount;
136 ScUnoAddInFuncData** ppFuncData;
137 ScAddInHashMap* pExactHashMap; ///< exact internal name
138 ScAddInHashMap* pNameHashMap; ///< internal name upper
139 ScAddInHashMap* pLocalHashMap; ///< localized name upper
140 bool bInitialized;
142 void Initialize();
143 void ReadConfiguration();
144 void ReadFromAddIn( const com::sun::star::uno::Reference<
145 com::sun::star::uno::XInterface>& xInterface );
146 void UpdateFromAddIn( const com::sun::star::uno::Reference<
147 com::sun::star::uno::XInterface>& xInterface,
148 const OUString& rServiceName );
149 void LoadComponent( const ScUnoAddInFuncData& rFuncData );
151 public:
152 ScUnoAddInCollection();
153 ~ScUnoAddInCollection();
155 /// User enetered name. rUpperName MUST already be upper case!
156 OUString FindFunction( const OUString& rUpperName, bool bLocalFirst );
158 /** Only if bComplete is set, the function reference and argument types
159 are initialized (component may have to be loaded).
160 @param rName is the exact Name. */
161 const ScUnoAddInFuncData* GetFuncData( const OUString& rName, bool bComplete = false );
163 /** For enumeration in ScCompiler::OpCodeMap::getAvailableMappings().
164 @param nIndex
165 0 <= nIndex < GetFuncCount()
167 const ScUnoAddInFuncData* GetFuncData( long nIndex );
169 void Clear();
171 void LocalizeString( OUString& rName ); ///< modify rName - input: exact name
173 long GetFuncCount();
174 bool FillFunctionDesc( long nFunc, ScFuncDesc& rDesc );
176 static bool FillFunctionDescFromData( const ScUnoAddInFuncData& rFuncData, ScFuncDesc& rDesc );
177 /// leave rRetExcelName unchanged, if no matching name is found
178 bool GetExcelName( const OUString& rCalcName, LanguageType eDestLang, OUString& rRetExcelName );
179 /// leave rRetCalcName unchanged, if no matching name is found
180 bool GetCalcName( const OUString& rExcelName, OUString& rRetCalcName );
183 class ScUnoAddInCall
185 private:
186 const ScUnoAddInFuncData* pFuncData;
187 com::sun::star::uno::Sequence<com::sun::star::uno::Any> aArgs;
188 com::sun::star::uno::Sequence<com::sun::star::uno::Any> aVarArg;
189 com::sun::star::uno::Reference<com::sun::star::uno::XInterface> xCaller;
190 bool bValidCount;
191 // result:
192 sal_uInt16 nErrCode;
193 bool bHasString;
194 double fValue;
195 OUString aString;
196 ScMatrixRef xMatrix;
197 com::sun::star::uno::Reference<com::sun::star::sheet::XVolatileResult> xVarRes;
199 void ExecuteCallWithArgs(
200 com::sun::star::uno::Sequence<com::sun::star::uno::Any>& rCallArgs);
202 public:
203 // exact name
204 ScUnoAddInCall( ScUnoAddInCollection& rColl, const OUString& rName,
205 long nParamCount );
206 ~ScUnoAddInCall();
208 bool NeedsCaller() const;
209 void SetCaller( const com::sun::star::uno::Reference<
210 com::sun::star::uno::XInterface>& rInterface );
211 void SetCallerFromObjectShell( SfxObjectShell* pSh );
213 bool ValidParamCount();
214 ScAddInArgumentType GetArgType( long nPos );
215 void SetParam( long nPos, const com::sun::star::uno::Any& rValue );
217 void ExecuteCall();
219 void SetResult( const com::sun::star::uno::Any& rNewRes );
221 sal_uInt16 GetErrCode() const { return nErrCode; }
222 bool HasString() const { return bHasString; }
223 bool HasMatrix() const { return xMatrix.get(); }
224 bool HasVarRes() const { return ( xVarRes.is() ); }
225 double GetValue() const { return fValue; }
226 const OUString& GetString() const { return aString; }
227 ScMatrixRef GetMatrix() const;
228 com::sun::star::uno::Reference<com::sun::star::sheet::XVolatileResult>
229 GetVarRes() const { return xVarRes; }
232 #endif
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */