1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AxisWrapper.cxx,v $
10 * $Revision: 1.11.8.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
33 #include "AxisWrapper.hxx"
34 #include "AxisHelper.hxx"
35 #include "Chart2ModelContact.hxx"
36 #include "ContainerHelper.hxx"
38 #include "WrappedDirectStateProperty.hxx"
39 #include <comphelper/InlineContainer.hxx>
40 #include <com/sun/star/beans/PropertyAttribute.hpp>
41 #include <com/sun/star/chart/ChartAxisArrangeOrderType.hpp>
42 #include <com/sun/star/chart/ChartAxisPosition.hpp>
43 #include <com/sun/star/chart/ChartAxisLabelPosition.hpp>
44 #include <com/sun/star/chart/ChartAxisMarkPosition.hpp>
46 #include "CharacterProperties.hxx"
47 #include "LineProperties.hxx"
48 #include "UserDefinedProperties.hxx"
49 #include "WrappedCharacterHeightProperty.hxx"
50 #include "WrappedTextRotationProperty.hxx"
51 #include "WrappedGapwidthProperty.hxx"
52 #include "WrappedScaleProperty.hxx"
53 #include "WrappedDefaultProperty.hxx"
54 #include "WrappedNumberFormatProperty.hxx"
55 #include "WrappedScaleTextProperties.hxx"
58 #include <rtl/ustrbuf.hxx>
59 #include <rtl/math.hxx>
61 using namespace ::com::sun::star
;
62 using namespace ::com::sun::star::chart2
;
63 using namespace ::chart::ContainerHelper
;
65 using ::com::sun::star::beans::Property
;
66 using ::osl::MutexGuard
;
67 using ::com::sun::star::uno::Reference
;
68 using ::com::sun::star::uno::Sequence
;
69 using ::com::sun::star::uno::Any
;
70 using ::rtl::OUString
;
74 static const OUString
lcl_aServiceName(
75 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart.Axis" ));
82 PROP_AXIS_STEPHELP
, //deprecated property use 'StepHelpCount' instead
83 PROP_AXIS_STEPHELP_COUNT
,
86 PROP_AXIS_AUTO_STEPMAIN
,
87 PROP_AXIS_AUTO_STEPHELP
,
88 PROP_AXIS_LOGARITHMIC
,
89 PROP_AXIS_REVERSEDIRECTION
,
91 PROP_AXIS_CROSSOVER_POSITION
,
92 PROP_AXIS_CROSSOVER_VALUE
,
94 PROP_AXIS_AUTO_ORIGIN
,
97 PROP_AXIS_MARK_POSITION
,
98 PROP_AXIS_DISPLAY_LABELS
,
99 PROP_AXIS_NUMBERFORMAT
,
100 PROP_AXIS_LINK_NUMBERFORMAT_TO_SOURCE
,
101 PROP_AXIS_LABEL_POSITION
,
102 PROP_AXIS_TEXT_ROTATION
,
103 PROP_AXIS_ARRANGE_ORDER
,
105 PROP_AXIS_CAN_OVERLAP
,
106 PROP_AXIS_STACKEDTEXT
,
111 void lcl_AddPropertiesToVector(
112 ::std::vector
< Property
> & rOutProperties
)
114 //Properties for scaling:
115 rOutProperties
.push_back(
116 Property( C2U( "Max" ),
118 ::getCppuType( reinterpret_cast< const double * >(0)),
119 beans::PropertyAttribute::BOUND
120 | beans::PropertyAttribute::MAYBEVOID
));
122 rOutProperties
.push_back(
123 Property( C2U( "Min" ),
125 ::getCppuType( reinterpret_cast< const double * >(0)),
126 beans::PropertyAttribute::BOUND
127 | beans::PropertyAttribute::MAYBEVOID
));
129 rOutProperties
.push_back(
130 Property( C2U( "StepMain" ),
132 ::getCppuType( reinterpret_cast< const double * >(0)),
133 beans::PropertyAttribute::BOUND
134 | beans::PropertyAttribute::MAYBEVOID
));
136 rOutProperties
.push_back(
137 Property( C2U( "StepHelpCount" ),
138 PROP_AXIS_STEPHELP_COUNT
,
139 ::getCppuType( reinterpret_cast< const sal_Int32
* >(0)),
140 beans::PropertyAttribute::BOUND
141 | beans::PropertyAttribute::MAYBEVOID
));
143 //deprecated property use 'StepHelpCount' instead
144 rOutProperties
.push_back(
145 Property( C2U( "StepHelp" ),
147 ::getCppuType( reinterpret_cast< const double * >(0)),
148 beans::PropertyAttribute::BOUND
149 | beans::PropertyAttribute::MAYBEVOID
));
151 rOutProperties
.push_back(
152 Property( C2U( "AutoMax" ),
154 ::getBooleanCppuType(),
155 beans::PropertyAttribute::BOUND
156 | beans::PropertyAttribute::MAYBEDEFAULT
));
158 rOutProperties
.push_back(
159 Property( C2U( "AutoMin" ),
161 ::getBooleanCppuType(),
162 beans::PropertyAttribute::BOUND
163 | beans::PropertyAttribute::MAYBEDEFAULT
));
165 rOutProperties
.push_back(
166 Property( C2U( "AutoStepMain" ),
167 PROP_AXIS_AUTO_STEPMAIN
,
168 ::getBooleanCppuType(),
169 beans::PropertyAttribute::BOUND
170 | beans::PropertyAttribute::MAYBEDEFAULT
));
172 rOutProperties
.push_back(
173 Property( C2U( "AutoStepHelp" ),
174 PROP_AXIS_AUTO_STEPHELP
,
175 ::getBooleanCppuType(),
176 beans::PropertyAttribute::BOUND
177 | beans::PropertyAttribute::MAYBEDEFAULT
));
179 rOutProperties
.push_back(
180 Property( C2U( "Logarithmic" ),
181 PROP_AXIS_LOGARITHMIC
,
182 ::getBooleanCppuType(),
183 beans::PropertyAttribute::BOUND
184 | beans::PropertyAttribute::MAYBEDEFAULT
));
186 rOutProperties
.push_back(
187 Property( C2U( "ReverseDirection" ),
188 PROP_AXIS_REVERSEDIRECTION
,
189 ::getBooleanCppuType(),
190 beans::PropertyAttribute::BOUND
191 | beans::PropertyAttribute::MAYBEDEFAULT
));
193 //todo: this property is missing in the API
194 rOutProperties
.push_back(
195 Property( C2U( "Visible" ),
197 ::getBooleanCppuType(),
198 beans::PropertyAttribute::BOUND
199 | beans::PropertyAttribute::MAYBEDEFAULT
));
201 rOutProperties
.push_back(
202 Property( C2U( "CrossoverPosition" ),
203 PROP_AXIS_CROSSOVER_POSITION
,
204 ::getCppuType( reinterpret_cast< const ::com::sun::star::chart::ChartAxisPosition
* >(0)),
205 beans::PropertyAttribute::MAYBEDEFAULT
));
207 rOutProperties
.push_back(
208 Property( C2U( "CrossoverValue" ),
209 PROP_AXIS_CROSSOVER_VALUE
,
210 ::getCppuType( reinterpret_cast< const double * >(0)),
211 beans::PropertyAttribute::MAYBEVOID
));
214 rOutProperties
.push_back(
215 Property( C2U( "Origin" ),
217 ::getCppuType( reinterpret_cast< const double * >(0)),
218 beans::PropertyAttribute::BOUND
219 | beans::PropertyAttribute::MAYBEVOID
));
221 rOutProperties
.push_back(
222 Property( C2U( "AutoOrigin" ),
223 PROP_AXIS_AUTO_ORIGIN
,
224 ::getBooleanCppuType(),
225 beans::PropertyAttribute::BOUND
226 | beans::PropertyAttribute::MAYBEDEFAULT
));
228 //Properties for interval marks:
229 rOutProperties
.push_back(
230 Property( C2U( "Marks" ),
232 ::getCppuType( reinterpret_cast< const sal_Int32
* >(0)),
233 beans::PropertyAttribute::BOUND
234 | beans::PropertyAttribute::MAYBEDEFAULT
));
236 rOutProperties
.push_back(
237 Property( C2U( "HelpMarks" ),
239 ::getCppuType( reinterpret_cast< const sal_Int32
* >(0)),
240 beans::PropertyAttribute::BOUND
241 | beans::PropertyAttribute::MAYBEDEFAULT
));
243 rOutProperties
.push_back(
244 Property( C2U( "MarkPosition" ),
245 PROP_AXIS_MARK_POSITION
,
246 ::getCppuType( reinterpret_cast< const ::com::sun::star::chart::ChartAxisMarkPosition
* >(0)),
247 beans::PropertyAttribute::MAYBEDEFAULT
));
250 //Properties for labels:
251 rOutProperties
.push_back(
252 Property( C2U( "DisplayLabels" ),
253 PROP_AXIS_DISPLAY_LABELS
,
254 ::getBooleanCppuType(),
255 beans::PropertyAttribute::BOUND
256 | beans::PropertyAttribute::MAYBEDEFAULT
));
258 rOutProperties
.push_back(
259 Property( C2U( "NumberFormat" ),
260 PROP_AXIS_NUMBERFORMAT
,
261 ::getCppuType( reinterpret_cast< const sal_Int32
* >(0)),
262 beans::PropertyAttribute::BOUND
263 | beans::PropertyAttribute::MAYBEDEFAULT
));
265 rOutProperties
.push_back(
266 Property( C2U( "LinkNumberFormatToSource" ),
267 PROP_AXIS_LINK_NUMBERFORMAT_TO_SOURCE
,
268 ::getBooleanCppuType(),
269 beans::PropertyAttribute::BOUND
270 | beans::PropertyAttribute::MAYBEDEFAULT
));
272 rOutProperties
.push_back(
273 Property( C2U( "LabelPosition" ),
274 PROP_AXIS_LABEL_POSITION
,
275 ::getCppuType( reinterpret_cast< const ::com::sun::star::chart::ChartAxisLabelPosition
* >(0)),
276 beans::PropertyAttribute::MAYBEDEFAULT
));
278 rOutProperties
.push_back(
279 Property( C2U( "TextRotation" ),
280 PROP_AXIS_TEXT_ROTATION
,
281 ::getCppuType( reinterpret_cast< const sal_Int32
* >(0)),
282 beans::PropertyAttribute::BOUND
283 | beans::PropertyAttribute::MAYBEDEFAULT
));
285 rOutProperties
.push_back(
286 Property( C2U( "ArrangeOrder" ),
287 PROP_AXIS_ARRANGE_ORDER
,
288 ::getCppuType( reinterpret_cast< const ::com::sun::star::chart::ChartAxisArrangeOrderType
* >(0)),
289 beans::PropertyAttribute::BOUND
290 | beans::PropertyAttribute::MAYBEDEFAULT
));
292 rOutProperties
.push_back(
293 Property( C2U( "TextBreak" ),
295 ::getBooleanCppuType(),
296 beans::PropertyAttribute::BOUND
297 | beans::PropertyAttribute::MAYBEDEFAULT
));
299 rOutProperties
.push_back(
300 Property( C2U( "TextCanOverlap" ),
301 PROP_AXIS_CAN_OVERLAP
,
302 ::getBooleanCppuType(),
303 beans::PropertyAttribute::BOUND
304 | beans::PropertyAttribute::MAYBEDEFAULT
));
306 rOutProperties
.push_back(
307 Property( C2U( "StackedText" ),
308 PROP_AXIS_STACKEDTEXT
,
309 ::getBooleanCppuType(),
310 beans::PropertyAttribute::BOUND
311 | beans::PropertyAttribute::MAYBEDEFAULT
));
313 // Properties related to bar charts:
314 rOutProperties
.push_back(
315 Property( C2U( "Overlap" ),
317 ::getCppuType( reinterpret_cast< const sal_Int32
* >(0)),
318 beans::PropertyAttribute::BOUND
319 | beans::PropertyAttribute::MAYBEDEFAULT
));
321 rOutProperties
.push_back(
322 Property( C2U( "GapWidth" ),
324 ::getCppuType( reinterpret_cast< const sal_Int32
* >(0)),
325 beans::PropertyAttribute::BOUND
326 | beans::PropertyAttribute::MAYBEDEFAULT
));
329 const Sequence
< Property
> & lcl_GetPropertySequence()
331 static Sequence
< Property
> aPropSeq
;
334 MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
335 if( 0 == aPropSeq
.getLength() )
338 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
339 lcl_AddPropertiesToVector( aProperties
);
340 ::chart::CharacterProperties::AddPropertiesToVector( aProperties
);
341 ::chart::LineProperties::AddPropertiesToVector( aProperties
);
342 // ::chart::NamedLineProperties::AddPropertiesToVector( aProperties );
343 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties
);
344 ::chart::wrapper::WrappedScaleTextProperties::addProperties( aProperties
);
346 // and sort them for access via bsearch
347 ::std::sort( aProperties
.begin(), aProperties
.end(),
348 ::chart::PropertyNameLess() );
350 // transfer result to static Sequence
351 aPropSeq
= ::chart::ContainerHelper::ContainerToSequence( aProperties
);
357 } // anonymous namespace
359 // --------------------------------------------------------------------------------
366 AxisWrapper::AxisWrapper(
367 tAxisType eType
, ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
) :
368 m_spChart2ModelContact( spChart2ModelContact
),
369 m_aEventListenerContainer( m_aMutex
),
374 AxisWrapper::~AxisWrapper()
379 awt::Point SAL_CALL
AxisWrapper::getPosition()
380 throw (uno::RuntimeException
)
382 awt::Point
aResult( m_spChart2ModelContact
->GetAxisPosition( this->getAxis() ) );
386 void SAL_CALL
AxisWrapper::setPosition( const awt::Point
& /*aPosition*/ )
387 throw (uno::RuntimeException
)
389 OSL_ENSURE( false, "trying to set position of Axis" );
392 awt::Size SAL_CALL
AxisWrapper::getSize()
393 throw (uno::RuntimeException
)
395 awt::Size
aSize( m_spChart2ModelContact
->GetAxisSize( this->getAxis() ) );
399 void SAL_CALL
AxisWrapper::setSize( const awt::Size
& /*aSize*/ )
400 throw (beans::PropertyVetoException
,
401 uno::RuntimeException
)
403 OSL_ENSURE( false, "trying to set size of Axis" );
406 // ____ XShapeDescriptor (base of XShape) ____
407 OUString SAL_CALL
AxisWrapper::getShapeType()
408 throw (uno::RuntimeException
)
410 return C2U( "com.sun.star.chart.ChartAxis" );
413 // ____ XNumberFormatsSupplier ____
414 uno::Reference
< beans::XPropertySet
> SAL_CALL
AxisWrapper::getNumberFormatSettings()
415 throw (uno::RuntimeException
)
417 Reference
< util::XNumberFormatsSupplier
> xNumSuppl( m_spChart2ModelContact
->getChartModel(), uno::UNO_QUERY
);
419 return xNumSuppl
->getNumberFormatSettings();
421 return uno::Reference
< beans::XPropertySet
>();
424 uno::Reference
< util::XNumberFormats
> SAL_CALL
AxisWrapper::getNumberFormats()
425 throw (uno::RuntimeException
)
427 Reference
< util::XNumberFormatsSupplier
> xNumSuppl( m_spChart2ModelContact
->getChartModel(), uno::UNO_QUERY
);
429 return xNumSuppl
->getNumberFormats();
431 return uno::Reference
< util::XNumberFormats
>();
435 void AxisWrapper::getDimensionAndMainAxisBool( tAxisType eType
, sal_Int32
& rnDimensionIndex
, sal_Bool
& rbMainAxis
)
440 rnDimensionIndex
= 0; rbMainAxis
= sal_True
; break;
442 rnDimensionIndex
= 1; rbMainAxis
= sal_True
; break;
444 rnDimensionIndex
= 2; rbMainAxis
= sal_True
; break;
446 rnDimensionIndex
= 0; rbMainAxis
= sal_False
; break;
448 rnDimensionIndex
= 1; rbMainAxis
= sal_False
; break;
452 // ____ XComponent ____
453 void SAL_CALL
AxisWrapper::dispose()
454 throw (uno::RuntimeException
)
456 Reference
< uno::XInterface
> xSource( static_cast< ::cppu::OWeakObject
* >( this ) );
457 m_aEventListenerContainer
.disposeAndClear( lang::EventObject( xSource
) );
459 clearWrappedPropertySet();
462 void SAL_CALL
AxisWrapper::addEventListener(
463 const Reference
< lang::XEventListener
>& xListener
)
464 throw (uno::RuntimeException
)
466 m_aEventListenerContainer
.addInterface( xListener
);
469 void SAL_CALL
AxisWrapper::removeEventListener(
470 const Reference
< lang::XEventListener
>& aListener
)
471 throw (uno::RuntimeException
)
473 m_aEventListenerContainer
.removeInterface( aListener
);
476 // ================================================================================
478 //ReferenceSizePropertyProvider
479 void AxisWrapper::updateReferenceSize()
481 Reference
< beans::XPropertySet
> xProp( this->getAxis(), uno::UNO_QUERY
);
484 if( xProp
->getPropertyValue( C2U("ReferencePageSize") ).hasValue() )
485 xProp
->setPropertyValue( C2U("ReferencePageSize"), uno::makeAny(
486 m_spChart2ModelContact
->GetPageSize() ));
489 Any
AxisWrapper::getReferenceSize()
492 Reference
< beans::XPropertySet
> xProp( this->getAxis(), uno::UNO_QUERY
);
494 aRet
= xProp
->getPropertyValue( C2U("ReferencePageSize") );
497 awt::Size
AxisWrapper::getCurrentSizeForReference()
499 return m_spChart2ModelContact
->GetPageSize();
502 // ================================================================================
504 Reference
< chart2::XAxis
> AxisWrapper::getAxis()
506 Reference
< chart2::XAxis
> xAxis
;
509 sal_Int32 nDimensionIndex
= 0;
510 sal_Bool bMainAxis
= sal_True
;
511 AxisWrapper::getDimensionAndMainAxisBool( m_eType
, nDimensionIndex
, bMainAxis
);
513 Reference
< XDiagram
> xDiagram( m_spChart2ModelContact
->getChart2Diagram() );
514 xAxis
= AxisHelper::getAxis( nDimensionIndex
, bMainAxis
, xDiagram
);
517 xAxis
= AxisHelper::createAxis( nDimensionIndex
, bMainAxis
, xDiagram
, m_spChart2ModelContact
->m_xContext
);
518 Reference
< beans::XPropertySet
> xProp( xAxis
, uno::UNO_QUERY
);
520 xProp
->setPropertyValue( C2U( "Show" ), uno::makeAny( sal_False
) );
523 catch( uno::Exception
& ex
)
525 ASSERT_EXCEPTION( ex
);
530 // WrappedPropertySet
531 Reference
< beans::XPropertySet
> AxisWrapper::getInnerPropertySet()
533 return Reference
< beans::XPropertySet
>( this->getAxis(), uno::UNO_QUERY
);
536 const Sequence
< beans::Property
>& AxisWrapper::getPropertySequence()
538 return lcl_GetPropertySequence();
541 const std::vector
< WrappedProperty
* > AxisWrapper::createWrappedProperties()
543 ::std::vector
< ::chart::WrappedProperty
* > aWrappedProperties
;
545 aWrappedProperties
.push_back( new WrappedTextRotationProperty() );
546 aWrappedProperties
.push_back( new WrappedProperty( C2U( "Marks" ), C2U( "MajorTickmarks" ) ) );
547 aWrappedProperties
.push_back( new WrappedProperty( C2U( "HelpMarks" ), C2U( "MinorTickmarks" ) ) );
548 aWrappedProperties
.push_back( new WrappedProperty( C2U( "TextCanOverlap" ), C2U( "TextOverlap" ) ) );
549 aWrappedProperties
.push_back( new WrappedProperty( C2U( "ArrangeOrder" ), C2U( "ArrangeOrder" ) ) );
550 aWrappedProperties
.push_back( new WrappedProperty( C2U( "Visible" ), C2U( "Show" ) ) );
551 aWrappedProperties
.push_back( new WrappedDirectStateProperty( C2U( "DisplayLabels" ), C2U( "DisplayLabels" ) ) );
552 aWrappedProperties
.push_back( new WrappedDirectStateProperty( C2U( "TextBreak" ), C2U( "TextBreak" ) ) );
553 WrappedNumberFormatProperty
* pWrappedNumberFormatProperty
= new WrappedNumberFormatProperty( m_spChart2ModelContact
);
554 aWrappedProperties
.push_back( pWrappedNumberFormatProperty
);
555 aWrappedProperties
.push_back( new WrappedLinkNumberFormatProperty(pWrappedNumberFormatProperty
) );
556 aWrappedProperties
.push_back( new WrappedProperty( C2U( "StackedText" ), C2U( "StackCharacters" ) ) );
557 aWrappedProperties
.push_back( new WrappedDirectStateProperty( C2U( "CrossoverPosition" ), C2U( "CrossoverPosition" ) ) );
559 WrappedGapwidthProperty
* pWrappedGapwidthProperty( new WrappedGapwidthProperty( m_spChart2ModelContact
) );
560 WrappedBarOverlapProperty
* pWrappedBarOverlapProperty( new WrappedBarOverlapProperty( m_spChart2ModelContact
) );
561 sal_Int32 nDimensionIndex
= 0;
562 sal_Bool bMainAxis
= sal_True
;
563 sal_Int32 nAxisIndex
= 0;
564 AxisWrapper::getDimensionAndMainAxisBool( m_eType
, nDimensionIndex
, bMainAxis
);
567 pWrappedGapwidthProperty
->setDimensionAndAxisIndex( nDimensionIndex
, nAxisIndex
);
568 pWrappedBarOverlapProperty
->setDimensionAndAxisIndex( nDimensionIndex
, nAxisIndex
);
569 aWrappedProperties
.push_back( pWrappedGapwidthProperty
);
570 aWrappedProperties
.push_back( pWrappedBarOverlapProperty
);
573 WrappedScaleProperty::addWrappedProperties( aWrappedProperties
, m_spChart2ModelContact
);
575 WrappedCharacterHeightProperty::addWrappedProperties( aWrappedProperties
, this );
576 WrappedScaleTextProperties::addWrappedProperties( aWrappedProperties
, m_spChart2ModelContact
);
578 return aWrappedProperties
;
581 // ================================================================================
583 Sequence
< OUString
> AxisWrapper::getSupportedServiceNames_Static()
585 Sequence
< OUString
> aServices( 3 );
586 aServices
[ 0 ] = C2U( "com.sun.star.chart.ChartAxis" );
587 aServices
[ 1 ] = C2U( "com.sun.star.xml.UserDefinedAttributeSupplier" );
588 aServices
[ 2 ] = C2U( "com.sun.star.style.CharacterProperties" );
589 // aServices[ 3 ] = C2U( "com.sun.star.beans.PropertySet" );
590 // aServices[ 4 ] = C2U( "com.sun.star.drawing.LineProperties" );
595 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
596 APPHELPER_XSERVICEINFO_IMPL( AxisWrapper
, lcl_aServiceName
);
598 } // namespace wrapper