Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/scaddins/source/datefunc/datefunc.hxx
Line
Count
Source
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>
32
#include <cppuhelper/implbase.hxx>
33
#include <unotools/resmgr.hxx>
34
35
enum class ScaCategory
36
{
37
    DateTime,
38
    Text,
39
    Finance,
40
    Inf,
41
    Math,
42
    Tech
43
};
44
45
struct ScaFuncDataBase
46
{
47
    const char*                 pIntName;           // internal name (get***)
48
    TranslateId                 pUINameID;          // resource ID to UI name
49
    const TranslateId*          pDescrID;           // resource ID to description, parameter names and ~ description
50
    const char**                pCompListID;        // list of valid names
51
    sal_uInt16                  nParamCount;        // number of named / described parameters
52
    ScaCategory                 eCat;               // function category
53
    bool                        bDouble;            // name already exist in Calc
54
    bool                        bWithOpt;           // first parameter is internal
55
};
56
57
class ScaFuncData final
58
{
59
private:
60
    OUString                    aIntName;           // internal name (get***)
61
    TranslateId                 pUINameID;          // resource ID to UI name
62
    const TranslateId*          pDescrID;           // leads also to parameter descriptions!
63
    sal_uInt16                  nParamCount;        // num of parameters
64
    std::vector<OUString>       aCompList;          // list of all valid names
65
    ScaCategory                 eCat;               // function category
66
    bool                    bDouble;            // name already exist in Calc
67
    bool                    bWithOpt;           // first parameter is internal
68
69
public:
70
                                ScaFuncData(const ScaFuncDataBase& rBaseData);
71
72
80
    const TranslateId &  GetUINameID() const     { return pUINameID; }
73
180
    const TranslateId*    GetDescrID() const      { return pDescrID; }
74
40
    ScaCategory          GetCategory() const     { return eCat; }
75
80
    bool                 IsDouble() const        { return bDouble; }
76
77
    sal_uInt16                  GetStrIndex( sal_uInt16 nParam ) const;
78
    bool                 Is( std::u16string_view rCompare ) const
79
1.27k
                                                    { return aIntName == rCompare; }
80
81
16
    const std::vector<OUString>& GetCompNameList() const { return aCompList; }
82
};
83
84
typedef std::vector<ScaFuncData> ScaFuncDataList;
85
86
// Predicate for use with std::find_if
87
struct FindScaFuncData
88
{
89
    const OUString& m_rId;
90
316
    explicit FindScaFuncData( const OUString& rId ) : m_rId(rId) {}
91
1.27k
    bool operator() ( ScaFuncData const & rCandidate ) const { return rCandidate.Is(m_rId); }
92
};
93
94
95
// THE AddIn class for date functions
96
97
class ScaDateAddIn : public ::cppu::WeakImplHelper<
98
                                css::sheet::XAddIn,
99
                                css::sheet::XCompatibilityNames,
100
                                css::sheet::addin::XDateFunctions,
101
                                css::sheet::addin::XMiscFunctions,
102
                                css::lang::XServiceName,
103
                                css::lang::XServiceInfo >
104
{
105
private:
106
    css::lang::Locale                          aFuncLoc;
107
    std::unique_ptr< css::lang::Locale[] >     pDefLocales;
108
    std::locale                                aResLocale;
109
    std::unique_ptr< ScaFuncDataList >         pFuncDataList;
110
111
112
    void                        InitDefLocales();
113
    const css::lang::Locale& GetLocale( sal_uInt32 nIndex );
114
    void                        InitData();
115
116
    /// @throws css::uno::RuntimeException
117
    OUString                    GetFuncDescrStr(const TranslateId* pResId, sal_uInt16 nStrIndex);
118
119
public:
120
                                ScaDateAddIn();
121
122
    OUString ScaResId(TranslateId aId);
123
124
                                // XAddIn
125
    virtual OUString SAL_CALL getProgrammaticFuntionName( const OUString& aDisplayName ) override;
126
    virtual OUString SAL_CALL getDisplayFunctionName( const OUString& aProgrammaticName ) override;
127
    virtual OUString SAL_CALL getFunctionDescription( const OUString& aProgrammaticName ) override;
128
    virtual OUString SAL_CALL getDisplayArgumentName( const OUString& aProgrammaticName, sal_Int32 nArgument ) override;
129
    virtual OUString SAL_CALL getArgumentDescription( const OUString& aProgrammaticName, sal_Int32 nArgument ) override;
130
    virtual OUString SAL_CALL getProgrammaticCategoryName( const OUString& aProgrammaticName ) override;
131
    virtual OUString SAL_CALL getDisplayCategoryName( const OUString& aProgrammaticName ) override;
132
133
                                // XCompatibilityNames
134
    virtual css::uno::Sequence< css::sheet::LocalizedName > SAL_CALL getCompatibilityNames( const OUString& aProgrammaticName ) override;
135
136
                                // XLocalizable
137
    virtual void SAL_CALL       setLocale( const css::lang::Locale& eLocale ) override;
138
    virtual css::lang::Locale SAL_CALL getLocale() override;
139
140
                                // XServiceName
141
    virtual OUString SAL_CALL getServiceName() override;
142
143
                                // XServiceInfo
144
    virtual OUString SAL_CALL getImplementationName() override;
145
    virtual sal_Bool SAL_CALL   supportsService( const OUString& ServiceName ) override;
146
    virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
147
148
    //  methods from own interfaces start here
149
150
                                // XDateFunctions
151
    virtual sal_Int32 SAL_CALL  getDiffWeeks(
152
                                    const css::uno::Reference< css::beans::XPropertySet >& xOptions,
153
                                    sal_Int32 nEndDate, sal_Int32 nStartDate,
154
                                    sal_Int32 nMode ) override;
155
156
    virtual sal_Int32 SAL_CALL  getDiffMonths(
157
                                    const css::uno::Reference< css::beans::XPropertySet >& xOptions,
158
                                    sal_Int32 nEndDate, sal_Int32 nStartDate,
159
                                    sal_Int32 nMode ) override;
160
161
    virtual sal_Int32 SAL_CALL  getDiffYears(
162
                                    const css::uno::Reference< css::beans::XPropertySet >& xOptions,
163
                                    sal_Int32 nEndDate, sal_Int32 nStartDate,
164
                                    sal_Int32 nMode ) override;
165
166
    virtual sal_Int32 SAL_CALL  getIsLeapYear(
167
                                    const css::uno::Reference< css::beans::XPropertySet >& xOptions,
168
                                    sal_Int32 nDate ) override;
169
170
    virtual sal_Int32 SAL_CALL  getDaysInMonth(
171
                                    const css::uno::Reference< css::beans::XPropertySet >& xOptions,
172
                                    sal_Int32 nDate ) override;
173
174
    virtual sal_Int32 SAL_CALL  getDaysInYear(
175
                                    const css::uno::Reference< css::beans::XPropertySet >& xOptions,
176
                                    sal_Int32 nDate ) override;
177
178
    virtual sal_Int32 SAL_CALL  getWeeksInYear(
179
                                    const css::uno::Reference< css::beans::XPropertySet >& xOptions,
180
                                    sal_Int32 nDate ) override;
181
182
                                // XMiscFunctions
183
    virtual OUString SAL_CALL getRot13(
184
                                    const OUString& aSrcText ) override;
185
};
186
187
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */