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