LibreOffice Module reportdesign (master) 1
Shape.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19#include <Shape.hxx>
20
22#include <svx/svdobj.hxx>
24
25#include <strings.hxx>
26#include <strings.hrc>
27#include <core_resource.hxx>
28#include <Tools.hxx>
29#include <FormatCondition.hxx>
30#include <ReportHelperImpl.hxx>
31#include <utility>
32
33namespace reportdesign
34{
35
36 using namespace com::sun::star;
37 using namespace comphelper;
38static uno::Sequence< OUString > lcl_getShapeOptionals()
39{
40 const OUString pProps[] = {
41 OUString(PROPERTY_DATAFIELD)
44 };
45 return uno::Sequence< OUString >(pProps,SAL_N_ELEMENTS(pProps));
46}
47
48
49OShape::OShape(uno::Reference< uno::XComponentContext > const & _xContext)
51,ShapePropertySet(_xContext,IMPLEMENTS_PROPERTY_SET,lcl_getShapeOptionals())
52,m_aProps(m_aMutex,static_cast< container::XContainer*>( this ),_xContext)
53,m_nZOrder(0)
54,m_bOpaque(false)
55{
56 m_aProps.aComponent.m_sName = RptResId(RID_STR_SHAPE);
57}
58
59OShape::OShape(uno::Reference< uno::XComponentContext > const & _xContext
60 ,const uno::Reference< lang::XMultiServiceFactory>& _xFactory
61 ,uno::Reference< drawing::XShape >& _xShape
62 ,OUString _sServiceName)
64,ShapePropertySet(_xContext,IMPLEMENTS_PROPERTY_SET,lcl_getShapeOptionals())
65,m_aProps(m_aMutex,static_cast< container::XContainer*>( this ),_xContext)
66,m_nZOrder(0)
67,m_bOpaque(false)
68,m_sServiceName(std::move(_sServiceName))
69{
70 m_aProps.aComponent.m_sName = RptResId(RID_STR_SHAPE);
71 m_aProps.aComponent.m_xFactory = _xFactory;
72 osl_atomic_increment( &m_refCount );
73 {
74 uno::Reference<beans::XPropertySet> xProp(_xShape,uno::UNO_QUERY);
75 if ( xProp.is() )
76 {
77 xProp->getPropertyValue(PROPERTY_ZORDER) >>= m_nZOrder;
78 xProp.clear();
79 }
80 m_aProps.aComponent.setShape(_xShape,this,m_refCount);
81 }
82 osl_atomic_decrement( &m_refCount );
83}
84
85OShape::~OShape()
86{
87}
88
89//IMPLEMENT_FORWARD_XINTERFACE2(OShape,ShapeBase,ShapePropertySet)
91
92uno::Any SAL_CALL OShape::queryInterface( const uno::Type& _rType )
93{
94 uno::Any aReturn = ShapeBase::queryInterface(_rType);
95 if ( !aReturn.hasValue() )
96 aReturn = ShapePropertySet::queryInterface(_rType);
97
98 if ( !aReturn.hasValue() && OReportControlModel::isInterfaceForbidden(_rType) )
99 return aReturn;
100
101 return aReturn.hasValue() ? aReturn : (m_aProps.aComponent.m_xProxy.is() ? m_aProps.aComponent.m_xProxy->queryAggregation(_rType) : aReturn);
102}
103
104
105void SAL_CALL OShape::dispose()
106{
107 ShapePropertySet::dispose();
108 cppu::WeakComponentImplHelperBase::dispose();
109}
110
111uno::Reference< uno::XInterface > OShape::create(uno::Reference< uno::XComponentContext > const & xContext)
112{
113 return *(new OShape(xContext));
114}
115
116
117OUString OShape::getImplementationName_Static( )
118{
119 return "com.sun.star.comp.report.Shape";
120}
121
122
123OUString SAL_CALL OShape::getImplementationName( )
124{
125 return getImplementationName_Static();
126}
127
128uno::Sequence< OUString > OShape::getSupportedServiceNames_Static( )
129{
130 return { SERVICE_SHAPE };
131}
132
133uno::Sequence< OUString > SAL_CALL OShape::getSupportedServiceNames( )
134{
135 if(m_sServiceName.isEmpty())
136 {
137 return getSupportedServiceNames_Static();
138 }
139 else
140 {
141 return { SERVICE_SHAPE, m_sServiceName };
142 }
143}
144
145sal_Bool SAL_CALL OShape::supportsService(const OUString& ServiceName)
146{
148}
149
150// XReportComponent
152REPORTCOMPONENT_IMPL2(OShape,m_aProps.aComponent)
153REPORTCOMPONENT_MASTERDETAIL(OShape,m_aProps.aComponent)
154REPORTCONTROLFORMAT_IMPL2(OShape,m_aProps.aFormatProperties)
155
156::sal_Int32 SAL_CALL OShape::getControlBackground()
157{
158 throw beans::UnknownPropertyException();
159}
160
161void SAL_CALL OShape::setControlBackground( ::sal_Int32 /*_backgroundcolor*/ )
162{
163 throw beans::UnknownPropertyException();
164}
165
166sal_Bool SAL_CALL OShape::getControlBackgroundTransparent()
167{
168 throw beans::UnknownPropertyException();
169}
170
171void SAL_CALL OShape::setControlBackgroundTransparent( sal_Bool /*_controlbackgroundtransparent*/ )
172{
173 throw beans::UnknownPropertyException();
174}
175
176uno::Reference< beans::XPropertySetInfo > SAL_CALL OShape::getPropertySetInfo( )
177{
178
179 //return ShapePropertySet::getPropertySetInfo();
180 return cppu::OPropertySetHelper::createPropertySetInfo( getInfoHelper() );
181}
182
183cppu::IPropertyArrayHelper& OShape::getInfoHelper()
184{
185 if (!m_pAggHelper)
186 {
187 uno::Sequence<beans::Property> aAggSeq;
188 if ( m_aProps.aComponent.m_xProperty.is() )
189 aAggSeq = m_aProps.aComponent.m_xProperty->getPropertySetInfo()->getProperties();
190 m_pAggHelper.reset(new OPropertyArrayAggregationHelper(ShapePropertySet::getPropertySetInfo()->getProperties(),aAggSeq));
191 }
192 return *m_pAggHelper;
193}
194
195
196void SAL_CALL OShape::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
197{
198 getInfoHelper();
199 if( m_pAggHelper->classifyProperty(aPropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Aggregate )
200 m_aProps.aComponent.m_xProperty->setPropertyValue( aPropertyName,aValue);
201 // can be in both
202 if( m_pAggHelper->classifyProperty(aPropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Delegator )
203 ShapePropertySet::setPropertyValue( aPropertyName, aValue );
204}
205
206uno::Any SAL_CALL OShape::getPropertyValue( const OUString& PropertyName )
207{
208 getInfoHelper();
209 if( m_pAggHelper->classifyProperty(PropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Aggregate )
210 return m_aProps.aComponent.m_xProperty->getPropertyValue( PropertyName);
211 // can be in both
212 if( m_pAggHelper->classifyProperty(PropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Delegator )
213 return ShapePropertySet::getPropertyValue( PropertyName);
214 return uno::Any();
215}
216
217void SAL_CALL OShape::addPropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& xListener )
218{
219 getInfoHelper();
220 if( m_pAggHelper->classifyProperty(aPropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Aggregate || aPropertyName.isEmpty() )
221 m_aProps.aComponent.m_xProperty->addPropertyChangeListener( aPropertyName, xListener);
222 // can be in both
223 if( m_pAggHelper->classifyProperty(aPropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Delegator || aPropertyName.isEmpty() )
224 ShapePropertySet::addPropertyChangeListener( aPropertyName, xListener );
225}
226
227void SAL_CALL OShape::removePropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& aListener )
228{
229 getInfoHelper();
230 if( m_pAggHelper->classifyProperty(aPropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Aggregate || aPropertyName.isEmpty() )
231 m_aProps.aComponent.m_xProperty->removePropertyChangeListener( aPropertyName, aListener );
232 // can be in both
233 if( m_pAggHelper->classifyProperty(aPropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Delegator || aPropertyName.isEmpty() )
234 ShapePropertySet::removePropertyChangeListener( aPropertyName, aListener );
235}
236
237void SAL_CALL OShape::addVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener )
238{
239 getInfoHelper();
240 if( m_pAggHelper->classifyProperty(PropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Aggregate || PropertyName.isEmpty() )
241 m_aProps.aComponent.m_xProperty->addVetoableChangeListener( PropertyName, aListener );
242 // can be in both
243 if( m_pAggHelper->classifyProperty(PropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Delegator || PropertyName.isEmpty() )
244 ShapePropertySet::addVetoableChangeListener( PropertyName, aListener );
245}
246
247void SAL_CALL OShape::removeVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener )
248{
249 getInfoHelper();
250 if( m_pAggHelper->classifyProperty(PropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Aggregate || PropertyName.isEmpty() )
251 m_aProps.aComponent.m_xProperty->removeVetoableChangeListener( PropertyName, aListener );
252 // can be in both
253 if( m_pAggHelper->classifyProperty(PropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Delegator || PropertyName.isEmpty() )
254 ShapePropertySet::removeVetoableChangeListener( PropertyName, aListener );
255}
256
257// XReportControlModel
258OUString SAL_CALL OShape::getDataField()
259{
260 throw beans::UnknownPropertyException();
261}
262
263void SAL_CALL OShape::setDataField( const OUString& /*_datafield*/ )
264{
265 throw beans::UnknownPropertyException();
266}
267
268sal_Bool SAL_CALL OShape::getPrintWhenGroupChange()
269{
270 ::osl::MutexGuard aGuard(m_aMutex);
271 return m_aProps.bPrintWhenGroupChange;
272}
273
274void SAL_CALL OShape::setPrintWhenGroupChange( sal_Bool _printwhengroupchange )
275{
276 set(PROPERTY_PRINTWHENGROUPCHANGE,_printwhengroupchange,m_aProps.bPrintWhenGroupChange);
277}
278
279OUString SAL_CALL OShape::getConditionalPrintExpression()
280{
281 ::osl::MutexGuard aGuard(m_aMutex);
282 return m_aProps.aConditionalPrintExpression;
283}
284
285void SAL_CALL OShape::setConditionalPrintExpression( const OUString& _conditionalprintexpression )
286{
287 set(PROPERTY_CONDITIONALPRINTEXPRESSION,_conditionalprintexpression,m_aProps.aConditionalPrintExpression);
288}
289
290
291// XCloneable
292uno::Reference< util::XCloneable > SAL_CALL OShape::createClone( )
293{
294 uno::Reference< report::XReportComponent> xSource = this;
295 uno::Reference< report::XReportComponent> xSet;
296 try
297 {
299 if ( pObject )
300 {
301 rtl::Reference<SdrObject> pClone(pObject->CloneSdrObject(pObject->getSdrModelFromSdrObject()));
302 if ( pClone )
303 {
304 xSet.set(pClone->getUnoShape(),uno::UNO_QUERY_THROW );
305 }
306 }
307 }
308 catch(const uno::Exception&)
309 {
310 DBG_UNHANDLED_EXCEPTION("reportdesign");
311 }
312 return xSet;
313}
314
315// XChild
316uno::Reference< uno::XInterface > SAL_CALL OShape::getParent( )
317{
318 return OShapeHelper::getParent(this);
319}
320
321void SAL_CALL OShape::setParent( const uno::Reference< uno::XInterface >& Parent )
322{
323 ::osl::MutexGuard aGuard(m_aMutex);
324 m_aProps.aComponent.m_xParent = uno::Reference< container::XChild >(Parent,uno::UNO_QUERY);
325}
326uno::Reference< report::XFormatCondition > SAL_CALL OShape::createFormatCondition( )
327{
328 return new OFormatCondition(m_aProps.aComponent.m_xContext);
329}
330
331// XContainer
332void SAL_CALL OShape::addContainerListener( const uno::Reference< container::XContainerListener >& xListener )
333{
334 m_aProps.addContainerListener(xListener);
335}
336
337void SAL_CALL OShape::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener )
338{
339 m_aProps.removeContainerListener(xListener);
340}
341
342// XElementAccess
343uno::Type SAL_CALL OShape::getElementType( )
344{
346}
347
348sal_Bool SAL_CALL OShape::hasElements( )
349{
350 return m_aProps.hasElements();
351}
352
353// XIndexContainer
354void SAL_CALL OShape::insertByIndex( ::sal_Int32 Index, const uno::Any& Element )
355{
356 m_aProps.insertByIndex(Index,Element);
357}
358
359void SAL_CALL OShape::removeByIndex( ::sal_Int32 Index )
360{
361 m_aProps.removeByIndex(Index);
362}
363
364// XIndexReplace
365void SAL_CALL OShape::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element )
366{
367 m_aProps.replaceByIndex(Index,Element);
368}
369
370// XIndexAccess
371::sal_Int32 SAL_CALL OShape::getCount( )
372{
373 return m_aProps.getCount();
374}
375
376uno::Any SAL_CALL OShape::getByIndex( ::sal_Int32 Index )
377{
378 return m_aProps.getByIndex( Index );
379}
380
381// XShape
382awt::Point SAL_CALL OShape::getPosition( )
383{
384 return OShapeHelper::getPosition(this);
385}
386
387void SAL_CALL OShape::setPosition( const awt::Point& aPosition )
388{
389 OShapeHelper::setPosition(aPosition,this);
390}
391
392awt::Size SAL_CALL OShape::getSize( )
393{
394 return OShapeHelper::getSize(this);
395}
396
397void SAL_CALL OShape::setSize( const awt::Size& aSize )
398{
399 OShapeHelper::setSize(aSize,this);
400}
401
402
403// XShapeDescriptor
404OUString SAL_CALL OShape::getShapeType( )
405{
406 ::osl::MutexGuard aGuard(m_aMutex);
407 if ( m_aProps.aComponent.m_xShape.is() )
408 return m_aProps.aComponent.m_xShape->getShapeType();
409 return "com.sun.star.drawing.CustomShape";
410}
411
412::sal_Int32 SAL_CALL OShape::getZOrder()
413{
414 ::osl::MutexGuard aGuard(m_aMutex);
415 m_aProps.aComponent.m_xProperty->getPropertyValue(PROPERTY_ZORDER) >>= m_nZOrder;
416 return m_nZOrder;
417}
418
419void SAL_CALL OShape::setZOrder( ::sal_Int32 _zorder )
420{
421 ::osl::MutexGuard aGuard(m_aMutex);
422 m_aProps.aComponent.m_xProperty->setPropertyValue(PROPERTY_ZORDER,uno::Any(_zorder));
423 set(PROPERTY_ZORDER,_zorder,m_nZOrder);
424}
425
426sal_Bool SAL_CALL OShape::getOpaque()
427{
428 ::osl::MutexGuard aGuard(m_aMutex);
429 return m_bOpaque;
430}
431
432void SAL_CALL OShape::setOpaque( sal_Bool _opaque )
433{
434 ::osl::MutexGuard aGuard(m_aMutex);
435 set(PROPERTY_OPAQUE,_opaque,m_bOpaque);
436}
437
438drawing::HomogenMatrix3 SAL_CALL OShape::getTransformation()
439{
440 ::osl::MutexGuard aGuard(m_aMutex);
441 m_aProps.aComponent.m_xProperty->getPropertyValue(PROPERTY_TRANSFORMATION) >>= m_Transformation;
442 return m_Transformation;
443}
444
445void SAL_CALL OShape::setTransformation( const drawing::HomogenMatrix3& _transformation )
446{
447 m_aProps.aComponent.m_xProperty->setPropertyValue(PROPERTY_TRANSFORMATION,uno::Any(_transformation));
448 set(PROPERTY_TRANSFORMATION,_transformation,m_Transformation);
449}
450
451OUString SAL_CALL OShape::getCustomShapeEngine()
452{
453 ::osl::MutexGuard aGuard(m_aMutex);
454 m_aProps.aComponent.m_xProperty->getPropertyValue(PROPERTY_CUSTOMSHAPEENGINE) >>= m_CustomShapeEngine;
455
456 return m_CustomShapeEngine;
457}
458
459void SAL_CALL OShape::setCustomShapeEngine( const OUString& _customshapeengine )
460{
461 m_aProps.aComponent.m_xProperty->setPropertyValue(PROPERTY_CUSTOMSHAPEENGINE,uno::Any(_customshapeengine));
462 set(PROPERTY_CUSTOMSHAPEENGINE,_customshapeengine,m_CustomShapeEngine);
463}
464
465OUString SAL_CALL OShape::getCustomShapeData()
466{
467 ::osl::MutexGuard aGuard(m_aMutex);
468 m_aProps.aComponent.m_xProperty->getPropertyValue(PROPERTY_CUSTOMSHAPEDATA) >>= m_CustomShapeData;
469 return m_CustomShapeData;
470}
471
472void SAL_CALL OShape::setCustomShapeData( const OUString& _customshapedata )
473{
474 m_aProps.aComponent.m_xProperty->setPropertyValue(PROPERTY_CUSTOMSHAPEDATA,uno::Any(_customshapedata));
475 set(PROPERTY_CUSTOMSHAPEDATA,_customshapedata,m_CustomShapeData);
476}
477
478uno::Sequence< beans::PropertyValue > SAL_CALL OShape::getCustomShapeGeometry()
479{
480 ::osl::MutexGuard aGuard(m_aMutex);
481 m_aProps.aComponent.m_xProperty->getPropertyValue(PROPERTY_CUSTOMSHAPEGEOMETRY) >>= m_CustomShapeGeometry;
482 return m_CustomShapeGeometry;
483}
484
485void SAL_CALL OShape::setCustomShapeGeometry( const uno::Sequence< beans::PropertyValue >& _customshapegeometry )
486{
487 m_aProps.aComponent.m_xProperty->setPropertyValue(PROPERTY_CUSTOMSHAPEGEOMETRY,uno::Any(_customshapegeometry));
488 set(PROPERTY_CUSTOMSHAPEGEOMETRY,_customshapegeometry,m_CustomShapeGeometry);
489}
490
491
492}// namespace reportdesign
493
494
495/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _ADOIndex Index
#define REPORTCOMPONENT_IMPL2(clazz, arg)
#define REPORTCOMPONENT_MASTERDETAIL(clazz, arg)
#define REPORTCONTROLFORMAT_IMPL2(clazz, varName)
#define REPORTCOMPONENT_IMPL(clazz, arg)
static SdrObject * getSdrObjectFromXShape(const css::uno::Reference< css::uno::XInterface > &xInt)
static css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL createPropertySetInfo(IPropertyArrayHelper &rProperties)
css::uno::Type const & get()
implementation of a
Definition: Shape.hxx:45
OShape(const OShape &)=delete
OUString RptResId(TranslateId aId)
#define DBG_UNHANDLED_EXCEPTION(...)
EmbeddedObjectRef * pObject
std::mutex m_aMutex
#define SAL_N_ELEMENTS(arr)
void set(css::uno::UnoInterfaceReference const &value)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
::cppu::PropertySetMixin< css::report::XShape > ShapePropertySet
Definition: Shape.hxx:34
static uno::Sequence< OUString > lcl_getShapeOptionals()
Definition: Shape.cxx:38
::cppu::WeakComponentImplHelper< css::report::XShape,css::lang::XServiceInfo > ShapeBase
Definition: Shape.hxx:36
uno::Sequence< beans::Property > m_aProps
constexpr OUStringLiteral PROPERTY_CONTROLBACKGROUNDTRANSPARENT
Definition: strings.hxx:41
constexpr OUStringLiteral PROPERTY_DATAFIELD
Definition: strings.hxx:78
constexpr OUStringLiteral PROPERTY_CUSTOMSHAPEGEOMETRY
Definition: strings.hxx:205
constexpr OUStringLiteral PROPERTY_CUSTOMSHAPEDATA
Definition: strings.hxx:204
constexpr OUStringLiteral SERVICE_SHAPE
Definition: strings.hxx:28
constexpr OUStringLiteral PROPERTY_TRANSFORMATION
Definition: strings.hxx:202
constexpr OUStringLiteral PROPERTY_ZORDER
Definition: strings.hxx:200
constexpr OUStringLiteral PROPERTY_PRINTWHENGROUPCHANGE
Definition: strings.hxx:111
constexpr OUStringLiteral PROPERTY_CONDITIONALPRINTEXPRESSION
Definition: strings.hxx:108
constexpr OUStringLiteral PROPERTY_OPAQUE
Definition: strings.hxx:201
constexpr OUStringLiteral PROPERTY_CUSTOMSHAPEENGINE
Definition: strings.hxx:203
constexpr OUStringLiteral PROPERTY_CONTROLBACKGROUND
Definition: strings.hxx:40
bool hasValue()
unsigned char sal_Bool
#define IMPLEMENT_FORWARD_REFCOUNT(classname, refcountbase)
Reference< XComponentContext > _xContext