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
25 #include <com/sun/star/sheet/XVolatileResult.hpp>
26 #include <com/sun/star/sheet/XAddIn.hpp>
27 #include <com/sun/star/sheet/XResultListener.hpp>
28 #include <com/sun/star/sheet/ResultEvent.hpp>
29 #include <com/sun/star/container/XNameAccess.hpp>
30 #include <com/sun/star/reflection/XIdlMethod.hpp>
31 #include <i18nlangtag/lang.h>
32 #include <rtl/ustring.h>
34 #include <rtl/ustring.hxx>
35 #include "scmatrix.hxx"
39 #include <unordered_map>
42 class ScUnoAddInFuncData
;
45 typedef std::unordered_map
< OUString
, const ScUnoAddInFuncData
* > ScAddInHashMap
;
47 enum ScAddInArgumentType
49 SC_ADDINARG_NONE
, ///< -
50 SC_ADDINARG_INTEGER
, ///< long
51 SC_ADDINARG_DOUBLE
, ///< double
52 SC_ADDINARG_STRING
, ///< string
53 SC_ADDINARG_INTEGER_ARRAY
, ///< sequence<sequence<long>>
54 SC_ADDINARG_DOUBLE_ARRAY
, ///< sequence<sequence<double>>
55 SC_ADDINARG_STRING_ARRAY
, ///< sequence<sequence<string>>
56 SC_ADDINARG_MIXED_ARRAY
, ///< sequence<sequence<any>>
57 SC_ADDINARG_VALUE_OR_ARRAY
, ///< any
58 SC_ADDINARG_CELLRANGE
, ///< XCellRange
59 SC_ADDINARG_CALLER
, ///< XPropertySet
60 SC_ADDINARG_VARARGS
///< sequence<any>
65 OUString aInternalName
; ///< used to match configuration and reflection information
67 OUString aDescription
;
68 ScAddInArgumentType eType
;
72 class ScUnoAddInFuncData
80 LocalizedName( const OUString
& rLocale
, const OUString
& rName
)
81 : maLocale( rLocale
), maName( rName
) { }
84 OUString aOriginalName
; ///< kept in formula
85 OUString aLocalName
; ///< for display
86 OUString aUpperName
; ///< for entering formulas
87 OUString aUpperLocal
; ///< for entering formulas
88 OUString aDescription
;
89 css::uno::Reference
< css::reflection::XIdlMethod
> xFunction
;
90 css::uno::Any aObject
;
92 std::unique_ptr
<ScAddInArgDesc
[]>
97 mutable ::std::vector
< LocalizedName
> maCompNames
;
98 mutable bool bCompInitialized
;
101 ScUnoAddInFuncData( const OUString
& rNam
, const OUString
& rLoc
,
102 const OUString
& rDesc
,
103 sal_uInt16 nCat
, const OString
&,
104 const css::uno::Reference
< css::reflection::XIdlMethod
>& rFunc
,
105 const css::uno::Any
& rO
,
106 long nAC
, const ScAddInArgDesc
* pAD
,
108 ~ScUnoAddInFuncData();
110 const OUString
& GetOriginalName() const { return aOriginalName
; }
111 const OUString
& GetLocalName() const { return aLocalName
; }
112 const OUString
& GetUpperName() const { return aUpperName
; }
113 const OUString
& GetUpperLocal() const { return aUpperLocal
; }
114 const css::uno::Reference
< css::reflection::XIdlMethod
>& GetFunction() const
115 { return xFunction
; }
116 const css::uno::Any
& GetObject() const { return aObject
; }
117 long GetArgumentCount() const { return nArgCount
; }
118 const ScAddInArgDesc
* GetArguments() const { return pArgDescs
.get(); }
119 long GetCallerPos() const { return nCallerPos
; }
120 const OUString
& GetDescription() const { return aDescription
; }
121 sal_uInt16
GetCategory() const { return nCategory
; }
122 const OString
& GetHelpId() const { return sHelpId
; }
124 const ::std::vector
< LocalizedName
>& GetCompNames() const;
125 bool GetExcelName( LanguageType eDestLang
, OUString
& rRetExcelName
) const;
127 void SetFunction( const css::uno::Reference
< css::reflection::XIdlMethod
>& rNewFunc
,
128 const css::uno::Any
& rNewObj
);
129 void SetArguments( long nNewCount
, const ScAddInArgDesc
* pNewDescs
);
130 void SetCallerPos( long nNewPos
);
131 void SetCompNames( const ::std::vector
< LocalizedName
>& rNew
);
134 class SC_DLLPUBLIC ScUnoAddInCollection
138 ScUnoAddInFuncData
** ppFuncData
;
139 ScAddInHashMap
* pExactHashMap
; ///< exact internal name
140 ScAddInHashMap
* pNameHashMap
; ///< internal name upper
141 ScAddInHashMap
* pLocalHashMap
; ///< localized name upper
145 void ReadConfiguration();
146 void ReadFromAddIn( const css::uno::Reference
< css::uno::XInterface
>& xInterface
);
147 void UpdateFromAddIn( const css::uno::Reference
< css::uno::XInterface
>& xInterface
,
148 const OUString
& rServiceName
);
149 void LoadComponent( const ScUnoAddInFuncData
& rFuncData
);
152 ScUnoAddInCollection();
153 ~ScUnoAddInCollection();
155 /// User entered name. rUpperName MUST already be upper case!
156 const OUString
& FindFunction( const OUString
& rUpperName
, bool bLocalFirst
);
158 /** Only if bComplete is set, the function reference and argument types
159 are initialized (component may have to be loaded).
160 @param rName is the exact Name. */
161 const ScUnoAddInFuncData
* GetFuncData( const OUString
& rName
, bool bComplete
= false );
163 /** For enumeration in ScCompiler::OpCodeMap::getAvailableMappings().
165 0 <= nIndex < GetFuncCount()
167 const ScUnoAddInFuncData
* GetFuncData( long nIndex
);
171 void LocalizeString( OUString
& rName
); ///< modify rName - input: exact name
174 bool FillFunctionDesc( long nFunc
, ScFuncDesc
& rDesc
);
176 static bool FillFunctionDescFromData( const ScUnoAddInFuncData
& rFuncData
, ScFuncDesc
& rDesc
);
177 /// leave rRetExcelName unchanged, if no matching name is found
178 bool GetExcelName( const OUString
& rCalcName
, LanguageType eDestLang
, OUString
& rRetExcelName
);
179 /// leave rRetCalcName unchanged, if no matching name is found
180 bool GetCalcName( const OUString
& rExcelName
, OUString
& rRetCalcName
);
186 const ScUnoAddInFuncData
* pFuncData
;
187 css::uno::Sequence
<css::uno::Any
> aArgs
;
188 css::uno::Sequence
<css::uno::Any
> aVarArg
;
189 css::uno::Reference
<css::uno::XInterface
> xCaller
;
192 FormulaError nErrCode
;
197 css::uno::Reference
<css::sheet::XVolatileResult
> xVarRes
;
199 void ExecuteCallWithArgs(css::uno::Sequence
<css::uno::Any
>& rCallArgs
);
203 ScUnoAddInCall( ScUnoAddInCollection
& rColl
, const OUString
& rName
,
207 bool NeedsCaller() const;
208 void SetCaller( const css::uno::Reference
<css::uno::XInterface
>& rInterface
);
209 void SetCallerFromObjectShell( const SfxObjectShell
* pSh
);
211 bool ValidParamCount() { return bValidCount
;}
212 ScAddInArgumentType
GetArgType( long nPos
);
213 void SetParam( long nPos
, const css::uno::Any
& rValue
);
217 void SetResult( const css::uno::Any
& rNewRes
);
219 FormulaError
GetErrCode() const { return nErrCode
; }
220 bool HasString() const { return bHasString
; }
221 bool HasMatrix() const { return xMatrix
.get(); }
222 bool HasVarRes() const { return xVarRes
.is(); }
223 double GetValue() const { return fValue
; }
224 const OUString
& GetString() const { return aString
; }
225 const ScMatrixRef
& GetMatrix() const { return xMatrix
;}
226 const css::uno::Reference
<css::sheet::XVolatileResult
>&
227 GetVarRes() const { return xVarRes
; }
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */