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 : #include <svl/numuno.hxx>
24 : #include <svl/zformat.hxx>
25 : #include <tools/color.hxx>
26 : #include <i18nlangtag/mslangid.hxx>
27 : #include <com/sun/star/util/Date.hpp>
28 :
29 : namespace chart
30 : {
31 : using namespace ::com::sun::star;
32 :
33 2006 : FixedNumberFormatter::FixedNumberFormatter(
34 : const uno::Reference< util::XNumberFormatsSupplier >& xSupplier
35 : , sal_Int32 nNumberFormatKey )
36 : : m_aNumberFormatterWrapper(xSupplier)
37 2006 : , m_nNumberFormatKey( nNumberFormatKey )
38 : {
39 2006 : }
40 :
41 2006 : FixedNumberFormatter::~FixedNumberFormatter()
42 : {
43 2006 : }
44 :
45 5978 : OUString FixedNumberFormatter::getFormattedString( double fValue, sal_Int32& rLabelColor, bool& rbColorChanged ) const
46 : {
47 : return m_aNumberFormatterWrapper.getFormattedString(
48 5978 : m_nNumberFormatKey, fValue, rLabelColor, rbColorChanged );
49 : }
50 :
51 4727 : NumberFormatterWrapper::NumberFormatterWrapper( const uno::Reference< util::XNumberFormatsSupplier >& xSupplier )
52 : : m_xNumberFormatsSupplier(xSupplier)
53 4727 : , m_pNumberFormatter(NULL)
54 :
55 : {
56 4727 : uno::Reference<beans::XPropertySet> xProp(m_xNumberFormatsSupplier,uno::UNO_QUERY);
57 9454 : OUString sNullDate( "NullDate" );
58 4727 : if ( xProp.is() && xProp->getPropertySetInfo()->hasPropertyByName(sNullDate) )
59 2714 : m_aNullDate = xProp->getPropertyValue(sNullDate);
60 4727 : SvNumberFormatsSupplierObj* pSupplierObj = SvNumberFormatsSupplierObj::getImplementation( xSupplier );
61 4727 : if( pSupplierObj )
62 4727 : m_pNumberFormatter = pSupplierObj->GetNumberFormatter();
63 4727 : SAL_WARN_IF(!m_pNumberFormatter,"chart2.tools","need a numberformatter");
64 4727 : }
65 :
66 5277 : NumberFormatterWrapper::~NumberFormatterWrapper()
67 : {
68 5277 : }
69 :
70 544 : Date NumberFormatterWrapper::getNullDate() const
71 : {
72 544 : sal_uInt16 nYear = 1899,nDay = 30,nMonth = 12;
73 544 : Date aRet(nDay,nMonth,nYear);
74 :
75 544 : util::Date aUtilDate;
76 544 : if( m_aNullDate.hasValue() && (m_aNullDate >>= aUtilDate) )
77 : {
78 176 : aRet = Date(aUtilDate.Day,aUtilDate.Month,aUtilDate.Year);
79 : }
80 368 : else if( m_pNumberFormatter )
81 : {
82 368 : Date* pDate = m_pNumberFormatter->GetNullDate();
83 368 : if( pDate )
84 368 : aRet = *pDate;
85 : }
86 544 : return aRet;
87 : }
88 :
89 8067 : OUString NumberFormatterWrapper::getFormattedString( sal_Int32 nNumberFormatKey, double fValue,
90 : sal_Int32& rLabelColor, bool& rbColorChanged ) const
91 : {
92 8067 : OUString aText;
93 8067 : Color* pTextColor = NULL;
94 8067 : if( !m_pNumberFormatter )
95 : {
96 : OSL_FAIL("Need a NumberFormatter");
97 0 : return aText;
98 : }
99 : // i99104 handle null date correctly
100 8067 : sal_uInt16 nYear = 1899,nDay = 30,nMonth = 12;
101 8067 : if ( m_aNullDate.hasValue() )
102 : {
103 2874 : Date* pDate = m_pNumberFormatter->GetNullDate();
104 2874 : if ( pDate )
105 : {
106 2874 : nYear = pDate->GetYear();
107 2874 : nMonth = pDate->GetMonth();
108 2874 : nDay = pDate->GetDay();
109 : } // if ( pDate )
110 2874 : util::Date aNewNullDate;
111 2874 : m_aNullDate >>= aNewNullDate;
112 2874 : m_pNumberFormatter->ChangeNullDate(aNewNullDate.Day,aNewNullDate.Month,aNewNullDate.Year);
113 : }
114 8067 : m_pNumberFormatter->GetOutputString(fValue, nNumberFormatKey, aText, &pTextColor);
115 8067 : if ( m_aNullDate.hasValue() )
116 : {
117 2874 : m_pNumberFormatter->ChangeNullDate(nDay,nMonth,nYear);
118 : }
119 :
120 8067 : if(pTextColor)
121 : {
122 0 : rbColorChanged = true;
123 0 : rLabelColor = pTextColor->GetColor();
124 : }
125 : else
126 8067 : rbColorChanged = false;
127 :
128 8067 : return aText;
129 : }
130 :
131 : } //namespace chart
132 :
133 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|