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 .
21 #include <tools/color.hxx>
22 #include <i18nlangtag/mslangid.hxx>
23 #include <osl/mutex.hxx>
24 #include <rtl/ustring.hxx>
26 #include <com/sun/star/util/Date.hpp>
27 #include <com/sun/star/beans/PropertyAttribute.hpp>
29 #include "numfmuno.hxx"
30 #include <svl/numuno.hxx>
31 #include <svl/zforlist.hxx>
32 #include <svl/zformat.hxx>
33 #include <svl/itemprop.hxx>
35 using namespace com::sun::star
;
37 //------------------------------------------------------------------------
39 #define SERVICENAME_NUMBERFORMATTER "com.sun.star.util.NumberFormatter"
40 #define SERVICENAME_NUMBERSETTINGS "com.sun.star.util.NumberFormatSettings"
41 #define SERVICENAME_NUMBERFORMATS "com.sun.star.util.NumberFormats"
42 #define SERVICENAME_NUMBERFORMAT "com.sun.star.util.NumberFormatProperties"
44 //------------------------------------------------------------------------
46 #define PROPERTYNAME_FMTSTR "FormatString"
47 #define PROPERTYNAME_LOCALE "Locale"
48 #define PROPERTYNAME_TYPE "Type"
49 #define PROPERTYNAME_COMMENT "Comment"
50 #define PROPERTYNAME_CURREXT "CurrencyExtension"
51 #define PROPERTYNAME_CURRSYM "CurrencySymbol"
52 #define PROPERTYNAME_CURRABB "CurrencyAbbreviation"
53 #define PROPERTYNAME_DECIMALS "Decimals"
54 #define PROPERTYNAME_LEADING "LeadingZeros"
55 #define PROPERTYNAME_NEGRED "NegativeRed"
56 #define PROPERTYNAME_STDFORM "StandardFormat"
57 #define PROPERTYNAME_THOUS "ThousandsSeparator"
58 #define PROPERTYNAME_USERDEF "UserDefined"
60 #define PROPERTYNAME_NOZERO "NoZero"
61 #define PROPERTYNAME_NULLDATE "NullDate"
62 #define PROPERTYNAME_STDDEC "StandardDecimals"
63 #define PROPERTYNAME_TWODIGIT "TwoDigitDateStart"
65 //------------------------------------------------------------------------
67 // alles ohne Which-ID, Map nur fuer PropertySetInfo
69 static const SfxItemPropertyMapEntry
* lcl_GetNumberFormatPropertyMap()
71 static SfxItemPropertyMapEntry aNumberFormatPropertyMap_Impl
[] =
73 {MAP_CHAR_LEN(PROPERTYNAME_FMTSTR
), 0, &getCppuType((OUString
*)0), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
74 {MAP_CHAR_LEN(PROPERTYNAME_LOCALE
), 0, &getCppuType((lang::Locale
*)0),beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
75 {MAP_CHAR_LEN(PROPERTYNAME_TYPE
), 0, &getCppuType((sal_Int16
*)0), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
76 {MAP_CHAR_LEN(PROPERTYNAME_COMMENT
), 0, &getCppuType((OUString
*)0), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
77 {MAP_CHAR_LEN(PROPERTYNAME_CURREXT
), 0, &getCppuType((OUString
*)0), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
78 {MAP_CHAR_LEN(PROPERTYNAME_CURRSYM
), 0, &getCppuType((OUString
*)0), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
79 {MAP_CHAR_LEN(PROPERTYNAME_DECIMALS
), 0, &getCppuType((sal_Int16
*)0), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
80 {MAP_CHAR_LEN(PROPERTYNAME_LEADING
), 0, &getCppuType((sal_Int16
*)0), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
81 {MAP_CHAR_LEN(PROPERTYNAME_NEGRED
), 0, &getBooleanCppuType(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
82 {MAP_CHAR_LEN(PROPERTYNAME_STDFORM
), 0, &getBooleanCppuType(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
83 {MAP_CHAR_LEN(PROPERTYNAME_THOUS
), 0, &getBooleanCppuType(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
84 {MAP_CHAR_LEN(PROPERTYNAME_USERDEF
), 0, &getBooleanCppuType(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
85 {MAP_CHAR_LEN(PROPERTYNAME_CURRABB
), 0, &getCppuType((OUString
*)0), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
88 return aNumberFormatPropertyMap_Impl
;
91 static const SfxItemPropertyMapEntry
* lcl_GetNumberSettingsPropertyMap()
93 static SfxItemPropertyMapEntry aNumberSettingsPropertyMap_Impl
[] =
95 {MAP_CHAR_LEN(PROPERTYNAME_NOZERO
), 0, &getBooleanCppuType(), beans::PropertyAttribute::BOUND
, 0},
96 {MAP_CHAR_LEN(PROPERTYNAME_NULLDATE
), 0, &getCppuType((util::Date
*)0), beans::PropertyAttribute::BOUND
, 0},
97 {MAP_CHAR_LEN(PROPERTYNAME_STDDEC
), 0, &getCppuType((sal_Int16
*)0), beans::PropertyAttribute::BOUND
, 0},
98 {MAP_CHAR_LEN(PROPERTYNAME_TWODIGIT
), 0, &getCppuType((sal_Int16
*)0), beans::PropertyAttribute::BOUND
, 0},
101 return aNumberSettingsPropertyMap_Impl
;
104 //----------------------------------------------------------------------------------------
106 static LanguageType
lcl_GetLanguage( const lang::Locale
& rLocale
)
108 // empty language -> LANGUAGE_SYSTEM
109 if ( rLocale
.Language
.isEmpty() )
110 return LANGUAGE_SYSTEM
;
112 LanguageType eRet
= LanguageTag( rLocale
).getLanguageType( false );
113 if ( eRet
== LANGUAGE_NONE
)
114 eRet
= LANGUAGE_SYSTEM
; //! or throw an exception?
119 //----------------------------------------------------------------------------------------
121 SvNumberFormatterServiceObj::SvNumberFormatterServiceObj()
126 SvNumberFormatterServiceObj::~SvNumberFormatterServiceObj()
130 com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> SAL_CALL
SvNumberFormatterServiceObj_CreateInstance( SAL_UNUSED_PARAMETER
const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& )
132 return ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>( ( ::cppu::OWeakObject
* ) new SvNumberFormatterServiceObj
);
137 void SAL_CALL
SvNumberFormatterServiceObj::attachNumberFormatsSupplier( const uno::Reference
<util::XNumberFormatsSupplier
>& _xSupplier
)
138 throw(uno::RuntimeException
)
140 ::rtl::Reference
< SvNumberFormatsSupplierObj
> xAutoReleaseOld
;
144 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
146 SvNumberFormatsSupplierObj
* pNew
= SvNumberFormatsSupplierObj::getImplementation( _xSupplier
);
148 throw uno::RuntimeException(); // wrong object
150 xAutoReleaseOld
= xSupplier
;
153 m_aMutex
= xSupplier
->getSharedMutex();
158 uno::Reference
<util::XNumberFormatsSupplier
> SAL_CALL
SvNumberFormatterServiceObj::getNumberFormatsSupplier()
159 throw(uno::RuntimeException
)
161 ::osl::MutexGuard
aGuard( m_aMutex
);
162 return xSupplier
.get();
165 sal_Int32 SAL_CALL
SvNumberFormatterServiceObj::detectNumberFormat( sal_Int32 nKey
, const OUString
& aString
)
166 throw(util::NotNumericException
, uno::RuntimeException
)
168 ::osl::MutexGuard
aGuard( m_aMutex
);
171 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : NULL
;
174 sal_uInt32 nUKey
= nKey
;
176 if ( pFormatter
->IsNumberFormat(aString
, nUKey
, fValue
) )
179 throw util::NotNumericException();
182 throw uno::RuntimeException();
187 double SAL_CALL
SvNumberFormatterServiceObj::convertStringToNumber( sal_Int32 nKey
, const OUString
& aString
)
188 throw(util::NotNumericException
, uno::RuntimeException
)
190 ::osl::MutexGuard
aGuard( m_aMutex
);
193 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : NULL
;
196 sal_uInt32 nUKey
= nKey
;
198 if ( pFormatter
->IsNumberFormat(aString
, nUKey
, fValue
) )
201 throw util::NotNumericException();
204 throw uno::RuntimeException();
209 OUString SAL_CALL
SvNumberFormatterServiceObj::convertNumberToString( sal_Int32 nKey
, double fValue
)
210 throw(uno::RuntimeException
)
212 ::osl::MutexGuard
aGuard( m_aMutex
);
215 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : NULL
;
218 Color
* pColor
= NULL
;
219 pFormatter
->GetOutputString(fValue
, nKey
, aRet
, &pColor
);
222 throw uno::RuntimeException();
227 util::Color SAL_CALL
SvNumberFormatterServiceObj::queryColorForNumber( sal_Int32 nKey
,
229 util::Color aDefaultColor
)
230 throw(uno::RuntimeException
)
232 ::osl::MutexGuard
aGuard( m_aMutex
);
234 util::Color nRet
= aDefaultColor
; // color = sal_Int32
235 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : NULL
;
239 Color
* pColor
= NULL
;
240 pFormatter
->GetOutputString(fValue
, nKey
, aStr
, &pColor
);
242 nRet
= pColor
->GetColor();
243 // sonst Default behalten
246 throw uno::RuntimeException();
251 OUString SAL_CALL
SvNumberFormatterServiceObj::formatString( sal_Int32 nKey
,
252 const OUString
& aString
)
253 throw(uno::RuntimeException
)
255 ::osl::MutexGuard
aGuard( m_aMutex
);
258 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : NULL
;
261 OUString aTemp
= aString
;
262 Color
* pColor
= NULL
;
263 pFormatter
->GetOutputString(aTemp
, nKey
, aRet
, &pColor
);
267 throw uno::RuntimeException();
272 util::Color SAL_CALL
SvNumberFormatterServiceObj::queryColorForString( sal_Int32 nKey
,
273 const OUString
& aString
,
274 util::Color aDefaultColor
)
275 throw(uno::RuntimeException
)
277 ::osl::MutexGuard
aGuard( m_aMutex
);
279 util::Color nRet
= aDefaultColor
; // color = sal_Int32
280 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : NULL
;
283 OUString aTemp
= aString
;
285 Color
* pColor
= NULL
;
286 pFormatter
->GetOutputString(aTemp
, nKey
, aStr
, &pColor
);
289 nRet
= pColor
->GetColor();
291 // sonst Default behalten
295 throw uno::RuntimeException();
301 OUString SAL_CALL
SvNumberFormatterServiceObj::getInputString( sal_Int32 nKey
, double fValue
)
302 throw(uno::RuntimeException
)
304 ::osl::MutexGuard
aGuard( m_aMutex
);
307 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : NULL
;
309 pFormatter
->GetInputLineString(fValue
, nKey
, aRet
);
311 throw uno::RuntimeException();
316 // XNumberFormatPreviewer
318 OUString SAL_CALL
SvNumberFormatterServiceObj::convertNumberToPreviewString( const OUString
& aFormat
,
320 const lang::Locale
& nLocale
,
321 sal_Bool bAllowEnglish
)
322 throw(util::MalformedNumberFormatException
, uno::RuntimeException
)
324 ::osl::MutexGuard
aGuard( m_aMutex
);
327 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : NULL
;
330 LanguageType eLang
= lcl_GetLanguage( nLocale
);
331 Color
* pColor
= NULL
;
335 bOk
= pFormatter
->GetPreviewStringGuess( aFormat
, fValue
, aRet
, &pColor
, eLang
);
337 bOk
= pFormatter
->GetPreviewString( aFormat
, fValue
, aRet
, &pColor
, eLang
);
340 throw util::MalformedNumberFormatException();
343 throw uno::RuntimeException();
348 util::Color SAL_CALL
SvNumberFormatterServiceObj::queryPreviewColorForNumber( const OUString
& aFormat
,
350 const lang::Locale
& nLocale
,
351 sal_Bool bAllowEnglish
,
352 util::Color aDefaultColor
)
353 throw(util::MalformedNumberFormatException
, uno::RuntimeException
)
355 ::osl::MutexGuard
aGuard( m_aMutex
);
357 util::Color nRet
= aDefaultColor
; // color = sal_Int32
358 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : NULL
;
362 LanguageType eLang
= lcl_GetLanguage( nLocale
);
363 Color
* pColor
= NULL
;
367 bOk
= pFormatter
->GetPreviewStringGuess( aFormat
, fValue
, aOutString
, &pColor
, eLang
);
369 bOk
= pFormatter
->GetPreviewString( aFormat
, fValue
, aOutString
, &pColor
, eLang
);
374 nRet
= pColor
->GetColor();
375 // sonst Default behalten
378 throw util::MalformedNumberFormatException();
381 throw uno::RuntimeException();
388 OUString SAL_CALL
SvNumberFormatterServiceObj::getImplementationName()
389 throw(uno::RuntimeException
)
391 return OUString("com.sun.star.uno.util.numbers.SvNumberFormatterServiceObject");
394 sal_Bool SAL_CALL
SvNumberFormatterServiceObj::supportsService( const OUString
& ServiceName
)
395 throw(uno::RuntimeException
)
397 return ( ServiceName
.compareToAscii(SERVICENAME_NUMBERFORMATTER
) == 0 );
400 uno::Sequence
<OUString
> SAL_CALL
SvNumberFormatterServiceObj::getSupportedServiceNames()
401 throw(uno::RuntimeException
)
403 uno::Sequence
<OUString
> aRet(1);
404 OUString
* pArray
= aRet
.getArray();
405 pArray
[0] = SERVICENAME_NUMBERFORMATTER
;
409 //------------------------------------------------------------------------
411 SvNumberFormatsObj::SvNumberFormatsObj( SvNumberFormatsSupplierObj
& _rParent
, ::comphelper::SharedMutex
& _rMutex
)
412 :rSupplier( _rParent
)
418 SvNumberFormatsObj::~SvNumberFormatsObj()
425 uno::Reference
<beans::XPropertySet
> SAL_CALL
SvNumberFormatsObj::getByKey( sal_Int32 nKey
)
426 throw(uno::RuntimeException
)
428 ::osl::MutexGuard
aGuard( m_aMutex
);
430 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
431 const SvNumberformat
* pFormat
= pFormatter
? pFormatter
->GetEntry(nKey
) : NULL
;
433 return new SvNumberFormatObj( rSupplier
, nKey
, m_aMutex
);
435 throw uno::RuntimeException();
438 uno::Sequence
<sal_Int32
> SAL_CALL
SvNumberFormatsObj::queryKeys( sal_Int16 nType
,
439 const lang::Locale
& nLocale
,
441 throw(uno::RuntimeException
)
443 ::osl::MutexGuard
aGuard( m_aMutex
);
445 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
448 sal_uInt32 nIndex
= 0;
449 LanguageType eLang
= lcl_GetLanguage( nLocale
);
450 SvNumberFormatTable
& rTable
= bCreate
?
451 pFormatter
->ChangeCL( nType
, nIndex
, eLang
) :
452 pFormatter
->GetEntryTable( nType
, nIndex
, eLang
);
453 sal_uInt32 nCount
= rTable
.size();
454 uno::Sequence
<sal_Int32
> aSeq(nCount
);
455 sal_Int32
* pAry
= aSeq
.getArray();
457 for (SvNumberFormatTable::iterator it
= rTable
.begin(); it
!= rTable
.end(); ++it
, ++i
)
463 throw uno::RuntimeException();
466 sal_Int32 SAL_CALL
SvNumberFormatsObj::queryKey( const OUString
& aFormat
,
467 const lang::Locale
& nLocale
,
469 throw(uno::RuntimeException
)
471 ::osl::MutexGuard
aGuard( m_aMutex
);
474 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
477 LanguageType eLang
= lcl_GetLanguage( nLocale
);
480 //! irgendwas muss hier noch passieren...
482 nRet
= pFormatter
->GetEntryKey( aFormat
, eLang
);
485 throw uno::RuntimeException();
490 sal_Int32 SAL_CALL
SvNumberFormatsObj::addNew( const OUString
& aFormat
,
491 const lang::Locale
& nLocale
)
492 throw(util::MalformedNumberFormatException
, uno::RuntimeException
)
494 ::osl::MutexGuard
aGuard( m_aMutex
);
497 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
500 OUString aFormStr
= aFormat
;
501 LanguageType eLang
= lcl_GetLanguage( nLocale
);
503 sal_Int32 nCheckPos
= 0;
505 bool bOk
= pFormatter
->PutEntry( aFormStr
, nCheckPos
, nType
, nKey
, eLang
);
510 throw util::MalformedNumberFormatException(); // ungueltiges Format
513 throw uno::RuntimeException(); // anderer Fehler (z.B. schon vorhanden)
516 throw uno::RuntimeException();
521 sal_Int32 SAL_CALL
SvNumberFormatsObj::addNewConverted( const OUString
& aFormat
,
522 const lang::Locale
& nLocale
,
523 const lang::Locale
& nNewLocale
)
524 throw(util::MalformedNumberFormatException
, uno::RuntimeException
)
526 ::osl::MutexGuard
aGuard( m_aMutex
);
529 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
532 OUString aFormStr
= aFormat
;
533 LanguageType eLang
= lcl_GetLanguage( nLocale
);
534 LanguageType eNewLang
= lcl_GetLanguage( nNewLocale
);
536 sal_Int32 nCheckPos
= 0;
538 bool bOk
= pFormatter
->PutandConvertEntry( aFormStr
, nCheckPos
, nType
, nKey
, eLang
, eNewLang
);
543 throw util::MalformedNumberFormatException(); // ungueltiges Format
546 throw uno::RuntimeException(); // anderer Fehler (z.B. schon vorhanden)
549 throw uno::RuntimeException();
554 void SAL_CALL
SvNumberFormatsObj::removeByKey( sal_Int32 nKey
) throw(uno::RuntimeException
)
556 ::osl::MutexGuard
aGuard( m_aMutex
);
557 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
561 pFormatter
->DeleteEntry(nKey
);
562 rSupplier
.NumberFormatDeleted(nKey
); // Benachrichtigung fuers Dokument
566 OUString SAL_CALL
SvNumberFormatsObj::generateFormat( sal_Int32 nBaseKey
,
567 const lang::Locale
& nLocale
,
569 sal_Bool bRed
, sal_Int16 nDecimals
,
571 throw(uno::RuntimeException
)
573 ::osl::MutexGuard
aGuard( m_aMutex
);
576 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
579 LanguageType eLang
= lcl_GetLanguage( nLocale
);
580 aRet
= pFormatter
->GenerateFormat(nBaseKey
, eLang
, bThousands
, bRed
, nDecimals
, nLeading
);
583 throw uno::RuntimeException();
588 // XNumberFormatTypes
590 sal_Int32 SAL_CALL
SvNumberFormatsObj::getStandardIndex( const lang::Locale
& nLocale
)
591 throw(uno::RuntimeException
)
593 ::osl::MutexGuard
aGuard( m_aMutex
);
596 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
599 LanguageType eLang
= lcl_GetLanguage( nLocale
);
600 nRet
= pFormatter
->GetStandardIndex(eLang
);
603 throw uno::RuntimeException();
608 sal_Int32 SAL_CALL
SvNumberFormatsObj::getStandardFormat( sal_Int16 nType
, const lang::Locale
& nLocale
)
609 throw(uno::RuntimeException
)
611 ::osl::MutexGuard
aGuard( m_aMutex
);
614 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
617 LanguageType eLang
= lcl_GetLanguage( nLocale
);
618 // mask out "defined" bit, so type from an existing number format
619 // can directly be used for getStandardFormat
620 nType
&= ~NUMBERFORMAT_DEFINED
;
621 nRet
= pFormatter
->GetStandardFormat(nType
, eLang
);
624 throw uno::RuntimeException();
629 sal_Int32 SAL_CALL
SvNumberFormatsObj::getFormatIndex( sal_Int16 nIndex
, const lang::Locale
& nLocale
)
630 throw(uno::RuntimeException
)
632 ::osl::MutexGuard
aGuard( m_aMutex
);
635 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
638 LanguageType eLang
= lcl_GetLanguage( nLocale
);
639 nRet
= pFormatter
->GetFormatIndex( (NfIndexTableOffset
)nIndex
, eLang
);
642 throw uno::RuntimeException();
647 sal_Bool SAL_CALL
SvNumberFormatsObj::isTypeCompatible( sal_Int16 nOldType
, sal_Int16 nNewType
)
648 throw(uno::RuntimeException
)
650 ::osl::MutexGuard
aGuard( m_aMutex
);
652 sal_Bool bRet
= sal_False
;
653 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
655 bRet
= pFormatter
->IsCompatible( nOldType
, nNewType
);
657 throw uno::RuntimeException();
662 sal_Int32 SAL_CALL
SvNumberFormatsObj::getFormatForLocale( sal_Int32 nKey
, const lang::Locale
& nLocale
)
663 throw(uno::RuntimeException
)
665 ::osl::MutexGuard
aGuard( m_aMutex
);
668 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
671 LanguageType eLang
= lcl_GetLanguage( nLocale
);
672 nRet
= pFormatter
->GetFormatForLanguageIfBuiltIn(nKey
, eLang
);
675 throw uno::RuntimeException();
682 OUString SAL_CALL
SvNumberFormatsObj::getImplementationName()
683 throw(uno::RuntimeException
)
685 return OUString("SvNumberFormatsObj");
688 sal_Bool SAL_CALL
SvNumberFormatsObj::supportsService( const OUString
& ServiceName
)
689 throw(uno::RuntimeException
)
691 return ( ServiceName
.compareToAscii(SERVICENAME_NUMBERFORMATS
) == 0 );
694 uno::Sequence
<OUString
> SAL_CALL
SvNumberFormatsObj::getSupportedServiceNames()
695 throw(uno::RuntimeException
)
697 uno::Sequence
<OUString
> aRet(1);
698 OUString
* pArray
= aRet
.getArray();
699 pArray
[0] = OUString(SERVICENAME_NUMBERFORMATS
);
703 //------------------------------------------------------------------------
705 SvNumberFormatObj::SvNumberFormatObj( SvNumberFormatsSupplierObj
& rParent
, sal_uLong nK
, const ::comphelper::SharedMutex
& _rMutex
)
706 :rSupplier( rParent
)
713 SvNumberFormatObj::~SvNumberFormatObj()
720 uno::Reference
<beans::XPropertySetInfo
> SAL_CALL
SvNumberFormatObj::getPropertySetInfo()
721 throw(uno::RuntimeException
)
723 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
724 static uno::Reference
<beans::XPropertySetInfo
> aRef
=
725 new SfxItemPropertySetInfo( lcl_GetNumberFormatPropertyMap() );
729 void SAL_CALL
SvNumberFormatObj::setPropertyValue( const OUString
&,
731 throw(beans::UnknownPropertyException
, beans::PropertyVetoException
,
732 lang::IllegalArgumentException
, lang::WrappedTargetException
,
733 uno::RuntimeException
)
735 throw beans::UnknownPropertyException(); // everything is read-only
738 uno::Any SAL_CALL
SvNumberFormatObj::getPropertyValue( const OUString
& aPropertyName
)
739 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
,
740 uno::RuntimeException
)
742 ::osl::MutexGuard
aGuard( m_aMutex
);
745 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
746 const SvNumberformat
* pFormat
= pFormatter
? pFormatter
->GetEntry(nKey
) : NULL
;
749 bool bThousand
, bRed
;
750 sal_uInt16 nDecimals
, nLeading
;
752 if (aPropertyName
.equalsAscii( PROPERTYNAME_FMTSTR
))
754 aRet
<<= OUString( pFormat
->GetFormatstring() );
756 else if (aPropertyName
.equalsAscii( PROPERTYNAME_LOCALE
))
758 lang::Locale
aLocale( LanguageTag( pFormat
->GetLanguage()).getLocale());
761 else if (aPropertyName
.equalsAscii( PROPERTYNAME_TYPE
))
763 aRet
<<= (sal_Int16
)( pFormat
->GetType() );
765 else if (aPropertyName
.equalsAscii( PROPERTYNAME_COMMENT
))
767 aRet
<<= OUString( pFormat
->GetComment() );
769 else if (aPropertyName
.equalsAscii( PROPERTYNAME_STDFORM
))
771 //! SvNumberformat Member bStandard rausreichen?
772 sal_Bool bStandard
= ( ( nKey
% SV_COUNTRY_LANGUAGE_OFFSET
) == 0 );
773 aRet
.setValue( &bStandard
, getBooleanCppuType() );
775 else if (aPropertyName
.equalsAscii( PROPERTYNAME_USERDEF
))
777 sal_Bool bUserDef
= ( ( pFormat
->GetType() & NUMBERFORMAT_DEFINED
) != 0 );
778 aRet
.setValue( &bUserDef
, getBooleanCppuType() );
780 else if (aPropertyName
.equalsAscii( PROPERTYNAME_DECIMALS
))
782 pFormat
->GetFormatSpecialInfo( bThousand
, bRed
, nDecimals
, nLeading
);
783 aRet
<<= (sal_Int16
)( nDecimals
);
785 else if (aPropertyName
.equalsAscii( PROPERTYNAME_LEADING
))
787 pFormat
->GetFormatSpecialInfo( bThousand
, bRed
, nDecimals
, nLeading
);
788 aRet
<<= (sal_Int16
)( nLeading
);
790 else if (aPropertyName
.equalsAscii( PROPERTYNAME_NEGRED
))
792 pFormat
->GetFormatSpecialInfo( bThousand
, bRed
, nDecimals
, nLeading
);
793 aRet
.setValue( &bRed
, getBooleanCppuType() );
795 else if (aPropertyName
.equalsAscii( PROPERTYNAME_THOUS
))
797 pFormat
->GetFormatSpecialInfo( bThousand
, bRed
, nDecimals
, nLeading
);
798 aRet
.setValue( &bThousand
, getBooleanCppuType() );
800 else if (aPropertyName
.equalsAscii( PROPERTYNAME_CURRSYM
))
802 OUString aSymbol
, aExt
;
803 pFormat
->GetNewCurrencySymbol( aSymbol
, aExt
);
806 else if (aPropertyName
.equalsAscii( PROPERTYNAME_CURREXT
))
808 OUString aSymbol
, aExt
;
809 pFormat
->GetNewCurrencySymbol( aSymbol
, aExt
);
812 else if (aPropertyName
.equalsAscii( PROPERTYNAME_CURRABB
))
814 OUString aSymbol
, aExt
;
816 pFormat
->GetNewCurrencySymbol( aSymbol
, aExt
);
817 const NfCurrencyEntry
* pCurr
= pFormatter
->GetCurrencyEntry( bBank
,
818 aSymbol
, aExt
, pFormat
->GetLanguage() );
820 aRet
<<= OUString( pCurr
->GetBankSymbol() );
825 throw beans::UnknownPropertyException();
828 throw uno::RuntimeException();
833 void SAL_CALL
SvNumberFormatObj::addPropertyChangeListener( const OUString
&,
834 const uno::Reference
<beans::XPropertyChangeListener
>&)
835 throw(beans::UnknownPropertyException
,
836 lang::WrappedTargetException
, uno::RuntimeException
)
838 OSL_FAIL("not implemented");
841 void SAL_CALL
SvNumberFormatObj::removePropertyChangeListener( const OUString
&,
842 const uno::Reference
<beans::XPropertyChangeListener
>&)
843 throw(beans::UnknownPropertyException
,
844 lang::WrappedTargetException
, uno::RuntimeException
)
846 OSL_FAIL("not implemented");
849 void SAL_CALL
SvNumberFormatObj::addVetoableChangeListener( const OUString
&,
850 const uno::Reference
<beans::XVetoableChangeListener
>&)
851 throw(beans::UnknownPropertyException
,
852 lang::WrappedTargetException
, uno::RuntimeException
)
854 OSL_FAIL("not implemented");
857 void SAL_CALL
SvNumberFormatObj::removeVetoableChangeListener( const OUString
&,
858 const uno::Reference
<beans::XVetoableChangeListener
>&)
859 throw(beans::UnknownPropertyException
,
860 lang::WrappedTargetException
, uno::RuntimeException
)
862 OSL_FAIL("not implemented");
867 uno::Sequence
<beans::PropertyValue
> SAL_CALL
SvNumberFormatObj::getPropertyValues()
868 throw(uno::RuntimeException
)
870 ::osl::MutexGuard
aGuard( m_aMutex
);
872 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
873 const SvNumberformat
* pFormat
= pFormatter
? pFormatter
->GetEntry(nKey
) : NULL
;
876 OUString aSymbol
, aExt
;
879 pFormat
->GetNewCurrencySymbol( aSymbol
, aExt
);
880 const NfCurrencyEntry
* pCurr
= pFormatter
->GetCurrencyEntry( bBank
,
881 aSymbol
, aExt
, pFormat
->GetLanguage() );
883 aAbb
= pCurr
->GetBankSymbol();
885 OUString aFmtStr
= pFormat
->GetFormatstring();
886 OUString aComment
= pFormat
->GetComment();
887 sal_Bool bStandard
= ( ( nKey
% SV_COUNTRY_LANGUAGE_OFFSET
) == 0 );
888 //! SvNumberformat Member bStandard rausreichen?
889 sal_Bool bUserDef
= ( ( pFormat
->GetType() & NUMBERFORMAT_DEFINED
) != 0 );
890 bool bThousand
, bRed
;
891 sal_uInt16 nDecimals
, nLeading
;
892 pFormat
->GetFormatSpecialInfo( bThousand
, bRed
, nDecimals
, nLeading
);
893 lang::Locale
aLocale( LanguageTag( pFormat
->GetLanguage()).getLocale());
895 uno::Sequence
<beans::PropertyValue
> aSeq(13);
896 beans::PropertyValue
* pArray
= aSeq
.getArray();
898 pArray
[0].Name
= PROPERTYNAME_FMTSTR
;
899 pArray
[0].Value
<<= aFmtStr
;
900 pArray
[1].Name
= PROPERTYNAME_LOCALE
;
901 pArray
[1].Value
<<= aLocale
;
902 pArray
[2].Name
= PROPERTYNAME_TYPE
;
903 pArray
[2].Value
<<= (sal_Int16
)( pFormat
->GetType() );
904 pArray
[3].Name
= PROPERTYNAME_COMMENT
;
905 pArray
[3].Value
<<= aComment
;
906 pArray
[4].Name
= PROPERTYNAME_STDFORM
;
907 pArray
[4].Value
.setValue( &bStandard
, getBooleanCppuType() );
908 pArray
[5].Name
= PROPERTYNAME_USERDEF
;
909 pArray
[5].Value
.setValue( &bUserDef
, getBooleanCppuType() );
910 pArray
[6].Name
= PROPERTYNAME_DECIMALS
;
911 pArray
[6].Value
<<= (sal_Int16
)( nDecimals
);
912 pArray
[7].Name
= PROPERTYNAME_LEADING
;
913 pArray
[7].Value
<<= (sal_Int16
)( nLeading
);
914 pArray
[8].Name
= PROPERTYNAME_NEGRED
;
915 pArray
[8].Value
.setValue( &bRed
, getBooleanCppuType() );
916 pArray
[9].Name
= PROPERTYNAME_THOUS
;
917 pArray
[9].Value
.setValue( &bThousand
, getBooleanCppuType() );
918 pArray
[10].Name
= PROPERTYNAME_CURRSYM
;
919 pArray
[10].Value
<<= aSymbol
;
920 pArray
[11].Name
= PROPERTYNAME_CURREXT
;
921 pArray
[11].Value
<<= aExt
;
922 pArray
[12].Name
= PROPERTYNAME_CURRABB
;
923 pArray
[12].Value
<<= aAbb
;
928 throw uno::RuntimeException();
931 void SAL_CALL
SvNumberFormatObj::setPropertyValues( const uno::Sequence
<beans::PropertyValue
>& )
932 throw(beans::UnknownPropertyException
, beans::PropertyVetoException
,
933 lang::IllegalArgumentException
, lang::WrappedTargetException
,
934 uno::RuntimeException
)
936 throw beans::UnknownPropertyException(); // everything is read-only
941 OUString SAL_CALL
SvNumberFormatObj::getImplementationName()
942 throw(uno::RuntimeException
)
944 return OUString("SvNumberFormatObj");
947 sal_Bool SAL_CALL
SvNumberFormatObj::supportsService( const OUString
& ServiceName
)
948 throw(uno::RuntimeException
)
950 return ( ServiceName
.compareToAscii(SERVICENAME_NUMBERFORMAT
) == 0 );
953 uno::Sequence
<OUString
> SAL_CALL
SvNumberFormatObj::getSupportedServiceNames()
954 throw(uno::RuntimeException
)
956 uno::Sequence
<OUString
> aRet(1);
957 OUString
* pArray
= aRet
.getArray();
958 pArray
[0] = SERVICENAME_NUMBERFORMAT
;
962 //------------------------------------------------------------------------
964 SvNumberFormatSettingsObj::SvNumberFormatSettingsObj( SvNumberFormatsSupplierObj
& rParent
, const ::comphelper::SharedMutex
& _rMutex
)
965 :rSupplier( rParent
)
971 SvNumberFormatSettingsObj::~SvNumberFormatSettingsObj()
978 uno::Reference
<beans::XPropertySetInfo
> SAL_CALL
SvNumberFormatSettingsObj::getPropertySetInfo()
979 throw(uno::RuntimeException
)
981 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
982 static uno::Reference
<beans::XPropertySetInfo
> aRef
=
983 new SfxItemPropertySetInfo( lcl_GetNumberSettingsPropertyMap() );
987 void SAL_CALL
SvNumberFormatSettingsObj::setPropertyValue( const OUString
& aPropertyName
,
988 const uno::Any
& aValue
)
989 throw(beans::UnknownPropertyException
, beans::PropertyVetoException
,
990 lang::IllegalArgumentException
, lang::WrappedTargetException
,
991 uno::RuntimeException
)
993 ::osl::MutexGuard
aGuard( m_aMutex
);
995 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
998 if (aPropertyName
.equalsAscii( PROPERTYNAME_NOZERO
))
1000 // operator >>= shouldn't be used for bool (?)
1001 if ( aValue
.getValueTypeClass() == uno::TypeClass_BOOLEAN
)
1002 pFormatter
->SetNoZero( *(sal_Bool
*)aValue
.getValue() );
1004 else if (aPropertyName
.equalsAscii( PROPERTYNAME_NULLDATE
))
1007 if ( aValue
>>= aDate
)
1008 pFormatter
->ChangeNullDate( aDate
.Day
, aDate
.Month
, aDate
.Year
);
1010 else if (aPropertyName
.equalsAscii( PROPERTYNAME_STDDEC
))
1012 sal_Int16 nInt16
= sal_Int16();
1013 if ( aValue
>>= nInt16
)
1014 pFormatter
->ChangeStandardPrec( nInt16
);
1016 else if (aPropertyName
.equalsAscii( PROPERTYNAME_TWODIGIT
))
1018 sal_Int16 nInt16
= sal_Int16();
1019 if ( aValue
>>= nInt16
)
1020 pFormatter
->SetYear2000( nInt16
);
1023 throw beans::UnknownPropertyException();
1025 rSupplier
.SettingsChanged();
1028 throw uno::RuntimeException();
1031 uno::Any SAL_CALL
SvNumberFormatSettingsObj::getPropertyValue( const OUString
& aPropertyName
)
1032 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
,
1033 uno::RuntimeException
)
1035 ::osl::MutexGuard
aGuard( m_aMutex
);
1038 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
1041 if (aPropertyName
.equalsAscii( PROPERTYNAME_NOZERO
))
1043 sal_Bool bNoZero
= pFormatter
->GetNoZero();
1044 aRet
.setValue( &bNoZero
, getBooleanCppuType() );
1046 else if (aPropertyName
.equalsAscii( PROPERTYNAME_NULLDATE
))
1048 Date
* pDate
= pFormatter
->GetNullDate();
1051 util::Date
aUnoDate( pDate
->GetDay(), pDate
->GetMonth(), pDate
->GetYear() );
1055 else if (aPropertyName
.equalsAscii( PROPERTYNAME_STDDEC
))
1056 aRet
<<= (sal_Int16
)( pFormatter
->GetStandardPrec() );
1057 else if (aPropertyName
.equalsAscii( PROPERTYNAME_TWODIGIT
))
1058 aRet
<<= (sal_Int16
)( pFormatter
->GetYear2000() );
1060 throw beans::UnknownPropertyException();
1063 throw uno::RuntimeException();
1068 void SAL_CALL
SvNumberFormatSettingsObj::addPropertyChangeListener( const OUString
&,
1069 const uno::Reference
<beans::XPropertyChangeListener
>&)
1070 throw(beans::UnknownPropertyException
,
1071 lang::WrappedTargetException
, uno::RuntimeException
)
1073 OSL_FAIL("not implemented");
1076 void SAL_CALL
SvNumberFormatSettingsObj::removePropertyChangeListener( const OUString
&,
1077 const uno::Reference
<beans::XPropertyChangeListener
>&)
1078 throw(beans::UnknownPropertyException
,
1079 lang::WrappedTargetException
, uno::RuntimeException
)
1081 OSL_FAIL("not implemented");
1084 void SAL_CALL
SvNumberFormatSettingsObj::addVetoableChangeListener( const OUString
&,
1085 const uno::Reference
<beans::XVetoableChangeListener
>&)
1086 throw(beans::UnknownPropertyException
,
1087 lang::WrappedTargetException
, uno::RuntimeException
)
1089 OSL_FAIL("not implemented");
1092 void SAL_CALL
SvNumberFormatSettingsObj::removeVetoableChangeListener( const OUString
&,
1093 const uno::Reference
<beans::XVetoableChangeListener
>&)
1094 throw(beans::UnknownPropertyException
,
1095 lang::WrappedTargetException
, uno::RuntimeException
)
1097 OSL_FAIL("not implemented");
1102 OUString SAL_CALL
SvNumberFormatSettingsObj::getImplementationName()
1103 throw(uno::RuntimeException
)
1105 return OUString("SvNumberFormatSettingsObj");
1108 sal_Bool SAL_CALL
SvNumberFormatSettingsObj::supportsService( const OUString
& ServiceName
)
1109 throw(uno::RuntimeException
)
1111 return ( ServiceName
.compareToAscii(SERVICENAME_NUMBERSETTINGS
) == 0 );
1114 uno::Sequence
<OUString
> SAL_CALL
SvNumberFormatSettingsObj::getSupportedServiceNames()
1115 throw(uno::RuntimeException
)
1117 uno::Sequence
<OUString
> aRet(1);
1118 OUString
* pArray
= aRet
.getArray();
1119 pArray
[0] = SERVICENAME_NUMBERSETTINGS
;
1124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */