1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: NumberFormatterWrapper.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
33 #include "chartview/NumberFormatterWrapper.hxx"
35 #include <comphelper/processfactory.hxx>
36 // header for class SvNumberFormatsSupplierObj
37 #include <svtools/numuno.hxx>
38 // header for class SvNumberformat
39 #include <svtools/zformat.hxx>
40 #include <tools/color.hxx>
41 #include <i18npool/mslangid.hxx>
42 #include <tools/debug.hxx>
43 #include <com/sun/star/util/DateTime.hpp>
45 //.............................................................................
48 //.............................................................................
49 using namespace ::com::sun::star
;
51 FixedNumberFormatter::FixedNumberFormatter(
52 const uno::Reference
< util::XNumberFormatsSupplier
>& xSupplier
53 , sal_Int32 nNumberFormatKey
)
54 : m_aNumberFormatterWrapper(xSupplier
)
55 , m_nNumberFormatKey( nNumberFormatKey
)
59 FixedNumberFormatter::~FixedNumberFormatter()
64 sal_Int32 FixedNumberFormatter::getTextAndColor( double fUnscaledValueForText, rtl::OUString& rLabel ) const
66 sal_Int32 nLabelColor = Color(COL_BLUE).GetColor(); //@todo get this from somewheres
67 rLabel = getFormattedString( fUnscaledValueForText, nLabelColor );
72 rtl::OUString
FixedNumberFormatter::getFormattedString( double fValue
, sal_Int32
& rLabelColor
, bool& rbColorChanged
) const
74 return m_aNumberFormatterWrapper
.getFormattedString(
75 m_nNumberFormatKey
, fValue
, rLabelColor
, rbColorChanged
);
78 //-----------------------------------------------------------------------
79 //-----------------------------------------------------------------------
80 //-----------------------------------------------------------------------
82 NumberFormatterWrapper::NumberFormatterWrapper( const uno::Reference
< util::XNumberFormatsSupplier
>& xSupplier
)
83 : m_xNumberFormatsSupplier(xSupplier
)
84 , m_pNumberFormatter(NULL
)
87 uno::Reference
<beans::XPropertySet
> xProp(m_xNumberFormatsSupplier
,uno::UNO_QUERY
);
88 rtl::OUString
sNullDate( RTL_CONSTASCII_USTRINGPARAM("NullDate"));
89 if ( xProp
.is() && xProp
->getPropertySetInfo()->hasPropertyByName(sNullDate
) )
90 m_aNullDate
= xProp
->getPropertyValue(sNullDate
);
91 SvNumberFormatsSupplierObj
* pSupplierObj
= SvNumberFormatsSupplierObj::getImplementation( xSupplier
);
93 m_pNumberFormatter
= pSupplierObj
->GetNumberFormatter();
94 DBG_ASSERT(m_pNumberFormatter
,"need a numberformatter");
97 NumberFormatterWrapper::~NumberFormatterWrapper()
101 SvNumberFormatter
* NumberFormatterWrapper::getSvNumberFormatter() const
103 return m_pNumberFormatter
;
106 rtl::OUString
NumberFormatterWrapper::getFormattedString(
107 sal_Int32 nNumberFormatKey
, double fValue
, sal_Int32
& rLabelColor
, bool& rbColorChanged
) const
110 Color
* pTextColor
= NULL
;
111 if( !m_pNumberFormatter
)
113 DBG_ERROR("Need a NumberFormatter");
116 // i99104 handle null date correctly
117 USHORT nYear
= 1899,nDay
= 30,nMonth
= 12;
118 if ( m_aNullDate
.hasValue() )
120 Date
* pDate
= m_pNumberFormatter
->GetNullDate();
123 nYear
= pDate
->GetYear();
124 nMonth
= pDate
->GetMonth();
125 nDay
= pDate
->GetDay();
127 util::DateTime aNewNullDate
;
128 m_aNullDate
>>= aNewNullDate
;
129 m_pNumberFormatter
->ChangeNullDate(aNewNullDate
.Day
,aNewNullDate
.Month
,aNewNullDate
.Year
);
131 m_pNumberFormatter
->GetOutputString(
132 fValue
, nNumberFormatKey
, aText
, &pTextColor
);
133 if ( m_aNullDate
.hasValue() )
135 m_pNumberFormatter
->ChangeNullDate(nDay
,nMonth
,nYear
);
137 rtl::OUString
aRet( aText
);
141 rbColorChanged
= true;
142 rLabelColor
= pTextColor
->GetColor();
145 rbColorChanged
= false;
150 // to get the language type use MsLangId::convertLocaleToLanguage( rNumberFormat.aLocale )
153 uno::Reference< i18n::XNumberFormatCode > xNumberFormatCode(
154 m_xCC->getServiceManager()->createInstanceWithContext( C2U(
155 "com.sun.star.i18n.NumberFormatMapper" ), m_xCC ), uno::UNO_QUERY );
157 i18n::NumberFormatCode aNumberFormatCode = xNumberFormatCode->getDefault (
158 i18n::KNumberFormatType::MEDIUM,
159 i18n::KNumberFormatUsage::SCIENTIFIC_NUMBER,
162 uno::Sequence< i18n::NumberFormatCode > aListOfNumberFormatCode = xNumberFormatCode->getAllFormatCode(
163 i18n::KNumberFormatUsage::SCIENTIFIC_NUMBER,
166 i18n::NumberFormatCode aNumberFormatCode0 = aListOfNumberFormatCode[0];
167 i18n::NumberFormatCode aNumberFormatCode1 = aListOfNumberFormatCode[1];
170 //.............................................................................
172 //.............................................................................