Bump version to 5.0-14
[LibreOffice.git] / scaddins / source / datefunc / datefunc.hxx
blob99c403df5208e446a62f47cb53068a366dac3389
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 <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>
38 class ScaList
40 private:
41 static const sal_uInt32 nStartSize;
42 static const sal_uInt32 nIncrSize;
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
49 void _Grow();
50 inline void Grow();
52 public:
53 ScaList();
54 virtual ~ScaList();
56 inline sal_uInt32 Count() const { return nCount; }
58 inline const void* GetObject( sal_uInt32 nIndex ) const
59 { return (nIndex < nCount) ? pData[ nIndex ] : NULL; }
61 inline void* First() { return nCount ? pData[ nCurr = 0 ] : NULL; }
62 inline void* Next() { return (nCurr + 1 < nCount) ? pData[ ++nCurr ] : NULL; }
64 inline void Append( void* pNew );
68 inline void ScaList::Grow()
70 if( nCount >= nSize )
71 _Grow();
74 inline void ScaList::Append( void* pNew )
76 Grow();
77 pData[ nCount++ ] = pNew;
81 class ScaStringList : protected ScaList
83 public:
84 inline ScaStringList() : ScaList() {};
85 virtual ~ScaStringList();
87 using ScaList::Count;
89 inline const OUString* Get( sal_uInt32 nIndex ) const;
91 inline OUString* First();
92 inline OUString* Next();
94 using ScaList::Append;
95 inline void Append( OUString* pNew );
96 inline void Append( const OUString& rNew );
100 inline const OUString* ScaStringList::Get( sal_uInt32 nIndex ) const
102 return static_cast< const OUString* >( ScaList::GetObject( nIndex ) );
105 inline OUString* ScaStringList::First()
107 return static_cast< OUString* >( ScaList::First() );
110 inline OUString* ScaStringList::Next()
112 return static_cast< OUString* >( ScaList::Next() );
115 inline void ScaStringList::Append( OUString* pNew )
117 ScaList::Append( pNew );
120 inline void ScaStringList::Append( const OUString& rNew )
122 ScaList::Append( new OUString( rNew ) );
126 class ScaResId : public ResId
128 public:
129 ScaResId( sal_uInt16 nResId, ResMgr& rResMgr );
133 class ScaResStringLoader : public Resource
135 private:
136 OUString aStr;
138 public:
139 inline ScaResStringLoader( sal_uInt16 nResId, sal_uInt16 nStrId, ResMgr& rResMgr );
141 inline const OUString& GetString() const { return aStr; }
146 inline ScaResStringLoader::ScaResStringLoader( sal_uInt16 nResId, sal_uInt16 nStrId, ResMgr& rResMgr ) :
147 Resource( ScaResId( nResId, rResMgr ) ),
148 aStr( ScaResId( nStrId, rResMgr ) )
150 FreeResource();
154 class ScaResStringArrLoader : public Resource
156 private:
157 ResStringArray aStrArray;
159 public:
160 inline ScaResStringArrLoader( sal_uInt16 nResId, sal_uInt16 nArrayId, ResMgr& rResMgr );
162 inline const ResStringArray& GetStringArray() const { return aStrArray; }
165 inline ScaResStringArrLoader::ScaResStringArrLoader( sal_uInt16 nResId, sal_uInt16 nArrayId, ResMgr& rResMgr ) :
166 Resource( ScaResId( nResId, rResMgr ) ),
167 aStrArray( ScaResId( nArrayId, rResMgr ) )
169 FreeResource();
173 class ScaResPublisher : public Resource
175 public:
176 inline ScaResPublisher( const ScaResId& rResId ) : Resource( rResId ) {}
178 inline bool IsAvailableRes( const ResId& rResId ) const
179 { return Resource::IsAvailableRes( rResId ); }
180 inline void FreeResource()
181 { Resource::FreeResource(); }
185 class ScaFuncRes : public Resource
187 public:
188 ScaFuncRes( ResId& rResId, ResMgr& rResMgr, sal_uInt16 nIndex, OUString& rRet );
192 enum ScaCategory
194 ScaCat_AddIn,
195 ScaCat_DateTime,
196 ScaCat_Text,
197 ScaCat_Finance,
198 ScaCat_Inf,
199 ScaCat_Math,
200 ScaCat_Tech
203 struct ScaFuncDataBase
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
215 class ScaFuncData
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
228 public:
229 ScaFuncData( const ScaFuncDataBase& rBaseData, ResMgr& rRscMgr );
230 virtual ~ScaFuncData();
232 inline sal_uInt16 GetUINameID() const { return nUINameID; }
233 inline sal_uInt16 GetDescrID() const { return nDescrID; }
234 inline ScaCategory GetCategory() const { return eCat; }
235 inline bool IsDouble() const { return bDouble; }
236 inline bool HasIntParam() const { return bWithOpt; }
238 sal_uInt16 GetStrIndex( sal_uInt16 nParam ) const;
239 inline bool Is( const OUString& rCompare ) const
240 { return aIntName == rCompare; }
242 inline const ScaStringList& GetCompNameList() const { return aCompList; }
246 class ScaFuncDataList : private ScaList
248 OUString aLastName;
249 sal_uInt32 nLast;
251 public:
252 ScaFuncDataList( ResMgr& rResMgr );
253 virtual ~ScaFuncDataList();
255 using ScaList::Count;
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();
262 using ScaList::Append;
263 inline void Append( ScaFuncData* pNew ) { ScaList::Append( pNew ); }
267 inline const ScaFuncData* ScaFuncDataList::Get( sal_uInt32 nIndex ) const
269 return static_cast< const ScaFuncData* >( ScaList::GetObject( nIndex ) );
272 inline ScaFuncData* ScaFuncDataList::First()
274 return static_cast< ScaFuncData* >( ScaList::First() );
277 inline ScaFuncData* ScaFuncDataList::Next()
279 return static_cast< ScaFuncData* >( ScaList::Next() );
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 >& );
288 // THE AddIn class for date functions
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 >
298 private:
299 ::com::sun::star::lang::Locale aFuncLoc;
300 ::com::sun::star::lang::Locale* pDefLocales;
301 ResMgr* pResMgr;
302 ScaFuncDataList* pFuncDataList;
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();
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 );
313 public:
314 ScaDateAddIn();
315 virtual ~ScaDateAddIn();
317 static OUString getImplementationName_Static();
318 static ::com::sun::star::uno::Sequence< OUString > getSupportedServiceNames_Static();
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;
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;
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;
336 // XServiceName
337 virtual OUString SAL_CALL getServiceName() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
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;
344 // methods from own interfaces start here
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;
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;
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;
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;
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;
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;
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;
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;
391 #endif // INCLUDED_SCADDINS_SOURCE_DATEFUNC_DATEFUNC_HXX
393 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */