1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: addincol.hxx,v $
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
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>
47 #ifndef SC_SCMATRIX_HXX
48 #include "scmatrix.hxx"
56 class ScUnoAddInFuncData
;
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 //------------------------------------------------------------------------
84 String aInternalName
; // used to match configuration and reflection information
87 ScAddInArgumentType eType
;
91 class ScUnoAddInFuncData
94 String aOriginalName
; // kept in formula
95 String aLocalName
; // for display
96 String aUpperName
; // for entering formulas
97 String aUpperLocal
; // for entering formulas
99 com::sun::star::uno::Reference
< com::sun::star::reflection::XIdlMethod
> xFunction
;
100 com::sun::star::uno::Any aObject
;
102 ScAddInArgDesc
* pArgDescs
;
106 mutable com::sun::star::uno::Sequence
< com::sun::star::sheet::LocalizedName
> aCompNames
;
107 mutable BOOL bCompInitialized
;
110 ScUnoAddInFuncData( const String
& rNam
, const String
& rLoc
,
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
,
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
150 ScUnoAddInFuncData
** ppFuncData
;
151 ScAddInHashMap
* pExactHashMap
; // exact internal name
152 ScAddInHashMap
* pNameHashMap
; // internal name upper
153 ScAddInHashMap
* pLocalHashMap
; // localized name upper
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
);
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().
179 0 <= nIndex < GetFuncCount()
181 const ScUnoAddInFuncData
* GetFuncData( long nIndex
);
185 void LocalizeString( String
& rName
); // modify rName - input: exact name
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
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
;
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
);
219 ScUnoAddInCall( ScUnoAddInCollection
& rColl
, const String
& rName
,
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
);
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
; }