Update ooo320-m1
[ooovba.git] / chart2 / source / controller / chartapiwrapper / TitleWrapper.cxx
blobf3ccf09cb614902c5c3248f4a05a9c01cb3af43e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TitleWrapper.cxx,v $
10 * $Revision: 1.8.44.4 $
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 "TitleWrapper.hxx"
34 #include "macros.hxx"
35 #include "ContainerHelper.hxx"
36 #include <comphelper/InlineContainer.hxx>
37 #include <com/sun/star/beans/PropertyAttribute.hpp>
38 #include <com/sun/star/chart2/RelativePosition.hpp>
40 #include "CharacterProperties.hxx"
41 #include "LineProperties.hxx"
42 #include "FillProperties.hxx"
43 #include "UserDefinedProperties.hxx"
44 #include "WrappedCharacterHeightProperty.hxx"
45 #include "WrappedTextRotationProperty.hxx"
46 #include "WrappedAutomaticPositionProperties.hxx"
47 #include "WrappedScaleTextProperties.hxx"
49 #include <algorithm>
50 #include <rtl/ustrbuf.hxx>
52 using namespace ::com::sun::star;
53 using ::com::sun::star::beans::Property;
54 using ::osl::MutexGuard;
55 using ::rtl::OUString;
56 using ::com::sun::star::uno::Any;
57 using ::com::sun::star::uno::Reference;
58 using ::com::sun::star::uno::Sequence;
61 namespace chart
63 class WrappedTitleStringProperty : public WrappedProperty
65 public:
66 WrappedTitleStringProperty( const Reference< uno::XComponentContext >& xContext );
67 virtual ~WrappedTitleStringProperty();
69 virtual void setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
70 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException);
71 virtual Any getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const
72 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException);
73 virtual Any getPropertyDefault( const Reference< beans::XPropertyState >& xInnerPropertyState ) const
74 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException);
76 protected:
77 Reference< uno::XComponentContext > m_xContext;
80 WrappedTitleStringProperty::WrappedTitleStringProperty( const Reference< uno::XComponentContext >& xContext )
81 : ::chart::WrappedProperty( C2U( "String" ), OUString() )
82 , m_xContext( xContext )
85 WrappedTitleStringProperty::~WrappedTitleStringProperty()
89 void WrappedTitleStringProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
90 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
92 Reference< chart2::XTitle > xTitle(xInnerPropertySet,uno::UNO_QUERY);
93 if(xTitle.is())
95 OUString aString;
96 rOuterValue >>= aString;
97 TitleHelper::setCompleteString( aString, xTitle, m_xContext );
100 Any WrappedTitleStringProperty::getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const
101 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
103 Any aRet( getPropertyDefault( Reference< beans::XPropertyState >( xInnerPropertySet, uno::UNO_QUERY ) ) );
104 Reference< chart2::XTitle > xTitle(xInnerPropertySet,uno::UNO_QUERY);
105 if(xTitle.is())
107 Sequence< Reference< chart2::XFormattedString > > aStrings( xTitle->getText());
109 ::rtl::OUStringBuffer aBuf;
110 for( sal_Int32 i = 0; i < aStrings.getLength(); ++i )
112 aBuf.append( aStrings[ i ]->getString());
114 aRet <<= aBuf.makeStringAndClear();
116 return aRet;
118 Any WrappedTitleStringProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
119 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
121 return uno::makeAny( rtl::OUString() );//default title is a empty String
124 //-----------------------------------------------------------------------------
125 //-----------------------------------------------------------------------------
127 class WrappedStackedTextProperty : public WrappedProperty
129 public:
130 WrappedStackedTextProperty();
131 virtual ~WrappedStackedTextProperty();
134 WrappedStackedTextProperty::WrappedStackedTextProperty()
135 : ::chart::WrappedProperty( C2U( "StackedText" ), C2U( "StackCharacters" ) )
138 WrappedStackedTextProperty::~WrappedStackedTextProperty()
142 }// end namespace chart
145 //-----------------------------------------------------------------------------
146 //-----------------------------------------------------------------------------
147 //-----------------------------------------------------------------------------
148 //-----------------------------------------------------------------------------
150 namespace
152 static const OUString lcl_aServiceName(
153 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart.Title" ));
155 enum
157 PROP_TITLE_STRING,
158 PROP_TITLE_TEXT_ROTATION,
159 PROP_TITLE_TEXT_STACKED
162 void lcl_AddPropertiesToVector(
163 ::std::vector< Property > & rOutProperties )
165 rOutProperties.push_back(
166 Property( C2U( "String" ),
167 PROP_TITLE_STRING,
168 ::getCppuType( reinterpret_cast< const ::rtl::OUString * >(0)),
169 beans::PropertyAttribute::BOUND
170 | beans::PropertyAttribute::MAYBEVOID ));
172 rOutProperties.push_back(
173 Property( C2U( "TextRotation" ),
174 PROP_TITLE_TEXT_ROTATION,
175 ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
176 beans::PropertyAttribute::BOUND
177 | beans::PropertyAttribute::MAYBEDEFAULT ));
178 rOutProperties.push_back(
179 Property( C2U( "StackedText" ),
180 PROP_TITLE_TEXT_STACKED,
181 ::getBooleanCppuType(),
182 beans::PropertyAttribute::BOUND
183 | beans::PropertyAttribute::MAYBEDEFAULT ));
186 const Sequence< Property > & lcl_GetPropertySequence()
188 static Sequence< Property > aPropSeq;
190 // /--
191 MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
192 if( 0 == aPropSeq.getLength() )
194 // get properties
195 ::std::vector< beans::Property > aProperties;
196 lcl_AddPropertiesToVector( aProperties );
197 ::chart::CharacterProperties::AddPropertiesToVector( aProperties );
198 ::chart::LineProperties::AddPropertiesToVector( aProperties );
199 ::chart::FillProperties::AddPropertiesToVector( aProperties );
200 // ::chart::NamedProperties::AddPropertiesToVector( aProperties );
201 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
202 ::chart::wrapper::WrappedAutomaticPositionProperties::addProperties( aProperties );
203 ::chart::wrapper::WrappedScaleTextProperties::addProperties( aProperties );
205 // and sort them for access via bsearch
206 ::std::sort( aProperties.begin(), aProperties.end(),
207 ::chart::PropertyNameLess() );
209 // transfer result to static Sequence
210 aPropSeq = ::chart::ContainerHelper::ContainerToSequence( aProperties );
213 return aPropSeq;
216 } // anonymous namespace
218 // --------------------------------------------------------------------------------
220 namespace chart
222 namespace wrapper
225 TitleWrapper::TitleWrapper( ::chart::TitleHelper::eTitleType eTitleType,
226 ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) :
227 m_spChart2ModelContact( spChart2ModelContact ),
228 m_aEventListenerContainer( m_aMutex ),
229 m_eTitleType(eTitleType)
233 TitleWrapper::~TitleWrapper()
237 // ____ XShape ____
238 awt::Point SAL_CALL TitleWrapper::getPosition()
239 throw (uno::RuntimeException)
241 return m_spChart2ModelContact->GetTitlePosition( this->getTitleObject() );
244 void SAL_CALL TitleWrapper::setPosition( const awt::Point& aPosition )
245 throw (uno::RuntimeException)
247 Reference< beans::XPropertySet > xPropertySet( this->getInnerPropertySet() );
248 if(xPropertySet.is())
250 awt::Size aPageSize( m_spChart2ModelContact->GetPageSize() );
252 chart2::RelativePosition aRelativePosition;
253 aRelativePosition.Anchor = drawing::Alignment_TOP_LEFT;
254 aRelativePosition.Primary = double(aPosition.X)/double(aPageSize.Width);
255 aRelativePosition.Secondary = double(aPosition.Y)/double(aPageSize.Height);
256 xPropertySet->setPropertyValue( C2U( "RelativePosition" ), uno::makeAny(aRelativePosition) );
260 awt::Size SAL_CALL TitleWrapper::getSize()
261 throw (uno::RuntimeException)
263 return m_spChart2ModelContact->GetTitleSize( this->getTitleObject() );
266 void SAL_CALL TitleWrapper::setSize( const awt::Size& /*aSize*/ )
267 throw (beans::PropertyVetoException,
268 uno::RuntimeException)
270 OSL_ENSURE( false, "trying to set size of title" );
273 // ____ XShapeDescriptor (base of XShape) ____
274 OUString SAL_CALL TitleWrapper::getShapeType()
275 throw (uno::RuntimeException)
277 return C2U( "com.sun.star.chart.ChartTitle" );
280 // ____ XComponent ____
281 void SAL_CALL TitleWrapper::dispose()
282 throw (uno::RuntimeException)
284 Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
285 m_aEventListenerContainer.disposeAndClear( lang::EventObject( xSource ) );
287 // /--
288 MutexGuard aGuard( GetMutex());
289 clearWrappedPropertySet();
290 // \--
293 void SAL_CALL TitleWrapper::addEventListener(
294 const Reference< lang::XEventListener >& xListener )
295 throw (uno::RuntimeException)
297 m_aEventListenerContainer.addInterface( xListener );
300 void SAL_CALL TitleWrapper::removeEventListener(
301 const Reference< lang::XEventListener >& aListener )
302 throw (uno::RuntimeException)
304 m_aEventListenerContainer.removeInterface( aListener );
307 // ================================================================================
309 Reference< beans::XPropertySet > TitleWrapper::getFirstCharacterPropertySet()
311 Reference< beans::XPropertySet > xProp;
313 Reference< chart2::XTitle > xTitle( this->getTitleObject() );
314 if( xTitle.is())
316 Sequence< Reference< chart2::XFormattedString > > aStrings( xTitle->getText());
317 if( aStrings.getLength() > 0 )
318 xProp.set( aStrings[0], uno::UNO_QUERY );
321 return xProp;
324 void TitleWrapper::getFastCharacterPropertyValue( sal_Int32 nHandle, Any& rValue )
326 OSL_ASSERT( FAST_PROPERTY_ID_START_CHAR_PROP <= nHandle &&
327 nHandle < CharacterProperties::FAST_PROPERTY_ID_END_CHAR_PROP );
329 Reference< beans::XPropertySet > xProp( getFirstCharacterPropertySet(), uno::UNO_QUERY );
330 Reference< beans::XFastPropertySet > xFastProp( xProp, uno::UNO_QUERY );
331 if(xProp.is())
333 const WrappedProperty* pWrappedProperty = getWrappedProperty( nHandle );
334 if( pWrappedProperty )
336 rValue = pWrappedProperty->getPropertyValue( xProp );
338 else if( xFastProp.is() )
340 rValue = xFastProp->getFastPropertyValue( nHandle );
346 void TitleWrapper::setFastCharacterPropertyValue(
347 sal_Int32 nHandle, const Any& rValue ) throw (uno::Exception)
349 OSL_ASSERT( FAST_PROPERTY_ID_START_CHAR_PROP <= nHandle &&
350 nHandle < CharacterProperties::FAST_PROPERTY_ID_END_CHAR_PROP );
352 Reference< chart2::XTitle > xTitle( this->getTitleObject() );
353 if( xTitle.is())
355 Sequence< Reference< chart2::XFormattedString > > aStrings( xTitle->getText());
356 const WrappedProperty* pWrappedProperty = getWrappedProperty( nHandle );
358 for( sal_Int32 i = 0; i < aStrings.getLength(); ++i )
360 Reference< beans::XFastPropertySet > xFastPropertySet( aStrings[ i ], uno::UNO_QUERY );
361 Reference< beans::XPropertySet > xPropSet( xFastPropertySet, uno::UNO_QUERY );
363 if( pWrappedProperty )
364 pWrappedProperty->setPropertyValue( rValue, xPropSet );
365 else if( xFastPropertySet.is() )
366 xFastPropertySet->setFastPropertyValue( nHandle, rValue );
371 // ================================================================================
372 // WrappedPropertySet
374 void SAL_CALL TitleWrapper::setPropertyValue( const OUString& rPropertyName, const Any& rValue )
375 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
377 sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName );
378 if( CharacterProperties::IsCharacterPropertyHandle( nHandle ) )
380 setFastCharacterPropertyValue( nHandle, rValue );
382 else
383 WrappedPropertySet::setPropertyValue( rPropertyName, rValue );
386 Any SAL_CALL TitleWrapper::getPropertyValue( const OUString& rPropertyName )
387 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
389 Any aRet;
390 sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName );
391 if( CharacterProperties::IsCharacterPropertyHandle( nHandle ) )
392 getFastCharacterPropertyValue( nHandle, aRet );
393 else
394 aRet = WrappedPropertySet::getPropertyValue( rPropertyName );
395 return aRet;
398 beans::PropertyState SAL_CALL TitleWrapper::getPropertyState( const OUString& rPropertyName )
399 throw (beans::UnknownPropertyException, uno::RuntimeException)
401 beans::PropertyState aState( beans::PropertyState_DIRECT_VALUE );
403 sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName );
404 if( CharacterProperties::IsCharacterPropertyHandle( nHandle ) )
406 Reference< beans::XPropertyState > xPropState( getFirstCharacterPropertySet(), uno::UNO_QUERY );
407 if( xPropState.is() )
409 const WrappedProperty* pWrappedProperty = getWrappedProperty( rPropertyName );
410 if( pWrappedProperty )
411 aState = pWrappedProperty->getPropertyState( xPropState );
412 else
413 aState = xPropState->getPropertyState( rPropertyName );
416 else
417 aState = WrappedPropertySet::getPropertyState( rPropertyName );
419 return aState;
421 void SAL_CALL TitleWrapper::setPropertyToDefault( const OUString& rPropertyName )
422 throw (beans::UnknownPropertyException, uno::RuntimeException)
424 sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName );
425 if( CharacterProperties::IsCharacterPropertyHandle( nHandle ) )
427 Any aDefault = getPropertyDefault( rPropertyName );
428 setFastCharacterPropertyValue( nHandle, aDefault );
430 else
431 WrappedPropertySet::setPropertyToDefault( rPropertyName );
433 Any SAL_CALL TitleWrapper::getPropertyDefault( const OUString& rPropertyName )
434 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
436 Any aRet;
438 sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName );
439 if( CharacterProperties::IsCharacterPropertyHandle( nHandle ) )
441 Reference< beans::XPropertyState > xPropState( getFirstCharacterPropertySet(), uno::UNO_QUERY );
442 if( xPropState.is() )
444 const WrappedProperty* pWrappedProperty = getWrappedProperty( rPropertyName );
445 if( pWrappedProperty )
446 aRet = pWrappedProperty->getPropertyDefault(xPropState);
447 else
448 aRet = xPropState->getPropertyDefault( rPropertyName );
451 else
452 aRet = WrappedPropertySet::getPropertyDefault( rPropertyName );
454 return aRet;
457 // ================================================================================
459 //ReferenceSizePropertyProvider
460 void TitleWrapper::updateReferenceSize()
462 Reference< beans::XPropertySet > xProp( this->getTitleObject(), uno::UNO_QUERY );
463 if( xProp.is() )
465 if( xProp->getPropertyValue( C2U("ReferencePageSize") ).hasValue() )
466 xProp->setPropertyValue( C2U("ReferencePageSize"), uno::makeAny(
467 m_spChart2ModelContact->GetPageSize() ));
470 Any TitleWrapper::getReferenceSize()
472 Any aRet;
473 Reference< beans::XPropertySet > xProp( this->getTitleObject(), uno::UNO_QUERY );
474 if( xProp.is() )
475 aRet = xProp->getPropertyValue( C2U("ReferencePageSize") );
477 return aRet;
479 awt::Size TitleWrapper::getCurrentSizeForReference()
481 return m_spChart2ModelContact->GetPageSize();
484 // ================================================================================
486 Reference< chart2::XTitle > TitleWrapper::getTitleObject()
488 return TitleHelper::getTitle( m_eTitleType, m_spChart2ModelContact->getChartModel() );
491 // WrappedPropertySet
493 Reference< beans::XPropertySet > TitleWrapper::getInnerPropertySet()
495 return Reference< beans::XPropertySet >( this->getTitleObject(), uno::UNO_QUERY );
498 const Sequence< beans::Property >& TitleWrapper::getPropertySequence()
500 return lcl_GetPropertySequence();
503 const std::vector< WrappedProperty* > TitleWrapper::createWrappedProperties()
505 ::std::vector< ::chart::WrappedProperty* > aWrappedProperties;
507 aWrappedProperties.push_back( new WrappedTitleStringProperty( m_spChart2ModelContact->m_xContext ) );
508 aWrappedProperties.push_back( new WrappedTextRotationProperty() );
509 aWrappedProperties.push_back( new WrappedStackedTextProperty() );
510 WrappedCharacterHeightProperty::addWrappedProperties( aWrappedProperties, this );
511 WrappedAutomaticPositionProperties::addWrappedProperties( aWrappedProperties );
512 WrappedScaleTextProperties::addWrappedProperties( aWrappedProperties, m_spChart2ModelContact );
514 return aWrappedProperties;
517 // ================================================================================
519 Sequence< OUString > TitleWrapper::getSupportedServiceNames_Static()
521 Sequence< OUString > aServices( 4 );
522 aServices[ 0 ] = C2U( "com.sun.star.chart.ChartTitle" );
523 aServices[ 1 ] = C2U( "com.sun.star.drawing.Shape" );
524 aServices[ 2 ] = C2U( "com.sun.star.xml.UserDefinedAttributeSupplier" );
525 aServices[ 3 ] = C2U( "com.sun.star.style.CharacterProperties" );
526 // aServices[ 4 ] = C2U( "com.sun.star.beans.PropertySet" );
527 // aServices[ 5 ] = C2U( "com.sun.star.drawing.FillProperties" );
528 // aServices[ 6 ] = C2U( "com.sun.star.drawing.LineProperties" );
530 return aServices;
533 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
534 APPHELPER_XSERVICEINFO_IMPL( TitleWrapper, lcl_aServiceName );
536 } // namespace wrapper
537 } // namespace chart