Fix build
[LibreOffice.git] / sc / inc / addincol.hxx
blobde5257a22bde432faaf481058f6789667b35e6d1
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 #pragma once
22 #include <memory>
23 #include <com/sun/star/uno/Any.h>
24 #include <com/sun/star/uno/Reference.h>
25 #include <com/sun/star/uno/Sequence.h>
26 #include <formula/errorcodes.hxx>
27 #include <i18nlangtag/lang.h>
28 #include "scdllapi.h"
29 #include <rtl/ustring.hxx>
30 #include <tools/long.hxx>
32 #include "types.hxx"
34 #include <string_view>
35 #include <utility>
36 #include <vector>
37 #include <unordered_map>
39 namespace com::sun::star::reflection { class XIdlMethod; }
40 namespace com::sun::star::sheet { class XVolatileResult; }
41 namespace com::sun::star::uno { class XInterface; }
43 class SfxObjectShell;
44 class ScUnoAddInFuncData;
45 class ScFuncDesc;
46 class LanguageTag;
47 class ScDocument;
49 typedef std::unordered_map< OUString, const ScUnoAddInFuncData* > ScAddInHashMap;
51 enum ScAddInArgumentType
53 SC_ADDINARG_NONE, ///< -
54 SC_ADDINARG_INTEGER, ///< long
55 SC_ADDINARG_DOUBLE, ///< double
56 SC_ADDINARG_STRING, ///< string
57 SC_ADDINARG_INTEGER_ARRAY, ///< sequence<sequence<long>>
58 SC_ADDINARG_DOUBLE_ARRAY, ///< sequence<sequence<double>>
59 SC_ADDINARG_STRING_ARRAY, ///< sequence<sequence<string>>
60 SC_ADDINARG_MIXED_ARRAY, ///< sequence<sequence<any>>
61 SC_ADDINARG_VALUE_OR_ARRAY, ///< any
62 SC_ADDINARG_CELLRANGE, ///< XCellRange
63 SC_ADDINARG_CALLER, ///< XPropertySet
64 SC_ADDINARG_VARARGS ///< sequence<any>
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( OUString aLocale, OUString aName )
85 : maLocale(std::move(aLocale)), maName(std::move(aName)) { }
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 aUpperEnglish; ///< for Function Wizard and tooltips
93 OUString aDescription;
94 css::uno::Reference< css::reflection::XIdlMethod> xFunction;
95 css::uno::Any aObject;
96 sal_Int32 nArgCount;
97 std::unique_ptr<ScAddInArgDesc[]>
98 pArgDescs;
99 sal_Int32 nCallerPos;
100 sal_uInt16 nCategory;
101 OUString sHelpId;
102 mutable ::std::vector< LocalizedName > maCompNames;
103 mutable bool bCompInitialized;
105 public:
106 ScUnoAddInFuncData( const OUString& rNam, const OUString& rLoc,
107 OUString aDesc,
108 sal_uInt16 nCat, OUString ,
109 css::uno::Reference< css::reflection::XIdlMethod> aFunc,
110 css::uno::Any aO,
111 sal_Int32 nAC, const ScAddInArgDesc* pAD,
112 sal_Int32 nCP );
113 ~ScUnoAddInFuncData();
115 const OUString& GetOriginalName() const { return aOriginalName; }
116 const OUString& GetLocalName() const { return aLocalName; }
117 const OUString& GetUpperName() const { return aUpperName; }
118 const OUString& GetUpperLocal() const { return aUpperLocal; }
119 const OUString& GetUpperEnglish() const { return aUpperEnglish; }
120 const css::uno::Reference< css::reflection::XIdlMethod>& GetFunction() const
121 { return xFunction; }
122 const css::uno::Any& GetObject() const { return aObject; }
123 sal_Int32 GetArgumentCount() const { return nArgCount; }
124 const ScAddInArgDesc* GetArguments() const { return pArgDescs.get(); }
125 sal_Int32 GetCallerPos() const { return nCallerPos; }
126 const OUString& GetDescription() const { return aDescription; }
127 sal_uInt16 GetCategory() const { return nCategory; }
128 const OUString& GetHelpId() const { return sHelpId; }
130 const ::std::vector< LocalizedName >& GetCompNames() const;
131 bool GetExcelName( const LanguageTag& rDestLang, OUString& rRetExcelName,
132 bool bFallbackToAny = true ) const;
134 void SetFunction( const css::uno::Reference< css::reflection::XIdlMethod>& rNewFunc,
135 const css::uno::Any& rNewObj );
136 void SetArguments( sal_Int32 nNewCount, const ScAddInArgDesc* pNewDescs );
137 void SetCallerPos( sal_Int32 nNewPos );
138 void SetCompNames( ::std::vector< LocalizedName >&& rNew );
140 /// Takes care of handling an empty name *after* upper local name was set.
141 void SetEnglishName( const OUString& rEnglishName );
144 class ScUnoAddInCollection
146 private:
147 sal_Int32 nFuncCount;
148 std::unique_ptr<std::unique_ptr<ScUnoAddInFuncData>[]> ppFuncData;
149 std::unique_ptr<ScAddInHashMap> pExactHashMap; ///< exact internal name
150 std::unique_ptr<ScAddInHashMap> pNameHashMap; ///< internal name upper
151 std::unique_ptr<ScAddInHashMap> pLocalHashMap; ///< localized name upper
152 std::unique_ptr<ScAddInHashMap> pEnglishHashMap; ///< English name upper
153 bool bInitialized;
155 void Initialize();
156 void ReadConfiguration();
157 void ReadFromAddIn( const css::uno::Reference< css::uno::XInterface>& xInterface );
158 void UpdateFromAddIn( const css::uno::Reference< css::uno::XInterface>& xInterface,
159 std::u16string_view rServiceName );
160 void LoadComponent( const ScUnoAddInFuncData& rFuncData );
162 public:
163 ScUnoAddInCollection();
164 ~ScUnoAddInCollection();
166 /// User entered name. rUpperName MUST already be upper case!
167 OUString FindFunction( const OUString& rUpperName, bool bLocalFirst );
169 /** Only if bComplete is set, the function reference and argument types
170 are initialized (component may have to be loaded).
171 @param rName is the exact Name. */
172 const ScUnoAddInFuncData* GetFuncData( const OUString& rName, bool bComplete = false );
174 /** For enumeration in ScCompiler::OpCodeMap::getAvailableMappings().
175 @param nIndex
176 0 <= nIndex < GetFuncCount()
178 const ScUnoAddInFuncData* GetFuncData( sal_Int32 nIndex );
180 void Clear();
182 void LocalizeString( OUString& rName ); ///< modify rName - input: exact name
184 sal_Int32 GetFuncCount();
185 bool FillFunctionDesc( sal_Int32 nFunc, ScFuncDesc& rDesc, bool bEnglishFunctionNames );
187 static bool FillFunctionDescFromData( const ScUnoAddInFuncData& rFuncData, ScFuncDesc& rDesc,
188 bool bEnglishFunctionNames );
189 /// leave rRetExcelName unchanged, if no matching name is found
190 SC_DLLPUBLIC bool GetExcelName( const OUString& rCalcName, LanguageType eDestLang, OUString& rRetExcelName );
191 /// leave rRetCalcName unchanged, if no matching name is found
192 SC_DLLPUBLIC bool GetCalcName( const OUString& rExcelName, OUString& rRetCalcName );
195 class ScUnoAddInCall
197 private:
198 const ScUnoAddInFuncData* pFuncData;
199 css::uno::Sequence<css::uno::Any> aArgs;
200 css::uno::Sequence<css::uno::Any> aVarArg;
201 css::uno::Reference<css::uno::XInterface> xCaller;
202 ScDocument& mrDoc;
203 bool bValidCount;
204 // result:
205 FormulaError nErrCode;
206 bool bHasString;
207 double fValue;
208 OUString aString;
209 ScMatrixRef xMatrix;
210 css::uno::Reference<css::sheet::XVolatileResult> xVarRes;
212 void ExecuteCallWithArgs(css::uno::Sequence<css::uno::Any>& rCallArgs);
214 public:
215 // exact name
216 ScUnoAddInCall( ScDocument& rDoc, ScUnoAddInCollection& rColl, const OUString& rName,
217 sal_Int32 nParamCount );
218 ~ScUnoAddInCall();
220 bool NeedsCaller() const;
221 void SetCaller( const css::uno::Reference<css::uno::XInterface>& rInterface );
222 void SetCallerFromObjectShell( const SfxObjectShell* pSh );
224 bool ValidParamCount() { return bValidCount;}
225 ScAddInArgumentType GetArgType( sal_Int32 nPos );
226 void SetParam( sal_Int32 nPos, const css::uno::Any& rValue );
228 void ExecuteCall();
230 void SetResult( const css::uno::Any& rNewRes );
232 FormulaError GetErrCode() const { return nErrCode; }
233 bool HasString() const { return bHasString; }
234 bool HasMatrix() const { return bool(xMatrix); }
235 bool HasVarRes() const { return xVarRes.is(); }
236 double GetValue() const { return fValue; }
237 const OUString& GetString() const { return aString; }
238 const ScMatrixRef& GetMatrix() const { return xMatrix;}
239 const css::uno::Reference<css::sheet::XVolatileResult>&
240 GetVarRes() const { return xVarRes; }
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */