1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include "calendarImpl.hxx"
22 #include "localedata.hxx"
23 #include <comphelper/processfactory.hxx>
25 using namespace ::com::sun::star::uno
;
26 using namespace ::com::sun::star::lang
;
27 using ::rtl::OUString
;
29 namespace com
{ namespace sun
{ namespace star
{ namespace i18n
{
31 #define ERROR RuntimeException()
33 CalendarImpl::CalendarImpl(const Reference
< XMultiServiceFactory
> &rxMSF
) : xMSF(rxMSF
)
37 CalendarImpl::~CalendarImpl()
40 for (size_t l
= 0; l
< lookupTable
.size(); l
++)
41 delete lookupTable
[l
];
47 CalendarImpl::loadDefaultCalendar( const Locale
& rLocale
) throw(RuntimeException
)
49 Sequence
< Calendar2
> xC
= LocaleData().getAllCalendars2(rLocale
);
50 for (sal_Int32 i
= 0; i
< xC
.getLength(); i
++) {
52 loadCalendar(xC
[i
].Name
, rLocale
);
60 CalendarImpl::loadCalendar(const OUString
& uniqueID
, const Locale
& rLocale
) throw (RuntimeException
)
62 Reference
< XCalendar3
> xOldCalendar( xCalendar
); // backup
65 for (i
= 0; i
< sal::static_int_cast
<sal_Int32
>(lookupTable
.size()); i
++) {
66 lookupTableItem
*listItem
= lookupTable
[i
];
67 if (uniqueID
== listItem
->uniqueID
) {
68 xCalendar
= listItem
->xCalendar
;
73 if (i
>= sal::static_int_cast
<sal_Int32
>(lookupTable
.size())) {
74 Reference
< XInterface
> xI
= xMSF
->createInstance(
75 OUString("com.sun.star.i18n.Calendar_") + uniqueID
);
78 // check if the calendar is defined in localedata, load gregorian calendar service.
79 Sequence
< Calendar2
> xC
= LocaleData().getAllCalendars2(rLocale
);
80 for (i
= 0; i
< xC
.getLength(); i
++) {
81 if (uniqueID
== xC
[i
].Name
) {
82 xI
= xMSF
->createInstance(
83 OUString("com.sun.star.i18n.Calendar_gregorian"));
90 xI
->queryInterface(::getCppuType((const Reference
< XCalendar3
>*)0)) >>= xCalendar
;
94 lookupTable
.push_back( new lookupTableItem(uniqueID
, xCalendar
) );
97 if ( !xCalendar
.is() )
99 xCalendar
= xOldCalendar
;
105 xCalendar
->loadCalendar(uniqueID
, rLocale
);
108 { // restore previous calendar and re-throw
109 xCalendar
= xOldCalendar
;
115 CalendarImpl::getLoadedCalendar2() throw(RuntimeException
)
118 return xCalendar
->getLoadedCalendar2();
124 CalendarImpl::getLoadedCalendar() throw(RuntimeException
)
127 return xCalendar
->getLoadedCalendar();
132 Sequence
< OUString
> SAL_CALL
133 CalendarImpl::getAllCalendars( const Locale
& rLocale
) throw(RuntimeException
)
135 Sequence
< Calendar2
> xC
= LocaleData().getAllCalendars2(rLocale
);
136 sal_Int32 nLen
= xC
.getLength();
137 Sequence
< OUString
> xSeq( nLen
);
138 for (sal_Int32 i
= 0; i
< nLen
; i
++)
139 xSeq
[i
] = xC
[i
].Name
;
144 CalendarImpl::setDateTime( double timeInDays
) throw(RuntimeException
)
147 xCalendar
->setDateTime( timeInDays
);
153 CalendarImpl::getDateTime() throw(RuntimeException
)
156 return xCalendar
->getDateTime();
162 CalendarImpl::getUniqueID() throw(RuntimeException
)
165 return xCalendar
->getUniqueID();
171 CalendarImpl::setValue( sal_Int16 fieldIndex
, sal_Int16 value
) throw(RuntimeException
)
174 xCalendar
->setValue( fieldIndex
, value
);
180 CalendarImpl::getValue( sal_Int16 fieldIndex
) throw(RuntimeException
)
183 return xCalendar
->getValue( fieldIndex
);
189 CalendarImpl::addValue( sal_Int16 fieldIndex
, sal_Int32 amount
) throw(RuntimeException
)
192 xCalendar
->addValue( fieldIndex
, amount
);
198 CalendarImpl::getFirstDayOfWeek() throw(RuntimeException
)
201 return xCalendar
->getFirstDayOfWeek();
207 CalendarImpl::setFirstDayOfWeek( sal_Int16 day
)
208 throw(RuntimeException
)
211 xCalendar
->setFirstDayOfWeek(day
);
217 CalendarImpl::setMinimumNumberOfDaysForFirstWeek( sal_Int16 days
) throw(RuntimeException
)
220 xCalendar
->setMinimumNumberOfDaysForFirstWeek(days
);
226 CalendarImpl::getMinimumNumberOfDaysForFirstWeek() throw(RuntimeException
)
229 return xCalendar
->getMinimumNumberOfDaysForFirstWeek();
236 CalendarImpl::getDisplayName( sal_Int16 displayIndex
, sal_Int16 idx
, sal_Int16 nameType
) throw(RuntimeException
)
239 return xCalendar
->getDisplayName( displayIndex
, idx
, nameType
);
245 CalendarImpl::getNumberOfMonthsInYear() throw(RuntimeException
)
248 return xCalendar
->getNumberOfMonthsInYear();
255 CalendarImpl::getNumberOfDaysInWeek() throw(RuntimeException
)
258 return xCalendar
->getNumberOfDaysInWeek();
264 Sequence
< CalendarItem
> SAL_CALL
265 CalendarImpl::getDays() throw(RuntimeException
)
268 return xCalendar
->getDays();
274 Sequence
< CalendarItem
> SAL_CALL
275 CalendarImpl::getMonths() throw(RuntimeException
)
278 return xCalendar
->getMonths();
284 Sequence
< CalendarItem2
> SAL_CALL
285 CalendarImpl::getDays2() throw(RuntimeException
)
288 return xCalendar
->getDays2();
294 Sequence
< CalendarItem2
> SAL_CALL
295 CalendarImpl::getMonths2() throw(RuntimeException
)
298 return xCalendar
->getMonths2();
304 Sequence
< CalendarItem2
> SAL_CALL
305 CalendarImpl::getGenitiveMonths2() throw(RuntimeException
)
308 return xCalendar
->getGenitiveMonths2();
314 Sequence
< CalendarItem2
> SAL_CALL
315 CalendarImpl::getPartitiveMonths2() throw(RuntimeException
)
318 return xCalendar
->getPartitiveMonths2();
325 CalendarImpl::isValid() throw(RuntimeException
)
328 return xCalendar
->isValid();
334 CalendarImpl::getDisplayString( sal_Int32 nCalendarDisplayCode
, sal_Int16 nNativeNumberMode
)
335 throw (RuntimeException
)
338 return xCalendar
->getDisplayString(nCalendarDisplayCode
, nNativeNumberMode
);
344 CalendarImpl::getImplementationName(void) throw( RuntimeException
)
346 return OUString("com.sun.star.i18n.CalendarImpl");
349 const sal_Char cCalendar
[] = "com.sun.star.i18n.LocaleCalendar";
352 CalendarImpl::supportsService(const OUString
& rServiceName
) throw( RuntimeException
)
354 return !rServiceName
.compareToAscii(cCalendar
);
357 Sequence
< OUString
> SAL_CALL
358 CalendarImpl::getSupportedServiceNames(void) throw( RuntimeException
)
360 Sequence
< OUString
> aRet(1);
361 aRet
[0] = OUString::createFromAscii(cCalendar
);
367 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */