Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef SC_ADDINCOL_HXX
21 : #define SC_ADDINCOL_HXX
22 :
23 : #include "global.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>
33 : #include "scdllapi.h"
34 : #include <rtl/ustring.hxx>
35 :
36 : #include "scmatrix.hxx"
37 :
38 : #include <boost/unordered_map.hpp>
39 :
40 :
41 : class String;
42 : class SfxObjectShell;
43 : class ScUnoAddInFuncData;
44 : class ScFuncDesc;
45 :
46 :
47 : typedef ::boost::unordered_map< ::rtl::OUString, const ScUnoAddInFuncData*, ScStringHashCode, ::std::equal_to< ::rtl::OUString > > ScAddInHashMap;
48 :
49 :
50 : enum ScAddInArgumentType
51 : {
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>
64 : };
65 :
66 : //------------------------------------------------------------------------
67 :
68 5229 : struct ScAddInArgDesc
69 : {
70 : ::rtl::OUString aInternalName; ///< used to match configuration and reflection information
71 : ::rtl::OUString aName;
72 : ::rtl::OUString aDescription;
73 : ScAddInArgumentType eType;
74 : sal_Bool bOptional;
75 : };
76 :
77 : class ScUnoAddInFuncData
78 : {
79 : private:
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;
87 : long nArgCount;
88 : ScAddInArgDesc* pArgDescs;
89 : long nCallerPos;
90 : sal_uInt16 nCategory;
91 : rtl::OString sHelpId;
92 : mutable com::sun::star::uno::Sequence< com::sun::star::sheet::LocalizedName> aCompNames;
93 : mutable sal_Bool bCompInitialized;
94 :
95 : public:
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,
103 : long nCP );
104 : ~ScUnoAddInFuncData();
105 :
106 763 : const ::rtl::OUString& GetOriginalName() const { return aOriginalName; }
107 0 : const ::rtl::OUString& GetLocalName() const { return aLocalName; }
108 654 : const ::rtl::OUString& GetUpperName() const { return aUpperName; }
109 327 : const ::rtl::OUString& GetUpperLocal() const { return aUpperLocal; }
110 0 : const com::sun::star::uno::Reference< com::sun::star::reflection::XIdlMethod>& GetFunction() const
111 0 : { return xFunction; }
112 0 : const com::sun::star::uno::Any& GetObject() const { return aObject; }
113 0 : long GetArgumentCount() const { return nArgCount; }
114 0 : const ScAddInArgDesc* GetArguments() const { return pArgDescs; }
115 0 : long GetCallerPos() const { return nCallerPos; }
116 0 : const ::rtl::OUString& GetDescription() const { return aDescription; }
117 0 : sal_uInt16 GetCategory() const { return nCategory; }
118 0 : const rtl::OString GetHelpId() const { return sHelpId; }
119 :
120 : const com::sun::star::uno::Sequence< com::sun::star::sheet::LocalizedName>& GetCompNames() const;
121 : sal_Bool GetExcelName( LanguageType eDestLang, ::rtl::OUString& rRetExcelName ) const;
122 :
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 );
128 : };
129 :
130 : //------------------------------------------------------------------------
131 :
132 : class SC_DLLPUBLIC ScUnoAddInCollection
133 : {
134 : private:
135 : long nFuncCount;
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;
141 :
142 : void Initialize();
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 );
150 :
151 : public:
152 : ScUnoAddInCollection();
153 : ~ScUnoAddInCollection();
154 :
155 : /// User enetered name. rUpperName MUST already be upper case!
156 : ::rtl::OUString FindFunction( const ::rtl::OUString& rUpperName, sal_Bool bLocalFirst );
157 :
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 );
162 :
163 : /** For enumeration in ScCompiler::OpCodeMap::getAvailableMappings().
164 : @param nIndex
165 : 0 <= nIndex < GetFuncCount()
166 : */
167 : const ScUnoAddInFuncData* GetFuncData( long nIndex );
168 :
169 : void Clear();
170 :
171 : void LocalizeString( ::rtl::OUString& rName ); ///< modify rName - input: exact name
172 :
173 : long GetFuncCount();
174 : sal_Bool FillFunctionDesc( long nFunc, ScFuncDesc& rDesc );
175 :
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 );
181 : };
182 :
183 :
184 : class ScUnoAddInCall
185 : {
186 : private:
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;
192 : // result:
193 : sal_uInt16 nErrCode;
194 : sal_Bool bHasString;
195 : double fValue;
196 : ::rtl::OUString aString;
197 : ScMatrixRef xMatrix;
198 : com::sun::star::uno::Reference<com::sun::star::sheet::XVolatileResult> xVarRes;
199 :
200 : void ExecuteCallWithArgs(
201 : com::sun::star::uno::Sequence<com::sun::star::uno::Any>& rCallArgs);
202 :
203 : public:
204 : // exact name
205 : ScUnoAddInCall( ScUnoAddInCollection& rColl, const ::rtl::OUString& rName,
206 : long nParamCount );
207 : ~ScUnoAddInCall();
208 :
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 );
213 :
214 : sal_Bool ValidParamCount();
215 : ScAddInArgumentType GetArgType( long nPos );
216 : void SetParam( long nPos, const com::sun::star::uno::Any& rValue );
217 :
218 : void ExecuteCall();
219 :
220 : void SetResult( const com::sun::star::uno::Any& rNewRes );
221 :
222 0 : sal_uInt16 GetErrCode() const { return nErrCode; }
223 0 : sal_Bool HasString() const { return bHasString; }
224 0 : bool HasMatrix() const { return xMatrix.get(); }
225 0 : sal_Bool HasVarRes() const { return ( xVarRes.is() ); }
226 0 : double GetValue() const { return fValue; }
227 0 : const ::rtl::OUString& GetString() const { return aString; }
228 0 : ScMatrixRef GetMatrix() const { return xMatrix; }
229 : com::sun::star::uno::Reference<com::sun::star::sheet::XVolatileResult>
230 0 : GetVarRes() const { return xVarRes; }
231 : };
232 :
233 :
234 : #endif
235 :
236 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|