1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: datefunc.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 //------------------------------------------------------------------
33 // date functions add in
35 //------------------------------------------------------------------
37 #ifndef _SCA_DATEFUNC_HXX
38 #define _SCA_DATEFUNC_HXX
41 #include <com/sun/star/lang/XServiceName.hpp>
42 #include <com/sun/star/lang/XServiceInfo.hpp>
43 #include <com/sun/star/sheet/XAddIn.hpp>
44 #include <com/sun/star/sheet/XCompatibilityNames.hpp>
45 #include <com/sun/star/sheet/addin/XDateFunctions.hpp>
46 #include <com/sun/star/sheet/addin/XMiscFunctions.hpp>
47 #include <cppuhelper/implbase6.hxx> // helper for implementations
48 #include <tools/resid.hxx>
49 #include <tools/rc.hxx>
50 #include <tools/resary.hxx>
52 //------------------------------------------------------------------
57 static const sal_uInt32 nStartSize
;
58 static const sal_uInt32 nIncrSize
;
60 void** pData
; // pointer array
61 sal_uInt32 nSize
; // array size
62 sal_uInt32 nCount
; // next index to be inserted at
63 sal_uInt32 nCurr
; // current pos for iterations
72 inline sal_uInt32
Count() const { return nCount
; }
74 inline const void* GetObject( sal_uInt32 nIndex
) const
75 { return (nIndex
< nCount
) ? pData
[ nIndex
] : NULL
; }
77 inline void* First() { return nCount
? pData
[ nCurr
= 0 ] : NULL
; }
78 inline void* Next() { return (nCurr
+ 1 < nCount
) ? pData
[ ++nCurr
] : NULL
; }
80 inline void Append( void* pNew
);
81 void Insert( void* pNew
, sal_uInt32 nIndex
);
85 inline void ScaList::Grow()
91 inline void ScaList::Append( void* pNew
)
94 pData
[ nCount
++ ] = pNew
;
98 //------------------------------------------------------------------
100 class ScaStringList
: protected ScaList
103 inline ScaStringList() : ScaList() {};
104 virtual ~ScaStringList();
106 using ScaList::Count
;
108 inline const ::rtl::OUString
* Get( sal_uInt32 nIndex
) const;
110 inline ::rtl::OUString
* First();
111 inline ::rtl::OUString
* Next();
113 using ScaList::Append
;
114 inline void Append( ::rtl::OUString
* pNew
);
115 inline void Append( const ::rtl::OUString
& rNew
);
119 inline const ::rtl::OUString
* ScaStringList::Get( sal_uInt32 nIndex
) const
121 return static_cast< const ::rtl::OUString
* >( ScaList::GetObject( nIndex
) );
124 inline ::rtl::OUString
* ScaStringList::First()
126 return static_cast< ::rtl::OUString
* >( ScaList::First() );
129 inline ::rtl::OUString
* ScaStringList::Next()
131 return static_cast< ::rtl::OUString
* >( ScaList::Next() );
134 inline void ScaStringList::Append( ::rtl::OUString
* pNew
)
136 ScaList::Append( pNew
);
139 inline void ScaStringList::Append( const ::rtl::OUString
& rNew
)
141 ScaList::Append( new ::rtl::OUString( rNew
) );
145 //------------------------------------------------------------------
147 class ScaResId
: public ResId
150 ScaResId( sal_uInt16 nResId
, ResMgr
& rResMgr
);
154 //------------------------------------------------------------------
156 class ScaResStringLoader
: public Resource
162 inline ScaResStringLoader( sal_uInt16 nResId
, sal_uInt16 nStrId
, ResMgr
& rResMgr
);
164 inline const String
& GetString() const { return aStr
; }
169 inline ScaResStringLoader::ScaResStringLoader( sal_uInt16 nResId
, sal_uInt16 nStrId
, ResMgr
& rResMgr
) :
170 Resource( ScaResId( nResId
, rResMgr
) ),
171 aStr( ScaResId( nStrId
, rResMgr
) )
177 //------------------------------------------------------------------
179 class ScaResStringArrLoader
: public Resource
182 ResStringArray aStrArray
;
185 inline ScaResStringArrLoader( sal_uInt16 nResId
, sal_uInt16 nArrayId
, ResMgr
& rResMgr
);
187 inline const ResStringArray
& GetStringArray() const { return aStrArray
; }
192 inline ScaResStringArrLoader::ScaResStringArrLoader( sal_uInt16 nResId
, sal_uInt16 nArrayId
, ResMgr
& rResMgr
) :
193 Resource( ScaResId( nResId
, rResMgr
) ),
194 aStrArray( ScaResId( nArrayId
, rResMgr
) )
200 //------------------------------------------------------------------
202 class ScaResPublisher
: public Resource
205 inline ScaResPublisher( const ScaResId
& rResId
) : Resource( rResId
) {}
207 inline sal_Bool
IsAvailableRes( const ResId
& rResId
) const
208 { return Resource::IsAvailableRes( rResId
); }
209 inline void FreeResource()
210 { Resource::FreeResource(); }
214 //------------------------------------------------------------------
216 class ScaFuncRes
: public Resource
219 ScaFuncRes( ResId
& rResId
, ResMgr
& rResMgr
, sal_uInt16 nIndex
, ::rtl::OUString
& rRet
);
223 //------------------------------------------------------------------
236 struct ScaFuncDataBase
238 const sal_Char
* pIntName
; // internal name (get***)
239 sal_uInt16 nUINameID
; // resource ID to UI name
240 sal_uInt16 nDescrID
; // resource ID to description, parameter names and ~ description
241 sal_uInt16 nCompListID
; // resource ID to list of valid names
242 sal_uInt16 nParamCount
; // number of named / described parameters
243 ScaCategory eCat
; // function category
244 sal_Bool bDouble
; // name already exist in Calc
245 sal_Bool bWithOpt
; // first parameter is internal
251 ::rtl::OUString aIntName
; // internal name (get***)
252 sal_uInt16 nUINameID
; // resource ID to UI name
253 sal_uInt16 nDescrID
; // leads also to parameter descriptions!
254 sal_uInt16 nCompListID
; // resource ID to list of valid names
255 sal_uInt16 nParamCount
; // num of parameters
256 ScaStringList aCompList
; // list of all valid names
257 ScaCategory eCat
; // function category
258 sal_Bool bDouble
; // name already exist in Calc
259 sal_Bool bWithOpt
; // first parameter is internal
262 ScaFuncData( const ScaFuncDataBase
& rBaseData
, ResMgr
& rRscMgr
);
263 virtual ~ScaFuncData();
265 inline sal_uInt16
GetUINameID() const { return nUINameID
; }
266 inline sal_uInt16
GetDescrID() const { return nDescrID
; }
267 inline ScaCategory
GetCategory() const { return eCat
; }
268 inline sal_Bool
IsDouble() const { return bDouble
; }
269 inline sal_Bool
HasIntParam() const { return bWithOpt
; }
271 sal_uInt16
GetStrIndex( sal_uInt16 nParam
) const;
272 inline sal_Bool
Is( const ::rtl::OUString
& rCompare
) const
273 { return aIntName
== rCompare
; }
275 inline const ScaStringList
& GetCompNameList() const { return aCompList
; }
279 //------------------------------------------------------------------
281 class ScaFuncDataList
: private ScaList
283 ::rtl::OUString aLastName
;
287 ScaFuncDataList( ResMgr
& rResMgr
);
288 virtual ~ScaFuncDataList();
290 using ScaList::Count
;
292 inline const ScaFuncData
* Get( sal_uInt32 nIndex
) const;
293 const ScaFuncData
* Get( const ::rtl::OUString
& rProgrammaticName
) const;
294 inline ScaFuncData
* First();
295 inline ScaFuncData
* Next();
297 using ScaList::Append
;
298 inline void Append( ScaFuncData
* pNew
) { ScaList::Append( pNew
); }
302 inline const ScaFuncData
* ScaFuncDataList::Get( sal_uInt32 nIndex
) const
304 return static_cast< const ScaFuncData
* >( ScaList::GetObject( nIndex
) );
307 inline ScaFuncData
* ScaFuncDataList::First()
309 return static_cast< ScaFuncData
* >( ScaList::First() );
312 inline ScaFuncData
* ScaFuncDataList::Next()
314 return static_cast< ScaFuncData
* >( ScaList::Next() );
318 //------------------------------------------------------------------
319 //------------------------------------------------------------------
321 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> SAL_CALL
DateFunctionAddIn_CreateInstance(
322 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& );
325 // THE AddIn class for date functions
327 class ScaDateAddIn
: public ::cppu::WeakImplHelper6
<
328 ::com::sun::star::sheet::XAddIn
,
329 ::com::sun::star::sheet::XCompatibilityNames
,
330 ::com::sun::star::sheet::addin::XDateFunctions
,
331 ::com::sun::star::sheet::addin::XMiscFunctions
,
332 ::com::sun::star::lang::XServiceName
,
333 ::com::sun::star::lang::XServiceInfo
>
336 ::com::sun::star::lang::Locale aFuncLoc
;
337 ::com::sun::star::lang::Locale
* pDefLocales
;
339 ScaFuncDataList
* pFuncDataList
;
342 void InitDefLocales();
343 const ::com::sun::star::lang::Locale
& GetLocale( sal_uInt32 nIndex
);
344 ResMgr
& GetResMgr() throw( ::com::sun::star::uno::RuntimeException
);
347 ::rtl::OUString
GetDisplFuncStr( sal_uInt16 nResId
) throw( ::com::sun::star::uno::RuntimeException
);
348 ::rtl::OUString
GetFuncDescrStr( sal_uInt16 nResId
, sal_uInt16 nStrIndex
) throw( ::com::sun::star::uno::RuntimeException
);
352 virtual ~ScaDateAddIn();
354 static ::rtl::OUString
getImplementationName_Static();
355 static ::com::sun::star::uno::Sequence
< ::rtl::OUString
> getSupportedServiceNames_Static();
358 virtual ::rtl::OUString SAL_CALL
getProgrammaticFuntionName( const ::rtl::OUString
& aDisplayName
) throw( ::com::sun::star::uno::RuntimeException
);
359 virtual ::rtl::OUString SAL_CALL
getDisplayFunctionName( const ::rtl::OUString
& aProgrammaticName
) throw( ::com::sun::star::uno::RuntimeException
);
360 virtual ::rtl::OUString SAL_CALL
getFunctionDescription( const ::rtl::OUString
& aProgrammaticName
) throw( ::com::sun::star::uno::RuntimeException
);
361 virtual ::rtl::OUString SAL_CALL
getDisplayArgumentName( const ::rtl::OUString
& aProgrammaticName
, sal_Int32 nArgument
) throw( ::com::sun::star::uno::RuntimeException
);
362 virtual ::rtl::OUString SAL_CALL
getArgumentDescription( const ::rtl::OUString
& aProgrammaticName
, sal_Int32 nArgument
) throw( ::com::sun::star::uno::RuntimeException
);
363 virtual ::rtl::OUString SAL_CALL
getProgrammaticCategoryName( const ::rtl::OUString
& aProgrammaticName
) throw( ::com::sun::star::uno::RuntimeException
);
364 virtual ::rtl::OUString SAL_CALL
getDisplayCategoryName( const ::rtl::OUString
& aProgrammaticName
) throw( ::com::sun::star::uno::RuntimeException
);
366 // XCompatibilityNames
367 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::sheet::LocalizedName
> SAL_CALL
getCompatibilityNames( const ::rtl::OUString
& aProgrammaticName
) throw( ::com::sun::star::uno::RuntimeException
);
370 virtual void SAL_CALL
setLocale( const ::com::sun::star::lang::Locale
& eLocale
) throw( ::com::sun::star::uno::RuntimeException
);
371 virtual ::com::sun::star::lang::Locale SAL_CALL
getLocale() throw( ::com::sun::star::uno::RuntimeException
);
374 virtual ::rtl::OUString SAL_CALL
getServiceName() throw( ::com::sun::star::uno::RuntimeException
);
377 virtual ::rtl::OUString SAL_CALL
getImplementationName() throw( ::com::sun::star::uno::RuntimeException
);
378 virtual sal_Bool SAL_CALL
supportsService( const ::rtl::OUString
& ServiceName
) throw( ::com::sun::star::uno::RuntimeException
);
379 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException
);
381 // methods from own interfaces start here
384 virtual sal_Int32 SAL_CALL
getDiffWeeks(
385 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& xOptions
,
386 sal_Int32 nEndDate
, sal_Int32 nStartDate
,
388 throw( ::com::sun::star::uno::RuntimeException
, ::com::sun::star::lang::IllegalArgumentException
);
390 virtual sal_Int32 SAL_CALL
getDiffMonths(
391 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& xOptions
,
392 sal_Int32 nEndDate
, sal_Int32 nStartDate
,
394 throw( ::com::sun::star::uno::RuntimeException
, ::com::sun::star::lang::IllegalArgumentException
);
396 virtual sal_Int32 SAL_CALL
getDiffYears(
397 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& xOptions
,
398 sal_Int32 nEndDate
, sal_Int32 nStartDate
,
400 throw( ::com::sun::star::uno::RuntimeException
, ::com::sun::star::lang::IllegalArgumentException
);
402 virtual sal_Int32 SAL_CALL
getIsLeapYear(
403 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& xOptions
,
405 throw( ::com::sun::star::uno::RuntimeException
, ::com::sun::star::lang::IllegalArgumentException
);
407 virtual sal_Int32 SAL_CALL
getDaysInMonth(
408 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& xOptions
,
410 throw( ::com::sun::star::uno::RuntimeException
, ::com::sun::star::lang::IllegalArgumentException
);
412 virtual sal_Int32 SAL_CALL
getDaysInYear(
413 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& xOptions
,
415 throw( ::com::sun::star::uno::RuntimeException
, ::com::sun::star::lang::IllegalArgumentException
);
417 virtual sal_Int32 SAL_CALL
getWeeksInYear(
418 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& xOptions
,
420 throw( ::com::sun::star::uno::RuntimeException
, ::com::sun::star::lang::IllegalArgumentException
);
423 virtual ::rtl::OUString SAL_CALL
getRot13(
424 const ::rtl::OUString
& aSrcText
)
425 throw( ::com::sun::star::uno::RuntimeException
, ::com::sun::star::lang::IllegalArgumentException
);
428 //------------------------------------------------------------------
430 #endif // _SCA_DATEFUNC_HXX