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