cURL: follow redirects
[LibreOffice.git] / reportdesign / source / core / api / Shape.cxx
blobbfbe296ae6b01f587566bf61a77c7d2bc14d4d7b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
19 #include "Shape.hxx"
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"
34 #include "Tools.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()
46 const OUString pProps[] = {
47 OUString(PROPERTY_DATAFIELD)
48 ,OUString(PROPERTY_CONTROLBACKGROUND)
49 ,OUString(PROPERTY_CONTROLBACKGROUNDTRANSPARENT)
51 return uno::Sequence< OUString >(pProps,SAL_N_ELEMENTS(pProps));
55 OShape::OShape(uno::Reference< uno::XComponentContext > const & _xContext)
56 :ShapeBase(m_aMutex)
57 ,ShapePropertySet(_xContext,static_cast< Implements >(IMPLEMENTS_PROPERTY_SET),lcl_getShapeOptionals())
58 ,m_aProps(m_aMutex,static_cast< container::XContainer*>( this ),_xContext)
59 ,m_nZOrder(0)
60 ,m_bOpaque(false)
62 m_aProps.aComponent.m_sName = RPT_RESSTRING(RID_STR_SHAPE);
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)
69 :ShapeBase(m_aMutex)
70 ,ShapePropertySet(_xContext,static_cast< Implements >(IMPLEMENTS_PROPERTY_SET),lcl_getShapeOptionals())
71 ,m_aProps(m_aMutex,static_cast< container::XContainer*>( this ),_xContext)
72 ,m_nZOrder(0)
73 ,m_bOpaque(false)
74 ,m_sServiceName(_sServiceName)
76 m_aProps.aComponent.m_sName = RPT_RESSTRING(RID_STR_SHAPE);
77 m_aProps.aComponent.m_xFactory = _xFactory;
78 osl_atomic_increment( &m_refCount );
80 uno::Reference<beans::XPropertySet> xProp(_xShape,uno::UNO_QUERY);
81 if ( xProp.is() )
83 xProp->getPropertyValue(PROPERTY_ZORDER) >>= m_nZOrder;
84 xProp.clear();
86 m_aProps.aComponent.setShape(_xShape,this,m_refCount);
88 osl_atomic_decrement( &m_refCount );
91 OShape::~OShape()
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) )
105 return aReturn;
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 { SERVICE_SHAPE };
138 return aServices;
141 uno::Sequence< OUString > SAL_CALL OShape::getSupportedServiceNames( ) throw(uno::RuntimeException, std::exception)
143 if(m_sServiceName.isEmpty())
145 return getSupportedServiceNames_Static();
147 else
149 uno::Sequence< OUString > aServices(2);
150 aServices.getArray()[0] = SERVICE_SHAPE;
151 aServices.getArray()[1] = m_sServiceName;
153 return aServices;
157 sal_Bool SAL_CALL OShape::supportsService(const OUString& ServiceName) throw( uno::RuntimeException, std::exception )
159 return cppu::supportsService(this, ServiceName);
162 // XReportComponent
163 REPORTCOMPONENT_IMPL(OShape,m_aProps.aComponent)
164 REPORTCOMPONENT_IMPL2(OShape,m_aProps.aComponent)
165 REPORTCOMPONENT_MASTERDETAIL(OShape,m_aProps.aComponent)
166 REPORTCONTROLFORMAT_IMPL2(OShape,m_aProps.aFormatProperties)
168 ::sal_Int32 SAL_CALL OShape::getControlBackground() throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
170 throw beans::UnknownPropertyException();
173 void SAL_CALL OShape::setControlBackground( ::sal_Int32 /*_backgroundcolor*/ ) throw (uno::RuntimeException,beans::UnknownPropertyException, std::exception)
175 throw beans::UnknownPropertyException();
178 sal_Bool SAL_CALL OShape::getControlBackgroundTransparent() throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
180 throw beans::UnknownPropertyException();
183 void SAL_CALL OShape::setControlBackgroundTransparent( sal_Bool /*_controlbackgroundtransparent*/ ) throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
185 throw beans::UnknownPropertyException();
188 uno::Reference< beans::XPropertySetInfo > SAL_CALL OShape::getPropertySetInfo( ) throw(uno::RuntimeException, std::exception)
191 //return ShapePropertySet::getPropertySetInfo();
192 return cppu::OPropertySetHelper::createPropertySetInfo( getInfoHelper() );
195 cppu::IPropertyArrayHelper& OShape::getInfoHelper()
197 if ( !m_pAggHelper.get() )
199 uno::Sequence<beans::Property> aAggSeq;
200 if ( m_aProps.aComponent.m_xProperty.is() )
201 aAggSeq = m_aProps.aComponent.m_xProperty->getPropertySetInfo()->getProperties();
202 m_pAggHelper.reset(new OPropertyArrayAggregationHelper(ShapePropertySet::getPropertySetInfo()->getProperties(),aAggSeq));
204 return *(m_pAggHelper.get());
208 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)
210 getInfoHelper();
211 if( m_pAggHelper->classifyProperty(aPropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Aggregate )
212 m_aProps.aComponent.m_xProperty->setPropertyValue( aPropertyName,aValue);
213 // can be in both
214 if( m_pAggHelper->classifyProperty(aPropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Delegator )
215 ShapePropertySet::setPropertyValue( aPropertyName, aValue );
218 uno::Any SAL_CALL OShape::getPropertyValue( const OUString& PropertyName ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
220 getInfoHelper();
221 if( m_pAggHelper->classifyProperty(PropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Aggregate )
222 return m_aProps.aComponent.m_xProperty->getPropertyValue( PropertyName);
223 // can be in both
224 if( m_pAggHelper->classifyProperty(PropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Delegator )
225 return ShapePropertySet::getPropertyValue( PropertyName);
226 return uno::Any();
229 void SAL_CALL OShape::addPropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& xListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
231 getInfoHelper();
232 if( m_pAggHelper->classifyProperty(aPropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Aggregate || aPropertyName.isEmpty() )
233 m_aProps.aComponent.m_xProperty->addPropertyChangeListener( aPropertyName, xListener);
234 // can be in both
235 if( m_pAggHelper->classifyProperty(aPropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Delegator || aPropertyName.isEmpty() )
236 ShapePropertySet::addPropertyChangeListener( aPropertyName, xListener );
239 void SAL_CALL OShape::removePropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& aListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
241 getInfoHelper();
242 if( m_pAggHelper->classifyProperty(aPropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Aggregate || aPropertyName.isEmpty() )
243 m_aProps.aComponent.m_xProperty->removePropertyChangeListener( aPropertyName, aListener );
244 // can be in both
245 if( m_pAggHelper->classifyProperty(aPropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Delegator || aPropertyName.isEmpty() )
246 ShapePropertySet::removePropertyChangeListener( aPropertyName, aListener );
249 void SAL_CALL OShape::addVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
251 getInfoHelper();
252 if( m_pAggHelper->classifyProperty(PropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Aggregate || PropertyName.isEmpty() )
253 m_aProps.aComponent.m_xProperty->addVetoableChangeListener( PropertyName, aListener );
254 // can be in both
255 if( m_pAggHelper->classifyProperty(PropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Delegator || PropertyName.isEmpty() )
256 ShapePropertySet::addVetoableChangeListener( PropertyName, aListener );
259 void SAL_CALL OShape::removeVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
261 getInfoHelper();
262 if( m_pAggHelper->classifyProperty(PropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Aggregate || PropertyName.isEmpty() )
263 m_aProps.aComponent.m_xProperty->removeVetoableChangeListener( PropertyName, aListener );
264 // can be in both
265 if( m_pAggHelper->classifyProperty(PropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Delegator || PropertyName.isEmpty() )
266 ShapePropertySet::removeVetoableChangeListener( PropertyName, aListener );
269 // XReportControlModel
270 OUString SAL_CALL OShape::getDataField() throw ( beans::UnknownPropertyException, uno::RuntimeException, std::exception)
272 throw beans::UnknownPropertyException();
275 void SAL_CALL OShape::setDataField( const OUString& /*_datafield*/ ) throw (lang::IllegalArgumentException, beans::UnknownPropertyException, uno::RuntimeException, std::exception)
277 throw beans::UnknownPropertyException();
280 sal_Bool SAL_CALL OShape::getPrintWhenGroupChange() throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
282 ::osl::MutexGuard aGuard(m_aMutex);
283 return m_aProps.bPrintWhenGroupChange;
286 void SAL_CALL OShape::setPrintWhenGroupChange( sal_Bool _printwhengroupchange ) throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
288 set(PROPERTY_PRINTWHENGROUPCHANGE,_printwhengroupchange,m_aProps.bPrintWhenGroupChange);
291 OUString SAL_CALL OShape::getConditionalPrintExpression() throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
293 ::osl::MutexGuard aGuard(m_aMutex);
294 return m_aProps.aConditionalPrintExpression;
297 void SAL_CALL OShape::setConditionalPrintExpression( const OUString& _conditionalprintexpression ) throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
299 set(PROPERTY_CONDITIONALPRINTEXPRESSION,_conditionalprintexpression,m_aProps.aConditionalPrintExpression);
303 // XCloneable
304 uno::Reference< util::XCloneable > SAL_CALL OShape::createClone( ) throw (uno::RuntimeException, std::exception)
306 uno::Reference< report::XReportComponent> xSource = this;
307 uno::Reference< report::XReportComponent> xSet;
310 SvxShape* pShape = SvxShape::getImplementation( xSource );
311 if ( pShape )
313 SdrObject* pObject = pShape->GetSdrObject();
314 if ( pObject )
316 SdrObject* pClone = pObject->Clone();
317 if ( pClone )
319 xSet.set(pClone->getUnoShape(),uno::UNO_QUERY_THROW );
324 catch(const uno::Exception&)
326 DBG_UNHANDLED_EXCEPTION();
328 return xSet.get();
331 // XChild
332 uno::Reference< uno::XInterface > SAL_CALL OShape::getParent( ) throw (uno::RuntimeException, std::exception)
334 return OShapeHelper::getParent(this);
337 void SAL_CALL OShape::setParent( const uno::Reference< uno::XInterface >& Parent ) throw (lang::NoSupportException, uno::RuntimeException, std::exception)
339 ::osl::MutexGuard aGuard(m_aMutex);
340 m_aProps.aComponent.m_xParent = uno::Reference< container::XChild >(Parent,uno::UNO_QUERY);
342 uno::Reference< report::XFormatCondition > SAL_CALL OShape::createFormatCondition( ) throw (uno::Exception, uno::RuntimeException, std::exception)
344 return new OFormatCondition(m_aProps.aComponent.m_xContext);
347 // XContainer
348 void SAL_CALL OShape::addContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException, std::exception)
350 m_aProps.addContainerListener(xListener);
353 void SAL_CALL OShape::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException, std::exception)
355 m_aProps.removeContainerListener(xListener);
358 // XElementAccess
359 uno::Type SAL_CALL OShape::getElementType( ) throw (uno::RuntimeException, std::exception)
361 return cppu::UnoType<report::XFormatCondition>::get();
364 sal_Bool SAL_CALL OShape::hasElements( ) throw (uno::RuntimeException, std::exception)
366 return m_aProps.hasElements();
369 // XIndexContainer
370 void SAL_CALL OShape::insertByIndex( ::sal_Int32 Index, const uno::Any& Element ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
372 m_aProps.insertByIndex(Index,Element);
375 void SAL_CALL OShape::removeByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
377 m_aProps.removeByIndex(Index);
380 // XIndexReplace
381 void SAL_CALL OShape::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
383 m_aProps.replaceByIndex(Index,Element);
386 // XIndexAccess
387 ::sal_Int32 SAL_CALL OShape::getCount( ) throw (uno::RuntimeException, std::exception)
389 return m_aProps.getCount();
392 uno::Any SAL_CALL OShape::getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
394 return m_aProps.getByIndex( Index );
397 // XShape
398 awt::Point SAL_CALL OShape::getPosition( ) throw (uno::RuntimeException, std::exception)
400 return OShapeHelper::getPosition(this);
403 void SAL_CALL OShape::setPosition( const awt::Point& aPosition ) throw (uno::RuntimeException, std::exception)
405 OShapeHelper::setPosition(aPosition,this);
408 awt::Size SAL_CALL OShape::getSize( ) throw (uno::RuntimeException, std::exception)
410 return OShapeHelper::getSize(this);
413 void SAL_CALL OShape::setSize( const awt::Size& aSize ) throw (beans::PropertyVetoException, uno::RuntimeException, std::exception)
415 OShapeHelper::setSize(aSize,this);
419 // XShapeDescriptor
420 OUString SAL_CALL OShape::getShapeType( ) throw (uno::RuntimeException, std::exception)
422 ::osl::MutexGuard aGuard(m_aMutex);
423 if ( m_aProps.aComponent.m_xShape.is() )
424 return m_aProps.aComponent.m_xShape->getShapeType();
425 return OUString("com.sun.star.drawing.CustomShape");
428 ::sal_Int32 SAL_CALL OShape::getZOrder() throw (uno::RuntimeException, std::exception)
430 ::osl::MutexGuard aGuard(m_aMutex);
431 m_aProps.aComponent.m_xProperty->getPropertyValue(PROPERTY_ZORDER) >>= m_nZOrder;
432 return m_nZOrder;
435 void SAL_CALL OShape::setZOrder( ::sal_Int32 _zorder ) throw (uno::RuntimeException, std::exception)
437 ::osl::MutexGuard aGuard(m_aMutex);
438 m_aProps.aComponent.m_xProperty->setPropertyValue(PROPERTY_ZORDER,uno::makeAny(_zorder));
439 set(PROPERTY_ZORDER,_zorder,m_nZOrder);
442 sal_Bool SAL_CALL OShape::getOpaque() throw (css::uno::RuntimeException, std::exception)
444 ::osl::MutexGuard aGuard(m_aMutex);
445 return m_bOpaque;
448 void SAL_CALL OShape::setOpaque( sal_Bool _opaque ) throw (css::uno::RuntimeException, std::exception)
450 ::osl::MutexGuard aGuard(m_aMutex);
451 set(PROPERTY_OPAQUE,_opaque,m_bOpaque);
454 drawing::HomogenMatrix3 SAL_CALL OShape::getTransformation() throw (uno::RuntimeException, std::exception)
456 ::osl::MutexGuard aGuard(m_aMutex);
457 m_aProps.aComponent.m_xProperty->getPropertyValue(PROPERTY_TRANSFORMATION) >>= m_Transformation;
458 return m_Transformation;
461 void SAL_CALL OShape::setTransformation( const drawing::HomogenMatrix3& _transformation ) throw (uno::RuntimeException, std::exception)
463 m_aProps.aComponent.m_xProperty->setPropertyValue(PROPERTY_TRANSFORMATION,uno::makeAny(_transformation));
464 set(PROPERTY_TRANSFORMATION,_transformation,m_Transformation);
467 OUString SAL_CALL OShape::getCustomShapeEngine() throw (uno::RuntimeException, std::exception)
469 ::osl::MutexGuard aGuard(m_aMutex);
470 m_aProps.aComponent.m_xProperty->getPropertyValue(PROPERTY_CUSTOMSHAPEENGINE) >>= m_CustomShapeEngine;
472 return m_CustomShapeEngine;
475 void SAL_CALL OShape::setCustomShapeEngine( const OUString& _customshapeengine ) throw (uno::RuntimeException, std::exception)
477 m_aProps.aComponent.m_xProperty->setPropertyValue(PROPERTY_CUSTOMSHAPEENGINE,uno::makeAny(_customshapeengine));
478 set(PROPERTY_CUSTOMSHAPEENGINE,_customshapeengine,m_CustomShapeEngine);
481 OUString SAL_CALL OShape::getCustomShapeData() throw (uno::RuntimeException, std::exception)
483 ::osl::MutexGuard aGuard(m_aMutex);
484 m_aProps.aComponent.m_xProperty->getPropertyValue(PROPERTY_CUSTOMSHAPEDATA) >>= m_CustomShapeData;
485 return m_CustomShapeData;
488 void SAL_CALL OShape::setCustomShapeData( const OUString& _customshapedata ) throw (uno::RuntimeException, std::exception)
490 m_aProps.aComponent.m_xProperty->setPropertyValue(PROPERTY_CUSTOMSHAPEDATA,uno::makeAny(_customshapedata));
491 set(PROPERTY_CUSTOMSHAPEDATA,_customshapedata,m_CustomShapeData);
494 uno::Sequence< beans::PropertyValue > SAL_CALL OShape::getCustomShapeGeometry() throw (uno::RuntimeException, std::exception)
496 ::osl::MutexGuard aGuard(m_aMutex);
497 m_aProps.aComponent.m_xProperty->getPropertyValue(PROPERTY_CUSTOMSHAPEGEOMETRY) >>= m_CustomShapeGeometry;
498 return m_CustomShapeGeometry;
501 void SAL_CALL OShape::setCustomShapeGeometry( const uno::Sequence< beans::PropertyValue >& _customshapegeometry ) throw (uno::RuntimeException, std::exception)
503 m_aProps.aComponent.m_xProperty->setPropertyValue(PROPERTY_CUSTOMSHAPEGEOMETRY,uno::makeAny(_customshapegeometry));
504 set(PROPERTY_CUSTOMSHAPEGEOMETRY,_customshapegeometry,m_CustomShapeGeometry);
508 }// namespace reportdesign
511 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */