1*cde9e8dcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*cde9e8dcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*cde9e8dcSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*cde9e8dcSAndrew Rist * distributed with this work for additional information
6*cde9e8dcSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*cde9e8dcSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*cde9e8dcSAndrew Rist * "License"); you may not use this file except in compliance
9*cde9e8dcSAndrew Rist * with the License. You may obtain a copy of the License at
10*cde9e8dcSAndrew Rist *
11*cde9e8dcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*cde9e8dcSAndrew Rist *
13*cde9e8dcSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*cde9e8dcSAndrew Rist * software distributed under the License is distributed on an
15*cde9e8dcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*cde9e8dcSAndrew Rist * KIND, either express or implied. See the License for the
17*cde9e8dcSAndrew Rist * specific language governing permissions and limitations
18*cde9e8dcSAndrew Rist * under the License.
19*cde9e8dcSAndrew Rist *
20*cde9e8dcSAndrew Rist *************************************************************/
21*cde9e8dcSAndrew Rist
22*cde9e8dcSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_chart2.hxx"
26cdf0e10cSrcweir #include "NumberFormatterWrapper.hxx"
27cdf0e10cSrcweir #include "macros.hxx"
28cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
29cdf0e10cSrcweir // header for class SvNumberFormatsSupplierObj
30cdf0e10cSrcweir #include <svl/numuno.hxx>
31cdf0e10cSrcweir // header for class SvNumberformat
32cdf0e10cSrcweir #include <svl/zformat.hxx>
33cdf0e10cSrcweir #include <tools/color.hxx>
34cdf0e10cSrcweir #include <i18npool/mslangid.hxx>
35cdf0e10cSrcweir #include <tools/debug.hxx>
36cdf0e10cSrcweir #include <com/sun/star/util/DateTime.hpp>
37cdf0e10cSrcweir
38cdf0e10cSrcweir //.............................................................................
39cdf0e10cSrcweir namespace chart
40cdf0e10cSrcweir {
41cdf0e10cSrcweir //.............................................................................
42cdf0e10cSrcweir using namespace ::com::sun::star;
43cdf0e10cSrcweir
FixedNumberFormatter(const uno::Reference<util::XNumberFormatsSupplier> & xSupplier,sal_Int32 nNumberFormatKey)44cdf0e10cSrcweir FixedNumberFormatter::FixedNumberFormatter(
45cdf0e10cSrcweir const uno::Reference< util::XNumberFormatsSupplier >& xSupplier
46cdf0e10cSrcweir , sal_Int32 nNumberFormatKey )
47cdf0e10cSrcweir : m_aNumberFormatterWrapper(xSupplier)
48cdf0e10cSrcweir , m_nNumberFormatKey( nNumberFormatKey )
49cdf0e10cSrcweir {
50cdf0e10cSrcweir }
51cdf0e10cSrcweir
~FixedNumberFormatter()52cdf0e10cSrcweir FixedNumberFormatter::~FixedNumberFormatter()
53cdf0e10cSrcweir {
54cdf0e10cSrcweir }
55cdf0e10cSrcweir
56cdf0e10cSrcweir /*
57cdf0e10cSrcweir sal_Int32 FixedNumberFormatter::getTextAndColor( double fUnscaledValueForText, rtl::OUString& rLabel ) const
58cdf0e10cSrcweir {
59cdf0e10cSrcweir sal_Int32 nLabelColor = Color(COL_BLUE).GetColor(); //@todo get this from somewheres
60cdf0e10cSrcweir rLabel = getFormattedString( fUnscaledValueForText, nLabelColor );
61cdf0e10cSrcweir return nLabelColor;
62cdf0e10cSrcweir }
63cdf0e10cSrcweir */
64cdf0e10cSrcweir
getFormattedString(double fValue,sal_Int32 & rLabelColor,bool & rbColorChanged) const65cdf0e10cSrcweir rtl::OUString FixedNumberFormatter::getFormattedString( double fValue, sal_Int32& rLabelColor, bool& rbColorChanged ) const
66cdf0e10cSrcweir {
67cdf0e10cSrcweir return m_aNumberFormatterWrapper.getFormattedString(
68cdf0e10cSrcweir m_nNumberFormatKey, fValue, rLabelColor, rbColorChanged );
69cdf0e10cSrcweir }
70cdf0e10cSrcweir
71cdf0e10cSrcweir //-----------------------------------------------------------------------
72cdf0e10cSrcweir //-----------------------------------------------------------------------
73cdf0e10cSrcweir //-----------------------------------------------------------------------
74cdf0e10cSrcweir
NumberFormatterWrapper(const uno::Reference<util::XNumberFormatsSupplier> & xSupplier)75cdf0e10cSrcweir NumberFormatterWrapper::NumberFormatterWrapper( const uno::Reference< util::XNumberFormatsSupplier >& xSupplier )
76cdf0e10cSrcweir : m_xNumberFormatsSupplier(xSupplier)
77cdf0e10cSrcweir , m_pNumberFormatter(NULL)
78cdf0e10cSrcweir
79cdf0e10cSrcweir {
80cdf0e10cSrcweir uno::Reference<beans::XPropertySet> xProp(m_xNumberFormatsSupplier,uno::UNO_QUERY);
81cdf0e10cSrcweir rtl::OUString sNullDate( RTL_CONSTASCII_USTRINGPARAM("NullDate"));
82cdf0e10cSrcweir if ( xProp.is() && xProp->getPropertySetInfo()->hasPropertyByName(sNullDate) )
83cdf0e10cSrcweir m_aNullDate = xProp->getPropertyValue(sNullDate);
84cdf0e10cSrcweir SvNumberFormatsSupplierObj* pSupplierObj = SvNumberFormatsSupplierObj::getImplementation( xSupplier );
85cdf0e10cSrcweir if( pSupplierObj )
86cdf0e10cSrcweir m_pNumberFormatter = pSupplierObj->GetNumberFormatter();
87cdf0e10cSrcweir DBG_ASSERT(m_pNumberFormatter,"need a numberformatter");
88cdf0e10cSrcweir }
89cdf0e10cSrcweir
~NumberFormatterWrapper()90cdf0e10cSrcweir NumberFormatterWrapper::~NumberFormatterWrapper()
91cdf0e10cSrcweir {
92cdf0e10cSrcweir }
93cdf0e10cSrcweir
getSvNumberFormatter() const94cdf0e10cSrcweir SvNumberFormatter* NumberFormatterWrapper::getSvNumberFormatter() const
95cdf0e10cSrcweir {
96cdf0e10cSrcweir return m_pNumberFormatter;
97cdf0e10cSrcweir }
98cdf0e10cSrcweir
getNullDate() const99cdf0e10cSrcweir Date NumberFormatterWrapper::getNullDate() const
100cdf0e10cSrcweir {
101cdf0e10cSrcweir sal_uInt16 nYear = 1899,nDay = 30,nMonth = 12;
102cdf0e10cSrcweir Date aRet(nDay,nMonth,nYear);
103cdf0e10cSrcweir
104cdf0e10cSrcweir util::DateTime aUtilDate;
105cdf0e10cSrcweir if( m_aNullDate.hasValue() && (m_aNullDate >>= aUtilDate) )
106cdf0e10cSrcweir {
107cdf0e10cSrcweir aRet = Date(aUtilDate.Day,aUtilDate.Month,aUtilDate.Year);
108cdf0e10cSrcweir }
109cdf0e10cSrcweir else if( m_pNumberFormatter )
110cdf0e10cSrcweir {
111cdf0e10cSrcweir Date* pDate = m_pNumberFormatter->GetNullDate();
112cdf0e10cSrcweir if( pDate )
113cdf0e10cSrcweir aRet = *pDate;
114cdf0e10cSrcweir }
115cdf0e10cSrcweir return aRet;
116cdf0e10cSrcweir }
117cdf0e10cSrcweir
getFormattedString(sal_Int32 nNumberFormatKey,double fValue,sal_Int32 & rLabelColor,bool & rbColorChanged) const118cdf0e10cSrcweir rtl::OUString NumberFormatterWrapper::getFormattedString(
119cdf0e10cSrcweir sal_Int32 nNumberFormatKey, double fValue, sal_Int32& rLabelColor, bool& rbColorChanged ) const
120cdf0e10cSrcweir {
121cdf0e10cSrcweir String aText;
122cdf0e10cSrcweir Color* pTextColor = NULL;
123cdf0e10cSrcweir if( !m_pNumberFormatter )
124cdf0e10cSrcweir {
125cdf0e10cSrcweir DBG_ERROR("Need a NumberFormatter");
126cdf0e10cSrcweir return aText;
127cdf0e10cSrcweir }
128cdf0e10cSrcweir // i99104 handle null date correctly
129cdf0e10cSrcweir sal_uInt16 nYear = 1899,nDay = 30,nMonth = 12;
130cdf0e10cSrcweir if ( m_aNullDate.hasValue() )
131cdf0e10cSrcweir {
132cdf0e10cSrcweir Date* pDate = m_pNumberFormatter->GetNullDate();
133cdf0e10cSrcweir if ( pDate )
134cdf0e10cSrcweir {
135cdf0e10cSrcweir nYear = pDate->GetYear();
136cdf0e10cSrcweir nMonth = pDate->GetMonth();
137cdf0e10cSrcweir nDay = pDate->GetDay();
138cdf0e10cSrcweir } // if ( pDate )
139cdf0e10cSrcweir util::DateTime aNewNullDate;
140cdf0e10cSrcweir m_aNullDate >>= aNewNullDate;
141cdf0e10cSrcweir m_pNumberFormatter->ChangeNullDate(aNewNullDate.Day,aNewNullDate.Month,aNewNullDate.Year);
142cdf0e10cSrcweir }
143cdf0e10cSrcweir m_pNumberFormatter->GetOutputString(
144cdf0e10cSrcweir fValue, nNumberFormatKey, aText, &pTextColor);
145cdf0e10cSrcweir if ( m_aNullDate.hasValue() )
146cdf0e10cSrcweir {
147cdf0e10cSrcweir m_pNumberFormatter->ChangeNullDate(nDay,nMonth,nYear);
148cdf0e10cSrcweir }
149cdf0e10cSrcweir rtl::OUString aRet( aText );
150cdf0e10cSrcweir
151cdf0e10cSrcweir if(pTextColor)
152cdf0e10cSrcweir {
153cdf0e10cSrcweir rbColorChanged = true;
154cdf0e10cSrcweir rLabelColor = pTextColor->GetColor();
155cdf0e10cSrcweir }
156cdf0e10cSrcweir else
157cdf0e10cSrcweir rbColorChanged = false;
158cdf0e10cSrcweir
159cdf0e10cSrcweir return aRet;
160cdf0e10cSrcweir }
161cdf0e10cSrcweir
162cdf0e10cSrcweir // to get the language type use MsLangId::convertLocaleToLanguage( rNumberFormat.aLocale )
163cdf0e10cSrcweir
164cdf0e10cSrcweir /*
165cdf0e10cSrcweir uno::Reference< i18n::XNumberFormatCode > xNumberFormatCode(
166cdf0e10cSrcweir m_xCC->getServiceManager()->createInstanceWithContext( C2U(
167cdf0e10cSrcweir "com.sun.star.i18n.NumberFormatMapper" ), m_xCC ), uno::UNO_QUERY );
168cdf0e10cSrcweir
169cdf0e10cSrcweir i18n::NumberFormatCode aNumberFormatCode = xNumberFormatCode->getDefault (
170cdf0e10cSrcweir i18n::KNumberFormatType::MEDIUM,
171cdf0e10cSrcweir i18n::KNumberFormatUsage::SCIENTIFIC_NUMBER,
172cdf0e10cSrcweir aLocale );
173cdf0e10cSrcweir
174cdf0e10cSrcweir uno::Sequence< i18n::NumberFormatCode > aListOfNumberFormatCode = xNumberFormatCode->getAllFormatCode(
175cdf0e10cSrcweir i18n::KNumberFormatUsage::SCIENTIFIC_NUMBER,
176cdf0e10cSrcweir aLocale );
177cdf0e10cSrcweir
178cdf0e10cSrcweir i18n::NumberFormatCode aNumberFormatCode0 = aListOfNumberFormatCode[0];
179cdf0e10cSrcweir i18n::NumberFormatCode aNumberFormatCode1 = aListOfNumberFormatCode[1];
180cdf0e10cSrcweir */
181cdf0e10cSrcweir
182cdf0e10cSrcweir //.............................................................................
183cdf0e10cSrcweir } //namespace chart
184cdf0e10cSrcweir //.............................................................................
185