1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef SC_ADDINCOL_HXX 25 #define SC_ADDINCOL_HXX 26 27 #include "global.hxx" 28 #include <com/sun/star/sheet/XVolatileResult.hpp> 29 #include <com/sun/star/sheet/XAddIn.hpp> 30 #include <com/sun/star/sheet/XResultListener.hpp> 31 #include <com/sun/star/sheet/ResultEvent.hpp> 32 #include <com/sun/star/container/XNameAccess.hpp> 33 #include <com/sun/star/reflection/XIdlMethod.hpp> 34 #include <com/sun/star/sheet/LocalizedName.hpp> 35 #include <tools/string.hxx> 36 #include <i18npool/lang.h> 37 #include <rtl/ustring.h> 38 #include "scdllapi.h" 39 #include <rtl/ustring.hxx> 40 41 #ifndef SC_SCMATRIX_HXX 42 #include "scmatrix.hxx" 43 #endif 44 45 #include <hash_map> 46 47 48 class String; 49 class SfxObjectShell; 50 class ScUnoAddInFuncData; 51 class ScMatrix; 52 class ScFuncDesc; 53 54 55 typedef ::std::hash_map< String, const ScUnoAddInFuncData*, ScStringHashCode, ::std::equal_to< String > > ScAddInHashMap; 56 57 58 enum ScAddInArgumentType 59 { 60 SC_ADDINARG_NONE, // - 61 SC_ADDINARG_INTEGER, // long 62 SC_ADDINARG_DOUBLE, // double 63 SC_ADDINARG_STRING, // string 64 SC_ADDINARG_INTEGER_ARRAY, // sequence<sequence<long>> 65 SC_ADDINARG_DOUBLE_ARRAY, // sequence<sequence<double>> 66 SC_ADDINARG_STRING_ARRAY, // sequence<sequence<string>> 67 SC_ADDINARG_MIXED_ARRAY, // sequence<sequence<any>> 68 SC_ADDINARG_VALUE_OR_ARRAY, // any 69 SC_ADDINARG_CELLRANGE, // XCellRange 70 SC_ADDINARG_CALLER, // XPropertySet 71 SC_ADDINARG_VARARGS // sequence<any> 72 }; 73 74 //------------------------------------------------------------------------ 75 76 struct ScAddInArgDesc 77 { 78 String aInternalName; // used to match configuration and reflection information 79 String aName; 80 String aDescription; 81 ScAddInArgumentType eType; 82 sal_Bool bOptional; 83 }; 84 85 class ScUnoAddInFuncData 86 { 87 private: 88 String aOriginalName; // kept in formula 89 String aLocalName; // for display 90 String aUpperName; // for entering formulas 91 String aUpperLocal; // for entering formulas 92 String aDescription; 93 com::sun::star::uno::Reference< com::sun::star::reflection::XIdlMethod> xFunction; 94 com::sun::star::uno::Any aObject; 95 long nArgCount; 96 ScAddInArgDesc* pArgDescs; 97 long nCallerPos; 98 sal_uInt16 nCategory; 99 rtl::OString sHelpId; 100 mutable com::sun::star::uno::Sequence< com::sun::star::sheet::LocalizedName> aCompNames; 101 mutable sal_Bool bCompInitialized; 102 103 public: 104 ScUnoAddInFuncData( const String& rNam, const String& rLoc, 105 const String& rDesc, 106 sal_uInt16 nCat, const rtl::OString&, 107 const com::sun::star::uno::Reference< 108 com::sun::star::reflection::XIdlMethod>& rFunc, 109 const com::sun::star::uno::Any& rO, 110 long nAC, const ScAddInArgDesc* pAD, 111 long nCP ); 112 ~ScUnoAddInFuncData(); 113 GetOriginalName() const114 const String& GetOriginalName() const { return aOriginalName; } GetLocalName() const115 const String& GetLocalName() const { return aLocalName; } GetUpperName() const116 const String& GetUpperName() const { return aUpperName; } GetUpperLocal() const117 const String& GetUpperLocal() const { return aUpperLocal; } GetFunction() const118 const com::sun::star::uno::Reference< com::sun::star::reflection::XIdlMethod>& GetFunction() const 119 { return xFunction; } GetObject() const120 const com::sun::star::uno::Any& GetObject() const { return aObject; } GetArgumentCount() const121 long GetArgumentCount() const { return nArgCount; } GetArguments() const122 const ScAddInArgDesc* GetArguments() const { return pArgDescs; } GetCallerPos() const123 long GetCallerPos() const { return nCallerPos; } GetDescription() const124 const String& GetDescription() const { return aDescription; } GetCategory() const125 sal_uInt16 GetCategory() const { return nCategory; } GetHelpId() const126 const rtl::OString GetHelpId() const { return sHelpId; } 127 128 const com::sun::star::uno::Sequence< com::sun::star::sheet::LocalizedName>& GetCompNames() const; 129 sal_Bool GetExcelName( LanguageType eDestLang, String& rRetExcelName ) const; 130 131 void SetFunction( const com::sun::star::uno::Reference< com::sun::star::reflection::XIdlMethod>& rNewFunc, 132 const com::sun::star::uno::Any& rNewObj ); 133 void SetArguments( long nNewCount, const ScAddInArgDesc* pNewDescs ); 134 void SetCallerPos( long nNewPos ); 135 void SetCompNames( const com::sun::star::uno::Sequence< com::sun::star::sheet::LocalizedName>& rNew ); 136 }; 137 138 //------------------------------------------------------------------------ 139 140 class SC_DLLPUBLIC ScUnoAddInCollection 141 { 142 private: 143 long nFuncCount; 144 ScUnoAddInFuncData** ppFuncData; 145 ScAddInHashMap* pExactHashMap; // exact internal name 146 ScAddInHashMap* pNameHashMap; // internal name upper 147 ScAddInHashMap* pLocalHashMap; // localized name upper 148 sal_Bool bInitialized; 149 150 void Initialize(); 151 void ReadConfiguration(); 152 void ReadFromAddIn( const com::sun::star::uno::Reference< 153 com::sun::star::uno::XInterface>& xInterface ); 154 void UpdateFromAddIn( const com::sun::star::uno::Reference< 155 com::sun::star::uno::XInterface>& xInterface, 156 const String& rServiceName ); 157 void LoadComponent( const ScUnoAddInFuncData& rFuncData ); 158 159 public: 160 ScUnoAddInCollection(); 161 ~ScUnoAddInCollection(); 162 163 /// User enetered name. rUpperName MUST already be upper case! 164 String FindFunction( const String& rUpperName, sal_Bool bLocalFirst ); 165 166 // rName is the exact Name. 167 // Only if bComplete is set, the function reference and argument types 168 // are initialized (component may have to be loaded). 169 const ScUnoAddInFuncData* GetFuncData( const String& rName, bool bComplete = false ); 170 171 /** For enumeration in ScCompiler::OpCodeMap::getAvailableMappings(). 172 @param nIndex 173 0 <= nIndex < GetFuncCount() 174 */ 175 const ScUnoAddInFuncData* GetFuncData( long nIndex ); 176 177 void Clear(); 178 179 void LocalizeString( String& rName ); // modify rName - input: exact name 180 181 long GetFuncCount(); 182 sal_Bool FillFunctionDesc( long nFunc, ScFuncDesc& rDesc ); 183 184 static sal_Bool FillFunctionDescFromData( const ScUnoAddInFuncData& rFuncData, ScFuncDesc& rDesc ); 185 186 sal_Bool GetExcelName( const String& rCalcName, LanguageType eDestLang, String& rRetExcelName ); 187 sal_Bool GetCalcName( const String& rExcelName, String& rRetCalcName ); 188 // both leave rRet... unchanged, if no matching name is found 189 }; 190 191 192 class ScUnoAddInCall 193 { 194 private: 195 const ScUnoAddInFuncData* pFuncData; 196 com::sun::star::uno::Sequence<com::sun::star::uno::Any> aArgs; 197 com::sun::star::uno::Sequence<com::sun::star::uno::Any> aVarArg; 198 com::sun::star::uno::Reference<com::sun::star::uno::XInterface> xCaller; 199 sal_Bool bValidCount; 200 // result: 201 sal_uInt16 nErrCode; 202 sal_Bool bHasString; 203 double fValue; 204 String aString; 205 ScMatrixRef xMatrix; 206 com::sun::star::uno::Reference<com::sun::star::sheet::XVolatileResult> xVarRes; 207 208 void ExecuteCallWithArgs( 209 com::sun::star::uno::Sequence<com::sun::star::uno::Any>& rCallArgs); 210 211 public: 212 // exact name 213 ScUnoAddInCall( ScUnoAddInCollection& rColl, const String& rName, 214 long nParamCount ); 215 ~ScUnoAddInCall(); 216 217 sal_Bool NeedsCaller() const; 218 void SetCaller( const com::sun::star::uno::Reference< 219 com::sun::star::uno::XInterface>& rInterface ); 220 void SetCallerFromObjectShell( SfxObjectShell* pSh ); 221 222 sal_Bool ValidParamCount(); 223 ScAddInArgumentType GetArgType( long nPos ); 224 void SetParam( long nPos, const com::sun::star::uno::Any& rValue ); 225 226 void ExecuteCall(); 227 228 void SetResult( const com::sun::star::uno::Any& rNewRes ); 229 GetErrCode() const230 sal_uInt16 GetErrCode() const { return nErrCode; } HasString() const231 sal_Bool HasString() const { return bHasString; } HasMatrix() const232 sal_Bool HasMatrix() const { return ( xMatrix.Is() ); } HasVarRes() const233 sal_Bool HasVarRes() const { return ( xVarRes.is() ); } GetValue() const234 double GetValue() const { return fValue; } GetString() const235 const String& GetString() const { return aString; } GetMatrix() const236 ScMatrixRef GetMatrix() const { return xMatrix; } 237 com::sun::star::uno::Reference<com::sun::star::sheet::XVolatileResult> GetVarRes() const238 GetVarRes() const { return xVarRes; } 239 }; 240 241 242 #endif 243 244