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/sheet/XVolatileResult.hpp>
25 #include <com/sun/star/sheet/XAddIn.hpp>
26 #include <com/sun/star/sheet/XResultListener.hpp>
27 #include <com/sun/star/sheet/ResultEvent.hpp>
28 #include <com/sun/star/container/XNameAccess.hpp>
29 #include <com/sun/star/reflection/XIdlMethod.hpp>
30 #include <i18nlangtag/lang.h>
31 #include <rtl/ustring.h>
33 #include <rtl/ustring.hxx>
37 #include <boost/unordered_map.hpp>
40 class ScUnoAddInFuncData
;
43 typedef ::boost::unordered_map
< OUString
, const ScUnoAddInFuncData
*, OUStringHash
> ScAddInHashMap
;
45 enum ScAddInArgumentType
47 SC_ADDINARG_NONE
, ///< -
48 SC_ADDINARG_INTEGER
, ///< long
49 SC_ADDINARG_DOUBLE
, ///< double
50 SC_ADDINARG_STRING
, ///< string
51 SC_ADDINARG_INTEGER_ARRAY
, ///< sequence<sequence<long>>
52 SC_ADDINARG_DOUBLE_ARRAY
, ///< sequence<sequence<double>>
53 SC_ADDINARG_STRING_ARRAY
, ///< sequence<sequence<string>>
54 SC_ADDINARG_MIXED_ARRAY
, ///< sequence<sequence<any>>
55 SC_ADDINARG_VALUE_OR_ARRAY
, ///< any
56 SC_ADDINARG_CELLRANGE
, ///< XCellRange
57 SC_ADDINARG_CALLER
, ///< XPropertySet
58 SC_ADDINARG_VARARGS
///< sequence<any>
63 OUString aInternalName
; ///< used to match configuration and reflection information
65 OUString aDescription
;
66 ScAddInArgumentType eType
;
70 class ScUnoAddInFuncData
78 LocalizedName( const OUString
& rLocale
, const OUString
& rName
)
79 : maLocale( rLocale
), maName( rName
) { }
82 OUString aOriginalName
; ///< kept in formula
83 OUString aLocalName
; ///< for display
84 OUString aUpperName
; ///< for entering formulas
85 OUString aUpperLocal
; ///< for entering formulas
86 OUString aDescription
;
87 com::sun::star::uno::Reference
< com::sun::star::reflection::XIdlMethod
> xFunction
;
88 com::sun::star::uno::Any aObject
;
90 ScAddInArgDesc
* pArgDescs
;
94 mutable ::std::vector
< LocalizedName
> maCompNames
;
95 mutable bool bCompInitialized
;
98 ScUnoAddInFuncData( const OUString
& rNam
, const OUString
& rLoc
,
99 const OUString
& rDesc
,
100 sal_uInt16 nCat
, const OString
&,
101 const com::sun::star::uno::Reference
<
102 com::sun::star::reflection::XIdlMethod
>& rFunc
,
103 const com::sun::star::uno::Any
& rO
,
104 long nAC
, const ScAddInArgDesc
* pAD
,
106 ~ScUnoAddInFuncData();
108 const OUString
& GetOriginalName() const { return aOriginalName
; }
109 const OUString
& GetLocalName() const { return aLocalName
; }
110 const OUString
& GetUpperName() const { return aUpperName
; }
111 const OUString
& GetUpperLocal() const { return aUpperLocal
; }
112 const com::sun::star::uno::Reference
< com::sun::star::reflection::XIdlMethod
>& GetFunction() const
113 { return xFunction
; }
114 const com::sun::star::uno::Any
& GetObject() const { return aObject
; }
115 long GetArgumentCount() const { return nArgCount
; }
116 const ScAddInArgDesc
* GetArguments() const { return pArgDescs
; }
117 long GetCallerPos() const { return nCallerPos
; }
118 const OUString
& GetDescription() const { return aDescription
; }
119 sal_uInt16
GetCategory() const { return nCategory
; }
120 const OString
GetHelpId() const { return sHelpId
; }
122 const ::std::vector
< LocalizedName
>& GetCompNames() const;
123 bool GetExcelName( LanguageType eDestLang
, OUString
& rRetExcelName
) const;
125 void SetFunction( const com::sun::star::uno::Reference
< com::sun::star::reflection::XIdlMethod
>& rNewFunc
,
126 const com::sun::star::uno::Any
& rNewObj
);
127 void SetArguments( long nNewCount
, const ScAddInArgDesc
* pNewDescs
);
128 void SetCallerPos( long nNewPos
);
129 void SetCompNames( const ::std::vector
< LocalizedName
>& rNew
);
132 class SC_DLLPUBLIC ScUnoAddInCollection
136 ScUnoAddInFuncData
** ppFuncData
;
137 ScAddInHashMap
* pExactHashMap
; ///< exact internal name
138 ScAddInHashMap
* pNameHashMap
; ///< internal name upper
139 ScAddInHashMap
* pLocalHashMap
; ///< localized name upper
143 void ReadConfiguration();
144 void ReadFromAddIn( const com::sun::star::uno::Reference
<
145 com::sun::star::uno::XInterface
>& xInterface
);
146 void UpdateFromAddIn( const com::sun::star::uno::Reference
<
147 com::sun::star::uno::XInterface
>& xInterface
,
148 const OUString
& rServiceName
);
149 void LoadComponent( const ScUnoAddInFuncData
& rFuncData
);
152 ScUnoAddInCollection();
153 ~ScUnoAddInCollection();
155 /// User enetered name. rUpperName MUST already be upper case!
156 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 com::sun::star::uno::Sequence
<com::sun::star::uno::Any
> aArgs
;
188 com::sun::star::uno::Sequence
<com::sun::star::uno::Any
> aVarArg
;
189 com::sun::star::uno::Reference
<com::sun::star::uno::XInterface
> xCaller
;
197 com::sun::star::uno::Reference
<com::sun::star::sheet::XVolatileResult
> xVarRes
;
199 void ExecuteCallWithArgs(
200 com::sun::star::uno::Sequence
<com::sun::star::uno::Any
>& rCallArgs
);
204 ScUnoAddInCall( ScUnoAddInCollection
& rColl
, const OUString
& rName
,
208 bool NeedsCaller() const;
209 void SetCaller( const com::sun::star::uno::Reference
<
210 com::sun::star::uno::XInterface
>& rInterface
);
211 void SetCallerFromObjectShell( SfxObjectShell
* pSh
);
213 bool ValidParamCount();
214 ScAddInArgumentType
GetArgType( long nPos
);
215 void SetParam( long nPos
, const com::sun::star::uno::Any
& rValue
);
219 void SetResult( const com::sun::star::uno::Any
& rNewRes
);
221 sal_uInt16
GetErrCode() const { return nErrCode
; }
222 bool HasString() const { return bHasString
; }
223 bool HasMatrix() const { return xMatrix
.get(); }
224 bool HasVarRes() const { return ( xVarRes
.is() ); }
225 double GetValue() const { return fValue
; }
226 const OUString
& GetString() const { return aString
; }
227 ScMatrixRef
GetMatrix() const;
228 com::sun::star::uno::Reference
<com::sun::star::sheet::XVolatileResult
>
229 GetVarRes() const { return xVarRes
; }
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */