1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <svl/numuno.hxx>
22 #include <svl/zforlist.hxx>
23 #include <tools/color.hxx>
24 #include <com/sun/star/util/Date.hpp>
25 #include <osl/diagnose.h>
26 #include <sal/log.hxx>
30 using namespace ::com::sun::star
;
32 FixedNumberFormatter::FixedNumberFormatter(
33 const uno::Reference
< util::XNumberFormatsSupplier
>& xSupplier
34 , sal_Int32 nNumberFormatKey
)
35 : m_aNumberFormatterWrapper(xSupplier
)
36 , m_nNumberFormatKey( nNumberFormatKey
)
40 FixedNumberFormatter::~FixedNumberFormatter()
44 OUString
FixedNumberFormatter::getFormattedString( double fValue
, Color
& rLabelColor
, bool& rbColorChanged
) const
46 return m_aNumberFormatterWrapper
.getFormattedString(
47 m_nNumberFormatKey
, fValue
, rLabelColor
, rbColorChanged
);
50 NumberFormatterWrapper::NumberFormatterWrapper( const uno::Reference
< util::XNumberFormatsSupplier
>& xSupplier
)
51 : m_xNumberFormatsSupplier(xSupplier
)
52 , m_pNumberFormatter(nullptr)
55 uno::Reference
<beans::XPropertySet
> xProp(m_xNumberFormatsSupplier
,uno::UNO_QUERY
);
56 OUString
sNullDate( "NullDate" );
57 if ( xProp
.is() && xProp
->getPropertySetInfo()->hasPropertyByName(sNullDate
) )
58 m_aNullDate
= xProp
->getPropertyValue(sNullDate
);
59 SvNumberFormatsSupplierObj
* pSupplierObj
= comphelper::getUnoTunnelImplementation
<SvNumberFormatsSupplierObj
>( xSupplier
);
61 m_pNumberFormatter
= pSupplierObj
->GetNumberFormatter();
62 SAL_WARN_IF(!m_pNumberFormatter
,"chart2.tools","need a numberformatter");
65 NumberFormatterWrapper::~NumberFormatterWrapper()
69 Date
NumberFormatterWrapper::getNullDate() const
71 Date
aRet(30,12,1899);
74 if( m_aNullDate
.hasValue() && (m_aNullDate
>>= aUtilDate
) )
76 aRet
= Date(aUtilDate
.Day
,aUtilDate
.Month
,aUtilDate
.Year
);
78 else if( m_pNumberFormatter
)
80 aRet
= m_pNumberFormatter
->GetNullDate();
85 OUString
NumberFormatterWrapper::getFormattedString( sal_Int32 nNumberFormatKey
, double fValue
,
86 Color
& rLabelColor
, bool& rbColorChanged
) const
89 Color
* pTextColor
= nullptr;
90 if( !m_pNumberFormatter
)
92 OSL_FAIL("Need a NumberFormatter");
95 // i99104 handle null date correctly
96 sal_Int16 nYear
= 1899;
97 sal_uInt16 nDay
= 30,nMonth
= 12;
98 if ( m_aNullDate
.hasValue() )
100 const Date
& rDate
= m_pNumberFormatter
->GetNullDate();
101 nYear
= rDate
.GetYear();
102 nMonth
= rDate
.GetMonth();
103 nDay
= rDate
.GetDay();
104 util::Date aNewNullDate
;
105 m_aNullDate
>>= aNewNullDate
;
106 m_pNumberFormatter
->ChangeNullDate(aNewNullDate
.Day
,aNewNullDate
.Month
,aNewNullDate
.Year
);
108 m_pNumberFormatter
->GetOutputString(fValue
, nNumberFormatKey
, aText
, &pTextColor
);
109 if ( m_aNullDate
.hasValue() )
111 m_pNumberFormatter
->ChangeNullDate(nDay
,nMonth
,nYear
);
116 rbColorChanged
= true;
117 rLabelColor
= *pTextColor
;
120 rbColorChanged
= false;
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */