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 .
21 #include <com/sun/star/beans/NamedValue.hpp>
22 #include <com/sun/star/beans/PropertyAttribute.hpp>
23 #include <com/sun/star/beans/XPropertyState.hpp>
24 #include <com/sun/star/text/ParagraphVertAlign.hpp>
25 #include <comphelper/property.hxx>
26 #include <cppuhelper/supportsservice.hxx>
27 #include <tools/debug.hxx>
28 #include <tools/diagnose_ex.h>
29 #include <svx/unoshape.hxx>
31 #include "corestrings.hrc"
32 #include "core_resource.hrc"
33 #include "core_resource.hxx"
35 #include "RptObject.hxx"
36 #include "FormatCondition.hxx"
37 #include "ReportHelperImpl.hxx"
39 namespace reportdesign
42 using namespace com::sun::star
;
43 using namespace comphelper
;
44 uno::Sequence
< OUString
> lcl_getShapeOptionals()
47 OUString(PROPERTY_DATAFIELD
)
48 ,OUString(PROPERTY_CONTROLBACKGROUND
)
49 ,OUString(PROPERTY_CONTROLBACKGROUNDTRANSPARENT
)
51 return uno::Sequence
< OUString
>(pProps
,sizeof(pProps
)/sizeof(pProps
[0]));
55 OShape::OShape(uno::Reference
< uno::XComponentContext
> const & _xContext
)
57 ,ShapePropertySet(_xContext
,static_cast< Implements
>(IMPLEMENTS_PROPERTY_SET
),lcl_getShapeOptionals())
58 ,m_aProps(m_aMutex
,static_cast< container::XContainer
*>( this ),_xContext
)
62 m_aProps
.aComponent
.m_sName
= RPT_RESSTRING(RID_STR_SHAPE
,m_aProps
.aComponent
.m_xContext
->getServiceManager());
65 OShape::OShape(uno::Reference
< uno::XComponentContext
> const & _xContext
66 ,const uno::Reference
< lang::XMultiServiceFactory
>& _xFactory
67 ,uno::Reference
< drawing::XShape
>& _xShape
68 ,const OUString
& _sServiceName
)
70 ,ShapePropertySet(_xContext
,static_cast< Implements
>(IMPLEMENTS_PROPERTY_SET
),lcl_getShapeOptionals())
71 ,m_aProps(m_aMutex
,static_cast< container::XContainer
*>( this ),_xContext
)
74 ,m_sServiceName(_sServiceName
)
76 m_aProps
.aComponent
.m_sName
= RPT_RESSTRING(RID_STR_SHAPE
,m_aProps
.aComponent
.m_xContext
->getServiceManager());
77 m_aProps
.aComponent
.m_xFactory
= _xFactory
;
78 osl_atomic_increment( &m_refCount
);
80 uno::Reference
<beans::XPropertySet
> xProp(_xShape
,uno::UNO_QUERY
);
83 xProp
->getPropertyValue(PROPERTY_ZORDER
) >>= m_nZOrder
;
86 m_aProps
.aComponent
.setShape(_xShape
,this,m_refCount
);
88 osl_atomic_decrement( &m_refCount
);
95 //IMPLEMENT_FORWARD_XINTERFACE2(OShape,ShapeBase,ShapePropertySet)
96 IMPLEMENT_FORWARD_REFCOUNT( OShape
, ShapeBase
)
98 uno::Any SAL_CALL
OShape::queryInterface( const uno::Type
& _rType
) throw (uno::RuntimeException
, std::exception
)
100 uno::Any aReturn
= ShapeBase::queryInterface(_rType
);
101 if ( !aReturn
.hasValue() )
102 aReturn
= ShapePropertySet::queryInterface(_rType
);
104 if ( !aReturn
.hasValue() && OReportControlModel::isInterfaceForbidden(_rType
) )
107 return aReturn
.hasValue() ? aReturn
: (m_aProps
.aComponent
.m_xProxy
.is() ? m_aProps
.aComponent
.m_xProxy
->queryAggregation(_rType
) : aReturn
);
111 void SAL_CALL
OShape::dispose() throw(uno::RuntimeException
, std::exception
)
113 ShapePropertySet::dispose();
114 cppu::WeakComponentImplHelperBase::dispose();
117 uno::Reference
< uno::XInterface
> OShape::create(uno::Reference
< uno::XComponentContext
> const & xContext
)
119 return *(new OShape(xContext
));
123 OUString
OShape::getImplementationName_Static( ) throw(uno::RuntimeException
)
125 return OUString("com.sun.star.comp.report.Shape");
129 OUString SAL_CALL
OShape::getImplementationName( ) throw(uno::RuntimeException
, std::exception
)
131 return getImplementationName_Static();
134 uno::Sequence
< OUString
> OShape::getSupportedServiceNames_Static( ) throw(uno::RuntimeException
)
136 uno::Sequence
< OUString
> aServices(1);
137 aServices
.getArray()[0] = SERVICE_SHAPE
;
142 uno::Sequence
< OUString
> SAL_CALL
OShape::getSupportedServiceNames( ) throw(uno::RuntimeException
, std::exception
)
144 if(m_sServiceName
.isEmpty())
146 return getSupportedServiceNames_Static();
150 uno::Sequence
< OUString
> aServices(2);
151 aServices
.getArray()[0] = SERVICE_SHAPE
;
152 aServices
.getArray()[1] = m_sServiceName
;
158 sal_Bool SAL_CALL
OShape::supportsService(const OUString
& ServiceName
) throw( uno::RuntimeException
, std::exception
)
160 return cppu::supportsService(this, ServiceName
);
164 REPORTCOMPONENT_IMPL(OShape
,m_aProps
.aComponent
)
165 REPORTCOMPONENT_IMPL2(OShape
,m_aProps
.aComponent
)
166 REPORTCOMPONENT_MASTERDETAIL(OShape
,m_aProps
.aComponent
)
167 REPORTCONTROLFORMAT_IMPL2(OShape
,m_aProps
.aFormatProperties
)
169 ::sal_Int32 SAL_CALL
OShape::getControlBackground() throw (beans::UnknownPropertyException
, uno::RuntimeException
, std::exception
)
171 throw beans::UnknownPropertyException();
174 void SAL_CALL
OShape::setControlBackground( ::sal_Int32
/*_backgroundcolor*/ ) throw (uno::RuntimeException
,beans::UnknownPropertyException
, std::exception
)
176 throw beans::UnknownPropertyException();
179 sal_Bool SAL_CALL
OShape::getControlBackgroundTransparent() throw (beans::UnknownPropertyException
, uno::RuntimeException
, std::exception
)
181 throw beans::UnknownPropertyException();
184 void SAL_CALL
OShape::setControlBackgroundTransparent( sal_Bool
/*_controlbackgroundtransparent*/ ) throw (beans::UnknownPropertyException
, uno::RuntimeException
, std::exception
)
186 throw beans::UnknownPropertyException();
189 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
OShape::getPropertySetInfo( ) throw(uno::RuntimeException
, std::exception
)
192 //return ShapePropertySet::getPropertySetInfo();
193 return cppu::OPropertySetHelper::createPropertySetInfo( getInfoHelper() );
196 cppu::IPropertyArrayHelper
& OShape::getInfoHelper()
198 if ( !m_pAggHelper
.get() )
200 uno::Sequence
<beans::Property
> aAggSeq
;
201 if ( m_aProps
.aComponent
.m_xProperty
.is() )
202 aAggSeq
= m_aProps
.aComponent
.m_xProperty
->getPropertySetInfo()->getProperties();
203 m_pAggHelper
.reset(new OPropertyArrayAggregationHelper(ShapePropertySet::getPropertySetInfo()->getProperties(),aAggSeq
));
205 return *(m_pAggHelper
.get());
209 void SAL_CALL
OShape::setPropertyValue( const OUString
& aPropertyName
, const uno::Any
& aValue
) throw (beans::UnknownPropertyException
, beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
212 if( m_pAggHelper
->classifyProperty(aPropertyName
) == OPropertyArrayAggregationHelper::AGGREGATE_PROPERTY
)
213 m_aProps
.aComponent
.m_xProperty
->setPropertyValue( aPropertyName
,aValue
);
215 if( m_pAggHelper
->classifyProperty(aPropertyName
) == OPropertyArrayAggregationHelper::DELEGATOR_PROPERTY
)
216 ShapePropertySet::setPropertyValue( aPropertyName
, aValue
);
219 uno::Any SAL_CALL
OShape::getPropertyValue( const OUString
& PropertyName
) throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
222 if( m_pAggHelper
->classifyProperty(PropertyName
) == OPropertyArrayAggregationHelper::AGGREGATE_PROPERTY
)
223 return m_aProps
.aComponent
.m_xProperty
->getPropertyValue( PropertyName
);
225 if( m_pAggHelper
->classifyProperty(PropertyName
) == OPropertyArrayAggregationHelper::DELEGATOR_PROPERTY
)
226 return ShapePropertySet::getPropertyValue( PropertyName
);
230 void SAL_CALL
OShape::addPropertyChangeListener( const OUString
& aPropertyName
, const uno::Reference
< beans::XPropertyChangeListener
>& xListener
) throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
233 if( m_pAggHelper
->classifyProperty(aPropertyName
) == OPropertyArrayAggregationHelper::AGGREGATE_PROPERTY
|| aPropertyName
.isEmpty() )
234 m_aProps
.aComponent
.m_xProperty
->addPropertyChangeListener( aPropertyName
, xListener
);
236 if( m_pAggHelper
->classifyProperty(aPropertyName
) == OPropertyArrayAggregationHelper::DELEGATOR_PROPERTY
|| aPropertyName
.isEmpty() )
237 ShapePropertySet::addPropertyChangeListener( aPropertyName
, xListener
);
240 void SAL_CALL
OShape::removePropertyChangeListener( const OUString
& aPropertyName
, const uno::Reference
< beans::XPropertyChangeListener
>& aListener
) throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
243 if( m_pAggHelper
->classifyProperty(aPropertyName
) == OPropertyArrayAggregationHelper::AGGREGATE_PROPERTY
|| aPropertyName
.isEmpty() )
244 m_aProps
.aComponent
.m_xProperty
->removePropertyChangeListener( aPropertyName
, aListener
);
246 if( m_pAggHelper
->classifyProperty(aPropertyName
) == OPropertyArrayAggregationHelper::DELEGATOR_PROPERTY
|| aPropertyName
.isEmpty() )
247 ShapePropertySet::removePropertyChangeListener( aPropertyName
, aListener
);
250 void SAL_CALL
OShape::addVetoableChangeListener( const OUString
& PropertyName
, const uno::Reference
< beans::XVetoableChangeListener
>& aListener
) throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
253 if( m_pAggHelper
->classifyProperty(PropertyName
) == OPropertyArrayAggregationHelper::AGGREGATE_PROPERTY
|| PropertyName
.isEmpty() )
254 m_aProps
.aComponent
.m_xProperty
->addVetoableChangeListener( PropertyName
, aListener
);
256 if( m_pAggHelper
->classifyProperty(PropertyName
) == OPropertyArrayAggregationHelper::DELEGATOR_PROPERTY
|| PropertyName
.isEmpty() )
257 ShapePropertySet::addVetoableChangeListener( PropertyName
, aListener
);
260 void SAL_CALL
OShape::removeVetoableChangeListener( const OUString
& PropertyName
, const uno::Reference
< beans::XVetoableChangeListener
>& aListener
) throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
263 if( m_pAggHelper
->classifyProperty(PropertyName
) == OPropertyArrayAggregationHelper::AGGREGATE_PROPERTY
|| PropertyName
.isEmpty() )
264 m_aProps
.aComponent
.m_xProperty
->removeVetoableChangeListener( PropertyName
, aListener
);
266 if( m_pAggHelper
->classifyProperty(PropertyName
) == OPropertyArrayAggregationHelper::DELEGATOR_PROPERTY
|| PropertyName
.isEmpty() )
267 ShapePropertySet::removeVetoableChangeListener( PropertyName
, aListener
);
270 // XReportControlModel
271 OUString SAL_CALL
OShape::getDataField() throw ( beans::UnknownPropertyException
, uno::RuntimeException
, std::exception
)
273 throw beans::UnknownPropertyException();
276 void SAL_CALL
OShape::setDataField( const OUString
& /*_datafield*/ ) throw (lang::IllegalArgumentException
, beans::UnknownPropertyException
, uno::RuntimeException
, std::exception
)
278 throw beans::UnknownPropertyException();
281 sal_Bool SAL_CALL
OShape::getPrintWhenGroupChange() throw (beans::UnknownPropertyException
, uno::RuntimeException
, std::exception
)
283 ::osl::MutexGuard
aGuard(m_aMutex
);
284 return m_aProps
.bPrintWhenGroupChange
;
287 void SAL_CALL
OShape::setPrintWhenGroupChange( sal_Bool _printwhengroupchange
) throw (beans::UnknownPropertyException
, uno::RuntimeException
, std::exception
)
289 set(PROPERTY_PRINTWHENGROUPCHANGE
,_printwhengroupchange
,m_aProps
.bPrintWhenGroupChange
);
292 OUString SAL_CALL
OShape::getConditionalPrintExpression() throw (beans::UnknownPropertyException
, uno::RuntimeException
, std::exception
)
294 ::osl::MutexGuard
aGuard(m_aMutex
);
295 return m_aProps
.aConditionalPrintExpression
;
298 void SAL_CALL
OShape::setConditionalPrintExpression( const OUString
& _conditionalprintexpression
) throw (beans::UnknownPropertyException
, uno::RuntimeException
, std::exception
)
300 set(PROPERTY_CONDITIONALPRINTEXPRESSION
,_conditionalprintexpression
,m_aProps
.aConditionalPrintExpression
);
305 uno::Reference
< util::XCloneable
> SAL_CALL
OShape::createClone( ) throw (uno::RuntimeException
, std::exception
)
307 uno::Reference
< report::XReportComponent
> xSource
= this;
308 uno::Reference
< report::XReportComponent
> xSet
;
311 SvxShape
* pShape
= SvxShape::getImplementation( xSource
);
314 SdrObject
* pObject
= pShape
->GetSdrObject();
317 SdrObject
* pClone
= pObject
->Clone();
320 xSet
.set(pClone
->getUnoShape(),uno::UNO_QUERY_THROW
);
325 catch(const uno::Exception
&)
327 DBG_UNHANDLED_EXCEPTION();
333 uno::Reference
< uno::XInterface
> SAL_CALL
OShape::getParent( ) throw (uno::RuntimeException
, std::exception
)
335 return OShapeHelper::getParent(this);
338 void SAL_CALL
OShape::setParent( const uno::Reference
< uno::XInterface
>& Parent
) throw (lang::NoSupportException
, uno::RuntimeException
, std::exception
)
340 ::osl::MutexGuard
aGuard(m_aMutex
);
341 m_aProps
.aComponent
.m_xParent
= uno::Reference
< container::XChild
>(Parent
,uno::UNO_QUERY
);
343 uno::Reference
< report::XFormatCondition
> SAL_CALL
OShape::createFormatCondition( ) throw (uno::Exception
, uno::RuntimeException
, std::exception
)
345 return new OFormatCondition(m_aProps
.aComponent
.m_xContext
);
349 void SAL_CALL
OShape::addContainerListener( const uno::Reference
< container::XContainerListener
>& xListener
) throw (uno::RuntimeException
, std::exception
)
351 m_aProps
.addContainerListener(xListener
);
354 void SAL_CALL
OShape::removeContainerListener( const uno::Reference
< container::XContainerListener
>& xListener
) throw (uno::RuntimeException
, std::exception
)
356 m_aProps
.removeContainerListener(xListener
);
360 uno::Type SAL_CALL
OShape::getElementType( ) throw (uno::RuntimeException
, std::exception
)
362 return cppu::UnoType
<report::XFormatCondition
>::get();
365 sal_Bool SAL_CALL
OShape::hasElements( ) throw (uno::RuntimeException
, std::exception
)
367 return m_aProps
.hasElements();
371 void SAL_CALL
OShape::insertByIndex( ::sal_Int32 Index
, const uno::Any
& Element
) throw (lang::IllegalArgumentException
, lang::IndexOutOfBoundsException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
373 m_aProps
.insertByIndex(Index
,Element
);
376 void SAL_CALL
OShape::removeByIndex( ::sal_Int32 Index
) throw (lang::IndexOutOfBoundsException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
378 m_aProps
.removeByIndex(Index
);
382 void SAL_CALL
OShape::replaceByIndex( ::sal_Int32 Index
, const uno::Any
& Element
) throw (lang::IllegalArgumentException
, lang::IndexOutOfBoundsException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
384 m_aProps
.replaceByIndex(Index
,Element
);
388 ::sal_Int32 SAL_CALL
OShape::getCount( ) throw (uno::RuntimeException
, std::exception
)
390 return m_aProps
.getCount();
393 uno::Any SAL_CALL
OShape::getByIndex( ::sal_Int32 Index
) throw (lang::IndexOutOfBoundsException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
395 return m_aProps
.getByIndex( Index
);
399 awt::Point SAL_CALL
OShape::getPosition( ) throw (uno::RuntimeException
, std::exception
)
401 return OShapeHelper::getPosition(this);
404 void SAL_CALL
OShape::setPosition( const awt::Point
& aPosition
) throw (uno::RuntimeException
, std::exception
)
406 OShapeHelper::setPosition(aPosition
,this);
409 awt::Size SAL_CALL
OShape::getSize( ) throw (uno::RuntimeException
, std::exception
)
411 return OShapeHelper::getSize(this);
414 void SAL_CALL
OShape::setSize( const awt::Size
& aSize
) throw (beans::PropertyVetoException
, uno::RuntimeException
, std::exception
)
416 OShapeHelper::setSize(aSize
,this);
421 OUString SAL_CALL
OShape::getShapeType( ) throw (uno::RuntimeException
, std::exception
)
423 ::osl::MutexGuard
aGuard(m_aMutex
);
424 if ( m_aProps
.aComponent
.m_xShape
.is() )
425 return m_aProps
.aComponent
.m_xShape
->getShapeType();
426 return OUString("com.sun.star.drawing.CustomShape");
429 ::sal_Int32 SAL_CALL
OShape::getZOrder() throw (uno::RuntimeException
, std::exception
)
431 ::osl::MutexGuard
aGuard(m_aMutex
);
432 m_aProps
.aComponent
.m_xProperty
->getPropertyValue(PROPERTY_ZORDER
) >>= m_nZOrder
;
436 void SAL_CALL
OShape::setZOrder( ::sal_Int32 _zorder
) throw (uno::RuntimeException
, std::exception
)
438 ::osl::MutexGuard
aGuard(m_aMutex
);
439 m_aProps
.aComponent
.m_xProperty
->setPropertyValue(PROPERTY_ZORDER
,uno::makeAny(_zorder
));
440 set(PROPERTY_ZORDER
,_zorder
,m_nZOrder
);
443 sal_Bool SAL_CALL
OShape::getOpaque() throw (::com::sun::star::uno::RuntimeException
, std::exception
)
445 ::osl::MutexGuard
aGuard(m_aMutex
);
449 void SAL_CALL
OShape::setOpaque( sal_Bool _opaque
) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
451 ::osl::MutexGuard
aGuard(m_aMutex
);
452 set(PROPERTY_OPAQUE
,_opaque
,m_bOpaque
);
455 drawing::HomogenMatrix3 SAL_CALL
OShape::getTransformation() throw (uno::RuntimeException
, std::exception
)
457 ::osl::MutexGuard
aGuard(m_aMutex
);
458 m_aProps
.aComponent
.m_xProperty
->getPropertyValue(PROPERTY_TRANSFORMATION
) >>= m_Transformation
;
459 return m_Transformation
;
462 void SAL_CALL
OShape::setTransformation( const drawing::HomogenMatrix3
& _transformation
) throw (uno::RuntimeException
, std::exception
)
464 m_aProps
.aComponent
.m_xProperty
->setPropertyValue(PROPERTY_TRANSFORMATION
,uno::makeAny(_transformation
));
465 set(PROPERTY_TRANSFORMATION
,_transformation
,m_Transformation
);
468 OUString SAL_CALL
OShape::getCustomShapeEngine() throw (uno::RuntimeException
, std::exception
)
470 ::osl::MutexGuard
aGuard(m_aMutex
);
471 m_aProps
.aComponent
.m_xProperty
->getPropertyValue(PROPERTY_CUSTOMSHAPEENGINE
) >>= m_CustomShapeEngine
;
473 return m_CustomShapeEngine
;
476 void SAL_CALL
OShape::setCustomShapeEngine( const OUString
& _customshapeengine
) throw (uno::RuntimeException
, std::exception
)
478 m_aProps
.aComponent
.m_xProperty
->setPropertyValue(PROPERTY_CUSTOMSHAPEENGINE
,uno::makeAny(_customshapeengine
));
479 set(PROPERTY_CUSTOMSHAPEENGINE
,_customshapeengine
,m_CustomShapeEngine
);
482 OUString SAL_CALL
OShape::getCustomShapeData() throw (uno::RuntimeException
, std::exception
)
484 ::osl::MutexGuard
aGuard(m_aMutex
);
485 m_aProps
.aComponent
.m_xProperty
->getPropertyValue(PROPERTY_CUSTOMSHAPEDATA
) >>= m_CustomShapeData
;
486 return m_CustomShapeData
;
489 void SAL_CALL
OShape::setCustomShapeData( const OUString
& _customshapedata
) throw (uno::RuntimeException
, std::exception
)
491 m_aProps
.aComponent
.m_xProperty
->setPropertyValue(PROPERTY_CUSTOMSHAPEDATA
,uno::makeAny(_customshapedata
));
492 set(PROPERTY_CUSTOMSHAPEDATA
,_customshapedata
,m_CustomShapeData
);
495 uno::Sequence
< beans::PropertyValue
> SAL_CALL
OShape::getCustomShapeGeometry() throw (uno::RuntimeException
, std::exception
)
497 ::osl::MutexGuard
aGuard(m_aMutex
);
498 m_aProps
.aComponent
.m_xProperty
->getPropertyValue(PROPERTY_CUSTOMSHAPEGEOMETRY
) >>= m_CustomShapeGeometry
;
499 return m_CustomShapeGeometry
;
502 void SAL_CALL
OShape::setCustomShapeGeometry( const uno::Sequence
< beans::PropertyValue
>& _customshapegeometry
) throw (uno::RuntimeException
, std::exception
)
504 m_aProps
.aComponent
.m_xProperty
->setPropertyValue(PROPERTY_CUSTOMSHAPEGEOMETRY
,uno::makeAny(_customshapegeometry
));
505 set(PROPERTY_CUSTOMSHAPEGEOMETRY
,_customshapegeometry
,m_CustomShapeGeometry
);
511 }// namespace reportdesign
514 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */