LCOV - code coverage report
Current view: top level - chart2/source/tools - NumberFormatterWrapper.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 51 54 94.4 %
Date: 2015-06-13 12:38:46 Functions: 8 9 88.9 %
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 "NumberFormatterWrapper.hxx"
      21             : #include "macros.hxx"
      22             : #include <comphelper/processfactory.hxx>
      23             : #include <svl/numuno.hxx>
      24             : #include <svl/zformat.hxx>
      25             : #include <tools/color.hxx>
      26             : #include <i18nlangtag/mslangid.hxx>
      27             : #include <com/sun/star/util/Date.hpp>
      28             : #include <osl/diagnose.h>
      29             : 
      30             : namespace chart
      31             : {
      32             : using namespace ::com::sun::star;
      33             : 
      34        3774 : FixedNumberFormatter::FixedNumberFormatter(
      35             :                 const uno::Reference< util::XNumberFormatsSupplier >& xSupplier
      36             :                 , sal_Int32 nNumberFormatKey )
      37             :             : m_aNumberFormatterWrapper(xSupplier)
      38        3774 :             , m_nNumberFormatKey( nNumberFormatKey )
      39             : {
      40        3774 : }
      41             : 
      42        3774 : FixedNumberFormatter::~FixedNumberFormatter()
      43             : {
      44        3774 : }
      45             : 
      46        9274 : OUString FixedNumberFormatter::getFormattedString( double fValue, sal_Int32& rLabelColor, bool& rbColorChanged ) const
      47             : {
      48             :     return m_aNumberFormatterWrapper.getFormattedString(
      49        9274 :         m_nNumberFormatKey, fValue, rLabelColor, rbColorChanged );
      50             : }
      51             : 
      52        9404 : NumberFormatterWrapper::NumberFormatterWrapper( const uno::Reference< util::XNumberFormatsSupplier >& xSupplier )
      53             :                     : m_xNumberFormatsSupplier(xSupplier)
      54        9404 :                     , m_pNumberFormatter(NULL)
      55             : 
      56             : {
      57        9404 :     uno::Reference<beans::XPropertySet> xProp(m_xNumberFormatsSupplier,uno::UNO_QUERY);
      58       18808 :     OUString sNullDate( "NullDate" );
      59        9404 :     if ( xProp.is() && xProp->getPropertySetInfo()->hasPropertyByName(sNullDate) )
      60        4566 :         m_aNullDate = xProp->getPropertyValue(sNullDate);
      61        9404 :     SvNumberFormatsSupplierObj* pSupplierObj = SvNumberFormatsSupplierObj::getImplementation( xSupplier );
      62        9404 :     if( pSupplierObj )
      63        9404 :         m_pNumberFormatter = pSupplierObj->GetNumberFormatter();
      64        9404 :     SAL_WARN_IF(!m_pNumberFormatter,"chart2.tools","need a numberformatter");
      65        9404 : }
      66             : 
      67       10478 : NumberFormatterWrapper::~NumberFormatterWrapper()
      68             : {
      69       10478 : }
      70             : 
      71        1053 : Date NumberFormatterWrapper::getNullDate() const
      72             : {
      73        1053 :     sal_uInt16 nYear = 1899,nDay = 30,nMonth = 12;
      74        1053 :     Date aRet(nDay,nMonth,nYear);
      75             : 
      76        1053 :     util::Date aUtilDate;
      77        1053 :     if( m_aNullDate.hasValue() && (m_aNullDate >>= aUtilDate) )
      78             :     {
      79         168 :         aRet = Date(aUtilDate.Day,aUtilDate.Month,aUtilDate.Year);
      80             :     }
      81         885 :     else if( m_pNumberFormatter )
      82             :     {
      83         885 :         Date* pDate = m_pNumberFormatter->GetNullDate();
      84         885 :         if( pDate )
      85         885 :             aRet = *pDate;
      86             :     }
      87        1053 :     return aRet;
      88             : }
      89             : 
      90       11001 : OUString NumberFormatterWrapper::getFormattedString( sal_Int32 nNumberFormatKey, double fValue,
      91             :                                                      sal_Int32& rLabelColor, bool& rbColorChanged ) const
      92             : {
      93       11001 :     OUString aText;
      94       11001 :     Color* pTextColor = NULL;
      95       11001 :     if( !m_pNumberFormatter )
      96             :     {
      97             :         OSL_FAIL("Need a NumberFormatter");
      98           0 :         return aText;
      99             :     }
     100             :     // i99104 handle null date correctly
     101       11001 :     sal_uInt16 nYear = 1899,nDay = 30,nMonth = 12;
     102       11001 :     if ( m_aNullDate.hasValue() )
     103             :     {
     104        2596 :         Date* pDate = m_pNumberFormatter->GetNullDate();
     105        2596 :         if ( pDate )
     106             :         {
     107        2596 :             nYear = pDate->GetYear();
     108        2596 :             nMonth = pDate->GetMonth();
     109        2596 :             nDay = pDate->GetDay();
     110             :         } // if ( pDate )
     111        2596 :         util::Date aNewNullDate;
     112        2596 :         m_aNullDate >>= aNewNullDate;
     113        2596 :         m_pNumberFormatter->ChangeNullDate(aNewNullDate.Day,aNewNullDate.Month,aNewNullDate.Year);
     114             :     }
     115       11001 :     m_pNumberFormatter->GetOutputString(fValue, nNumberFormatKey, aText, &pTextColor);
     116       11001 :     if ( m_aNullDate.hasValue() )
     117             :     {
     118        2596 :         m_pNumberFormatter->ChangeNullDate(nDay,nMonth,nYear);
     119             :     }
     120             : 
     121       11001 :     if(pTextColor)
     122             :     {
     123           0 :         rbColorChanged = true;
     124           0 :         rLabelColor = pTextColor->GetColor();
     125             :     }
     126             :     else
     127       11001 :         rbColorChanged = false;
     128             : 
     129       11001 :     return aText;
     130             : }
     131             : 
     132             : } //namespace chart
     133             : 
     134             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11