Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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/Date.hpp>
30 :
31 : namespace chart
32 : {
33 : using namespace ::com::sun::star;
34 :
35 0 : FixedNumberFormatter::FixedNumberFormatter(
36 : const uno::Reference< util::XNumberFormatsSupplier >& xSupplier
37 : , sal_Int32 nNumberFormatKey )
38 : : m_aNumberFormatterWrapper(xSupplier)
39 0 : , m_nNumberFormatKey( nNumberFormatKey )
40 : {
41 0 : }
42 :
43 0 : FixedNumberFormatter::~FixedNumberFormatter()
44 : {
45 0 : }
46 :
47 0 : OUString FixedNumberFormatter::getFormattedString( double fValue, sal_Int32& rLabelColor, bool& rbColorChanged ) const
48 : {
49 : return m_aNumberFormatterWrapper.getFormattedString(
50 0 : m_nNumberFormatKey, fValue, rLabelColor, rbColorChanged );
51 : }
52 :
53 0 : NumberFormatterWrapper::NumberFormatterWrapper( const uno::Reference< util::XNumberFormatsSupplier >& xSupplier )
54 : : m_xNumberFormatsSupplier(xSupplier)
55 0 : , m_pNumberFormatter(NULL)
56 :
57 : {
58 0 : uno::Reference<beans::XPropertySet> xProp(m_xNumberFormatsSupplier,uno::UNO_QUERY);
59 0 : OUString sNullDate( "NullDate" );
60 0 : if ( xProp.is() && xProp->getPropertySetInfo()->hasPropertyByName(sNullDate) )
61 0 : m_aNullDate = xProp->getPropertyValue(sNullDate);
62 0 : SvNumberFormatsSupplierObj* pSupplierObj = SvNumberFormatsSupplierObj::getImplementation( xSupplier );
63 0 : if( pSupplierObj )
64 0 : m_pNumberFormatter = pSupplierObj->GetNumberFormatter();
65 0 : SAL_WARN_IF(!m_pNumberFormatter,"chart2.tools","need a numberformatter");
66 0 : }
67 :
68 0 : NumberFormatterWrapper::~NumberFormatterWrapper()
69 : {
70 0 : }
71 :
72 0 : SvNumberFormatter* NumberFormatterWrapper::getSvNumberFormatter() const
73 : {
74 0 : return m_pNumberFormatter;
75 : }
76 :
77 0 : Date NumberFormatterWrapper::getNullDate() const
78 : {
79 0 : sal_uInt16 nYear = 1899,nDay = 30,nMonth = 12;
80 0 : Date aRet(nDay,nMonth,nYear);
81 :
82 0 : util::Date aUtilDate;
83 0 : if( m_aNullDate.hasValue() && (m_aNullDate >>= aUtilDate) )
84 : {
85 0 : aRet = Date(aUtilDate.Day,aUtilDate.Month,aUtilDate.Year);
86 : }
87 0 : else if( m_pNumberFormatter )
88 : {
89 0 : Date* pDate = m_pNumberFormatter->GetNullDate();
90 0 : if( pDate )
91 0 : aRet = *pDate;
92 : }
93 0 : return aRet;
94 : }
95 :
96 0 : OUString NumberFormatterWrapper::getFormattedString( sal_Int32 nNumberFormatKey, double fValue,
97 : sal_Int32& rLabelColor, bool& rbColorChanged ) const
98 : {
99 0 : OUString aText;
100 0 : Color* pTextColor = NULL;
101 0 : if( !m_pNumberFormatter )
102 : {
103 : OSL_FAIL("Need a NumberFormatter");
104 0 : return aText;
105 : }
106 : // i99104 handle null date correctly
107 0 : sal_uInt16 nYear = 1899,nDay = 30,nMonth = 12;
108 0 : if ( m_aNullDate.hasValue() )
109 : {
110 0 : Date* pDate = m_pNumberFormatter->GetNullDate();
111 0 : if ( pDate )
112 : {
113 0 : nYear = pDate->GetYear();
114 0 : nMonth = pDate->GetMonth();
115 0 : nDay = pDate->GetDay();
116 : } // if ( pDate )
117 0 : util::Date aNewNullDate;
118 0 : m_aNullDate >>= aNewNullDate;
119 0 : m_pNumberFormatter->ChangeNullDate(aNewNullDate.Day,aNewNullDate.Month,aNewNullDate.Year);
120 : }
121 0 : m_pNumberFormatter->GetOutputString(fValue, nNumberFormatKey, aText, &pTextColor);
122 0 : if ( m_aNullDate.hasValue() )
123 : {
124 0 : m_pNumberFormatter->ChangeNullDate(nDay,nMonth,nYear);
125 : }
126 :
127 0 : if(pTextColor)
128 : {
129 0 : rbColorChanged = true;
130 0 : rLabelColor = pTextColor->GetColor();
131 : }
132 : else
133 0 : rbColorChanged = false;
134 :
135 0 : return aText;
136 : }
137 :
138 : } //namespace chart
139 :
140 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|