1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chartcontroller.hxx"
26
27 #include "WrappedNumberFormatProperty.hxx"
28 #include "macros.hxx"
29
30 // header for define DBG_ERROR
31 #include <tools/debug.hxx>
32
33 using namespace ::com::sun::star;
34 using ::com::sun::star::uno::Reference;
35 using ::com::sun::star::uno::Any;
36 using ::rtl::OUString;
37
38 //.............................................................................
39 namespace chart
40 {
41 namespace wrapper
42 {
43 //.............................................................................
44
WrappedNumberFormatProperty(::boost::shared_ptr<Chart2ModelContact> spChart2ModelContact)45 WrappedNumberFormatProperty::WrappedNumberFormatProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
46 : WrappedDirectStateProperty( C2U("NumberFormat"), C2U("NumberFormat") )
47 , m_spChart2ModelContact(spChart2ModelContact)
48 {
49 m_aOuterValue = getPropertyDefault( 0 );
50 }
51
~WrappedNumberFormatProperty()52 WrappedNumberFormatProperty::~WrappedNumberFormatProperty()
53 {
54 if( m_pWrappedLinkNumberFormatProperty )
55 {
56 if( m_pWrappedLinkNumberFormatProperty->m_pWrappedNumberFormatProperty == this )
57 m_pWrappedLinkNumberFormatProperty->m_pWrappedNumberFormatProperty = 0;
58 }
59 }
60
setPropertyValue(const Any & rOuterValue,const Reference<beans::XPropertySet> & xInnerPropertySet) const61 void WrappedNumberFormatProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
62 {
63 sal_Int32 nFormat = 0;
64 if( ! (rOuterValue >>= nFormat) )
65 throw lang::IllegalArgumentException( C2U("Property 'NumberFormat' requires value of type sal_Int32"), 0, 0 );
66
67 m_aOuterValue = rOuterValue;
68 if(xInnerPropertySet.is())
69 {
70 bool bUseSourceFormat = !xInnerPropertySet->getPropertyValue( C2U("NumberFormat" )).hasValue();
71 if( bUseSourceFormat )
72 {
73 uno::Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() );
74 if( xChartDoc.is() && xChartDoc->hasInternalDataProvider() )
75 bUseSourceFormat = false;
76 }
77 if( !bUseSourceFormat )
78 xInnerPropertySet->setPropertyValue( m_aInnerName, this->convertOuterToInnerValue( rOuterValue ) );
79 }
80 }
81
getPropertyValue(const Reference<beans::XPropertySet> & xInnerPropertySet) const82 Any WrappedNumberFormatProperty::getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const
83 {
84 if( !xInnerPropertySet.is() )
85 {
86 DBG_ERROR("missing xInnerPropertySet in WrappedNumberFormatProperty::getPropertyValue");
87 return Any();
88 }
89 Any aRet( xInnerPropertySet->getPropertyValue( m_aInnerName ));
90 if( !aRet.hasValue() )
91 {
92 sal_Int32 nKey = 0;
93 Reference< chart2::XDataSeries > xSeries( xInnerPropertySet, uno::UNO_QUERY );
94 if( xSeries.is() )
95 nKey = m_spChart2ModelContact->getExplicitNumberFormatKeyForSeries( xSeries );
96 else
97 {
98 Reference< chart2::XAxis > xAxis( xInnerPropertySet, uno::UNO_QUERY );
99 nKey = m_spChart2ModelContact->getExplicitNumberFormatKeyForAxis( xAxis );
100 }
101 aRet <<= nKey;
102 }
103 return aRet;
104 }
105
getPropertyDefault(const Reference<beans::XPropertyState> &) const106 Any WrappedNumberFormatProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
107 {
108 return uno::makeAny( sal_Int32( 0 ) );
109 }
110
111 //-----------------------------------------------------------------------------
112 //-----------------------------------------------------------------------------
113 //-----------------------------------------------------------------------------
114
WrappedLinkNumberFormatProperty(WrappedNumberFormatProperty * pWrappedNumberFormatProperty)115 WrappedLinkNumberFormatProperty::WrappedLinkNumberFormatProperty( WrappedNumberFormatProperty* pWrappedNumberFormatProperty )
116 : WrappedProperty( C2U("LinkNumberFormatToSource"), C2U("") )
117 , m_pWrappedNumberFormatProperty( pWrappedNumberFormatProperty )
118 {
119 if( m_pWrappedNumberFormatProperty )
120 {
121 m_pWrappedNumberFormatProperty->m_pWrappedLinkNumberFormatProperty = this;
122 }
123 }
124
~WrappedLinkNumberFormatProperty()125 WrappedLinkNumberFormatProperty::~WrappedLinkNumberFormatProperty()
126 {
127 if( m_pWrappedNumberFormatProperty )
128 {
129 if( m_pWrappedNumberFormatProperty->m_pWrappedLinkNumberFormatProperty == this )
130 m_pWrappedNumberFormatProperty->m_pWrappedLinkNumberFormatProperty = 0;
131 }
132 }
133
setPropertyValue(const Any & rOuterValue,const Reference<beans::XPropertySet> & xInnerPropertySet) const134 void WrappedLinkNumberFormatProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
135 {
136 if( !xInnerPropertySet.is() )
137 {
138 DBG_ERROR("missing xInnerPropertySet in WrappedNumberFormatProperty::setPropertyValue");
139 return;
140 }
141
142 bool bLinkFormat = false;
143 if( rOuterValue >>= bLinkFormat )
144 {
145 Any aValue;
146 if( bLinkFormat )
147 {
148 if( m_pWrappedNumberFormatProperty )
149 {
150 uno::Reference< chart2::XChartDocument > xChartDoc( m_pWrappedNumberFormatProperty->m_spChart2ModelContact->getChart2Document() );
151 if( xChartDoc.is() && xChartDoc->hasInternalDataProvider() )
152 return;
153 }
154 }
155 else
156 {
157 if( m_pWrappedNumberFormatProperty )
158 {
159 aValue = m_pWrappedNumberFormatProperty->getPropertyValue( xInnerPropertySet );
160 }
161 else
162 aValue <<= sal_Int32( 0 );
163 }
164
165 xInnerPropertySet->setPropertyValue( C2U("NumberFormat"), aValue );
166 }
167 }
168
getPropertyValue(const Reference<beans::XPropertySet> & xInnerPropertySet) const169 Any WrappedLinkNumberFormatProperty::getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const
170 {
171 if( !xInnerPropertySet.is() )
172 {
173 DBG_ERROR("missing xInnerPropertySet in WrappedNumberFormatProperty::getPropertyValue");
174 return getPropertyDefault(0);
175 }
176 bool bLink = ! xInnerPropertySet->getPropertyValue( C2U("NumberFormat" )).hasValue();
177 return uno::makeAny( bLink );
178 }
179
getPropertyDefault(const Reference<beans::XPropertyState> &) const180 Any WrappedLinkNumberFormatProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
181 {
182 bool bLink = true;
183 return uno::makeAny( bLink );
184 }
185
186 //.............................................................................
187 } //namespace wrapper
188 } //namespace chart
189 //.............................................................................
190