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 <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/beans/PropertyAttribute.hpp>
28 #include <cppuhelper/supportsservice.hxx>
30 #include "numfmuno.hxx"
31 #include <svl/numuno.hxx>
32 #include <svl/zforlist.hxx>
33 #include <svl/zformat.hxx>
34 #include <svl/itemprop.hxx>
36 using namespace com::sun::star
;
38 #define PROPERTYNAME_FMTSTR "FormatString"
39 #define PROPERTYNAME_LOCALE "Locale"
40 #define PROPERTYNAME_TYPE "Type"
41 #define PROPERTYNAME_COMMENT "Comment"
42 #define PROPERTYNAME_CURREXT "CurrencyExtension"
43 #define PROPERTYNAME_CURRSYM "CurrencySymbol"
44 #define PROPERTYNAME_CURRABB "CurrencyAbbreviation"
45 #define PROPERTYNAME_DECIMALS "Decimals"
46 #define PROPERTYNAME_LEADING "LeadingZeros"
47 #define PROPERTYNAME_NEGRED "NegativeRed"
48 #define PROPERTYNAME_STDFORM "StandardFormat"
49 #define PROPERTYNAME_THOUS "ThousandsSeparator"
50 #define PROPERTYNAME_USERDEF "UserDefined"
52 #define PROPERTYNAME_NOZERO "NoZero"
53 #define PROPERTYNAME_NULLDATE "NullDate"
54 #define PROPERTYNAME_STDDEC "StandardDecimals"
55 #define PROPERTYNAME_TWODIGIT "TwoDigitDateStart"
57 // All without a Which-ID, Map only for PropertySetInfo
59 static const SfxItemPropertyMapEntry
* lcl_GetNumberFormatPropertyMap()
61 static const SfxItemPropertyMapEntry aNumberFormatPropertyMap_Impl
[] =
63 {OUString(PROPERTYNAME_FMTSTR
), 0, cppu::UnoType
<OUString
>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
64 {OUString(PROPERTYNAME_LOCALE
), 0, cppu::UnoType
<lang::Locale
>::get(),beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
65 {OUString(PROPERTYNAME_TYPE
), 0, cppu::UnoType
<sal_Int16
>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
66 {OUString(PROPERTYNAME_COMMENT
), 0, cppu::UnoType
<OUString
>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
67 {OUString(PROPERTYNAME_CURREXT
), 0, cppu::UnoType
<OUString
>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
68 {OUString(PROPERTYNAME_CURRSYM
), 0, cppu::UnoType
<OUString
>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
69 {OUString(PROPERTYNAME_DECIMALS
), 0, cppu::UnoType
<sal_Int16
>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
70 {OUString(PROPERTYNAME_LEADING
), 0, cppu::UnoType
<sal_Int16
>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
71 {OUString(PROPERTYNAME_NEGRED
), 0, cppu::UnoType
<bool>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
72 {OUString(PROPERTYNAME_STDFORM
), 0, cppu::UnoType
<bool>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
73 {OUString(PROPERTYNAME_THOUS
), 0, cppu::UnoType
<bool>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
74 {OUString(PROPERTYNAME_USERDEF
), 0, cppu::UnoType
<bool>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
75 {OUString(PROPERTYNAME_CURRABB
), 0, cppu::UnoType
<OUString
>::get(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
76 { OUString(), 0, css::uno::Type(), 0, 0 }
78 return aNumberFormatPropertyMap_Impl
;
81 static const SfxItemPropertyMapEntry
* lcl_GetNumberSettingsPropertyMap()
83 static const SfxItemPropertyMapEntry aNumberSettingsPropertyMap_Impl
[] =
85 {OUString(PROPERTYNAME_NOZERO
), 0, cppu::UnoType
<bool>::get(), beans::PropertyAttribute::BOUND
, 0},
86 {OUString(PROPERTYNAME_NULLDATE
), 0, cppu::UnoType
<util::Date
>::get(), beans::PropertyAttribute::BOUND
, 0},
87 {OUString(PROPERTYNAME_STDDEC
), 0, cppu::UnoType
<sal_Int16
>::get(), beans::PropertyAttribute::BOUND
, 0},
88 {OUString(PROPERTYNAME_TWODIGIT
), 0, cppu::UnoType
<sal_Int16
>::get(), beans::PropertyAttribute::BOUND
, 0},
89 { OUString(), 0, css::uno::Type(), 0, 0 }
91 return aNumberSettingsPropertyMap_Impl
;
94 static LanguageType
lcl_GetLanguage( const lang::Locale
& rLocale
)
96 // empty language -> LANGUAGE_SYSTEM
97 if ( rLocale
.Language
.isEmpty() )
98 return LANGUAGE_SYSTEM
;
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
)
119 throw(uno::RuntimeException
, std::exception
)
121 ::rtl::Reference
< SvNumberFormatsSupplierObj
> xAutoReleaseOld
;
125 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
127 SvNumberFormatsSupplierObj
* pNew
= SvNumberFormatsSupplierObj::getImplementation( _xSupplier
);
129 throw uno::RuntimeException(); // wrong object
131 xAutoReleaseOld
= xSupplier
;
134 m_aMutex
= xSupplier
->getSharedMutex();
139 uno::Reference
<util::XNumberFormatsSupplier
> SAL_CALL
SvNumberFormatterServiceObj::getNumberFormatsSupplier()
140 throw(uno::RuntimeException
, std::exception
)
142 ::osl::MutexGuard
aGuard( m_aMutex
);
143 return xSupplier
.get();
146 sal_Int32 SAL_CALL
SvNumberFormatterServiceObj::detectNumberFormat( sal_Int32 nKey
, const OUString
& aString
)
147 throw(util::NotNumericException
, uno::RuntimeException
, std::exception
)
149 ::osl::MutexGuard
aGuard( m_aMutex
);
152 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : NULL
;
155 sal_uInt32 nUKey
= nKey
;
157 if ( pFormatter
->IsNumberFormat(aString
, nUKey
, fValue
) )
160 throw util::NotNumericException();
163 throw uno::RuntimeException();
168 double SAL_CALL
SvNumberFormatterServiceObj::convertStringToNumber( sal_Int32 nKey
, const OUString
& aString
)
169 throw(util::NotNumericException
, uno::RuntimeException
, std::exception
)
171 ::osl::MutexGuard
aGuard( m_aMutex
);
174 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : NULL
;
177 sal_uInt32 nUKey
= nKey
;
179 if ( pFormatter
->IsNumberFormat(aString
, nUKey
, fValue
) )
182 throw util::NotNumericException();
185 throw uno::RuntimeException();
190 OUString SAL_CALL
SvNumberFormatterServiceObj::convertNumberToString( sal_Int32 nKey
, double fValue
)
191 throw(uno::RuntimeException
, std::exception
)
193 ::osl::MutexGuard
aGuard( m_aMutex
);
196 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : NULL
;
199 Color
* pColor
= NULL
;
200 pFormatter
->GetOutputString(fValue
, nKey
, aRet
, &pColor
);
203 throw uno::RuntimeException();
208 util::Color SAL_CALL
SvNumberFormatterServiceObj::queryColorForNumber( sal_Int32 nKey
,
210 util::Color aDefaultColor
)
211 throw(uno::RuntimeException
, std::exception
)
213 ::osl::MutexGuard
aGuard( m_aMutex
);
215 util::Color nRet
= aDefaultColor
; // color = sal_Int32
216 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : NULL
;
220 Color
* pColor
= NULL
;
221 pFormatter
->GetOutputString(fValue
, nKey
, aStr
, &pColor
);
223 nRet
= pColor
->GetColor();
227 throw uno::RuntimeException();
232 OUString SAL_CALL
SvNumberFormatterServiceObj::formatString( sal_Int32 nKey
,
233 const OUString
& aString
)
234 throw(uno::RuntimeException
, std::exception
)
236 ::osl::MutexGuard
aGuard( m_aMutex
);
239 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : NULL
;
242 Color
* pColor
= NULL
;
243 pFormatter
->GetOutputString(aString
, nKey
, aRet
, &pColor
);
247 throw uno::RuntimeException();
252 util::Color SAL_CALL
SvNumberFormatterServiceObj::queryColorForString( sal_Int32 nKey
,
253 const OUString
& aString
,
254 util::Color aDefaultColor
)
255 throw(uno::RuntimeException
, std::exception
)
257 ::osl::MutexGuard
aGuard( m_aMutex
);
259 util::Color nRet
= aDefaultColor
; // color = sal_Int32
260 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : NULL
;
264 Color
* pColor
= NULL
;
265 pFormatter
->GetOutputString(aString
, nKey
, aStr
, &pColor
);
268 nRet
= pColor
->GetColor();
274 throw uno::RuntimeException();
280 OUString SAL_CALL
SvNumberFormatterServiceObj::getInputString( sal_Int32 nKey
, double fValue
)
281 throw(uno::RuntimeException
, std::exception
)
283 ::osl::MutexGuard
aGuard( m_aMutex
);
286 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : NULL
;
288 pFormatter
->GetInputLineString(fValue
, nKey
, aRet
);
290 throw uno::RuntimeException();
295 // XNumberFormatPreviewer
297 OUString SAL_CALL
SvNumberFormatterServiceObj::convertNumberToPreviewString( const OUString
& aFormat
,
299 const lang::Locale
& nLocale
,
300 sal_Bool bAllowEnglish
)
301 throw(util::MalformedNumberFormatException
, uno::RuntimeException
, std::exception
)
303 ::osl::MutexGuard
aGuard( m_aMutex
);
306 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : NULL
;
309 LanguageType eLang
= lcl_GetLanguage( nLocale
);
310 Color
* pColor
= NULL
;
314 bOk
= pFormatter
->GetPreviewStringGuess( aFormat
, fValue
, aRet
, &pColor
, eLang
);
316 bOk
= pFormatter
->GetPreviewString( aFormat
, fValue
, aRet
, &pColor
, eLang
);
319 throw util::MalformedNumberFormatException();
322 throw uno::RuntimeException();
327 util::Color SAL_CALL
SvNumberFormatterServiceObj::queryPreviewColorForNumber( const OUString
& aFormat
,
329 const lang::Locale
& nLocale
,
330 sal_Bool bAllowEnglish
,
331 util::Color aDefaultColor
)
332 throw(util::MalformedNumberFormatException
, uno::RuntimeException
, std::exception
)
334 ::osl::MutexGuard
aGuard( m_aMutex
);
336 util::Color nRet
= aDefaultColor
; // color = sal_Int32
337 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : NULL
;
341 LanguageType eLang
= lcl_GetLanguage( nLocale
);
342 Color
* pColor
= NULL
;
346 bOk
= pFormatter
->GetPreviewStringGuess( aFormat
, fValue
, aOutString
, &pColor
, eLang
);
348 bOk
= pFormatter
->GetPreviewString( aFormat
, fValue
, aOutString
, &pColor
, eLang
);
353 nRet
= pColor
->GetColor();
357 throw util::MalformedNumberFormatException();
360 throw uno::RuntimeException();
367 OUString SAL_CALL
SvNumberFormatterServiceObj::getImplementationName()
368 throw(uno::RuntimeException
, std::exception
)
370 return OUString("com.sun.star.uno.util.numbers.SvNumberFormatterServiceObject");
373 sal_Bool SAL_CALL
SvNumberFormatterServiceObj::supportsService( const OUString
& ServiceName
)
374 throw(uno::RuntimeException
, std::exception
)
376 return cppu::supportsService( this, ServiceName
);
379 uno::Sequence
<OUString
> SAL_CALL
SvNumberFormatterServiceObj::getSupportedServiceNames()
380 throw(uno::RuntimeException
, std::exception
)
382 uno::Sequence
<OUString
> aRet(1);
383 OUString
* pArray
= aRet
.getArray();
384 pArray
[0] = "com.sun.star.util.NumberFormatter";
388 SvNumberFormatsObj::SvNumberFormatsObj( SvNumberFormatsSupplierObj
& _rParent
, ::comphelper::SharedMutex
& _rMutex
)
389 :rSupplier( _rParent
)
395 SvNumberFormatsObj::~SvNumberFormatsObj()
402 uno::Reference
<beans::XPropertySet
> SAL_CALL
SvNumberFormatsObj::getByKey( sal_Int32 nKey
)
403 throw(uno::RuntimeException
, std::exception
)
405 ::osl::MutexGuard
aGuard( m_aMutex
);
407 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
408 const SvNumberformat
* pFormat
= pFormatter
? pFormatter
->GetEntry(nKey
) : NULL
;
410 return new SvNumberFormatObj( rSupplier
, nKey
, m_aMutex
);
412 throw uno::RuntimeException();
415 uno::Sequence
<sal_Int32
> SAL_CALL
SvNumberFormatsObj::queryKeys( sal_Int16 nType
,
416 const lang::Locale
& nLocale
,
418 throw(uno::RuntimeException
, std::exception
)
420 ::osl::MutexGuard
aGuard( m_aMutex
);
422 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
425 sal_uInt32 nIndex
= 0;
426 LanguageType eLang
= lcl_GetLanguage( nLocale
);
427 SvNumberFormatTable
& rTable
= bCreate
?
428 pFormatter
->ChangeCL( nType
, nIndex
, eLang
) :
429 pFormatter
->GetEntryTable( nType
, nIndex
, eLang
);
430 sal_uInt32 nCount
= rTable
.size();
431 uno::Sequence
<sal_Int32
> aSeq(nCount
);
432 sal_Int32
* pAry
= aSeq
.getArray();
434 for (SvNumberFormatTable::iterator it
= rTable
.begin(); it
!= rTable
.end(); ++it
, ++i
)
440 throw uno::RuntimeException();
443 sal_Int32 SAL_CALL
SvNumberFormatsObj::queryKey( const OUString
& aFormat
,
444 const lang::Locale
& nLocale
,
446 throw(uno::RuntimeException
, std::exception
)
448 ::osl::MutexGuard
aGuard( m_aMutex
);
451 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
454 LanguageType eLang
= lcl_GetLanguage( nLocale
);
457 //! FIXME: Something still needs to happen here ...
459 nRet
= pFormatter
->GetEntryKey( aFormat
, eLang
);
462 throw uno::RuntimeException();
467 sal_Int32 SAL_CALL
SvNumberFormatsObj::addNew( const OUString
& aFormat
,
468 const lang::Locale
& nLocale
)
469 throw(util::MalformedNumberFormatException
, uno::RuntimeException
, std::exception
)
471 ::osl::MutexGuard
aGuard( m_aMutex
);
474 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
477 OUString aFormStr
= aFormat
;
478 LanguageType eLang
= lcl_GetLanguage( nLocale
);
480 sal_Int32 nCheckPos
= 0;
482 bool bOk
= pFormatter
->PutEntry( aFormStr
, nCheckPos
, nType
, nKey
, eLang
);
487 throw util::MalformedNumberFormatException(); // Invalid Format
490 throw uno::RuntimeException(); // Other error (e.g. already added)
493 throw uno::RuntimeException();
498 sal_Int32 SAL_CALL
SvNumberFormatsObj::addNewConverted( const OUString
& aFormat
,
499 const lang::Locale
& nLocale
,
500 const lang::Locale
& nNewLocale
)
501 throw(util::MalformedNumberFormatException
, uno::RuntimeException
, std::exception
)
503 ::osl::MutexGuard
aGuard( m_aMutex
);
506 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
509 OUString aFormStr
= aFormat
;
510 LanguageType eLang
= lcl_GetLanguage( nLocale
);
511 LanguageType eNewLang
= lcl_GetLanguage( nNewLocale
);
513 sal_Int32 nCheckPos
= 0;
515 bool bOk
= pFormatter
->PutandConvertEntry( aFormStr
, nCheckPos
, nType
, nKey
, eLang
, eNewLang
);
520 throw util::MalformedNumberFormatException(); // Invalid format
523 throw uno::RuntimeException(); // Other error (e.g. already added)
526 throw uno::RuntimeException();
531 void SAL_CALL
SvNumberFormatsObj::removeByKey( sal_Int32 nKey
) throw(uno::RuntimeException
, std::exception
)
533 ::osl::MutexGuard
aGuard( m_aMutex
);
534 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
538 pFormatter
->DeleteEntry(nKey
);
542 OUString SAL_CALL
SvNumberFormatsObj::generateFormat( sal_Int32 nBaseKey
,
543 const lang::Locale
& nLocale
,
545 sal_Bool bRed
, sal_Int16 nDecimals
,
547 throw(uno::RuntimeException
, std::exception
)
549 ::osl::MutexGuard
aGuard( m_aMutex
);
552 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
555 LanguageType eLang
= lcl_GetLanguage( nLocale
);
556 aRet
= pFormatter
->GenerateFormat(nBaseKey
, eLang
, bThousands
, bRed
, nDecimals
, nLeading
);
559 throw uno::RuntimeException();
564 // XNumberFormatTypes
566 sal_Int32 SAL_CALL
SvNumberFormatsObj::getStandardIndex( const lang::Locale
& nLocale
)
567 throw(uno::RuntimeException
, std::exception
)
569 ::osl::MutexGuard
aGuard( m_aMutex
);
572 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
575 LanguageType eLang
= lcl_GetLanguage( nLocale
);
576 nRet
= pFormatter
->GetStandardIndex(eLang
);
579 throw uno::RuntimeException();
584 sal_Int32 SAL_CALL
SvNumberFormatsObj::getStandardFormat( sal_Int16 nType
, const lang::Locale
& nLocale
)
585 throw(uno::RuntimeException
, std::exception
)
587 ::osl::MutexGuard
aGuard( m_aMutex
);
590 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
593 LanguageType eLang
= lcl_GetLanguage( nLocale
);
594 // Mask out "defined" bit, so type from an existing number format
595 // can directly be used for getStandardFormat
596 nType
&= ~css::util::NumberFormat::DEFINED
;
597 nRet
= pFormatter
->GetStandardFormat(nType
, eLang
);
600 throw uno::RuntimeException();
605 sal_Int32 SAL_CALL
SvNumberFormatsObj::getFormatIndex( sal_Int16 nIndex
, const lang::Locale
& nLocale
)
606 throw(uno::RuntimeException
, std::exception
)
608 ::osl::MutexGuard
aGuard( m_aMutex
);
611 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
614 LanguageType eLang
= lcl_GetLanguage( nLocale
);
615 nRet
= pFormatter
->GetFormatIndex( (NfIndexTableOffset
)nIndex
, eLang
);
618 throw uno::RuntimeException();
623 sal_Bool SAL_CALL
SvNumberFormatsObj::isTypeCompatible( sal_Int16 nOldType
, sal_Int16 nNewType
)
624 throw(uno::RuntimeException
, std::exception
)
626 ::osl::MutexGuard
aGuard( m_aMutex
);
629 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
631 bRet
= pFormatter
->IsCompatible( nOldType
, nNewType
);
633 throw uno::RuntimeException();
638 sal_Int32 SAL_CALL
SvNumberFormatsObj::getFormatForLocale( sal_Int32 nKey
, const lang::Locale
& nLocale
)
639 throw(uno::RuntimeException
, std::exception
)
641 ::osl::MutexGuard
aGuard( m_aMutex
);
644 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
647 LanguageType eLang
= lcl_GetLanguage( nLocale
);
648 nRet
= pFormatter
->GetFormatForLanguageIfBuiltIn(nKey
, eLang
);
651 throw uno::RuntimeException();
658 OUString SAL_CALL
SvNumberFormatsObj::getImplementationName()
659 throw(uno::RuntimeException
, std::exception
)
661 return OUString("SvNumberFormatsObj");
664 sal_Bool SAL_CALL
SvNumberFormatsObj::supportsService( const OUString
& ServiceName
)
665 throw(uno::RuntimeException
, std::exception
)
667 return cppu::supportsService( this, ServiceName
);
670 uno::Sequence
<OUString
> SAL_CALL
SvNumberFormatsObj::getSupportedServiceNames()
671 throw(uno::RuntimeException
, std::exception
)
673 uno::Sequence
<OUString
> aRet(1);
674 OUString
* pArray
= aRet
.getArray();
675 pArray
[0] = "com.sun.star.util.NumberFormats";
679 SvNumberFormatObj::SvNumberFormatObj( SvNumberFormatsSupplierObj
& rParent
, sal_uLong nK
, const ::comphelper::SharedMutex
& _rMutex
)
680 :rSupplier( rParent
)
687 SvNumberFormatObj::~SvNumberFormatObj()
694 uno::Reference
<beans::XPropertySetInfo
> SAL_CALL
SvNumberFormatObj::getPropertySetInfo()
695 throw(uno::RuntimeException
, std::exception
)
697 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
698 static uno::Reference
<beans::XPropertySetInfo
> aRef
=
699 new SfxItemPropertySetInfo( lcl_GetNumberFormatPropertyMap() );
703 void SAL_CALL
SvNumberFormatObj::setPropertyValue( const OUString
&,
705 throw(beans::UnknownPropertyException
, beans::PropertyVetoException
,
706 lang::IllegalArgumentException
, lang::WrappedTargetException
,
707 uno::RuntimeException
, std::exception
)
709 throw beans::UnknownPropertyException(); // Everything is read-only
712 uno::Any SAL_CALL
SvNumberFormatObj::getPropertyValue( const OUString
& aPropertyName
)
713 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
,
714 uno::RuntimeException
, std::exception
)
716 ::osl::MutexGuard
aGuard( m_aMutex
);
719 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
720 const SvNumberformat
* pFormat
= pFormatter
? pFormatter
->GetEntry(nKey
) : NULL
;
723 bool bThousand
, bRed
;
724 sal_uInt16 nDecimals
, nLeading
;
726 if (aPropertyName
== PROPERTYNAME_FMTSTR
)
728 aRet
<<= OUString( pFormat
->GetFormatstring() );
730 else if (aPropertyName
== PROPERTYNAME_LOCALE
)
732 lang::Locale
aLocale( LanguageTag( pFormat
->GetLanguage()).getLocale());
735 else if (aPropertyName
== PROPERTYNAME_TYPE
)
737 aRet
<<= (sal_Int16
)( pFormat
->GetType() );
739 else if (aPropertyName
== PROPERTYNAME_COMMENT
)
741 aRet
<<= OUString( pFormat
->GetComment() );
743 else if (aPropertyName
== PROPERTYNAME_STDFORM
)
745 //! Pass through SvNumberformat Member bStandard?
746 sal_Bool bStandard
= ( ( nKey
% SV_COUNTRY_LANGUAGE_OFFSET
) == 0 );
747 aRet
.setValue( &bStandard
, cppu::UnoType
<bool>::get() );
749 else if (aPropertyName
== PROPERTYNAME_USERDEF
)
751 sal_Bool bUserDef
= ( ( pFormat
->GetType() & css::util::NumberFormat::DEFINED
) != 0 );
752 aRet
.setValue( &bUserDef
, cppu::UnoType
<bool>::get() );
754 else if (aPropertyName
== PROPERTYNAME_DECIMALS
)
756 pFormat
->GetFormatSpecialInfo( bThousand
, bRed
, nDecimals
, nLeading
);
757 aRet
<<= (sal_Int16
)( nDecimals
);
759 else if (aPropertyName
== PROPERTYNAME_LEADING
)
761 pFormat
->GetFormatSpecialInfo( bThousand
, bRed
, nDecimals
, nLeading
);
762 aRet
<<= (sal_Int16
)( nLeading
);
764 else if (aPropertyName
== PROPERTYNAME_NEGRED
)
766 pFormat
->GetFormatSpecialInfo( bThousand
, bRed
, nDecimals
, nLeading
);
767 aRet
.setValue( &bRed
, cppu::UnoType
<bool>::get() );
769 else if (aPropertyName
== PROPERTYNAME_THOUS
)
771 pFormat
->GetFormatSpecialInfo( bThousand
, bRed
, nDecimals
, nLeading
);
772 aRet
.setValue( &bThousand
, cppu::UnoType
<bool>::get() );
774 else if (aPropertyName
== PROPERTYNAME_CURRSYM
)
776 OUString aSymbol
, aExt
;
777 pFormat
->GetNewCurrencySymbol( aSymbol
, aExt
);
780 else if (aPropertyName
== PROPERTYNAME_CURREXT
)
782 OUString aSymbol
, aExt
;
783 pFormat
->GetNewCurrencySymbol( aSymbol
, aExt
);
786 else if (aPropertyName
== PROPERTYNAME_CURRABB
)
788 OUString aSymbol
, aExt
;
790 pFormat
->GetNewCurrencySymbol( aSymbol
, aExt
);
791 const NfCurrencyEntry
* pCurr
= SvNumberFormatter::GetCurrencyEntry( bBank
,
792 aSymbol
, aExt
, pFormat
->GetLanguage() );
794 aRet
<<= OUString( pCurr
->GetBankSymbol() );
799 throw beans::UnknownPropertyException();
802 throw uno::RuntimeException();
807 void SAL_CALL
SvNumberFormatObj::addPropertyChangeListener( const OUString
&,
808 const uno::Reference
<beans::XPropertyChangeListener
>&)
809 throw(beans::UnknownPropertyException
,
810 lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
812 OSL_FAIL("not implemented");
815 void SAL_CALL
SvNumberFormatObj::removePropertyChangeListener( const OUString
&,
816 const uno::Reference
<beans::XPropertyChangeListener
>&)
817 throw(beans::UnknownPropertyException
,
818 lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
820 OSL_FAIL("not implemented");
823 void SAL_CALL
SvNumberFormatObj::addVetoableChangeListener( const OUString
&,
824 const uno::Reference
<beans::XVetoableChangeListener
>&)
825 throw(beans::UnknownPropertyException
,
826 lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
828 OSL_FAIL("not implemented");
831 void SAL_CALL
SvNumberFormatObj::removeVetoableChangeListener( const OUString
&,
832 const uno::Reference
<beans::XVetoableChangeListener
>&)
833 throw(beans::UnknownPropertyException
,
834 lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
836 OSL_FAIL("not implemented");
841 uno::Sequence
<beans::PropertyValue
> SAL_CALL
SvNumberFormatObj::getPropertyValues()
842 throw(uno::RuntimeException
, std::exception
)
844 ::osl::MutexGuard
aGuard( m_aMutex
);
846 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
847 const SvNumberformat
* pFormat
= pFormatter
? pFormatter
->GetEntry(nKey
) : NULL
;
850 OUString aSymbol
, aExt
;
853 pFormat
->GetNewCurrencySymbol( aSymbol
, aExt
);
854 const NfCurrencyEntry
* pCurr
= SvNumberFormatter::GetCurrencyEntry( bBank
,
855 aSymbol
, aExt
, pFormat
->GetLanguage() );
857 aAbb
= pCurr
->GetBankSymbol();
859 OUString aFmtStr
= pFormat
->GetFormatstring();
860 OUString aComment
= pFormat
->GetComment();
861 sal_Bool bStandard
= ( ( nKey
% SV_COUNTRY_LANGUAGE_OFFSET
) == 0 );
862 //! Pass through SvNumberformat Member bStandard?
863 sal_Bool bUserDef
= ( ( pFormat
->GetType() & css::util::NumberFormat::DEFINED
) != 0 );
864 bool bThousand
, bRed
;
865 sal_uInt16 nDecimals
, nLeading
;
866 pFormat
->GetFormatSpecialInfo( bThousand
, bRed
, nDecimals
, nLeading
);
867 lang::Locale
aLocale( LanguageTag( pFormat
->GetLanguage()).getLocale());
869 uno::Sequence
<beans::PropertyValue
> aSeq(13);
870 beans::PropertyValue
* pArray
= aSeq
.getArray();
872 pArray
[0].Name
= PROPERTYNAME_FMTSTR
;
873 pArray
[0].Value
<<= aFmtStr
;
874 pArray
[1].Name
= PROPERTYNAME_LOCALE
;
875 pArray
[1].Value
<<= aLocale
;
876 pArray
[2].Name
= PROPERTYNAME_TYPE
;
877 pArray
[2].Value
<<= (sal_Int16
)( pFormat
->GetType() );
878 pArray
[3].Name
= PROPERTYNAME_COMMENT
;
879 pArray
[3].Value
<<= aComment
;
880 pArray
[4].Name
= PROPERTYNAME_STDFORM
;
881 pArray
[4].Value
.setValue( &bStandard
, cppu::UnoType
<bool>::get() );
882 pArray
[5].Name
= PROPERTYNAME_USERDEF
;
883 pArray
[5].Value
.setValue( &bUserDef
, cppu::UnoType
<bool>::get() );
884 pArray
[6].Name
= PROPERTYNAME_DECIMALS
;
885 pArray
[6].Value
<<= (sal_Int16
)( nDecimals
);
886 pArray
[7].Name
= PROPERTYNAME_LEADING
;
887 pArray
[7].Value
<<= (sal_Int16
)( nLeading
);
888 pArray
[8].Name
= PROPERTYNAME_NEGRED
;
889 pArray
[8].Value
.setValue( &bRed
, cppu::UnoType
<bool>::get() );
890 pArray
[9].Name
= PROPERTYNAME_THOUS
;
891 pArray
[9].Value
.setValue( &bThousand
, cppu::UnoType
<bool>::get() );
892 pArray
[10].Name
= PROPERTYNAME_CURRSYM
;
893 pArray
[10].Value
<<= aSymbol
;
894 pArray
[11].Name
= PROPERTYNAME_CURREXT
;
895 pArray
[11].Value
<<= aExt
;
896 pArray
[12].Name
= PROPERTYNAME_CURRABB
;
897 pArray
[12].Value
<<= aAbb
;
902 throw uno::RuntimeException();
905 void SAL_CALL
SvNumberFormatObj::setPropertyValues( const uno::Sequence
<beans::PropertyValue
>& )
906 throw(beans::UnknownPropertyException
, beans::PropertyVetoException
,
907 lang::IllegalArgumentException
, lang::WrappedTargetException
,
908 uno::RuntimeException
, std::exception
)
910 throw beans::UnknownPropertyException(); // Everything is read-only
915 OUString SAL_CALL
SvNumberFormatObj::getImplementationName()
916 throw(uno::RuntimeException
, std::exception
)
918 return OUString("SvNumberFormatObj");
921 sal_Bool SAL_CALL
SvNumberFormatObj::supportsService( const OUString
& ServiceName
)
922 throw(uno::RuntimeException
, std::exception
)
924 return cppu::supportsService( this, ServiceName
);
927 uno::Sequence
<OUString
> SAL_CALL
SvNumberFormatObj::getSupportedServiceNames()
928 throw(uno::RuntimeException
, std::exception
)
930 uno::Sequence
<OUString
> aRet(1);
931 OUString
* pArray
= aRet
.getArray();
932 pArray
[0] = "com.sun.star.util.NumberFormatProperties";
936 SvNumberFormatSettingsObj::SvNumberFormatSettingsObj( SvNumberFormatsSupplierObj
& rParent
, const ::comphelper::SharedMutex
& _rMutex
)
937 :rSupplier( rParent
)
943 SvNumberFormatSettingsObj::~SvNumberFormatSettingsObj()
950 uno::Reference
<beans::XPropertySetInfo
> SAL_CALL
SvNumberFormatSettingsObj::getPropertySetInfo()
951 throw(uno::RuntimeException
, std::exception
)
953 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
954 static uno::Reference
<beans::XPropertySetInfo
> aRef
=
955 new SfxItemPropertySetInfo( lcl_GetNumberSettingsPropertyMap() );
959 void SAL_CALL
SvNumberFormatSettingsObj::setPropertyValue( const OUString
& aPropertyName
,
960 const uno::Any
& aValue
)
961 throw(beans::UnknownPropertyException
, beans::PropertyVetoException
,
962 lang::IllegalArgumentException
, lang::WrappedTargetException
,
963 uno::RuntimeException
, std::exception
)
965 ::osl::MutexGuard
aGuard( m_aMutex
);
967 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
970 if (aPropertyName
== PROPERTYNAME_NOZERO
)
972 // operator >>= shouldn't be used for bool (?)
973 if ( aValue
.getValueTypeClass() == uno::TypeClass_BOOLEAN
)
974 pFormatter
->SetNoZero( *static_cast<sal_Bool
const *>(aValue
.getValue()) );
976 else if (aPropertyName
== PROPERTYNAME_NULLDATE
)
979 if ( aValue
>>= aDate
)
980 pFormatter
->ChangeNullDate( aDate
.Day
, aDate
.Month
, aDate
.Year
);
982 else if (aPropertyName
== PROPERTYNAME_STDDEC
)
984 sal_Int16 nInt16
= sal_Int16();
985 if ( aValue
>>= nInt16
)
986 pFormatter
->ChangeStandardPrec( nInt16
);
988 else if (aPropertyName
== PROPERTYNAME_TWODIGIT
)
990 sal_Int16 nInt16
= sal_Int16();
991 if ( aValue
>>= nInt16
)
992 pFormatter
->SetYear2000( nInt16
);
995 throw beans::UnknownPropertyException();
998 throw uno::RuntimeException();
1001 uno::Any SAL_CALL
SvNumberFormatSettingsObj::getPropertyValue( const OUString
& aPropertyName
)
1002 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
,
1003 uno::RuntimeException
, std::exception
)
1005 ::osl::MutexGuard
aGuard( m_aMutex
);
1008 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
1011 if (aPropertyName
== PROPERTYNAME_NOZERO
)
1013 sal_Bool bNoZero
= pFormatter
->GetNoZero();
1014 aRet
.setValue( &bNoZero
, cppu::UnoType
<bool>::get() );
1016 else if (aPropertyName
== PROPERTYNAME_NULLDATE
)
1018 Date
* pDate
= pFormatter
->GetNullDate();
1021 aRet
<<= pDate
->GetUNODate();
1024 else if (aPropertyName
== PROPERTYNAME_STDDEC
)
1025 aRet
<<= (sal_Int16
)( pFormatter
->GetStandardPrec() );
1026 else if (aPropertyName
== PROPERTYNAME_TWODIGIT
)
1027 aRet
<<= (sal_Int16
)( pFormatter
->GetYear2000() );
1029 throw beans::UnknownPropertyException();
1032 throw uno::RuntimeException();
1037 void SAL_CALL
SvNumberFormatSettingsObj::addPropertyChangeListener( const OUString
&,
1038 const uno::Reference
<beans::XPropertyChangeListener
>&)
1039 throw(beans::UnknownPropertyException
,
1040 lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
1042 OSL_FAIL("not implemented");
1045 void SAL_CALL
SvNumberFormatSettingsObj::removePropertyChangeListener( const OUString
&,
1046 const uno::Reference
<beans::XPropertyChangeListener
>&)
1047 throw(beans::UnknownPropertyException
,
1048 lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
1050 OSL_FAIL("not implemented");
1053 void SAL_CALL
SvNumberFormatSettingsObj::addVetoableChangeListener( const OUString
&,
1054 const uno::Reference
<beans::XVetoableChangeListener
>&)
1055 throw(beans::UnknownPropertyException
,
1056 lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
1058 OSL_FAIL("not implemented");
1061 void SAL_CALL
SvNumberFormatSettingsObj::removeVetoableChangeListener( const OUString
&,
1062 const uno::Reference
<beans::XVetoableChangeListener
>&)
1063 throw(beans::UnknownPropertyException
,
1064 lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
1066 OSL_FAIL("not implemented");
1071 OUString SAL_CALL
SvNumberFormatSettingsObj::getImplementationName()
1072 throw(uno::RuntimeException
, std::exception
)
1074 return OUString("SvNumberFormatSettingsObj");
1077 sal_Bool SAL_CALL
SvNumberFormatSettingsObj::supportsService( const OUString
& ServiceName
)
1078 throw(uno::RuntimeException
, std::exception
)
1080 return cppu::supportsService( this, ServiceName
);
1083 uno::Sequence
<OUString
> SAL_CALL
SvNumberFormatSettingsObj::getSupportedServiceNames()
1084 throw(uno::RuntimeException
, std::exception
)
1086 uno::Sequence
<OUString
> aRet(1);
1087 OUString
* pArray
= aRet
.getArray();
1088 pArray
[0] = "com.sun.star.util.NumberFormatSettings";
1093 extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface
* SAL_CALL
1094 com_sun_star_uno_util_numbers_SvNumberFormatterServiceObject_get_implementation(::com::sun::star::uno::XComponentContext
*,
1095 ::com::sun::star::uno::Sequence
<css::uno::Any
> const &)
1097 return cppu::acquire(new SvNumberFormatterServiceObj());
1102 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */