tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / svl / source / numbers / supservs.cxx
blobb8f396ffb57813de34bca80079076c7ffcc5bcd3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <svl/numformat.hxx>
28 #include <tools/debug.hxx>
29 #include <osl/mutex.hxx>
30 #include <utility>
31 #include <osl/diagnose.h>
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::lang;
35 using namespace ::com::sun::star::beans;
36 using namespace ::com::sun::star::util;
39 SvNumberFormatsSupplierServiceObject::SvNumberFormatsSupplierServiceObject(css::uno::Reference< css::uno::XComponentContext > _xORB)
40 :m_xORB(std::move(_xORB))
44 SvNumberFormatsSupplierServiceObject::~SvNumberFormatsSupplierServiceObject()
48 Any SAL_CALL SvNumberFormatsSupplierServiceObject::queryAggregation( const Type& _rType )
50 Any aReturn = ::cppu::queryInterface(_rType,
51 static_cast< XInitialization* >(this),
52 static_cast< XServiceInfo* >(this)
55 if (!aReturn.hasValue())
56 aReturn = SvNumberFormatsSupplierObj::queryAggregation(_rType);
58 return aReturn;
61 void SAL_CALL SvNumberFormatsSupplierServiceObject::initialize( const Sequence< Any >& _rArguments )
63 ::osl::MutexGuard aGuard( getSharedMutex() );
65 DBG_ASSERT(m_pOwnFormatter == nullptr,
66 "SvNumberFormatsSupplierServiceObject::initialize : already initialized !");
67 // maybe you already called a method which needed the formatter
68 // you should use XMultiServiceFactory::createInstanceWithArguments to avoid that
69 if (m_pOwnFormatter)
70 { // !!! this is only an emergency handling, normally this should not occur !!!
71 m_pOwnFormatter.reset();
72 SetNumberFormatter(m_pOwnFormatter.get());
75 Type aExpectedArgType = ::cppu::UnoType<css::lang::Locale>::get();
76 LanguageType eNewFormatterLanguage = LANGUAGE_SYSTEM;
77 // the default
79 for (const Any& rArg : _rArguments)
81 if (rArg.getValueType().equals(aExpectedArgType))
83 css::lang::Locale aLocale;
84 rArg >>= aLocale;
85 eNewFormatterLanguage = LanguageTag::convertToLanguageType( aLocale, false);
87 #ifdef DBG_UTIL
88 else
90 OSL_FAIL("SvNumberFormatsSupplierServiceObject::initialize : unknown argument !");
92 #endif
95 m_pOwnFormatter.reset( new SvNumberFormatter( m_xORB, eNewFormatterLanguage) );
96 m_pOwnFormatter->SetEvalDateFormat( NF_EVALDATEFORMAT_FORMAT_INTL );
97 SetNumberFormatter(m_pOwnFormatter.get());
100 OUString SAL_CALL SvNumberFormatsSupplierServiceObject::getImplementationName( )
102 return u"com.sun.star.uno.util.numbers.SvNumberFormatsSupplierServiceObject"_ustr;
105 sal_Bool SAL_CALL SvNumberFormatsSupplierServiceObject::supportsService( const OUString& _rServiceName )
107 return cppu::supportsService(this, _rServiceName);
110 Sequence< OUString > SAL_CALL SvNumberFormatsSupplierServiceObject::getSupportedServiceNames( )
112 return { u"com.sun.star.util.NumberFormatsSupplier"_ustr };
115 Reference< XPropertySet > SAL_CALL SvNumberFormatsSupplierServiceObject::getNumberFormatSettings()
117 ::osl::MutexGuard aGuard( getSharedMutex() );
118 implEnsureFormatter();
119 return SvNumberFormatsSupplierObj::getNumberFormatSettings();
122 Reference< XNumberFormats > SAL_CALL SvNumberFormatsSupplierServiceObject::getNumberFormats()
124 ::osl::MutexGuard aGuard( getSharedMutex() );
125 implEnsureFormatter();
126 return SvNumberFormatsSupplierObj::getNumberFormats();
129 sal_Int64 SAL_CALL SvNumberFormatsSupplierServiceObject::getSomething( const Sequence< sal_Int8 >& aIdentifier )
131 sal_Int64 nReturn = SvNumberFormatsSupplierObj::getSomething( aIdentifier );
132 if ( nReturn )
133 // if somebody accesses internals then we should have the formatter
134 implEnsureFormatter();
135 return nReturn;
138 void SvNumberFormatsSupplierServiceObject::implEnsureFormatter()
140 if (!m_pOwnFormatter)
142 // get the office's UI locale
143 SvtSysLocale aSysLocale;
144 css::lang::Locale aOfficeLocale = aSysLocale.GetLocaleData().getLanguageTag().getLocale();
146 // initialize with this locale
147 initialize({ Any(aOfficeLocale) });
152 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
153 com_sun_star_uno_util_numbers_SvNumberFormatsSupplierServiceObject_get_implementation(css::uno::XComponentContext* context,
154 css::uno::Sequence<css::uno::Any> const &)
156 return cppu::acquire(new SvNumberFormatsSupplierServiceObject(context));
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */