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 RPTUI_FUNCTIONHELPER_HXX
25 #define RPTUI_FUNCTIONHELPER_HXX
26 
27 #include <formula/IFunctionDescription.hxx>
28 #include <com/sun/star/report/meta/XFunctionManager.hpp>
29 #include <com/sun/star/report/meta/XFunctionCategory.hpp>
30 #include <com/sun/star/report/meta/XFunctionDescription.hpp>
31 #include <vector>
32 #include <boost/shared_ptr.hpp>
33 #include <tools/string.hxx>
34 #include <comphelper/stl_types.hxx>
35 
36 
37 namespace rptui
38 {
39 //============================================================================
40 class FunctionCategory;
41 class FunctionDescription;
42 //============================================================================
43 class FunctionManager : public formula::IFunctionManager
44 {
45     DECLARE_STL_USTRINGACCESS_MAP( ::boost::shared_ptr< FunctionDescription >,  TFunctionsMap);
46     DECLARE_STL_USTRINGACCESS_MAP( ::boost::shared_ptr< FunctionCategory > ,    TCategoriesMap);
47     ::com::sun::star::uno::Reference< ::com::sun::star::report::meta::XFunctionManager> m_xMgr;
48     mutable TCategoriesMap  m_aCategories;
49     mutable ::std::vector< TCategoriesMap::iterator > m_aCategoryIndex;
50     mutable TFunctionsMap   m_aFunctions;
51 public:
52             FunctionManager(const ::com::sun::star::uno::Reference< ::com::sun::star::report::meta::XFunctionManager>& _xMgr);
53     virtual ~FunctionManager();
54     virtual sal_uInt32                              getCount() const;
55     virtual const formula::IFunctionCategory*       getCategory(sal_uInt32 nPos) const;
56     virtual void                                    fillLastRecentlyUsedFunctions(::std::vector< const formula::IFunctionDescription*>& _rLastRUFunctions) const;
57     virtual const formula::IFunctionDescription*    getFunctionByName(const ::rtl::OUString& _sFunctionName) const;
58     virtual sal_Unicode                       getSingleToken(const EToken _eToken) const;
59 
60     ::boost::shared_ptr< FunctionDescription >      get(const ::com::sun::star::uno::Reference< ::com::sun::star::report::meta::XFunctionDescription>& _xFunctionDescription) const;
61 };
62 //============================================================================
63 class FunctionDescription : public formula::IFunctionDescription
64 {
65     ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FunctionArgument > m_aParameter;
66     ::com::sun::star::uno::Reference< ::com::sun::star::report::meta::XFunctionDescription> m_xFunctionDescription;
67     const formula::IFunctionCategory* m_pFunctionCategory;
68 public:
69     FunctionDescription(const formula::IFunctionCategory* _pFunctionCategory,const ::com::sun::star::uno::Reference< ::com::sun::star::report::meta::XFunctionDescription>& _xFunctionDescription);
~FunctionDescription()70     virtual ~FunctionDescription(){}
71 
72     virtual ::rtl::OUString getFunctionName() const ;
73     virtual const formula::IFunctionCategory* getCategory() const ;
74     virtual ::rtl::OUString getDescription() const ;
75     virtual xub_StrLen getSuppressedArgumentCount() const ;
76     virtual ::rtl::OUString getFormula(const ::std::vector< ::rtl::OUString >& _aArguments) const ;
77     virtual void fillVisibleArgumentMapping(::std::vector<sal_uInt16>& _rArguments) const ;
78     virtual void initArgumentInfo()  const;
79     virtual ::rtl::OUString getSignature() const ;
80     virtual rtl::OString getHelpId() const ;
81     virtual sal_uInt32 getParameterCount() const ;
82     virtual ::rtl::OUString getParameterName(sal_uInt32 _nPos) const ;
83     virtual ::rtl::OUString getParameterDescription(sal_uInt32 _nPos) const ;
84     virtual bool isParameterOptional(sal_uInt32 _nPos) const ;
85 };
86 //============================================================================
87 class FunctionCategory : public formula::IFunctionCategory
88 {
89     mutable ::std::vector< ::boost::shared_ptr< FunctionDescription > > m_aFunctions;
90     ::com::sun::star::uno::Reference< ::com::sun::star::report::meta::XFunctionCategory> m_xCategory;
91     sal_uInt32 m_nFunctionCount;
92     sal_uInt32 m_nNumber;
93     const FunctionManager* m_pFunctionManager;
94 public:
95     FunctionCategory(const FunctionManager* _pFMgr,sal_uInt32 _nPos,const ::com::sun::star::uno::Reference< ::com::sun::star::report::meta::XFunctionCategory>& _xCategory);
~FunctionCategory()96     virtual ~FunctionCategory() {}
97 
98     virtual sal_uInt32                              getCount() const;
99     virtual const formula::IFunctionDescription*    getFunction(sal_uInt32 _nPos) const;
100     virtual sal_uInt32                              getNumber() const;
101     virtual const formula::IFunctionManager*        getFunctionManager() const;
102     virtual ::rtl::OUString                         getName() const;
103 };
104 // =============================================================================
105 } // rptui
106 // =============================================================================
107 
108 #endif //RPTUI_FUNCTIONHELPER_HXX
109