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