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 <i18nlangtag/mslangid.hxx>
22 #include <o3tl/any.hxx>
23 #include <osl/mutex.hxx>
24 #include <osl/diagnose.h>
25 #include <rtl/ustring.hxx>
27 #include <com/sun/star/util/Date.hpp>
28 #include <com/sun/star/util/MalformedNumberFormatException.hpp>
29 #include <com/sun/star/util/NotNumericException.hpp>
30 #include <com/sun/star/beans/PropertyAttribute.hpp>
31 #include <comphelper/propertysequence.hxx>
32 #include <cppuhelper/supportsservice.hxx>
34 #include "numfmuno.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 #define PROPERTYNAME_FMTSTR "FormatString"
43 #define PROPERTYNAME_LOCALE "Locale"
44 #define PROPERTYNAME_TYPE "Type"
45 #define PROPERTYNAME_COMMENT "Comment"
46 #define PROPERTYNAME_CURREXT "CurrencyExtension"
47 #define PROPERTYNAME_CURRSYM "CurrencySymbol"
48 #define PROPERTYNAME_CURRABB "CurrencyAbbreviation"
49 #define PROPERTYNAME_DECIMALS "Decimals"
50 #define PROPERTYNAME_LEADING "LeadingZeros"
51 #define PROPERTYNAME_NEGRED "NegativeRed"
52 #define PROPERTYNAME_STDFORM "StandardFormat"
53 #define PROPERTYNAME_THOUS "ThousandsSeparator"
54 #define PROPERTYNAME_USERDEF "UserDefined"
56 #define PROPERTYNAME_NOZERO "NoZero"
57 #define PROPERTYNAME_NULLDATE "NullDate"
58 #define PROPERTYNAME_STDDEC "StandardDecimals"
59 #define PROPERTYNAME_TWODIGIT "TwoDigitDateStart"
61 // All without a Which-ID, Map only for PropertySetInfo
63 static const SfxItemPropertyMapEntry
* lcl_GetNumberFormatPropertyMap()
65 static const SfxItemPropertyMapEntry aNumberFormatPropertyMap_Impl
[] =
67 {OUString(PROPERTYNAME_FMTSTR
), 0, cppu::UnoType
<OUString
>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
68 {OUString(PROPERTYNAME_LOCALE
), 0, cppu::UnoType
<lang::Locale
>::get(),beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
69 {OUString(PROPERTYNAME_TYPE
), 0, cppu::UnoType
<sal_Int16
>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
70 {OUString(PROPERTYNAME_COMMENT
), 0, cppu::UnoType
<OUString
>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
71 {OUString(PROPERTYNAME_CURREXT
), 0, cppu::UnoType
<OUString
>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
72 {OUString(PROPERTYNAME_CURRSYM
), 0, cppu::UnoType
<OUString
>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
73 {OUString(PROPERTYNAME_DECIMALS
), 0, cppu::UnoType
<sal_Int16
>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
74 {OUString(PROPERTYNAME_LEADING
), 0, cppu::UnoType
<sal_Int16
>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
75 {OUString(PROPERTYNAME_NEGRED
), 0, cppu::UnoType
<bool>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
76 {OUString(PROPERTYNAME_STDFORM
), 0, cppu::UnoType
<bool>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
77 {OUString(PROPERTYNAME_THOUS
), 0, cppu::UnoType
<bool>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
78 {OUString(PROPERTYNAME_USERDEF
), 0, cppu::UnoType
<bool>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
79 {OUString(PROPERTYNAME_CURRABB
), 0, cppu::UnoType
<OUString
>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
80 { OUString(), 0, css::uno::Type(), 0, 0 }
82 return aNumberFormatPropertyMap_Impl
;
85 static const SfxItemPropertyMapEntry
* lcl_GetNumberSettingsPropertyMap()
87 static const SfxItemPropertyMapEntry aNumberSettingsPropertyMap_Impl
[] =
89 {OUString(PROPERTYNAME_NOZERO
), 0, cppu::UnoType
<bool>::get(), beans::PropertyAttribute::BOUND
, 0},
90 {OUString(PROPERTYNAME_NULLDATE
), 0, cppu::UnoType
<util::Date
>::get(), beans::PropertyAttribute::BOUND
, 0},
91 {OUString(PROPERTYNAME_STDDEC
), 0, cppu::UnoType
<sal_Int16
>::get(), beans::PropertyAttribute::BOUND
, 0},
92 {OUString(PROPERTYNAME_TWODIGIT
), 0, cppu::UnoType
<sal_Int16
>::get(), beans::PropertyAttribute::BOUND
, 0},
93 { OUString(), 0, css::uno::Type(), 0, 0 }
95 return aNumberSettingsPropertyMap_Impl
;
98 static LanguageType
lcl_GetLanguage( const lang::Locale
& rLocale
)
100 LanguageType eRet
= LanguageTag::convertToLanguageType( rLocale
, false);
101 if ( eRet
== LANGUAGE_NONE
)
102 eRet
= LANGUAGE_SYSTEM
; //! or throw an exception?
107 SvNumberFormatterServiceObj::SvNumberFormatterServiceObj()
112 SvNumberFormatterServiceObj::~SvNumberFormatterServiceObj()
118 void SAL_CALL
SvNumberFormatterServiceObj::attachNumberFormatsSupplier( const uno::Reference
<util::XNumberFormatsSupplier
>& _xSupplier
)
120 ::rtl::Reference
< SvNumberFormatsSupplierObj
> xAutoReleaseOld
;
124 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
126 SvNumberFormatsSupplierObj
* pNew
= SvNumberFormatsSupplierObj::getImplementation( _xSupplier
);
128 throw uno::RuntimeException(); // wrong object
130 xAutoReleaseOld
= xSupplier
;
133 m_aMutex
= xSupplier
->getSharedMutex();
138 uno::Reference
<util::XNumberFormatsSupplier
> SAL_CALL
SvNumberFormatterServiceObj::getNumberFormatsSupplier()
140 ::osl::MutexGuard
aGuard( m_aMutex
);
141 return xSupplier
.get();
144 sal_Int32 SAL_CALL
SvNumberFormatterServiceObj::detectNumberFormat( sal_Int32 nKey
, const OUString
& aString
)
146 ::osl::MutexGuard
aGuard( m_aMutex
);
148 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : nullptr;
150 throw uno::RuntimeException();
152 sal_uInt32 nUKey
= nKey
;
154 if ( !pFormatter
->IsNumberFormat(aString
, nUKey
, fValue
) )
155 throw util::NotNumericException();
160 double SAL_CALL
SvNumberFormatterServiceObj::convertStringToNumber( sal_Int32 nKey
, const OUString
& aString
)
162 ::osl::MutexGuard
aGuard( m_aMutex
);
164 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : nullptr;
166 throw uno::RuntimeException();
168 sal_uInt32 nUKey
= nKey
;
170 if ( !pFormatter
->IsNumberFormat(aString
, nUKey
, fValue
) )
171 throw util::NotNumericException();
176 OUString SAL_CALL
SvNumberFormatterServiceObj::convertNumberToString( sal_Int32 nKey
, double fValue
)
178 ::osl::MutexGuard
aGuard( m_aMutex
);
181 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : nullptr;
183 throw uno::RuntimeException();
185 Color
* pColor
= nullptr;
186 pFormatter
->GetOutputString(fValue
, nKey
, aRet
, &pColor
);
191 util::Color SAL_CALL
SvNumberFormatterServiceObj::queryColorForNumber( sal_Int32 nKey
,
193 util::Color aDefaultColor
)
195 ::osl::MutexGuard
aGuard( m_aMutex
);
197 util::Color nRet
= aDefaultColor
; // color = sal_Int32
198 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : nullptr;
200 throw uno::RuntimeException();
203 Color
* pColor
= nullptr;
204 pFormatter
->GetOutputString(fValue
, nKey
, aStr
, &pColor
);
206 nRet
= sal_uInt32(*pColor
);
212 OUString SAL_CALL
SvNumberFormatterServiceObj::formatString( sal_Int32 nKey
,
213 const OUString
& aString
)
215 ::osl::MutexGuard
aGuard( m_aMutex
);
218 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : nullptr;
221 throw uno::RuntimeException();
224 Color
* pColor
= nullptr;
225 pFormatter
->GetOutputString(aString
, nKey
, aRet
, &pColor
);
230 util::Color SAL_CALL
SvNumberFormatterServiceObj::queryColorForString( sal_Int32 nKey
,
231 const OUString
& aString
,
232 util::Color aDefaultColor
)
234 ::osl::MutexGuard
aGuard( m_aMutex
);
236 util::Color nRet
= aDefaultColor
; // color = sal_Int32
237 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : nullptr;
240 throw uno::RuntimeException();
244 Color
* pColor
= nullptr;
245 pFormatter
->GetOutputString(aString
, nKey
, aStr
, &pColor
);
248 nRet
= sal_uInt32(*pColor
);
255 OUString SAL_CALL
SvNumberFormatterServiceObj::getInputString( sal_Int32 nKey
, double fValue
)
257 ::osl::MutexGuard
aGuard( m_aMutex
);
260 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : nullptr;
262 throw uno::RuntimeException();
264 pFormatter
->GetInputLineString(fValue
, nKey
, aRet
);
269 // XNumberFormatPreviewer
271 OUString SAL_CALL
SvNumberFormatterServiceObj::convertNumberToPreviewString( const OUString
& aFormat
,
273 const lang::Locale
& nLocale
,
274 sal_Bool bAllowEnglish
)
276 ::osl::MutexGuard
aGuard( m_aMutex
);
279 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : nullptr;
281 throw uno::RuntimeException();
283 LanguageType eLang
= lcl_GetLanguage( nLocale
);
284 Color
* pColor
= nullptr;
288 bOk
= pFormatter
->GetPreviewStringGuess( aFormat
, fValue
, aRet
, &pColor
, eLang
);
290 bOk
= pFormatter
->GetPreviewString( aFormat
, fValue
, aRet
, &pColor
, eLang
);
293 throw util::MalformedNumberFormatException();
298 util::Color SAL_CALL
SvNumberFormatterServiceObj::queryPreviewColorForNumber( const OUString
& aFormat
,
300 const lang::Locale
& nLocale
,
301 sal_Bool bAllowEnglish
,
302 util::Color aDefaultColor
)
304 ::osl::MutexGuard
aGuard( m_aMutex
);
306 util::Color nRet
= aDefaultColor
; // color = sal_Int32
307 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : nullptr;
309 throw uno::RuntimeException();
312 LanguageType eLang
= lcl_GetLanguage( nLocale
);
313 Color
* pColor
= nullptr;
317 bOk
= pFormatter
->GetPreviewStringGuess( aFormat
, fValue
, aOutString
, &pColor
, eLang
);
319 bOk
= pFormatter
->GetPreviewString( aFormat
, fValue
, aOutString
, &pColor
, eLang
);
322 throw util::MalformedNumberFormatException();
325 nRet
= sal_uInt32(*pColor
);
333 OUString SAL_CALL
SvNumberFormatterServiceObj::getImplementationName()
335 return OUString("com.sun.star.uno.util.numbers.SvNumberFormatterServiceObject");
338 sal_Bool SAL_CALL
SvNumberFormatterServiceObj::supportsService( const OUString
& ServiceName
)
340 return cppu::supportsService( this, ServiceName
);
343 uno::Sequence
<OUString
> SAL_CALL
SvNumberFormatterServiceObj::getSupportedServiceNames()
345 return { "com.sun.star.util.NumberFormatter" };
348 SvNumberFormatsObj::SvNumberFormatsObj( SvNumberFormatsSupplierObj
& _rParent
, ::comphelper::SharedMutex
const & _rMutex
)
349 :m_xSupplier( &_rParent
)
354 SvNumberFormatsObj::~SvNumberFormatsObj()
360 uno::Reference
<beans::XPropertySet
> SAL_CALL
SvNumberFormatsObj::getByKey( sal_Int32 nKey
)
362 ::osl::MutexGuard
aGuard( m_aMutex
);
364 SvNumberFormatter
* pFormatter
= m_xSupplier
->GetNumberFormatter();
365 const SvNumberformat
* pFormat
= pFormatter
? pFormatter
->GetEntry(nKey
) : nullptr;
367 throw uno::RuntimeException();
369 return new SvNumberFormatObj( *m_xSupplier
, nKey
, m_aMutex
);
372 uno::Sequence
<sal_Int32
> SAL_CALL
SvNumberFormatsObj::queryKeys( sal_Int16 nType
,
373 const lang::Locale
& nLocale
,
376 ::osl::MutexGuard
aGuard( m_aMutex
);
378 SvNumberFormatter
* pFormatter
= m_xSupplier
->GetNumberFormatter();
380 throw uno::RuntimeException();
382 sal_uInt32 nIndex
= 0;
383 LanguageType eLang
= lcl_GetLanguage( nLocale
);
384 SvNumberFormatTable
& rTable
= bCreate
?
385 pFormatter
->ChangeCL( static_cast<SvNumFormatType
>(nType
), nIndex
, eLang
) :
386 pFormatter
->GetEntryTable( static_cast<SvNumFormatType
>(nType
), nIndex
, eLang
);
387 sal_uInt32 nCount
= rTable
.size();
388 uno::Sequence
<sal_Int32
> aSeq(nCount
);
389 sal_Int32
* pAry
= aSeq
.getArray();
391 for (SvNumberFormatTable::const_iterator it
= rTable
.begin(); it
!= rTable
.end(); ++it
, ++i
)
397 sal_Int32 SAL_CALL
SvNumberFormatsObj::queryKey( const OUString
& aFormat
,
398 const lang::Locale
& nLocale
,
401 ::osl::MutexGuard
aGuard( m_aMutex
);
403 SvNumberFormatter
* pFormatter
= m_xSupplier
->GetNumberFormatter();
405 throw uno::RuntimeException();
407 LanguageType eLang
= lcl_GetLanguage( nLocale
);
410 //! FIXME: Something still needs to happen here ...
412 sal_Int32 nRet
= pFormatter
->GetEntryKey( aFormat
, eLang
);
416 sal_Int32 SAL_CALL
SvNumberFormatsObj::addNew( const OUString
& aFormat
,
417 const lang::Locale
& nLocale
)
419 ::osl::MutexGuard
aGuard( m_aMutex
);
422 SvNumberFormatter
* pFormatter
= m_xSupplier
->GetNumberFormatter();
424 throw uno::RuntimeException();
426 OUString aFormStr
= aFormat
;
427 LanguageType eLang
= lcl_GetLanguage( nLocale
);
429 sal_Int32 nCheckPos
= 0;
430 SvNumFormatType nType
= SvNumFormatType::ALL
;
431 bool bOk
= pFormatter
->PutEntry( aFormStr
, nCheckPos
, nType
, nKey
, eLang
);
436 throw util::MalformedNumberFormatException(); // Invalid Format
439 throw uno::RuntimeException(); // Other error (e.g. already added)
444 sal_Int32 SAL_CALL
SvNumberFormatsObj::addNewConverted( const OUString
& aFormat
,
445 const lang::Locale
& nLocale
,
446 const lang::Locale
& nNewLocale
)
448 ::osl::MutexGuard
aGuard( m_aMutex
);
451 SvNumberFormatter
* pFormatter
= m_xSupplier
->GetNumberFormatter();
453 throw uno::RuntimeException();
455 OUString aFormStr
= aFormat
;
456 LanguageType eLang
= lcl_GetLanguage( nLocale
);
457 LanguageType eNewLang
= lcl_GetLanguage( nNewLocale
);
459 sal_Int32 nCheckPos
= 0;
460 SvNumFormatType nType
= SvNumFormatType::ALL
;
461 // This is used also when reading OOXML documents, there's no indicator
462 // whether to convert date particle order as well, so don't. See tdf#119013
463 bool bOk
= pFormatter
->PutandConvertEntry( aFormStr
, nCheckPos
, nType
, nKey
, eLang
, eNewLang
, false);
468 throw util::MalformedNumberFormatException(); // Invalid format
471 throw uno::RuntimeException(); // Other error (e.g. already added)
476 void SAL_CALL
SvNumberFormatsObj::removeByKey( sal_Int32 nKey
)
478 ::osl::MutexGuard
aGuard( m_aMutex
);
479 SvNumberFormatter
* pFormatter
= m_xSupplier
->GetNumberFormatter();
483 pFormatter
->DeleteEntry(nKey
);
487 OUString SAL_CALL
SvNumberFormatsObj::generateFormat( sal_Int32 nBaseKey
,
488 const lang::Locale
& nLocale
,
490 sal_Bool bRed
, sal_Int16 nDecimals
,
493 ::osl::MutexGuard
aGuard( m_aMutex
);
495 SvNumberFormatter
* pFormatter
= m_xSupplier
->GetNumberFormatter();
497 throw uno::RuntimeException();
499 LanguageType eLang
= lcl_GetLanguage( nLocale
);
500 OUString aRet
= pFormatter
->GenerateFormat(nBaseKey
, eLang
, bThousands
, bRed
, nDecimals
, nLeading
);
504 // XNumberFormatTypes
506 sal_Int32 SAL_CALL
SvNumberFormatsObj::getStandardIndex( const lang::Locale
& nLocale
)
508 ::osl::MutexGuard
aGuard( m_aMutex
);
510 SvNumberFormatter
* pFormatter
= m_xSupplier
->GetNumberFormatter();
512 throw uno::RuntimeException();
514 LanguageType eLang
= lcl_GetLanguage( nLocale
);
515 sal_Int32 nRet
= pFormatter
->GetStandardIndex(eLang
);
519 sal_Int32 SAL_CALL
SvNumberFormatsObj::getStandardFormat( sal_Int16 nType
, const lang::Locale
& nLocale
)
521 ::osl::MutexGuard
aGuard( m_aMutex
);
523 SvNumberFormatter
* pFormatter
= m_xSupplier
->GetNumberFormatter();
525 throw uno::RuntimeException();
527 LanguageType eLang
= lcl_GetLanguage( nLocale
);
528 // Mask out "defined" bit, so type from an existing number format
529 // can directly be used for getStandardFormat
530 SvNumFormatType nType2
= static_cast<SvNumFormatType
>(nType
);
531 nType2
&= ~SvNumFormatType::DEFINED
;
532 sal_Int32 nRet
= pFormatter
->GetStandardFormat(nType2
, eLang
);
536 sal_Int32 SAL_CALL
SvNumberFormatsObj::getFormatIndex( sal_Int16 nIndex
, const lang::Locale
& nLocale
)
538 ::osl::MutexGuard
aGuard( m_aMutex
);
540 SvNumberFormatter
* pFormatter
= m_xSupplier
->GetNumberFormatter();
542 throw uno::RuntimeException();
544 LanguageType eLang
= lcl_GetLanguage( nLocale
);
545 sal_Int32 nRet
= pFormatter
->GetFormatIndex( static_cast<NfIndexTableOffset
>(nIndex
), eLang
);
549 sal_Bool SAL_CALL
SvNumberFormatsObj::isTypeCompatible( sal_Int16 nOldType
, sal_Int16 nNewType
)
551 ::osl::MutexGuard
aGuard( m_aMutex
);
553 return SvNumberFormatter::IsCompatible( static_cast<SvNumFormatType
>(nOldType
), static_cast<SvNumFormatType
>(nNewType
) );
556 sal_Int32 SAL_CALL
SvNumberFormatsObj::getFormatForLocale( sal_Int32 nKey
, const lang::Locale
& nLocale
)
558 ::osl::MutexGuard
aGuard( m_aMutex
);
560 SvNumberFormatter
* pFormatter
= m_xSupplier
->GetNumberFormatter();
562 throw uno::RuntimeException();
564 LanguageType eLang
= lcl_GetLanguage( nLocale
);
565 sal_Int32 nRet
= pFormatter
->GetFormatForLanguageIfBuiltIn(nKey
, eLang
);
571 OUString SAL_CALL
SvNumberFormatsObj::getImplementationName()
573 return OUString("SvNumberFormatsObj");
576 sal_Bool SAL_CALL
SvNumberFormatsObj::supportsService( const OUString
& ServiceName
)
578 return cppu::supportsService( this, ServiceName
);
581 uno::Sequence
<OUString
> SAL_CALL
SvNumberFormatsObj::getSupportedServiceNames()
583 return { "com.sun.star.util.NumberFormats" };
586 SvNumberFormatObj::SvNumberFormatObj( SvNumberFormatsSupplierObj
& rParent
, sal_uLong nK
, const ::comphelper::SharedMutex
& _rMutex
)
587 :m_xSupplier( &rParent
)
593 SvNumberFormatObj::~SvNumberFormatObj()
599 uno::Reference
<beans::XPropertySetInfo
> SAL_CALL
SvNumberFormatObj::getPropertySetInfo()
601 static uno::Reference
<beans::XPropertySetInfo
> aRef
=
602 new SfxItemPropertySetInfo( lcl_GetNumberFormatPropertyMap() );
606 void SAL_CALL
SvNumberFormatObj::setPropertyValue( const OUString
&,
609 throw beans::UnknownPropertyException(); // Everything is read-only
612 uno::Any SAL_CALL
SvNumberFormatObj::getPropertyValue( const OUString
& aPropertyName
)
614 ::osl::MutexGuard
aGuard( m_aMutex
);
617 SvNumberFormatter
* pFormatter
= m_xSupplier
->GetNumberFormatter();
618 const SvNumberformat
* pFormat
= pFormatter
? pFormatter
->GetEntry(nKey
) : nullptr;
620 throw uno::RuntimeException();
622 bool bThousand
, bRed
;
623 sal_uInt16 nDecimals
, nLeading
;
625 if (aPropertyName
== PROPERTYNAME_FMTSTR
)
627 aRet
<<= pFormat
->GetFormatstring();
629 else if (aPropertyName
== PROPERTYNAME_LOCALE
)
631 lang::Locale
aLocale( LanguageTag::convertToLocale( pFormat
->GetLanguage(), false));
634 else if (aPropertyName
== PROPERTYNAME_TYPE
)
636 aRet
<<= static_cast<sal_Int16
>( pFormat
->GetType() );
638 else if (aPropertyName
== PROPERTYNAME_COMMENT
)
640 aRet
<<= pFormat
->GetComment();
642 else if (aPropertyName
== PROPERTYNAME_STDFORM
)
644 //! Pass through SvNumberformat Member bStandard?
645 aRet
<<= ( ( nKey
% SV_COUNTRY_LANGUAGE_OFFSET
) == 0 );
647 else if (aPropertyName
== PROPERTYNAME_USERDEF
)
649 aRet
<<= bool( pFormat
->GetType() & SvNumFormatType::DEFINED
);
651 else if (aPropertyName
== PROPERTYNAME_DECIMALS
)
653 pFormat
->GetFormatSpecialInfo( bThousand
, bRed
, nDecimals
, nLeading
);
654 aRet
<<= static_cast<sal_Int16
>(nDecimals
);
656 else if (aPropertyName
== PROPERTYNAME_LEADING
)
658 pFormat
->GetFormatSpecialInfo( bThousand
, bRed
, nDecimals
, nLeading
);
659 aRet
<<= static_cast<sal_Int16
>(nLeading
);
661 else if (aPropertyName
== PROPERTYNAME_NEGRED
)
663 pFormat
->GetFormatSpecialInfo( bThousand
, bRed
, nDecimals
, nLeading
);
666 else if (aPropertyName
== PROPERTYNAME_THOUS
)
668 pFormat
->GetFormatSpecialInfo( bThousand
, bRed
, nDecimals
, nLeading
);
671 else if (aPropertyName
== PROPERTYNAME_CURRSYM
)
673 OUString aSymbol
, aExt
;
674 pFormat
->GetNewCurrencySymbol( aSymbol
, aExt
);
677 else if (aPropertyName
== PROPERTYNAME_CURREXT
)
679 OUString aSymbol
, aExt
;
680 pFormat
->GetNewCurrencySymbol( aSymbol
, aExt
);
683 else if (aPropertyName
== PROPERTYNAME_CURRABB
)
685 OUString aSymbol
, aExt
;
687 pFormat
->GetNewCurrencySymbol( aSymbol
, aExt
);
688 const NfCurrencyEntry
* pCurr
= SvNumberFormatter::GetCurrencyEntry( bBank
,
689 aSymbol
, aExt
, pFormat
->GetLanguage() );
691 aRet
<<= pCurr
->GetBankSymbol();
696 throw beans::UnknownPropertyException();
701 void SAL_CALL
SvNumberFormatObj::addPropertyChangeListener( const OUString
&,
702 const uno::Reference
<beans::XPropertyChangeListener
>&)
704 OSL_FAIL("not implemented");
707 void SAL_CALL
SvNumberFormatObj::removePropertyChangeListener( const OUString
&,
708 const uno::Reference
<beans::XPropertyChangeListener
>&)
710 OSL_FAIL("not implemented");
713 void SAL_CALL
SvNumberFormatObj::addVetoableChangeListener( const OUString
&,
714 const uno::Reference
<beans::XVetoableChangeListener
>&)
716 OSL_FAIL("not implemented");
719 void SAL_CALL
SvNumberFormatObj::removeVetoableChangeListener( const OUString
&,
720 const uno::Reference
<beans::XVetoableChangeListener
>&)
722 OSL_FAIL("not implemented");
727 uno::Sequence
<beans::PropertyValue
> SAL_CALL
SvNumberFormatObj::getPropertyValues()
729 ::osl::MutexGuard
aGuard( m_aMutex
);
731 SvNumberFormatter
* pFormatter
= m_xSupplier
->GetNumberFormatter();
732 const SvNumberformat
* pFormat
= pFormatter
? pFormatter
->GetEntry(nKey
) : nullptr;
734 throw uno::RuntimeException();
736 OUString aSymbol
, aExt
;
739 pFormat
->GetNewCurrencySymbol( aSymbol
, aExt
);
740 const NfCurrencyEntry
* pCurr
= SvNumberFormatter::GetCurrencyEntry( bBank
,
741 aSymbol
, aExt
, pFormat
->GetLanguage() );
743 aAbb
= pCurr
->GetBankSymbol();
745 OUString aFmtStr
= pFormat
->GetFormatstring();
746 OUString aComment
= pFormat
->GetComment();
747 bool bStandard
= ( ( nKey
% SV_COUNTRY_LANGUAGE_OFFSET
) == 0 );
748 //! Pass through SvNumberformat Member bStandard?
749 bool bUserDef( pFormat
->GetType() & SvNumFormatType::DEFINED
);
750 bool bThousand
, bRed
;
751 sal_uInt16 nDecimals
, nLeading
;
752 pFormat
->GetFormatSpecialInfo( bThousand
, bRed
, nDecimals
, nLeading
);
753 lang::Locale
aLocale( LanguageTag( pFormat
->GetLanguage()).getLocale());
755 uno::Sequence
<beans::PropertyValue
> aSeq( comphelper::InitPropertySequence({
756 { PROPERTYNAME_FMTSTR
, uno::Any(aFmtStr
) },
757 { PROPERTYNAME_LOCALE
, uno::Any(aLocale
) },
758 { PROPERTYNAME_TYPE
, uno::Any(sal_Int16( pFormat
->GetType() )) },
759 { PROPERTYNAME_COMMENT
, uno::Any(aComment
) },
760 { PROPERTYNAME_STDFORM
, uno::Any(bStandard
) },
761 { PROPERTYNAME_USERDEF
, uno::Any(bUserDef
) },
762 { PROPERTYNAME_DECIMALS
, uno::Any(sal_Int16( nDecimals
)) },
763 { PROPERTYNAME_LEADING
, uno::Any(sal_Int16( nLeading
)) },
764 { PROPERTYNAME_NEGRED
, uno::Any(bRed
) },
765 { PROPERTYNAME_THOUS
, uno::Any(bThousand
) },
766 { PROPERTYNAME_CURRSYM
, uno::Any(aSymbol
) },
767 { PROPERTYNAME_CURREXT
, uno::Any(aExt
) },
768 { PROPERTYNAME_CURRABB
, uno::Any(aAbb
) }
774 void SAL_CALL
SvNumberFormatObj::setPropertyValues( const uno::Sequence
<beans::PropertyValue
>& )
776 throw beans::UnknownPropertyException(); // Everything is read-only
781 OUString SAL_CALL
SvNumberFormatObj::getImplementationName()
783 return OUString("SvNumberFormatObj");
786 sal_Bool SAL_CALL
SvNumberFormatObj::supportsService( const OUString
& ServiceName
)
788 return cppu::supportsService( this, ServiceName
);
791 uno::Sequence
<OUString
> SAL_CALL
SvNumberFormatObj::getSupportedServiceNames()
793 return { "com.sun.star.util.NumberFormatProperties" };
796 SvNumberFormatSettingsObj::SvNumberFormatSettingsObj( SvNumberFormatsSupplierObj
& rParent
, const ::comphelper::SharedMutex
& _rMutex
)
797 :m_xSupplier( &rParent
)
802 SvNumberFormatSettingsObj::~SvNumberFormatSettingsObj()
808 uno::Reference
<beans::XPropertySetInfo
> SAL_CALL
SvNumberFormatSettingsObj::getPropertySetInfo()
810 static uno::Reference
<beans::XPropertySetInfo
> aRef
=
811 new SfxItemPropertySetInfo( lcl_GetNumberSettingsPropertyMap() );
815 void SAL_CALL
SvNumberFormatSettingsObj::setPropertyValue( const OUString
& aPropertyName
,
816 const uno::Any
& aValue
)
818 ::osl::MutexGuard
aGuard( m_aMutex
);
820 SvNumberFormatter
* pFormatter
= m_xSupplier
->GetNumberFormatter();
822 throw uno::RuntimeException();
824 if (aPropertyName
== PROPERTYNAME_NOZERO
)
826 // operator >>= shouldn't be used for bool (?)
827 if ( auto b
= o3tl::tryAccess
<bool>(aValue
) )
828 pFormatter
->SetNoZero( *b
);
830 else if (aPropertyName
== PROPERTYNAME_NULLDATE
)
833 if ( aValue
>>= aDate
)
834 pFormatter
->ChangeNullDate( aDate
.Day
, aDate
.Month
, aDate
.Year
);
836 else if (aPropertyName
== PROPERTYNAME_STDDEC
)
838 sal_Int16 nInt16
= sal_Int16();
839 if ( aValue
>>= nInt16
)
840 pFormatter
->ChangeStandardPrec( nInt16
);
842 else if (aPropertyName
== PROPERTYNAME_TWODIGIT
)
844 sal_Int16 nInt16
= sal_Int16();
845 if ( aValue
>>= nInt16
)
846 pFormatter
->SetYear2000( nInt16
);
849 throw beans::UnknownPropertyException();
853 uno::Any SAL_CALL
SvNumberFormatSettingsObj::getPropertyValue( const OUString
& aPropertyName
)
855 ::osl::MutexGuard
aGuard( m_aMutex
);
858 SvNumberFormatter
* pFormatter
= m_xSupplier
->GetNumberFormatter();
860 throw uno::RuntimeException();
862 if (aPropertyName
== PROPERTYNAME_NOZERO
)
864 aRet
<<= pFormatter
->GetNoZero();
866 else if (aPropertyName
== PROPERTYNAME_NULLDATE
)
868 const Date
& rDate
= pFormatter
->GetNullDate();
869 aRet
<<= rDate
.GetUNODate();
871 else if (aPropertyName
== PROPERTYNAME_STDDEC
)
872 aRet
<<= static_cast<sal_Int16
>( pFormatter
->GetStandardPrec() );
873 else if (aPropertyName
== PROPERTYNAME_TWODIGIT
)
874 aRet
<<= static_cast<sal_Int16
>( pFormatter
->GetYear2000() );
876 throw beans::UnknownPropertyException();
881 void SAL_CALL
SvNumberFormatSettingsObj::addPropertyChangeListener( const OUString
&,
882 const uno::Reference
<beans::XPropertyChangeListener
>&)
884 OSL_FAIL("not implemented");
887 void SAL_CALL
SvNumberFormatSettingsObj::removePropertyChangeListener( const OUString
&,
888 const uno::Reference
<beans::XPropertyChangeListener
>&)
890 OSL_FAIL("not implemented");
893 void SAL_CALL
SvNumberFormatSettingsObj::addVetoableChangeListener( const OUString
&,
894 const uno::Reference
<beans::XVetoableChangeListener
>&)
896 OSL_FAIL("not implemented");
899 void SAL_CALL
SvNumberFormatSettingsObj::removeVetoableChangeListener( const OUString
&,
900 const uno::Reference
<beans::XVetoableChangeListener
>&)
902 OSL_FAIL("not implemented");
907 OUString SAL_CALL
SvNumberFormatSettingsObj::getImplementationName()
909 return OUString("SvNumberFormatSettingsObj");
912 sal_Bool SAL_CALL
SvNumberFormatSettingsObj::supportsService( const OUString
& ServiceName
)
914 return cppu::supportsService( this, ServiceName
);
917 uno::Sequence
<OUString
> SAL_CALL
SvNumberFormatSettingsObj::getSupportedServiceNames()
919 return { "com.sun.star.util.NumberFormatSettings" };
923 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
924 com_sun_star_uno_util_numbers_SvNumberFormatterServiceObject_get_implementation(css::uno::XComponentContext
*,
925 css::uno::Sequence
<css::uno::Any
> const &)
927 return cppu::acquire(new SvNumberFormatterServiceObj());
931 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */