Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / scaddins / source / datefunc / datefunc.hxx
blob967837e35e06afee094bd78dad36cfea7cb6d451
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 <vector>
26 #include <memory>
27 #include <com/sun/star/lang/XServiceName.hpp>
28 #include <com/sun/star/lang/XServiceInfo.hpp>
29 #include <com/sun/star/sheet/XAddIn.hpp>
30 #include <com/sun/star/sheet/XCompatibilityNames.hpp>
31 #include <com/sun/star/sheet/addin/XDateFunctions.hpp>
32 #include <com/sun/star/sheet/addin/XMiscFunctions.hpp>
33 #include <cppuhelper/implbase.hxx>
35 namespace com::sun::star::lang { class XMultiServiceFactory; }
37 enum class ScaCategory
39 DateTime,
40 Text,
41 Finance,
42 Inf,
43 Math,
44 Tech
47 struct ScaFuncDataBase
49 const sal_Char* pIntName; // internal name (get***)
50 const char* pUINameID; // resource ID to UI name
51 const char** pDescrID; // resource ID to description, parameter names and ~ description
52 const char** pCompListID; // list of valid names
53 sal_uInt16 const nParamCount; // number of named / described parameters
54 ScaCategory const eCat; // function category
55 bool const bDouble; // name already exist in Calc
56 bool const bWithOpt; // first parameter is internal
59 class ScaFuncData final
61 private:
62 OUString const aIntName; // internal name (get***)
63 const char* pUINameID; // resource ID to UI name
64 const char** pDescrID; // leads also to parameter descriptions!
65 sal_uInt16 const nParamCount; // num of parameters
66 std::vector<OUString> aCompList; // list of all valid names
67 ScaCategory const eCat; // function category
68 bool const bDouble; // name already exist in Calc
69 bool const bWithOpt; // first parameter is internal
71 public:
72 ScaFuncData(const ScaFuncDataBase& rBaseData);
73 ~ScaFuncData();
75 const char* GetUINameID() const { return pUINameID; }
76 const char** GetDescrID() const { return pDescrID; }
77 ScaCategory GetCategory() const { return eCat; }
78 bool IsDouble() const { return bDouble; }
80 sal_uInt16 GetStrIndex( sal_uInt16 nParam ) const;
81 bool Is( const OUString& rCompare ) const
82 { return aIntName == rCompare; }
84 const std::vector<OUString>& GetCompNameList() const { return aCompList; }
87 typedef std::vector<ScaFuncData> ScaFuncDataList;
89 // Predicate for use with std::find_if
90 struct FindScaFuncData
92 const OUString& m_rId;
93 explicit FindScaFuncData( const OUString& rId ) : m_rId(rId) {}
94 bool operator() ( ScaFuncData const & rCandidate ) const { return rCandidate.Is(m_rId); }
98 css::uno::Reference< css::uno::XInterface > SAL_CALL DateFunctionAddIn_CreateInstance(
99 const css::uno::Reference< css::lang::XMultiServiceFactory >& );
102 // THE AddIn class for date functions
104 class ScaDateAddIn : public ::cppu::WeakImplHelper<
105 css::sheet::XAddIn,
106 css::sheet::XCompatibilityNames,
107 css::sheet::addin::XDateFunctions,
108 css::sheet::addin::XMiscFunctions,
109 css::lang::XServiceName,
110 css::lang::XServiceInfo >
112 private:
113 css::lang::Locale aFuncLoc;
114 std::unique_ptr< css::lang::Locale[] > pDefLocales;
115 std::locale aResLocale;
116 std::unique_ptr< ScaFuncDataList > pFuncDataList;
119 void InitDefLocales();
120 const css::lang::Locale& GetLocale( sal_uInt32 nIndex );
121 void InitData();
123 /// @throws css::uno::RuntimeException
124 OUString GetFuncDescrStr(const char** pResId, sal_uInt16 nStrIndex);
126 public:
127 ScaDateAddIn();
129 OUString ScaResId(const char* pId);
131 static OUString getImplementationName_Static();
132 static css::uno::Sequence< OUString > getSupportedServiceNames_Static();
134 // XAddIn
135 virtual OUString SAL_CALL getProgrammaticFuntionName( const OUString& aDisplayName ) override;
136 virtual OUString SAL_CALL getDisplayFunctionName( const OUString& aProgrammaticName ) override;
137 virtual OUString SAL_CALL getFunctionDescription( const OUString& aProgrammaticName ) override;
138 virtual OUString SAL_CALL getDisplayArgumentName( const OUString& aProgrammaticName, sal_Int32 nArgument ) override;
139 virtual OUString SAL_CALL getArgumentDescription( const OUString& aProgrammaticName, sal_Int32 nArgument ) override;
140 virtual OUString SAL_CALL getProgrammaticCategoryName( const OUString& aProgrammaticName ) override;
141 virtual OUString SAL_CALL getDisplayCategoryName( const OUString& aProgrammaticName ) override;
143 // XCompatibilityNames
144 virtual css::uno::Sequence< css::sheet::LocalizedName > SAL_CALL getCompatibilityNames( const OUString& aProgrammaticName ) override;
146 // XLocalizable
147 virtual void SAL_CALL setLocale( const css::lang::Locale& eLocale ) override;
148 virtual css::lang::Locale SAL_CALL getLocale() override;
150 // XServiceName
151 virtual OUString SAL_CALL getServiceName() override;
153 // XServiceInfo
154 virtual OUString SAL_CALL getImplementationName() override;
155 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
156 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
158 // methods from own interfaces start here
160 // XDateFunctions
161 virtual sal_Int32 SAL_CALL getDiffWeeks(
162 const css::uno::Reference< css::beans::XPropertySet >& xOptions,
163 sal_Int32 nEndDate, sal_Int32 nStartDate,
164 sal_Int32 nMode ) override;
166 virtual sal_Int32 SAL_CALL getDiffMonths(
167 const css::uno::Reference< css::beans::XPropertySet >& xOptions,
168 sal_Int32 nEndDate, sal_Int32 nStartDate,
169 sal_Int32 nMode ) override;
171 virtual sal_Int32 SAL_CALL getDiffYears(
172 const css::uno::Reference< css::beans::XPropertySet >& xOptions,
173 sal_Int32 nEndDate, sal_Int32 nStartDate,
174 sal_Int32 nMode ) override;
176 virtual sal_Int32 SAL_CALL getIsLeapYear(
177 const css::uno::Reference< css::beans::XPropertySet >& xOptions,
178 sal_Int32 nDate ) override;
180 virtual sal_Int32 SAL_CALL getDaysInMonth(
181 const css::uno::Reference< css::beans::XPropertySet >& xOptions,
182 sal_Int32 nDate ) override;
184 virtual sal_Int32 SAL_CALL getDaysInYear(
185 const css::uno::Reference< css::beans::XPropertySet >& xOptions,
186 sal_Int32 nDate ) override;
188 virtual sal_Int32 SAL_CALL getWeeksInYear(
189 const css::uno::Reference< css::beans::XPropertySet >& xOptions,
190 sal_Int32 nDate ) override;
192 // XMiscFunctions
193 virtual OUString SAL_CALL getRot13(
194 const OUString& aSrcText ) override;
197 #endif // INCLUDED_SCADDINS_SOURCE_DATEFUNC_DATEFUNC_HXX
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */