LCOV - code coverage report
Current view: top level - svl/source/numbers - numfmuno.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 237 516 45.9 %
Date: 2014-11-03 Functions: 33 69 47.8 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10