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 "WrappedAxisAndGridExistenceProperties.hxx"
28 #include "AxisHelper.hxx"
29 #include "ChartModelHelper.hxx"
30 #include "TitleHelper.hxx"
31 #include "macros.hxx"
32
33 using namespace ::com::sun::star;
34 using ::com::sun::star::uno::Any;
35 using ::com::sun::star::uno::Reference;
36 using ::com::sun::star::uno::Sequence;
37 using ::rtl::OUString;
38
39 //.............................................................................
40 namespace chart
41 {
42 namespace wrapper
43 {
44
45 class WrappedAxisAndGridExistenceProperty : public WrappedProperty
46 {
47 public:
48 WrappedAxisAndGridExistenceProperty( bool bAxis, bool bMain, sal_Int32 nDimensionIndex
49 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
50 virtual ~WrappedAxisAndGridExistenceProperty();
51
52 virtual void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
53 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
54
55 virtual ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
56 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
57
58 virtual ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& xInnerPropertyState ) const
59 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
60
61 private: //member
62 ::boost::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
63 bool m_bAxis;
64 bool m_bMain;
65 sal_Int32 m_nDimensionIndex;
66 };
67
addWrappedProperties(std::vector<WrappedProperty * > & rList,::boost::shared_ptr<Chart2ModelContact> spChart2ModelContact)68 void WrappedAxisAndGridExistenceProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList
69 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
70 {
71 rList.push_back( new WrappedAxisAndGridExistenceProperty( true, true, 0, spChart2ModelContact ) );//x axis
72 rList.push_back( new WrappedAxisAndGridExistenceProperty( true, false, 0, spChart2ModelContact ) );//x secondary axis
73 rList.push_back( new WrappedAxisAndGridExistenceProperty( false, true, 0, spChart2ModelContact ) );//x grid
74 rList.push_back( new WrappedAxisAndGridExistenceProperty( false, false, 0, spChart2ModelContact ) );//x help grid
75
76 rList.push_back( new WrappedAxisAndGridExistenceProperty( true, true, 1, spChart2ModelContact ) );//y axis
77 rList.push_back( new WrappedAxisAndGridExistenceProperty( true, false, 1, spChart2ModelContact ) );//y secondary axis
78 rList.push_back( new WrappedAxisAndGridExistenceProperty( false, true, 1, spChart2ModelContact ) );//y grid
79 rList.push_back( new WrappedAxisAndGridExistenceProperty( false, false, 1, spChart2ModelContact ) );//y help grid
80
81 rList.push_back( new WrappedAxisAndGridExistenceProperty( true, true, 2, spChart2ModelContact ) );//z axis
82 rList.push_back( new WrappedAxisAndGridExistenceProperty( false, true, 2, spChart2ModelContact ) );//z grid
83 rList.push_back( new WrappedAxisAndGridExistenceProperty( false, false, 2, spChart2ModelContact ) );//z help grid
84 }
85
WrappedAxisAndGridExistenceProperty(bool bAxis,bool bMain,sal_Int32 nDimensionIndex,::boost::shared_ptr<Chart2ModelContact> spChart2ModelContact)86 WrappedAxisAndGridExistenceProperty::WrappedAxisAndGridExistenceProperty( bool bAxis, bool bMain, sal_Int32 nDimensionIndex
87 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
88 : WrappedProperty(OUString(),OUString())
89 , m_spChart2ModelContact( spChart2ModelContact )
90 , m_bAxis( bAxis )
91 , m_bMain( bMain )
92 , m_nDimensionIndex( nDimensionIndex )
93 {
94 switch( m_nDimensionIndex )
95 {
96 case 0:
97 {
98 if( m_bAxis )
99 {
100 if( m_bMain )
101 m_aOuterName = C2U( "HasXAxis" );
102 else
103 m_aOuterName = C2U( "HasSecondaryXAxis" );
104 }
105 else
106 {
107 if( m_bMain )
108 m_aOuterName = C2U( "HasXAxisGrid" );
109 else
110 m_aOuterName = C2U( "HasXAxisHelpGrid" );
111 }
112 }
113 break;
114 case 2:
115 {
116 if( m_bAxis )
117 {
118 OSL_ENSURE(m_bMain == true,"there is no secondary z axis at the old api");
119 m_bMain = true;
120 m_aOuterName = C2U( "HasZAxis" );
121 }
122 else
123 {
124 if( m_bMain )
125 m_aOuterName = C2U( "HasZAxisGrid" );
126 else
127 m_aOuterName = C2U( "HasZAxisHelpGrid" );
128 }
129 }
130 break;
131 default:
132 {
133 if( m_bAxis )
134 {
135 if( m_bMain )
136 m_aOuterName = C2U( "HasYAxis" );
137 else
138 m_aOuterName = C2U( "HasSecondaryYAxis" );
139 }
140 else
141 {
142 if( m_bMain )
143 m_aOuterName = C2U( "HasYAxisGrid" );
144 else
145 m_aOuterName = C2U( "HasYAxisHelpGrid" );
146 }
147 }
148 break;
149 }
150 }
151
~WrappedAxisAndGridExistenceProperty()152 WrappedAxisAndGridExistenceProperty::~WrappedAxisAndGridExistenceProperty()
153 {
154 }
155
setPropertyValue(const Any & rOuterValue,const Reference<beans::XPropertySet> & xInnerPropertySet) const156 void WrappedAxisAndGridExistenceProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
157 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
158 {
159 sal_Bool bNewValue = false;
160 if( ! (rOuterValue >>= bNewValue) )
161 throw lang::IllegalArgumentException( C2U("Has axis or grid properties require boolean values"), 0, 0 );
162
163 sal_Bool bOldValue = sal_False;
164 getPropertyValue( xInnerPropertySet ) >>= bOldValue;
165
166 if( bOldValue == bNewValue )
167 return;
168
169 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
170 if( bNewValue )
171 {
172 if( m_bAxis )
173 AxisHelper::showAxis( m_nDimensionIndex, m_bMain, xDiagram, m_spChart2ModelContact->m_xContext );
174 else
175 AxisHelper::showGrid( m_nDimensionIndex, 0, m_bMain, xDiagram, m_spChart2ModelContact->m_xContext );
176 }
177 else
178 {
179 if( m_bAxis )
180 AxisHelper::hideAxis( m_nDimensionIndex, m_bMain, xDiagram );
181 else
182 AxisHelper::hideGrid( m_nDimensionIndex, 0, m_bMain, xDiagram );
183 }
184 }
185
getPropertyValue(const Reference<beans::XPropertySet> &) const186 Any WrappedAxisAndGridExistenceProperty::getPropertyValue( const Reference< beans::XPropertySet >& /* xInnerPropertySet */ ) const
187 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
188 {
189 Any aRet;
190 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
191 if(m_bAxis)
192 {
193 sal_Bool bShown = AxisHelper::isAxisShown( m_nDimensionIndex, m_bMain, xDiagram );
194 aRet <<= bShown;
195 }
196 else
197 {
198 sal_Bool bShown = AxisHelper::isGridShown( m_nDimensionIndex, 0, m_bMain, xDiagram );
199 aRet <<= bShown;
200 }
201 return aRet;
202 }
203
getPropertyDefault(const Reference<beans::XPropertyState> &) const204 Any WrappedAxisAndGridExistenceProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
205 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
206 {
207 Any aRet;
208 aRet <<= false;
209 return aRet;
210 }
211
212 //---------------------------------------------------------------------------------------------------------------
213 //---------------------------------------------------------------------------------------------------------------
214 //---------------------------------------------------------------------------------------------------------------
215
216 class WrappedAxisTitleExistenceProperty : public WrappedProperty
217 {
218 public:
219 WrappedAxisTitleExistenceProperty( sal_Int32 nTitleIndex
220 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
221 virtual ~WrappedAxisTitleExistenceProperty();
222
223 virtual void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
224 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
225
226 virtual ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
227 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
228
229 virtual ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& xInnerPropertyState ) const
230 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
231
232 private: //member
233 ::boost::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
234 TitleHelper::eTitleType m_eTitleType;
235 };
236
addWrappedProperties(std::vector<WrappedProperty * > & rList,::boost::shared_ptr<Chart2ModelContact> spChart2ModelContact)237 void WrappedAxisTitleExistenceProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList
238 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
239 {
240 rList.push_back( new WrappedAxisTitleExistenceProperty( 0, spChart2ModelContact ) );//x axis title
241 rList.push_back( new WrappedAxisTitleExistenceProperty( 1, spChart2ModelContact ) );//y axis title
242 rList.push_back( new WrappedAxisTitleExistenceProperty( 2, spChart2ModelContact ) );//z axis title
243 rList.push_back( new WrappedAxisTitleExistenceProperty( 3, spChart2ModelContact ) );//secondary x axis title
244 rList.push_back( new WrappedAxisTitleExistenceProperty( 4, spChart2ModelContact ) );//secondary y axis title
245 }
246
WrappedAxisTitleExistenceProperty(sal_Int32 nTitleIndex,::boost::shared_ptr<Chart2ModelContact> spChart2ModelContact)247 WrappedAxisTitleExistenceProperty::WrappedAxisTitleExistenceProperty( sal_Int32 nTitleIndex
248 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
249 : WrappedProperty(OUString(),OUString())
250 , m_spChart2ModelContact( spChart2ModelContact )
251 , m_eTitleType( TitleHelper::Y_AXIS_TITLE )
252 {
253 switch( nTitleIndex )
254 {
255 case 0:
256 m_aOuterName = C2U( "HasXAxisTitle" );
257 m_eTitleType = TitleHelper::X_AXIS_TITLE;
258 break;
259 case 2:
260 m_aOuterName = C2U( "HasZAxisTitle" );
261 m_eTitleType = TitleHelper::Z_AXIS_TITLE;
262 break;
263 case 3:
264 m_aOuterName = C2U( "HasSecondaryXAxisTitle" );
265 m_eTitleType = TitleHelper::SECONDARY_X_AXIS_TITLE;
266 break;
267 case 4:
268 m_aOuterName = C2U( "HasSecondaryYAxisTitle" );
269 m_eTitleType = TitleHelper::SECONDARY_Y_AXIS_TITLE;
270 break;
271 default:
272 m_aOuterName = C2U( "HasYAxisTitle" );
273 m_eTitleType = TitleHelper::Y_AXIS_TITLE;
274 break;
275 }
276 }
277
~WrappedAxisTitleExistenceProperty()278 WrappedAxisTitleExistenceProperty::~WrappedAxisTitleExistenceProperty()
279 {
280 }
281
setPropertyValue(const Any & rOuterValue,const Reference<beans::XPropertySet> & xInnerPropertySet) const282 void WrappedAxisTitleExistenceProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
283 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
284 {
285 sal_Bool bNewValue = false;
286 if( ! (rOuterValue >>= bNewValue) )
287 throw lang::IllegalArgumentException( C2U("Has axis or grid properties require boolean values"), 0, 0 );
288
289 sal_Bool bOldValue = sal_False;
290 getPropertyValue( xInnerPropertySet ) >>= bOldValue;
291
292 if( bOldValue == bNewValue )
293 return;
294
295 if( bNewValue )
296 {
297 rtl::OUString aTitleText;
298 TitleHelper::createTitle( m_eTitleType, aTitleText
299 , m_spChart2ModelContact->getChartModel(), m_spChart2ModelContact->m_xContext );
300 }
301 else
302 {
303 TitleHelper::removeTitle( m_eTitleType, m_spChart2ModelContact->getChartModel() );
304 }
305 }
306
getPropertyValue(const Reference<beans::XPropertySet> &) const307 Any WrappedAxisTitleExistenceProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
308 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
309 {
310 sal_Bool bHasTitle = sal_False;
311
312 Reference< chart2::XTitle > xTitle( TitleHelper::getTitle( m_eTitleType, m_spChart2ModelContact->getChartModel() ) );
313 if( xTitle.is() && (TitleHelper::getCompleteString( xTitle ).isEmpty() == false) )
314 bHasTitle = sal_True;
315
316 Any aRet;
317 aRet <<= bHasTitle;
318 return aRet;
319
320 }
321
getPropertyDefault(const Reference<beans::XPropertyState> &) const322 Any WrappedAxisTitleExistenceProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
323 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
324 {
325 Any aRet;
326 aRet <<= sal_Bool( sal_False );
327 return aRet;
328 }
329
330 //---------------------------------------------------------------------------------------------------------------
331 //---------------------------------------------------------------------------------------------------------------
332 //---------------------------------------------------------------------------------------------------------------
333
334 class WrappedAxisLabelExistenceProperty : public WrappedProperty
335 {
336 public:
337 WrappedAxisLabelExistenceProperty( bool bMain, sal_Int32 nDimensionIndex
338 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
339 virtual ~WrappedAxisLabelExistenceProperty();
340
341 virtual void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
342 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
343
344 virtual ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
345 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
346
347 virtual ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& xInnerPropertyState ) const
348 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
349
350 private: //member
351 ::boost::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
352 bool m_bMain;
353 sal_Int32 m_nDimensionIndex;
354 };
355
addWrappedProperties(std::vector<WrappedProperty * > & rList,::boost::shared_ptr<Chart2ModelContact> spChart2ModelContact)356 void WrappedAxisLabelExistenceProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList
357 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
358 {
359 rList.push_back( new WrappedAxisLabelExistenceProperty( true, 0, spChart2ModelContact ) );//x axis
360 rList.push_back( new WrappedAxisLabelExistenceProperty( true, 1, spChart2ModelContact ) );//y axis
361 rList.push_back( new WrappedAxisLabelExistenceProperty( true, 2, spChart2ModelContact ) );//z axis
362 rList.push_back( new WrappedAxisLabelExistenceProperty( false, 0, spChart2ModelContact ) );//secondary x axis
363 rList.push_back( new WrappedAxisLabelExistenceProperty( false, 1, spChart2ModelContact ) );//secondary y axis
364 }
365
WrappedAxisLabelExistenceProperty(bool bMain,sal_Int32 nDimensionIndex,::boost::shared_ptr<Chart2ModelContact> spChart2ModelContact)366 WrappedAxisLabelExistenceProperty::WrappedAxisLabelExistenceProperty( bool bMain, sal_Int32 nDimensionIndex
367 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
368 : WrappedProperty(OUString(),OUString())
369 , m_spChart2ModelContact( spChart2ModelContact )
370 , m_bMain( bMain )
371 , m_nDimensionIndex( nDimensionIndex )
372 {
373 switch( m_nDimensionIndex )
374 {
375 case 0:
376 m_aOuterName = m_bMain ? C2U( "HasXAxisDescription" ) : C2U( "HasSecondaryXAxisDescription" );
377 break;
378 case 2:
379 OSL_ENSURE(m_bMain,"there is no description available for a secondary z axis");
380 m_aOuterName = C2U( "HasZAxisDescription" );
381 break;
382 default:
383 m_aOuterName = m_bMain ? C2U( "HasYAxisDescription" ) : C2U( "HasSecondaryYAxisDescription" );
384 break;
385 }
386 }
387
~WrappedAxisLabelExistenceProperty()388 WrappedAxisLabelExistenceProperty::~WrappedAxisLabelExistenceProperty()
389 {
390 }
391
setPropertyValue(const Any & rOuterValue,const Reference<beans::XPropertySet> & xInnerPropertySet) const392 void WrappedAxisLabelExistenceProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
393 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
394 {
395 sal_Bool bNewValue = false;
396 if( ! (rOuterValue >>= bNewValue) )
397 throw lang::IllegalArgumentException( C2U("Has axis or grid properties require boolean values"), 0, 0 );
398
399 sal_Bool bOldValue = sal_False;
400 getPropertyValue( xInnerPropertySet ) >>= bOldValue;
401
402 if( bOldValue == bNewValue )
403 return;
404
405 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
406 Reference< beans::XPropertySet > xProp( AxisHelper::getAxis( m_nDimensionIndex, m_bMain, xDiagram ), uno::UNO_QUERY );
407 if( !xProp.is() && bNewValue )
408 {
409 //create axis if needed
410 xProp.set( AxisHelper::createAxis( m_nDimensionIndex, m_bMain, xDiagram, m_spChart2ModelContact->m_xContext ), uno::UNO_QUERY );
411 if( xProp.is() )
412 xProp->setPropertyValue( C2U( "Show" ), uno::makeAny( sal_False ) );
413 }
414 if( xProp.is() )
415 xProp->setPropertyValue( C2U( "DisplayLabels" ), rOuterValue );
416 }
417
getPropertyValue(const Reference<beans::XPropertySet> &) const418 Any WrappedAxisLabelExistenceProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
419 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
420 {
421 Any aRet;
422 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
423 Reference< beans::XPropertySet > xProp( AxisHelper::getAxis( m_nDimensionIndex, m_bMain, xDiagram ), uno::UNO_QUERY );
424 if( xProp.is() )
425 aRet = xProp->getPropertyValue( C2U( "DisplayLabels" ));
426 else
427 aRet <<= sal_False;
428 return aRet;
429 }
430
getPropertyDefault(const Reference<beans::XPropertyState> &) const431 Any WrappedAxisLabelExistenceProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
432 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
433 {
434 Any aRet;
435 aRet <<= sal_Bool( sal_True );
436 return aRet;
437 }
438
439 } //namespace wrapper
440 } //namespace chart
441 //.............................................................................
442