1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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>
29 #include <rtl/ustring.hxx>
30 #include <tools/long.hxx>
34 #include <string_view>
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
; }
44 class ScUnoAddInFuncData
;
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>
69 OUString aInternalName
; ///< used to match configuration and reflection information
71 OUString aDescription
;
72 ScAddInArgumentType eType
;
76 class ScUnoAddInFuncData
84 LocalizedName( OUString aLocale
, OUString aName
)
85 : maLocale(std::move(aLocale
)), maName(std::move(aName
)) { }
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 tools::Long nArgCount
;
97 std::unique_ptr
<ScAddInArgDesc
[]>
99 tools::Long nCallerPos
;
100 sal_uInt16 nCategory
;
102 mutable ::std::vector
< LocalizedName
> maCompNames
;
103 mutable bool bCompInitialized
;
106 ScUnoAddInFuncData( const OUString
& rNam
, const OUString
& rLoc
,
108 sal_uInt16 nCat
, OString
,
109 css::uno::Reference
< css::reflection::XIdlMethod
> aFunc
,
111 tools::Long nAC
, const ScAddInArgDesc
* pAD
,
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 tools::Long
GetArgumentCount() const { return nArgCount
; }
124 const ScAddInArgDesc
* GetArguments() const { return pArgDescs
.get(); }
125 tools::Long
GetCallerPos() const { return nCallerPos
; }
126 const OUString
& GetDescription() const { return aDescription
; }
127 sal_uInt16
GetCategory() const { return nCategory
; }
128 const OString
& 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( tools::Long nNewCount
, const ScAddInArgDesc
* pNewDescs
);
137 void SetCallerPos( tools::Long 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 SC_DLLPUBLIC ScUnoAddInCollection
147 tools::Long 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
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
);
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().
176 0 <= nIndex < GetFuncCount()
178 const ScUnoAddInFuncData
* GetFuncData( tools::Long nIndex
);
182 void LocalizeString( OUString
& rName
); ///< modify rName - input: exact name
184 tools::Long
GetFuncCount();
185 bool FillFunctionDesc( tools::Long 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 bool GetExcelName( const OUString
& rCalcName
, LanguageType eDestLang
, OUString
& rRetExcelName
);
191 /// leave rRetCalcName unchanged, if no matching name is found
192 bool GetCalcName( const OUString
& rExcelName
, OUString
& rRetCalcName
);
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
;
205 FormulaError nErrCode
;
210 css::uno::Reference
<css::sheet::XVolatileResult
> xVarRes
;
212 void ExecuteCallWithArgs(css::uno::Sequence
<css::uno::Any
>& rCallArgs
);
216 ScUnoAddInCall( ScDocument
& rDoc
, ScUnoAddInCollection
& rColl
, const OUString
& rName
,
217 tools::Long nParamCount
);
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( tools::Long nPos
);
226 void SetParam( tools::Long nPos
, const css::uno::Any
& rValue
);
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: */