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_FUNCDESC_HXX 25 #define SC_FUNCDESC_HXX 26 27 /* Function descriptions for function wizard / autopilot / most recent used 28 * list et al. Separated from the global.hxx lump, implementation still in 29 * global.cxx 30 */ 31 32 #include <tools/list.hxx> 33 #include <tools/string.hxx> 34 #include <formula/IFunctionDescription.hxx> 35 36 #define MAX_FUNCCAT 12 /* maximum number of categories for functions */ 37 38 class ScFuncDesc : public formula::IFunctionDescription 39 { 40 public: 41 42 virtual ::rtl::OUString getFunctionName() const ; 43 virtual const formula::IFunctionCategory* getCategory() const ; 44 virtual ::rtl::OUString getDescription() const ; 45 // GetSuppressedArgCount 46 virtual xub_StrLen getSuppressedArgumentCount() const ; 47 /** Returns the function signature with parameters from the passed string array. */ 48 virtual ::rtl::OUString getFormula(const ::std::vector< ::rtl::OUString >& _aArguments) const ; 49 // GetVisibleArgMapping 50 /** Returns mapping from visible arguments to real arguments, e.g. if of 4 51 parameters the second one is suppressed {0,2,3}. For VAR_ARGS 52 parameters only one element is added to the end of the sequence. */ 53 virtual void fillVisibleArgumentMapping(::std::vector<sal_uInt16>& _rArguments) const ; 54 virtual void initArgumentInfo() const; 55 virtual ::rtl::OUString getSignature() const ; 56 virtual rtl::OString getHelpId() const ; 57 58 // parameter 59 virtual sal_uInt32 getParameterCount() const ; 60 virtual ::rtl::OUString getParameterName(sal_uInt32 _nPos) const ; 61 virtual ::rtl::OUString getParameterDescription(sal_uInt32 _nPos) const ; 62 virtual bool isParameterOptional(sal_uInt32 _nPos) const ; 63 64 struct ParameterFlags 65 { 66 bool bOptional :1; // Parameter is optional 67 bool bSuppress :1; // Suppress parameter in UI because not implemented yet 68 ParameterFlagsScFuncDesc::ParameterFlags69 ParameterFlags() : bOptional(false), bSuppress(false) {} 70 }; 71 72 73 ScFuncDesc(); 74 virtual ~ScFuncDesc(); 75 76 void Clear(); 77 78 /** Returns a semicolon separated list of all parameter names. */ 79 String GetParamList () const; 80 /** Returns the full function signature: "FUNCTIONNAME( parameter list )". */ 81 String GetSignature () const; 82 83 84 85 /** Returns the number of non-suppressed arguments. In case there are 86 variable arguments the number of fixed non-suppressed arguments plus 87 VAR_ARGS, same as for nArgCount (variable arguments can't be 88 suppressed). */ 89 sal_uInt16 GetSuppressedArgCount() const; 90 91 String *pFuncName; // Function name 92 String *pFuncDesc; // Description of function 93 String **ppDefArgNames; // Parameter name(s) 94 String **ppDefArgDescs; // Description(s) of parameter(s) 95 ParameterFlags *pDefArgFlags; // Flags for each parameter 96 sal_uInt16 nFIndex; // Unique function index 97 sal_uInt16 nCategory; // Function category 98 sal_uInt16 nArgCount; // All parameter count, suppressed and unsuppressed 99 rtl::OString sHelpId; // HelpID of function 100 bool bIncomplete :1; // Incomplete argument info (set for add-in info from configuration) 101 bool bHasSuppressedArgs :1; // Whether there is any suppressed parameter. 102 }; 103 104 //============================================================================ 105 106 class ScFunctionList 107 { 108 public: 109 ScFunctionList(); 110 ~ScFunctionList(); 111 GetCount() const112 sal_uLong GetCount() const 113 { return aFunctionList.Count(); } 114 First()115 const ScFuncDesc* First() 116 { return (const ScFuncDesc*) aFunctionList.First(); } 117 Next()118 const ScFuncDesc* Next() 119 { return (const ScFuncDesc*) aFunctionList.Next(); } 120 GetFunction(sal_uLong nIndex) const121 const ScFuncDesc* GetFunction( sal_uLong nIndex ) const 122 { return (const ScFuncDesc*) aFunctionList.GetObject( nIndex ); } 123 GetMaxFuncNameLen() const124 xub_StrLen GetMaxFuncNameLen() const 125 { return nMaxFuncNameLen; } 126 127 private: 128 List aFunctionList; 129 xub_StrLen nMaxFuncNameLen; 130 }; 131 132 //============================================================================ 133 class ScFunctionCategory : public formula::IFunctionCategory 134 { 135 ScFunctionMgr* m_pMgr; 136 List* m_pCategory; 137 mutable ::rtl::OUString m_sName; 138 sal_uInt32 m_nCategory; 139 public: ScFunctionCategory(ScFunctionMgr * _pMgr,List * _pCategory,sal_uInt32 _nCategory)140 ScFunctionCategory(ScFunctionMgr* _pMgr,List* _pCategory,sal_uInt32 _nCategory) : m_pMgr(_pMgr),m_pCategory(_pCategory),m_nCategory(_nCategory){} ~ScFunctionCategory()141 virtual ~ScFunctionCategory(){} 142 virtual sal_uInt32 getCount() const; 143 virtual const formula::IFunctionManager* getFunctionManager() const; 144 virtual const formula::IFunctionDescription* getFunction(sal_uInt32 _nPos) const; 145 virtual sal_uInt32 getNumber() const; 146 virtual ::rtl::OUString getName() const; 147 }; 148 //============================================================================ 149 #define SC_FUNCGROUP_COUNT ID_FUNCTION_GRP_ADDINS 150 class ScFunctionMgr : public formula::IFunctionManager 151 { 152 public: 153 ScFunctionMgr(); 154 virtual ~ScFunctionMgr(); 155 156 static String GetCategoryName(sal_uInt32 _nCategoryNumber ); 157 158 const ScFuncDesc* Get( const String& rFName ) const; 159 const ScFuncDesc* Get( sal_uInt16 nFIndex ) const; 160 const ScFuncDesc* First( sal_uInt16 nCategory = 0 ) const; 161 const ScFuncDesc* Next() const; 162 163 // formula::IFunctionManager 164 virtual sal_uInt32 getCount() const; 165 virtual const formula::IFunctionCategory* getCategory(sal_uInt32 nPos) const; 166 virtual void fillLastRecentlyUsedFunctions(::std::vector< const formula::IFunctionDescription*>& _rLastRUFunctions) const; 167 virtual const formula::IFunctionDescription* getFunctionByName(const ::rtl::OUString& _sFunctionName) const; 168 virtual sal_Unicode getSingleToken(const formula::IFunctionManager::EToken _eToken) const; 169 private: 170 ScFunctionList* pFuncList; 171 List* aCatLists[MAX_FUNCCAT]; 172 mutable List* pCurCatList; 173 }; 174 175 //============================================================================ 176 #endif // SC_FUNCDESC_HXX 177