LCOV - code coverage report
Current view: top level - comphelper/source/misc - numbers.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 7 41 17.1 %
Date: 2012-08-25 Functions: 1 5 20.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 7 108 6.5 %

           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                 :            : #include <comphelper/numbers.hxx>
      21                 :            : #include <osl/diagnose.h>
      22                 :            : #include <com/sun/star/util/NumberFormat.hpp>
      23                 :            : #include <com/sun/star/util/XNumberFormatTypes.hpp>
      24                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      25                 :            : #include <com/sun/star/lang/Locale.hpp>
      26                 :            : 
      27                 :            : //.........................................................................
      28                 :            : namespace comphelper
      29                 :            : {
      30                 :            : //.........................................................................
      31                 :            : 
      32                 :            : namespace starbeans = ::com::sun::star::beans;
      33                 :            : namespace starlang  = ::com::sun::star::lang;
      34                 :            : 
      35                 :            : //------------------------------------------------------------------------------
      36                 :        152 : sal_Int16 getNumberFormatType(const staruno::Reference<starutil::XNumberFormats>& xFormats, sal_Int32 nKey)
      37                 :            : {
      38                 :        152 :     sal_Int16 nReturn(starutil::NumberFormat::UNDEFINED);
      39         [ +  - ]:        152 :     if (xFormats.is())
      40                 :            :     {
      41                 :            :         try
      42                 :            :         {
      43 [ +  - ][ +  - ]:        152 :             staruno::Reference<starbeans::XPropertySet> xFormat(xFormats->getByKey(nKey));
      44         [ +  - ]:        152 :             if (xFormat.is())
      45 [ +  - ][ +  - ]:        152 :                 xFormat->getPropertyValue(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Type" ))) >>= nReturn;
                 [ +  - ]
      46                 :            :         }
      47         [ #  # ]:          0 :         catch(...)
      48                 :            :         {
      49                 :            :             OSL_TRACE("getNumberFormatType : invalid key! (maybe created with another formatter ?)");
      50                 :            :         }
      51                 :            :     }
      52                 :        152 :     return nReturn;
      53                 :            : }
      54                 :            : 
      55                 :            : //------------------------------------------------------------------------------
      56                 :          0 : sal_Int16 getNumberFormatType(const staruno::Reference<starutil::XNumberFormatter>& xFormatter, sal_Int32 nKey)
      57                 :            : {
      58                 :            :     OSL_ENSURE(xFormatter.is(), "getNumberFormatType : the formatter isn't valid !");
      59 [ #  # ][ #  # ]:          0 :     staruno::Reference<starutil::XNumberFormatsSupplier> xSupplier( xFormatter->getNumberFormatsSupplier());
      60                 :            :     OSL_ENSURE(xSupplier.is(), "getNumberFormatType : the formatter doesn't implement a supplier !");
      61 [ #  # ][ #  # ]:          0 :     staruno::Reference<starutil::XNumberFormats> xFormats( xSupplier->getNumberFormats());
      62         [ #  # ]:          0 :     return getNumberFormatType(xFormats, nKey);
      63                 :            : }
      64                 :            : 
      65                 :            : //------------------------------------------------------------------------------
      66                 :          0 : staruno::Any getNumberFormatDecimals(const staruno::Reference<starutil::XNumberFormats>& xFormats, sal_Int32 nKey)
      67                 :            : {
      68         [ #  # ]:          0 :     if (xFormats.is())
      69                 :            :     {
      70                 :            :         try
      71                 :            :         {
      72 [ #  # ][ #  # ]:          0 :             staruno::Reference<starbeans::XPropertySet> xFormat( xFormats->getByKey(nKey));
      73         [ #  # ]:          0 :             if (xFormat.is())
      74                 :            :             {
      75 [ #  # ][ #  # ]:          0 :                 static ::rtl::OUString PROPERTY_DECIMALS( RTL_CONSTASCII_USTRINGPARAM( "Decimals" ));
         [ #  # ][ #  # ]
      76 [ #  # ][ #  # ]:          0 :                 return xFormat->getPropertyValue(PROPERTY_DECIMALS);
      77         [ #  # ]:          0 :             }
      78                 :            :         }
      79                 :          0 :         catch(...)
      80                 :            :         {
      81                 :            :             OSL_TRACE("getNumberFormatDecimals : invalid key! (may be created with another formatter ?)");
      82                 :            :         }
      83                 :            :     }
      84         [ #  # ]:          0 :     return staruno::makeAny((sal_Int16)0);
      85                 :            : }
      86                 :            : 
      87                 :            : 
      88                 :            : //------------------------------------------------------------------------------
      89                 :          0 : sal_Int32 getStandardFormat(
      90                 :            :         const staruno::Reference<starutil::XNumberFormatter>& xFormatter,
      91                 :            :         sal_Int16 nType,
      92                 :            :         const starlang::Locale& _rLocale)
      93                 :            : {
      94 [ #  # ][ #  # ]:          0 :     staruno::Reference<starutil::XNumberFormatsSupplier> xSupplier( xFormatter.is() ? xFormatter->getNumberFormatsSupplier() : staruno::Reference<starutil::XNumberFormatsSupplier>(NULL));
         [ #  # ][ #  # ]
      95 [ #  # ][ #  # ]:          0 :     staruno::Reference<starutil::XNumberFormats> xFormats( xSupplier.is() ? xSupplier->getNumberFormats() : staruno::Reference<starutil::XNumberFormats>(NULL));
         [ #  # ][ #  # ]
      96         [ #  # ]:          0 :     staruno::Reference<starutil::XNumberFormatTypes> xTypes(xFormats, staruno::UNO_QUERY);
      97                 :            :     OSL_ENSURE(xTypes.is(), "getStandardFormat : no format types !");
      98                 :            : 
      99 [ #  # ][ #  # ]:          0 :     return xTypes.is() ? xTypes->getStandardFormat(nType, _rLocale) : 0;
                 [ #  # ]
     100                 :            : }
     101                 :            : 
     102                 :            : //------------------------------------------------------------------------------
     103                 :            : using namespace ::com::sun::star::uno;
     104                 :            : using namespace ::com::sun::star::util;
     105                 :            : using namespace ::com::sun::star::beans;
     106                 :            : 
     107                 :            : //------------------------------------------------------------------------------
     108                 :          0 : Any getNumberFormatProperty( const Reference< XNumberFormatter >& _rxFormatter, sal_Int32 _nKey, const rtl::OUString& _rPropertyName )
     109                 :            : {
     110                 :          0 :     Any aReturn;
     111                 :            : 
     112                 :            :     OSL_ENSURE( _rxFormatter.is() && !_rPropertyName.isEmpty(), "getNumberFormatProperty: invalid arguments!" );
     113                 :            :     try
     114                 :            :     {
     115                 :          0 :         Reference< XNumberFormatsSupplier > xSupplier;
     116                 :          0 :         Reference< XNumberFormats > xFormats;
     117                 :          0 :         Reference< XPropertySet > xFormatProperties;
     118                 :            : 
     119         [ #  # ]:          0 :         if ( _rxFormatter.is() )
     120 [ #  # ][ #  # ]:          0 :             xSupplier = _rxFormatter->getNumberFormatsSupplier();
                 [ #  # ]
     121         [ #  # ]:          0 :         if ( xSupplier.is() )
     122 [ #  # ][ #  # ]:          0 :             xFormats = xSupplier->getNumberFormats();
                 [ #  # ]
     123         [ #  # ]:          0 :         if ( xFormats.is() )
     124 [ #  # ][ #  # ]:          0 :             xFormatProperties = xFormats->getByKey( _nKey );
                 [ #  # ]
     125                 :            : 
     126         [ #  # ]:          0 :         if ( xFormatProperties.is() )
     127 [ #  # ][ #  # ]:          0 :             aReturn = xFormatProperties->getPropertyValue( _rPropertyName );
                 [ #  # ]
     128                 :            :     }
     129         [ #  # ]:          0 :     catch( const Exception& )
     130                 :            :     {
     131                 :            :         OSL_FAIL( "::getNumberFormatProperty: caught an exception (did you create the key with another formatter?)!" );
     132                 :            :     }
     133                 :            : 
     134                 :          0 :     return aReturn;
     135                 :            : }
     136                 :            : 
     137                 :            : //.........................................................................
     138                 :            : }   // namespace comphelper
     139                 :            : //.........................................................................
     140                 :            : 
     141                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10