Line data Source code
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 : #ifndef INCLUDED_SCADDINS_SOURCE_DATEFUNC_DATEFUNC_HXX
23 : #define INCLUDED_SCADDINS_SOURCE_DATEFUNC_DATEFUNC_HXX
24 :
25 : #include <string.h>
26 : #include <com/sun/star/lang/XServiceName.hpp>
27 : #include <com/sun/star/lang/XServiceInfo.hpp>
28 : #include <com/sun/star/lang/XMultiServiceFactory.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/implbase6.hxx>
34 : #include <tools/resid.hxx>
35 : #include <tools/rc.hxx>
36 : #include <tools/resary.hxx>
37 :
38 : class ScaList
39 : {
40 : private:
41 : static const sal_uInt32 nStartSize;
42 : static const sal_uInt32 nIncrSize;
43 :
44 : void** pData; // pointer array
45 : sal_uInt32 nSize; // array size
46 : sal_uInt32 nCount; // next index to be inserted at
47 : sal_uInt32 nCurr; // current pos for iterations
48 :
49 : void _Grow();
50 : inline void Grow();
51 :
52 : public:
53 : ScaList();
54 : virtual ~ScaList();
55 :
56 816 : inline sal_uInt32 Count() const { return nCount; }
57 :
58 1676 : inline const void* GetObject( sal_uInt32 nIndex ) const
59 1676 : { return (nIndex < nCount) ? pData[ nIndex ] : NULL; }
60 :
61 90 : inline void* First() { return nCount ? pData[ nCurr = 0 ] : NULL; }
62 240 : inline void* Next() { return (nCurr + 1 < nCount) ? pData[ ++nCurr ] : NULL; }
63 :
64 : inline void Append( void* pNew );
65 : };
66 :
67 :
68 456 : inline void ScaList::Grow()
69 : {
70 456 : if( nCount >= nSize )
71 0 : _Grow();
72 456 : }
73 :
74 456 : inline void ScaList::Append( void* pNew )
75 : {
76 456 : Grow();
77 456 : pData[ nCount++ ] = pNew;
78 456 : }
79 :
80 :
81 : class ScaStringList : protected ScaList
82 : {
83 : public:
84 152 : inline ScaStringList() : ScaList() {};
85 : virtual ~ScaStringList();
86 :
87 : using ScaList::Count;
88 :
89 : inline const OUString* Get( sal_uInt32 nIndex ) const;
90 :
91 : inline OUString* First();
92 : inline OUString* Next();
93 :
94 : using ScaList::Append;
95 : inline void Append( OUString* pNew );
96 : inline void Append( const OUString& rNew );
97 : };
98 :
99 :
100 48 : inline const OUString* ScaStringList::Get( sal_uInt32 nIndex ) const
101 : {
102 48 : return static_cast< const OUString* >( ScaList::GetObject( nIndex ) );
103 : }
104 :
105 80 : inline OUString* ScaStringList::First()
106 : {
107 80 : return static_cast< OUString* >( ScaList::First() );
108 : }
109 :
110 160 : inline OUString* ScaStringList::Next()
111 : {
112 160 : return static_cast< OUString* >( ScaList::Next() );
113 : }
114 :
115 : inline void ScaStringList::Append( OUString* pNew )
116 : {
117 : ScaList::Append( pNew );
118 : }
119 :
120 304 : inline void ScaStringList::Append( const OUString& rNew )
121 : {
122 304 : ScaList::Append( new OUString( rNew ) );
123 304 : }
124 :
125 :
126 : class ScaResId : public ResId
127 : {
128 : public:
129 : ScaResId( sal_uInt16 nResId, ResMgr& rResMgr );
130 : };
131 :
132 :
133 152 : class ScaResStringLoader : public Resource
134 : {
135 : private:
136 : OUString aStr;
137 :
138 : public:
139 : inline ScaResStringLoader( sal_uInt16 nResId, sal_uInt16 nStrId, ResMgr& rResMgr );
140 :
141 152 : inline const OUString& GetString() const { return aStr; }
142 :
143 : };
144 :
145 :
146 152 : inline ScaResStringLoader::ScaResStringLoader( sal_uInt16 nResId, sal_uInt16 nStrId, ResMgr& rResMgr ) :
147 : Resource( ScaResId( nResId, rResMgr ) ),
148 152 : aStr( ScaResId( nStrId, rResMgr ) )
149 : {
150 152 : FreeResource();
151 152 : }
152 :
153 :
154 152 : class ScaResStringArrLoader : public Resource
155 : {
156 : private:
157 : ResStringArray aStrArray;
158 :
159 : public:
160 : inline ScaResStringArrLoader( sal_uInt16 nResId, sal_uInt16 nArrayId, ResMgr& rResMgr );
161 :
162 152 : inline const ResStringArray& GetStringArray() const { return aStrArray; }
163 : };
164 :
165 152 : inline ScaResStringArrLoader::ScaResStringArrLoader( sal_uInt16 nResId, sal_uInt16 nArrayId, ResMgr& rResMgr ) :
166 : Resource( ScaResId( nResId, rResMgr ) ),
167 152 : aStrArray( ScaResId( nArrayId, rResMgr ) )
168 : {
169 152 : FreeResource();
170 152 : }
171 :
172 :
173 684 : class ScaResPublisher : public Resource
174 : {
175 : public:
176 684 : inline ScaResPublisher( const ScaResId& rResId ) : Resource( rResId ) {}
177 :
178 684 : inline bool IsAvailableRes( const ResId& rResId ) const
179 684 : { return Resource::IsAvailableRes( rResId ); }
180 684 : inline void FreeResource()
181 684 : { Resource::FreeResource(); }
182 : };
183 :
184 :
185 684 : class ScaFuncRes : public Resource
186 : {
187 : public:
188 : ScaFuncRes( ResId& rResId, ResMgr& rResMgr, sal_uInt16 nIndex, OUString& rRet );
189 : };
190 :
191 :
192 : enum ScaCategory
193 : {
194 : ScaCat_AddIn,
195 : ScaCat_DateTime,
196 : ScaCat_Text,
197 : ScaCat_Finance,
198 : ScaCat_Inf,
199 : ScaCat_Math,
200 : ScaCat_Tech
201 : };
202 :
203 : struct ScaFuncDataBase
204 : {
205 : const sal_Char* pIntName; // internal name (get***)
206 : sal_uInt16 nUINameID; // resource ID to UI name
207 : sal_uInt16 nDescrID; // resource ID to description, parameter names and ~ description
208 : sal_uInt16 nCompListID; // resource ID to list of valid names
209 : sal_uInt16 nParamCount; // number of named / described parameters
210 : ScaCategory eCat; // function category
211 : bool bDouble; // name already exist in Calc
212 : bool bWithOpt; // first parameter is internal
213 : };
214 :
215 : class ScaFuncData
216 : {
217 : private:
218 : OUString aIntName; // internal name (get***)
219 : sal_uInt16 nUINameID; // resource ID to UI name
220 : sal_uInt16 nDescrID; // leads also to parameter descriptions!
221 : sal_uInt16 nCompListID; // resource ID to list of valid names
222 : sal_uInt16 nParamCount; // num of parameters
223 : ScaStringList aCompList; // list of all valid names
224 : ScaCategory eCat; // function category
225 : bool bDouble; // name already exist in Calc
226 : bool bWithOpt; // first parameter is internal
227 :
228 : public:
229 : ScaFuncData( const ScaFuncDataBase& rBaseData, ResMgr& rRscMgr );
230 : virtual ~ScaFuncData();
231 :
232 152 : inline sal_uInt16 GetUINameID() const { return nUINameID; }
233 684 : inline sal_uInt16 GetDescrID() const { return nDescrID; }
234 152 : inline ScaCategory GetCategory() const { return eCat; }
235 152 : inline bool IsDouble() const { return bDouble; }
236 : inline bool HasIntParam() const { return bWithOpt; }
237 :
238 : sal_uInt16 GetStrIndex( sal_uInt16 nParam ) const;
239 792 : inline bool Is( const OUString& rCompare ) const
240 792 : { return aIntName == rCompare; }
241 :
242 24 : inline const ScaStringList& GetCompNameList() const { return aCompList; }
243 : };
244 :
245 :
246 : class ScaFuncDataList : private ScaList
247 : {
248 : OUString aLastName;
249 : sal_uInt32 nLast;
250 :
251 : public:
252 : ScaFuncDataList( ResMgr& rResMgr );
253 : virtual ~ScaFuncDataList();
254 :
255 : using ScaList::Count;
256 :
257 : inline const ScaFuncData* Get( sal_uInt32 nIndex ) const;
258 : const ScaFuncData* Get( const OUString& rProgrammaticName ) const;
259 : inline ScaFuncData* First();
260 : inline ScaFuncData* Next();
261 :
262 : using ScaList::Append;
263 152 : inline void Append( ScaFuncData* pNew ) { ScaList::Append( pNew ); }
264 : };
265 :
266 :
267 1628 : inline const ScaFuncData* ScaFuncDataList::Get( sal_uInt32 nIndex ) const
268 : {
269 1628 : return static_cast< const ScaFuncData* >( ScaList::GetObject( nIndex ) );
270 : }
271 :
272 10 : inline ScaFuncData* ScaFuncDataList::First()
273 : {
274 10 : return static_cast< ScaFuncData* >( ScaList::First() );
275 : }
276 :
277 80 : inline ScaFuncData* ScaFuncDataList::Next()
278 : {
279 80 : return static_cast< ScaFuncData* >( ScaList::Next() );
280 : }
281 :
282 :
283 :
284 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL DateFunctionAddIn_CreateInstance(
285 : const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& );
286 :
287 :
288 : // THE AddIn class for date functions
289 :
290 : class ScaDateAddIn : public ::cppu::WeakImplHelper6<
291 : ::com::sun::star::sheet::XAddIn,
292 : ::com::sun::star::sheet::XCompatibilityNames,
293 : ::com::sun::star::sheet::addin::XDateFunctions,
294 : ::com::sun::star::sheet::addin::XMiscFunctions,
295 : ::com::sun::star::lang::XServiceName,
296 : ::com::sun::star::lang::XServiceInfo >
297 : {
298 : private:
299 : ::com::sun::star::lang::Locale aFuncLoc;
300 : ::com::sun::star::lang::Locale* pDefLocales;
301 : ResMgr* pResMgr;
302 : ScaFuncDataList* pFuncDataList;
303 :
304 :
305 : void InitDefLocales();
306 : const ::com::sun::star::lang::Locale& GetLocale( sal_uInt32 nIndex );
307 : ResMgr& GetResMgr() throw( ::com::sun::star::uno::RuntimeException );
308 : void InitData();
309 :
310 : OUString GetDisplFuncStr( sal_uInt16 nResId ) throw( ::com::sun::star::uno::RuntimeException );
311 : OUString GetFuncDescrStr( sal_uInt16 nResId, sal_uInt16 nStrIndex ) throw( ::com::sun::star::uno::RuntimeException );
312 :
313 : public:
314 : ScaDateAddIn();
315 : virtual ~ScaDateAddIn();
316 :
317 : static OUString getImplementationName_Static();
318 : static ::com::sun::star::uno::Sequence< OUString > getSupportedServiceNames_Static();
319 :
320 : // XAddIn
321 : virtual OUString SAL_CALL getProgrammaticFuntionName( const OUString& aDisplayName ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
322 : virtual OUString SAL_CALL getDisplayFunctionName( const OUString& aProgrammaticName ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
323 : virtual OUString SAL_CALL getFunctionDescription( const OUString& aProgrammaticName ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
324 : virtual OUString SAL_CALL getDisplayArgumentName( const OUString& aProgrammaticName, sal_Int32 nArgument ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
325 : virtual OUString SAL_CALL getArgumentDescription( const OUString& aProgrammaticName, sal_Int32 nArgument ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
326 : virtual OUString SAL_CALL getProgrammaticCategoryName( const OUString& aProgrammaticName ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
327 : virtual OUString SAL_CALL getDisplayCategoryName( const OUString& aProgrammaticName ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
328 :
329 : // XCompatibilityNames
330 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::LocalizedName > SAL_CALL getCompatibilityNames( const OUString& aProgrammaticName ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
331 :
332 : // XLocalizable
333 : virtual void SAL_CALL setLocale( const ::com::sun::star::lang::Locale& eLocale ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
334 : virtual ::com::sun::star::lang::Locale SAL_CALL getLocale() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
335 :
336 : // XServiceName
337 : virtual OUString SAL_CALL getServiceName() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
338 :
339 : // XServiceInfo
340 : virtual OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
341 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
342 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
343 :
344 : // methods from own interfaces start here
345 :
346 : // XDateFunctions
347 : virtual sal_Int32 SAL_CALL getDiffWeeks(
348 : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xOptions,
349 : sal_Int32 nEndDate, sal_Int32 nStartDate,
350 : sal_Int32 nMode )
351 : throw( ::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException, std::exception ) SAL_OVERRIDE;
352 :
353 : virtual sal_Int32 SAL_CALL getDiffMonths(
354 : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xOptions,
355 : sal_Int32 nEndDate, sal_Int32 nStartDate,
356 : sal_Int32 nMode )
357 : throw( ::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException, std::exception ) SAL_OVERRIDE;
358 :
359 : virtual sal_Int32 SAL_CALL getDiffYears(
360 : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xOptions,
361 : sal_Int32 nEndDate, sal_Int32 nStartDate,
362 : sal_Int32 nMode )
363 : throw( ::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException, std::exception ) SAL_OVERRIDE;
364 :
365 : virtual sal_Int32 SAL_CALL getIsLeapYear(
366 : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xOptions,
367 : sal_Int32 nDate )
368 : throw( ::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException, std::exception ) SAL_OVERRIDE;
369 :
370 : virtual sal_Int32 SAL_CALL getDaysInMonth(
371 : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xOptions,
372 : sal_Int32 nDate )
373 : throw( ::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException, std::exception ) SAL_OVERRIDE;
374 :
375 : virtual sal_Int32 SAL_CALL getDaysInYear(
376 : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xOptions,
377 : sal_Int32 nDate )
378 : throw( ::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException, std::exception ) SAL_OVERRIDE;
379 :
380 : virtual sal_Int32 SAL_CALL getWeeksInYear(
381 : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xOptions,
382 : sal_Int32 nDate )
383 : throw( ::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException, std::exception ) SAL_OVERRIDE;
384 :
385 : // XMiscFunctions
386 : virtual OUString SAL_CALL getRot13(
387 : const OUString& aSrcText )
388 : throw( ::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException, std::exception ) SAL_OVERRIDE;
389 : };
390 :
391 : #endif // INCLUDED_SCADDINS_SOURCE_DATEFUNC_DATEFUNC_HXX
392 :
393 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|