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
;
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
];
46 CalendarImpl::loadDefaultCalendar( const Locale
& rLocale
) throw(RuntimeException
)
48 Sequence
< Calendar2
> xC
= LocaleDataImpl().getAllCalendars2(rLocale
);
49 for (sal_Int32 i
= 0; i
< xC
.getLength(); i
++) {
51 loadCalendar(xC
[i
].Name
, rLocale
);
59 CalendarImpl::loadCalendar(const OUString
& uniqueID
, const Locale
& rLocale
) throw (RuntimeException
)
61 Reference
< XCalendar3
> xOldCalendar( xCalendar
); // backup
64 for (i
= 0; i
< sal::static_int_cast
<sal_Int32
>(lookupTable
.size()); i
++) {
65 lookupTableItem
*listItem
= lookupTable
[i
];
66 if (uniqueID
== listItem
->uniqueID
) {
67 xCalendar
= listItem
->xCalendar
;
72 if (i
>= sal::static_int_cast
<sal_Int32
>(lookupTable
.size())) {
73 Reference
< XInterface
> xI
= m_xContext
->getServiceManager()->createInstanceWithContext(
74 OUString("com.sun.star.i18n.Calendar_") + uniqueID
, m_xContext
);
77 // check if the calendar is defined in localedata, load gregorian calendar service.
78 Sequence
< Calendar2
> xC
= LocaleDataImpl().getAllCalendars2(rLocale
);
79 for (i
= 0; i
< xC
.getLength(); i
++) {
80 if (uniqueID
== xC
[i
].Name
) {
81 xI
= m_xContext
->getServiceManager()->createInstanceWithContext("com.sun.star.i18n.Calendar_gregorian", m_xContext
);
88 xCalendar
.set(xI
, UNO_QUERY
);
92 lookupTable
.push_back( new lookupTableItem(uniqueID
, xCalendar
) );
95 if ( !xCalendar
.is() )
97 xCalendar
= xOldCalendar
;
103 xCalendar
->loadCalendar(uniqueID
, rLocale
);
106 { // restore previous calendar and re-throw
107 xCalendar
= xOldCalendar
;
113 CalendarImpl::getLoadedCalendar2() throw(RuntimeException
)
116 return xCalendar
->getLoadedCalendar2();
122 CalendarImpl::getLoadedCalendar() throw(RuntimeException
)
125 return xCalendar
->getLoadedCalendar();
130 Sequence
< OUString
> SAL_CALL
131 CalendarImpl::getAllCalendars( const Locale
& rLocale
) throw(RuntimeException
)
133 Sequence
< Calendar2
> xC
= LocaleDataImpl().getAllCalendars2(rLocale
);
134 sal_Int32 nLen
= xC
.getLength();
135 Sequence
< OUString
> xSeq( nLen
);
136 for (sal_Int32 i
= 0; i
< nLen
; i
++)
137 xSeq
[i
] = xC
[i
].Name
;
142 CalendarImpl::setDateTime( double timeInDays
) throw(RuntimeException
)
145 xCalendar
->setDateTime( timeInDays
);
151 CalendarImpl::getDateTime() throw(RuntimeException
)
154 return xCalendar
->getDateTime();
160 CalendarImpl::getUniqueID() throw(RuntimeException
)
163 return xCalendar
->getUniqueID();
169 CalendarImpl::setValue( sal_Int16 fieldIndex
, sal_Int16 value
) throw(RuntimeException
)
172 xCalendar
->setValue( fieldIndex
, value
);
178 CalendarImpl::getValue( sal_Int16 fieldIndex
) throw(RuntimeException
)
181 return xCalendar
->getValue( fieldIndex
);
187 CalendarImpl::addValue( sal_Int16 fieldIndex
, sal_Int32 amount
) throw(RuntimeException
)
190 xCalendar
->addValue( fieldIndex
, amount
);
196 CalendarImpl::getFirstDayOfWeek() throw(RuntimeException
)
199 return xCalendar
->getFirstDayOfWeek();
205 CalendarImpl::setFirstDayOfWeek( sal_Int16 day
)
206 throw(RuntimeException
)
209 xCalendar
->setFirstDayOfWeek(day
);
215 CalendarImpl::setMinimumNumberOfDaysForFirstWeek( sal_Int16 days
) throw(RuntimeException
)
218 xCalendar
->setMinimumNumberOfDaysForFirstWeek(days
);
224 CalendarImpl::getMinimumNumberOfDaysForFirstWeek() throw(RuntimeException
)
227 return xCalendar
->getMinimumNumberOfDaysForFirstWeek();
234 CalendarImpl::getDisplayName( sal_Int16 displayIndex
, sal_Int16 idx
, sal_Int16 nameType
) throw(RuntimeException
)
237 return xCalendar
->getDisplayName( displayIndex
, idx
, nameType
);
243 CalendarImpl::getNumberOfMonthsInYear() throw(RuntimeException
)
246 return xCalendar
->getNumberOfMonthsInYear();
253 CalendarImpl::getNumberOfDaysInWeek() throw(RuntimeException
)
256 return xCalendar
->getNumberOfDaysInWeek();
262 Sequence
< CalendarItem
> SAL_CALL
263 CalendarImpl::getDays() throw(RuntimeException
)
266 return xCalendar
->getDays();
272 Sequence
< CalendarItem
> SAL_CALL
273 CalendarImpl::getMonths() throw(RuntimeException
)
276 return xCalendar
->getMonths();
282 Sequence
< CalendarItem2
> SAL_CALL
283 CalendarImpl::getDays2() throw(RuntimeException
)
286 return xCalendar
->getDays2();
292 Sequence
< CalendarItem2
> SAL_CALL
293 CalendarImpl::getMonths2() throw(RuntimeException
)
296 return xCalendar
->getMonths2();
302 Sequence
< CalendarItem2
> SAL_CALL
303 CalendarImpl::getGenitiveMonths2() throw(RuntimeException
)
306 return xCalendar
->getGenitiveMonths2();
312 Sequence
< CalendarItem2
> SAL_CALL
313 CalendarImpl::getPartitiveMonths2() throw(RuntimeException
)
316 return xCalendar
->getPartitiveMonths2();
323 CalendarImpl::isValid() throw(RuntimeException
)
326 return xCalendar
->isValid();
332 CalendarImpl::getDisplayString( sal_Int32 nCalendarDisplayCode
, sal_Int16 nNativeNumberMode
)
333 throw (RuntimeException
)
336 return xCalendar
->getDisplayString(nCalendarDisplayCode
, nNativeNumberMode
);
342 CalendarImpl::getImplementationName(void) throw( RuntimeException
)
344 return OUString("com.sun.star.i18n.CalendarImpl");
347 const sal_Char cCalendar
[] = "com.sun.star.i18n.LocaleCalendar";
350 CalendarImpl::supportsService(const OUString
& rServiceName
) throw( RuntimeException
)
352 return rServiceName
.equalsAscii(cCalendar
);
355 Sequence
< OUString
> SAL_CALL
356 CalendarImpl::getSupportedServiceNames(void) throw( RuntimeException
)
358 Sequence
< OUString
> aRet(1);
359 aRet
[0] = OUString::createFromAscii(cCalendar
);
365 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */