bump product version to 4.1.6.2
[LibreOffice.git] / chart2 / source / tools / NumberFormatterWrapper.cxx
bloba1080b34c79268e622ff9e44bb39fad8275ae420
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "NumberFormatterWrapper.hxx"
21 #include "macros.hxx"
22 #include <comphelper/processfactory.hxx>
23 // header for class SvNumberFormatsSupplierObj
24 #include <svl/numuno.hxx>
25 // header for class SvNumberformat
26 #include <svl/zformat.hxx>
27 #include <tools/color.hxx>
28 #include <i18nlangtag/mslangid.hxx>
29 #include <com/sun/star/util/DateTime.hpp>
31 //.............................................................................
32 namespace chart
34 //.............................................................................
35 using namespace ::com::sun::star;
37 FixedNumberFormatter::FixedNumberFormatter(
38 const uno::Reference< util::XNumberFormatsSupplier >& xSupplier
39 , sal_Int32 nNumberFormatKey )
40 : m_aNumberFormatterWrapper(xSupplier)
41 , m_nNumberFormatKey( nNumberFormatKey )
45 FixedNumberFormatter::~FixedNumberFormatter()
49 OUString FixedNumberFormatter::getFormattedString( double fValue, sal_Int32& rLabelColor, bool& rbColorChanged ) const
51 return m_aNumberFormatterWrapper.getFormattedString(
52 m_nNumberFormatKey, fValue, rLabelColor, rbColorChanged );
55 //-----------------------------------------------------------------------
56 //-----------------------------------------------------------------------
57 //-----------------------------------------------------------------------
59 NumberFormatterWrapper::NumberFormatterWrapper( const uno::Reference< util::XNumberFormatsSupplier >& xSupplier )
60 : m_xNumberFormatsSupplier(xSupplier)
61 , m_pNumberFormatter(NULL)
64 uno::Reference<beans::XPropertySet> xProp(m_xNumberFormatsSupplier,uno::UNO_QUERY);
65 OUString sNullDate( "NullDate" );
66 if ( xProp.is() && xProp->getPropertySetInfo()->hasPropertyByName(sNullDate) )
67 m_aNullDate = xProp->getPropertyValue(sNullDate);
68 SvNumberFormatsSupplierObj* pSupplierObj = SvNumberFormatsSupplierObj::getImplementation( xSupplier );
69 if( pSupplierObj )
70 m_pNumberFormatter = pSupplierObj->GetNumberFormatter();
71 OSL_POSTCOND(m_pNumberFormatter,"need a numberformatter");
74 NumberFormatterWrapper::~NumberFormatterWrapper()
78 SvNumberFormatter* NumberFormatterWrapper::getSvNumberFormatter() const
80 return m_pNumberFormatter;
83 Date NumberFormatterWrapper::getNullDate() const
85 sal_uInt16 nYear = 1899,nDay = 30,nMonth = 12;
86 Date aRet(nDay,nMonth,nYear);
88 util::DateTime aUtilDate;
89 if( m_aNullDate.hasValue() && (m_aNullDate >>= aUtilDate) )
91 aRet = Date(aUtilDate.Day,aUtilDate.Month,aUtilDate.Year);
93 else if( m_pNumberFormatter )
95 Date* pDate = m_pNumberFormatter->GetNullDate();
96 if( pDate )
97 aRet = *pDate;
99 return aRet;
102 OUString NumberFormatterWrapper::getFormattedString(
103 sal_Int32 nNumberFormatKey, double fValue, sal_Int32& rLabelColor, bool& rbColorChanged ) const
105 String aText;
106 Color* pTextColor = NULL;
107 if( !m_pNumberFormatter )
109 OSL_FAIL("Need a NumberFormatter");
110 return aText;
112 // i99104 handle null date correctly
113 sal_uInt16 nYear = 1899,nDay = 30,nMonth = 12;
114 if ( m_aNullDate.hasValue() )
116 Date* pDate = m_pNumberFormatter->GetNullDate();
117 if ( pDate )
119 nYear = pDate->GetYear();
120 nMonth = pDate->GetMonth();
121 nDay = pDate->GetDay();
122 } // if ( pDate )
123 util::DateTime aNewNullDate;
124 m_aNullDate >>= aNewNullDate;
125 m_pNumberFormatter->ChangeNullDate(aNewNullDate.Day,aNewNullDate.Month,aNewNullDate.Year);
127 m_pNumberFormatter->GetOutputString(
128 fValue, nNumberFormatKey, aText, &pTextColor);
129 if ( m_aNullDate.hasValue() )
131 m_pNumberFormatter->ChangeNullDate(nDay,nMonth,nYear);
133 OUString aRet( aText );
135 if(pTextColor)
137 rbColorChanged = true;
138 rLabelColor = pTextColor->GetColor();
140 else
141 rbColorChanged = false;
143 return aRet;
146 //.............................................................................
147 } //namespace chart
148 //.............................................................................
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */