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_chart2.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                 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
63 {
64     sal_Int32 nFormat = 0;
65     if( ! (rOuterValue >>= nFormat) )
66         throw lang::IllegalArgumentException( C2U("Property 'NumberFormat' requires value of type sal_Int32"), 0, 0 );
67 
68     m_aOuterValue = rOuterValue;
69     if(xInnerPropertySet.is())
70     {
71         bool bUseSourceFormat = !xInnerPropertySet->getPropertyValue( C2U("NumberFormat" )).hasValue();
72         if( bUseSourceFormat )
73         {
74             uno::Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() );
75             if( xChartDoc.is() && xChartDoc->hasInternalDataProvider() )
76                 bUseSourceFormat = false;
77         }
78         if( !bUseSourceFormat )
79             xInnerPropertySet->setPropertyValue( m_aInnerName, this->convertOuterToInnerValue( rOuterValue ) );
80     }
81 }
82 
getPropertyValue(const Reference<beans::XPropertySet> & xInnerPropertySet) const83 Any WrappedNumberFormatProperty::getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const
84                         throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
85 {
86     if( !xInnerPropertySet.is() )
87     {
88         DBG_ERROR("missing xInnerPropertySet in WrappedNumberFormatProperty::getPropertyValue");
89         return Any();
90     }
91     Any aRet( xInnerPropertySet->getPropertyValue( m_aInnerName ));
92     if( !aRet.hasValue() )
93     {
94         sal_Int32 nKey = 0;
95         Reference< chart2::XDataSeries > xSeries( xInnerPropertySet, uno::UNO_QUERY );
96         if( xSeries.is() )
97             nKey = m_spChart2ModelContact->getExplicitNumberFormatKeyForSeries( xSeries );
98         else
99         {
100             Reference< chart2::XAxis > xAxis( xInnerPropertySet, uno::UNO_QUERY );
101             nKey = m_spChart2ModelContact->getExplicitNumberFormatKeyForAxis( xAxis );
102         }
103         aRet <<= nKey;
104     }
105     return aRet;
106 }
107 
getPropertyDefault(const Reference<beans::XPropertyState> &) const108 Any WrappedNumberFormatProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
109                         throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
110 {
111     return uno::makeAny( sal_Int32( 0 ) );
112 }
113 
114 //-----------------------------------------------------------------------------
115 //-----------------------------------------------------------------------------
116 //-----------------------------------------------------------------------------
117 
WrappedLinkNumberFormatProperty(WrappedNumberFormatProperty * pWrappedNumberFormatProperty)118 WrappedLinkNumberFormatProperty::WrappedLinkNumberFormatProperty( WrappedNumberFormatProperty* pWrappedNumberFormatProperty )
119         : WrappedProperty( C2U("LinkNumberFormatToSource"), C2U("") )
120         , m_pWrappedNumberFormatProperty( pWrappedNumberFormatProperty )
121 {
122     if( m_pWrappedNumberFormatProperty )
123     {
124         m_pWrappedNumberFormatProperty->m_pWrappedLinkNumberFormatProperty = this;
125     }
126 }
127 
~WrappedLinkNumberFormatProperty()128 WrappedLinkNumberFormatProperty::~WrappedLinkNumberFormatProperty()
129 {
130     if( m_pWrappedNumberFormatProperty )
131     {
132         if( m_pWrappedNumberFormatProperty->m_pWrappedLinkNumberFormatProperty == this )
133             m_pWrappedNumberFormatProperty->m_pWrappedLinkNumberFormatProperty = 0;
134     }
135 }
136 
setPropertyValue(const Any & rOuterValue,const Reference<beans::XPropertySet> & xInnerPropertySet) const137 void WrappedLinkNumberFormatProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
138                 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
139 {
140     if( !xInnerPropertySet.is() )
141     {
142         DBG_ERROR("missing xInnerPropertySet in WrappedNumberFormatProperty::setPropertyValue");
143         return;
144     }
145 
146     bool bLinkFormat = false;
147     if( rOuterValue >>= bLinkFormat )
148     {
149         Any aValue;
150         if( bLinkFormat )
151         {
152             if( m_pWrappedNumberFormatProperty )
153             {
154                 uno::Reference< chart2::XChartDocument > xChartDoc( m_pWrappedNumberFormatProperty->m_spChart2ModelContact->getChart2Document() );
155                 if( xChartDoc.is() && xChartDoc->hasInternalDataProvider() )
156                     return;
157             }
158         }
159         else
160         {
161             if( m_pWrappedNumberFormatProperty )
162             {
163                 aValue = m_pWrappedNumberFormatProperty->getPropertyValue( xInnerPropertySet );
164             }
165             else
166                 aValue <<= sal_Int32( 0 );
167         }
168 
169         xInnerPropertySet->setPropertyValue( C2U("NumberFormat"), aValue );
170     }
171 }
172 
getPropertyValue(const Reference<beans::XPropertySet> & xInnerPropertySet) const173 Any WrappedLinkNumberFormatProperty::getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const
174                         throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
175 {
176     if( !xInnerPropertySet.is() )
177     {
178         DBG_ERROR("missing xInnerPropertySet in WrappedNumberFormatProperty::getPropertyValue");
179         return getPropertyDefault(0);
180     }
181     bool bLink = ! xInnerPropertySet->getPropertyValue( C2U("NumberFormat" )).hasValue();
182     return uno::makeAny( bLink );
183 }
184 
getPropertyDefault(const Reference<beans::XPropertyState> &) const185 Any WrappedLinkNumberFormatProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
186                         throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
187 {
188     bool bLink = true;
189     return uno::makeAny( bLink );
190 }
191 
192 //.............................................................................
193 } //namespace wrapper
194 } //namespace chart
195 //.............................................................................
196