Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / scaddins / source / datefunc / datefunc.hxx
blob8299a3635418852d61cabf41237e477a787cbc01
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 // date functions add in
22 #ifndef INCLUDED_SCADDINS_SOURCE_DATEFUNC_DATEFUNC_HXX
23 #define INCLUDED_SCADDINS_SOURCE_DATEFUNC_DATEFUNC_HXX
25 #include <string.h>
26 #include <vector>
27 #include <memory>
28 #include <com/sun/star/lang/XServiceName.hpp>
29 #include <com/sun/star/lang/XServiceInfo.hpp>
30 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 #include <com/sun/star/sheet/XAddIn.hpp>
32 #include <com/sun/star/sheet/XCompatibilityNames.hpp>
33 #include <com/sun/star/sheet/addin/XDateFunctions.hpp>
34 #include <com/sun/star/sheet/addin/XMiscFunctions.hpp>
35 #include <cppuhelper/implbase.hxx>
36 #include <tools/resid.hxx>
37 #include <tools/resary.hxx>
39 class ScaResId : public ResId
41 public:
42 ScaResId(sal_uInt16 nResId, ResMgr& rResMgr);
45 enum class ScaCategory
47 DateTime,
48 Text,
49 Finance,
50 Inf,
51 Math,
52 Tech
55 struct ScaFuncDataBase
57 const sal_Char* pIntName; // internal name (get***)
58 sal_uInt16 nUINameID; // resource ID to UI name
59 sal_uInt16 nDescrID; // resource ID to description, parameter names and ~ description
60 const char** pCompListID; // list of valid names
61 sal_uInt16 nParamCount; // number of named / described parameters
62 ScaCategory eCat; // function category
63 bool bDouble; // name already exist in Calc
64 bool bWithOpt; // first parameter is internal
67 class ScaFuncData final
69 private:
70 OUString aIntName; // internal name (get***)
71 sal_uInt16 nUINameID; // resource ID to UI name
72 sal_uInt16 nDescrID; // leads also to parameter descriptions!
73 sal_uInt16 nParamCount; // num of parameters
74 std::vector<OUString> aCompList; // list of all valid names
75 ScaCategory eCat; // function category
76 bool bDouble; // name already exist in Calc
77 bool bWithOpt; // first parameter is internal
79 public:
80 ScaFuncData(const ScaFuncDataBase& rBaseData);
81 ~ScaFuncData();
83 sal_uInt16 GetUINameID() const { return nUINameID; }
84 sal_uInt16 GetDescrID() const { return nDescrID; }
85 ScaCategory GetCategory() const { return eCat; }
86 bool IsDouble() const { return bDouble; }
88 sal_uInt16 GetStrIndex( sal_uInt16 nParam ) const;
89 bool Is( const OUString& rCompare ) const
90 { return aIntName == rCompare; }
92 const std::vector<OUString>& GetCompNameList() const { return aCompList; }
95 typedef std::vector<ScaFuncData> ScaFuncDataList;
97 // Predicate for use with std::find_if
98 struct FindScaFuncData
100 const OUString& m_rId;
101 explicit FindScaFuncData( const OUString& rId ) : m_rId(rId) {}
102 bool operator() ( ScaFuncData& rCandidate ) const { return rCandidate.Is(m_rId); }
106 css::uno::Reference< css::uno::XInterface > SAL_CALL DateFunctionAddIn_CreateInstance(
107 const css::uno::Reference< css::lang::XMultiServiceFactory >& );
110 // THE AddIn class for date functions
112 class ScaDateAddIn : public ::cppu::WeakImplHelper<
113 css::sheet::XAddIn,
114 css::sheet::XCompatibilityNames,
115 css::sheet::addin::XDateFunctions,
116 css::sheet::addin::XMiscFunctions,
117 css::lang::XServiceName,
118 css::lang::XServiceInfo >
120 private:
121 css::lang::Locale aFuncLoc;
122 std::unique_ptr< css::lang::Locale[] > pDefLocales;
123 std::unique_ptr< ResMgr > pResMgr;
124 std::unique_ptr< ScaFuncDataList > pFuncDataList;
127 void InitDefLocales();
128 const css::lang::Locale& GetLocale( sal_uInt32 nIndex );
129 /// @throws css::uno::RuntimeException
130 ResMgr& GetResMgr();
131 void InitData();
133 /// @throws css::uno::RuntimeException
134 OUString GetFuncDescrStr( sal_uInt16 nResId, sal_uInt16 nStrIndex );
136 public:
137 ScaDateAddIn();
139 static OUString getImplementationName_Static();
140 static css::uno::Sequence< OUString > getSupportedServiceNames_Static();
142 // XAddIn
143 virtual OUString SAL_CALL getProgrammaticFuntionName( const OUString& aDisplayName ) override;
144 virtual OUString SAL_CALL getDisplayFunctionName( const OUString& aProgrammaticName ) override;
145 virtual OUString SAL_CALL getFunctionDescription( const OUString& aProgrammaticName ) override;
146 virtual OUString SAL_CALL getDisplayArgumentName( const OUString& aProgrammaticName, sal_Int32 nArgument ) override;
147 virtual OUString SAL_CALL getArgumentDescription( const OUString& aProgrammaticName, sal_Int32 nArgument ) override;
148 virtual OUString SAL_CALL getProgrammaticCategoryName( const OUString& aProgrammaticName ) override;
149 virtual OUString SAL_CALL getDisplayCategoryName( const OUString& aProgrammaticName ) override;
151 // XCompatibilityNames
152 virtual css::uno::Sequence< css::sheet::LocalizedName > SAL_CALL getCompatibilityNames( const OUString& aProgrammaticName ) override;
154 // XLocalizable
155 virtual void SAL_CALL setLocale( const css::lang::Locale& eLocale ) override;
156 virtual css::lang::Locale SAL_CALL getLocale() override;
158 // XServiceName
159 virtual OUString SAL_CALL getServiceName() override;
161 // XServiceInfo
162 virtual OUString SAL_CALL getImplementationName() override;
163 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
164 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
166 // methods from own interfaces start here
168 // XDateFunctions
169 virtual sal_Int32 SAL_CALL getDiffWeeks(
170 const css::uno::Reference< css::beans::XPropertySet >& xOptions,
171 sal_Int32 nEndDate, sal_Int32 nStartDate,
172 sal_Int32 nMode ) override;
174 virtual sal_Int32 SAL_CALL getDiffMonths(
175 const css::uno::Reference< css::beans::XPropertySet >& xOptions,
176 sal_Int32 nEndDate, sal_Int32 nStartDate,
177 sal_Int32 nMode ) override;
179 virtual sal_Int32 SAL_CALL getDiffYears(
180 const css::uno::Reference< css::beans::XPropertySet >& xOptions,
181 sal_Int32 nEndDate, sal_Int32 nStartDate,
182 sal_Int32 nMode ) override;
184 virtual sal_Int32 SAL_CALL getIsLeapYear(
185 const css::uno::Reference< css::beans::XPropertySet >& xOptions,
186 sal_Int32 nDate ) override;
188 virtual sal_Int32 SAL_CALL getDaysInMonth(
189 const css::uno::Reference< css::beans::XPropertySet >& xOptions,
190 sal_Int32 nDate ) override;
192 virtual sal_Int32 SAL_CALL getDaysInYear(
193 const css::uno::Reference< css::beans::XPropertySet >& xOptions,
194 sal_Int32 nDate ) override;
196 virtual sal_Int32 SAL_CALL getWeeksInYear(
197 const css::uno::Reference< css::beans::XPropertySet >& xOptions,
198 sal_Int32 nDate ) override;
200 // XMiscFunctions
201 virtual OUString SAL_CALL getRot13(
202 const OUString& aSrcText ) override;
205 #endif // INCLUDED_SCADDINS_SOURCE_DATEFUNC_DATEFUNC_HXX
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */