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 .
20 #include "calendarImpl.hxx"
21 #include "localedata.hxx"
22 #include <comphelper/processfactory.hxx>
23 #include <cppuhelper/supportsservice.hxx>
25 using namespace ::com::sun::star::uno
;
26 using namespace ::com::sun::star::lang
;
28 namespace com
{ namespace sun
{ namespace star
{ namespace i18n
{
30 #define ERROR RuntimeException()
32 CalendarImpl::CalendarImpl(const Reference
< XComponentContext
> &rxContext
) : m_xContext(rxContext
)
36 CalendarImpl::~CalendarImpl()
39 for (size_t l
= 0; l
< lookupTable
.size(); l
++)
40 delete lookupTable
[l
];
45 CalendarImpl::loadDefaultCalendar( const Locale
& rLocale
) throw(RuntimeException
, std::exception
)
47 Sequence
< Calendar2
> xC
= LocaleDataImpl().getAllCalendars2(rLocale
);
48 for (sal_Int32 i
= 0; i
< xC
.getLength(); i
++) {
50 loadCalendar(xC
[i
].Name
, rLocale
);
58 CalendarImpl::loadCalendar(const OUString
& uniqueID
, const Locale
& rLocale
) throw (RuntimeException
, std::exception
)
60 Reference
< XCalendar3
> xOldCalendar( xCalendar
); // backup
63 for (i
= 0; i
< sal::static_int_cast
<sal_Int32
>(lookupTable
.size()); i
++) {
64 lookupTableItem
*listItem
= lookupTable
[i
];
65 if (uniqueID
== listItem
->uniqueID
) {
66 xCalendar
= listItem
->xCalendar
;
71 if (i
>= sal::static_int_cast
<sal_Int32
>(lookupTable
.size())) {
72 Reference
< XInterface
> xI
= m_xContext
->getServiceManager()->createInstanceWithContext(
73 OUString("com.sun.star.i18n.Calendar_") + uniqueID
, m_xContext
);
76 // check if the calendar is defined in localedata, load gregorian calendar service.
77 Sequence
< Calendar2
> xC
= LocaleDataImpl().getAllCalendars2(rLocale
);
78 for (i
= 0; i
< xC
.getLength(); i
++) {
79 if (uniqueID
== xC
[i
].Name
) {
80 xI
= m_xContext
->getServiceManager()->createInstanceWithContext("com.sun.star.i18n.Calendar_gregorian", m_xContext
);
87 xCalendar
.set(xI
, UNO_QUERY
);
91 lookupTable
.push_back( new lookupTableItem(uniqueID
, xCalendar
) );
94 if ( !xCalendar
.is() )
96 xCalendar
= xOldCalendar
;
102 xCalendar
->loadCalendar(uniqueID
, rLocale
);
105 { // restore previous calendar and re-throw
106 xCalendar
= xOldCalendar
;
112 CalendarImpl::getLoadedCalendar2() throw(RuntimeException
, std::exception
)
115 return xCalendar
->getLoadedCalendar2();
121 CalendarImpl::getLoadedCalendar() throw(RuntimeException
, std::exception
)
124 return xCalendar
->getLoadedCalendar();
129 Sequence
< OUString
> SAL_CALL
130 CalendarImpl::getAllCalendars( const Locale
& rLocale
) throw(RuntimeException
, std::exception
)
132 Sequence
< Calendar2
> xC
= LocaleDataImpl().getAllCalendars2(rLocale
);
133 sal_Int32 nLen
= xC
.getLength();
134 Sequence
< OUString
> xSeq( nLen
);
135 for (sal_Int32 i
= 0; i
< nLen
; i
++)
136 xSeq
[i
] = xC
[i
].Name
;
141 CalendarImpl::setDateTime( double timeInDays
) throw(RuntimeException
, std::exception
)
144 xCalendar
->setDateTime( timeInDays
);
150 CalendarImpl::getDateTime() throw(RuntimeException
, std::exception
)
153 return xCalendar
->getDateTime();
159 CalendarImpl::getUniqueID() throw(RuntimeException
, std::exception
)
162 return xCalendar
->getUniqueID();
168 CalendarImpl::setValue( sal_Int16 fieldIndex
, sal_Int16 value
) throw(RuntimeException
, std::exception
)
171 xCalendar
->setValue( fieldIndex
, value
);
177 CalendarImpl::getValue( sal_Int16 fieldIndex
) throw(RuntimeException
, std::exception
)
180 return xCalendar
->getValue( fieldIndex
);
186 CalendarImpl::addValue( sal_Int16 fieldIndex
, sal_Int32 amount
) throw(RuntimeException
, std::exception
)
189 xCalendar
->addValue( fieldIndex
, amount
);
195 CalendarImpl::getFirstDayOfWeek() throw(RuntimeException
, std::exception
)
198 return xCalendar
->getFirstDayOfWeek();
204 CalendarImpl::setFirstDayOfWeek( sal_Int16 day
)
205 throw(RuntimeException
, std::exception
)
208 xCalendar
->setFirstDayOfWeek(day
);
214 CalendarImpl::setMinimumNumberOfDaysForFirstWeek( sal_Int16 days
) throw(RuntimeException
, std::exception
)
217 xCalendar
->setMinimumNumberOfDaysForFirstWeek(days
);
223 CalendarImpl::getMinimumNumberOfDaysForFirstWeek() throw(RuntimeException
, std::exception
)
226 return xCalendar
->getMinimumNumberOfDaysForFirstWeek();
233 CalendarImpl::getDisplayName( sal_Int16 displayIndex
, sal_Int16 idx
, sal_Int16 nameType
) throw(RuntimeException
, std::exception
)
236 return xCalendar
->getDisplayName( displayIndex
, idx
, nameType
);
242 CalendarImpl::getNumberOfMonthsInYear() throw(RuntimeException
, std::exception
)
245 return xCalendar
->getNumberOfMonthsInYear();
252 CalendarImpl::getNumberOfDaysInWeek() throw(RuntimeException
, std::exception
)
255 return xCalendar
->getNumberOfDaysInWeek();
261 Sequence
< CalendarItem
> SAL_CALL
262 CalendarImpl::getDays() throw(RuntimeException
, std::exception
)
265 return xCalendar
->getDays();
271 Sequence
< CalendarItem
> SAL_CALL
272 CalendarImpl::getMonths() throw(RuntimeException
, std::exception
)
275 return xCalendar
->getMonths();
281 Sequence
< CalendarItem2
> SAL_CALL
282 CalendarImpl::getDays2() throw(RuntimeException
, std::exception
)
285 return xCalendar
->getDays2();
291 Sequence
< CalendarItem2
> SAL_CALL
292 CalendarImpl::getMonths2() throw(RuntimeException
, std::exception
)
295 return xCalendar
->getMonths2();
301 Sequence
< CalendarItem2
> SAL_CALL
302 CalendarImpl::getGenitiveMonths2() throw(RuntimeException
, std::exception
)
305 return xCalendar
->getGenitiveMonths2();
311 Sequence
< CalendarItem2
> SAL_CALL
312 CalendarImpl::getPartitiveMonths2() throw(RuntimeException
, std::exception
)
315 return xCalendar
->getPartitiveMonths2();
322 CalendarImpl::isValid() throw(RuntimeException
, std::exception
)
325 return xCalendar
->isValid();
331 CalendarImpl::getDisplayString( sal_Int32 nCalendarDisplayCode
, sal_Int16 nNativeNumberMode
)
332 throw (RuntimeException
, std::exception
)
335 return xCalendar
->getDisplayString(nCalendarDisplayCode
, nNativeNumberMode
);
341 CalendarImpl::getImplementationName(void) throw( RuntimeException
, std::exception
)
343 return OUString("com.sun.star.i18n.CalendarImpl");
347 CalendarImpl::supportsService(const OUString
& rServiceName
) throw( RuntimeException
, std::exception
)
349 return cppu::supportsService(this, rServiceName
);
352 Sequence
< OUString
> SAL_CALL
353 CalendarImpl::getSupportedServiceNames(void) throw( RuntimeException
, std::exception
)
355 Sequence
< OUString
> aRet(1);
356 aRet
[0] = "com.sun.star.i18n.LocaleCalendar";
362 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */