1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "TitleWrapper.hxx"
22 #include "ContainerHelper.hxx"
23 #include "ControllerLockGuard.hxx"
25 #include <comphelper/InlineContainer.hxx>
26 #include <cppuhelper/supportsservice.hxx>
27 #include <com/sun/star/beans/PropertyAttribute.hpp>
28 #include <com/sun/star/chart2/RelativePosition.hpp>
30 #include "CharacterProperties.hxx"
31 #include "LinePropertiesHelper.hxx"
32 #include "FillProperties.hxx"
33 #include "UserDefinedProperties.hxx"
34 #include "WrappedCharacterHeightProperty.hxx"
35 #include "WrappedTextRotationProperty.hxx"
36 #include "WrappedAutomaticPositionProperties.hxx"
37 #include "WrappedScaleTextProperties.hxx"
40 #include <rtl/ustrbuf.hxx>
42 using namespace ::com::sun::star
;
43 using ::com::sun::star::beans::Property
;
44 using ::osl::MutexGuard
;
45 using ::com::sun::star::uno::Any
;
46 using ::com::sun::star::uno::Reference
;
47 using ::com::sun::star::uno::Sequence
;
51 class WrappedTitleStringProperty
: public WrappedProperty
54 WrappedTitleStringProperty( const Reference
< uno::XComponentContext
>& xContext
);
55 virtual ~WrappedTitleStringProperty();
57 virtual void setPropertyValue( const Any
& rOuterValue
, const Reference
< beans::XPropertySet
>& xInnerPropertySet
) const
58 throw (beans::UnknownPropertyException
, beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
) SAL_OVERRIDE
;
59 virtual Any
getPropertyValue( const Reference
< beans::XPropertySet
>& xInnerPropertySet
) const
60 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
) SAL_OVERRIDE
;
61 virtual Any
getPropertyDefault( const Reference
< beans::XPropertyState
>& xInnerPropertyState
) const
62 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
) SAL_OVERRIDE
;
65 Reference
< uno::XComponentContext
> m_xContext
;
68 WrappedTitleStringProperty::WrappedTitleStringProperty( const Reference
< uno::XComponentContext
>& xContext
)
69 : ::chart::WrappedProperty( "String", OUString() )
70 , m_xContext( xContext
)
73 WrappedTitleStringProperty::~WrappedTitleStringProperty()
77 void WrappedTitleStringProperty::setPropertyValue( const Any
& rOuterValue
, const Reference
< beans::XPropertySet
>& xInnerPropertySet
) const
78 throw (beans::UnknownPropertyException
, beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
)
80 Reference
< chart2::XTitle
> xTitle(xInnerPropertySet
,uno::UNO_QUERY
);
84 rOuterValue
>>= aString
;
85 TitleHelper::setCompleteString( aString
, xTitle
, m_xContext
);
88 Any
WrappedTitleStringProperty::getPropertyValue( const Reference
< beans::XPropertySet
>& xInnerPropertySet
) const
89 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
91 Any
aRet( getPropertyDefault( Reference
< beans::XPropertyState
>( xInnerPropertySet
, uno::UNO_QUERY
) ) );
92 Reference
< chart2::XTitle
> xTitle(xInnerPropertySet
,uno::UNO_QUERY
);
95 Sequence
< Reference
< chart2::XFormattedString
> > aStrings( xTitle
->getText());
98 for( sal_Int32 i
= 0; i
< aStrings
.getLength(); ++i
)
100 aBuf
.append( aStrings
[ i
]->getString());
102 aRet
<<= aBuf
.makeStringAndClear();
106 Any
WrappedTitleStringProperty::getPropertyDefault( const Reference
< beans::XPropertyState
>& /*xInnerPropertyState*/ ) const
107 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
109 return uno::makeAny( OUString() );//default title is a empty String
112 class WrappedStackedTextProperty
: public WrappedProperty
115 WrappedStackedTextProperty();
116 virtual ~WrappedStackedTextProperty();
119 WrappedStackedTextProperty::WrappedStackedTextProperty()
120 : ::chart::WrappedProperty( "StackedText", "StackCharacters" )
123 WrappedStackedTextProperty::~WrappedStackedTextProperty()
127 }// end namespace chart
131 static const char lcl_aServiceName
[] = "com.sun.star.comp.chart.Title";
136 PROP_TITLE_TEXT_ROTATION
,
137 PROP_TITLE_TEXT_STACKED
140 void lcl_AddPropertiesToVector(
141 ::std::vector
< Property
> & rOutProperties
)
143 rOutProperties
.push_back(
146 cppu::UnoType
<OUString
>::get(),
147 beans::PropertyAttribute::BOUND
148 | beans::PropertyAttribute::MAYBEVOID
));
150 rOutProperties
.push_back(
151 Property( "TextRotation",
152 PROP_TITLE_TEXT_ROTATION
,
153 cppu::UnoType
<sal_Int32
>::get(),
154 beans::PropertyAttribute::BOUND
155 | beans::PropertyAttribute::MAYBEDEFAULT
));
156 rOutProperties
.push_back(
157 Property( "StackedText",
158 PROP_TITLE_TEXT_STACKED
,
159 cppu::UnoType
<bool>::get(),
160 beans::PropertyAttribute::BOUND
161 | beans::PropertyAttribute::MAYBEDEFAULT
));
164 struct StaticTitleWrapperPropertyArray_Initializer
166 Sequence
< Property
>* operator()()
168 static Sequence
< Property
> aPropSeq( lcl_GetPropertySequence() );
173 static Sequence
< Property
> lcl_GetPropertySequence()
175 ::std::vector
< beans::Property
> aProperties
;
176 lcl_AddPropertiesToVector( aProperties
);
177 ::chart::CharacterProperties::AddPropertiesToVector( aProperties
);
178 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties
);
179 ::chart::FillProperties::AddPropertiesToVector( aProperties
);
180 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties
);
181 ::chart::wrapper::WrappedAutomaticPositionProperties::addProperties( aProperties
);
182 ::chart::wrapper::WrappedScaleTextProperties::addProperties( aProperties
);
184 ::std::sort( aProperties
.begin(), aProperties
.end(),
185 ::chart::PropertyNameLess() );
187 return ::chart::ContainerHelper::ContainerToSequence( aProperties
);
191 struct StaticTitleWrapperPropertyArray
: public rtl::StaticAggregate
< Sequence
< Property
>, StaticTitleWrapperPropertyArray_Initializer
>
195 } // anonymous namespace
202 TitleWrapper::TitleWrapper( ::chart::TitleHelper::eTitleType eTitleType
,
203 ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
) :
204 m_spChart2ModelContact( spChart2ModelContact
),
205 m_aEventListenerContainer( m_aMutex
),
206 m_eTitleType(eTitleType
)
208 ControllerLockGuardUNO
aCtrlLockGuard( Reference
< frame::XModel
>( m_spChart2ModelContact
->getChart2Document(), uno::UNO_QUERY
));
209 if( !getTitleObject().is() ) //#i83831# create an empty title at the model, thus references to properties can be mapped mapped correctly
210 TitleHelper::createTitle( m_eTitleType
, OUString(), m_spChart2ModelContact
->getChartModel(), m_spChart2ModelContact
->m_xContext
);
213 TitleWrapper::~TitleWrapper()
218 awt::Point SAL_CALL
TitleWrapper::getPosition()
219 throw (uno::RuntimeException
, std::exception
)
221 return m_spChart2ModelContact
->GetTitlePosition( this->getTitleObject() );
224 void SAL_CALL
TitleWrapper::setPosition( const awt::Point
& aPosition
)
225 throw (uno::RuntimeException
, std::exception
)
227 Reference
< beans::XPropertySet
> xPropertySet( this->getInnerPropertySet() );
228 if(xPropertySet
.is())
230 awt::Size
aPageSize( m_spChart2ModelContact
->GetPageSize() );
232 chart2::RelativePosition aRelativePosition
;
233 aRelativePosition
.Anchor
= drawing::Alignment_TOP_LEFT
;
234 aRelativePosition
.Primary
= double(aPosition
.X
)/double(aPageSize
.Width
);
235 aRelativePosition
.Secondary
= double(aPosition
.Y
)/double(aPageSize
.Height
);
236 xPropertySet
->setPropertyValue( "RelativePosition", uno::makeAny(aRelativePosition
) );
240 awt::Size SAL_CALL
TitleWrapper::getSize()
241 throw (uno::RuntimeException
, std::exception
)
243 return m_spChart2ModelContact
->GetTitleSize( this->getTitleObject() );
246 void SAL_CALL
TitleWrapper::setSize( const awt::Size
& /*aSize*/ )
247 throw (beans::PropertyVetoException
,
248 uno::RuntimeException
, std::exception
)
250 OSL_FAIL( "trying to set size of title" );
253 // ____ XShapeDescriptor (base of XShape) ____
254 OUString SAL_CALL
TitleWrapper::getShapeType()
255 throw (uno::RuntimeException
, std::exception
)
257 return OUString( "com.sun.star.chart.ChartTitle" );
260 // ____ XComponent ____
261 void SAL_CALL
TitleWrapper::dispose()
262 throw (uno::RuntimeException
, std::exception
)
264 Reference
< uno::XInterface
> xSource( static_cast< ::cppu::OWeakObject
* >( this ) );
265 m_aEventListenerContainer
.disposeAndClear( lang::EventObject( xSource
) );
267 MutexGuard
aGuard( GetMutex());
268 clearWrappedPropertySet();
271 void SAL_CALL
TitleWrapper::addEventListener(
272 const Reference
< lang::XEventListener
>& xListener
)
273 throw (uno::RuntimeException
, std::exception
)
275 m_aEventListenerContainer
.addInterface( xListener
);
278 void SAL_CALL
TitleWrapper::removeEventListener(
279 const Reference
< lang::XEventListener
>& aListener
)
280 throw (uno::RuntimeException
, std::exception
)
282 m_aEventListenerContainer
.removeInterface( aListener
);
285 Reference
< beans::XPropertySet
> TitleWrapper::getFirstCharacterPropertySet()
287 Reference
< beans::XPropertySet
> xProp
;
289 Reference
< chart2::XTitle
> xTitle( this->getTitleObject() );
292 Sequence
< Reference
< chart2::XFormattedString
> > aStrings( xTitle
->getText());
293 if( aStrings
.getLength() > 0 )
294 xProp
.set( aStrings
[0], uno::UNO_QUERY
);
300 void TitleWrapper::getFastCharacterPropertyValue( sal_Int32 nHandle
, Any
& rValue
)
302 OSL_ASSERT( FAST_PROPERTY_ID_START_CHAR_PROP
<= nHandle
&&
303 nHandle
< CharacterProperties::FAST_PROPERTY_ID_END_CHAR_PROP
);
305 Reference
< beans::XPropertySet
> xProp( getFirstCharacterPropertySet(), uno::UNO_QUERY
);
306 Reference
< beans::XFastPropertySet
> xFastProp( xProp
, uno::UNO_QUERY
);
309 const WrappedProperty
* pWrappedProperty
= getWrappedProperty( nHandle
);
310 if( pWrappedProperty
)
312 rValue
= pWrappedProperty
->getPropertyValue( xProp
);
314 else if( xFastProp
.is() )
316 rValue
= xFastProp
->getFastPropertyValue( nHandle
);
322 void TitleWrapper::setFastCharacterPropertyValue(
323 sal_Int32 nHandle
, const Any
& rValue
) throw (uno::Exception
)
325 OSL_ASSERT( FAST_PROPERTY_ID_START_CHAR_PROP
<= nHandle
&&
326 nHandle
< CharacterProperties::FAST_PROPERTY_ID_END_CHAR_PROP
);
328 Reference
< chart2::XTitle
> xTitle( this->getTitleObject() );
331 Sequence
< Reference
< chart2::XFormattedString
> > aStrings( xTitle
->getText());
332 const WrappedProperty
* pWrappedProperty
= getWrappedProperty( nHandle
);
334 for( sal_Int32 i
= 0; i
< aStrings
.getLength(); ++i
)
336 Reference
< beans::XFastPropertySet
> xFastPropertySet( aStrings
[ i
], uno::UNO_QUERY
);
337 Reference
< beans::XPropertySet
> xPropSet( xFastPropertySet
, uno::UNO_QUERY
);
339 if( pWrappedProperty
)
340 pWrappedProperty
->setPropertyValue( rValue
, xPropSet
);
341 else if( xFastPropertySet
.is() )
342 xFastPropertySet
->setFastPropertyValue( nHandle
, rValue
);
347 // WrappedPropertySet
349 void SAL_CALL
TitleWrapper::setPropertyValue( const OUString
& rPropertyName
, const Any
& rValue
)
350 throw (beans::UnknownPropertyException
, beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
352 sal_Int32 nHandle
= getInfoHelper().getHandleByName( rPropertyName
);
353 if( CharacterProperties::IsCharacterPropertyHandle( nHandle
) )
355 setFastCharacterPropertyValue( nHandle
, rValue
);
358 WrappedPropertySet::setPropertyValue( rPropertyName
, rValue
);
361 Any SAL_CALL
TitleWrapper::getPropertyValue( const OUString
& rPropertyName
)
362 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
365 sal_Int32 nHandle
= getInfoHelper().getHandleByName( rPropertyName
);
366 if( CharacterProperties::IsCharacterPropertyHandle( nHandle
) )
367 getFastCharacterPropertyValue( nHandle
, aRet
);
369 aRet
= WrappedPropertySet::getPropertyValue( rPropertyName
);
373 beans::PropertyState SAL_CALL
TitleWrapper::getPropertyState( const OUString
& rPropertyName
)
374 throw (beans::UnknownPropertyException
, uno::RuntimeException
, std::exception
)
376 beans::PropertyState
aState( beans::PropertyState_DIRECT_VALUE
);
378 sal_Int32 nHandle
= getInfoHelper().getHandleByName( rPropertyName
);
379 if( CharacterProperties::IsCharacterPropertyHandle( nHandle
) )
381 Reference
< beans::XPropertyState
> xPropState( getFirstCharacterPropertySet(), uno::UNO_QUERY
);
382 if( xPropState
.is() )
384 const WrappedProperty
* pWrappedProperty
= getWrappedProperty( rPropertyName
);
385 if( pWrappedProperty
)
386 aState
= pWrappedProperty
->getPropertyState( xPropState
);
388 aState
= xPropState
->getPropertyState( rPropertyName
);
392 aState
= WrappedPropertySet::getPropertyState( rPropertyName
);
396 void SAL_CALL
TitleWrapper::setPropertyToDefault( const OUString
& rPropertyName
)
397 throw (beans::UnknownPropertyException
, uno::RuntimeException
, std::exception
)
399 sal_Int32 nHandle
= getInfoHelper().getHandleByName( rPropertyName
);
400 if( CharacterProperties::IsCharacterPropertyHandle( nHandle
) )
402 Any aDefault
= getPropertyDefault( rPropertyName
);
403 setFastCharacterPropertyValue( nHandle
, aDefault
);
406 WrappedPropertySet::setPropertyToDefault( rPropertyName
);
408 Any SAL_CALL
TitleWrapper::getPropertyDefault( const OUString
& rPropertyName
)
409 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
413 sal_Int32 nHandle
= getInfoHelper().getHandleByName( rPropertyName
);
414 if( CharacterProperties::IsCharacterPropertyHandle( nHandle
) )
416 Reference
< beans::XPropertyState
> xPropState( getFirstCharacterPropertySet(), uno::UNO_QUERY
);
417 if( xPropState
.is() )
419 const WrappedProperty
* pWrappedProperty
= getWrappedProperty( rPropertyName
);
420 if( pWrappedProperty
)
421 aRet
= pWrappedProperty
->getPropertyDefault(xPropState
);
423 aRet
= xPropState
->getPropertyDefault( rPropertyName
);
427 aRet
= WrappedPropertySet::getPropertyDefault( rPropertyName
);
432 void SAL_CALL
TitleWrapper::addPropertyChangeListener( const OUString
& rPropertyName
, const Reference
< beans::XPropertyChangeListener
>& xListener
)
433 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
435 sal_Int32 nHandle
= getInfoHelper().getHandleByName( rPropertyName
);
436 if( CharacterProperties::IsCharacterPropertyHandle( nHandle
) )
438 Reference
< beans::XPropertySet
> xPropSet( getFirstCharacterPropertySet(), uno::UNO_QUERY
);
440 xPropSet
->addPropertyChangeListener( rPropertyName
, xListener
);
443 WrappedPropertySet::addPropertyChangeListener( rPropertyName
, xListener
);
445 void SAL_CALL
TitleWrapper::removePropertyChangeListener( const OUString
& rPropertyName
, const Reference
< beans::XPropertyChangeListener
>& xListener
)
446 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
448 sal_Int32 nHandle
= getInfoHelper().getHandleByName( rPropertyName
);
449 if( CharacterProperties::IsCharacterPropertyHandle( nHandle
) )
451 Reference
< beans::XPropertySet
> xPropSet( getFirstCharacterPropertySet(), uno::UNO_QUERY
);
453 xPropSet
->removePropertyChangeListener( rPropertyName
, xListener
);
456 WrappedPropertySet::removePropertyChangeListener( rPropertyName
, xListener
);
459 //ReferenceSizePropertyProvider
460 void TitleWrapper::updateReferenceSize()
462 Reference
< beans::XPropertySet
> xProp( this->getTitleObject(), uno::UNO_QUERY
);
465 if( xProp
->getPropertyValue( "ReferencePageSize" ).hasValue() )
466 xProp
->setPropertyValue( "ReferencePageSize", uno::makeAny(
467 m_spChart2ModelContact
->GetPageSize() ));
470 Any
TitleWrapper::getReferenceSize()
473 Reference
< beans::XPropertySet
> xProp( this->getTitleObject(), uno::UNO_QUERY
);
475 aRet
= xProp
->getPropertyValue( "ReferencePageSize" );
479 awt::Size
TitleWrapper::getCurrentSizeForReference()
481 return m_spChart2ModelContact
->GetPageSize();
484 Reference
< chart2::XTitle
> TitleWrapper::getTitleObject()
486 return TitleHelper::getTitle( m_eTitleType
, m_spChart2ModelContact
->getChartModel() );
489 // WrappedPropertySet
491 Reference
< beans::XPropertySet
> TitleWrapper::getInnerPropertySet()
493 return Reference
< beans::XPropertySet
>( this->getTitleObject(), uno::UNO_QUERY
);
496 const Sequence
< beans::Property
>& TitleWrapper::getPropertySequence()
498 return *StaticTitleWrapperPropertyArray::get();
501 const std::vector
< WrappedProperty
* > TitleWrapper::createWrappedProperties()
503 ::std::vector
< ::chart::WrappedProperty
* > aWrappedProperties
;
505 aWrappedProperties
.push_back( new WrappedTitleStringProperty( m_spChart2ModelContact
->m_xContext
) );
506 aWrappedProperties
.push_back( new WrappedTextRotationProperty( true ) );
507 aWrappedProperties
.push_back( new WrappedStackedTextProperty() );
508 WrappedCharacterHeightProperty::addWrappedProperties( aWrappedProperties
, this );
509 WrappedAutomaticPositionProperties::addWrappedProperties( aWrappedProperties
);
510 WrappedScaleTextProperties::addWrappedProperties( aWrappedProperties
, m_spChart2ModelContact
);
512 return aWrappedProperties
;
515 Sequence
< OUString
> TitleWrapper::getSupportedServiceNames_Static()
517 Sequence
< OUString
> aServices( 4 );
518 aServices
[ 0 ] = "com.sun.star.chart.ChartTitle";
519 aServices
[ 1 ] = "com.sun.star.drawing.Shape";
520 aServices
[ 2 ] = "com.sun.star.xml.UserDefinedAttributesSupplier";
521 aServices
[ 3 ] = "com.sun.star.style.CharacterProperties";
526 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
527 OUString SAL_CALL
TitleWrapper::getImplementationName()
528 throw( css::uno::RuntimeException
, std::exception
)
530 return getImplementationName_Static();
533 OUString
TitleWrapper::getImplementationName_Static()
535 return OUString(lcl_aServiceName
);
538 sal_Bool SAL_CALL
TitleWrapper::supportsService( const OUString
& rServiceName
)
539 throw( css::uno::RuntimeException
, std::exception
)
541 return cppu::supportsService(this, rServiceName
);
544 css::uno::Sequence
< OUString
> SAL_CALL
TitleWrapper::getSupportedServiceNames()
545 throw( css::uno::RuntimeException
, std::exception
)
547 return getSupportedServiceNames_Static();
550 } // namespace wrapper
553 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */