1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_chart2.hxx" 30*cdf0e10cSrcweir #include "NumberFormatterWrapper.hxx" 31*cdf0e10cSrcweir #include "macros.hxx" 32*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 33*cdf0e10cSrcweir // header for class SvNumberFormatsSupplierObj 34*cdf0e10cSrcweir #include <svl/numuno.hxx> 35*cdf0e10cSrcweir // header for class SvNumberformat 36*cdf0e10cSrcweir #include <svl/zformat.hxx> 37*cdf0e10cSrcweir #include <tools/color.hxx> 38*cdf0e10cSrcweir #include <i18npool/mslangid.hxx> 39*cdf0e10cSrcweir #include <tools/debug.hxx> 40*cdf0e10cSrcweir #include <com/sun/star/util/DateTime.hpp> 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir //............................................................................. 43*cdf0e10cSrcweir namespace chart 44*cdf0e10cSrcweir { 45*cdf0e10cSrcweir //............................................................................. 46*cdf0e10cSrcweir using namespace ::com::sun::star; 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir FixedNumberFormatter::FixedNumberFormatter( 49*cdf0e10cSrcweir const uno::Reference< util::XNumberFormatsSupplier >& xSupplier 50*cdf0e10cSrcweir , sal_Int32 nNumberFormatKey ) 51*cdf0e10cSrcweir : m_aNumberFormatterWrapper(xSupplier) 52*cdf0e10cSrcweir , m_nNumberFormatKey( nNumberFormatKey ) 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir } 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir FixedNumberFormatter::~FixedNumberFormatter() 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir } 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir /* 61*cdf0e10cSrcweir sal_Int32 FixedNumberFormatter::getTextAndColor( double fUnscaledValueForText, rtl::OUString& rLabel ) const 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir sal_Int32 nLabelColor = Color(COL_BLUE).GetColor(); //@todo get this from somewheres 64*cdf0e10cSrcweir rLabel = getFormattedString( fUnscaledValueForText, nLabelColor ); 65*cdf0e10cSrcweir return nLabelColor; 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir */ 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir rtl::OUString FixedNumberFormatter::getFormattedString( double fValue, sal_Int32& rLabelColor, bool& rbColorChanged ) const 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir return m_aNumberFormatterWrapper.getFormattedString( 72*cdf0e10cSrcweir m_nNumberFormatKey, fValue, rLabelColor, rbColorChanged ); 73*cdf0e10cSrcweir } 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir //----------------------------------------------------------------------- 76*cdf0e10cSrcweir //----------------------------------------------------------------------- 77*cdf0e10cSrcweir //----------------------------------------------------------------------- 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir NumberFormatterWrapper::NumberFormatterWrapper( const uno::Reference< util::XNumberFormatsSupplier >& xSupplier ) 80*cdf0e10cSrcweir : m_xNumberFormatsSupplier(xSupplier) 81*cdf0e10cSrcweir , m_pNumberFormatter(NULL) 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir uno::Reference<beans::XPropertySet> xProp(m_xNumberFormatsSupplier,uno::UNO_QUERY); 85*cdf0e10cSrcweir rtl::OUString sNullDate( RTL_CONSTASCII_USTRINGPARAM("NullDate")); 86*cdf0e10cSrcweir if ( xProp.is() && xProp->getPropertySetInfo()->hasPropertyByName(sNullDate) ) 87*cdf0e10cSrcweir m_aNullDate = xProp->getPropertyValue(sNullDate); 88*cdf0e10cSrcweir SvNumberFormatsSupplierObj* pSupplierObj = SvNumberFormatsSupplierObj::getImplementation( xSupplier ); 89*cdf0e10cSrcweir if( pSupplierObj ) 90*cdf0e10cSrcweir m_pNumberFormatter = pSupplierObj->GetNumberFormatter(); 91*cdf0e10cSrcweir DBG_ASSERT(m_pNumberFormatter,"need a numberformatter"); 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir NumberFormatterWrapper::~NumberFormatterWrapper() 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir SvNumberFormatter* NumberFormatterWrapper::getSvNumberFormatter() const 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir return m_pNumberFormatter; 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir Date NumberFormatterWrapper::getNullDate() const 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir sal_uInt16 nYear = 1899,nDay = 30,nMonth = 12; 106*cdf0e10cSrcweir Date aRet(nDay,nMonth,nYear); 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir util::DateTime aUtilDate; 109*cdf0e10cSrcweir if( m_aNullDate.hasValue() && (m_aNullDate >>= aUtilDate) ) 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir aRet = Date(aUtilDate.Day,aUtilDate.Month,aUtilDate.Year); 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir else if( m_pNumberFormatter ) 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir Date* pDate = m_pNumberFormatter->GetNullDate(); 116*cdf0e10cSrcweir if( pDate ) 117*cdf0e10cSrcweir aRet = *pDate; 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir return aRet; 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir rtl::OUString NumberFormatterWrapper::getFormattedString( 123*cdf0e10cSrcweir sal_Int32 nNumberFormatKey, double fValue, sal_Int32& rLabelColor, bool& rbColorChanged ) const 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir String aText; 126*cdf0e10cSrcweir Color* pTextColor = NULL; 127*cdf0e10cSrcweir if( !m_pNumberFormatter ) 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir DBG_ERROR("Need a NumberFormatter"); 130*cdf0e10cSrcweir return aText; 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir // i99104 handle null date correctly 133*cdf0e10cSrcweir sal_uInt16 nYear = 1899,nDay = 30,nMonth = 12; 134*cdf0e10cSrcweir if ( m_aNullDate.hasValue() ) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir Date* pDate = m_pNumberFormatter->GetNullDate(); 137*cdf0e10cSrcweir if ( pDate ) 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir nYear = pDate->GetYear(); 140*cdf0e10cSrcweir nMonth = pDate->GetMonth(); 141*cdf0e10cSrcweir nDay = pDate->GetDay(); 142*cdf0e10cSrcweir } // if ( pDate ) 143*cdf0e10cSrcweir util::DateTime aNewNullDate; 144*cdf0e10cSrcweir m_aNullDate >>= aNewNullDate; 145*cdf0e10cSrcweir m_pNumberFormatter->ChangeNullDate(aNewNullDate.Day,aNewNullDate.Month,aNewNullDate.Year); 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir m_pNumberFormatter->GetOutputString( 148*cdf0e10cSrcweir fValue, nNumberFormatKey, aText, &pTextColor); 149*cdf0e10cSrcweir if ( m_aNullDate.hasValue() ) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir m_pNumberFormatter->ChangeNullDate(nDay,nMonth,nYear); 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir rtl::OUString aRet( aText ); 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir if(pTextColor) 156*cdf0e10cSrcweir { 157*cdf0e10cSrcweir rbColorChanged = true; 158*cdf0e10cSrcweir rLabelColor = pTextColor->GetColor(); 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir else 161*cdf0e10cSrcweir rbColorChanged = false; 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir return aRet; 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir // to get the language type use MsLangId::convertLocaleToLanguage( rNumberFormat.aLocale ) 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir /* 169*cdf0e10cSrcweir uno::Reference< i18n::XNumberFormatCode > xNumberFormatCode( 170*cdf0e10cSrcweir m_xCC->getServiceManager()->createInstanceWithContext( C2U( 171*cdf0e10cSrcweir "com.sun.star.i18n.NumberFormatMapper" ), m_xCC ), uno::UNO_QUERY ); 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir i18n::NumberFormatCode aNumberFormatCode = xNumberFormatCode->getDefault ( 174*cdf0e10cSrcweir i18n::KNumberFormatType::MEDIUM, 175*cdf0e10cSrcweir i18n::KNumberFormatUsage::SCIENTIFIC_NUMBER, 176*cdf0e10cSrcweir aLocale ); 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir uno::Sequence< i18n::NumberFormatCode > aListOfNumberFormatCode = xNumberFormatCode->getAllFormatCode( 179*cdf0e10cSrcweir i18n::KNumberFormatUsage::SCIENTIFIC_NUMBER, 180*cdf0e10cSrcweir aLocale ); 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir i18n::NumberFormatCode aNumberFormatCode0 = aListOfNumberFormatCode[0]; 183*cdf0e10cSrcweir i18n::NumberFormatCode aNumberFormatCode1 = aListOfNumberFormatCode[1]; 184*cdf0e10cSrcweir */ 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir //............................................................................. 187*cdf0e10cSrcweir } //namespace chart 188*cdf0e10cSrcweir //............................................................................. 189