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 .
20 #ifndef INCLUDED_SC_INC_ADDINCOL_HXX
21 #define INCLUDED_SC_INC_ADDINCOL_HXX
24 #include <com/sun/star/uno/Any.h>
25 #include <com/sun/star/uno/Reference.h>
26 #include <com/sun/star/uno/Sequence.h>
27 #include <formula/errorcodes.hxx>
28 #include <i18nlangtag/lang.h>
30 #include <rtl/ustring.hxx>
31 #include <tools/long.hxx>
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
;
46 typedef std::unordered_map
< OUString
, const ScUnoAddInFuncData
* > ScAddInHashMap
;
48 enum ScAddInArgumentType
50 SC_ADDINARG_NONE
, ///< -
51 SC_ADDINARG_INTEGER
, ///< long
52 SC_ADDINARG_DOUBLE
, ///< double
53 SC_ADDINARG_STRING
, ///< string
54 SC_ADDINARG_INTEGER_ARRAY
, ///< sequence<sequence<long>>
55 SC_ADDINARG_DOUBLE_ARRAY
, ///< sequence<sequence<double>>
56 SC_ADDINARG_STRING_ARRAY
, ///< sequence<sequence<string>>
57 SC_ADDINARG_MIXED_ARRAY
, ///< sequence<sequence<any>>
58 SC_ADDINARG_VALUE_OR_ARRAY
, ///< any
59 SC_ADDINARG_CELLRANGE
, ///< XCellRange
60 SC_ADDINARG_CALLER
, ///< XPropertySet
61 SC_ADDINARG_VARARGS
///< sequence<any>
66 OUString aInternalName
; ///< used to match configuration and reflection information
68 OUString aDescription
;
69 ScAddInArgumentType eType
;
73 class ScUnoAddInFuncData
81 LocalizedName( const OUString
& rLocale
, const OUString
& rName
)
82 : maLocale( rLocale
), maName( rName
) { }
85 OUString aOriginalName
; ///< kept in formula
86 OUString aLocalName
; ///< for display
87 OUString aUpperName
; ///< for entering formulas
88 OUString aUpperLocal
; ///< for entering formulas
89 OUString aDescription
;
90 css::uno::Reference
< css::reflection::XIdlMethod
> xFunction
;
91 css::uno::Any aObject
;
92 tools::Long nArgCount
;
93 std::unique_ptr
<ScAddInArgDesc
[]>
95 tools::Long nCallerPos
;
98 mutable ::std::vector
< LocalizedName
> maCompNames
;
99 mutable bool bCompInitialized
;
102 ScUnoAddInFuncData( const OUString
& rNam
, const OUString
& rLoc
,
103 const OUString
& rDesc
,
104 sal_uInt16 nCat
, const OString
&,
105 const css::uno::Reference
< css::reflection::XIdlMethod
>& rFunc
,
106 const css::uno::Any
& rO
,
107 tools::Long nAC
, const ScAddInArgDesc
* pAD
,
109 ~ScUnoAddInFuncData();
111 const OUString
& GetOriginalName() const { return aOriginalName
; }
112 const OUString
& GetLocalName() const { return aLocalName
; }
113 const OUString
& GetUpperName() const { return aUpperName
; }
114 const OUString
& GetUpperLocal() const { return aUpperLocal
; }
115 const css::uno::Reference
< css::reflection::XIdlMethod
>& GetFunction() const
116 { return xFunction
; }
117 const css::uno::Any
& GetObject() const { return aObject
; }
118 tools::Long
GetArgumentCount() const { return nArgCount
; }
119 const ScAddInArgDesc
* GetArguments() const { return pArgDescs
.get(); }
120 tools::Long
GetCallerPos() const { return nCallerPos
; }
121 const OUString
& GetDescription() const { return aDescription
; }
122 sal_uInt16
GetCategory() const { return nCategory
; }
123 const OString
& GetHelpId() const { return sHelpId
; }
125 const ::std::vector
< LocalizedName
>& GetCompNames() const;
126 bool GetExcelName( LanguageType eDestLang
, OUString
& rRetExcelName
) const;
128 void SetFunction( const css::uno::Reference
< css::reflection::XIdlMethod
>& rNewFunc
,
129 const css::uno::Any
& rNewObj
);
130 void SetArguments( tools::Long nNewCount
, const ScAddInArgDesc
* pNewDescs
);
131 void SetCallerPos( tools::Long nNewPos
);
132 void SetCompNames( const ::std::vector
< LocalizedName
>& rNew
);
135 class SC_DLLPUBLIC ScUnoAddInCollection
138 tools::Long nFuncCount
;
139 std::unique_ptr
<std::unique_ptr
<ScUnoAddInFuncData
>[]> ppFuncData
;
140 std::unique_ptr
<ScAddInHashMap
> pExactHashMap
; ///< exact internal name
141 std::unique_ptr
<ScAddInHashMap
> pNameHashMap
; ///< internal name upper
142 std::unique_ptr
<ScAddInHashMap
> pLocalHashMap
; ///< localized name upper
146 void ReadConfiguration();
147 void ReadFromAddIn( const css::uno::Reference
< css::uno::XInterface
>& xInterface
);
148 void UpdateFromAddIn( const css::uno::Reference
< css::uno::XInterface
>& xInterface
,
149 const OUString
& rServiceName
);
150 void LoadComponent( const ScUnoAddInFuncData
& rFuncData
);
153 ScUnoAddInCollection();
154 ~ScUnoAddInCollection();
156 /// User entered name. rUpperName MUST already be upper case!
157 const OUString
& FindFunction( const OUString
& rUpperName
, bool bLocalFirst
);
159 /** Only if bComplete is set, the function reference and argument types
160 are initialized (component may have to be loaded).
161 @param rName is the exact Name. */
162 const ScUnoAddInFuncData
* GetFuncData( const OUString
& rName
, bool bComplete
= false );
164 /** For enumeration in ScCompiler::OpCodeMap::getAvailableMappings().
166 0 <= nIndex < GetFuncCount()
168 const ScUnoAddInFuncData
* GetFuncData( tools::Long nIndex
);
172 void LocalizeString( OUString
& rName
); ///< modify rName - input: exact name
174 tools::Long
GetFuncCount();
175 bool FillFunctionDesc( tools::Long nFunc
, ScFuncDesc
& rDesc
);
177 static bool FillFunctionDescFromData( const ScUnoAddInFuncData
& rFuncData
, ScFuncDesc
& rDesc
);
178 /// leave rRetExcelName unchanged, if no matching name is found
179 bool GetExcelName( const OUString
& rCalcName
, LanguageType eDestLang
, OUString
& rRetExcelName
);
180 /// leave rRetCalcName unchanged, if no matching name is found
181 bool GetCalcName( const OUString
& rExcelName
, OUString
& rRetCalcName
);
187 const ScUnoAddInFuncData
* pFuncData
;
188 css::uno::Sequence
<css::uno::Any
> aArgs
;
189 css::uno::Sequence
<css::uno::Any
> aVarArg
;
190 css::uno::Reference
<css::uno::XInterface
> xCaller
;
193 FormulaError nErrCode
;
198 css::uno::Reference
<css::sheet::XVolatileResult
> xVarRes
;
200 void ExecuteCallWithArgs(css::uno::Sequence
<css::uno::Any
>& rCallArgs
);
204 ScUnoAddInCall( ScUnoAddInCollection
& rColl
, const OUString
& rName
,
205 tools::Long nParamCount
);
208 bool NeedsCaller() const;
209 void SetCaller( const css::uno::Reference
<css::uno::XInterface
>& rInterface
);
210 void SetCallerFromObjectShell( const SfxObjectShell
* pSh
);
212 bool ValidParamCount() { return bValidCount
;}
213 ScAddInArgumentType
GetArgType( tools::Long nPos
);
214 void SetParam( tools::Long nPos
, const css::uno::Any
& rValue
);
218 void SetResult( const css::uno::Any
& rNewRes
);
220 FormulaError
GetErrCode() const { return nErrCode
; }
221 bool HasString() const { return bHasString
; }
222 bool HasMatrix() const { return bool(xMatrix
); }
223 bool HasVarRes() const { return xVarRes
.is(); }
224 double GetValue() const { return fValue
; }
225 const OUString
& GetString() const { return aString
; }
226 const ScMatrixRef
& GetMatrix() const { return xMatrix
;}
227 const css::uno::Reference
<css::sheet::XVolatileResult
>&
228 GetVarRes() const { return xVarRes
; }
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */