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 
111 OUString SAL_CALL OShape::getImplementationName( )
112 {
113  return "com.sun.star.comp.report.Shape";
114 }
115 
116 uno::Sequence< OUString > SAL_CALL OShape::getSupportedServiceNames( )
117 {
118  if(m_sServiceName.isEmpty())
119  {
120  return { SERVICE_SHAPE };
121  }
122  else
123  {
124  uno::Sequence< OUString > aServices(2);
125  aServices.getArray()[0] = SERVICE_SHAPE;
126  aServices.getArray()[1] = m_sServiceName;
127 
128  return aServices;
129  }
130 }
131 
132 sal_Bool SAL_CALL OShape::supportsService(const OUString& ServiceName)
133 {
134  return cppu::supportsService(this, ServiceName);
135 }
136 
137 // XReportComponent
138 REPORTCOMPONENT_IMPL(OShape,m_aProps.aComponent)
139 REPORTCOMPONENT_IMPL2(OShape,m_aProps.aComponent)
140 REPORTCOMPONENT_MASTERDETAIL(OShape,m_aProps.aComponent)
141 REPORTCONTROLFORMAT_IMPL2(OShape,m_aProps.aFormatProperties)
142 
143 ::sal_Int32 SAL_CALL OShape::getControlBackground()
144 {
145  throw beans::UnknownPropertyException();
146 }
147 
148 void SAL_CALL OShape::setControlBackground( ::sal_Int32 /*_backgroundcolor*/ )
149 {
150  throw beans::UnknownPropertyException();
151 }
152 
153 sal_Bool SAL_CALL OShape::getControlBackgroundTransparent()
154 {
155  throw beans::UnknownPropertyException();
156 }
157 
158 void SAL_CALL OShape::setControlBackgroundTransparent( sal_Bool /*_controlbackgroundtransparent*/ )
159 {
160  throw beans::UnknownPropertyException();
161 }
162 
163 uno::Reference< beans::XPropertySetInfo > SAL_CALL OShape::getPropertySetInfo( )
164 {
165 
166  //return ShapePropertySet::getPropertySetInfo();
167  return cppu::OPropertySetHelper::createPropertySetInfo( getInfoHelper() );
168 }
169 
170 cppu::IPropertyArrayHelper& OShape::getInfoHelper()
171 {
172  if (!m_pAggHelper)
173  {
174  uno::Sequence<beans::Property> aAggSeq;
175  if ( m_aProps.aComponent.m_xProperty.is() )
176  aAggSeq = m_aProps.aComponent.m_xProperty->getPropertySetInfo()->getProperties();
177  m_pAggHelper.reset(new OPropertyArrayAggregationHelper(ShapePropertySet::getPropertySetInfo()->getProperties(),aAggSeq));
178  }
179  return *m_pAggHelper;
180 }
181 
182 
183 void SAL_CALL OShape::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
184 {
185  getInfoHelper();
186  if( m_pAggHelper->classifyProperty(aPropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Aggregate )
187  m_aProps.aComponent.m_xProperty->setPropertyValue( aPropertyName,aValue);
188  // can be in both
189  if( m_pAggHelper->classifyProperty(aPropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Delegator )
190  ShapePropertySet::setPropertyValue( aPropertyName, aValue );
191 }
192 
193 uno::Any SAL_CALL OShape::getPropertyValue( const OUString& PropertyName )
194 {
195  getInfoHelper();
196  if( m_pAggHelper->classifyProperty(PropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Aggregate )
197  return m_aProps.aComponent.m_xProperty->getPropertyValue( PropertyName);
198  // can be in both
199  if( m_pAggHelper->classifyProperty(PropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Delegator )
200  return ShapePropertySet::getPropertyValue( PropertyName);
201  return uno::Any();
202 }
203 
204 void SAL_CALL OShape::addPropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& xListener )
205 {
206  getInfoHelper();
207  if( m_pAggHelper->classifyProperty(aPropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Aggregate || aPropertyName.isEmpty() )
208  m_aProps.aComponent.m_xProperty->addPropertyChangeListener( aPropertyName, xListener);
209  // can be in both
210  if( m_pAggHelper->classifyProperty(aPropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Delegator || aPropertyName.isEmpty() )
211  ShapePropertySet::addPropertyChangeListener( aPropertyName, xListener );
212 }
213 
214 void SAL_CALL OShape::removePropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& aListener )
215 {
216  getInfoHelper();
217  if( m_pAggHelper->classifyProperty(aPropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Aggregate || aPropertyName.isEmpty() )
218  m_aProps.aComponent.m_xProperty->removePropertyChangeListener( aPropertyName, aListener );
219  // can be in both
220  if( m_pAggHelper->classifyProperty(aPropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Delegator || aPropertyName.isEmpty() )
221  ShapePropertySet::removePropertyChangeListener( aPropertyName, aListener );
222 }
223 
224 void SAL_CALL OShape::addVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener )
225 {
226  getInfoHelper();
227  if( m_pAggHelper->classifyProperty(PropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Aggregate || PropertyName.isEmpty() )
228  m_aProps.aComponent.m_xProperty->addVetoableChangeListener( PropertyName, aListener );
229  // can be in both
230  if( m_pAggHelper->classifyProperty(PropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Delegator || PropertyName.isEmpty() )
231  ShapePropertySet::addVetoableChangeListener( PropertyName, aListener );
232 }
233 
234 void SAL_CALL OShape::removeVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener )
235 {
236  getInfoHelper();
237  if( m_pAggHelper->classifyProperty(PropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Aggregate || PropertyName.isEmpty() )
238  m_aProps.aComponent.m_xProperty->removeVetoableChangeListener( PropertyName, aListener );
239  // can be in both
240  if( m_pAggHelper->classifyProperty(PropertyName) == OPropertyArrayAggregationHelper::PropertyOrigin::Delegator || PropertyName.isEmpty() )
241  ShapePropertySet::removeVetoableChangeListener( PropertyName, aListener );
242 }
243 
244 // XReportControlModel
245 OUString SAL_CALL OShape::getDataField()
246 {
247  throw beans::UnknownPropertyException();
248 }
249 
250 void SAL_CALL OShape::setDataField( const OUString& /*_datafield*/ )
251 {
252  throw beans::UnknownPropertyException();
253 }
254 
255 sal_Bool SAL_CALL OShape::getPrintWhenGroupChange()
256 {
257  ::osl::MutexGuard aGuard(m_aMutex);
258  return m_aProps.bPrintWhenGroupChange;
259 }
260 
261 void SAL_CALL OShape::setPrintWhenGroupChange( sal_Bool _printwhengroupchange )
262 {
263  set(PROPERTY_PRINTWHENGROUPCHANGE,_printwhengroupchange,m_aProps.bPrintWhenGroupChange);
264 }
265 
266 OUString SAL_CALL OShape::getConditionalPrintExpression()
267 {
268  ::osl::MutexGuard aGuard(m_aMutex);
269  return m_aProps.aConditionalPrintExpression;
270 }
271 
272 void SAL_CALL OShape::setConditionalPrintExpression( const OUString& _conditionalprintexpression )
273 {
274  set(PROPERTY_CONDITIONALPRINTEXPRESSION,_conditionalprintexpression,m_aProps.aConditionalPrintExpression);
275 }
276 
277 
278 // XCloneable
279 uno::Reference< util::XCloneable > SAL_CALL OShape::createClone( )
280 {
281  uno::Reference< report::XReportComponent> xSource = this;
282  uno::Reference< report::XReportComponent> xSet;
283  try
284  {
286  if ( pObject )
287  {
288  SdrObject* pClone(pObject->CloneSdrObject(pObject->getSdrModelFromSdrObject()));
289  if ( pClone )
290  {
291  xSet.set(pClone->getUnoShape(),uno::UNO_QUERY_THROW );
292  }
293  }
294  }
295  catch(const uno::Exception&)
296  {
297  DBG_UNHANDLED_EXCEPTION("reportdesign");
298  }
299  return xSet;
300 }
301 
302 // XChild
303 uno::Reference< uno::XInterface > SAL_CALL OShape::getParent( )
304 {
305  return OShapeHelper::getParent(this);
306 }
307 
308 void SAL_CALL OShape::setParent( const uno::Reference< uno::XInterface >& Parent )
309 {
310  ::osl::MutexGuard aGuard(m_aMutex);
311  m_aProps.aComponent.m_xParent = uno::Reference< container::XChild >(Parent,uno::UNO_QUERY);
312 }
313 uno::Reference< report::XFormatCondition > SAL_CALL OShape::createFormatCondition( )
314 {
315  return new OFormatCondition(m_aProps.aComponent.m_xContext);
316 }
317 
318 // XContainer
319 void SAL_CALL OShape::addContainerListener( const uno::Reference< container::XContainerListener >& xListener )
320 {
321  m_aProps.addContainerListener(xListener);
322 }
323 
324 void SAL_CALL OShape::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener )
325 {
326  m_aProps.removeContainerListener(xListener);
327 }
328 
329 // XElementAccess
330 uno::Type SAL_CALL OShape::getElementType( )
331 {
333 }
334 
335 sal_Bool SAL_CALL OShape::hasElements( )
336 {
337  return m_aProps.hasElements();
338 }
339 
340 // XIndexContainer
341 void SAL_CALL OShape::insertByIndex( ::sal_Int32 Index, const uno::Any& Element )
342 {
343  m_aProps.insertByIndex(Index,Element);
344 }
345 
346 void SAL_CALL OShape::removeByIndex( ::sal_Int32 Index )
347 {
348  m_aProps.removeByIndex(Index);
349 }
350 
351 // XIndexReplace
352 void SAL_CALL OShape::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element )
353 {
354  m_aProps.replaceByIndex(Index,Element);
355 }
356 
357 // XIndexAccess
358 ::sal_Int32 SAL_CALL OShape::getCount( )
359 {
360  return m_aProps.getCount();
361 }
362 
363 uno::Any SAL_CALL OShape::getByIndex( ::sal_Int32 Index )
364 {
365  return m_aProps.getByIndex( Index );
366 }
367 
368 // XShape
369 awt::Point SAL_CALL OShape::getPosition( )
370 {
371  return OShapeHelper::getPosition(this);
372 }
373 
374 void SAL_CALL OShape::setPosition( const awt::Point& aPosition )
375 {
376  OShapeHelper::setPosition(aPosition,this);
377 }
378 
379 awt::Size SAL_CALL OShape::getSize( )
380 {
381  return OShapeHelper::getSize(this);
382 }
383 
384 void SAL_CALL OShape::setSize( const awt::Size& aSize )
385 {
386  OShapeHelper::setSize(aSize,this);
387 }
388 
389 
390 // XShapeDescriptor
391 OUString SAL_CALL OShape::getShapeType( )
392 {
393  ::osl::MutexGuard aGuard(m_aMutex);
394  if ( m_aProps.aComponent.m_xShape.is() )
395  return m_aProps.aComponent.m_xShape->getShapeType();
396  return "com.sun.star.drawing.CustomShape";
397 }
398 
399 ::sal_Int32 SAL_CALL OShape::getZOrder()
400 {
401  ::osl::MutexGuard aGuard(m_aMutex);
402  m_aProps.aComponent.m_xProperty->getPropertyValue(PROPERTY_ZORDER) >>= m_nZOrder;
403  return m_nZOrder;
404 }
405 
406 void SAL_CALL OShape::setZOrder( ::sal_Int32 _zorder )
407 {
408  ::osl::MutexGuard aGuard(m_aMutex);
409  m_aProps.aComponent.m_xProperty->setPropertyValue(PROPERTY_ZORDER,uno::makeAny(_zorder));
410  set(PROPERTY_ZORDER,_zorder,m_nZOrder);
411 }
412 
413 sal_Bool SAL_CALL OShape::getOpaque()
414 {
415  ::osl::MutexGuard aGuard(m_aMutex);
416  return m_bOpaque;
417 }
418 
419 void SAL_CALL OShape::setOpaque( sal_Bool _opaque )
420 {
421  ::osl::MutexGuard aGuard(m_aMutex);
422  set(PROPERTY_OPAQUE,_opaque,m_bOpaque);
423 }
424 
425 drawing::HomogenMatrix3 SAL_CALL OShape::getTransformation()
426 {
427  ::osl::MutexGuard aGuard(m_aMutex);
428  m_aProps.aComponent.m_xProperty->getPropertyValue(PROPERTY_TRANSFORMATION) >>= m_Transformation;
429  return m_Transformation;
430 }
431 
432 void SAL_CALL OShape::setTransformation( const drawing::HomogenMatrix3& _transformation )
433 {
434  m_aProps.aComponent.m_xProperty->setPropertyValue(PROPERTY_TRANSFORMATION,uno::makeAny(_transformation));
435  set(PROPERTY_TRANSFORMATION,_transformation,m_Transformation);
436 }
437 
438 OUString SAL_CALL OShape::getCustomShapeEngine()
439 {
440  ::osl::MutexGuard aGuard(m_aMutex);
441  m_aProps.aComponent.m_xProperty->getPropertyValue(PROPERTY_CUSTOMSHAPEENGINE) >>= m_CustomShapeEngine;
442 
443  return m_CustomShapeEngine;
444 }
445 
446 void SAL_CALL OShape::setCustomShapeEngine( const OUString& _customshapeengine )
447 {
448  m_aProps.aComponent.m_xProperty->setPropertyValue(PROPERTY_CUSTOMSHAPEENGINE,uno::makeAny(_customshapeengine));
449  set(PROPERTY_CUSTOMSHAPEENGINE,_customshapeengine,m_CustomShapeEngine);
450 }
451 
452 OUString SAL_CALL OShape::getCustomShapeData()
453 {
454  ::osl::MutexGuard aGuard(m_aMutex);
455  m_aProps.aComponent.m_xProperty->getPropertyValue(PROPERTY_CUSTOMSHAPEDATA) >>= m_CustomShapeData;
456  return m_CustomShapeData;
457 }
458 
459 void SAL_CALL OShape::setCustomShapeData( const OUString& _customshapedata )
460 {
461  m_aProps.aComponent.m_xProperty->setPropertyValue(PROPERTY_CUSTOMSHAPEDATA,uno::makeAny(_customshapedata));
462  set(PROPERTY_CUSTOMSHAPEDATA,_customshapedata,m_CustomShapeData);
463 }
464 
465 uno::Sequence< beans::PropertyValue > SAL_CALL OShape::getCustomShapeGeometry()
466 {
467  ::osl::MutexGuard aGuard(m_aMutex);
468  m_aProps.aComponent.m_xProperty->getPropertyValue(PROPERTY_CUSTOMSHAPEGEOMETRY) >>= m_CustomShapeGeometry;
469  return m_CustomShapeGeometry;
470 }
471 
472 void SAL_CALL OShape::setCustomShapeGeometry( const uno::Sequence< beans::PropertyValue >& _customshapegeometry )
473 {
474  m_aProps.aComponent.m_xProperty->setPropertyValue(PROPERTY_CUSTOMSHAPEGEOMETRY,uno::makeAny(_customshapegeometry));
475  set(PROPERTY_CUSTOMSHAPEGEOMETRY,_customshapegeometry,m_CustomShapeGeometry);
476 }
477 
478 
479 }// namespace reportdesign
480 
481 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
483  css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
484 {
485  return cppu::acquire(new reportdesign::OShape(context));
486 }
487 
488 
489 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL createPropertySetInfo(IPropertyArrayHelper &rProperties)
bool hasValue()
virtual css::uno::Sequence< css::beans::Property > SAL_CALL getProperties()=0
osl::Mutex m_aMutex
#define PROPERTY_TRANSFORMATION
Definition: strings.hxx:208
static SdrObject * getSdrObjectFromXShape(const css::uno::Reference< css::uno::XInterface > &xInt)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * reportdesign_OShape_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Definition: Shape.cxx:482
#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()
OUString RptResId(const char *pId)
#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)