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