build fix
[LibreOffice.git] / sc / inc / addincol.hxx
blob79150156f9693af3f8598e73e326375ecb07d025
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>
34 #include "scmatrix.hxx"
36 #include "types.hxx"
38 #include <unordered_map>
40 class SfxObjectShell;
41 class ScUnoAddInFuncData;
42 class ScFuncDesc;
44 typedef std::unordered_map< OUString, const ScUnoAddInFuncData*, OUStringHash > ScAddInHashMap;
46 enum ScAddInArgumentType
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>
62 struct ScAddInArgDesc
64 OUString aInternalName; ///< used to match configuration and reflection information
65 OUString aName;
66 OUString aDescription;
67 ScAddInArgumentType eType;
68 bool bOptional;
71 class ScUnoAddInFuncData
73 public:
74 struct LocalizedName
76 OUString maLocale;
77 OUString maName;
79 LocalizedName( const OUString& rLocale, const OUString& rName )
80 : maLocale( rLocale), maName( rName) { }
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 css::uno::Reference< css::reflection::XIdlMethod> xFunction;
89 css::uno::Any aObject;
90 long nArgCount;
91 std::unique_ptr<ScAddInArgDesc[]>
92 pArgDescs;
93 long nCallerPos;
94 sal_uInt16 nCategory;
95 OString sHelpId;
96 mutable ::std::vector< LocalizedName > maCompNames;
97 mutable bool bCompInitialized;
99 public:
100 ScUnoAddInFuncData( const OUString& rNam, const OUString& rLoc,
101 const OUString& rDesc,
102 sal_uInt16 nCat, const OString&,
103 const css::uno::Reference< css::reflection::XIdlMethod>& rFunc,
104 const css::uno::Any& rO,
105 long nAC, const ScAddInArgDesc* pAD,
106 long nCP );
107 ~ScUnoAddInFuncData();
109 const OUString& GetOriginalName() const { return aOriginalName; }
110 const OUString& GetLocalName() const { return aLocalName; }
111 const OUString& GetUpperName() const { return aUpperName; }
112 const OUString& GetUpperLocal() const { return aUpperLocal; }
113 const css::uno::Reference< css::reflection::XIdlMethod>& GetFunction() const
114 { return xFunction; }
115 const css::uno::Any& GetObject() const { return aObject; }
116 long GetArgumentCount() const { return nArgCount; }
117 const ScAddInArgDesc* GetArguments() const { return pArgDescs.get(); }
118 long GetCallerPos() const { return nCallerPos; }
119 const OUString& GetDescription() const { return aDescription; }
120 sal_uInt16 GetCategory() const { return nCategory; }
121 const OString& GetHelpId() const { return sHelpId; }
123 const ::std::vector< LocalizedName >& GetCompNames() const;
124 bool GetExcelName( LanguageType eDestLang, OUString& rRetExcelName ) const;
126 void SetFunction( const css::uno::Reference< css::reflection::XIdlMethod>& rNewFunc,
127 const css::uno::Any& rNewObj );
128 void SetArguments( long nNewCount, const ScAddInArgDesc* pNewDescs );
129 void SetCallerPos( long nNewPos );
130 void SetCompNames( const ::std::vector< LocalizedName >& rNew );
133 class SC_DLLPUBLIC ScUnoAddInCollection
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;
143 void Initialize();
144 void ReadConfiguration();
145 void ReadFromAddIn( const css::uno::Reference< css::uno::XInterface>& xInterface );
146 void UpdateFromAddIn( const css::uno::Reference< css::uno::XInterface>& xInterface,
147 const OUString& rServiceName );
148 void LoadComponent( const ScUnoAddInFuncData& rFuncData );
150 public:
151 ScUnoAddInCollection();
152 ~ScUnoAddInCollection();
154 /// User entered name. rUpperName MUST already be upper case!
155 OUString FindFunction( const OUString& rUpperName, bool bLocalFirst );
157 /** Only if bComplete is set, the function reference and argument types
158 are initialized (component may have to be loaded).
159 @param rName is the exact Name. */
160 const ScUnoAddInFuncData* GetFuncData( const OUString& rName, bool bComplete = false );
162 /** For enumeration in ScCompiler::OpCodeMap::getAvailableMappings().
163 @param nIndex
164 0 <= nIndex < GetFuncCount()
166 const ScUnoAddInFuncData* GetFuncData( long nIndex );
168 void Clear();
170 void LocalizeString( OUString& rName ); ///< modify rName - input: exact name
172 long GetFuncCount();
173 bool FillFunctionDesc( long nFunc, ScFuncDesc& rDesc );
175 static bool FillFunctionDescFromData( const ScUnoAddInFuncData& rFuncData, ScFuncDesc& rDesc );
176 /// leave rRetExcelName unchanged, if no matching name is found
177 bool GetExcelName( const OUString& rCalcName, LanguageType eDestLang, OUString& rRetExcelName );
178 /// leave rRetCalcName unchanged, if no matching name is found
179 bool GetCalcName( const OUString& rExcelName, OUString& rRetCalcName );
182 class ScUnoAddInCall
184 private:
185 const ScUnoAddInFuncData* pFuncData;
186 css::uno::Sequence<css::uno::Any> aArgs;
187 css::uno::Sequence<css::uno::Any> aVarArg;
188 css::uno::Reference<css::uno::XInterface> xCaller;
189 bool bValidCount;
190 // result:
191 FormulaError nErrCode;
192 bool bHasString;
193 double fValue;
194 OUString aString;
195 ScMatrixRef xMatrix;
196 css::uno::Reference<css::sheet::XVolatileResult> xVarRes;
198 void ExecuteCallWithArgs(css::uno::Sequence<css::uno::Any>& rCallArgs);
200 public:
201 // exact name
202 ScUnoAddInCall( ScUnoAddInCollection& rColl, const OUString& rName,
203 long nParamCount );
204 ~ScUnoAddInCall();
206 bool NeedsCaller() const;
207 void SetCaller( const css::uno::Reference<css::uno::XInterface>& rInterface );
208 void SetCallerFromObjectShell( SfxObjectShell* pSh );
210 bool ValidParamCount() { return bValidCount;}
211 ScAddInArgumentType GetArgType( long nPos );
212 void SetParam( long nPos, const css::uno::Any& rValue );
214 void ExecuteCall();
216 void SetResult( const css::uno::Any& rNewRes );
218 FormulaError GetErrCode() const { return nErrCode; }
219 bool HasString() const { return bHasString; }
220 bool HasMatrix() const { return xMatrix.get(); }
221 bool HasVarRes() const { return ( xVarRes.is() ); }
222 double GetValue() const { return fValue; }
223 const OUString& GetString() const { return aString; }
224 const ScMatrixRef& GetMatrix() const { return xMatrix;}
225 const css::uno::Reference<css::sheet::XVolatileResult>&
226 GetVarRes() const { return xVarRes; }
229 #endif
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */