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>
36 #include <unordered_map>
38 namespace com::sun::star::reflection
{ class XIdlMethod
; }
39 namespace com::sun::star::sheet
{ class XVolatileResult
; }
40 namespace com::sun::star::uno
{ class XInterface
; }
43 class ScUnoAddInFuncData
;
47 typedef std::unordered_map
< OUString
, const ScUnoAddInFuncData
* > 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>
67 OUString aInternalName
; ///< used to match configuration and reflection information
69 OUString aDescription
;
70 ScAddInArgumentType eType
;
74 class ScUnoAddInFuncData
82 LocalizedName( const OUString
& rLocale
, const OUString
& rName
)
83 : maLocale( rLocale
), maName( rName
) { }
86 OUString aOriginalName
; ///< kept in formula
87 OUString aLocalName
; ///< for display
88 OUString aUpperName
; ///< for entering formulas
89 OUString aUpperLocal
; ///< for entering formulas
90 OUString aDescription
;
91 css::uno::Reference
< css::reflection::XIdlMethod
> xFunction
;
92 css::uno::Any aObject
;
93 tools::Long nArgCount
;
94 std::unique_ptr
<ScAddInArgDesc
[]>
96 tools::Long nCallerPos
;
99 mutable ::std::vector
< LocalizedName
> maCompNames
;
100 mutable bool bCompInitialized
;
103 ScUnoAddInFuncData( const OUString
& rNam
, const OUString
& rLoc
,
104 const OUString
& rDesc
,
105 sal_uInt16 nCat
, const OString
&,
106 const css::uno::Reference
< css::reflection::XIdlMethod
>& rFunc
,
107 const css::uno::Any
& rO
,
108 tools::Long nAC
, const ScAddInArgDesc
* pAD
,
110 ~ScUnoAddInFuncData();
112 const OUString
& GetOriginalName() const { return aOriginalName
; }
113 const OUString
& GetLocalName() const { return aLocalName
; }
114 const OUString
& GetUpperName() const { return aUpperName
; }
115 const OUString
& GetUpperLocal() const { return aUpperLocal
; }
116 const css::uno::Reference
< css::reflection::XIdlMethod
>& GetFunction() const
117 { return xFunction
; }
118 const css::uno::Any
& GetObject() const { return aObject
; }
119 tools::Long
GetArgumentCount() const { return nArgCount
; }
120 const ScAddInArgDesc
* GetArguments() const { return pArgDescs
.get(); }
121 tools::Long
GetCallerPos() const { return nCallerPos
; }
122 const OUString
& GetDescription() const { return aDescription
; }
123 sal_uInt16
GetCategory() const { return nCategory
; }
124 const OString
& GetHelpId() const { return sHelpId
; }
126 const ::std::vector
< LocalizedName
>& GetCompNames() const;
127 bool GetExcelName( LanguageType eDestLang
, OUString
& rRetExcelName
) const;
129 void SetFunction( const css::uno::Reference
< css::reflection::XIdlMethod
>& rNewFunc
,
130 const css::uno::Any
& rNewObj
);
131 void SetArguments( tools::Long nNewCount
, const ScAddInArgDesc
* pNewDescs
);
132 void SetCallerPos( tools::Long nNewPos
);
133 void SetCompNames( ::std::vector
< LocalizedName
>&& rNew
);
136 class SC_DLLPUBLIC ScUnoAddInCollection
139 tools::Long nFuncCount
;
140 std::unique_ptr
<std::unique_ptr
<ScUnoAddInFuncData
>[]> ppFuncData
;
141 std::unique_ptr
<ScAddInHashMap
> pExactHashMap
; ///< exact internal name
142 std::unique_ptr
<ScAddInHashMap
> pNameHashMap
; ///< internal name upper
143 std::unique_ptr
<ScAddInHashMap
> pLocalHashMap
; ///< localized name upper
147 void ReadConfiguration();
148 void ReadFromAddIn( const css::uno::Reference
< css::uno::XInterface
>& xInterface
);
149 void UpdateFromAddIn( const css::uno::Reference
< css::uno::XInterface
>& xInterface
,
150 std::u16string_view rServiceName
);
151 void LoadComponent( const ScUnoAddInFuncData
& rFuncData
);
154 ScUnoAddInCollection();
155 ~ScUnoAddInCollection();
157 /// User entered name. rUpperName MUST already be upper case!
158 OUString
FindFunction( const OUString
& rUpperName
, bool bLocalFirst
);
160 /** Only if bComplete is set, the function reference and argument types
161 are initialized (component may have to be loaded).
162 @param rName is the exact Name. */
163 const ScUnoAddInFuncData
* GetFuncData( const OUString
& rName
, bool bComplete
= false );
165 /** For enumeration in ScCompiler::OpCodeMap::getAvailableMappings().
167 0 <= nIndex < GetFuncCount()
169 const ScUnoAddInFuncData
* GetFuncData( tools::Long nIndex
);
173 void LocalizeString( OUString
& rName
); ///< modify rName - input: exact name
175 tools::Long
GetFuncCount();
176 bool FillFunctionDesc( tools::Long nFunc
, ScFuncDesc
& rDesc
);
178 static bool FillFunctionDescFromData( const ScUnoAddInFuncData
& rFuncData
, ScFuncDesc
& rDesc
);
179 /// leave rRetExcelName unchanged, if no matching name is found
180 bool GetExcelName( const OUString
& rCalcName
, LanguageType eDestLang
, OUString
& rRetExcelName
);
181 /// leave rRetCalcName unchanged, if no matching name is found
182 bool GetCalcName( const OUString
& rExcelName
, OUString
& rRetCalcName
);
188 const ScUnoAddInFuncData
* pFuncData
;
189 css::uno::Sequence
<css::uno::Any
> aArgs
;
190 css::uno::Sequence
<css::uno::Any
> aVarArg
;
191 css::uno::Reference
<css::uno::XInterface
> xCaller
;
195 FormulaError nErrCode
;
200 css::uno::Reference
<css::sheet::XVolatileResult
> xVarRes
;
202 void ExecuteCallWithArgs(css::uno::Sequence
<css::uno::Any
>& rCallArgs
);
206 ScUnoAddInCall( ScDocument
& rDoc
, ScUnoAddInCollection
& rColl
, const OUString
& rName
,
207 tools::Long nParamCount
);
210 bool NeedsCaller() const;
211 void SetCaller( const css::uno::Reference
<css::uno::XInterface
>& rInterface
);
212 void SetCallerFromObjectShell( const SfxObjectShell
* pSh
);
214 bool ValidParamCount() { return bValidCount
;}
215 ScAddInArgumentType
GetArgType( tools::Long nPos
);
216 void SetParam( tools::Long nPos
, const css::uno::Any
& rValue
);
220 void SetResult( const css::uno::Any
& rNewRes
);
222 FormulaError
GetErrCode() const { return nErrCode
; }
223 bool HasString() const { return bHasString
; }
224 bool HasMatrix() const { return bool(xMatrix
); }
225 bool HasVarRes() const { return xVarRes
.is(); }
226 double GetValue() const { return fValue
; }
227 const OUString
& GetString() const { return aString
; }
228 const ScMatrixRef
& GetMatrix() const { return xMatrix
;}
229 const css::uno::Reference
<css::sheet::XVolatileResult
>&
230 GetVarRes() const { return xVarRes
; }
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */