LibreOffice Module svl (master) 1
supservs.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "supservs.hxx"
21#include <com/sun/star/lang/Locale.hpp>
25#include <cppuhelper/weak.hxx>
27#include <svl/numformat.hxx>
28#include <tools/debug.hxx>
29#include <osl/mutex.hxx>
30#include <utility>
31#include <osl/diagnose.h>
32
33using namespace ::com::sun::star::uno;
34using namespace ::com::sun::star::lang;
35using namespace ::com::sun::star::beans;
36using namespace ::com::sun::star::util;
37using namespace ::utl;
38
39
40SvNumberFormatsSupplierServiceObject::SvNumberFormatsSupplierServiceObject(css::uno::Reference< css::uno::XComponentContext > _xORB)
41 :m_xORB(std::move(_xORB))
42{
43}
44
46{
47}
48
50{
51 Any aReturn = ::cppu::queryInterface(_rType,
52 static_cast< XInitialization* >(this),
53 static_cast< XServiceInfo* >(this)
54 );
55
56 if (!aReturn.hasValue())
58
59 return aReturn;
60}
61
62void SAL_CALL SvNumberFormatsSupplierServiceObject::initialize( const Sequence< Any >& _rArguments )
63{
64 ::osl::MutexGuard aGuard( getSharedMutex() );
65
66 DBG_ASSERT(m_pOwnFormatter == nullptr,
67 "SvNumberFormatsSupplierServiceObject::initialize : already initialized !");
68 // maybe you already called a method which needed the formatter
69 // you should use XMultiServiceFactory::createInstanceWithArguments to avoid that
71 { // !!! this is only an emergency handling, normally this should not occur !!!
72 m_pOwnFormatter.reset();
74 }
75
77 LanguageType eNewFormatterLanguage = LANGUAGE_SYSTEM;
78 // the default
79
80 for (const Any& rArg : _rArguments)
81 {
82 if (rArg.getValueType().equals(aExpectedArgType))
83 {
84 css::lang::Locale aLocale;
85 rArg >>= aLocale;
86 eNewFormatterLanguage = LanguageTag::convertToLanguageType( aLocale, false);
87 }
88#ifdef DBG_UTIL
89 else
90 {
91 OSL_FAIL("SvNumberFormatsSupplierServiceObject::initialize : unknown argument !");
92 }
93#endif
94 }
95
96 m_pOwnFormatter.reset( new SvNumberFormatter( m_xORB, eNewFormatterLanguage) );
99}
100
102{
103 return "com.sun.star.uno.util.numbers.SvNumberFormatsSupplierServiceObject";
104}
105
107{
108 return cppu::supportsService(this, _rServiceName);
109}
110
112{
113 return { "com.sun.star.util.NumberFormatsSupplier" };
114}
115
117{
118 ::osl::MutexGuard aGuard( getSharedMutex() );
121}
122
123Reference< XNumberFormats > SAL_CALL SvNumberFormatsSupplierServiceObject::getNumberFormats()
124{
125 ::osl::MutexGuard aGuard( getSharedMutex() );
128}
129
131{
132 sal_Int64 nReturn = SvNumberFormatsSupplierObj::getSomething( aIdentifier );
133 if ( nReturn )
134 // if somebody accesses internals then we should have the formatter
136 return nReturn;
137}
138
140{
141 if (!m_pOwnFormatter)
142 {
143 // get the office's UI locale
144 SvtSysLocale aSysLocale;
145 css::lang::Locale aOfficeLocale = aSysLocale.GetLocaleData().getLanguageTag().getLocale();
146
147 // initialize with this locale
148 initialize({ Any(aOfficeLocale) });
149 }
150}
151
152
153extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
155 css::uno::Sequence<css::uno::Any> const &)
156{
157 return cppu::acquire(new SvNumberFormatsSupplierServiceObject(context));
158}
159
160
161/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
static LanguageType convertToLanguageType(const css::lang::Locale &rLocale, bool bResolveSystem=true)
const LanguageTag & getLanguageTag() const
void SetNumberFormatter(SvNumberFormatter *pNew)
Definition: numuno.cxx:63
virtual css::uno::Reference< css::beans::XPropertySet > SAL_CALL getNumberFormatSettings() override
Definition: numuno.cxx:71
virtual css::uno::Reference< css::util::XNumberFormats > SAL_CALL getNumberFormats() override
Definition: numuno.cxx:78
SvNumberFormatsSupplierServiceObject - a number formats supplier which.
Definition: supservs.hxx:40
virtual css::uno::Reference< css::beans::XPropertySet > SAL_CALL getNumberFormatSettings() override
Definition: supservs.cxx:116
SvNumberFormatsSupplierServiceObject(css::uno::Reference< css::uno::XComponentContext > _xORB)
Definition: supservs.cxx:40
std::unique_ptr< SvNumberFormatter > m_pOwnFormatter
Definition: supservs.hxx:41
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: supservs.cxx:111
virtual css::uno::Reference< css::util::XNumberFormats > SAL_CALL getNumberFormats() override
Definition: supservs.cxx:123
virtual OUString SAL_CALL getImplementationName() override
Definition: supservs.cxx:101
virtual ~SvNumberFormatsSupplierServiceObject() override
Definition: supservs.cxx:45
css::uno::Reference< css::uno::XComponentContext > m_xORB
Definition: supservs.hxx:42
virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type &_rType) override
Definition: supservs.cxx:49
virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence< sal_Int8 > &aIdentifier) override
Definition: supservs.cxx:130
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: supservs.cxx:106
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
Definition: supservs.cxx:62
const LocaleDataWrapper & GetLocaleData() const
css::uno::Type const & get()
virtual css::uno::Any SAL_CALL queryAggregation(css::uno::Type const &rType) SAL_OVERRIDE
#define DBG_ASSERT(sCon, aError)
#define LANGUAGE_SYSTEM
Type
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_uno_util_numbers_SvNumberFormatsSupplierServiceObject_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Definition: supservs.cxx:154
unsigned char sal_Bool
@ NF_EVALDATEFORMAT_FORMAT_INTL
First try the DateFormat from the date format passed.
Definition: zforlist.hxx:279