LibreOffice Module scaddins (master) 1
datefunc.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20// date functions add in
21
22#pragma once
23
24#include <vector>
25#include <memory>
26#include <com/sun/star/lang/XServiceName.hpp>
27#include <com/sun/star/lang/XServiceInfo.hpp>
28#include <com/sun/star/sheet/XAddIn.hpp>
29#include <com/sun/star/sheet/XCompatibilityNames.hpp>
30#include <com/sun/star/sheet/addin/XDateFunctions.hpp>
31#include <com/sun/star/sheet/addin/XMiscFunctions.hpp>
33#include <unotools/resmgr.hxx>
34
35namespace com::sun::star::lang { class XMultiServiceFactory; }
36
37enum class ScaCategory
38{
40 Text,
41 Finance,
42 Inf,
43 Math,
44 Tech
45};
46
48{
49 const char* pIntName; // internal name (get***)
50 TranslateId pUINameID; // resource ID to UI name
51 const TranslateId* pDescrID; // resource ID to description, parameter names and ~ description
52 const char** pCompListID; // list of valid names
53 sal_uInt16 nParamCount; // number of named / described parameters
54 ScaCategory eCat; // function category
55 bool bDouble; // name already exist in Calc
56 bool bWithOpt; // first parameter is internal
57};
58
59class ScaFuncData final
60{
61private:
62 OUString aIntName; // internal name (get***)
63 TranslateId pUINameID; // resource ID to UI name
64 const TranslateId* pDescrID; // leads also to parameter descriptions!
65 sal_uInt16 nParamCount; // num of parameters
66 std::vector<OUString> aCompList; // list of all valid names
67 ScaCategory eCat; // function category
68 bool bDouble; // name already exist in Calc
69 bool bWithOpt; // first parameter is internal
70
71public:
72 ScaFuncData(const ScaFuncDataBase& rBaseData);
73
74 const TranslateId & GetUINameID() const { return pUINameID; }
75 const TranslateId* GetDescrID() const { return pDescrID; }
76 ScaCategory GetCategory() const { return eCat; }
77 bool IsDouble() const { return bDouble; }
78
79 sal_uInt16 GetStrIndex( sal_uInt16 nParam ) const;
80 bool Is( std::u16string_view rCompare ) const
81 { return aIntName == rCompare; }
82
83 const std::vector<OUString>& GetCompNameList() const { return aCompList; }
84};
85
86typedef std::vector<ScaFuncData> ScaFuncDataList;
87
88// Predicate for use with std::find_if
90{
91 const OUString& m_rId;
92 explicit FindScaFuncData( const OUString& rId ) : m_rId(rId) {}
93 bool operator() ( ScaFuncData const & rCandidate ) const { return rCandidate.Is(m_rId); }
94};
95
96
97// THE AddIn class for date functions
98
99class ScaDateAddIn : public ::cppu::WeakImplHelper<
100 css::sheet::XAddIn,
101 css::sheet::XCompatibilityNames,
102 css::sheet::addin::XDateFunctions,
103 css::sheet::addin::XMiscFunctions,
104 css::lang::XServiceName,
105 css::lang::XServiceInfo >
106{
107private:
108 css::lang::Locale aFuncLoc;
109 std::unique_ptr< css::lang::Locale[] > pDefLocales;
110 std::locale aResLocale;
111 std::unique_ptr< ScaFuncDataList > pFuncDataList;
112
113
114 void InitDefLocales();
115 const css::lang::Locale& GetLocale( sal_uInt32 nIndex );
116 void InitData();
117
119 OUString GetFuncDescrStr(const TranslateId* pResId, sal_uInt16 nStrIndex);
120
121public:
122 ScaDateAddIn();
123
124 OUString ScaResId(TranslateId aId);
125
126 // XAddIn
127 virtual OUString SAL_CALL getProgrammaticFuntionName( const OUString& aDisplayName ) override;
128 virtual OUString SAL_CALL getDisplayFunctionName( const OUString& aProgrammaticName ) override;
129 virtual OUString SAL_CALL getFunctionDescription( const OUString& aProgrammaticName ) override;
130 virtual OUString SAL_CALL getDisplayArgumentName( const OUString& aProgrammaticName, sal_Int32 nArgument ) override;
131 virtual OUString SAL_CALL getArgumentDescription( const OUString& aProgrammaticName, sal_Int32 nArgument ) override;
132 virtual OUString SAL_CALL getProgrammaticCategoryName( const OUString& aProgrammaticName ) override;
133 virtual OUString SAL_CALL getDisplayCategoryName( const OUString& aProgrammaticName ) override;
134
135 // XCompatibilityNames
136 virtual css::uno::Sequence< css::sheet::LocalizedName > SAL_CALL getCompatibilityNames( const OUString& aProgrammaticName ) override;
137
138 // XLocalizable
139 virtual void SAL_CALL setLocale( const css::lang::Locale& eLocale ) override;
140 virtual css::lang::Locale SAL_CALL getLocale() override;
141
142 // XServiceName
143 virtual OUString SAL_CALL getServiceName() override;
144
145 // XServiceInfo
146 virtual OUString SAL_CALL getImplementationName() override;
147 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
148 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
149
150 // methods from own interfaces start here
151
152 // XDateFunctions
153 virtual sal_Int32 SAL_CALL getDiffWeeks(
154 const css::uno::Reference< css::beans::XPropertySet >& xOptions,
155 sal_Int32 nEndDate, sal_Int32 nStartDate,
156 sal_Int32 nMode ) override;
157
158 virtual sal_Int32 SAL_CALL getDiffMonths(
159 const css::uno::Reference< css::beans::XPropertySet >& xOptions,
160 sal_Int32 nEndDate, sal_Int32 nStartDate,
161 sal_Int32 nMode ) override;
162
163 virtual sal_Int32 SAL_CALL getDiffYears(
164 const css::uno::Reference< css::beans::XPropertySet >& xOptions,
165 sal_Int32 nEndDate, sal_Int32 nStartDate,
166 sal_Int32 nMode ) override;
167
168 virtual sal_Int32 SAL_CALL getIsLeapYear(
169 const css::uno::Reference< css::beans::XPropertySet >& xOptions,
170 sal_Int32 nDate ) override;
171
172 virtual sal_Int32 SAL_CALL getDaysInMonth(
173 const css::uno::Reference< css::beans::XPropertySet >& xOptions,
174 sal_Int32 nDate ) override;
175
176 virtual sal_Int32 SAL_CALL getDaysInYear(
177 const css::uno::Reference< css::beans::XPropertySet >& xOptions,
178 sal_Int32 nDate ) override;
179
180 virtual sal_Int32 SAL_CALL getWeeksInYear(
181 const css::uno::Reference< css::beans::XPropertySet >& xOptions,
182 sal_Int32 nDate ) override;
183
184 // XMiscFunctions
185 virtual OUString SAL_CALL getRot13(
186 const OUString& aSrcText ) override;
187};
188
189/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: datefunc.cxx:158
virtual void SAL_CALL setLocale(const css::lang::Locale &eLocale) override
Definition: datefunc.cxx:169
std::unique_ptr< ScaFuncDataList > pFuncDataList
Definition: datefunc.hxx:111
OUString GetFuncDescrStr(const TranslateId *pResId, sal_uInt16 nStrIndex)
Definition: datefunc.cxx:140
const css::lang::Locale & GetLocale(sal_uInt32 nIndex)
Definition: datefunc.cxx:118
virtual sal_Int32 SAL_CALL getDaysInMonth(const css::uno::Reference< css::beans::XPropertySet > &xOptions, sal_Int32 nDate) override
Get the Number of Days in the month for a date.
Definition: datefunc.cxx:587
virtual sal_Int32 SAL_CALL getDiffYears(const css::uno::Reference< css::beans::XPropertySet > &xOptions, sal_Int32 nEndDate, sal_Int32 nStartDate, sal_Int32 nMode) override
Get Year difference between 2 dates.
Definition: datefunc.cxx:544
virtual sal_Int32 SAL_CALL getWeeksInYear(const css::uno::Reference< css::beans::XPropertySet > &xOptions, sal_Int32 nDate) override
Get number of weeks in the year for a date.
Definition: datefunc.cxx:631
virtual OUString SAL_CALL getFunctionDescription(const OUString &aProgrammaticName) override
Definition: datefunc.cxx:207
virtual css::uno::Sequence< css::sheet::LocalizedName > SAL_CALL getCompatibilityNames(const OUString &aProgrammaticName) override
Definition: datefunc.cxx:289
virtual sal_Int32 SAL_CALL getDiffMonths(const css::uno::Reference< css::beans::XPropertySet > &xOptions, sal_Int32 nEndDate, sal_Int32 nStartDate, sal_Int32 nMode) override
Get month difference between 2 dates =Month(start, end, mode) Function for StarCalc.
Definition: datefunc.cxx:496
virtual OUString SAL_CALL getProgrammaticFuntionName(const OUString &aDisplayName) override
Definition: datefunc.cxx:180
css::lang::Locale aFuncLoc
Definition: datefunc.hxx:108
virtual sal_Int32 SAL_CALL getIsLeapYear(const css::uno::Reference< css::beans::XPropertySet > &xOptions, sal_Int32 nDate) override
Check if a Date is in a leap year in the Gregorian calendar.
Definition: datefunc.cxx:571
virtual sal_Int32 SAL_CALL getDiffWeeks(const css::uno::Reference< css::beans::XPropertySet > &xOptions, sal_Int32 nEndDate, sal_Int32 nStartDate, sal_Int32 nMode) override
Get week difference between 2 dates.
Definition: datefunc.cxx:465
std::locale aResLocale
Definition: datefunc.hxx:110
virtual OUString SAL_CALL getDisplayArgumentName(const OUString &aProgrammaticName, sal_Int32 nArgument) override
Definition: datefunc.cxx:219
void InitDefLocales()
Definition: datefunc.cxx:107
virtual OUString SAL_CALL getDisplayCategoryName(const OUString &aProgrammaticName) override
Definition: datefunc.cxx:282
virtual OUString SAL_CALL getServiceName() override
Definition: datefunc.cxx:146
virtual css::lang::Locale SAL_CALL getLocale() override
Definition: datefunc.cxx:175
virtual OUString SAL_CALL getArgumentDescription(const OUString &aProgrammaticName, sal_Int32 nArgument) override
Definition: datefunc.cxx:238
virtual OUString SAL_CALL getRot13(const OUString &aSrcText) override
Encrypt or decrypt a string using ROT13 algorithm.
Definition: datefunc.cxx:660
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: datefunc.cxx:163
void InitData()
Definition: datefunc.cxx:126
std::unique_ptr< css::lang::Locale[] > pDefLocales
Definition: datefunc.hxx:109
OUString ScaResId(TranslateId aId)
Definition: datefunc.cxx:683
virtual OUString SAL_CALL getDisplayFunctionName(const OUString &aProgrammaticName) override
Definition: datefunc.cxx:187
virtual OUString SAL_CALL getImplementationName() override
Definition: datefunc.cxx:153
virtual OUString SAL_CALL getProgrammaticCategoryName(const OUString &aProgrammaticName) override
Definition: datefunc.cxx:257
virtual sal_Int32 SAL_CALL getDaysInYear(const css::uno::Reference< css::beans::XPropertySet > &xOptions, sal_Int32 nDate) override
Get number of days in the year of a date specified.
Definition: datefunc.cxx:603
const TranslateId & GetUINameID() const
Definition: datefunc.hxx:74
ScaCategory eCat
Definition: datefunc.hxx:67
const TranslateId * pDescrID
Definition: datefunc.hxx:64
ScaFuncData(const ScaFuncDataBase &rBaseData)
Definition: datefunc.cxx:62
const std::vector< OUString > & GetCompNameList() const
Definition: datefunc.hxx:83
sal_uInt16 nParamCount
Definition: datefunc.hxx:65
bool IsDouble() const
Definition: datefunc.hxx:77
const TranslateId * GetDescrID() const
Definition: datefunc.hxx:75
bool bWithOpt
Definition: datefunc.hxx:69
ScaCategory GetCategory() const
Definition: datefunc.hxx:76
TranslateId pUINameID
Definition: datefunc.hxx:63
OUString aIntName
Definition: datefunc.hxx:62
bool bDouble
Definition: datefunc.hxx:68
bool Is(std::u16string_view rCompare) const
Definition: datefunc.hxx:80
std::vector< OUString > aCompList
Definition: datefunc.hxx:66
sal_uInt16 GetStrIndex(sal_uInt16 nParam) const
Definition: datefunc.cxx:75
std::vector< ScaFuncData > ScaFuncDataList
Definition: datefunc.hxx:86
ScaCategory
Definition: datefunc.hxx:38
FindScaFuncData(const OUString &rId)
Definition: datefunc.hxx:92
bool operator()(ScaFuncData const &rCandidate) const
Definition: datefunc.hxx:93
const OUString & m_rId
Definition: datefunc.hxx:91
const TranslateId * pDescrID
Definition: datefunc.hxx:51
const char * pIntName
Definition: datefunc.hxx:49
const char ** pCompListID
Definition: datefunc.hxx:52
ScaCategory eCat
Definition: datefunc.hxx:54
TranslateId pUINameID
Definition: datefunc.hxx:50
sal_uInt16 nParamCount
Definition: datefunc.hxx:53
unsigned char sal_Bool