xref: /aoo4110/main/svl/source/numbers/numfmuno.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svl.hxx"
26 #ifndef GCC
27 #endif
28 
29 #include <tools/color.hxx>
30 #include <tools/debug.hxx>
31 #include <i18npool/mslangid.hxx>
32 #include <vos/mutex.hxx>
33 #include <rtl/ustring.hxx>
34 
35 #include <com/sun/star/util/Date.hpp>
36 #include <com/sun/star/beans/PropertyAttribute.hpp>
37 
38 #include "numfmuno.hxx"
39 #include <svl/numuno.hxx>
40 #include <svl/zforlist.hxx>
41 #include <svl/zformat.hxx>
42 #include <svl/itemprop.hxx>
43 
44 using namespace com::sun::star;
45 
46 //------------------------------------------------------------------------
47 
48 #define SERVICENAME_NUMBERFORMATTER	"com.sun.star.util.NumberFormatter"
49 #define SERVICENAME_NUMBERSETTINGS	"com.sun.star.util.NumberFormatSettings"
50 #define SERVICENAME_NUMBERFORMATS	"com.sun.star.util.NumberFormats"
51 #define SERVICENAME_NUMBERFORMAT	"com.sun.star.util.NumberFormatProperties"
52 
53 //------------------------------------------------------------------------
54 
55 #define PROPERTYNAME_FMTSTR		"FormatString"
56 #define PROPERTYNAME_LOCALE		"Locale"
57 #define PROPERTYNAME_TYPE		"Type"
58 #define PROPERTYNAME_COMMENT 	"Comment"
59 #define PROPERTYNAME_CURREXT 	"CurrencyExtension"
60 #define PROPERTYNAME_CURRSYM 	"CurrencySymbol"
61 #define PROPERTYNAME_CURRABB 	"CurrencyAbbreviation"
62 #define PROPERTYNAME_DECIMALS	"Decimals"
63 #define PROPERTYNAME_LEADING	"LeadingZeros"
64 #define PROPERTYNAME_NEGRED		"NegativeRed"
65 #define PROPERTYNAME_STDFORM	"StandardFormat"
66 #define PROPERTYNAME_THOUS		"ThousandsSeparator"
67 #define PROPERTYNAME_USERDEF	"UserDefined"
68 
69 #define PROPERTYNAME_NOZERO		"NoZero"
70 #define PROPERTYNAME_NULLDATE	"NullDate"
71 #define PROPERTYNAME_STDDEC		"StandardDecimals"
72 #define PROPERTYNAME_TWODIGIT	"TwoDigitDateStart"
73 
74 //------------------------------------------------------------------------
75 
76 //	alles ohne Which-ID, Map nur fuer PropertySetInfo
77 
lcl_GetNumberFormatPropertyMap()78 const SfxItemPropertyMapEntry* lcl_GetNumberFormatPropertyMap()
79 {
80     static SfxItemPropertyMapEntry aNumberFormatPropertyMap_Impl[] =
81 	{
82 		{MAP_CHAR_LEN(PROPERTYNAME_FMTSTR),	  0, &getCppuType((rtl::OUString*)0),beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY, 0},
83 		{MAP_CHAR_LEN(PROPERTYNAME_LOCALE),	  0, &getCppuType((lang::Locale*)0),beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY, 0},
84 		{MAP_CHAR_LEN(PROPERTYNAME_TYPE),	  0, &getCppuType((sal_Int16*)0),	beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY, 0},
85 		{MAP_CHAR_LEN(PROPERTYNAME_COMMENT),  0, &getCppuType((rtl::OUString*)0),beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY, 0},
86 		{MAP_CHAR_LEN(PROPERTYNAME_CURREXT),  0, &getCppuType((rtl::OUString*)0),beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY, 0},
87 		{MAP_CHAR_LEN(PROPERTYNAME_CURRSYM),  0, &getCppuType((rtl::OUString*)0),beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY, 0},
88 		{MAP_CHAR_LEN(PROPERTYNAME_DECIMALS), 0, &getCppuType((sal_Int16*)0),	beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY, 0},
89 		{MAP_CHAR_LEN(PROPERTYNAME_LEADING),  0, &getCppuType((sal_Int16*)0),	beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY, 0},
90 		{MAP_CHAR_LEN(PROPERTYNAME_NEGRED),	  0, &getBooleanCppuType(),			beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY, 0},
91 		{MAP_CHAR_LEN(PROPERTYNAME_STDFORM),  0, &getBooleanCppuType(),			beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY, 0},
92 		{MAP_CHAR_LEN(PROPERTYNAME_THOUS),	  0, &getBooleanCppuType(),			beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY, 0},
93 		{MAP_CHAR_LEN(PROPERTYNAME_USERDEF),  0, &getBooleanCppuType(),			beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY, 0},
94 		{MAP_CHAR_LEN(PROPERTYNAME_CURRABB),  0, &getCppuType((rtl::OUString*)0),beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY, 0},
95 		{0,0,0,0,0,0}
96 	};
97 	return aNumberFormatPropertyMap_Impl;
98 }
99 
lcl_GetNumberSettingsPropertyMap()100 const SfxItemPropertyMapEntry* lcl_GetNumberSettingsPropertyMap()
101 {
102     static SfxItemPropertyMapEntry aNumberSettingsPropertyMap_Impl[] =
103 	{
104 		{MAP_CHAR_LEN(PROPERTYNAME_NOZERO),	  0, &getBooleanCppuType(),			beans::PropertyAttribute::BOUND, 0},
105 		{MAP_CHAR_LEN(PROPERTYNAME_NULLDATE), 0, &getCppuType((util::Date*)0),	beans::PropertyAttribute::BOUND, 0},
106 		{MAP_CHAR_LEN(PROPERTYNAME_STDDEC),	  0, &getCppuType((sal_Int16*)0),	beans::PropertyAttribute::BOUND, 0},
107 		{MAP_CHAR_LEN(PROPERTYNAME_TWODIGIT), 0, &getCppuType((sal_Int16*)0),	beans::PropertyAttribute::BOUND, 0},
108 		{0,0,0,0,0,0}
109 	};
110 	return aNumberSettingsPropertyMap_Impl;
111 }
112 
113 //----------------------------------------------------------------------------------------
114 
lcl_GetLanguage(const lang::Locale & rLocale)115 LanguageType lcl_GetLanguage( const lang::Locale& rLocale )
116 {
117 	//	empty language -> LANGUAGE_SYSTEM
118 	if ( rLocale.Language.getLength() == 0 )
119 		return LANGUAGE_SYSTEM;
120 
121 	LanguageType eRet = MsLangId::convertLocaleToLanguage( rLocale );
122 	if ( eRet == LANGUAGE_NONE )
123 		eRet = LANGUAGE_SYSTEM;			//! or throw an exception?
124 
125 	return eRet;
126 }
127 
128 //----------------------------------------------------------------------------------------
129 
SvNumberFormatterServiceObj()130 SvNumberFormatterServiceObj::SvNumberFormatterServiceObj()
131     :m_aMutex()
132 {
133 }
134 
~SvNumberFormatterServiceObj()135 SvNumberFormatterServiceObj::~SvNumberFormatterServiceObj()
136 {
137 }
138 
SvNumberFormatterServiceObj_CreateInstance(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> &)139 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 >& )
140 {
141 	return ::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface >( ( ::cppu::OWeakObject* ) new SvNumberFormatterServiceObj );
142 }
143 
144 // XNumberFormatter
145 
attachNumberFormatsSupplier(const uno::Reference<util::XNumberFormatsSupplier> & _xSupplier)146 void SAL_CALL SvNumberFormatterServiceObj::attachNumberFormatsSupplier(
147 							const uno::Reference<util::XNumberFormatsSupplier>& _xSupplier )
148 									throw(uno::RuntimeException)
149 {
150     ::rtl::Reference< SvNumberFormatsSupplierObj > xAutoReleaseOld;
151 
152     // SYNCHRONIZED ->
153     {
154         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
155 
156 	    SvNumberFormatsSupplierObj*	pNew = SvNumberFormatsSupplierObj::getImplementation( _xSupplier );
157 	    if (!pNew)
158 		    throw uno::RuntimeException();		// wrong object
159 
160         xAutoReleaseOld = xSupplier;
161 
162         xSupplier = pNew;
163         m_aMutex = xSupplier->getSharedMutex();
164     }
165     // <- SYNCHRONIZED
166 }
167 
168 uno::Reference<util::XNumberFormatsSupplier> SAL_CALL
getNumberFormatsSupplier()169 							SvNumberFormatterServiceObj::getNumberFormatsSupplier()
170 									throw(uno::RuntimeException)
171 {
172     ::osl::MutexGuard aGuard( m_aMutex );
173 	return xSupplier.get();
174 }
175 
detectNumberFormat(sal_Int32 nKey,const rtl::OUString & aString)176 sal_Int32 SAL_CALL SvNumberFormatterServiceObj::detectNumberFormat(
177 									sal_Int32 nKey, const rtl::OUString& aString )
178 							throw(util::NotNumericException, uno::RuntimeException)
179 {
180     ::osl::MutexGuard aGuard( m_aMutex );
181 
182 	sal_Int32 nRet = 0;
183     SvNumberFormatter* pFormatter = xSupplier.is() ? xSupplier->GetNumberFormatter() : NULL;
184 	if (pFormatter)
185 	{
186 		String aTemp = aString;
187 		sal_uInt32 nUKey = nKey;
188 		double fValue = 0.0;
189 		if ( pFormatter->IsNumberFormat(aTemp, nUKey, fValue) )
190 			nRet = nUKey;
191 		else
192 			throw util::NotNumericException();
193 	}
194 	else
195 		throw uno::RuntimeException();
196 
197 	return nRet;
198 }
199 
convertStringToNumber(sal_Int32 nKey,const rtl::OUString & aString)200 double SAL_CALL SvNumberFormatterServiceObj::convertStringToNumber(
201 									sal_Int32 nKey, const rtl::OUString& aString )
202 							throw(util::NotNumericException, uno::RuntimeException)
203 {
204     ::osl::MutexGuard aGuard( m_aMutex );
205 
206 	double fRet = 0.0;
207     SvNumberFormatter* pFormatter = xSupplier.is() ? xSupplier->GetNumberFormatter() : NULL;
208 	if (pFormatter)
209 	{
210 		String aTemp = aString;
211 		sal_uInt32 nUKey = nKey;
212 		double fValue = 0.0;
213 		if ( pFormatter->IsNumberFormat(aTemp, nUKey, fValue) )
214 			fRet = fValue;
215 		else
216 			throw util::NotNumericException();
217 	}
218 	else
219 		throw uno::RuntimeException();
220 
221 	return fRet;
222 }
223 
convertNumberToString(sal_Int32 nKey,double fValue)224 rtl::OUString SAL_CALL SvNumberFormatterServiceObj::convertNumberToString(
225 									sal_Int32 nKey, double fValue ) throw(uno::RuntimeException)
226 {
227     ::osl::MutexGuard aGuard( m_aMutex );
228 
229 	String aRet;
230 	SvNumberFormatter* pFormatter = xSupplier.is() ? xSupplier->GetNumberFormatter() : NULL;
231 	if (pFormatter)
232 	{
233 		Color* pColor = NULL;
234 		pFormatter->GetOutputString(fValue, nKey, aRet, &pColor);
235 	}
236 	else
237 		throw uno::RuntimeException();
238 
239 	return aRet;
240 }
241 
queryColorForNumber(sal_Int32 nKey,double fValue,util::Color aDefaultColor)242 util::Color SAL_CALL SvNumberFormatterServiceObj::queryColorForNumber( sal_Int32 nKey,
243 									double fValue, util::Color aDefaultColor )
244 							throw(uno::RuntimeException)
245 {
246     ::osl::MutexGuard aGuard( m_aMutex );
247 
248 	util::Color nRet = aDefaultColor;		// color = sal_Int32
249     SvNumberFormatter* pFormatter = xSupplier.is() ? xSupplier->GetNumberFormatter() : NULL;
250 	if (pFormatter)
251 	{
252 		String aStr;
253 		Color* pColor = NULL;
254 		pFormatter->GetOutputString(fValue, nKey, aStr, &pColor);
255 		if (pColor)
256 			nRet = pColor->GetColor();
257 		// sonst Default behalten
258 	}
259 	else
260 		throw uno::RuntimeException();
261 
262 	return nRet;
263 }
264 
formatString(sal_Int32 nKey,const rtl::OUString & aString)265 rtl::OUString SAL_CALL SvNumberFormatterServiceObj::formatString( sal_Int32 nKey,
266 									const rtl::OUString& aString ) throw(uno::RuntimeException)
267 {
268     ::osl::MutexGuard aGuard( m_aMutex );
269 
270 	String aRet;
271     SvNumberFormatter* pFormatter = xSupplier.is() ? xSupplier->GetNumberFormatter() : NULL;
272 	if (pFormatter)
273 	{
274 		String aTemp = aString;
275 		Color* pColor = NULL;
276 		pFormatter->GetOutputString(aTemp, nKey, aRet, &pColor);
277 	}
278 	else
279 		throw uno::RuntimeException();
280 
281 	return aRet;
282 }
283 
queryColorForString(sal_Int32 nKey,const rtl::OUString & aString,util::Color aDefaultColor)284 util::Color SAL_CALL SvNumberFormatterServiceObj::queryColorForString( sal_Int32 nKey,
285 									const rtl::OUString& aString,util::Color aDefaultColor )
286 							throw(uno::RuntimeException)
287 {
288     ::osl::MutexGuard aGuard( m_aMutex );
289 
290 	util::Color nRet = aDefaultColor;		// color = sal_Int32
291     SvNumberFormatter* pFormatter = xSupplier.is() ? xSupplier->GetNumberFormatter() : NULL;
292 	if (pFormatter)
293 	{
294 		String aTemp = aString;
295 		String aStr;
296 		Color* pColor = NULL;
297 		pFormatter->GetOutputString(aTemp, nKey, aStr, &pColor);
298 		if (pColor)
299 			nRet = pColor->GetColor();
300 		// sonst Default behalten
301 	}
302 	else
303 		throw uno::RuntimeException();
304 
305 	return nRet;
306 }
307 
getInputString(sal_Int32 nKey,double fValue)308 rtl::OUString SAL_CALL SvNumberFormatterServiceObj::getInputString( sal_Int32 nKey, double fValue )
309 							throw(uno::RuntimeException)
310 {
311     ::osl::MutexGuard aGuard( m_aMutex );
312 
313 	String aRet;
314     SvNumberFormatter* pFormatter = xSupplier.is() ? xSupplier->GetNumberFormatter() : NULL;
315 	if (pFormatter)
316 		pFormatter->GetInputLineString(fValue, nKey, aRet);
317 	else
318 		throw uno::RuntimeException();
319 
320 	return aRet;
321 }
322 
323 // XNumberFormatPreviewer
324 
convertNumberToPreviewString(const rtl::OUString & aFormat,double fValue,const lang::Locale & nLocale,sal_Bool bAllowEnglish)325 rtl::OUString SAL_CALL SvNumberFormatterServiceObj::convertNumberToPreviewString(
326 									const rtl::OUString& aFormat, double fValue,
327 									const lang::Locale& nLocale, sal_Bool bAllowEnglish )
328 							throw(util::MalformedNumberFormatException, uno::RuntimeException)
329 {
330     ::osl::MutexGuard aGuard( m_aMutex );
331 
332 	String aRet;
333     SvNumberFormatter* pFormatter = xSupplier.is() ? xSupplier->GetNumberFormatter() : NULL;
334 	if (pFormatter)
335 	{
336 		String aOutString;
337 		String aFormString = aFormat;
338 		LanguageType eLang = lcl_GetLanguage( nLocale );
339 		Color* pColor = NULL;
340 
341 		sal_Bool bOk;
342 		if ( bAllowEnglish )
343 			bOk = pFormatter->GetPreviewStringGuess(
344 								aFormString, fValue, aOutString, &pColor, eLang );
345 		else
346 			bOk = pFormatter->GetPreviewString(
347 								aFormString, fValue, aOutString, &pColor, eLang );
348 
349 		if (bOk)
350 			aRet = aOutString;
351 		else
352 			throw util::MalformedNumberFormatException();
353 	}
354 	else
355 		throw uno::RuntimeException();
356 
357 	return aRet;
358 }
359 
queryPreviewColorForNumber(const rtl::OUString & aFormat,double fValue,const lang::Locale & nLocale,sal_Bool bAllowEnglish,util::Color aDefaultColor)360 util::Color SAL_CALL SvNumberFormatterServiceObj::queryPreviewColorForNumber(
361 									const rtl::OUString& aFormat, double fValue,
362 									const lang::Locale& nLocale, sal_Bool bAllowEnglish,
363 									util::Color aDefaultColor )
364 							throw(util::MalformedNumberFormatException, uno::RuntimeException)
365 {
366     ::osl::MutexGuard aGuard( m_aMutex );
367 
368 	util::Color nRet = aDefaultColor;		// color = sal_Int32
369     SvNumberFormatter* pFormatter = xSupplier.is() ? xSupplier->GetNumberFormatter() : NULL;
370 	if (pFormatter)
371 	{
372 		String aOutString;
373 		String aFormString = aFormat;
374 		LanguageType eLang = lcl_GetLanguage( nLocale );
375 		Color* pColor = NULL;
376 
377 		sal_Bool bOk;
378 		if ( bAllowEnglish )
379 			bOk = pFormatter->GetPreviewStringGuess(
380 								aFormString, fValue, aOutString, &pColor, eLang );
381 		else
382 			bOk = pFormatter->GetPreviewString(
383 								aFormString, fValue, aOutString, &pColor, eLang );
384 
385 		if (bOk)
386 		{
387 			if (pColor)
388 				nRet = pColor->GetColor();
389 			// sonst Default behalten
390 		}
391 		else
392 			throw util::MalformedNumberFormatException();
393 	}
394 	else
395 		throw uno::RuntimeException();
396 
397 	return nRet;
398 }
399 
400 // XServiceInfo
401 
getImplementationName()402 rtl::OUString SAL_CALL SvNumberFormatterServiceObj::getImplementationName()
403 							throw(uno::RuntimeException)
404 {
405 	return rtl::OUString::createFromAscii("com.sun.star.uno.util.numbers.SvNumberFormatterServiceObject");
406 }
407 
supportsService(const rtl::OUString & ServiceName)408 sal_Bool SAL_CALL SvNumberFormatterServiceObj::supportsService( const rtl::OUString& ServiceName )
409 							throw(uno::RuntimeException)
410 {
411 	return ( ServiceName.compareToAscii(SERVICENAME_NUMBERFORMATTER) == 0 );
412 }
413 
getSupportedServiceNames()414 uno::Sequence<rtl::OUString> SAL_CALL SvNumberFormatterServiceObj::getSupportedServiceNames()
415 							throw(uno::RuntimeException)
416 {
417 	uno::Sequence<rtl::OUString> aRet(1);
418 	rtl::OUString* pArray = aRet.getArray();
419 	pArray[0] = rtl::OUString::createFromAscii(SERVICENAME_NUMBERFORMATTER);
420 	return aRet;
421 }
422 
423 //------------------------------------------------------------------------
424 
SvNumberFormatsObj(SvNumberFormatsSupplierObj & _rParent,::comphelper::SharedMutex & _rMutex)425 SvNumberFormatsObj::SvNumberFormatsObj( SvNumberFormatsSupplierObj& _rParent, ::comphelper::SharedMutex& _rMutex )
426     :rSupplier( _rParent )
427     ,m_aMutex( _rMutex )
428 {
429 	rSupplier.acquire();
430 }
431 
~SvNumberFormatsObj()432 SvNumberFormatsObj::~SvNumberFormatsObj()
433 {
434 	rSupplier.release();
435 }
436 
437 // XNumberFormats
438 
getByKey(sal_Int32 nKey)439 uno::Reference<beans::XPropertySet> SAL_CALL SvNumberFormatsObj::getByKey( sal_Int32 nKey )
440 							throw(uno::RuntimeException)
441 {
442     ::osl::MutexGuard aGuard( m_aMutex );
443 
444 	SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter();
445 	const SvNumberformat* pFormat = pFormatter ? pFormatter->GetEntry(nKey) : NULL;
446 	if (pFormat)
447 		return new SvNumberFormatObj( rSupplier, nKey, m_aMutex );
448 	else
449 		throw uno::RuntimeException();
450 }
451 
queryKeys(sal_Int16 nType,const lang::Locale & nLocale,sal_Bool bCreate)452 uno::Sequence<sal_Int32> SAL_CALL SvNumberFormatsObj::queryKeys( sal_Int16 nType,
453 									const lang::Locale& nLocale, sal_Bool bCreate )
454 							throw(uno::RuntimeException)
455 {
456     ::osl::MutexGuard aGuard( m_aMutex );
457 
458 	SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter();
459 	if ( pFormatter )
460 	{
461 		sal_uInt32 nIndex = 0;
462 		LanguageType eLang = lcl_GetLanguage( nLocale );
463 		SvNumberFormatTable& rTable = bCreate ?
464 										pFormatter->ChangeCL( nType, nIndex, eLang ) :
465 										pFormatter->GetEntryTable( nType, nIndex, eLang );
466 		sal_uInt32 nCount = rTable.Count();
467 		uno::Sequence<sal_Int32> aSeq(nCount);
468 		sal_Int32* pAry = aSeq.getArray();
469 		for (sal_uInt32 i=0; i<nCount; i++)
470 			pAry[i] = rTable.GetObjectKey( i );
471 
472 		return aSeq;
473 	}
474 	else
475 		throw uno::RuntimeException();
476 }
477 
queryKey(const rtl::OUString & aFormat,const lang::Locale & nLocale,sal_Bool bScan)478 sal_Int32 SAL_CALL SvNumberFormatsObj::queryKey( const rtl::OUString& aFormat,
479 									const lang::Locale& nLocale, sal_Bool bScan )
480 							throw(uno::RuntimeException)
481 {
482     ::osl::MutexGuard aGuard( m_aMutex );
483 
484 	sal_Int32 nRet = 0;
485 	SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter();
486 	if (pFormatter)
487 	{
488 		String aFormStr = aFormat;
489 		LanguageType eLang = lcl_GetLanguage( nLocale );
490 		if (bScan)
491 		{
492 			//!	irgendwas muss hier noch passieren...
493 		}
494 		nRet = pFormatter->GetEntryKey( aFormat, eLang );
495 	}
496 	else
497 		throw uno::RuntimeException();
498 
499 	return nRet;
500 }
501 
addNew(const rtl::OUString & aFormat,const lang::Locale & nLocale)502 sal_Int32 SAL_CALL SvNumberFormatsObj::addNew( const rtl::OUString& aFormat,
503 									const lang::Locale& nLocale )
504 							throw(util::MalformedNumberFormatException, uno::RuntimeException)
505 {
506     ::osl::MutexGuard aGuard( m_aMutex );
507 
508 	sal_Int32 nRet = 0;
509 	SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter();
510 	if (pFormatter)
511 	{
512 		String aFormStr = aFormat;
513 		LanguageType eLang = lcl_GetLanguage( nLocale );
514 		sal_uInt32 nKey = 0;
515 		xub_StrLen nCheckPos = 0;
516 		short nType = 0;
517 		sal_Bool bOk = pFormatter->PutEntry( aFormStr, nCheckPos, nType, nKey, eLang );
518 		if (bOk)
519 			nRet = nKey;
520 		else if (nCheckPos)
521 		{
522 			throw util::MalformedNumberFormatException();		// ungueltiges Format
523 		}
524 		else
525 			throw uno::RuntimeException();						// anderer Fehler (z.B. schon vorhanden)
526 	}
527 	else
528 		throw uno::RuntimeException();
529 
530 	return nRet;
531 }
532 
addNewConverted(const rtl::OUString & aFormat,const lang::Locale & nLocale,const lang::Locale & nNewLocale)533 sal_Int32 SAL_CALL SvNumberFormatsObj::addNewConverted( const rtl::OUString& aFormat,
534 									const lang::Locale& nLocale, const lang::Locale& nNewLocale )
535 							throw(util::MalformedNumberFormatException, uno::RuntimeException)
536 {
537     ::osl::MutexGuard aGuard( m_aMutex );
538 
539 	sal_Int32 nRet = 0;
540 	SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter();
541 	if (pFormatter)
542 	{
543 		String aFormStr = aFormat;
544 		LanguageType eLang = lcl_GetLanguage( nLocale );
545 		LanguageType eNewLang = lcl_GetLanguage( nNewLocale );
546 		sal_uInt32 nKey = 0;
547 		xub_StrLen nCheckPos = 0;
548 		short nType = 0;
549 		sal_Bool bOk = pFormatter->PutandConvertEntry( aFormStr, nCheckPos, nType, nKey, eLang, eNewLang );
550         if (bOk || nKey > 0)
551 			nRet = nKey;
552 		else if (nCheckPos)
553 		{
554 			throw util::MalformedNumberFormatException();		// ungueltiges Format
555 		}
556 		else
557 			throw uno::RuntimeException();						// anderer Fehler (z.B. schon vorhanden)
558 	}
559 	else
560 		throw uno::RuntimeException();
561 
562 	return nRet;
563 }
564 
removeByKey(sal_Int32 nKey)565 void SAL_CALL SvNumberFormatsObj::removeByKey( sal_Int32 nKey ) throw(uno::RuntimeException)
566 {
567     ::osl::MutexGuard aGuard( m_aMutex );
568 	SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter();
569 
570 	if (pFormatter)
571 	{
572 		pFormatter->DeleteEntry(nKey);
573 		rSupplier.NumberFormatDeleted(nKey);		// Benachrichtigung fuers Dokument
574 	}
575 }
576 
generateFormat(sal_Int32 nBaseKey,const lang::Locale & nLocale,sal_Bool bThousands,sal_Bool bRed,sal_Int16 nDecimals,sal_Int16 nLeading)577 rtl::OUString SAL_CALL SvNumberFormatsObj::generateFormat( sal_Int32 nBaseKey,
578 									const lang::Locale& nLocale, sal_Bool bThousands,
579 									sal_Bool bRed, sal_Int16 nDecimals, sal_Int16 nLeading )
580 							throw(uno::RuntimeException)
581 {
582     ::osl::MutexGuard aGuard( m_aMutex );
583 
584 	String aRet;
585 	SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter();
586 	if (pFormatter)
587 	{
588 		LanguageType eLang = lcl_GetLanguage( nLocale );
589 		pFormatter->GenerateFormat( aRet, nBaseKey, eLang, bThousands, bRed, nDecimals, nLeading );
590 	}
591 	else
592 		throw uno::RuntimeException();
593 
594 	return aRet;
595 }
596 
597 // XNumberFormatTypes
598 
getStandardIndex(const lang::Locale & nLocale)599 sal_Int32 SAL_CALL SvNumberFormatsObj::getStandardIndex( const lang::Locale& nLocale )
600 							throw(uno::RuntimeException)
601 {
602     ::osl::MutexGuard aGuard( m_aMutex );
603 
604 	sal_Int32 nRet = 0;
605 	SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter();
606 	if (pFormatter)
607 	{
608 		LanguageType eLang = lcl_GetLanguage( nLocale );
609 		nRet = pFormatter->GetStandardIndex(eLang);
610 	}
611 	else
612 		throw uno::RuntimeException();
613 
614 	return nRet;
615 }
616 
getStandardFormat(sal_Int16 nType,const lang::Locale & nLocale)617 sal_Int32 SAL_CALL SvNumberFormatsObj::getStandardFormat( sal_Int16 nType, const lang::Locale& nLocale )
618 							throw(uno::RuntimeException)
619 {
620     ::osl::MutexGuard aGuard( m_aMutex );
621 
622 	sal_Int32 nRet = 0;
623 	SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter();
624 	if (pFormatter)
625 	{
626 		LanguageType eLang = lcl_GetLanguage( nLocale );
627 		//	mask out "defined" bit, so type from an existing number format
628 		//	can directly be used for getStandardFormat
629 		nType &= ~NUMBERFORMAT_DEFINED;
630 		nRet = pFormatter->GetStandardFormat(nType, eLang);
631 	}
632 	else
633 		throw uno::RuntimeException();
634 
635 	return nRet;
636 }
637 
getFormatIndex(sal_Int16 nIndex,const lang::Locale & nLocale)638 sal_Int32 SAL_CALL SvNumberFormatsObj::getFormatIndex( sal_Int16 nIndex, const lang::Locale& nLocale )
639 							throw(uno::RuntimeException)
640 {
641     ::osl::MutexGuard aGuard( m_aMutex );
642 
643 	sal_Int32 nRet = 0;
644 	SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter();
645 	if (pFormatter)
646 	{
647 		LanguageType eLang = lcl_GetLanguage( nLocale );
648 		nRet = pFormatter->GetFormatIndex( (NfIndexTableOffset)nIndex, eLang );
649 	}
650 	else
651 		throw uno::RuntimeException();
652 
653 	return nRet;
654 }
655 
isTypeCompatible(sal_Int16 nOldType,sal_Int16 nNewType)656 sal_Bool SAL_CALL SvNumberFormatsObj::isTypeCompatible( sal_Int16 nOldType, sal_Int16 nNewType )
657 							throw(uno::RuntimeException)
658 {
659     ::osl::MutexGuard aGuard( m_aMutex );
660 
661 	sal_Bool bRet = sal_False;
662 	SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter();
663 	if (pFormatter)
664 		bRet = pFormatter->IsCompatible( nOldType, nNewType );
665 	else
666 		throw uno::RuntimeException();
667 
668 	return bRet;
669 }
670 
getFormatForLocale(sal_Int32 nKey,const lang::Locale & nLocale)671 sal_Int32 SAL_CALL SvNumberFormatsObj::getFormatForLocale( sal_Int32 nKey, const lang::Locale& nLocale )
672 							throw(uno::RuntimeException)
673 {
674     ::osl::MutexGuard aGuard( m_aMutex );
675 
676 	sal_Int32 nRet = 0;
677 	SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter();
678 	if (pFormatter)
679 	{
680 		LanguageType eLang = lcl_GetLanguage( nLocale );
681 		nRet = pFormatter->GetFormatForLanguageIfBuiltIn(nKey, eLang);
682 	}
683 	else
684 		throw uno::RuntimeException();
685 
686 	return nRet;
687 }
688 
689 // XServiceInfo
690 
getImplementationName()691 rtl::OUString SAL_CALL SvNumberFormatsObj::getImplementationName()
692 							throw(uno::RuntimeException)
693 {
694 	return rtl::OUString::createFromAscii("SvNumberFormatsObj");
695 }
696 
supportsService(const rtl::OUString & ServiceName)697 sal_Bool SAL_CALL SvNumberFormatsObj::supportsService( const rtl::OUString& ServiceName )
698 							throw(uno::RuntimeException)
699 {
700 	return ( ServiceName.compareToAscii(SERVICENAME_NUMBERFORMATS) == 0 );
701 }
702 
getSupportedServiceNames()703 uno::Sequence<rtl::OUString> SAL_CALL SvNumberFormatsObj::getSupportedServiceNames()
704 							throw(uno::RuntimeException)
705 {
706 	uno::Sequence<rtl::OUString> aRet(1);
707 	rtl::OUString* pArray = aRet.getArray();
708 	pArray[0] = rtl::OUString::createFromAscii(SERVICENAME_NUMBERFORMATS);
709 	return aRet;
710 }
711 
712 //------------------------------------------------------------------------
713 
SvNumberFormatObj(SvNumberFormatsSupplierObj & rParent,sal_uLong nK,const::comphelper::SharedMutex & _rMutex)714 SvNumberFormatObj::SvNumberFormatObj( SvNumberFormatsSupplierObj& rParent, sal_uLong nK, const ::comphelper::SharedMutex& _rMutex )
715     :rSupplier( rParent )
716 	,nKey( nK )
717     ,m_aMutex( _rMutex )
718 {
719 	rSupplier.acquire();
720 }
721 
~SvNumberFormatObj()722 SvNumberFormatObj::~SvNumberFormatObj()
723 {
724 	rSupplier.release();
725 }
726 
727 // XPropertySet
728 
getPropertySetInfo()729 uno::Reference<beans::XPropertySetInfo> SAL_CALL SvNumberFormatObj::getPropertySetInfo()
730 							throw(uno::RuntimeException)
731 {
732     ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
733 	static uno::Reference<beans::XPropertySetInfo> aRef =
734 		new SfxItemPropertySetInfo( lcl_GetNumberFormatPropertyMap() );
735 	return aRef;
736 }
737 
setPropertyValue(const rtl::OUString &,const uno::Any &)738 void SAL_CALL SvNumberFormatObj::setPropertyValue( const rtl::OUString&,
739 												   const uno::Any& )
740 				throw(beans::UnknownPropertyException, beans::PropertyVetoException,
741 						lang::IllegalArgumentException, lang::WrappedTargetException,
742 						uno::RuntimeException)
743 {
744 	throw beans::UnknownPropertyException();	//	everything is read-only
745 }
746 
getPropertyValue(const rtl::OUString & aPropertyName)747 uno::Any SAL_CALL SvNumberFormatObj::getPropertyValue( const rtl::OUString& aPropertyName )
748 				throw(beans::UnknownPropertyException, lang::WrappedTargetException,
749 						uno::RuntimeException)
750 {
751     ::osl::MutexGuard aGuard( m_aMutex );
752 
753 	uno::Any aRet;
754 	SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter();
755 	const SvNumberformat* pFormat = pFormatter ? pFormatter->GetEntry(nKey) : NULL;
756 	if (pFormat)
757 	{
758 		sal_Bool bThousand, bRed;
759 		sal_uInt16 nDecimals, nLeading;
760 
761 		String aString = aPropertyName;
762 		if (aString.EqualsAscii( PROPERTYNAME_FMTSTR ))
763 		{
764 			aRet <<= rtl::OUString( pFormat->GetFormatstring() );
765 		}
766 		else if (aString.EqualsAscii( PROPERTYNAME_LOCALE ))
767 		{
768 			lang::Locale aLocale( MsLangId::convertLanguageToLocale(
769                         	pFormat->GetLanguage()));
770 			aRet <<= aLocale;
771 		}
772 		else if (aString.EqualsAscii( PROPERTYNAME_TYPE ))
773 		{
774 			aRet <<= (sal_Int16)( pFormat->GetType() );
775 		}
776 		else if (aString.EqualsAscii( PROPERTYNAME_COMMENT ))
777 		{
778 			aRet <<= rtl::OUString( pFormat->GetComment() );
779 		}
780 		else if (aString.EqualsAscii( PROPERTYNAME_STDFORM ))
781 		{
782 			//!	SvNumberformat Member bStandard rausreichen?
783 			sal_Bool bStandard = ( ( nKey % SV_COUNTRY_LANGUAGE_OFFSET ) == 0 );
784 			aRet.setValue( &bStandard, getBooleanCppuType() );
785 		}
786 		else if (aString.EqualsAscii( PROPERTYNAME_USERDEF ))
787 		{
788 			sal_Bool bUserDef = ( ( pFormat->GetType() & NUMBERFORMAT_DEFINED ) != 0 );
789 			aRet.setValue( &bUserDef, getBooleanCppuType() );
790 		}
791 		else if (aString.EqualsAscii( PROPERTYNAME_DECIMALS ))
792 		{
793 			pFormat->GetFormatSpecialInfo( bThousand, bRed, nDecimals, nLeading );
794 			aRet <<= (sal_Int16)( nDecimals );
795 		}
796 		else if (aString.EqualsAscii( PROPERTYNAME_LEADING ))
797 		{
798 			pFormat->GetFormatSpecialInfo( bThousand, bRed, nDecimals, nLeading );
799 			aRet <<= (sal_Int16)( nLeading );
800 		}
801 		else if (aString.EqualsAscii( PROPERTYNAME_NEGRED ))
802 		{
803 			pFormat->GetFormatSpecialInfo( bThousand, bRed, nDecimals, nLeading );
804 			aRet.setValue( &bRed, getBooleanCppuType() );
805 		}
806 		else if (aString.EqualsAscii( PROPERTYNAME_THOUS ))
807 		{
808 			pFormat->GetFormatSpecialInfo( bThousand, bRed, nDecimals, nLeading );
809 			aRet.setValue( &bThousand, getBooleanCppuType() );
810 		}
811 		else if (aString.EqualsAscii( PROPERTYNAME_CURRSYM ))
812 		{
813 			String aSymbol, aExt;
814 			pFormat->GetNewCurrencySymbol( aSymbol, aExt );
815 			aRet <<= rtl::OUString( aSymbol );
816 		}
817 		else if (aString.EqualsAscii( PROPERTYNAME_CURREXT ))
818 		{
819 			String aSymbol, aExt;
820 			pFormat->GetNewCurrencySymbol( aSymbol, aExt );
821 			aRet <<= rtl::OUString( aExt );
822 		}
823 		else if (aString.EqualsAscii( PROPERTYNAME_CURRABB ))
824 		{
825 			String aSymbol, aExt;
826 			sal_Bool bBank = sal_False;
827 			pFormat->GetNewCurrencySymbol( aSymbol, aExt );
828 			const NfCurrencyEntry* pCurr = pFormatter->GetCurrencyEntry( bBank,
829 				aSymbol, aExt, pFormat->GetLanguage() );
830 			if ( pCurr )
831 				aRet <<= rtl::OUString( pCurr->GetBankSymbol() );
832 			else
833 				aRet <<= rtl::OUString();
834 		}
835 		else
836 			throw beans::UnknownPropertyException();
837 	}
838 	else
839 		throw uno::RuntimeException();
840 
841 	return aRet;
842 }
843 
addPropertyChangeListener(const rtl::OUString &,const uno::Reference<beans::XPropertyChangeListener> &)844 void SAL_CALL SvNumberFormatObj::addPropertyChangeListener( const rtl::OUString&,
845 						const uno::Reference<beans::XPropertyChangeListener>&)
846 						throw(beans::UnknownPropertyException,
847 						lang::WrappedTargetException, uno::RuntimeException)
848 {
849 	DBG_ERROR("not implemented");
850 }
851 
removePropertyChangeListener(const rtl::OUString &,const uno::Reference<beans::XPropertyChangeListener> &)852 void SAL_CALL SvNumberFormatObj::removePropertyChangeListener( const rtl::OUString&,
853 						const uno::Reference<beans::XPropertyChangeListener>&)
854 						throw(beans::UnknownPropertyException,
855 						lang::WrappedTargetException, uno::RuntimeException)
856 {
857 	DBG_ERROR("not implemented");
858 }
859 
addVetoableChangeListener(const rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)860 void SAL_CALL SvNumberFormatObj::addVetoableChangeListener( const rtl::OUString&,
861 						const uno::Reference<beans::XVetoableChangeListener>&)
862 						throw(beans::UnknownPropertyException,
863 						lang::WrappedTargetException, uno::RuntimeException)
864 {
865 	DBG_ERROR("not implemented");
866 }
867 
removeVetoableChangeListener(const rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)868 void SAL_CALL SvNumberFormatObj::removeVetoableChangeListener( const rtl::OUString&,
869 						const uno::Reference<beans::XVetoableChangeListener>&)
870 						throw(beans::UnknownPropertyException,
871 						lang::WrappedTargetException, uno::RuntimeException)
872 {
873 	DBG_ERROR("not implemented");
874 }
875 
876 // XPropertyAccess
877 
getPropertyValues()878 uno::Sequence<beans::PropertyValue> SAL_CALL SvNumberFormatObj::getPropertyValues()
879 							throw(uno::RuntimeException)
880 {
881     ::osl::MutexGuard aGuard( m_aMutex );
882 
883 	SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter();
884 	const SvNumberformat* pFormat = pFormatter ? pFormatter->GetEntry(nKey) : NULL;
885 	if (pFormat)
886 	{
887 		String aSymbol, aExt, aAbb;
888 		sal_Bool bBank = sal_False;
889 		pFormat->GetNewCurrencySymbol( aSymbol, aExt );
890 		const NfCurrencyEntry* pCurr = pFormatter->GetCurrencyEntry( bBank,
891 			aSymbol, aExt, pFormat->GetLanguage() );
892 		if ( pCurr )
893 			aAbb = pCurr->GetBankSymbol();
894 
895 		String aFmtStr = pFormat->GetFormatstring();
896 		String aComment = pFormat->GetComment();
897 		sal_Bool bStandard = ( ( nKey % SV_COUNTRY_LANGUAGE_OFFSET ) == 0 );
898 		//!	SvNumberformat Member bStandard rausreichen?
899 		sal_Bool bUserDef = ( ( pFormat->GetType() & NUMBERFORMAT_DEFINED ) != 0 );
900 		sal_Bool bThousand, bRed;
901 		sal_uInt16 nDecimals, nLeading;
902 		pFormat->GetFormatSpecialInfo( bThousand, bRed, nDecimals, nLeading );
903 		lang::Locale aLocale( MsLangId::convertLanguageToLocale(
904                     pFormat->GetLanguage()));
905 
906 		uno::Sequence<beans::PropertyValue> aSeq(13);
907 		beans::PropertyValue* pArray = aSeq.getArray();
908 
909 		pArray[0].Name = rtl::OUString::createFromAscii( PROPERTYNAME_FMTSTR );
910 		pArray[0].Value <<= rtl::OUString( aFmtStr );
911 		pArray[1].Name = rtl::OUString::createFromAscii( PROPERTYNAME_LOCALE );
912 		pArray[1].Value <<= aLocale;
913 		pArray[2].Name = rtl::OUString::createFromAscii( PROPERTYNAME_TYPE );
914 		pArray[2].Value <<= (sal_Int16)( pFormat->GetType() );
915 		pArray[3].Name = rtl::OUString::createFromAscii( PROPERTYNAME_COMMENT );
916 		pArray[3].Value <<= rtl::OUString( aComment );
917 		pArray[4].Name = rtl::OUString::createFromAscii( PROPERTYNAME_STDFORM );
918 		pArray[4].Value.setValue( &bStandard, getBooleanCppuType() );
919 		pArray[5].Name = rtl::OUString::createFromAscii( PROPERTYNAME_USERDEF );
920 		pArray[5].Value.setValue( &bUserDef, getBooleanCppuType() );
921 		pArray[6].Name = rtl::OUString::createFromAscii( PROPERTYNAME_DECIMALS );
922 		pArray[6].Value <<= (sal_Int16)( nDecimals );
923 		pArray[7].Name = rtl::OUString::createFromAscii( PROPERTYNAME_LEADING );
924 		pArray[7].Value <<= (sal_Int16)( nLeading );
925 		pArray[8].Name = rtl::OUString::createFromAscii( PROPERTYNAME_NEGRED );
926 		pArray[8].Value.setValue( &bRed, getBooleanCppuType() );
927 		pArray[9].Name = rtl::OUString::createFromAscii( PROPERTYNAME_THOUS );
928 		pArray[9].Value.setValue( &bThousand, getBooleanCppuType() );
929 		pArray[10].Name = rtl::OUString::createFromAscii( PROPERTYNAME_CURRSYM );
930 		pArray[10].Value <<= rtl::OUString( aSymbol );
931 		pArray[11].Name = rtl::OUString::createFromAscii( PROPERTYNAME_CURREXT );
932 		pArray[11].Value <<= rtl::OUString( aExt );
933 		pArray[12].Name = rtl::OUString::createFromAscii( PROPERTYNAME_CURRABB );
934 		pArray[12].Value <<= rtl::OUString( aAbb );
935 
936 		return aSeq;
937 	}
938 	else
939 		throw uno::RuntimeException();
940 }
941 
setPropertyValues(const uno::Sequence<beans::PropertyValue> &)942 void SAL_CALL SvNumberFormatObj::setPropertyValues( const uno::Sequence<beans::PropertyValue>& )
943 						throw(beans::UnknownPropertyException, beans::PropertyVetoException,
944 								lang::IllegalArgumentException, lang::WrappedTargetException,
945 								uno::RuntimeException)
946 {
947 	throw beans::UnknownPropertyException();	//	everything is read-only
948 }
949 
950 // XServiceInfo
951 
getImplementationName()952 rtl::OUString SAL_CALL SvNumberFormatObj::getImplementationName()
953 							throw(uno::RuntimeException)
954 {
955 	return rtl::OUString::createFromAscii("SvNumberFormatObj");
956 }
957 
supportsService(const rtl::OUString & ServiceName)958 sal_Bool SAL_CALL SvNumberFormatObj::supportsService( const rtl::OUString& ServiceName )
959 							throw(uno::RuntimeException)
960 {
961 	return ( ServiceName.compareToAscii(SERVICENAME_NUMBERFORMAT) == 0 );
962 }
963 
getSupportedServiceNames()964 uno::Sequence<rtl::OUString> SAL_CALL SvNumberFormatObj::getSupportedServiceNames()
965 							throw(uno::RuntimeException)
966 {
967 	uno::Sequence<rtl::OUString> aRet(1);
968 	rtl::OUString* pArray = aRet.getArray();
969 	pArray[0] = rtl::OUString::createFromAscii(SERVICENAME_NUMBERFORMAT);
970 	return aRet;
971 }
972 
973 //------------------------------------------------------------------------
974 
SvNumberFormatSettingsObj(SvNumberFormatsSupplierObj & rParent,const::comphelper::SharedMutex & _rMutex)975 SvNumberFormatSettingsObj::SvNumberFormatSettingsObj( SvNumberFormatsSupplierObj& rParent, const ::comphelper::SharedMutex& _rMutex )
976     :rSupplier( rParent )
977     ,m_aMutex( _rMutex )
978 {
979 	rSupplier.acquire();
980 }
981 
~SvNumberFormatSettingsObj()982 SvNumberFormatSettingsObj::~SvNumberFormatSettingsObj()
983 {
984 	rSupplier.release();
985 }
986 
987 // XPropertySet
988 
getPropertySetInfo()989 uno::Reference<beans::XPropertySetInfo> SAL_CALL SvNumberFormatSettingsObj::getPropertySetInfo()
990 							throw(uno::RuntimeException)
991 {
992     ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
993 	static uno::Reference<beans::XPropertySetInfo> aRef =
994 		new SfxItemPropertySetInfo( lcl_GetNumberSettingsPropertyMap() );
995 	return aRef;
996 }
997 
setPropertyValue(const rtl::OUString & aPropertyName,const uno::Any & aValue)998 void SAL_CALL SvNumberFormatSettingsObj::setPropertyValue( const rtl::OUString& aPropertyName,
999 													const uno::Any& aValue )
1000 				throw(beans::UnknownPropertyException, beans::PropertyVetoException,
1001 						lang::IllegalArgumentException, lang::WrappedTargetException,
1002 						uno::RuntimeException)
1003 {
1004     ::osl::MutexGuard aGuard( m_aMutex );
1005 
1006 	SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter();
1007 	if (pFormatter)
1008 	{
1009 		String aString = aPropertyName;
1010 		if (aString.EqualsAscii( PROPERTYNAME_NOZERO ))
1011 		{
1012 			//	operator >>= shouldn't be used for bool (?)
1013 			if ( aValue.getValueTypeClass() == uno::TypeClass_BOOLEAN )
1014 				pFormatter->SetNoZero( *(sal_Bool*)aValue.getValue() );
1015 		}
1016 		else if (aString.EqualsAscii( PROPERTYNAME_NULLDATE ))
1017 		{
1018 			util::Date aDate;
1019 			if ( aValue >>= aDate )
1020 				pFormatter->ChangeNullDate( aDate.Day, aDate.Month, aDate.Year );
1021 		}
1022 		else if (aString.EqualsAscii( PROPERTYNAME_STDDEC ))
1023 		{
1024 			sal_Int16 nInt16 = sal_Int16();
1025 			if ( aValue >>= nInt16 )
1026 				pFormatter->ChangeStandardPrec( nInt16 );
1027 		}
1028 		else if (aString.EqualsAscii( PROPERTYNAME_TWODIGIT ))
1029 		{
1030 			sal_Int16 nInt16 = sal_Int16();
1031 			if ( aValue >>= nInt16 )
1032 				pFormatter->SetYear2000( nInt16 );
1033 		}
1034 		else
1035 			throw beans::UnknownPropertyException();
1036 
1037 		rSupplier.SettingsChanged();
1038 	}
1039 	else
1040 		throw uno::RuntimeException();
1041 }
1042 
getPropertyValue(const rtl::OUString & aPropertyName)1043 uno::Any SAL_CALL SvNumberFormatSettingsObj::getPropertyValue( const rtl::OUString& aPropertyName )
1044 				throw(beans::UnknownPropertyException, lang::WrappedTargetException,
1045 						uno::RuntimeException)
1046 {
1047     ::osl::MutexGuard aGuard( m_aMutex );
1048 
1049 	uno::Any aRet;
1050 	SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter();
1051 	if (pFormatter)
1052 	{
1053 		String aString = aPropertyName;
1054 		if (aString.EqualsAscii( PROPERTYNAME_NOZERO ))
1055 		{
1056 			sal_Bool bNoZero = pFormatter->GetNoZero();
1057 			aRet.setValue( &bNoZero, getBooleanCppuType() );
1058 		}
1059 		else if (aString.EqualsAscii( PROPERTYNAME_NULLDATE ))
1060 		{
1061 			Date* pDate = pFormatter->GetNullDate();
1062 			if (pDate)
1063 			{
1064 				util::Date aUnoDate( pDate->GetDay(), pDate->GetMonth(), pDate->GetYear() );
1065 				aRet <<= aUnoDate;
1066 			}
1067 		}
1068 		else if (aString.EqualsAscii( PROPERTYNAME_STDDEC ))
1069 			aRet <<= (sal_Int16)( pFormatter->GetStandardPrec() );
1070 		else if (aString.EqualsAscii( PROPERTYNAME_TWODIGIT ))
1071 			aRet <<= (sal_Int16)( pFormatter->GetYear2000() );
1072 		else
1073 			throw beans::UnknownPropertyException();
1074 	}
1075 	else
1076 		throw uno::RuntimeException();
1077 
1078 	return aRet;
1079 }
1080 
addPropertyChangeListener(const rtl::OUString &,const uno::Reference<beans::XPropertyChangeListener> &)1081 void SAL_CALL SvNumberFormatSettingsObj::addPropertyChangeListener( const rtl::OUString&,
1082 						const uno::Reference<beans::XPropertyChangeListener>&)
1083 						throw(beans::UnknownPropertyException,
1084 						lang::WrappedTargetException, uno::RuntimeException)
1085 {
1086 	DBG_ERROR("not implemented");
1087 }
1088 
removePropertyChangeListener(const rtl::OUString &,const uno::Reference<beans::XPropertyChangeListener> &)1089 void SAL_CALL SvNumberFormatSettingsObj::removePropertyChangeListener( const rtl::OUString&,
1090 						const uno::Reference<beans::XPropertyChangeListener>&)
1091 						throw(beans::UnknownPropertyException,
1092 						lang::WrappedTargetException, uno::RuntimeException)
1093 {
1094 	DBG_ERROR("not implemented");
1095 }
1096 
addVetoableChangeListener(const rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)1097 void SAL_CALL SvNumberFormatSettingsObj::addVetoableChangeListener( const rtl::OUString&,
1098 						const uno::Reference<beans::XVetoableChangeListener>&)
1099 						throw(beans::UnknownPropertyException,
1100 						lang::WrappedTargetException, uno::RuntimeException)
1101 {
1102 	DBG_ERROR("not implemented");
1103 }
1104 
removeVetoableChangeListener(const rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)1105 void SAL_CALL SvNumberFormatSettingsObj::removeVetoableChangeListener( const rtl::OUString&,
1106 						const uno::Reference<beans::XVetoableChangeListener>&)
1107 						throw(beans::UnknownPropertyException,
1108 						lang::WrappedTargetException, uno::RuntimeException)
1109 {
1110 	DBG_ERROR("not implemented");
1111 }
1112 
1113 // XServiceInfo
1114 
getImplementationName()1115 rtl::OUString SAL_CALL SvNumberFormatSettingsObj::getImplementationName()
1116 							throw(uno::RuntimeException)
1117 {
1118 	return rtl::OUString::createFromAscii("SvNumberFormatSettingsObj");
1119 }
1120 
supportsService(const rtl::OUString & ServiceName)1121 sal_Bool SAL_CALL SvNumberFormatSettingsObj::supportsService( const rtl::OUString& ServiceName )
1122 							throw(uno::RuntimeException)
1123 {
1124 	return ( ServiceName.compareToAscii(SERVICENAME_NUMBERSETTINGS) == 0 );
1125 }
1126 
getSupportedServiceNames()1127 uno::Sequence<rtl::OUString> SAL_CALL SvNumberFormatSettingsObj::getSupportedServiceNames()
1128 							throw(uno::RuntimeException)
1129 {
1130 	uno::Sequence<rtl::OUString> aRet(1);
1131 	rtl::OUString* pArray = aRet.getArray();
1132 	pArray[0] = rtl::OUString::createFromAscii(SERVICENAME_NUMBERSETTINGS);
1133 	return aRet;
1134 }
1135 
1136 
1137