1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: numfmuno.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
36 #include <vcl/svapp.hxx>
37 #include <tools/color.hxx>
38 #include <tools/debug.hxx>
39 #include <i18npool/mslangid.hxx>
40 #include <vos/mutex.hxx>
41 #include <rtl/ustring.hxx>
43 #include <com/sun/star/util/Date.hpp>
44 #include <com/sun/star/beans/PropertyAttribute.hpp>
46 #include "numfmuno.hxx"
48 #include <svtools/zforlist.hxx>
49 #include <svtools/zformat.hxx>
50 #include <svtools/itemprop.hxx>
52 using namespace com::sun::star
;
54 //------------------------------------------------------------------------
56 #define SERVICENAME_NUMBERFORMATTER "com.sun.star.util.NumberFormatter"
57 #define SERVICENAME_NUMBERSETTINGS "com.sun.star.util.NumberFormatSettings"
58 #define SERVICENAME_NUMBERFORMATS "com.sun.star.util.NumberFormats"
59 #define SERVICENAME_NUMBERFORMAT "com.sun.star.util.NumberFormatProperties"
61 //------------------------------------------------------------------------
63 #define PROPERTYNAME_FMTSTR "FormatString"
64 #define PROPERTYNAME_LOCALE "Locale"
65 #define PROPERTYNAME_TYPE "Type"
66 #define PROPERTYNAME_COMMENT "Comment"
67 #define PROPERTYNAME_CURREXT "CurrencyExtension"
68 #define PROPERTYNAME_CURRSYM "CurrencySymbol"
69 #define PROPERTYNAME_CURRABB "CurrencyAbbreviation"
70 #define PROPERTYNAME_DECIMALS "Decimals"
71 #define PROPERTYNAME_LEADING "LeadingZeros"
72 #define PROPERTYNAME_NEGRED "NegativeRed"
73 #define PROPERTYNAME_STDFORM "StandardFormat"
74 #define PROPERTYNAME_THOUS "ThousandsSeparator"
75 #define PROPERTYNAME_USERDEF "UserDefined"
77 #define PROPERTYNAME_NOZERO "NoZero"
78 #define PROPERTYNAME_NULLDATE "NullDate"
79 #define PROPERTYNAME_STDDEC "StandardDecimals"
80 #define PROPERTYNAME_TWODIGIT "TwoDigitDateStart"
82 //------------------------------------------------------------------------
84 // alles ohne Which-ID, Map nur fuer PropertySetInfo
86 const SfxItemPropertyMapEntry
* lcl_GetNumberFormatPropertyMap()
88 static SfxItemPropertyMapEntry aNumberFormatPropertyMap_Impl
[] =
90 {MAP_CHAR_LEN(PROPERTYNAME_FMTSTR
), 0, &getCppuType((rtl::OUString
*)0),beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
91 {MAP_CHAR_LEN(PROPERTYNAME_LOCALE
), 0, &getCppuType((lang::Locale
*)0),beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
92 {MAP_CHAR_LEN(PROPERTYNAME_TYPE
), 0, &getCppuType((sal_Int16
*)0), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
93 {MAP_CHAR_LEN(PROPERTYNAME_COMMENT
), 0, &getCppuType((rtl::OUString
*)0),beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
94 {MAP_CHAR_LEN(PROPERTYNAME_CURREXT
), 0, &getCppuType((rtl::OUString
*)0),beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
95 {MAP_CHAR_LEN(PROPERTYNAME_CURRSYM
), 0, &getCppuType((rtl::OUString
*)0),beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
96 {MAP_CHAR_LEN(PROPERTYNAME_DECIMALS
), 0, &getCppuType((sal_Int16
*)0), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
97 {MAP_CHAR_LEN(PROPERTYNAME_LEADING
), 0, &getCppuType((sal_Int16
*)0), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
98 {MAP_CHAR_LEN(PROPERTYNAME_NEGRED
), 0, &getBooleanCppuType(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
99 {MAP_CHAR_LEN(PROPERTYNAME_STDFORM
), 0, &getBooleanCppuType(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
100 {MAP_CHAR_LEN(PROPERTYNAME_THOUS
), 0, &getBooleanCppuType(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
101 {MAP_CHAR_LEN(PROPERTYNAME_USERDEF
), 0, &getBooleanCppuType(), beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
102 {MAP_CHAR_LEN(PROPERTYNAME_CURRABB
), 0, &getCppuType((rtl::OUString
*)0),beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::READONLY
, 0},
105 return aNumberFormatPropertyMap_Impl
;
108 const SfxItemPropertyMapEntry
* lcl_GetNumberSettingsPropertyMap()
110 static SfxItemPropertyMapEntry aNumberSettingsPropertyMap_Impl
[] =
112 {MAP_CHAR_LEN(PROPERTYNAME_NOZERO
), 0, &getBooleanCppuType(), beans::PropertyAttribute::BOUND
, 0},
113 {MAP_CHAR_LEN(PROPERTYNAME_NULLDATE
), 0, &getCppuType((util::Date
*)0), beans::PropertyAttribute::BOUND
, 0},
114 {MAP_CHAR_LEN(PROPERTYNAME_STDDEC
), 0, &getCppuType((sal_Int16
*)0), beans::PropertyAttribute::BOUND
, 0},
115 {MAP_CHAR_LEN(PROPERTYNAME_TWODIGIT
), 0, &getCppuType((sal_Int16
*)0), beans::PropertyAttribute::BOUND
, 0},
118 return aNumberSettingsPropertyMap_Impl
;
121 //----------------------------------------------------------------------------------------
123 LanguageType
lcl_GetLanguage( const lang::Locale
& rLocale
)
125 // empty language -> LANGUAGE_SYSTEM
126 if ( rLocale
.Language
.getLength() == 0 )
127 return LANGUAGE_SYSTEM
;
129 LanguageType eRet
= MsLangId::convertLocaleToLanguage( rLocale
);
130 if ( eRet
== LANGUAGE_NONE
)
131 eRet
= LANGUAGE_SYSTEM
; //! or throw an exception?
136 //----------------------------------------------------------------------------------------
138 SvNumberFormatterServiceObj::SvNumberFormatterServiceObj()
143 SvNumberFormatterServiceObj::~SvNumberFormatterServiceObj()
147 com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> SAL_CALL
SvNumberFormatterServiceObj_CreateInstance( const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& )
149 return ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>( ( ::cppu::OWeakObject
* ) new SvNumberFormatterServiceObj
);
154 void SAL_CALL
SvNumberFormatterServiceObj::attachNumberFormatsSupplier(
155 const uno::Reference
<util::XNumberFormatsSupplier
>& _xSupplier
)
156 throw(uno::RuntimeException
)
158 ::rtl::Reference
< SvNumberFormatsSupplierObj
> xAutoReleaseOld
;
162 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
164 SvNumberFormatsSupplierObj
* pNew
= SvNumberFormatsSupplierObj::getImplementation( _xSupplier
);
166 throw uno::RuntimeException(); // wrong object
168 xAutoReleaseOld
= xSupplier
;
171 m_aMutex
= xSupplier
->getSharedMutex();
176 uno::Reference
<util::XNumberFormatsSupplier
> SAL_CALL
177 SvNumberFormatterServiceObj::getNumberFormatsSupplier()
178 throw(uno::RuntimeException
)
180 ::osl::MutexGuard
aGuard( m_aMutex
);
181 return xSupplier
.get();
184 sal_Int32 SAL_CALL
SvNumberFormatterServiceObj::detectNumberFormat(
185 sal_Int32 nKey
, const rtl::OUString
& aString
)
186 throw(util::NotNumericException
, uno::RuntimeException
)
188 ::osl::MutexGuard
aGuard( m_aMutex
);
191 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : NULL
;
194 String aTemp
= aString
;
195 sal_uInt32 nUKey
= nKey
;
197 if ( pFormatter
->IsNumberFormat(aTemp
, nUKey
, fValue
) )
200 throw util::NotNumericException();
203 throw uno::RuntimeException();
208 double SAL_CALL
SvNumberFormatterServiceObj::convertStringToNumber(
209 sal_Int32 nKey
, const rtl::OUString
& aString
)
210 throw(util::NotNumericException
, uno::RuntimeException
)
212 ::osl::MutexGuard
aGuard( m_aMutex
);
215 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : NULL
;
218 String aTemp
= aString
;
219 sal_uInt32 nUKey
= nKey
;
221 if ( pFormatter
->IsNumberFormat(aTemp
, nUKey
, fValue
) )
224 throw util::NotNumericException();
227 throw uno::RuntimeException();
232 rtl::OUString SAL_CALL
SvNumberFormatterServiceObj::convertNumberToString(
233 sal_Int32 nKey
, double fValue
) throw(uno::RuntimeException
)
235 ::osl::MutexGuard
aGuard( m_aMutex
);
238 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : NULL
;
241 Color
* pColor
= NULL
;
242 pFormatter
->GetOutputString(fValue
, nKey
, aRet
, &pColor
);
245 throw uno::RuntimeException();
250 util::Color SAL_CALL
SvNumberFormatterServiceObj::queryColorForNumber( sal_Int32 nKey
,
251 double fValue
, util::Color aDefaultColor
)
252 throw(uno::RuntimeException
)
254 ::osl::MutexGuard
aGuard( m_aMutex
);
256 util::Color nRet
= aDefaultColor
; // color = INT32
257 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : NULL
;
261 Color
* pColor
= NULL
;
262 pFormatter
->GetOutputString(fValue
, nKey
, aStr
, &pColor
);
264 nRet
= pColor
->GetColor();
265 // sonst Default behalten
268 throw uno::RuntimeException();
273 rtl::OUString SAL_CALL
SvNumberFormatterServiceObj::formatString( sal_Int32 nKey
,
274 const rtl::OUString
& aString
) throw(uno::RuntimeException
)
276 ::osl::MutexGuard
aGuard( m_aMutex
);
279 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : NULL
;
282 String aTemp
= aString
;
283 Color
* pColor
= NULL
;
284 pFormatter
->GetOutputString(aTemp
, nKey
, aRet
, &pColor
);
287 throw uno::RuntimeException();
292 util::Color SAL_CALL
SvNumberFormatterServiceObj::queryColorForString( sal_Int32 nKey
,
293 const rtl::OUString
& aString
,util::Color aDefaultColor
)
294 throw(uno::RuntimeException
)
296 ::osl::MutexGuard
aGuard( m_aMutex
);
298 util::Color nRet
= aDefaultColor
; // color = INT32
299 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : NULL
;
302 String aTemp
= aString
;
304 Color
* pColor
= NULL
;
305 pFormatter
->GetOutputString(aTemp
, nKey
, aStr
, &pColor
);
307 nRet
= pColor
->GetColor();
308 // sonst Default behalten
311 throw uno::RuntimeException();
316 rtl::OUString SAL_CALL
SvNumberFormatterServiceObj::getInputString( sal_Int32 nKey
, double fValue
)
317 throw(uno::RuntimeException
)
319 ::osl::MutexGuard
aGuard( m_aMutex
);
322 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : NULL
;
324 pFormatter
->GetInputLineString(fValue
, nKey
, aRet
);
326 throw uno::RuntimeException();
331 // XNumberFormatPreviewer
333 rtl::OUString SAL_CALL
SvNumberFormatterServiceObj::convertNumberToPreviewString(
334 const rtl::OUString
& aFormat
, double fValue
,
335 const lang::Locale
& nLocale
, sal_Bool bAllowEnglish
)
336 throw(util::MalformedNumberFormatException
, uno::RuntimeException
)
338 ::osl::MutexGuard
aGuard( m_aMutex
);
341 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : NULL
;
345 String aFormString
= aFormat
;
346 LanguageType eLang
= lcl_GetLanguage( nLocale
);
347 Color
* pColor
= NULL
;
351 bOk
= pFormatter
->GetPreviewStringGuess(
352 aFormString
, fValue
, aOutString
, &pColor
, eLang
);
354 bOk
= pFormatter
->GetPreviewString(
355 aFormString
, fValue
, aOutString
, &pColor
, eLang
);
360 throw util::MalformedNumberFormatException();
363 throw uno::RuntimeException();
368 util::Color SAL_CALL
SvNumberFormatterServiceObj::queryPreviewColorForNumber(
369 const rtl::OUString
& aFormat
, double fValue
,
370 const lang::Locale
& nLocale
, sal_Bool bAllowEnglish
,
371 util::Color aDefaultColor
)
372 throw(util::MalformedNumberFormatException
, uno::RuntimeException
)
374 ::osl::MutexGuard
aGuard( m_aMutex
);
376 util::Color nRet
= aDefaultColor
; // color = INT32
377 SvNumberFormatter
* pFormatter
= xSupplier
.is() ? xSupplier
->GetNumberFormatter() : NULL
;
381 String aFormString
= aFormat
;
382 LanguageType eLang
= lcl_GetLanguage( nLocale
);
383 Color
* pColor
= NULL
;
387 bOk
= pFormatter
->GetPreviewStringGuess(
388 aFormString
, fValue
, aOutString
, &pColor
, eLang
);
390 bOk
= pFormatter
->GetPreviewString(
391 aFormString
, fValue
, aOutString
, &pColor
, eLang
);
396 nRet
= pColor
->GetColor();
397 // sonst Default behalten
400 throw util::MalformedNumberFormatException();
403 throw uno::RuntimeException();
410 rtl::OUString SAL_CALL
SvNumberFormatterServiceObj::getImplementationName()
411 throw(uno::RuntimeException
)
413 return rtl::OUString::createFromAscii("com.sun.star.uno.util.numbers.SvNumberFormatterServiceObject");
416 sal_Bool SAL_CALL
SvNumberFormatterServiceObj::supportsService( const rtl::OUString
& ServiceName
)
417 throw(uno::RuntimeException
)
419 return ( ServiceName
.compareToAscii(SERVICENAME_NUMBERFORMATTER
) == 0 );
422 uno::Sequence
<rtl::OUString
> SAL_CALL
SvNumberFormatterServiceObj::getSupportedServiceNames()
423 throw(uno::RuntimeException
)
425 uno::Sequence
<rtl::OUString
> aRet(1);
426 rtl::OUString
* pArray
= aRet
.getArray();
427 pArray
[0] = rtl::OUString::createFromAscii(SERVICENAME_NUMBERFORMATTER
);
431 //------------------------------------------------------------------------
433 SvNumberFormatsObj::SvNumberFormatsObj( SvNumberFormatsSupplierObj
& _rParent
, ::comphelper::SharedMutex
& _rMutex
)
434 :rSupplier( _rParent
)
440 SvNumberFormatsObj::~SvNumberFormatsObj()
447 uno::Reference
<beans::XPropertySet
> SAL_CALL
SvNumberFormatsObj::getByKey( sal_Int32 nKey
)
448 throw(uno::RuntimeException
)
450 ::osl::MutexGuard
aGuard( m_aMutex
);
452 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
453 const SvNumberformat
* pFormat
= pFormatter
? pFormatter
->GetEntry(nKey
) : NULL
;
455 return new SvNumberFormatObj( rSupplier
, nKey
, m_aMutex
);
457 throw uno::RuntimeException();
460 uno::Sequence
<sal_Int32
> SAL_CALL
SvNumberFormatsObj::queryKeys( sal_Int16 nType
,
461 const lang::Locale
& nLocale
, sal_Bool bCreate
)
462 throw(uno::RuntimeException
)
464 ::osl::MutexGuard
aGuard( m_aMutex
);
466 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
469 sal_uInt32 nIndex
= 0;
470 LanguageType eLang
= lcl_GetLanguage( nLocale
);
471 SvNumberFormatTable
& rTable
= bCreate
?
472 pFormatter
->ChangeCL( nType
, nIndex
, eLang
) :
473 pFormatter
->GetEntryTable( nType
, nIndex
, eLang
);
474 sal_uInt32 nCount
= rTable
.Count();
475 uno::Sequence
<sal_Int32
> aSeq(nCount
);
476 sal_Int32
* pAry
= aSeq
.getArray();
477 for (sal_uInt32 i
=0; i
<nCount
; i
++)
478 pAry
[i
] = rTable
.GetObjectKey( i
);
483 throw uno::RuntimeException();
486 sal_Int32 SAL_CALL
SvNumberFormatsObj::queryKey( const rtl::OUString
& aFormat
,
487 const lang::Locale
& nLocale
, sal_Bool bScan
)
488 throw(uno::RuntimeException
)
490 ::osl::MutexGuard
aGuard( m_aMutex
);
493 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
496 String aFormStr
= aFormat
;
497 LanguageType eLang
= lcl_GetLanguage( nLocale
);
500 //! irgendwas muss hier noch passieren...
502 nRet
= pFormatter
->GetEntryKey( aFormat
, eLang
);
505 throw uno::RuntimeException();
510 sal_Int32 SAL_CALL
SvNumberFormatsObj::addNew( const rtl::OUString
& aFormat
,
511 const lang::Locale
& nLocale
)
512 throw(util::MalformedNumberFormatException
, uno::RuntimeException
)
514 ::osl::MutexGuard
aGuard( m_aMutex
);
517 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
520 String aFormStr
= aFormat
;
521 LanguageType eLang
= lcl_GetLanguage( nLocale
);
523 xub_StrLen nCheckPos
= 0;
525 BOOL bOk
= pFormatter
->PutEntry( aFormStr
, nCheckPos
, nType
, nKey
, eLang
);
530 throw util::MalformedNumberFormatException(); // ungueltiges Format
533 throw uno::RuntimeException(); // anderer Fehler (z.B. schon vorhanden)
536 throw uno::RuntimeException();
541 sal_Int32 SAL_CALL
SvNumberFormatsObj::addNewConverted( const rtl::OUString
& aFormat
,
542 const lang::Locale
& nLocale
, const lang::Locale
& nNewLocale
)
543 throw(util::MalformedNumberFormatException
, uno::RuntimeException
)
545 ::osl::MutexGuard
aGuard( m_aMutex
);
548 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
551 String aFormStr
= aFormat
;
552 LanguageType eLang
= lcl_GetLanguage( nLocale
);
553 LanguageType eNewLang
= lcl_GetLanguage( nNewLocale
);
555 xub_StrLen nCheckPos
= 0;
557 BOOL bOk
= pFormatter
->PutandConvertEntry( aFormStr
, nCheckPos
, nType
, nKey
, eLang
, eNewLang
);
562 throw util::MalformedNumberFormatException(); // ungueltiges Format
565 throw uno::RuntimeException(); // anderer Fehler (z.B. schon vorhanden)
568 throw uno::RuntimeException();
573 void SAL_CALL
SvNumberFormatsObj::removeByKey( sal_Int32 nKey
) throw(uno::RuntimeException
)
575 ::osl::MutexGuard
aGuard( m_aMutex
);
576 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
580 pFormatter
->DeleteEntry(nKey
);
581 rSupplier
.NumberFormatDeleted(nKey
); // Benachrichtigung fuers Dokument
585 rtl::OUString SAL_CALL
SvNumberFormatsObj::generateFormat( sal_Int32 nBaseKey
,
586 const lang::Locale
& nLocale
, sal_Bool bThousands
,
587 sal_Bool bRed
, sal_Int16 nDecimals
, sal_Int16 nLeading
)
588 throw(uno::RuntimeException
)
590 ::osl::MutexGuard
aGuard( m_aMutex
);
593 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
596 LanguageType eLang
= lcl_GetLanguage( nLocale
);
597 pFormatter
->GenerateFormat( aRet
, nBaseKey
, eLang
, bThousands
, bRed
, nDecimals
, nLeading
);
600 throw uno::RuntimeException();
605 // XNumberFormatTypes
607 sal_Int32 SAL_CALL
SvNumberFormatsObj::getStandardIndex( const lang::Locale
& nLocale
)
608 throw(uno::RuntimeException
)
610 ::osl::MutexGuard
aGuard( m_aMutex
);
613 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
616 LanguageType eLang
= lcl_GetLanguage( nLocale
);
617 nRet
= pFormatter
->GetStandardIndex(eLang
);
620 throw uno::RuntimeException();
625 sal_Int32 SAL_CALL
SvNumberFormatsObj::getStandardFormat( sal_Int16 nType
, const lang::Locale
& nLocale
)
626 throw(uno::RuntimeException
)
628 ::osl::MutexGuard
aGuard( m_aMutex
);
631 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
634 LanguageType eLang
= lcl_GetLanguage( nLocale
);
635 // mask out "defined" bit, so type from an existing number format
636 // can directly be used for getStandardFormat
637 nType
&= ~NUMBERFORMAT_DEFINED
;
638 nRet
= pFormatter
->GetStandardFormat(nType
, eLang
);
641 throw uno::RuntimeException();
646 sal_Int32 SAL_CALL
SvNumberFormatsObj::getFormatIndex( sal_Int16 nIndex
, const lang::Locale
& nLocale
)
647 throw(uno::RuntimeException
)
649 ::osl::MutexGuard
aGuard( m_aMutex
);
652 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
655 LanguageType eLang
= lcl_GetLanguage( nLocale
);
656 nRet
= pFormatter
->GetFormatIndex( (NfIndexTableOffset
)nIndex
, eLang
);
659 throw uno::RuntimeException();
664 sal_Bool SAL_CALL
SvNumberFormatsObj::isTypeCompatible( sal_Int16 nOldType
, sal_Int16 nNewType
)
665 throw(uno::RuntimeException
)
667 ::osl::MutexGuard
aGuard( m_aMutex
);
670 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
672 bRet
= pFormatter
->IsCompatible( nOldType
, nNewType
);
674 throw uno::RuntimeException();
679 sal_Int32 SAL_CALL
SvNumberFormatsObj::getFormatForLocale( sal_Int32 nKey
, const lang::Locale
& nLocale
)
680 throw(uno::RuntimeException
)
682 ::osl::MutexGuard
aGuard( m_aMutex
);
685 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
688 LanguageType eLang
= lcl_GetLanguage( nLocale
);
689 nRet
= pFormatter
->GetFormatForLanguageIfBuiltIn(nKey
, eLang
);
692 throw uno::RuntimeException();
699 rtl::OUString SAL_CALL
SvNumberFormatsObj::getImplementationName()
700 throw(uno::RuntimeException
)
702 return rtl::OUString::createFromAscii("SvNumberFormatsObj");
705 sal_Bool SAL_CALL
SvNumberFormatsObj::supportsService( const rtl::OUString
& ServiceName
)
706 throw(uno::RuntimeException
)
708 return ( ServiceName
.compareToAscii(SERVICENAME_NUMBERFORMATS
) == 0 );
711 uno::Sequence
<rtl::OUString
> SAL_CALL
SvNumberFormatsObj::getSupportedServiceNames()
712 throw(uno::RuntimeException
)
714 uno::Sequence
<rtl::OUString
> aRet(1);
715 rtl::OUString
* pArray
= aRet
.getArray();
716 pArray
[0] = rtl::OUString::createFromAscii(SERVICENAME_NUMBERFORMATS
);
720 //------------------------------------------------------------------------
722 SvNumberFormatObj::SvNumberFormatObj( SvNumberFormatsSupplierObj
& rParent
, ULONG nK
, const ::comphelper::SharedMutex
& _rMutex
)
723 :rSupplier( rParent
)
730 SvNumberFormatObj::~SvNumberFormatObj()
737 uno::Reference
<beans::XPropertySetInfo
> SAL_CALL
SvNumberFormatObj::getPropertySetInfo()
738 throw(uno::RuntimeException
)
740 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
741 static uno::Reference
<beans::XPropertySetInfo
> aRef
=
742 new SfxItemPropertySetInfo( lcl_GetNumberFormatPropertyMap() );
746 void SAL_CALL
SvNumberFormatObj::setPropertyValue( const rtl::OUString
&,
748 throw(beans::UnknownPropertyException
, beans::PropertyVetoException
,
749 lang::IllegalArgumentException
, lang::WrappedTargetException
,
750 uno::RuntimeException
)
752 throw beans::UnknownPropertyException(); // everything is read-only
755 uno::Any SAL_CALL
SvNumberFormatObj::getPropertyValue( const rtl::OUString
& aPropertyName
)
756 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
,
757 uno::RuntimeException
)
759 ::osl::MutexGuard
aGuard( m_aMutex
);
762 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
763 const SvNumberformat
* pFormat
= pFormatter
? pFormatter
->GetEntry(nKey
) : NULL
;
766 BOOL bThousand
, bRed
;
767 USHORT nDecimals
, nLeading
;
769 String aString
= aPropertyName
;
770 if (aString
.EqualsAscii( PROPERTYNAME_FMTSTR
))
772 aRet
<<= rtl::OUString( pFormat
->GetFormatstring() );
774 else if (aString
.EqualsAscii( PROPERTYNAME_LOCALE
))
776 lang::Locale
aLocale( MsLangId::convertLanguageToLocale(
777 pFormat
->GetLanguage()));
780 else if (aString
.EqualsAscii( PROPERTYNAME_TYPE
))
782 aRet
<<= (sal_Int16
)( pFormat
->GetType() );
784 else if (aString
.EqualsAscii( PROPERTYNAME_COMMENT
))
786 aRet
<<= rtl::OUString( pFormat
->GetComment() );
788 else if (aString
.EqualsAscii( PROPERTYNAME_STDFORM
))
790 //! SvNumberformat Member bStandard rausreichen?
791 BOOL bStandard
= ( ( nKey
% SV_COUNTRY_LANGUAGE_OFFSET
) == 0 );
792 aRet
.setValue( &bStandard
, getBooleanCppuType() );
794 else if (aString
.EqualsAscii( PROPERTYNAME_USERDEF
))
796 BOOL bUserDef
= ( ( pFormat
->GetType() & NUMBERFORMAT_DEFINED
) != 0 );
797 aRet
.setValue( &bUserDef
, getBooleanCppuType() );
799 else if (aString
.EqualsAscii( PROPERTYNAME_DECIMALS
))
801 pFormat
->GetFormatSpecialInfo( bThousand
, bRed
, nDecimals
, nLeading
);
802 aRet
<<= (sal_Int16
)( nDecimals
);
804 else if (aString
.EqualsAscii( PROPERTYNAME_LEADING
))
806 pFormat
->GetFormatSpecialInfo( bThousand
, bRed
, nDecimals
, nLeading
);
807 aRet
<<= (sal_Int16
)( nLeading
);
809 else if (aString
.EqualsAscii( PROPERTYNAME_NEGRED
))
811 pFormat
->GetFormatSpecialInfo( bThousand
, bRed
, nDecimals
, nLeading
);
812 aRet
.setValue( &bRed
, getBooleanCppuType() );
814 else if (aString
.EqualsAscii( PROPERTYNAME_THOUS
))
816 pFormat
->GetFormatSpecialInfo( bThousand
, bRed
, nDecimals
, nLeading
);
817 aRet
.setValue( &bThousand
, getBooleanCppuType() );
819 else if (aString
.EqualsAscii( PROPERTYNAME_CURRSYM
))
821 String aSymbol
, aExt
;
822 pFormat
->GetNewCurrencySymbol( aSymbol
, aExt
);
823 aRet
<<= rtl::OUString( aSymbol
);
825 else if (aString
.EqualsAscii( PROPERTYNAME_CURREXT
))
827 String aSymbol
, aExt
;
828 pFormat
->GetNewCurrencySymbol( aSymbol
, aExt
);
829 aRet
<<= rtl::OUString( aExt
);
831 else if (aString
.EqualsAscii( PROPERTYNAME_CURRABB
))
833 String aSymbol
, aExt
;
835 pFormat
->GetNewCurrencySymbol( aSymbol
, aExt
);
836 const NfCurrencyEntry
* pCurr
= pFormatter
->GetCurrencyEntry( bBank
,
837 aSymbol
, aExt
, pFormat
->GetLanguage() );
839 aRet
<<= rtl::OUString( pCurr
->GetBankSymbol() );
841 aRet
<<= rtl::OUString();
844 throw beans::UnknownPropertyException();
847 throw uno::RuntimeException();
852 void SAL_CALL
SvNumberFormatObj::addPropertyChangeListener( const rtl::OUString
&,
853 const uno::Reference
<beans::XPropertyChangeListener
>&)
854 throw(beans::UnknownPropertyException
,
855 lang::WrappedTargetException
, uno::RuntimeException
)
857 DBG_ERROR("not implemented");
860 void SAL_CALL
SvNumberFormatObj::removePropertyChangeListener( const rtl::OUString
&,
861 const uno::Reference
<beans::XPropertyChangeListener
>&)
862 throw(beans::UnknownPropertyException
,
863 lang::WrappedTargetException
, uno::RuntimeException
)
865 DBG_ERROR("not implemented");
868 void SAL_CALL
SvNumberFormatObj::addVetoableChangeListener( const rtl::OUString
&,
869 const uno::Reference
<beans::XVetoableChangeListener
>&)
870 throw(beans::UnknownPropertyException
,
871 lang::WrappedTargetException
, uno::RuntimeException
)
873 DBG_ERROR("not implemented");
876 void SAL_CALL
SvNumberFormatObj::removeVetoableChangeListener( const rtl::OUString
&,
877 const uno::Reference
<beans::XVetoableChangeListener
>&)
878 throw(beans::UnknownPropertyException
,
879 lang::WrappedTargetException
, uno::RuntimeException
)
881 DBG_ERROR("not implemented");
886 uno::Sequence
<beans::PropertyValue
> SAL_CALL
SvNumberFormatObj::getPropertyValues()
887 throw(uno::RuntimeException
)
889 ::osl::MutexGuard
aGuard( m_aMutex
);
891 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
892 const SvNumberformat
* pFormat
= pFormatter
? pFormatter
->GetEntry(nKey
) : NULL
;
895 String aSymbol
, aExt
, aAbb
;
897 pFormat
->GetNewCurrencySymbol( aSymbol
, aExt
);
898 const NfCurrencyEntry
* pCurr
= pFormatter
->GetCurrencyEntry( bBank
,
899 aSymbol
, aExt
, pFormat
->GetLanguage() );
901 aAbb
= pCurr
->GetBankSymbol();
903 String aFmtStr
= pFormat
->GetFormatstring();
904 String aComment
= pFormat
->GetComment();
905 BOOL bStandard
= ( ( nKey
% SV_COUNTRY_LANGUAGE_OFFSET
) == 0 );
906 //! SvNumberformat Member bStandard rausreichen?
907 BOOL bUserDef
= ( ( pFormat
->GetType() & NUMBERFORMAT_DEFINED
) != 0 );
908 BOOL bThousand
, bRed
;
909 USHORT nDecimals
, nLeading
;
910 pFormat
->GetFormatSpecialInfo( bThousand
, bRed
, nDecimals
, nLeading
);
911 lang::Locale
aLocale( MsLangId::convertLanguageToLocale(
912 pFormat
->GetLanguage()));
914 uno::Sequence
<beans::PropertyValue
> aSeq(13);
915 beans::PropertyValue
* pArray
= aSeq
.getArray();
917 pArray
[0].Name
= rtl::OUString::createFromAscii( PROPERTYNAME_FMTSTR
);
918 pArray
[0].Value
<<= rtl::OUString( aFmtStr
);
919 pArray
[1].Name
= rtl::OUString::createFromAscii( PROPERTYNAME_LOCALE
);
920 pArray
[1].Value
<<= aLocale
;
921 pArray
[2].Name
= rtl::OUString::createFromAscii( PROPERTYNAME_TYPE
);
922 pArray
[2].Value
<<= (sal_Int16
)( pFormat
->GetType() );
923 pArray
[3].Name
= rtl::OUString::createFromAscii( PROPERTYNAME_COMMENT
);
924 pArray
[3].Value
<<= rtl::OUString( aComment
);
925 pArray
[4].Name
= rtl::OUString::createFromAscii( PROPERTYNAME_STDFORM
);
926 pArray
[4].Value
.setValue( &bStandard
, getBooleanCppuType() );
927 pArray
[5].Name
= rtl::OUString::createFromAscii( PROPERTYNAME_USERDEF
);
928 pArray
[5].Value
.setValue( &bUserDef
, getBooleanCppuType() );
929 pArray
[6].Name
= rtl::OUString::createFromAscii( PROPERTYNAME_DECIMALS
);
930 pArray
[6].Value
<<= (sal_Int16
)( nDecimals
);
931 pArray
[7].Name
= rtl::OUString::createFromAscii( PROPERTYNAME_LEADING
);
932 pArray
[7].Value
<<= (sal_Int16
)( nLeading
);
933 pArray
[8].Name
= rtl::OUString::createFromAscii( PROPERTYNAME_NEGRED
);
934 pArray
[8].Value
.setValue( &bRed
, getBooleanCppuType() );
935 pArray
[9].Name
= rtl::OUString::createFromAscii( PROPERTYNAME_THOUS
);
936 pArray
[9].Value
.setValue( &bThousand
, getBooleanCppuType() );
937 pArray
[10].Name
= rtl::OUString::createFromAscii( PROPERTYNAME_CURRSYM
);
938 pArray
[10].Value
<<= rtl::OUString( aSymbol
);
939 pArray
[11].Name
= rtl::OUString::createFromAscii( PROPERTYNAME_CURREXT
);
940 pArray
[11].Value
<<= rtl::OUString( aExt
);
941 pArray
[12].Name
= rtl::OUString::createFromAscii( PROPERTYNAME_CURRABB
);
942 pArray
[12].Value
<<= rtl::OUString( aAbb
);
947 throw uno::RuntimeException();
950 void SAL_CALL
SvNumberFormatObj::setPropertyValues( const uno::Sequence
<beans::PropertyValue
>& )
951 throw(beans::UnknownPropertyException
, beans::PropertyVetoException
,
952 lang::IllegalArgumentException
, lang::WrappedTargetException
,
953 uno::RuntimeException
)
955 throw beans::UnknownPropertyException(); // everything is read-only
960 rtl::OUString SAL_CALL
SvNumberFormatObj::getImplementationName()
961 throw(uno::RuntimeException
)
963 return rtl::OUString::createFromAscii("SvNumberFormatObj");
966 sal_Bool SAL_CALL
SvNumberFormatObj::supportsService( const rtl::OUString
& ServiceName
)
967 throw(uno::RuntimeException
)
969 return ( ServiceName
.compareToAscii(SERVICENAME_NUMBERFORMAT
) == 0 );
972 uno::Sequence
<rtl::OUString
> SAL_CALL
SvNumberFormatObj::getSupportedServiceNames()
973 throw(uno::RuntimeException
)
975 uno::Sequence
<rtl::OUString
> aRet(1);
976 rtl::OUString
* pArray
= aRet
.getArray();
977 pArray
[0] = rtl::OUString::createFromAscii(SERVICENAME_NUMBERFORMAT
);
981 //------------------------------------------------------------------------
983 SvNumberFormatSettingsObj::SvNumberFormatSettingsObj( SvNumberFormatsSupplierObj
& rParent
, const ::comphelper::SharedMutex
& _rMutex
)
984 :rSupplier( rParent
)
990 SvNumberFormatSettingsObj::~SvNumberFormatSettingsObj()
997 uno::Reference
<beans::XPropertySetInfo
> SAL_CALL
SvNumberFormatSettingsObj::getPropertySetInfo()
998 throw(uno::RuntimeException
)
1000 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
1001 static uno::Reference
<beans::XPropertySetInfo
> aRef
=
1002 new SfxItemPropertySetInfo( lcl_GetNumberSettingsPropertyMap() );
1006 void SAL_CALL
SvNumberFormatSettingsObj::setPropertyValue( const rtl::OUString
& aPropertyName
,
1007 const uno::Any
& aValue
)
1008 throw(beans::UnknownPropertyException
, beans::PropertyVetoException
,
1009 lang::IllegalArgumentException
, lang::WrappedTargetException
,
1010 uno::RuntimeException
)
1012 ::osl::MutexGuard
aGuard( m_aMutex
);
1014 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
1017 String aString
= aPropertyName
;
1018 if (aString
.EqualsAscii( PROPERTYNAME_NOZERO
))
1020 // operator >>= shouldn't be used for bool (?)
1021 if ( aValue
.getValueTypeClass() == uno::TypeClass_BOOLEAN
)
1022 pFormatter
->SetNoZero( *(sal_Bool
*)aValue
.getValue() );
1024 else if (aString
.EqualsAscii( PROPERTYNAME_NULLDATE
))
1027 if ( aValue
>>= aDate
)
1028 pFormatter
->ChangeNullDate( aDate
.Day
, aDate
.Month
, aDate
.Year
);
1030 else if (aString
.EqualsAscii( PROPERTYNAME_STDDEC
))
1032 sal_Int16 nInt16
= sal_Int16();
1033 if ( aValue
>>= nInt16
)
1034 pFormatter
->ChangeStandardPrec( nInt16
);
1036 else if (aString
.EqualsAscii( PROPERTYNAME_TWODIGIT
))
1038 sal_Int16 nInt16
= sal_Int16();
1039 if ( aValue
>>= nInt16
)
1040 pFormatter
->SetYear2000( nInt16
);
1043 throw beans::UnknownPropertyException();
1045 rSupplier
.SettingsChanged();
1048 throw uno::RuntimeException();
1051 uno::Any SAL_CALL
SvNumberFormatSettingsObj::getPropertyValue( const rtl::OUString
& aPropertyName
)
1052 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
,
1053 uno::RuntimeException
)
1055 ::osl::MutexGuard
aGuard( m_aMutex
);
1058 SvNumberFormatter
* pFormatter
= rSupplier
.GetNumberFormatter();
1061 String aString
= aPropertyName
;
1062 if (aString
.EqualsAscii( PROPERTYNAME_NOZERO
))
1064 BOOL bNoZero
= pFormatter
->GetNoZero();
1065 aRet
.setValue( &bNoZero
, getBooleanCppuType() );
1067 else if (aString
.EqualsAscii( PROPERTYNAME_NULLDATE
))
1069 Date
* pDate
= pFormatter
->GetNullDate();
1072 util::Date
aUnoDate( pDate
->GetDay(), pDate
->GetMonth(), pDate
->GetYear() );
1076 else if (aString
.EqualsAscii( PROPERTYNAME_STDDEC
))
1077 aRet
<<= (sal_Int16
)( pFormatter
->GetStandardPrec() );
1078 else if (aString
.EqualsAscii( PROPERTYNAME_TWODIGIT
))
1079 aRet
<<= (sal_Int16
)( pFormatter
->GetYear2000() );
1081 throw beans::UnknownPropertyException();
1084 throw uno::RuntimeException();
1089 void SAL_CALL
SvNumberFormatSettingsObj::addPropertyChangeListener( const rtl::OUString
&,
1090 const uno::Reference
<beans::XPropertyChangeListener
>&)
1091 throw(beans::UnknownPropertyException
,
1092 lang::WrappedTargetException
, uno::RuntimeException
)
1094 DBG_ERROR("not implemented");
1097 void SAL_CALL
SvNumberFormatSettingsObj::removePropertyChangeListener( const rtl::OUString
&,
1098 const uno::Reference
<beans::XPropertyChangeListener
>&)
1099 throw(beans::UnknownPropertyException
,
1100 lang::WrappedTargetException
, uno::RuntimeException
)
1102 DBG_ERROR("not implemented");
1105 void SAL_CALL
SvNumberFormatSettingsObj::addVetoableChangeListener( const rtl::OUString
&,
1106 const uno::Reference
<beans::XVetoableChangeListener
>&)
1107 throw(beans::UnknownPropertyException
,
1108 lang::WrappedTargetException
, uno::RuntimeException
)
1110 DBG_ERROR("not implemented");
1113 void SAL_CALL
SvNumberFormatSettingsObj::removeVetoableChangeListener( const rtl::OUString
&,
1114 const uno::Reference
<beans::XVetoableChangeListener
>&)
1115 throw(beans::UnknownPropertyException
,
1116 lang::WrappedTargetException
, uno::RuntimeException
)
1118 DBG_ERROR("not implemented");
1123 rtl::OUString SAL_CALL
SvNumberFormatSettingsObj::getImplementationName()
1124 throw(uno::RuntimeException
)
1126 return rtl::OUString::createFromAscii("SvNumberFormatSettingsObj");
1129 sal_Bool SAL_CALL
SvNumberFormatSettingsObj::supportsService( const rtl::OUString
& ServiceName
)
1130 throw(uno::RuntimeException
)
1132 return ( ServiceName
.compareToAscii(SERVICENAME_NUMBERSETTINGS
) == 0 );
1135 uno::Sequence
<rtl::OUString
> SAL_CALL
SvNumberFormatSettingsObj::getSupportedServiceNames()
1136 throw(uno::RuntimeException
)
1138 uno::Sequence
<rtl::OUString
> aRet(1);
1139 rtl::OUString
* pArray
= aRet
.getArray();
1140 pArray
[0] = rtl::OUString::createFromAscii(SERVICENAME_NUMBERSETTINGS
);