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