lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / reportdesign / source / core / api / Shape.cxx
blob5b59b8924b3007afbd751fc43fe1773704ca117a
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 <cppuhelper/supportsservice.hxx>
26 #include <tools/debug.hxx>
27 #include <tools/diagnose_ex.h>
28 #include <svx/unoshape.hxx>
30 #include <strings.hxx>
31 #include <strings.hrc>
32 #include <core_resource.hxx>
33 #include <Tools.hxx>
34 #include <RptObject.hxx>
35 #include <FormatCondition.hxx>
36 #include <ReportHelperImpl.hxx>
38 namespace reportdesign
41 using namespace com::sun::star;
42 using namespace comphelper;
43 static uno::Sequence< OUString > lcl_getShapeOptionals()
45 const OUString pProps[] = {
46 OUString(PROPERTY_DATAFIELD)
47 ,OUString(PROPERTY_CONTROLBACKGROUND)
48 ,OUString(PROPERTY_CONTROLBACKGROUNDTRANSPARENT)
50 return uno::Sequence< OUString >(pProps,SAL_N_ELEMENTS(pProps));
54 OShape::OShape(uno::Reference< uno::XComponentContext > const & _xContext)
55 :ShapeBase(m_aMutex)
56 ,ShapePropertySet(_xContext,IMPLEMENTS_PROPERTY_SET,lcl_getShapeOptionals())
57 ,m_aProps(m_aMutex,static_cast< container::XContainer*>( this ),_xContext)
58 ,m_nZOrder(0)
59 ,m_bOpaque(false)
61 m_aProps.aComponent.m_sName = RptResId(RID_STR_SHAPE);
64 OShape::OShape(uno::Reference< uno::XComponentContext > const & _xContext
65 ,const uno::Reference< lang::XMultiServiceFactory>& _xFactory
66 ,uno::Reference< drawing::XShape >& _xShape
67 ,const OUString& _sServiceName)
68 :ShapeBase(m_aMutex)
69 ,ShapePropertySet(_xContext,IMPLEMENTS_PROPERTY_SET,lcl_getShapeOptionals())
70 ,m_aProps(m_aMutex,static_cast< container::XContainer*>( this ),_xContext)
71 ,m_nZOrder(0)
72 ,m_bOpaque(false)
73 ,m_sServiceName(_sServiceName)
75 m_aProps.aComponent.m_sName = RptResId(RID_STR_SHAPE);
76 m_aProps.aComponent.m_xFactory = _xFactory;
77 osl_atomic_increment( &m_refCount );
79 uno::Reference<beans::XPropertySet> xProp(_xShape,uno::UNO_QUERY);
80 if ( xProp.is() )
82 xProp->getPropertyValue(PROPERTY_ZORDER) >>= m_nZOrder;
83 xProp.clear();
85 m_aProps.aComponent.setShape(_xShape,this,m_refCount);
87 osl_atomic_decrement( &m_refCount );
90 OShape::~OShape()
94 //IMPLEMENT_FORWARD_XINTERFACE2(OShape,ShapeBase,ShapePropertySet)
95 IMPLEMENT_FORWARD_REFCOUNT( OShape, ShapeBase )
97 uno::Any SAL_CALL OShape::queryInterface( const uno::Type& _rType )
99 uno::Any aReturn = ShapeBase::queryInterface(_rType);
100 if ( !aReturn.hasValue() )
101 aReturn = ShapePropertySet::queryInterface(_rType);
103 if ( !aReturn.hasValue() && OReportControlModel::isInterfaceForbidden(_rType) )
104 return aReturn;
106 return aReturn.hasValue() ? aReturn : (m_aProps.aComponent.m_xProxy.is() ? m_aProps.aComponent.m_xProxy->queryAggregation(_rType) : aReturn);
110 void SAL_CALL OShape::dispose()
112 ShapePropertySet::dispose();
113 cppu::WeakComponentImplHelperBase::dispose();
116 uno::Reference< uno::XInterface > OShape::create(uno::Reference< uno::XComponentContext > const & xContext)
118 return *(new OShape(xContext));
122 OUString OShape::getImplementationName_Static( )
124 return OUString("com.sun.star.comp.report.Shape");
128 OUString SAL_CALL OShape::getImplementationName( )
130 return getImplementationName_Static();
133 uno::Sequence< OUString > OShape::getSupportedServiceNames_Static( )
135 uno::Sequence< OUString > aServices { SERVICE_SHAPE };
137 return aServices;
140 uno::Sequence< OUString > SAL_CALL OShape::getSupportedServiceNames( )
142 if(m_sServiceName.isEmpty())
144 return getSupportedServiceNames_Static();
146 else
148 uno::Sequence< OUString > aServices(2);
149 aServices.getArray()[0] = SERVICE_SHAPE;
150 aServices.getArray()[1] = m_sServiceName;
152 return aServices;
156 sal_Bool SAL_CALL OShape::supportsService(const OUString& ServiceName)
158 return cppu::supportsService(this, ServiceName);
161 // XReportComponent
162 REPORTCOMPONENT_IMPL(OShape,m_aProps.aComponent)
163 REPORTCOMPONENT_IMPL2(OShape,m_aProps.aComponent)
164 REPORTCOMPONENT_MASTERDETAIL(OShape,m_aProps.aComponent)
165 REPORTCONTROLFORMAT_IMPL2(OShape,m_aProps.aFormatProperties)
167 ::sal_Int32 SAL_CALL OShape::getControlBackground()
169 throw beans::UnknownPropertyException();
172 void SAL_CALL OShape::setControlBackground( ::sal_Int32 /*_backgroundcolor*/ )
174 throw beans::UnknownPropertyException();
177 sal_Bool SAL_CALL OShape::getControlBackgroundTransparent()
179 throw beans::UnknownPropertyException();
182 void SAL_CALL OShape::setControlBackgroundTransparent( sal_Bool /*_controlbackgroundtransparent*/ )
184 throw beans::UnknownPropertyException();
187 uno::Reference< beans::XPropertySetInfo > SAL_CALL OShape::getPropertySetInfo( )
190 //return ShapePropertySet::getPropertySetInfo();
191 return cppu::OPropertySetHelper::createPropertySetInfo( getInfoHelper() );
194 cppu::IPropertyArrayHelper& OShape::getInfoHelper()
196 if (!m_pAggHelper)
198 uno::Sequence<beans::Property> aAggSeq;
199 if ( m_aProps.aComponent.m_xProperty.is() )
200 aAggSeq = m_aProps.aComponent.m_xProperty->getPropertySetInfo()->getProperties();
201 m_pAggHelper.reset(new OPropertyArrayAggregationHelper(ShapePropertySet::getPropertySetInfo()->getProperties(),aAggSeq));
203 return *(m_pAggHelper.get());
207 void SAL_CALL OShape::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
209 getInfoHelper();
210 if( m_pAggHelper->classifyProperty(aPropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Aggregate )
211 m_aProps.aComponent.m_xProperty->setPropertyValue( aPropertyName,aValue);
212 // can be in both
213 if( m_pAggHelper->classifyProperty(aPropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Delegator )
214 ShapePropertySet::setPropertyValue( aPropertyName, aValue );
217 uno::Any SAL_CALL OShape::getPropertyValue( const OUString& PropertyName )
219 getInfoHelper();
220 if( m_pAggHelper->classifyProperty(PropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Aggregate )
221 return m_aProps.aComponent.m_xProperty->getPropertyValue( PropertyName);
222 // can be in both
223 if( m_pAggHelper->classifyProperty(PropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Delegator )
224 return ShapePropertySet::getPropertyValue( PropertyName);
225 return uno::Any();
228 void SAL_CALL OShape::addPropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& xListener )
230 getInfoHelper();
231 if( m_pAggHelper->classifyProperty(aPropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Aggregate || aPropertyName.isEmpty() )
232 m_aProps.aComponent.m_xProperty->addPropertyChangeListener( aPropertyName, xListener);
233 // can be in both
234 if( m_pAggHelper->classifyProperty(aPropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Delegator || aPropertyName.isEmpty() )
235 ShapePropertySet::addPropertyChangeListener( aPropertyName, xListener );
238 void SAL_CALL OShape::removePropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& aListener )
240 getInfoHelper();
241 if( m_pAggHelper->classifyProperty(aPropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Aggregate || aPropertyName.isEmpty() )
242 m_aProps.aComponent.m_xProperty->removePropertyChangeListener( aPropertyName, aListener );
243 // can be in both
244 if( m_pAggHelper->classifyProperty(aPropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Delegator || aPropertyName.isEmpty() )
245 ShapePropertySet::removePropertyChangeListener( aPropertyName, aListener );
248 void SAL_CALL OShape::addVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener )
250 getInfoHelper();
251 if( m_pAggHelper->classifyProperty(PropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Aggregate || PropertyName.isEmpty() )
252 m_aProps.aComponent.m_xProperty->addVetoableChangeListener( PropertyName, aListener );
253 // can be in both
254 if( m_pAggHelper->classifyProperty(PropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Delegator || PropertyName.isEmpty() )
255 ShapePropertySet::addVetoableChangeListener( PropertyName, aListener );
258 void SAL_CALL OShape::removeVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener )
260 getInfoHelper();
261 if( m_pAggHelper->classifyProperty(PropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Aggregate || PropertyName.isEmpty() )
262 m_aProps.aComponent.m_xProperty->removeVetoableChangeListener( PropertyName, aListener );
263 // can be in both
264 if( m_pAggHelper->classifyProperty(PropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Delegator || PropertyName.isEmpty() )
265 ShapePropertySet::removeVetoableChangeListener( PropertyName, aListener );
268 // XReportControlModel
269 OUString SAL_CALL OShape::getDataField()
271 throw beans::UnknownPropertyException();
274 void SAL_CALL OShape::setDataField( const OUString& /*_datafield*/ )
276 throw beans::UnknownPropertyException();
279 sal_Bool SAL_CALL OShape::getPrintWhenGroupChange()
281 ::osl::MutexGuard aGuard(m_aMutex);
282 return m_aProps.bPrintWhenGroupChange;
285 void SAL_CALL OShape::setPrintWhenGroupChange( sal_Bool _printwhengroupchange )
287 set(PROPERTY_PRINTWHENGROUPCHANGE,_printwhengroupchange,m_aProps.bPrintWhenGroupChange);
290 OUString SAL_CALL OShape::getConditionalPrintExpression()
292 ::osl::MutexGuard aGuard(m_aMutex);
293 return m_aProps.aConditionalPrintExpression;
296 void SAL_CALL OShape::setConditionalPrintExpression( const OUString& _conditionalprintexpression )
298 set(PROPERTY_CONDITIONALPRINTEXPRESSION,_conditionalprintexpression,m_aProps.aConditionalPrintExpression);
302 // XCloneable
303 uno::Reference< util::XCloneable > SAL_CALL OShape::createClone( )
305 uno::Reference< report::XReportComponent> xSource = this;
306 uno::Reference< report::XReportComponent> xSet;
309 SvxShape* pShape = SvxShape::getImplementation( xSource );
310 if ( pShape )
312 SdrObject* pObject = pShape->GetSdrObject();
313 if ( pObject )
315 SdrObject* pClone(pObject->CloneSdrObject(pObject->getSdrModelFromSdrObject()));
316 if ( pClone )
318 xSet.set(pClone->getUnoShape(),uno::UNO_QUERY_THROW );
323 catch(const uno::Exception&)
325 DBG_UNHANDLED_EXCEPTION("reportdesign");
327 return xSet.get();
330 // XChild
331 uno::Reference< uno::XInterface > SAL_CALL OShape::getParent( )
333 return OShapeHelper::getParent(this);
336 void SAL_CALL OShape::setParent( const uno::Reference< uno::XInterface >& Parent )
338 ::osl::MutexGuard aGuard(m_aMutex);
339 m_aProps.aComponent.m_xParent = uno::Reference< container::XChild >(Parent,uno::UNO_QUERY);
341 uno::Reference< report::XFormatCondition > SAL_CALL OShape::createFormatCondition( )
343 return new OFormatCondition(m_aProps.aComponent.m_xContext);
346 // XContainer
347 void SAL_CALL OShape::addContainerListener( const uno::Reference< container::XContainerListener >& xListener )
349 m_aProps.addContainerListener(xListener);
352 void SAL_CALL OShape::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener )
354 m_aProps.removeContainerListener(xListener);
357 // XElementAccess
358 uno::Type SAL_CALL OShape::getElementType( )
360 return cppu::UnoType<report::XFormatCondition>::get();
363 sal_Bool SAL_CALL OShape::hasElements( )
365 return m_aProps.hasElements();
368 // XIndexContainer
369 void SAL_CALL OShape::insertByIndex( ::sal_Int32 Index, const uno::Any& Element )
371 m_aProps.insertByIndex(Index,Element);
374 void SAL_CALL OShape::removeByIndex( ::sal_Int32 Index )
376 m_aProps.removeByIndex(Index);
379 // XIndexReplace
380 void SAL_CALL OShape::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element )
382 m_aProps.replaceByIndex(Index,Element);
385 // XIndexAccess
386 ::sal_Int32 SAL_CALL OShape::getCount( )
388 return m_aProps.getCount();
391 uno::Any SAL_CALL OShape::getByIndex( ::sal_Int32 Index )
393 return m_aProps.getByIndex( Index );
396 // XShape
397 awt::Point SAL_CALL OShape::getPosition( )
399 return OShapeHelper::getPosition(this);
402 void SAL_CALL OShape::setPosition( const awt::Point& aPosition )
404 OShapeHelper::setPosition(aPosition,this);
407 awt::Size SAL_CALL OShape::getSize( )
409 return OShapeHelper::getSize(this);
412 void SAL_CALL OShape::setSize( const awt::Size& aSize )
414 OShapeHelper::setSize(aSize,this);
418 // XShapeDescriptor
419 OUString SAL_CALL OShape::getShapeType( )
421 ::osl::MutexGuard aGuard(m_aMutex);
422 if ( m_aProps.aComponent.m_xShape.is() )
423 return m_aProps.aComponent.m_xShape->getShapeType();
424 return OUString("com.sun.star.drawing.CustomShape");
427 ::sal_Int32 SAL_CALL OShape::getZOrder()
429 ::osl::MutexGuard aGuard(m_aMutex);
430 m_aProps.aComponent.m_xProperty->getPropertyValue(PROPERTY_ZORDER) >>= m_nZOrder;
431 return m_nZOrder;
434 void SAL_CALL OShape::setZOrder( ::sal_Int32 _zorder )
436 ::osl::MutexGuard aGuard(m_aMutex);
437 m_aProps.aComponent.m_xProperty->setPropertyValue(PROPERTY_ZORDER,uno::makeAny(_zorder));
438 set(PROPERTY_ZORDER,_zorder,m_nZOrder);
441 sal_Bool SAL_CALL OShape::getOpaque()
443 ::osl::MutexGuard aGuard(m_aMutex);
444 return m_bOpaque;
447 void SAL_CALL OShape::setOpaque( sal_Bool _opaque )
449 ::osl::MutexGuard aGuard(m_aMutex);
450 set(PROPERTY_OPAQUE,_opaque,m_bOpaque);
453 drawing::HomogenMatrix3 SAL_CALL OShape::getTransformation()
455 ::osl::MutexGuard aGuard(m_aMutex);
456 m_aProps.aComponent.m_xProperty->getPropertyValue(PROPERTY_TRANSFORMATION) >>= m_Transformation;
457 return m_Transformation;
460 void SAL_CALL OShape::setTransformation( const drawing::HomogenMatrix3& _transformation )
462 m_aProps.aComponent.m_xProperty->setPropertyValue(PROPERTY_TRANSFORMATION,uno::makeAny(_transformation));
463 set(PROPERTY_TRANSFORMATION,_transformation,m_Transformation);
466 OUString SAL_CALL OShape::getCustomShapeEngine()
468 ::osl::MutexGuard aGuard(m_aMutex);
469 m_aProps.aComponent.m_xProperty->getPropertyValue(PROPERTY_CUSTOMSHAPEENGINE) >>= m_CustomShapeEngine;
471 return m_CustomShapeEngine;
474 void SAL_CALL OShape::setCustomShapeEngine( const OUString& _customshapeengine )
476 m_aProps.aComponent.m_xProperty->setPropertyValue(PROPERTY_CUSTOMSHAPEENGINE,uno::makeAny(_customshapeengine));
477 set(PROPERTY_CUSTOMSHAPEENGINE,_customshapeengine,m_CustomShapeEngine);
480 OUString SAL_CALL OShape::getCustomShapeData()
482 ::osl::MutexGuard aGuard(m_aMutex);
483 m_aProps.aComponent.m_xProperty->getPropertyValue(PROPERTY_CUSTOMSHAPEDATA) >>= m_CustomShapeData;
484 return m_CustomShapeData;
487 void SAL_CALL OShape::setCustomShapeData( const OUString& _customshapedata )
489 m_aProps.aComponent.m_xProperty->setPropertyValue(PROPERTY_CUSTOMSHAPEDATA,uno::makeAny(_customshapedata));
490 set(PROPERTY_CUSTOMSHAPEDATA,_customshapedata,m_CustomShapeData);
493 uno::Sequence< beans::PropertyValue > SAL_CALL OShape::getCustomShapeGeometry()
495 ::osl::MutexGuard aGuard(m_aMutex);
496 m_aProps.aComponent.m_xProperty->getPropertyValue(PROPERTY_CUSTOMSHAPEGEOMETRY) >>= m_CustomShapeGeometry;
497 return m_CustomShapeGeometry;
500 void SAL_CALL OShape::setCustomShapeGeometry( const uno::Sequence< beans::PropertyValue >& _customshapegeometry )
502 m_aProps.aComponent.m_xProperty->setPropertyValue(PROPERTY_CUSTOMSHAPEGEOMETRY,uno::makeAny(_customshapegeometry));
503 set(PROPERTY_CUSTOMSHAPEGEOMETRY,_customshapegeometry,m_CustomShapeGeometry);
507 }// namespace reportdesign
510 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */