xref: /aoo4110/main/chart2/source/model/main/Axis.cxx (revision b1cdbd2c)
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 #include "Axis.hxx"
27 #include "GridProperties.hxx"
28 #include "macros.hxx"
29 #include "CharacterProperties.hxx"
30 #include "LineProperties.hxx"
31 #include "UserDefinedProperties.hxx"
32 #include "PropertyHelper.hxx"
33 #include "ContainerHelper.hxx"
34 #include "CloneHelper.hxx"
35 #include "AxisHelper.hxx"
36 #include "EventListenerHelper.hxx"
37 #include <com/sun/star/chart/ChartAxisArrangeOrderType.hpp>
38 #include <com/sun/star/chart/ChartAxisLabelPosition.hpp>
39 #include <com/sun/star/chart/ChartAxisMarkPosition.hpp>
40 #include <com/sun/star/chart/ChartAxisPosition.hpp>
41 #include <com/sun/star/chart2/AxisType.hpp>
42 #include <com/sun/star/beans/PropertyAttribute.hpp>
43 #include <com/sun/star/lang/Locale.hpp>
44 #include <com/sun/star/drawing/LineStyle.hpp>
45 #include <com/sun/star/drawing/LineDash.hpp>
46 #include <com/sun/star/drawing/LineJoint.hpp>
47 #include <com/sun/star/awt/Size.hpp>
48 #include <rtl/uuid.h>
49 #include <cppuhelper/queryinterface.hxx>
50 
51 #include <vector>
52 #include <algorithm>
53 
54 using namespace ::com::sun::star;
55 using namespace ::com::sun::star::beans::PropertyAttribute;
56 
57 using ::rtl::OUString;
58 using ::com::sun::star::uno::Sequence;
59 using ::com::sun::star::uno::Reference;
60 using ::com::sun::star::uno::Any;
61 using ::com::sun::star::beans::Property;
62 using ::osl::MutexGuard;
63 
64 namespace
65 {
66 
67 static const OUString lcl_aServiceName(
68     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.Axis" ));
69 
70 enum
71 {
72     PROP_AXIS_SHOW,
73     PROP_AXIS_CROSSOVER_POSITION,
74     PROP_AXIS_CROSSOVER_VALUE,
75     PROP_AXIS_DISPLAY_LABELS,
76     PROP_AXIS_NUMBER_FORMAT,
77     PROP_AXIS_LABEL_POSITION,
78     PROP_AXIS_TEXT_ROTATION,
79     PROP_AXIS_TEXT_BREAK,
80     PROP_AXIS_TEXT_OVERLAP,
81     PROP_AXIS_TEXT_STACKED,
82     PROP_AXIS_TEXT_ARRANGE_ORDER,
83     PROP_AXIS_REFERENCE_DIAGRAM_SIZE,
84 
85     PROP_AXIS_MAJOR_TICKMARKS,
86     PROP_AXIS_MINOR_TICKMARKS,
87     PROP_AXIS_MARK_POSITION
88 };
89 
lcl_AddPropertiesToVector(::std::vector<Property> & rOutProperties)90 void lcl_AddPropertiesToVector(
91     ::std::vector< Property > & rOutProperties )
92 {
93     rOutProperties.push_back(
94         Property( C2U( "Show" ),
95                   PROP_AXIS_SHOW,
96                   ::getBooleanCppuType(),
97                   beans::PropertyAttribute::BOUND
98                   | beans::PropertyAttribute::MAYBEDEFAULT ));
99 
100     rOutProperties.push_back(
101         Property( C2U( "CrossoverPosition" ),
102                   PROP_AXIS_CROSSOVER_POSITION,
103                   ::getCppuType( reinterpret_cast< const ::com::sun::star::chart::ChartAxisPosition * >(0)),
104                   beans::PropertyAttribute::MAYBEDEFAULT ));
105 
106     rOutProperties.push_back(
107         Property( C2U( "CrossoverValue" ),
108                   PROP_AXIS_CROSSOVER_VALUE,
109                   ::getCppuType( reinterpret_cast< const double * >(0)),
110                   beans::PropertyAttribute::MAYBEVOID ));
111 
112     rOutProperties.push_back(
113         Property( C2U( "DisplayLabels" ),
114                   PROP_AXIS_DISPLAY_LABELS,
115                   ::getBooleanCppuType(),
116                   beans::PropertyAttribute::BOUND
117                   | beans::PropertyAttribute::MAYBEDEFAULT ));
118 
119     rOutProperties.push_back(
120         Property( C2U( "NumberFormat" ),
121                   PROP_AXIS_NUMBER_FORMAT,
122                   ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
123                   beans::PropertyAttribute::BOUND
124                   | beans::PropertyAttribute::MAYBEVOID ));
125 
126     rOutProperties.push_back(
127         Property( C2U( "LabelPosition" ),
128                   PROP_AXIS_LABEL_POSITION,
129                   ::getCppuType( reinterpret_cast< const ::com::sun::star::chart::ChartAxisLabelPosition * >(0)),
130                   beans::PropertyAttribute::MAYBEDEFAULT ));
131 
132     rOutProperties.push_back(
133         Property( C2U( "TextRotation" ),
134                   PROP_AXIS_TEXT_ROTATION,
135                   ::getCppuType( reinterpret_cast< const double * >(0)),
136                   beans::PropertyAttribute::BOUND
137                   | beans::PropertyAttribute::MAYBEDEFAULT ));
138 
139     rOutProperties.push_back(
140         Property( C2U( "TextBreak" ),
141                   PROP_AXIS_TEXT_BREAK,
142                   ::getBooleanCppuType(),
143                   beans::PropertyAttribute::BOUND
144                   | beans::PropertyAttribute::MAYBEDEFAULT ));
145 
146     rOutProperties.push_back(
147         Property( C2U( "TextOverlap" ),
148                   PROP_AXIS_TEXT_OVERLAP,
149                   ::getBooleanCppuType(),
150                   beans::PropertyAttribute::BOUND
151                   | beans::PropertyAttribute::MAYBEDEFAULT ));
152 
153     rOutProperties.push_back(
154         Property( C2U( "StackCharacters" ),
155                   PROP_AXIS_TEXT_STACKED,
156                   ::getBooleanCppuType(),
157                   beans::PropertyAttribute::BOUND
158                   | beans::PropertyAttribute::MAYBEDEFAULT ));
159 
160     rOutProperties.push_back(
161         Property( C2U( "ArrangeOrder" ),
162                   PROP_AXIS_TEXT_ARRANGE_ORDER,
163                   ::getCppuType( reinterpret_cast< const ::com::sun::star::chart::ChartAxisArrangeOrderType * >(0)),
164                   beans::PropertyAttribute::BOUND
165                   | beans::PropertyAttribute::MAYBEDEFAULT ));
166 
167     rOutProperties.push_back(
168         Property( C2U( "ReferencePageSize" ),
169                   PROP_AXIS_REFERENCE_DIAGRAM_SIZE,
170                   ::getCppuType( reinterpret_cast< const awt::Size * >(0)),
171                   beans::PropertyAttribute::BOUND
172                   | beans::PropertyAttribute::MAYBEVOID ));
173 
174     rOutProperties.push_back(
175         Property( C2U( "MajorTickmarks" ),
176                   PROP_AXIS_MAJOR_TICKMARKS,
177                   ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
178                   beans::PropertyAttribute::BOUND
179                   | beans::PropertyAttribute::MAYBEDEFAULT ));
180     rOutProperties.push_back(
181         Property( C2U( "MinorTickmarks" ),
182                   PROP_AXIS_MINOR_TICKMARKS,
183                   ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
184                   beans::PropertyAttribute::BOUND
185                   | beans::PropertyAttribute::MAYBEDEFAULT ));
186     rOutProperties.push_back(
187         Property( C2U( "MarkPosition" ),
188                   PROP_AXIS_MARK_POSITION,
189                   ::getCppuType( reinterpret_cast< const ::com::sun::star::chart::ChartAxisMarkPosition * >(0)),
190                   beans::PropertyAttribute::MAYBEDEFAULT ));
191 }
192 
193 struct StaticAxisDefaults_Initializer
194 {
operator ()__anon4b1e4c1c0111::StaticAxisDefaults_Initializer195     ::chart::tPropertyValueMap* operator()()
196     {
197         static ::chart::tPropertyValueMap aStaticDefaults;
198         lcl_AddDefaultsToMap( aStaticDefaults );
199         return &aStaticDefaults;
200     }
201 private:
lcl_AddDefaultsToMap__anon4b1e4c1c0111::StaticAxisDefaults_Initializer202     void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
203     {
204         ::chart::CharacterProperties::AddDefaultsToMap( rOutMap );
205         ::chart::LineProperties::AddDefaultsToMap( rOutMap );
206 
207         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_AXIS_SHOW, true );
208         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_AXIS_CROSSOVER_POSITION, ::com::sun::star::chart::ChartAxisPosition_ZERO );
209         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_AXIS_DISPLAY_LABELS, true );
210         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_AXIS_LABEL_POSITION, ::com::sun::star::chart::ChartAxisLabelPosition_NEAR_AXIS );
211         ::chart::PropertyHelper::setPropertyValueDefault< double >( rOutMap, PROP_AXIS_TEXT_ROTATION, 0.0 );
212         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_AXIS_TEXT_BREAK, false );
213         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_AXIS_TEXT_OVERLAP, false );
214         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_AXIS_TEXT_STACKED, false );
215         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_AXIS_TEXT_ARRANGE_ORDER, ::com::sun::star::chart::ChartAxisArrangeOrderType_AUTO );
216 
217         float fDefaultCharHeight = 10.0;
218         ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_CHAR_HEIGHT, fDefaultCharHeight );
219         ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_ASIAN_CHAR_HEIGHT, fDefaultCharHeight );
220         ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_COMPLEX_CHAR_HEIGHT, fDefaultCharHeight );
221 
222         ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_AXIS_MAJOR_TICKMARKS, 2 /* CHAXIS_MARK_OUTER */ );
223         ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_AXIS_MINOR_TICKMARKS, 0 /* CHAXIS_MARK_NONE */ );
224         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_AXIS_MARK_POSITION, ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS_AND_AXIS );
225     }
226 };
227 
228 struct StaticAxisDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticAxisDefaults_Initializer >
229 {
230 };
231 
232 struct StaticAxisInfoHelper_Initializer
233 {
operator ()__anon4b1e4c1c0111::StaticAxisInfoHelper_Initializer234     ::cppu::OPropertyArrayHelper* operator()()
235     {
236         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
237         return &aPropHelper;
238     }
239 
240 private:
lcl_GetPropertySequence__anon4b1e4c1c0111::StaticAxisInfoHelper_Initializer241     Sequence< Property > lcl_GetPropertySequence()
242     {
243         ::std::vector< ::com::sun::star::beans::Property > aProperties;
244         lcl_AddPropertiesToVector( aProperties );
245         ::chart::CharacterProperties::AddPropertiesToVector( aProperties );
246         ::chart::LineProperties::AddPropertiesToVector( aProperties );
247         ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
248 
249         ::std::sort( aProperties.begin(), aProperties.end(),
250                      ::chart::PropertyNameLess() );
251 
252         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
253     }
254 };
255 
256 struct StaticAxisInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticAxisInfoHelper_Initializer >
257 {
258 };
259 
260 struct StaticAxisInfo_Initializer
261 {
operator ()__anon4b1e4c1c0111::StaticAxisInfo_Initializer262     uno::Reference< beans::XPropertySetInfo >* operator()()
263     {
264         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
265             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticAxisInfoHelper::get() ) );
266         return &xPropertySetInfo;
267     }
268 };
269 
270 struct StaticAxisInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticAxisInfo_Initializer >
271 {
272 };
273 
274 typedef uno::Reference< beans::XPropertySet > lcl_tSubGridType;
275 typedef uno::Sequence< lcl_tSubGridType >     lcl_tSubGridSeq;
276 
lcl_CloneSubGrids(const lcl_tSubGridSeq & rSource,lcl_tSubGridSeq & rDestination)277 void lcl_CloneSubGrids(
278     const lcl_tSubGridSeq & rSource, lcl_tSubGridSeq & rDestination )
279 {
280     const lcl_tSubGridType * pBegin = rSource.getConstArray();
281     const lcl_tSubGridType * pEnd = pBegin + rSource.getLength();
282 
283     rDestination.realloc( rSource.getLength());
284     lcl_tSubGridType * pDestBegin = rDestination.getArray();
285     lcl_tSubGridType * pDestEnd   = pDestBegin + rDestination.getLength();
286     lcl_tSubGridType * pDestIt    = pDestBegin;
287 
288     for( const lcl_tSubGridType * pIt = pBegin; pIt != pEnd; ++pIt )
289     {
290         Reference< beans::XPropertySet > xSubGrid( *pIt );
291         if( xSubGrid.is())
292         {
293             Reference< util::XCloneable > xCloneable( xSubGrid, uno::UNO_QUERY );
294             if( xCloneable.is())
295                 xSubGrid.set( xCloneable->createClone(), uno::UNO_QUERY );
296         }
297 
298         (*pDestIt) = xSubGrid;
299         OSL_ASSERT( pDestIt != pDestEnd );
300         ++pDestIt;
301     }
302     OSL_ASSERT( pDestIt == pDestEnd );
303     (void)(pDestEnd); // avoid warning
304 }
305 
306 } // anonymous namespace
307 
308 // ================================================================================
309 
310 namespace chart
311 {
312 
Axis(Reference<uno::XComponentContext> const &)313 Axis::Axis( Reference< uno::XComponentContext > const & /* xContext */ ) :
314         ::property::OPropertySet( m_aMutex ),
315         m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
316         m_aScaleData( AxisHelper::createDefaultScale() ),
317         m_xGrid( new GridProperties() ),
318         m_aSubGridProperties(),
319         m_xTitle()
320 {
321     osl_incrementInterlockedCount(&m_refCount);
322     setFastPropertyValue_NoBroadcast(
323         ::chart::LineProperties::PROP_LINE_COLOR, uno::makeAny( static_cast< sal_Int32 >( 0xb3b3b3 ) ) );  // gray30
324 
325     if( m_xGrid.is())
326         ModifyListenerHelper::addListener( m_xGrid, m_xModifyEventForwarder );
327     if( m_aScaleData.Categories.is())
328         ModifyListenerHelper::addListener( m_aScaleData.Categories, m_xModifyEventForwarder );
329 
330     AllocateSubGrids();
331     osl_decrementInterlockedCount(&m_refCount);
332 }
333 
Axis(const Axis & rOther)334 Axis::Axis( const Axis & rOther ) :
335         MutexContainer(),
336         impl::Axis_Base(),
337         ::property::OPropertySet( rOther, m_aMutex ),
338     m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
339     m_aScaleData( rOther.m_aScaleData )
340 {
341     m_xGrid.set( CloneHelper::CreateRefClone< Reference< beans::XPropertySet > >()( rOther.m_xGrid ));
342     if( m_xGrid.is())
343         ModifyListenerHelper::addListener( m_xGrid, m_xModifyEventForwarder );
344 
345     if( m_aScaleData.Categories.is())
346         ModifyListenerHelper::addListener( m_aScaleData.Categories, m_xModifyEventForwarder );
347 
348     if( rOther.m_aSubGridProperties.getLength() != 0 )
349         lcl_CloneSubGrids( rOther.m_aSubGridProperties, m_aSubGridProperties );
350     ModifyListenerHelper::addListenerToAllSequenceElements( m_aSubGridProperties, m_xModifyEventForwarder );
351 
352     m_xTitle.set( CloneHelper::CreateRefClone< Reference< chart2::XTitle > >()( rOther.m_xTitle ));
353     if( m_xTitle.is())
354         ModifyListenerHelper::addListener( m_xTitle, m_xModifyEventForwarder );
355 }
356 
357 // late initialization to call after copy-constructing
Init(const Axis &)358 void Axis::Init( const Axis & /* rOther */ )
359 {
360     if( m_aScaleData.Categories.is())
361         EventListenerHelper::addListener( m_aScaleData.Categories, this );
362 }
363 
~Axis()364 Axis::~Axis()
365 {
366     try
367     {
368         ModifyListenerHelper::removeListener( m_xGrid, m_xModifyEventForwarder );
369         ModifyListenerHelper::removeListenerFromAllSequenceElements( m_aSubGridProperties, m_xModifyEventForwarder );
370         ModifyListenerHelper::removeListener( m_xTitle, m_xModifyEventForwarder );
371         if( m_aScaleData.Categories.is())
372         {
373             ModifyListenerHelper::removeListener( m_aScaleData.Categories, m_xModifyEventForwarder );
374             m_aScaleData.Categories.set(0);
375         }
376     }
377     catch( const uno::Exception & ex )
378     {
379         ASSERT_EXCEPTION( ex );
380     }
381 
382     m_aSubGridProperties.realloc(0);
383     m_xGrid = 0;
384     m_xTitle = 0;
385 }
386 
AllocateSubGrids()387 void Axis::AllocateSubGrids()
388 {
389     Reference< util::XModifyListener > xModifyEventForwarder;
390     Reference< lang::XEventListener > xEventListener;
391     std::vector< Reference< beans::XPropertySet > > aOldBroadcasters;
392     std::vector< Reference< beans::XPropertySet > > aNewBroadcasters;
393     {
394         MutexGuard aGuard( m_aMutex );
395         xModifyEventForwarder = m_xModifyEventForwarder;
396         xEventListener = this;
397 
398         sal_Int32 nNewSubIncCount = m_aScaleData.IncrementData.SubIncrements.getLength();
399         sal_Int32 nOldSubIncCount = m_aSubGridProperties.getLength();
400 
401         if( nOldSubIncCount > nNewSubIncCount )
402         {
403             // remove superfluous entries
404             for( sal_Int32 i = nNewSubIncCount; i < nOldSubIncCount; ++i )
405                 aOldBroadcasters.push_back( m_aSubGridProperties[ i ] );
406             m_aSubGridProperties.realloc( nNewSubIncCount );
407         }
408         else if( nOldSubIncCount < nNewSubIncCount )
409         {
410             m_aSubGridProperties.realloc( nNewSubIncCount );
411 
412             // allocate new entries
413             for( sal_Int32 i = nOldSubIncCount; i < nNewSubIncCount; ++i )
414             {
415                 m_aSubGridProperties[ i ] = new GridProperties();
416                 LineProperties::SetLineInvisible( m_aSubGridProperties[ i ] );
417                 aNewBroadcasters.push_back( m_aSubGridProperties[ i ] );
418             }
419         }
420     }
421     //don't keep the mutex locked while calling out
422     std::vector< Reference< beans::XPropertySet > >::iterator aBroadcaster = aOldBroadcasters.begin();
423     for( ;aBroadcaster != aOldBroadcasters.end(); ++aBroadcaster )
424         ModifyListenerHelper::removeListener( *aBroadcaster, xModifyEventForwarder );
425     for( aBroadcaster = aNewBroadcasters.begin(); aBroadcaster != aNewBroadcasters.end(); ++aBroadcaster )
426         ModifyListenerHelper::addListener( *aBroadcaster, xModifyEventForwarder );
427 }
428 
429 // --------------------------------------------------------------------------------
430 
431 // ____ XAxis ____
setScaleData(const chart2::ScaleData & rScaleData)432 void SAL_CALL Axis::setScaleData( const chart2::ScaleData& rScaleData )
433     throw (uno::RuntimeException)
434 {
435     Reference< util::XModifyListener > xModifyEventForwarder;
436     Reference< lang::XEventListener > xEventListener;
437     Reference< chart2::data::XLabeledDataSequence > xOldCategories;
438     Reference< chart2::data::XLabeledDataSequence > xNewCategories = rScaleData.Categories;
439     {
440         MutexGuard aGuard( m_aMutex );
441         xModifyEventForwarder = m_xModifyEventForwarder;
442         xEventListener = this;
443         xOldCategories = m_aScaleData.Categories;
444         m_aScaleData = rScaleData;
445     }
446     AllocateSubGrids();
447 
448     //don't keep the mutex locked while calling out
449     if( xOldCategories.is() && xOldCategories != xNewCategories )
450     {
451         ModifyListenerHelper::removeListener( xOldCategories, xModifyEventForwarder );
452         EventListenerHelper::removeListener( xOldCategories, xEventListener );
453     }
454     if( xNewCategories.is() && xOldCategories != xNewCategories )
455     {
456         ModifyListenerHelper::addListener( xNewCategories, m_xModifyEventForwarder );
457         EventListenerHelper::addListener( xNewCategories, xEventListener );
458     }
459     fireModifyEvent();
460 }
461 
getScaleData()462 chart2::ScaleData SAL_CALL Axis::getScaleData()
463     throw (uno::RuntimeException)
464 {
465     // /--
466     MutexGuard aGuard( m_aMutex );
467     return m_aScaleData;
468     // \--
469 }
470 
getGridProperties()471 Reference< beans::XPropertySet > SAL_CALL Axis::getGridProperties()
472     throw (uno::RuntimeException)
473 {
474     // /--
475     MutexGuard aGuard( m_aMutex );
476     return m_xGrid;
477     // \--
478 }
getSubGridProperties()479 Sequence< Reference< beans::XPropertySet > > SAL_CALL Axis::getSubGridProperties()
480     throw (uno::RuntimeException)
481 {
482     // /--
483     MutexGuard aGuard( m_aMutex );
484     return m_aSubGridProperties;
485     // \--
486 }
487 
getSubTickProperties()488 Sequence< Reference< beans::XPropertySet > > SAL_CALL Axis::getSubTickProperties()
489     throw (uno::RuntimeException)
490 {
491     OSL_ENSURE( false, "Not implemented yet" );
492     return Sequence< Reference< beans::XPropertySet > >();
493 }
494 
495 
496 // ____ XTitled ____
getTitleObject()497 Reference< chart2::XTitle > SAL_CALL Axis::getTitleObject()
498     throw (uno::RuntimeException)
499 {
500     // /--
501     MutexGuard aGuard( GetMutex() );
502     return m_xTitle;
503     // \--
504 }
505 
setTitleObject(const Reference<chart2::XTitle> & xNewTitle)506 void SAL_CALL Axis::setTitleObject( const Reference< chart2::XTitle >& xNewTitle )
507     throw (uno::RuntimeException)
508 {
509     Reference< util::XModifyListener > xModifyEventForwarder;
510     Reference< chart2::XTitle > xOldTitle;
511     {
512         MutexGuard aGuard( GetMutex() );
513         xOldTitle = m_xTitle;
514         xModifyEventForwarder = m_xModifyEventForwarder;
515         m_xTitle = xNewTitle;
516     }
517 
518     //don't keep the mutex locked while calling out
519     if( xOldTitle.is() && xOldTitle != xNewTitle )
520         ModifyListenerHelper::removeListener( xOldTitle, xModifyEventForwarder );
521     if( xNewTitle.is() && xOldTitle != xNewTitle )
522         ModifyListenerHelper::addListener( xNewTitle, xModifyEventForwarder );
523     fireModifyEvent();
524 }
525 
526 // ____ XCloneable ____
createClone()527 Reference< util::XCloneable > SAL_CALL Axis::createClone()
528     throw (uno::RuntimeException)
529 {
530     Axis * pNewAxis( new Axis( *this ));
531     // hold a reference to the clone
532     Reference< util::XCloneable > xResult( pNewAxis );
533     // do initialization that uses uno references to the clone
534     pNewAxis->Init( *this );
535     return xResult;
536 }
537 
538 // ____ XModifyBroadcaster ____
addModifyListener(const Reference<util::XModifyListener> & aListener)539 void SAL_CALL Axis::addModifyListener( const Reference< util::XModifyListener >& aListener )
540     throw (uno::RuntimeException)
541 {
542     try
543     {
544         Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
545         xBroadcaster->addModifyListener( aListener );
546     }
547     catch( const uno::Exception & ex )
548     {
549         ASSERT_EXCEPTION( ex );
550     }
551 }
552 
removeModifyListener(const Reference<util::XModifyListener> & aListener)553 void SAL_CALL Axis::removeModifyListener( const Reference< util::XModifyListener >& aListener )
554     throw (uno::RuntimeException)
555 {
556     try
557     {
558         Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
559         xBroadcaster->removeModifyListener( aListener );
560     }
561     catch( const uno::Exception & ex )
562     {
563         ASSERT_EXCEPTION( ex );
564     }
565 }
566 
567 // ____ XModifyListener ____
modified(const lang::EventObject & aEvent)568 void SAL_CALL Axis::modified( const lang::EventObject& aEvent )
569     throw (uno::RuntimeException)
570 {
571     m_xModifyEventForwarder->modified( aEvent );
572 }
573 
574 // ____ XEventListener (base of XModifyListener) ____
disposing(const lang::EventObject & Source)575 void SAL_CALL Axis::disposing( const lang::EventObject& Source )
576     throw (uno::RuntimeException)
577 {
578     if( Source.Source == m_aScaleData.Categories )
579         m_aScaleData.Categories = 0;
580 }
581 
582 // ____ OPropertySet ____
firePropertyChangeEvent()583 void Axis::firePropertyChangeEvent()
584 {
585     fireModifyEvent();
586 }
587 
fireModifyEvent()588 void Axis::fireModifyEvent()
589 {
590     m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
591 }
592 
593 // ================================================================================
594 
595 // ____ OPropertySet ____
GetDefaultValue(sal_Int32 nHandle) const596 uno::Any Axis::GetDefaultValue( sal_Int32 nHandle ) const
597     throw(beans::UnknownPropertyException)
598 {
599     const tPropertyValueMap& rStaticDefaults = *StaticAxisDefaults::get();
600     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
601     if( aFound == rStaticDefaults.end() )
602         return uno::Any();
603     return (*aFound).second;
604 }
605 
getInfoHelper()606 ::cppu::IPropertyArrayHelper & SAL_CALL Axis::getInfoHelper()
607 {
608     return *StaticAxisInfoHelper::get();
609 }
610 
611 // ____ XPropertySet ____
getPropertySetInfo()612 Reference< beans::XPropertySetInfo > SAL_CALL Axis::getPropertySetInfo()
613     throw (uno::RuntimeException)
614 {
615     return *StaticAxisInfo::get();
616 }
617 
618 // ================================================================================
619 
getSupportedServiceNames_Static()620 Sequence< OUString > Axis::getSupportedServiceNames_Static()
621 {
622     Sequence< OUString > aServices( 2 );
623     aServices[ 0 ] = C2U( "com.sun.star.chart2.Axis" );
624     aServices[ 1 ] = C2U( "com.sun.star.beans.PropertySet" );
625     return aServices;
626 }
627 
628 using impl::Axis_Base;
629 
630 IMPLEMENT_FORWARD_XINTERFACE2( Axis, Axis_Base, ::property::OPropertySet )
631 IMPLEMENT_FORWARD_XTYPEPROVIDER2( Axis, Axis_Base, ::property::OPropertySet )
632 
633 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
634 APPHELPER_XSERVICEINFO_IMPL( Axis, lcl_aServiceName );
635 
636 } //  namespace chart
637