Branch data 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 <i18npool/mslangid.hxx>
29 : : #include <com/sun/star/util/DateTime.hpp>
30 : :
31 : : //.............................................................................
32 : : namespace chart
33 : : {
34 : : //.............................................................................
35 : : using namespace ::com::sun::star;
36 : :
37 : 3420 : FixedNumberFormatter::FixedNumberFormatter(
38 : : const uno::Reference< util::XNumberFormatsSupplier >& xSupplier
39 : : , sal_Int32 nNumberFormatKey )
40 : : : m_aNumberFormatterWrapper(xSupplier)
41 : 3420 : , m_nNumberFormatKey( nNumberFormatKey )
42 : : {
43 : 3420 : }
44 : :
45 : 3420 : FixedNumberFormatter::~FixedNumberFormatter()
46 : : {
47 [ - + ]: 3420 : }
48 : :
49 : 7814 : rtl::OUString FixedNumberFormatter::getFormattedString( double fValue, sal_Int32& rLabelColor, bool& rbColorChanged ) const
50 : : {
51 : : return m_aNumberFormatterWrapper.getFormattedString(
52 : 7814 : m_nNumberFormatKey, fValue, rLabelColor, rbColorChanged );
53 : : }
54 : :
55 : : //-----------------------------------------------------------------------
56 : : //-----------------------------------------------------------------------
57 : : //-----------------------------------------------------------------------
58 : :
59 : 8823 : NumberFormatterWrapper::NumberFormatterWrapper( const uno::Reference< util::XNumberFormatsSupplier >& xSupplier )
60 : : : m_xNumberFormatsSupplier(xSupplier)
61 : 8823 : , m_pNumberFormatter(NULL)
62 : :
63 : : {
64 [ + - ]: 8823 : uno::Reference<beans::XPropertySet> xProp(m_xNumberFormatsSupplier,uno::UNO_QUERY);
65 [ + - ]: 8823 : rtl::OUString sNullDate( RTL_CONSTASCII_USTRINGPARAM("NullDate"));
66 [ + - ][ + - ]: 8823 : if ( xProp.is() && xProp->getPropertySetInfo()->hasPropertyByName(sNullDate) )
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
[ + - # # ]
67 [ + - ][ + - ]: 8823 : m_aNullDate = xProp->getPropertyValue(sNullDate);
68 [ + - ]: 8823 : SvNumberFormatsSupplierObj* pSupplierObj = SvNumberFormatsSupplierObj::getImplementation( xSupplier );
69 [ + - ]: 8823 : if( pSupplierObj )
70 [ + - ]: 8823 : m_pNumberFormatter = pSupplierObj->GetNumberFormatter();
71 : 8823 : OSL_POSTCOND(m_pNumberFormatter,"need a numberformatter");
72 : 8823 : }
73 : :
74 : 8823 : NumberFormatterWrapper::~NumberFormatterWrapper()
75 : : {
76 [ - + ]: 9804 : }
77 : :
78 : 2462 : SvNumberFormatter* NumberFormatterWrapper::getSvNumberFormatter() const
79 : : {
80 : 2462 : return m_pNumberFormatter;
81 : : }
82 : :
83 : 993 : Date NumberFormatterWrapper::getNullDate() const
84 : : {
85 : 993 : sal_uInt16 nYear = 1899,nDay = 30,nMonth = 12;
86 : 993 : Date aRet(nDay,nMonth,nYear);
87 : :
88 : 993 : util::DateTime aUtilDate;
89 [ # # ][ # # ]: 993 : if( m_aNullDate.hasValue() && (m_aNullDate >>= aUtilDate) )
[ - + ][ - + ]
90 : : {
91 : 0 : aRet = Date(aUtilDate.Day,aUtilDate.Month,aUtilDate.Year);
92 : : }
93 [ + - ]: 993 : else if( m_pNumberFormatter )
94 : : {
95 [ + - ]: 993 : Date* pDate = m_pNumberFormatter->GetNullDate();
96 [ + - ]: 993 : if( pDate )
97 : 993 : aRet = *pDate;
98 : : }
99 : 993 : return aRet;
100 : : }
101 : :
102 : 10096 : rtl::OUString NumberFormatterWrapper::getFormattedString(
103 : : sal_Int32 nNumberFormatKey, double fValue, sal_Int32& rLabelColor, bool& rbColorChanged ) const
104 : : {
105 [ + - ]: 10096 : String aText;
106 : 10096 : Color* pTextColor = NULL;
107 [ - + ]: 10096 : if( !m_pNumberFormatter )
108 : : {
109 : : OSL_FAIL("Need a NumberFormatter");
110 [ # # ]: 0 : return aText;
111 : : }
112 : : // i99104 handle null date correctly
113 : 10096 : sal_uInt16 nYear = 1899,nDay = 30,nMonth = 12;
114 [ - + ]: 10096 : if ( m_aNullDate.hasValue() )
115 : : {
116 [ # # ]: 0 : Date* pDate = m_pNumberFormatter->GetNullDate();
117 [ # # ]: 0 : if ( pDate )
118 : : {
119 : 0 : nYear = pDate->GetYear();
120 : 0 : nMonth = pDate->GetMonth();
121 : 0 : nDay = pDate->GetDay();
122 : : } // if ( pDate )
123 : 0 : util::DateTime aNewNullDate;
124 [ # # ]: 0 : m_aNullDate >>= aNewNullDate;
125 [ # # ]: 0 : m_pNumberFormatter->ChangeNullDate(aNewNullDate.Day,aNewNullDate.Month,aNewNullDate.Year);
126 : : }
127 : : m_pNumberFormatter->GetOutputString(
128 [ + - ]: 10096 : fValue, nNumberFormatKey, aText, &pTextColor);
129 [ - + ]: 10096 : if ( m_aNullDate.hasValue() )
130 : : {
131 [ # # ]: 0 : m_pNumberFormatter->ChangeNullDate(nDay,nMonth,nYear);
132 : : }
133 [ + - ]: 10096 : rtl::OUString aRet( aText );
134 : :
135 [ - + ]: 10096 : if(pTextColor)
136 : : {
137 : 0 : rbColorChanged = true;
138 : 0 : rLabelColor = pTextColor->GetColor();
139 : : }
140 : : else
141 : 10096 : rbColorChanged = false;
142 : :
143 [ + - ]: 10096 : return aRet;
144 : : }
145 : :
146 : : //.............................................................................
147 : : } //namespace chart
148 : : //.............................................................................
149 : :
150 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|