update dev300-m57
[ooovba.git] / sc / inc / addincol.hxx
blob7fbfb616c9ee946d2c8a3bfbda5b35a8a1c40d6b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: addincol.hxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SC_ADDINCOL_HXX
32 #define SC_ADDINCOL_HXX
34 #include "global.hxx"
35 #include <com/sun/star/sheet/XVolatileResult.hpp>
36 #include <com/sun/star/sheet/XAddIn.hpp>
37 #include <com/sun/star/sheet/XResultListener.hpp>
38 #include <com/sun/star/sheet/ResultEvent.hpp>
39 #include <com/sun/star/container/XNameAccess.hpp>
40 #include <com/sun/star/reflection/XIdlMethod.hpp>
41 #include <com/sun/star/sheet/LocalizedName.hpp>
42 #include <tools/string.hxx>
43 #include <i18npool/lang.h>
44 #include <rtl/ustring.h>
45 #include "scdllapi.h"
47 #ifndef SC_SCMATRIX_HXX
48 #include "scmatrix.hxx"
49 #endif
51 #include <hash_map>
54 class String;
55 class SfxObjectShell;
56 class ScUnoAddInFuncData;
57 class ScMatrix;
58 class ScFuncDesc;
61 typedef ::std::hash_map< String, const ScUnoAddInFuncData*, ScStringHashCode, ::std::equal_to< String > > ScAddInHashMap;
64 enum ScAddInArgumentType
66 SC_ADDINARG_NONE, // -
67 SC_ADDINARG_INTEGER, // long
68 SC_ADDINARG_DOUBLE, // double
69 SC_ADDINARG_STRING, // string
70 SC_ADDINARG_INTEGER_ARRAY, // sequence<sequence<long>>
71 SC_ADDINARG_DOUBLE_ARRAY, // sequence<sequence<double>>
72 SC_ADDINARG_STRING_ARRAY, // sequence<sequence<string>>
73 SC_ADDINARG_MIXED_ARRAY, // sequence<sequence<any>>
74 SC_ADDINARG_VALUE_OR_ARRAY, // any
75 SC_ADDINARG_CELLRANGE, // XCellRange
76 SC_ADDINARG_CALLER, // XPropertySet
77 SC_ADDINARG_VARARGS // sequence<any>
80 //------------------------------------------------------------------------
82 struct ScAddInArgDesc
84 String aInternalName; // used to match configuration and reflection information
85 String aName;
86 String aDescription;
87 ScAddInArgumentType eType;
88 BOOL bOptional;
91 class ScUnoAddInFuncData
93 private:
94 String aOriginalName; // kept in formula
95 String aLocalName; // for display
96 String aUpperName; // for entering formulas
97 String aUpperLocal; // for entering formulas
98 String aDescription;
99 com::sun::star::uno::Reference< com::sun::star::reflection::XIdlMethod> xFunction;
100 com::sun::star::uno::Any aObject;
101 long nArgCount;
102 ScAddInArgDesc* pArgDescs;
103 long nCallerPos;
104 USHORT nCategory;
105 USHORT nHelpId;
106 mutable com::sun::star::uno::Sequence< com::sun::star::sheet::LocalizedName> aCompNames;
107 mutable BOOL bCompInitialized;
109 public:
110 ScUnoAddInFuncData( const String& rNam, const String& rLoc,
111 const String& rDesc,
112 USHORT nCat, USHORT nHelp,
113 const com::sun::star::uno::Reference<
114 com::sun::star::reflection::XIdlMethod>& rFunc,
115 const com::sun::star::uno::Any& rO,
116 long nAC, const ScAddInArgDesc* pAD,
117 long nCP );
118 ~ScUnoAddInFuncData();
120 const String& GetOriginalName() const { return aOriginalName; }
121 const String& GetLocalName() const { return aLocalName; }
122 const String& GetUpperName() const { return aUpperName; }
123 const String& GetUpperLocal() const { return aUpperLocal; }
124 const com::sun::star::uno::Reference< com::sun::star::reflection::XIdlMethod>& GetFunction() const
125 { return xFunction; }
126 const com::sun::star::uno::Any& GetObject() const { return aObject; }
127 long GetArgumentCount() const { return nArgCount; }
128 const ScAddInArgDesc* GetArguments() const { return pArgDescs; }
129 long GetCallerPos() const { return nCallerPos; }
130 const String& GetDescription() const { return aDescription; }
131 USHORT GetCategory() const { return nCategory; }
132 USHORT GetHelpId() const { return nHelpId; }
134 const com::sun::star::uno::Sequence< com::sun::star::sheet::LocalizedName>& GetCompNames() const;
135 BOOL GetExcelName( LanguageType eDestLang, String& rRetExcelName ) const;
137 void SetFunction( const com::sun::star::uno::Reference< com::sun::star::reflection::XIdlMethod>& rNewFunc,
138 const com::sun::star::uno::Any& rNewObj );
139 void SetArguments( long nNewCount, const ScAddInArgDesc* pNewDescs );
140 void SetCallerPos( long nNewPos );
141 void SetCompNames( const com::sun::star::uno::Sequence< com::sun::star::sheet::LocalizedName>& rNew );
144 //------------------------------------------------------------------------
146 class SC_DLLPUBLIC ScUnoAddInCollection
148 private:
149 long nFuncCount;
150 ScUnoAddInFuncData** ppFuncData;
151 ScAddInHashMap* pExactHashMap; // exact internal name
152 ScAddInHashMap* pNameHashMap; // internal name upper
153 ScAddInHashMap* pLocalHashMap; // localized name upper
154 BOOL bInitialized;
156 void Initialize();
157 void ReadConfiguration();
158 void ReadFromAddIn( const com::sun::star::uno::Reference<
159 com::sun::star::uno::XInterface>& xInterface );
160 void UpdateFromAddIn( const com::sun::star::uno::Reference<
161 com::sun::star::uno::XInterface>& xInterface,
162 const String& rServiceName );
163 void LoadComponent( const ScUnoAddInFuncData& rFuncData );
165 public:
166 ScUnoAddInCollection();
167 ~ScUnoAddInCollection();
169 /// User enetered name. rUpperName MUST already be upper case!
170 String FindFunction( const String& rUpperName, BOOL bLocalFirst );
172 // rName is the exact Name.
173 // Only if bComplete is set, the function reference and argument types
174 // are initialized (component may have to be loaded).
175 const ScUnoAddInFuncData* GetFuncData( const String& rName, bool bComplete = false );
177 /** For enumeration in ScCompiler::OpCodeMap::getAvailableMappings().
178 @param nIndex
179 0 <= nIndex < GetFuncCount()
181 const ScUnoAddInFuncData* GetFuncData( long nIndex );
183 void Clear();
185 void LocalizeString( String& rName ); // modify rName - input: exact name
187 long GetFuncCount();
188 BOOL FillFunctionDesc( long nFunc, ScFuncDesc& rDesc );
190 static BOOL FillFunctionDescFromData( const ScUnoAddInFuncData& rFuncData, ScFuncDesc& rDesc );
192 BOOL GetExcelName( const String& rCalcName, LanguageType eDestLang, String& rRetExcelName );
193 BOOL GetCalcName( const String& rExcelName, String& rRetCalcName );
194 // both leave rRet... unchanged, if no matching name is found
198 class ScUnoAddInCall
200 private:
201 const ScUnoAddInFuncData* pFuncData;
202 com::sun::star::uno::Sequence<com::sun::star::uno::Any> aArgs;
203 com::sun::star::uno::Sequence<com::sun::star::uno::Any> aVarArg;
204 com::sun::star::uno::Reference<com::sun::star::uno::XInterface> xCaller;
205 BOOL bValidCount;
206 // result:
207 USHORT nErrCode;
208 BOOL bHasString;
209 double fValue;
210 String aString;
211 ScMatrixRef xMatrix;
212 com::sun::star::uno::Reference<com::sun::star::sheet::XVolatileResult> xVarRes;
214 void ExecuteCallWithArgs(
215 com::sun::star::uno::Sequence<com::sun::star::uno::Any>& rCallArgs);
217 public:
218 // exact name
219 ScUnoAddInCall( ScUnoAddInCollection& rColl, const String& rName,
220 long nParamCount );
221 ~ScUnoAddInCall();
223 BOOL NeedsCaller() const;
224 void SetCaller( const com::sun::star::uno::Reference<
225 com::sun::star::uno::XInterface>& rInterface );
226 void SetCallerFromObjectShell( SfxObjectShell* pSh );
228 BOOL ValidParamCount();
229 ScAddInArgumentType GetArgType( long nPos );
230 void SetParam( long nPos, const com::sun::star::uno::Any& rValue );
232 void ExecuteCall();
234 void SetResult( const com::sun::star::uno::Any& rNewRes );
236 USHORT GetErrCode() const { return nErrCode; }
237 BOOL HasString() const { return bHasString; }
238 BOOL HasMatrix() const { return ( xMatrix.Is() ); }
239 BOOL HasVarRes() const { return ( xVarRes.is() ); }
240 double GetValue() const { return fValue; }
241 const String& GetString() const { return aString; }
242 ScMatrixRef GetMatrix() const { return xMatrix; }
243 com::sun::star::uno::Reference<com::sun::star::sheet::XVolatileResult>
244 GetVarRes() const { return xVarRes; }
248 #endif