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 SC_ADDINCOL_HXX
21 #define SC_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 <com/sun/star/sheet/LocalizedName.hpp>
31 #include <i18npool/lang.h>
32 #include <rtl/ustring.h>
34 #include <rtl/ustring.hxx>
36 #include "scmatrix.hxx"
38 #include <boost/unordered_map.hpp>
43 class ScUnoAddInFuncData
;
47 typedef ::boost::unordered_map
< ::rtl::OUString
, const ScUnoAddInFuncData
*, ScStringHashCode
, ::std::equal_to
< ::rtl::OUString
> > ScAddInHashMap
;
50 enum ScAddInArgumentType
52 SC_ADDINARG_NONE
, ///< -
53 SC_ADDINARG_INTEGER
, ///< long
54 SC_ADDINARG_DOUBLE
, ///< double
55 SC_ADDINARG_STRING
, ///< string
56 SC_ADDINARG_INTEGER_ARRAY
, ///< sequence<sequence<long>>
57 SC_ADDINARG_DOUBLE_ARRAY
, ///< sequence<sequence<double>>
58 SC_ADDINARG_STRING_ARRAY
, ///< sequence<sequence<string>>
59 SC_ADDINARG_MIXED_ARRAY
, ///< sequence<sequence<any>>
60 SC_ADDINARG_VALUE_OR_ARRAY
, ///< any
61 SC_ADDINARG_CELLRANGE
, ///< XCellRange
62 SC_ADDINARG_CALLER
, ///< XPropertySet
63 SC_ADDINARG_VARARGS
///< sequence<any>
66 //------------------------------------------------------------------------
70 ::rtl::OUString aInternalName
; ///< used to match configuration and reflection information
71 ::rtl::OUString aName
;
72 ::rtl::OUString aDescription
;
73 ScAddInArgumentType eType
;
77 class ScUnoAddInFuncData
80 ::rtl::OUString aOriginalName
; ///< kept in formula
81 ::rtl::OUString aLocalName
; ///< for display
82 ::rtl::OUString aUpperName
; ///< for entering formulas
83 ::rtl::OUString aUpperLocal
; ///< for entering formulas
84 ::rtl::OUString aDescription
;
85 com::sun::star::uno::Reference
< com::sun::star::reflection::XIdlMethod
> xFunction
;
86 com::sun::star::uno::Any aObject
;
88 ScAddInArgDesc
* pArgDescs
;
92 mutable com::sun::star::uno::Sequence
< com::sun::star::sheet::LocalizedName
> aCompNames
;
93 mutable sal_Bool bCompInitialized
;
96 ScUnoAddInFuncData( const ::rtl::OUString
& rNam
, const ::rtl::OUString
& rLoc
,
97 const ::rtl::OUString
& rDesc
,
98 sal_uInt16 nCat
, const rtl::OString
&,
99 const com::sun::star::uno::Reference
<
100 com::sun::star::reflection::XIdlMethod
>& rFunc
,
101 const com::sun::star::uno::Any
& rO
,
102 long nAC
, const ScAddInArgDesc
* pAD
,
104 ~ScUnoAddInFuncData();
106 const ::rtl::OUString
& GetOriginalName() const { return aOriginalName
; }
107 const ::rtl::OUString
& GetLocalName() const { return aLocalName
; }
108 const ::rtl::OUString
& GetUpperName() const { return aUpperName
; }
109 const ::rtl::OUString
& GetUpperLocal() const { return aUpperLocal
; }
110 const com::sun::star::uno::Reference
< com::sun::star::reflection::XIdlMethod
>& GetFunction() const
111 { return xFunction
; }
112 const com::sun::star::uno::Any
& GetObject() const { return aObject
; }
113 long GetArgumentCount() const { return nArgCount
; }
114 const ScAddInArgDesc
* GetArguments() const { return pArgDescs
; }
115 long GetCallerPos() const { return nCallerPos
; }
116 const ::rtl::OUString
& GetDescription() const { return aDescription
; }
117 sal_uInt16
GetCategory() const { return nCategory
; }
118 const rtl::OString
GetHelpId() const { return sHelpId
; }
120 const com::sun::star::uno::Sequence
< com::sun::star::sheet::LocalizedName
>& GetCompNames() const;
121 sal_Bool
GetExcelName( LanguageType eDestLang
, ::rtl::OUString
& rRetExcelName
) const;
123 void SetFunction( const com::sun::star::uno::Reference
< com::sun::star::reflection::XIdlMethod
>& rNewFunc
,
124 const com::sun::star::uno::Any
& rNewObj
);
125 void SetArguments( long nNewCount
, const ScAddInArgDesc
* pNewDescs
);
126 void SetCallerPos( long nNewPos
);
127 void SetCompNames( const com::sun::star::uno::Sequence
< com::sun::star::sheet::LocalizedName
>& rNew
);
130 //------------------------------------------------------------------------
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
140 sal_Bool bInitialized
;
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 ::rtl::OUString
& rServiceName
);
149 void LoadComponent( const ScUnoAddInFuncData
& rFuncData
);
152 ScUnoAddInCollection();
153 ~ScUnoAddInCollection();
155 /// User enetered name. rUpperName MUST already be upper case!
156 ::rtl::OUString
FindFunction( const ::rtl::OUString
& rUpperName
, sal_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 ::rtl::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( ::rtl::OUString
& rName
); ///< modify rName - input: exact name
174 sal_Bool
FillFunctionDesc( long nFunc
, ScFuncDesc
& rDesc
);
176 static sal_Bool
FillFunctionDescFromData( const ScUnoAddInFuncData
& rFuncData
, ScFuncDesc
& rDesc
);
177 /// leave rRetExcelName unchanged, if no matching name is found
178 sal_Bool
GetExcelName( const ::rtl::OUString
& rCalcName
, LanguageType eDestLang
, ::rtl::OUString
& rRetExcelName
);
179 /// leave rRetCalcName unchanged, if no matching name is found
180 sal_Bool
GetCalcName( const ::rtl::OUString
& rExcelName
, ::rtl::OUString
& rRetCalcName
);
187 const ScUnoAddInFuncData
* pFuncData
;
188 com::sun::star::uno::Sequence
<com::sun::star::uno::Any
> aArgs
;
189 com::sun::star::uno::Sequence
<com::sun::star::uno::Any
> aVarArg
;
190 com::sun::star::uno::Reference
<com::sun::star::uno::XInterface
> xCaller
;
191 sal_Bool bValidCount
;
196 ::rtl::OUString aString
;
198 com::sun::star::uno::Reference
<com::sun::star::sheet::XVolatileResult
> xVarRes
;
200 void ExecuteCallWithArgs(
201 com::sun::star::uno::Sequence
<com::sun::star::uno::Any
>& rCallArgs
);
205 ScUnoAddInCall( ScUnoAddInCollection
& rColl
, const ::rtl::OUString
& rName
,
209 sal_Bool
NeedsCaller() const;
210 void SetCaller( const com::sun::star::uno::Reference
<
211 com::sun::star::uno::XInterface
>& rInterface
);
212 void SetCallerFromObjectShell( SfxObjectShell
* pSh
);
214 sal_Bool
ValidParamCount();
215 ScAddInArgumentType
GetArgType( long nPos
);
216 void SetParam( long nPos
, const com::sun::star::uno::Any
& rValue
);
220 void SetResult( const com::sun::star::uno::Any
& rNewRes
);
222 sal_uInt16
GetErrCode() const { return nErrCode
; }
223 sal_Bool
HasString() const { return bHasString
; }
224 bool HasMatrix() const { return xMatrix
.get(); }
225 sal_Bool
HasVarRes() const { return ( xVarRes
.is() ); }
226 double GetValue() const { return fValue
; }
227 const ::rtl::OUString
& GetString() const { return aString
; }
228 ScMatrixRef
GetMatrix() const { return xMatrix
; }
229 com::sun::star::uno::Reference
<com::sun::star::sheet::XVolatileResult
>
230 GetVarRes() const { return xVarRes
; }
236 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */