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