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 "supservs.hxx"
21 #include <com/sun/star/lang/Locale.hpp>
22 #include <comphelper/sharedmutex.hxx>
23 #include <cppuhelper/supportsservice.hxx>
24 #include <cppuhelper/queryinterface.hxx>
25 #include <cppuhelper/weak.hxx>
26 #include <i18nlangtag/languagetag.hxx>
27 #include <tools/debug.hxx>
28 #include <osl/mutex.hxx>
29 #include <osl/diagnose.h>
31 using namespace ::com::sun::star::uno
;
32 using namespace ::com::sun::star::lang
;
33 using namespace ::com::sun::star::beans
;
34 using namespace ::com::sun::star::util
;
35 using namespace ::utl
;
38 SvNumberFormatsSupplierServiceObject::SvNumberFormatsSupplierServiceObject(const css::uno::Reference
< css::uno::XComponentContext
>& _rxORB
)
43 SvNumberFormatsSupplierServiceObject::~SvNumberFormatsSupplierServiceObject()
47 Any SAL_CALL
SvNumberFormatsSupplierServiceObject::queryAggregation( const Type
& _rType
)
49 Any aReturn
= ::cppu::queryInterface(_rType
,
50 static_cast< XInitialization
* >(this),
51 static_cast< XServiceInfo
* >(this)
54 if (!aReturn
.hasValue())
55 aReturn
= SvNumberFormatsSupplierObj::queryAggregation(_rType
);
60 void SAL_CALL
SvNumberFormatsSupplierServiceObject::initialize( const Sequence
< Any
>& _rArguments
)
62 ::osl::MutexGuard
aGuard( getSharedMutex() );
64 DBG_ASSERT(m_pOwnFormatter
== nullptr,
65 "SvNumberFormatsSupplierServiceObject::initialize : already initialized !");
66 // maybe you already called a method which needed the formatter
67 // you should use XMultiServiceFactory::createInstanceWithArguments to avoid that
69 { // !!! this is only an emergency handling, normally this should not occur !!!
70 m_pOwnFormatter
.reset();
71 SetNumberFormatter(m_pOwnFormatter
.get());
74 Type aExpectedArgType
= ::cppu::UnoType
<css::lang::Locale
>::get();
75 LanguageType eNewFormatterLanguage
= LANGUAGE_SYSTEM
;
78 for (const Any
& rArg
: _rArguments
)
80 if (rArg
.getValueType().equals(aExpectedArgType
))
82 css::lang::Locale aLocale
;
84 eNewFormatterLanguage
= LanguageTag::convertToLanguageType( aLocale
, false);
89 OSL_FAIL("SvNumberFormatsSupplierServiceObject::initialize : unknown argument !");
94 m_pOwnFormatter
.reset( new SvNumberFormatter( m_xORB
, eNewFormatterLanguage
) );
95 m_pOwnFormatter
->SetEvalDateFormat( NF_EVALDATEFORMAT_FORMAT_INTL
);
96 SetNumberFormatter(m_pOwnFormatter
.get());
99 OUString SAL_CALL
SvNumberFormatsSupplierServiceObject::getImplementationName( )
101 return "com.sun.star.uno.util.numbers.SvNumberFormatsSupplierServiceObject";
104 sal_Bool SAL_CALL
SvNumberFormatsSupplierServiceObject::supportsService( const OUString
& _rServiceName
)
106 return cppu::supportsService(this, _rServiceName
);
109 Sequence
< OUString
> SAL_CALL
SvNumberFormatsSupplierServiceObject::getSupportedServiceNames( )
111 return { "com.sun.star.util.NumberFormatsSupplier" };
114 Reference
< XPropertySet
> SAL_CALL
SvNumberFormatsSupplierServiceObject::getNumberFormatSettings()
116 ::osl::MutexGuard
aGuard( getSharedMutex() );
117 implEnsureFormatter();
118 return SvNumberFormatsSupplierObj::getNumberFormatSettings();
121 Reference
< XNumberFormats
> SAL_CALL
SvNumberFormatsSupplierServiceObject::getNumberFormats()
123 ::osl::MutexGuard
aGuard( getSharedMutex() );
124 implEnsureFormatter();
125 return SvNumberFormatsSupplierObj::getNumberFormats();
128 sal_Int64 SAL_CALL
SvNumberFormatsSupplierServiceObject::getSomething( const Sequence
< sal_Int8
>& aIdentifier
)
130 sal_Int64 nReturn
= SvNumberFormatsSupplierObj::getSomething( aIdentifier
);
132 // if somebody accesses internals then we should have the formatter
133 implEnsureFormatter();
137 void SvNumberFormatsSupplierServiceObject::implEnsureFormatter()
139 if (!m_pOwnFormatter
)
141 // get the office's UI locale
142 SvtSysLocale aSysLocale
;
143 css::lang::Locale aOfficeLocale
= aSysLocale
.GetLocaleData().getLanguageTag().getLocale();
145 // initialize with this locale
146 Sequence
< Any
> aFakedInitProps( 1 );
147 aFakedInitProps
[0] <<= aOfficeLocale
;
149 initialize( aFakedInitProps
);
154 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
155 com_sun_star_uno_util_numbers_SvNumberFormatsSupplierServiceObject_get_implementation(css::uno::XComponentContext
* context
,
156 css::uno::Sequence
<css::uno::Any
> const &)
158 return cppu::acquire(new SvNumberFormatsSupplierServiceObject(context
));
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */