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"
21 #include "Chart2ModelContact.hxx"
22 #include <ControllerLockGuard.hxx>
24 #include <comphelper/sequence.hxx>
25 #include <cppuhelper/supportsservice.hxx>
26 #include <com/sun/star/beans/PropertyAttribute.hpp>
27 #include <com/sun/star/chart2/RelativePosition.hpp>
28 #include <com/sun/star/chart2/XTitle.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>
41 #include <cppuhelper/propshlp.hxx>
44 using namespace ::com::sun::star
;
45 using ::com::sun::star::beans::Property
;
46 using ::com::sun::star::uno::Any
;
47 using ::com::sun::star::uno::Reference
;
48 using ::com::sun::star::uno::Sequence
;
54 class WrappedTitleStringProperty
: public WrappedProperty
57 explicit WrappedTitleStringProperty( const Reference
< uno::XComponentContext
>& xContext
);
59 virtual void setPropertyValue( const Any
& rOuterValue
, const Reference
< beans::XPropertySet
>& xInnerPropertySet
) const override
;
60 virtual Any
getPropertyValue( const Reference
< beans::XPropertySet
>& xInnerPropertySet
) const override
;
61 virtual Any
getPropertyDefault( const Reference
< beans::XPropertyState
>& xInnerPropertyState
) const override
;
64 Reference
< uno::XComponentContext
> m_xContext
;
69 WrappedTitleStringProperty::WrappedTitleStringProperty( const Reference
< uno::XComponentContext
>& xContext
)
70 : ::chart::WrappedProperty( "String", OUString() )
71 , m_xContext( xContext
)
75 void WrappedTitleStringProperty::setPropertyValue( const Any
& rOuterValue
, const Reference
< beans::XPropertySet
>& xInnerPropertySet
) const
77 Title
* pTitle
= dynamic_cast<Title
*>(xInnerPropertySet
.get());
81 rOuterValue
>>= aString
;
82 TitleHelper::setCompleteString( aString
, pTitle
, m_xContext
);
85 Any
WrappedTitleStringProperty::getPropertyValue( const Reference
< beans::XPropertySet
>& xInnerPropertySet
) const
87 Any
aRet( getPropertyDefault( Reference
< beans::XPropertyState
>( xInnerPropertySet
, uno::UNO_QUERY
) ) );
88 Reference
< chart2::XTitle
> xTitle(xInnerPropertySet
,uno::UNO_QUERY
);
91 const Sequence
< Reference
< chart2::XFormattedString
> > aStrings( xTitle
->getText());
94 for( Reference
< chart2::XFormattedString
> const & formattedStr
: aStrings
)
96 aBuf
.append( formattedStr
->getString());
98 aRet
<<= aBuf
.makeStringAndClear();
102 Any
WrappedTitleStringProperty::getPropertyDefault( const Reference
< beans::XPropertyState
>& /*xInnerPropertyState*/ ) const
104 return uno::Any( OUString() );//default title is an empty String
109 class WrappedStackedTextProperty
: public WrappedProperty
112 WrappedStackedTextProperty();
117 WrappedStackedTextProperty::WrappedStackedTextProperty()
118 : ::chart::WrappedProperty( "StackedText", "StackCharacters" )
122 }// end namespace chart
131 PROP_TITLE_TEXT_ROTATION
,
132 PROP_TITLE_TEXT_STACKED
135 void lcl_AddPropertiesToVector(
136 std::vector
< Property
> & rOutProperties
)
138 rOutProperties
.emplace_back( "String",
140 cppu::UnoType
<OUString
>::get(),
141 beans::PropertyAttribute::BOUND
142 | beans::PropertyAttribute::MAYBEVOID
);
144 rOutProperties
.emplace_back( "Visible",
146 cppu::UnoType
<OUString
>::get(),
147 beans::PropertyAttribute::BOUND
148 | beans::PropertyAttribute::MAYBEVOID
);
150 rOutProperties
.emplace_back( "TextRotation",
151 PROP_TITLE_TEXT_ROTATION
,
152 cppu::UnoType
<sal_Int32
>::get(),
153 beans::PropertyAttribute::BOUND
154 | beans::PropertyAttribute::MAYBEDEFAULT
);
155 rOutProperties
.emplace_back( "StackedText",
156 PROP_TITLE_TEXT_STACKED
,
157 cppu::UnoType
<bool>::get(),
158 beans::PropertyAttribute::BOUND
159 | beans::PropertyAttribute::MAYBEDEFAULT
);
162 const Sequence
< Property
> & StaticTitleWrapperPropertyArray()
164 static Sequence
< Property
> aPropSeq
= []()
166 std::vector
< beans::Property
> aProperties
;
167 lcl_AddPropertiesToVector( aProperties
);
168 ::chart::CharacterProperties::AddPropertiesToVector( aProperties
);
169 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties
);
170 ::chart::FillProperties::AddPropertiesToVector( aProperties
);
171 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties
);
172 ::chart::wrapper::WrappedAutomaticPositionProperties::addProperties( aProperties
);
173 ::chart::wrapper::WrappedScaleTextProperties::addProperties( aProperties
);
175 std::sort( aProperties
.begin(), aProperties
.end(),
176 ::chart::PropertyNameLess() );
178 return comphelper::containerToSequence( aProperties
);
184 } // anonymous namespace
186 namespace chart::wrapper
189 TitleWrapper::TitleWrapper( ::chart::TitleHelper::eTitleType eTitleType
,
190 std::shared_ptr
<Chart2ModelContact
> spChart2ModelContact
) :
191 m_spChart2ModelContact(std::move( spChart2ModelContact
)),
192 m_eTitleType(eTitleType
)
194 ControllerLockGuardUNO
aCtrlLockGuard( m_spChart2ModelContact
->getDocumentModel() );
195 if( !getTitleObject().is() ) //#i83831# create an empty title at the model, thus references to properties can be mapped correctly
196 TitleHelper::createTitle( m_eTitleType
, OUString(), m_spChart2ModelContact
->getDocumentModel(), m_spChart2ModelContact
->m_xContext
);
199 TitleWrapper::~TitleWrapper()
204 awt::Point SAL_CALL
TitleWrapper::getPosition()
206 return m_spChart2ModelContact
->GetTitlePosition( getTitleObject() );
209 void SAL_CALL
TitleWrapper::setPosition( const awt::Point
& aPosition
)
211 Reference
< beans::XPropertySet
> xPropertySet( getInnerPropertySet() );
212 if(xPropertySet
.is())
214 awt::Size
aPageSize( m_spChart2ModelContact
->GetPageSize() );
216 chart2::RelativePosition aRelativePosition
;
217 aRelativePosition
.Anchor
= drawing::Alignment_TOP_LEFT
;
218 aRelativePosition
.Primary
= double(aPosition
.X
)/double(aPageSize
.Width
);
219 aRelativePosition
.Secondary
= double(aPosition
.Y
)/double(aPageSize
.Height
);
220 xPropertySet
->setPropertyValue( "RelativePosition", uno::Any(aRelativePosition
) );
224 awt::Size SAL_CALL
TitleWrapper::getSize()
226 return m_spChart2ModelContact
->GetTitleSize( getTitleObject() );
229 void SAL_CALL
TitleWrapper::setSize( const awt::Size
& /*aSize*/ )
231 OSL_FAIL( "trying to set size of title" );
234 // ____ XShapeDescriptor (base of XShape) ____
235 OUString SAL_CALL
TitleWrapper::getShapeType()
237 return "com.sun.star.chart.ChartTitle";
240 // ____ XComponent ____
241 void SAL_CALL
TitleWrapper::dispose()
243 std::unique_lock
g(m_aMutex
);
244 Reference
< uno::XInterface
> xSource( static_cast< ::cppu::OWeakObject
* >( this ) );
245 m_aEventListenerContainer
.disposeAndClear( g
, lang::EventObject( xSource
) );
247 clearWrappedPropertySet();
250 void SAL_CALL
TitleWrapper::addEventListener(
251 const Reference
< lang::XEventListener
>& xListener
)
253 std::unique_lock
g(m_aMutex
);
254 m_aEventListenerContainer
.addInterface( g
, xListener
);
257 void SAL_CALL
TitleWrapper::removeEventListener(
258 const Reference
< lang::XEventListener
>& aListener
)
260 std::unique_lock
g(m_aMutex
);
261 m_aEventListenerContainer
.removeInterface( g
, aListener
);
264 Reference
< beans::XPropertySet
> TitleWrapper::getFirstCharacterPropertySet()
266 Reference
< beans::XPropertySet
> xProp
;
268 Reference
< chart2::XTitle
> xTitle( getTitleObject() );
271 Sequence
< Reference
< chart2::XFormattedString
> > aStrings( xTitle
->getText());
272 if( aStrings
.hasElements() )
273 xProp
.set( aStrings
[0], uno::UNO_QUERY
);
279 void TitleWrapper::getFastCharacterPropertyValue( sal_Int32 nHandle
, Any
& rValue
)
281 OSL_ASSERT( FAST_PROPERTY_ID_START_CHAR_PROP
<= nHandle
&&
282 nHandle
< CharacterProperties::FAST_PROPERTY_ID_END_CHAR_PROP
);
284 Reference
< beans::XPropertySet
> xProp
= getFirstCharacterPropertySet();
285 Reference
< beans::XFastPropertySet
> xFastProp( xProp
, uno::UNO_QUERY
);
288 const WrappedProperty
* pWrappedProperty
= getWrappedProperty( nHandle
);
289 if( pWrappedProperty
)
291 rValue
= pWrappedProperty
->getPropertyValue( xProp
);
293 else if( xFastProp
.is() )
295 rValue
= xFastProp
->getFastPropertyValue( nHandle
);
301 void TitleWrapper::setFastCharacterPropertyValue(
302 sal_Int32 nHandle
, const Any
& rValue
)
304 OSL_ASSERT( FAST_PROPERTY_ID_START_CHAR_PROP
<= nHandle
&&
305 nHandle
< CharacterProperties::FAST_PROPERTY_ID_END_CHAR_PROP
);
307 Reference
< chart2::XTitle
> xTitle( getTitleObject() );
311 const Sequence
< Reference
< chart2::XFormattedString
> > aStrings( xTitle
->getText());
312 const WrappedProperty
* pWrappedProperty
= getWrappedProperty( nHandle
);
314 for( Reference
< chart2::XFormattedString
> const & formattedStr
: aStrings
)
316 Reference
< beans::XFastPropertySet
> xFastPropertySet( formattedStr
, uno::UNO_QUERY
);
317 Reference
< beans::XPropertySet
> xPropSet( xFastPropertySet
, uno::UNO_QUERY
);
319 if( pWrappedProperty
)
320 pWrappedProperty
->setPropertyValue( rValue
, xPropSet
);
321 else if( xFastPropertySet
.is() )
322 xFastPropertySet
->setFastPropertyValue( nHandle
, rValue
);
326 // WrappedPropertySet
328 void SAL_CALL
TitleWrapper::setPropertyValue( const OUString
& rPropertyName
, const Any
& rValue
)
330 sal_Int32 nHandle
= getInfoHelper().getHandleByName( rPropertyName
);
331 if( CharacterProperties::IsCharacterPropertyHandle( nHandle
) )
333 setFastCharacterPropertyValue( nHandle
, rValue
);
336 WrappedPropertySet::setPropertyValue( rPropertyName
, rValue
);
339 Any SAL_CALL
TitleWrapper::getPropertyValue( const OUString
& rPropertyName
)
342 sal_Int32 nHandle
= getInfoHelper().getHandleByName( rPropertyName
);
343 if( CharacterProperties::IsCharacterPropertyHandle( nHandle
) )
344 getFastCharacterPropertyValue( nHandle
, aRet
);
346 aRet
= WrappedPropertySet::getPropertyValue( rPropertyName
);
350 beans::PropertyState SAL_CALL
TitleWrapper::getPropertyState( const OUString
& rPropertyName
)
352 beans::PropertyState
aState( beans::PropertyState_DIRECT_VALUE
);
354 sal_Int32 nHandle
= getInfoHelper().getHandleByName( rPropertyName
);
355 if( CharacterProperties::IsCharacterPropertyHandle( nHandle
) )
357 Reference
< beans::XPropertyState
> xPropState( getFirstCharacterPropertySet(), uno::UNO_QUERY
);
358 if( xPropState
.is() )
360 const WrappedProperty
* pWrappedProperty
= getWrappedProperty( rPropertyName
);
361 if( pWrappedProperty
)
362 aState
= pWrappedProperty
->getPropertyState( xPropState
);
364 aState
= xPropState
->getPropertyState( rPropertyName
);
368 aState
= WrappedPropertySet::getPropertyState( rPropertyName
);
372 void SAL_CALL
TitleWrapper::setPropertyToDefault( const OUString
& rPropertyName
)
374 sal_Int32 nHandle
= getInfoHelper().getHandleByName( rPropertyName
);
375 if( CharacterProperties::IsCharacterPropertyHandle( nHandle
) )
377 Any aDefault
= getPropertyDefault( rPropertyName
);
378 setFastCharacterPropertyValue( nHandle
, aDefault
);
381 WrappedPropertySet::setPropertyToDefault( rPropertyName
);
383 Any SAL_CALL
TitleWrapper::getPropertyDefault( const OUString
& rPropertyName
)
387 sal_Int32 nHandle
= getInfoHelper().getHandleByName( rPropertyName
);
388 if( CharacterProperties::IsCharacterPropertyHandle( nHandle
) )
390 Reference
< beans::XPropertyState
> xPropState( getFirstCharacterPropertySet(), uno::UNO_QUERY
);
391 if( xPropState
.is() )
393 const WrappedProperty
* pWrappedProperty
= getWrappedProperty( rPropertyName
);
394 if( pWrappedProperty
)
395 aRet
= pWrappedProperty
->getPropertyDefault(xPropState
);
397 aRet
= xPropState
->getPropertyDefault( rPropertyName
);
401 aRet
= WrappedPropertySet::getPropertyDefault( rPropertyName
);
406 void SAL_CALL
TitleWrapper::addPropertyChangeListener( const OUString
& rPropertyName
, const Reference
< beans::XPropertyChangeListener
>& xListener
)
408 sal_Int32 nHandle
= getInfoHelper().getHandleByName( rPropertyName
);
409 if( CharacterProperties::IsCharacterPropertyHandle( nHandle
) )
411 Reference
< beans::XPropertySet
> xPropSet
= getFirstCharacterPropertySet();
413 xPropSet
->addPropertyChangeListener( rPropertyName
, xListener
);
416 WrappedPropertySet::addPropertyChangeListener( rPropertyName
, xListener
);
418 void SAL_CALL
TitleWrapper::removePropertyChangeListener( const OUString
& rPropertyName
, const Reference
< beans::XPropertyChangeListener
>& xListener
)
420 sal_Int32 nHandle
= getInfoHelper().getHandleByName( rPropertyName
);
421 if( CharacterProperties::IsCharacterPropertyHandle( nHandle
) )
423 Reference
< beans::XPropertySet
> xPropSet
= getFirstCharacterPropertySet();
425 xPropSet
->removePropertyChangeListener( rPropertyName
, xListener
);
428 WrappedPropertySet::removePropertyChangeListener( rPropertyName
, xListener
);
431 //ReferenceSizePropertyProvider
432 void TitleWrapper::updateReferenceSize()
434 Reference
< beans::XPropertySet
> xProp( getTitleObject(), uno::UNO_QUERY
);
437 if( xProp
->getPropertyValue( "ReferencePageSize" ).hasValue() )
438 xProp
->setPropertyValue( "ReferencePageSize", uno::Any(
439 m_spChart2ModelContact
->GetPageSize() ));
442 Any
TitleWrapper::getReferenceSize()
445 Reference
< beans::XPropertySet
> xProp( getTitleObject(), uno::UNO_QUERY
);
447 aRet
= xProp
->getPropertyValue( "ReferencePageSize" );
451 awt::Size
TitleWrapper::getCurrentSizeForReference()
453 return m_spChart2ModelContact
->GetPageSize();
456 Reference
< chart2::XTitle
> TitleWrapper::getTitleObject()
458 return TitleHelper::getTitle( m_eTitleType
, m_spChart2ModelContact
->getDocumentModel() );
461 // WrappedPropertySet
463 Reference
< beans::XPropertySet
> TitleWrapper::getInnerPropertySet()
465 return Reference
< beans::XPropertySet
>( getTitleObject(), uno::UNO_QUERY
);
468 const Sequence
< beans::Property
>& TitleWrapper::getPropertySequence()
470 return StaticTitleWrapperPropertyArray();
473 std::vector
< std::unique_ptr
<WrappedProperty
> > TitleWrapper::createWrappedProperties()
475 std::vector
< std::unique_ptr
<WrappedProperty
> > aWrappedProperties
;
477 aWrappedProperties
.emplace_back( new WrappedTitleStringProperty( m_spChart2ModelContact
->m_xContext
) );
478 aWrappedProperties
.emplace_back( new WrappedTextRotationProperty( true ) );
479 aWrappedProperties
.emplace_back( new WrappedStackedTextProperty() );
480 WrappedCharacterHeightProperty::addWrappedProperties( aWrappedProperties
, this );
481 WrappedAutomaticPositionProperties::addWrappedProperties( aWrappedProperties
);
482 WrappedScaleTextProperties::addWrappedProperties( aWrappedProperties
, m_spChart2ModelContact
);
484 return aWrappedProperties
;
487 OUString SAL_CALL
TitleWrapper::getImplementationName()
489 return "com.sun.star.comp.chart.Title";
492 sal_Bool SAL_CALL
TitleWrapper::supportsService( const OUString
& rServiceName
)
494 return cppu::supportsService(this, rServiceName
);
497 css::uno::Sequence
< OUString
> SAL_CALL
TitleWrapper::getSupportedServiceNames()
500 "com.sun.star.chart.ChartTitle",
501 "com.sun.star.drawing.Shape",
502 "com.sun.star.xml.UserDefinedAttributesSupplier",
503 "com.sun.star.style.CharacterProperties"
509 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */