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 <tools/color.hxx>
21 #include <o3tl/any.hxx>
22 #include <osl/mutex.hxx>
23 #include <osl/diagnose.h>
24 #include <rtl/ustring.hxx>
26 #include <com/sun/star/util/Date.hpp>
27 #include <com/sun/star/util/MalformedNumberFormatException.hpp>
28 #include <com/sun/star/util/NotNumericException.hpp>
29 #include <com/sun/star/beans/PropertyAttribute.hpp>
30 #include <comphelper/propertysequence.hxx>
31 #include <cppuhelper/supportsservice.hxx>
33 #include "numfmuno.hxx"
34 #include <svl/numformat.hxx>
35 #include <svl/numuno.hxx>
36 #include <svl/zforlist.hxx>
37 #include <svl/zformat.hxx>
38 #include <svl/itemprop.hxx>
40 using namespace com::sun::star
;
42 constexpr OUStringLiteral PROPERTYNAME_FMTSTR
= u
"FormatString";
43 constexpr OUStringLiteral PROPERTYNAME_LOCALE
= u
"Locale";
44 constexpr OUStringLiteral PROPERTYNAME_TYPE
= u
"Type";
45 constexpr OUStringLiteral PROPERTYNAME_COMMENT
= u
"Comment";
46 constexpr OUStringLiteral PROPERTYNAME_CURREXT
= u
"CurrencyExtension";
47 constexpr OUStringLiteral PROPERTYNAME_CURRSYM
= u
"CurrencySymbol";
48 constexpr OUStringLiteral PROPERTYNAME_CURRABB
= u
"CurrencyAbbreviation";
49 constexpr OUStringLiteral PROPERTYNAME_DECIMALS
= u
"Decimals";
50 constexpr OUStringLiteral PROPERTYNAME_LEADING
= u
"LeadingZeros";
51 constexpr OUStringLiteral PROPERTYNAME_NEGRED
= u
"NegativeRed";
52 constexpr OUStringLiteral PROPERTYNAME_STDFORM
= u
"StandardFormat";
53 constexpr OUStringLiteral PROPERTYNAME_THOUS
= u
"ThousandsSeparator";
54 constexpr OUStringLiteral PROPERTYNAME_USERDEF
= u
"UserDefined";
56 constexpr OUStringLiteral PROPERTYNAME_NOZERO
= u
"NoZero";
57 constexpr OUStringLiteral PROPERTYNAME_NULLDATE
= u
"NullDate";
58 constexpr OUStringLiteral PROPERTYNAME_STDDEC
= u
"StandardDecimals";
59 constexpr OUStringLiteral PROPERTYNAME_TWODIGIT
= u
"TwoDigitDateStart";
61 // All without a Which-ID, Map only for PropertySetInfo
63 static const SfxItemPropertyMapEntry
* lcl_GetNumberFormatPropertyMap()
65 static const SfxItemPropertyMapEntry aNumberFormatPropertyMap_Impl
[] =
67 {PROPERTYNAME_FMTSTR
, 0, cppu::UnoType
<OUString
>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
68 {PROPERTYNAME_LOCALE
, 0, cppu::UnoType
<lang::Locale
>::get(),beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
69 {PROPERTYNAME_TYPE
, 0, cppu::UnoType
<sal_Int16
>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
70 {PROPERTYNAME_COMMENT
, 0, cppu::UnoType
<OUString
>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
71 {PROPERTYNAME_CURREXT
, 0, cppu::UnoType
<OUString
>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
72 {PROPERTYNAME_CURRSYM
, 0, cppu::UnoType
<OUString
>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
73 {PROPERTYNAME_DECIMALS
, 0, cppu::UnoType
<sal_Int16
>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
74 {PROPERTYNAME_LEADING
, 0, cppu::UnoType
<sal_Int16
>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
75 {PROPERTYNAME_NEGRED
, 0, cppu::UnoType
<bool>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
76 {PROPERTYNAME_STDFORM
, 0, cppu::UnoType
<bool>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
77 {PROPERTYNAME_THOUS
, 0, cppu::UnoType
<bool>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
78 {PROPERTYNAME_USERDEF
, 0, cppu::UnoType
<bool>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
79 {PROPERTYNAME_CURRABB
, 0, cppu::UnoType
<OUString
>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
80 { u
"", 0, css::uno::Type(), 0, 0 }
82 return aNumberFormatPropertyMap_Impl
;
85 static const SfxItemPropertyMapEntry
* lcl_GetNumberSettingsPropertyMap()
87 static const SfxItemPropertyMapEntry aNumberSettingsPropertyMap_Impl
[] =
89 {PROPERTYNAME_NOZERO
, 0, cppu::UnoType
<bool>::get(), beans::PropertyAttribute::BOUND
, 0},
90 {PROPERTYNAME_NULLDATE
, 0, cppu::UnoType
<util::Date
>::get(), beans::PropertyAttribute::BOUND
, 0},
91 {PROPERTYNAME_STDDEC
, 0, cppu::UnoType
<sal_Int16
>::get(), beans::PropertyAttribute::BOUND
, 0},
92 {PROPERTYNAME_TWODIGIT
, 0, cppu::UnoType
<sal_Int16
>::get(), beans::PropertyAttribute::BOUND
, 0},
93 { u
"", 0, css::uno::Type(), 0, 0 }
95 return aNumberSettingsPropertyMap_Impl
;
98 static LanguageType
lcl_GetLanguage( const lang::Locale
& rLocale
)
100 LanguageType eRet
= LanguageTag::convertToLanguageTypeWithFallback( rLocale
, false);
101 if ( eRet
== LANGUAGE_NONE
)
102 eRet
= LANGUAGE_SYSTEM
; //! or throw an exception?
107 SvNumberFormatterServiceObj::SvNumberFormatterServiceObj()
111 SvNumberFormatterServiceObj::~SvNumberFormatterServiceObj()
117 void SAL_CALL
SvNumberFormatterServiceObj::attachNumberFormatsSupplier( const uno::Reference
<util::XNumberFormatsSupplier
>& _xSupplier
)
119 ::rtl::Reference
< SvNumberFormatsSupplierObj
> xAutoReleaseOld
;
123 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
125 SvNumberFormatsSupplierObj
* pNew
= comphelper::getFromUnoTunnel
<SvNumberFormatsSupplierObj
>( _xSupplier
);
127 throw uno::RuntimeException(); // wrong object
129 xAutoReleaseOld
= xSupplier
;
132 m_aMutex
= xSupplier
->getSharedMutex();
137 uno::Reference
<util::XNumberFormatsSupplier
> SAL_CALL
SvNumberFormatterServiceObj::getNumberFormatsSupplier()
139 ::osl::MutexGuard
aGuard( m_aMutex
);
143 sal_Int32 SAL_CALL
SvNumberFormatterServiceObj::detectNumberFormat( sal_Int32 nKey
, const OUString
& aString
)
145 ::osl::MutexGuard
aGuard( m_aMutex
);
147 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : nullptr;
149 throw uno::RuntimeException();
151 sal_uInt32 nUKey
= nKey
;
153 if ( !pFormatter
->IsNumberFormat(aString
, nUKey
, fValue
) )
154 throw util::NotNumericException();
159 double SAL_CALL
SvNumberFormatterServiceObj::convertStringToNumber( sal_Int32 nKey
, const OUString
& aString
)
161 ::osl::MutexGuard
aGuard( m_aMutex
);
163 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : nullptr;
165 throw uno::RuntimeException();
167 sal_uInt32 nUKey
= nKey
;
169 if ( !pFormatter
->IsNumberFormat(aString
, nUKey
, fValue
) )
170 throw util::NotNumericException();
175 OUString SAL_CALL
SvNumberFormatterServiceObj::convertNumberToString( sal_Int32 nKey
, double fValue
)
177 ::osl::MutexGuard
aGuard( m_aMutex
);
180 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : nullptr;
182 throw uno::RuntimeException();
184 const Color
* pColor
= nullptr;
185 pFormatter
->GetOutputString(fValue
, nKey
, aRet
, &pColor
);
190 sal_Int32 SAL_CALL
SvNumberFormatterServiceObj::queryColorForNumber( sal_Int32 nKey
,
192 sal_Int32 aDefaultColor
)
194 ::osl::MutexGuard
aGuard( m_aMutex
);
196 util::Color nRet
= aDefaultColor
; // color = sal_Int32
197 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : nullptr;
199 throw uno::RuntimeException();
202 const Color
* pColor
= nullptr;
203 pFormatter
->GetOutputString(fValue
, nKey
, aStr
, &pColor
);
205 nRet
= sal_uInt32(*pColor
);
211 OUString SAL_CALL
SvNumberFormatterServiceObj::formatString( sal_Int32 nKey
,
212 const OUString
& aString
)
214 ::osl::MutexGuard
aGuard( m_aMutex
);
217 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : nullptr;
220 throw uno::RuntimeException();
223 const Color
* pColor
= nullptr;
224 pFormatter
->GetOutputString(aString
, nKey
, aRet
, &pColor
);
229 sal_Int32 SAL_CALL
SvNumberFormatterServiceObj::queryColorForString( sal_Int32 nKey
,
230 const OUString
& aString
,
231 sal_Int32 aDefaultColor
)
233 ::osl::MutexGuard
aGuard( m_aMutex
);
235 util::Color nRet
= aDefaultColor
; // color = sal_Int32
236 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : nullptr;
239 throw uno::RuntimeException();
243 const Color
* pColor
= nullptr;
244 pFormatter
->GetOutputString(aString
, nKey
, aStr
, &pColor
);
247 nRet
= sal_uInt32(*pColor
);
254 OUString SAL_CALL
SvNumberFormatterServiceObj::getInputString( sal_Int32 nKey
, double fValue
)
256 ::osl::MutexGuard
aGuard( m_aMutex
);
259 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : nullptr;
261 throw uno::RuntimeException();
263 pFormatter
->GetInputLineString(fValue
, nKey
, aRet
);
268 // XNumberFormatPreviewer
270 OUString SAL_CALL
SvNumberFormatterServiceObj::convertNumberToPreviewString( const OUString
& aFormat
,
272 const lang::Locale
& nLocale
,
273 sal_Bool bAllowEnglish
)
275 ::osl::MutexGuard
aGuard( m_aMutex
);
278 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : nullptr;
280 throw uno::RuntimeException();
282 LanguageType eLang
= lcl_GetLanguage( nLocale
);
283 const Color
* pColor
= nullptr;
287 bOk
= pFormatter
->GetPreviewStringGuess( aFormat
, fValue
, aRet
, &pColor
, eLang
);
289 bOk
= pFormatter
->GetPreviewString( aFormat
, fValue
, aRet
, &pColor
, eLang
);
292 throw util::MalformedNumberFormatException();
297 sal_Int32 SAL_CALL
SvNumberFormatterServiceObj::queryPreviewColorForNumber( const OUString
& aFormat
,
299 const lang::Locale
& nLocale
,
300 sal_Bool bAllowEnglish
,
301 sal_Int32 aDefaultColor
)
303 ::osl::MutexGuard
aGuard( m_aMutex
);
305 util::Color nRet
= aDefaultColor
; // color = sal_Int32
306 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : nullptr;
308 throw uno::RuntimeException();
311 LanguageType eLang
= lcl_GetLanguage( nLocale
);
312 const Color
* pColor
= nullptr;
316 bOk
= pFormatter
->GetPreviewStringGuess( aFormat
, fValue
, aOutString
, &pColor
, eLang
);
318 bOk
= pFormatter
->GetPreviewString( aFormat
, fValue
, aOutString
, &pColor
, eLang
);
321 throw util::MalformedNumberFormatException();
324 nRet
= sal_uInt32(*pColor
);
332 OUString SAL_CALL
SvNumberFormatterServiceObj::getImplementationName()
334 return "com.sun.star.uno.util.numbers.SvNumberFormatterServiceObject";
337 sal_Bool SAL_CALL
SvNumberFormatterServiceObj::supportsService( const OUString
& ServiceName
)
339 return cppu::supportsService( this, ServiceName
);
342 uno::Sequence
<OUString
> SAL_CALL
SvNumberFormatterServiceObj::getSupportedServiceNames()
344 return { "com.sun.star.util.NumberFormatter" };
347 SvNumberFormatsObj::SvNumberFormatsObj( SvNumberFormatsSupplierObj
& _rParent
, ::comphelper::SharedMutex
const & _rMutex
)
348 :m_xSupplier( &_rParent
)
353 SvNumberFormatsObj::~SvNumberFormatsObj()
359 uno::Reference
<beans::XPropertySet
> SAL_CALL
SvNumberFormatsObj::getByKey( sal_Int32 nKey
)
361 ::osl::MutexGuard
aGuard( m_aMutex
);
363 SvNumberFormatter
* pFormatter
= m_xSupplier
->GetNumberFormatter();
364 const SvNumberformat
* pFormat
= pFormatter
? pFormatter
->GetEntry(nKey
) : nullptr;
366 throw uno::RuntimeException();
368 return new SvNumberFormatObj( *m_xSupplier
, nKey
, m_aMutex
);
371 uno::Sequence
<sal_Int32
> SAL_CALL
SvNumberFormatsObj::queryKeys( sal_Int16 nType
,
372 const lang::Locale
& nLocale
,
375 ::osl::MutexGuard
aGuard( m_aMutex
);
377 SvNumberFormatter
* pFormatter
= m_xSupplier
->GetNumberFormatter();
379 throw uno::RuntimeException();
381 sal_uInt32 nIndex
= 0;
382 LanguageType eLang
= lcl_GetLanguage( nLocale
);
383 SvNumberFormatTable
& rTable
= bCreate
?
384 pFormatter
->ChangeCL( static_cast<SvNumFormatType
>(nType
), nIndex
, eLang
) :
385 pFormatter
->GetEntryTable( static_cast<SvNumFormatType
>(nType
), nIndex
, eLang
);
386 sal_uInt32 nCount
= rTable
.size();
387 uno::Sequence
<sal_Int32
> aSeq(nCount
);
388 sal_Int32
* pAry
= aSeq
.getArray();
390 for (const auto& rEntry
: rTable
)
392 pAry
[i
] = rEntry
.first
;
398 sal_Int32 SAL_CALL
SvNumberFormatsObj::queryKey( const OUString
& aFormat
,
399 const lang::Locale
& nLocale
,
402 ::osl::MutexGuard
aGuard( m_aMutex
);
404 SvNumberFormatter
* pFormatter
= m_xSupplier
->GetNumberFormatter();
406 throw uno::RuntimeException();
408 LanguageType eLang
= lcl_GetLanguage( nLocale
);
411 //! FIXME: Something still needs to happen here ...
413 sal_Int32 nRet
= pFormatter
->GetEntryKey( aFormat
, eLang
);
417 sal_Int32 SAL_CALL
SvNumberFormatsObj::addNew( const OUString
& aFormat
,
418 const lang::Locale
& nLocale
)
420 ::osl::MutexGuard
aGuard( m_aMutex
);
423 SvNumberFormatter
* pFormatter
= m_xSupplier
->GetNumberFormatter();
425 throw uno::RuntimeException();
427 OUString aFormStr
= aFormat
;
428 LanguageType eLang
= lcl_GetLanguage( nLocale
);
430 sal_Int32 nCheckPos
= 0;
431 SvNumFormatType nType
= SvNumFormatType::ALL
;
432 bool bOk
= pFormatter
->PutEntry( aFormStr
, nCheckPos
, nType
, nKey
, eLang
);
437 throw util::MalformedNumberFormatException(); // Invalid Format
440 throw uno::RuntimeException(); // Other error (e.g. already added)
445 sal_Int32 SAL_CALL
SvNumberFormatsObj::addNewConverted( const OUString
& aFormat
,
446 const lang::Locale
& nLocale
,
447 const lang::Locale
& nNewLocale
)
449 ::osl::MutexGuard
aGuard( m_aMutex
);
452 SvNumberFormatter
* pFormatter
= m_xSupplier
->GetNumberFormatter();
454 throw uno::RuntimeException();
456 OUString aFormStr
= aFormat
;
457 LanguageType eLang
= lcl_GetLanguage( nLocale
);
458 LanguageType eNewLang
= lcl_GetLanguage( nNewLocale
);
460 sal_Int32 nCheckPos
= 0;
461 SvNumFormatType nType
= SvNumFormatType::ALL
;
462 // This is used also when reading OOXML documents, there's no indicator
463 // whether to convert date particle order as well, so don't. See tdf#119013
464 bool bOk
= pFormatter
->PutandConvertEntry( aFormStr
, nCheckPos
, nType
, nKey
, eLang
, eNewLang
, false);
469 throw util::MalformedNumberFormatException(); // Invalid format
472 throw uno::RuntimeException(); // Other error (e.g. already added)
477 void SAL_CALL
SvNumberFormatsObj::removeByKey( sal_Int32 nKey
)
479 ::osl::MutexGuard
aGuard( m_aMutex
);
480 SvNumberFormatter
* pFormatter
= m_xSupplier
->GetNumberFormatter();
484 pFormatter
->DeleteEntry(nKey
);
488 OUString SAL_CALL
SvNumberFormatsObj::generateFormat( sal_Int32 nBaseKey
,
489 const lang::Locale
& nLocale
,
491 sal_Bool bRed
, sal_Int16 nDecimals
,
494 ::osl::MutexGuard
aGuard( m_aMutex
);
496 SvNumberFormatter
* pFormatter
= m_xSupplier
->GetNumberFormatter();
498 throw uno::RuntimeException();
500 LanguageType eLang
= lcl_GetLanguage( nLocale
);
501 OUString aRet
= pFormatter
->GenerateFormat(nBaseKey
, eLang
, bThousands
, bRed
, nDecimals
, nLeading
);
505 // XNumberFormatTypes
507 sal_Int32 SAL_CALL
SvNumberFormatsObj::getStandardIndex( const lang::Locale
& nLocale
)
509 ::osl::MutexGuard
aGuard( m_aMutex
);
511 SvNumberFormatter
* pFormatter
= m_xSupplier
->GetNumberFormatter();
513 throw uno::RuntimeException();
515 LanguageType eLang
= lcl_GetLanguage( nLocale
);
516 sal_Int32 nRet
= pFormatter
->GetStandardIndex(eLang
);
520 sal_Int32 SAL_CALL
SvNumberFormatsObj::getStandardFormat( sal_Int16 nType
, const lang::Locale
& nLocale
)
522 ::osl::MutexGuard
aGuard( m_aMutex
);
524 SvNumberFormatter
* pFormatter
= m_xSupplier
->GetNumberFormatter();
526 throw uno::RuntimeException();
528 LanguageType eLang
= lcl_GetLanguage( nLocale
);
529 // Mask out "defined" bit, so type from an existing number format
530 // can directly be used for getStandardFormat
531 SvNumFormatType nType2
= static_cast<SvNumFormatType
>(nType
);
532 nType2
&= ~SvNumFormatType::DEFINED
;
533 sal_Int32 nRet
= pFormatter
->GetStandardFormat(nType2
, eLang
);
537 sal_Int32 SAL_CALL
SvNumberFormatsObj::getFormatIndex( sal_Int16 nIndex
, const lang::Locale
& nLocale
)
539 ::osl::MutexGuard
aGuard( m_aMutex
);
541 SvNumberFormatter
* pFormatter
= m_xSupplier
->GetNumberFormatter();
543 throw uno::RuntimeException();
545 LanguageType eLang
= lcl_GetLanguage( nLocale
);
546 sal_Int32 nRet
= pFormatter
->GetFormatIndex( static_cast<NfIndexTableOffset
>(nIndex
), eLang
);
550 sal_Bool SAL_CALL
SvNumberFormatsObj::isTypeCompatible( sal_Int16 nOldType
, sal_Int16 nNewType
)
552 ::osl::MutexGuard
aGuard( m_aMutex
);
554 return SvNumberFormatter::IsCompatible( static_cast<SvNumFormatType
>(nOldType
), static_cast<SvNumFormatType
>(nNewType
) );
557 sal_Int32 SAL_CALL
SvNumberFormatsObj::getFormatForLocale( sal_Int32 nKey
, const lang::Locale
& nLocale
)
559 ::osl::MutexGuard
aGuard( m_aMutex
);
561 SvNumberFormatter
* pFormatter
= m_xSupplier
->GetNumberFormatter();
563 throw uno::RuntimeException();
565 LanguageType eLang
= lcl_GetLanguage( nLocale
);
566 sal_Int32 nRet
= pFormatter
->GetFormatForLanguageIfBuiltIn(nKey
, eLang
);
572 OUString SAL_CALL
SvNumberFormatsObj::getImplementationName()
574 return "SvNumberFormatsObj";
577 sal_Bool SAL_CALL
SvNumberFormatsObj::supportsService( const OUString
& ServiceName
)
579 return cppu::supportsService( this, ServiceName
);
582 uno::Sequence
<OUString
> SAL_CALL
SvNumberFormatsObj::getSupportedServiceNames()
584 return { "com.sun.star.util.NumberFormats" };
587 SvNumberFormatObj::SvNumberFormatObj( SvNumberFormatsSupplierObj
& rParent
, sal_uLong nK
, const ::comphelper::SharedMutex
& _rMutex
)
588 :m_xSupplier( &rParent
)
594 SvNumberFormatObj::~SvNumberFormatObj()
600 uno::Reference
<beans::XPropertySetInfo
> SAL_CALL
SvNumberFormatObj::getPropertySetInfo()
602 static uno::Reference
<beans::XPropertySetInfo
> aRef
=
603 new SfxItemPropertySetInfo( lcl_GetNumberFormatPropertyMap() );
607 void SAL_CALL
SvNumberFormatObj::setPropertyValue( const OUString
&,
610 throw beans::UnknownPropertyException(); // Everything is read-only
613 uno::Any SAL_CALL
SvNumberFormatObj::getPropertyValue( const OUString
& aPropertyName
)
615 ::osl::MutexGuard
aGuard( m_aMutex
);
618 SvNumberFormatter
* pFormatter
= m_xSupplier
->GetNumberFormatter();
619 const SvNumberformat
* pFormat
= pFormatter
? pFormatter
->GetEntry(nKey
) : nullptr;
621 throw uno::RuntimeException();
623 bool bThousand
, bRed
;
624 sal_uInt16 nDecimals
, nLeading
;
626 if (aPropertyName
== PROPERTYNAME_FMTSTR
)
628 aRet
<<= pFormat
->GetFormatstring();
630 else if (aPropertyName
== PROPERTYNAME_LOCALE
)
632 lang::Locale
aLocale( LanguageTag::convertToLocale( pFormat
->GetLanguage(), false));
635 else if (aPropertyName
== PROPERTYNAME_TYPE
)
637 aRet
<<= static_cast<sal_Int16
>( pFormat
->GetType() );
639 else if (aPropertyName
== PROPERTYNAME_COMMENT
)
641 aRet
<<= pFormat
->GetComment();
643 else if (aPropertyName
== PROPERTYNAME_STDFORM
)
645 //! Pass through SvNumberformat Member bStandard?
646 aRet
<<= ( ( nKey
% SV_COUNTRY_LANGUAGE_OFFSET
) == 0 );
648 else if (aPropertyName
== PROPERTYNAME_USERDEF
)
650 aRet
<<= bool( pFormat
->GetType() & SvNumFormatType::DEFINED
);
652 else if (aPropertyName
== PROPERTYNAME_DECIMALS
)
654 pFormat
->GetFormatSpecialInfo( bThousand
, bRed
, nDecimals
, nLeading
);
655 aRet
<<= static_cast<sal_Int16
>(nDecimals
);
657 else if (aPropertyName
== PROPERTYNAME_LEADING
)
659 pFormat
->GetFormatSpecialInfo( bThousand
, bRed
, nDecimals
, nLeading
);
660 aRet
<<= static_cast<sal_Int16
>(nLeading
);
662 else if (aPropertyName
== PROPERTYNAME_NEGRED
)
664 pFormat
->GetFormatSpecialInfo( bThousand
, bRed
, nDecimals
, nLeading
);
667 else if (aPropertyName
== PROPERTYNAME_THOUS
)
669 pFormat
->GetFormatSpecialInfo( bThousand
, bRed
, nDecimals
, nLeading
);
672 else if (aPropertyName
== PROPERTYNAME_CURRSYM
)
674 OUString aSymbol
, aExt
;
675 pFormat
->GetNewCurrencySymbol( aSymbol
, aExt
);
678 else if (aPropertyName
== PROPERTYNAME_CURREXT
)
680 OUString aSymbol
, aExt
;
681 pFormat
->GetNewCurrencySymbol( aSymbol
, aExt
);
684 else if (aPropertyName
== PROPERTYNAME_CURRABB
)
686 OUString aSymbol
, aExt
;
688 pFormat
->GetNewCurrencySymbol( aSymbol
, aExt
);
689 const NfCurrencyEntry
* pCurr
= SvNumberFormatter::GetCurrencyEntry( bBank
,
690 aSymbol
, aExt
, pFormat
->GetLanguage() );
692 aRet
<<= pCurr
->GetBankSymbol();
697 throw beans::UnknownPropertyException(aPropertyName
);
702 void SAL_CALL
SvNumberFormatObj::addPropertyChangeListener( const OUString
&,
703 const uno::Reference
<beans::XPropertyChangeListener
>&)
705 OSL_FAIL("not implemented");
708 void SAL_CALL
SvNumberFormatObj::removePropertyChangeListener( const OUString
&,
709 const uno::Reference
<beans::XPropertyChangeListener
>&)
711 OSL_FAIL("not implemented");
714 void SAL_CALL
SvNumberFormatObj::addVetoableChangeListener( const OUString
&,
715 const uno::Reference
<beans::XVetoableChangeListener
>&)
717 OSL_FAIL("not implemented");
720 void SAL_CALL
SvNumberFormatObj::removeVetoableChangeListener( const OUString
&,
721 const uno::Reference
<beans::XVetoableChangeListener
>&)
723 OSL_FAIL("not implemented");
728 uno::Sequence
<beans::PropertyValue
> SAL_CALL
SvNumberFormatObj::getPropertyValues()
730 ::osl::MutexGuard
aGuard( m_aMutex
);
732 SvNumberFormatter
* pFormatter
= m_xSupplier
->GetNumberFormatter();
733 const SvNumberformat
* pFormat
= pFormatter
? pFormatter
->GetEntry(nKey
) : nullptr;
735 throw uno::RuntimeException();
737 OUString aSymbol
, aExt
;
740 pFormat
->GetNewCurrencySymbol( aSymbol
, aExt
);
741 const NfCurrencyEntry
* pCurr
= SvNumberFormatter::GetCurrencyEntry( bBank
,
742 aSymbol
, aExt
, pFormat
->GetLanguage() );
744 aAbb
= pCurr
->GetBankSymbol();
746 OUString aFmtStr
= pFormat
->GetFormatstring();
747 OUString aComment
= pFormat
->GetComment();
748 bool bStandard
= ( ( nKey
% SV_COUNTRY_LANGUAGE_OFFSET
) == 0 );
749 //! Pass through SvNumberformat Member bStandard?
750 bool bUserDef( pFormat
->GetType() & SvNumFormatType::DEFINED
);
751 bool bThousand
, bRed
;
752 sal_uInt16 nDecimals
, nLeading
;
753 pFormat
->GetFormatSpecialInfo( bThousand
, bRed
, nDecimals
, nLeading
);
754 lang::Locale
aLocale( LanguageTag( pFormat
->GetLanguage()).getLocale());
756 uno::Sequence
<beans::PropertyValue
> aSeq( comphelper::InitPropertySequence({
757 { PROPERTYNAME_FMTSTR
, uno::Any(aFmtStr
) },
758 { PROPERTYNAME_LOCALE
, uno::Any(aLocale
) },
759 { PROPERTYNAME_TYPE
, uno::Any(sal_Int16( pFormat
->GetType() )) },
760 { PROPERTYNAME_COMMENT
, uno::Any(aComment
) },
761 { PROPERTYNAME_STDFORM
, uno::Any(bStandard
) },
762 { PROPERTYNAME_USERDEF
, uno::Any(bUserDef
) },
763 { PROPERTYNAME_DECIMALS
, uno::Any(sal_Int16( nDecimals
)) },
764 { PROPERTYNAME_LEADING
, uno::Any(sal_Int16( nLeading
)) },
765 { PROPERTYNAME_NEGRED
, uno::Any(bRed
) },
766 { PROPERTYNAME_THOUS
, uno::Any(bThousand
) },
767 { PROPERTYNAME_CURRSYM
, uno::Any(aSymbol
) },
768 { PROPERTYNAME_CURREXT
, uno::Any(aExt
) },
769 { PROPERTYNAME_CURRABB
, uno::Any(aAbb
) }
775 void SAL_CALL
SvNumberFormatObj::setPropertyValues( const uno::Sequence
<beans::PropertyValue
>& )
777 throw beans::UnknownPropertyException(); // Everything is read-only
782 OUString SAL_CALL
SvNumberFormatObj::getImplementationName()
784 return "SvNumberFormatObj";
787 sal_Bool SAL_CALL
SvNumberFormatObj::supportsService( const OUString
& ServiceName
)
789 return cppu::supportsService( this, ServiceName
);
792 uno::Sequence
<OUString
> SAL_CALL
SvNumberFormatObj::getSupportedServiceNames()
794 return { "com.sun.star.util.NumberFormatProperties" };
797 SvNumberFormatSettingsObj::SvNumberFormatSettingsObj( SvNumberFormatsSupplierObj
& rParent
, const ::comphelper::SharedMutex
& _rMutex
)
798 :m_xSupplier( &rParent
)
803 SvNumberFormatSettingsObj::~SvNumberFormatSettingsObj()
809 uno::Reference
<beans::XPropertySetInfo
> SAL_CALL
SvNumberFormatSettingsObj::getPropertySetInfo()
811 static uno::Reference
<beans::XPropertySetInfo
> aRef
=
812 new SfxItemPropertySetInfo( lcl_GetNumberSettingsPropertyMap() );
816 void SAL_CALL
SvNumberFormatSettingsObj::setPropertyValue( const OUString
& aPropertyName
,
817 const uno::Any
& aValue
)
819 ::osl::MutexGuard
aGuard( m_aMutex
);
821 SvNumberFormatter
* pFormatter
= m_xSupplier
->GetNumberFormatter();
823 throw uno::RuntimeException();
825 if (aPropertyName
== PROPERTYNAME_NOZERO
)
827 // operator >>= shouldn't be used for bool (?)
828 if ( auto b
= o3tl::tryAccess
<bool>(aValue
) )
829 pFormatter
->SetNoZero( *b
);
831 else if (aPropertyName
== PROPERTYNAME_NULLDATE
)
834 if ( aValue
>>= aDate
)
835 pFormatter
->ChangeNullDate( aDate
.Day
, aDate
.Month
, aDate
.Year
);
837 else if (aPropertyName
== PROPERTYNAME_STDDEC
)
839 sal_Int16 nInt16
= sal_Int16();
840 if ( aValue
>>= nInt16
)
841 pFormatter
->ChangeStandardPrec( nInt16
);
843 else if (aPropertyName
== PROPERTYNAME_TWODIGIT
)
845 sal_Int16 nInt16
= sal_Int16();
846 if ( aValue
>>= nInt16
)
847 pFormatter
->SetYear2000( nInt16
);
850 throw beans::UnknownPropertyException(aPropertyName
);
854 uno::Any SAL_CALL
SvNumberFormatSettingsObj::getPropertyValue( const OUString
& aPropertyName
)
856 ::osl::MutexGuard
aGuard( m_aMutex
);
859 SvNumberFormatter
* pFormatter
= m_xSupplier
->GetNumberFormatter();
861 throw uno::RuntimeException();
863 if (aPropertyName
== PROPERTYNAME_NOZERO
)
865 aRet
<<= pFormatter
->GetNoZero();
867 else if (aPropertyName
== PROPERTYNAME_NULLDATE
)
869 const Date
& rDate
= pFormatter
->GetNullDate();
870 aRet
<<= rDate
.GetUNODate();
872 else if (aPropertyName
== PROPERTYNAME_STDDEC
)
873 aRet
<<= static_cast<sal_Int16
>( pFormatter
->GetStandardPrec() );
874 else if (aPropertyName
== PROPERTYNAME_TWODIGIT
)
875 aRet
<<= static_cast<sal_Int16
>( pFormatter
->GetYear2000() );
877 throw beans::UnknownPropertyException(aPropertyName
);
882 void SAL_CALL
SvNumberFormatSettingsObj::addPropertyChangeListener( const OUString
&,
883 const uno::Reference
<beans::XPropertyChangeListener
>&)
885 OSL_FAIL("not implemented");
888 void SAL_CALL
SvNumberFormatSettingsObj::removePropertyChangeListener( const OUString
&,
889 const uno::Reference
<beans::XPropertyChangeListener
>&)
891 OSL_FAIL("not implemented");
894 void SAL_CALL
SvNumberFormatSettingsObj::addVetoableChangeListener( const OUString
&,
895 const uno::Reference
<beans::XVetoableChangeListener
>&)
897 OSL_FAIL("not implemented");
900 void SAL_CALL
SvNumberFormatSettingsObj::removeVetoableChangeListener( const OUString
&,
901 const uno::Reference
<beans::XVetoableChangeListener
>&)
903 OSL_FAIL("not implemented");
908 OUString SAL_CALL
SvNumberFormatSettingsObj::getImplementationName()
910 return "SvNumberFormatSettingsObj";
913 sal_Bool SAL_CALL
SvNumberFormatSettingsObj::supportsService( const OUString
& ServiceName
)
915 return cppu::supportsService( this, ServiceName
);
918 uno::Sequence
<OUString
> SAL_CALL
SvNumberFormatSettingsObj::getSupportedServiceNames()
920 return { "com.sun.star.util.NumberFormatSettings" };
924 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
925 com_sun_star_uno_util_numbers_SvNumberFormatterServiceObject_get_implementation(css::uno::XComponentContext
*,
926 css::uno::Sequence
<css::uno::Any
> const &)
928 return cppu::acquire(new SvNumberFormatterServiceObj());
932 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */