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/mslangid.hxx>
27 #include <tools/debug.hxx>
28 #include <osl/mutex.hxx>
29 #include <osl/diagnose.h>
30 #include <tools/stream.hxx>
31 #include <svl/instrm.hxx>
33 using namespace ::com::sun::star::uno
;
34 using namespace ::com::sun::star::lang
;
35 using namespace ::com::sun::star::io
;
36 using namespace ::com::sun::star::beans
;
37 using namespace ::com::sun::star::util
;
38 using namespace ::utl
;
41 SvNumberFormatsSupplierServiceObject::SvNumberFormatsSupplierServiceObject(const css::uno::Reference
< css::uno::XComponentContext
>& _rxORB
)
46 SvNumberFormatsSupplierServiceObject::~SvNumberFormatsSupplierServiceObject()
50 Any SAL_CALL
SvNumberFormatsSupplierServiceObject::queryAggregation( const Type
& _rType
)
52 Any aReturn
= ::cppu::queryInterface(_rType
,
53 static_cast< XInitialization
* >(this),
54 static_cast< XServiceInfo
* >(this)
57 if (!aReturn
.hasValue())
58 aReturn
= SvNumberFormatsSupplierObj::queryAggregation(_rType
);
63 void SAL_CALL
SvNumberFormatsSupplierServiceObject::initialize( const Sequence
< Any
>& _rArguments
)
65 ::osl::MutexGuard
aGuard( getSharedMutex() );
67 DBG_ASSERT(m_pOwnFormatter
== nullptr,
68 "SvNumberFormatsSupplierServiceObject::initialize : already initialized !");
69 // maybe you already called a method which needed the formatter
70 // you should use XMultiServiceFactory::createInstanceWithArguments to avoid that
72 { // !!! this is only a emergency handling, normally this should not occur !!!
73 m_pOwnFormatter
.reset();
74 SetNumberFormatter(m_pOwnFormatter
.get());
77 Type aExpectedArgType
= ::cppu::UnoType
<css::lang::Locale
>::get();
78 LanguageType eNewFormatterLanguage
= LANGUAGE_SYSTEM
;
81 const Any
* pArgs
= _rArguments
.getConstArray();
82 for (sal_Int32 i
=0; i
<_rArguments
.getLength(); ++i
, ++pArgs
)
84 if (pArgs
->getValueType().equals(aExpectedArgType
))
86 css::lang::Locale aLocale
;
88 eNewFormatterLanguage
= LanguageTag::convertToLanguageType( aLocale
, false);
93 OSL_FAIL("SvNumberFormatsSupplierServiceObject::initialize : unknown argument !");
98 m_pOwnFormatter
.reset( new SvNumberFormatter( m_xORB
, eNewFormatterLanguage
) );
99 m_pOwnFormatter
->SetEvalDateFormat( NF_EVALDATEFORMAT_FORMAT_INTL
);
100 SetNumberFormatter(m_pOwnFormatter
.get());
103 OUString SAL_CALL
SvNumberFormatsSupplierServiceObject::getImplementationName( )
105 return OUString("com.sun.star.uno.util.numbers.SvNumberFormatsSupplierServiceObject");
108 sal_Bool SAL_CALL
SvNumberFormatsSupplierServiceObject::supportsService( const OUString
& _rServiceName
)
110 return cppu::supportsService(this, _rServiceName
);
113 Sequence
< OUString
> SAL_CALL
SvNumberFormatsSupplierServiceObject::getSupportedServiceNames( )
115 Sequence
< OUString
> aSupported
{ "com.sun.star.util.NumberFormatsSupplier" };
119 Reference
< XPropertySet
> SAL_CALL
SvNumberFormatsSupplierServiceObject::getNumberFormatSettings()
121 ::osl::MutexGuard
aGuard( getSharedMutex() );
122 implEnsureFormatter();
123 return SvNumberFormatsSupplierObj::getNumberFormatSettings();
126 Reference
< XNumberFormats
> SAL_CALL
SvNumberFormatsSupplierServiceObject::getNumberFormats()
128 ::osl::MutexGuard
aGuard( getSharedMutex() );
129 implEnsureFormatter();
130 return SvNumberFormatsSupplierObj::getNumberFormats();
133 sal_Int64 SAL_CALL
SvNumberFormatsSupplierServiceObject::getSomething( const Sequence
< sal_Int8
>& aIdentifier
)
135 sal_Int64 nReturn
= SvNumberFormatsSupplierObj::getSomething( aIdentifier
);
137 // if somebody accesses internals then we should have the formatter
138 implEnsureFormatter();
142 void SvNumberFormatsSupplierServiceObject::implEnsureFormatter()
144 if (!m_pOwnFormatter
)
146 // get the office's UI locale
147 SvtSysLocale aSysLocale
;
148 css::lang::Locale aOfficeLocale
= aSysLocale
.GetLocaleData().getLanguageTag().getLocale();
150 // initialize with this locale
151 Sequence
< Any
> aFakedInitProps( 1 );
152 aFakedInitProps
[0] <<= aOfficeLocale
;
154 initialize( aFakedInitProps
);
159 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
160 com_sun_star_uno_util_numbers_SvNumberFormatsSupplierServiceObject_get_implementation(css::uno::XComponentContext
* context
,
161 css::uno::Sequence
<css::uno::Any
> const &)
163 return cppu::acquire(new SvNumberFormatsSupplierServiceObject(context
));
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */