bump product version to 5.0.4.1
[LibreOffice.git] / reportdesign / source / core / api / ImageControl.cxx
blob36355d0d53aec6ecab40ba0efc3ec3ead6a7c2fd
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 "ImageControl.hxx"
20 #include <com/sun/star/beans/PropertyAttribute.hpp>
21 #include <com/sun/star/beans/XPropertyState.hpp>
22 #include "corestrings.hrc"
23 #include "core_resource.hrc"
24 #include "core_resource.hxx"
25 #include "Tools.hxx"
26 #include <tools/color.hxx>
27 #include <tools/debug.hxx>
28 #include <comphelper/property.hxx>
29 #include <cppuhelper/supportsservice.hxx>
30 #include "FormatCondition.hxx"
31 #include <com/sun/star/awt/ImageScaleMode.hpp>
32 #include <com/sun/star/text/ParagraphVertAlign.hpp>
33 #include "ReportHelperImpl.hxx"
35 namespace reportdesign
38 using namespace com::sun::star;
39 using namespace comphelper;
40 uno::Sequence< OUString > lcl_getImageOptionals()
42 OUString pProps[] = {
43 OUString(PROPERTY_CHARCOLOR)
44 ,OUString(PROPERTY_CHAREMPHASIS)
45 ,OUString(PROPERTY_CHARFONTCHARSET)
46 ,OUString(PROPERTY_CHARFONTFAMILY)
47 ,OUString(PROPERTY_CHARFONTNAME)
48 ,OUString(PROPERTY_CHARFONTPITCH)
49 ,OUString(PROPERTY_CHARFONTSTYLENAME)
50 ,OUString(PROPERTY_CHARHEIGHT)
51 ,OUString(PROPERTY_CHARPOSTURE)
52 ,OUString(PROPERTY_CHARRELIEF)
53 ,OUString(PROPERTY_FONTDESCRIPTOR)
54 ,OUString(PROPERTY_FONTDESCRIPTORASIAN)
55 ,OUString(PROPERTY_FONTDESCRIPTORCOMPLEX)
56 ,OUString(PROPERTY_CONTROLTEXTEMPHASISMARK)
57 ,OUString(PROPERTY_CHARROTATION)
58 ,OUString(PROPERTY_CHARSCALEWIDTH)
59 ,OUString(PROPERTY_CHARSTRIKEOUT)
60 ,OUString(PROPERTY_CHARUNDERLINECOLOR)
61 ,OUString(PROPERTY_CHARUNDERLINE)
62 ,OUString(PROPERTY_CHARWEIGHT)
63 ,OUString(PROPERTY_CHARWORDMODE)
64 ,OUString(PROPERTY_CHARFLASH)
65 ,OUString(PROPERTY_CHARAUTOKERNING)
66 ,OUString(PROPERTY_CHARESCAPEMENTHEIGHT)
67 ,OUString(PROPERTY_CHARLOCALE)
68 ,OUString(PROPERTY_CHARESCAPEMENT)
69 ,OUString(PROPERTY_CHARCASEMAP)
70 ,OUString(PROPERTY_CHARCOMBINEISON)
71 ,OUString(PROPERTY_CHARCOMBINEPREFIX)
72 ,OUString(PROPERTY_CHARCOMBINESUFFIX)
73 ,OUString(PROPERTY_CHARHIDDEN)
74 ,OUString(PROPERTY_CHARSHADOWED)
75 ,OUString(PROPERTY_CHARCONTOURED)
76 ,OUString(PROPERTY_VISITEDCHARSTYLENAME)
77 ,OUString(PROPERTY_UNVISITEDCHARSTYLENAME)
78 ,OUString(PROPERTY_CHARKERNING)
79 ,OUString(PROPERTY_MASTERFIELDS)
80 ,OUString(PROPERTY_DETAILFIELDS)
81 ,OUString(PROPERTY_PARAADJUST)
82 , OUString(PROPERTY_CHAREMPHASISASIAN)
83 , OUString(PROPERTY_CHARFONTNAMEASIAN)
84 , OUString(PROPERTY_CHARFONTSTYLENAMEASIAN)
85 , OUString(PROPERTY_CHARFONTFAMILYASIAN)
86 , OUString(PROPERTY_CHARFONTCHARSETASIAN)
87 , OUString(PROPERTY_CHARFONTPITCHASIAN)
88 , OUString(PROPERTY_CHARHEIGHTASIAN)
89 , OUString(PROPERTY_CHARUNDERLINEASIAN)
90 , OUString(PROPERTY_CHARWEIGHTASIAN)
91 , OUString(PROPERTY_CHARPOSTUREASIAN)
92 , OUString(PROPERTY_CHARWORDMODEASIAN)
93 , OUString(PROPERTY_CHARROTATIONASIAN)
94 , OUString(PROPERTY_CHARSCALEWIDTHASIAN)
95 , OUString(PROPERTY_CHARLOCALEASIAN)
96 , OUString(PROPERTY_CHAREMPHASISCOMPLEX)
97 , OUString(PROPERTY_CHARFONTNAMECOMPLEX)
98 , OUString(PROPERTY_CHARFONTSTYLENAMECOMPLEX)
99 , OUString(PROPERTY_CHARFONTFAMILYCOMPLEX)
100 , OUString(PROPERTY_CHARFONTCHARSETCOMPLEX)
101 , OUString(PROPERTY_CHARFONTPITCHCOMPLEX)
102 , OUString(PROPERTY_CHARHEIGHTCOMPLEX)
103 , OUString(PROPERTY_CHARUNDERLINECOMPLEX)
104 , OUString(PROPERTY_CHARWEIGHTCOMPLEX)
105 , OUString(PROPERTY_CHARPOSTURECOMPLEX)
106 , OUString(PROPERTY_CHARWORDMODECOMPLEX)
107 , OUString(PROPERTY_CHARROTATIONCOMPLEX)
108 , OUString(PROPERTY_CHARSCALEWIDTHCOMPLEX)
109 , OUString(PROPERTY_CHARLOCALECOMPLEX)
112 return uno::Sequence< OUString >(pProps,sizeof(pProps)/sizeof(pProps[0]));
116 OImageControl::OImageControl(uno::Reference< uno::XComponentContext > const & _xContext)
117 :ImageControlBase(m_aMutex)
118 ,ImageControlPropertySet(_xContext,static_cast< Implements >(IMPLEMENTS_PROPERTY_SET),lcl_getImageOptionals())
119 ,m_aProps(m_aMutex,static_cast< container::XContainer*>( this ),_xContext)
120 ,m_nScaleMode(awt::ImageScaleMode::NONE)
121 ,m_bPreserveIRI(true)
123 m_aProps.aComponent.m_sName = RPT_RESSTRING(RID_STR_IMAGECONTROL,m_aProps.aComponent.m_xContext->getServiceManager());
126 OImageControl::OImageControl(uno::Reference< uno::XComponentContext > const & _xContext
127 ,const uno::Reference< lang::XMultiServiceFactory>& _xFactory
128 ,uno::Reference< drawing::XShape >& _xShape)
129 :ImageControlBase(m_aMutex)
130 ,ImageControlPropertySet(_xContext,static_cast< Implements >(IMPLEMENTS_PROPERTY_SET),lcl_getImageOptionals())
131 ,m_aProps(m_aMutex,static_cast< container::XContainer*>( this ),_xContext)
132 ,m_nScaleMode(awt::ImageScaleMode::NONE)
133 ,m_bPreserveIRI(true)
135 m_aProps.aComponent.m_sName = RPT_RESSTRING(RID_STR_IMAGECONTROL,m_aProps.aComponent.m_xContext->getServiceManager());
136 m_aProps.aComponent.m_xFactory = _xFactory;
137 osl_atomic_increment( &m_refCount );
139 m_aProps.aComponent.setShape(_xShape,this,m_refCount);
141 osl_atomic_decrement( &m_refCount );
144 OImageControl::~OImageControl()
148 //IMPLEMENT_FORWARD_XINTERFACE2(OImageControl,ImageControlBase,ImageControlPropertySet)
149 IMPLEMENT_FORWARD_REFCOUNT( OImageControl, ImageControlBase )
151 uno::Any SAL_CALL OImageControl::queryInterface( const uno::Type& _rType ) throw (uno::RuntimeException, std::exception)
153 uno::Any aReturn = ImageControlBase::queryInterface(_rType);
154 if ( !aReturn.hasValue() )
155 aReturn = ImageControlPropertySet::queryInterface(_rType);
157 if ( !aReturn.hasValue() && OReportControlModel::isInterfaceForbidden(_rType) )
158 return aReturn;
160 return aReturn.hasValue() ? aReturn : (m_aProps.aComponent.m_xProxy.is() ? m_aProps.aComponent.m_xProxy->queryAggregation(_rType) : aReturn);
164 void SAL_CALL OImageControl::dispose() throw(uno::RuntimeException, std::exception)
166 ImageControlPropertySet::dispose();
167 cppu::WeakComponentImplHelperBase::dispose();
170 OUString OImageControl::getImplementationName_Static( ) throw(uno::RuntimeException)
172 return OUString("com.sun.star.comp.report.OImageControl");
176 OUString SAL_CALL OImageControl::getImplementationName( ) throw(uno::RuntimeException, std::exception)
178 return getImplementationName_Static();
181 uno::Sequence< OUString > OImageControl::getSupportedServiceNames_Static( ) throw(uno::RuntimeException)
183 uno::Sequence< OUString > aServices(1);
184 aServices.getArray()[0] = SERVICE_IMAGECONTROL;
186 return aServices;
189 uno::Reference< uno::XInterface > OImageControl::create(uno::Reference< uno::XComponentContext > const & xContext)
191 return *(new OImageControl(xContext));
195 uno::Sequence< OUString > SAL_CALL OImageControl::getSupportedServiceNames( ) throw(uno::RuntimeException, std::exception)
197 return getSupportedServiceNames_Static();
200 sal_Bool SAL_CALL OImageControl::supportsService(const OUString& ServiceName) throw( uno::RuntimeException, std::exception )
202 return cppu::supportsService(this, ServiceName);
205 // XReportComponent
206 REPORTCOMPONENT_IMPL(OImageControl,m_aProps.aComponent)
207 REPORTCOMPONENT_IMPL2(OImageControl,m_aProps.aComponent)
208 REPORTCOMPONENT_NOMASTERDETAIL(OImageControl)
209 NO_REPORTCONTROLFORMAT_IMPL(OImageControl)
210 OUString SAL_CALL OImageControl::getHyperLinkURL() throw (uno::RuntimeException, beans::UnknownPropertyException, std::exception)
212 ::osl::MutexGuard aGuard(m_aMutex);
213 return m_aProps.aFormatProperties.sHyperLinkURL;
215 void SAL_CALL OImageControl::setHyperLinkURL(const OUString & the_value) throw (uno::RuntimeException, beans::UnknownPropertyException, std::exception)
217 set(PROPERTY_HYPERLINKURL,the_value,m_aProps.aFormatProperties.sHyperLinkURL);
219 OUString SAL_CALL OImageControl::getHyperLinkTarget() throw (uno::RuntimeException, beans::UnknownPropertyException, std::exception)
221 ::osl::MutexGuard aGuard(m_aMutex);
222 return m_aProps.aFormatProperties.sHyperLinkTarget;
224 void SAL_CALL OImageControl::setHyperLinkTarget(const OUString & the_value) throw (uno::RuntimeException, beans::UnknownPropertyException, std::exception)
226 set(PROPERTY_HYPERLINKTARGET,the_value,m_aProps.aFormatProperties.sHyperLinkTarget);
228 OUString SAL_CALL OImageControl::getHyperLinkName() throw (uno::RuntimeException, beans::UnknownPropertyException, std::exception)
230 ::osl::MutexGuard aGuard(m_aMutex);
231 return m_aProps.aFormatProperties.sHyperLinkName;
233 void SAL_CALL OImageControl::setHyperLinkName(const OUString & the_value) throw (uno::RuntimeException, beans::UnknownPropertyException, std::exception)
235 set(PROPERTY_HYPERLINKNAME,the_value,m_aProps.aFormatProperties.sHyperLinkName);
239 ::sal_Int32 SAL_CALL OImageControl::getControlBackground() throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
241 ::osl::MutexGuard aGuard(m_aMutex);
242 return m_aProps.aFormatProperties.m_bBackgroundTransparent ? COL_TRANSPARENT : m_aProps.aFormatProperties.nBackgroundColor;
245 void SAL_CALL OImageControl::setControlBackground( ::sal_Int32 _backgroundcolor ) throw (uno::RuntimeException, beans::UnknownPropertyException, std::exception)
247 bool bTransparent = _backgroundcolor == static_cast<sal_Int32>(COL_TRANSPARENT);
248 setControlBackgroundTransparent(bTransparent);
249 if ( !bTransparent )
250 set(PROPERTY_CONTROLBACKGROUND,_backgroundcolor,m_aProps.aFormatProperties.nBackgroundColor);
253 sal_Bool SAL_CALL OImageControl::getControlBackgroundTransparent() throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
255 ::osl::MutexGuard aGuard(m_aMutex);
256 return m_aProps.aFormatProperties.m_bBackgroundTransparent;
259 void SAL_CALL OImageControl::setControlBackgroundTransparent( sal_Bool _controlbackgroundtransparent ) throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
261 set(PROPERTY_CONTROLBACKGROUNDTRANSPARENT,_controlbackgroundtransparent,m_aProps.aFormatProperties.m_bBackgroundTransparent);
262 if ( _controlbackgroundtransparent )
263 set(PROPERTY_CONTROLBACKGROUND,static_cast<sal_Int32>(COL_TRANSPARENT),m_aProps.aFormatProperties.nBackgroundColor);
267 uno::Reference< beans::XPropertySetInfo > SAL_CALL OImageControl::getPropertySetInfo( ) throw(uno::RuntimeException, std::exception)
269 return ImageControlPropertySet::getPropertySetInfo();
272 void SAL_CALL OImageControl::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue ) throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
274 ImageControlPropertySet::setPropertyValue( aPropertyName, aValue );
277 uno::Any SAL_CALL OImageControl::getPropertyValue( const OUString& PropertyName ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
279 return ImageControlPropertySet::getPropertyValue( PropertyName);
282 void SAL_CALL OImageControl::addPropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& xListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
284 ImageControlPropertySet::addPropertyChangeListener( aPropertyName, xListener );
287 void SAL_CALL OImageControl::removePropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& aListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
289 ImageControlPropertySet::removePropertyChangeListener( aPropertyName, aListener );
292 void SAL_CALL OImageControl::addVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
294 ImageControlPropertySet::addVetoableChangeListener( PropertyName, aListener );
297 void SAL_CALL OImageControl::removeVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
299 ImageControlPropertySet::removeVetoableChangeListener( PropertyName, aListener );
302 // XReportControlModel
303 OUString SAL_CALL OImageControl::getDataField() throw ( beans::UnknownPropertyException, uno::RuntimeException, std::exception)
305 ::osl::MutexGuard aGuard(m_aMutex);
306 return m_aProps.aDataField;
309 void SAL_CALL OImageControl::setDataField( const OUString& _datafield ) throw (lang::IllegalArgumentException, beans::UnknownPropertyException, uno::RuntimeException, std::exception)
311 set(PROPERTY_DATAFIELD,_datafield,m_aProps.aDataField);
315 sal_Bool SAL_CALL OImageControl::getPrintWhenGroupChange() throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
317 ::osl::MutexGuard aGuard(m_aMutex);
318 return m_aProps.bPrintWhenGroupChange;
321 void SAL_CALL OImageControl::setPrintWhenGroupChange( sal_Bool _printwhengroupchange ) throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
323 set(PROPERTY_PRINTWHENGROUPCHANGE,_printwhengroupchange,m_aProps.bPrintWhenGroupChange);
326 OUString SAL_CALL OImageControl::getConditionalPrintExpression() throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
328 ::osl::MutexGuard aGuard(m_aMutex);
329 return m_aProps.aConditionalPrintExpression;
332 void SAL_CALL OImageControl::setConditionalPrintExpression( const OUString& _conditionalprintexpression ) throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
334 set(PROPERTY_CONDITIONALPRINTEXPRESSION,_conditionalprintexpression,m_aProps.aConditionalPrintExpression);
339 // XCloneable
340 uno::Reference< util::XCloneable > SAL_CALL OImageControl::createClone( ) throw (uno::RuntimeException, std::exception)
342 uno::Reference< report::XReportComponent> xSource = this;
343 uno::Reference< report::XImageControl> xSet(cloneObject(xSource,m_aProps.aComponent.m_xFactory,SERVICE_IMAGECONTROL),uno::UNO_QUERY_THROW);
344 return xSet.get();
348 // XImageControl
350 OUString SAL_CALL OImageControl::getImageURL() throw (uno::RuntimeException, std::exception)
352 ::osl::MutexGuard aGuard(m_aMutex);
353 return m_aImageURL;
356 void SAL_CALL OImageControl::setImageURL( const OUString& _imageurl ) throw (uno::RuntimeException, std::exception)
358 set(PROPERTY_IMAGEURL,_imageurl,m_aImageURL);
361 uno::Reference< awt::XImageProducer > SAL_CALL OImageControl::getImageProducer( ) throw (uno::RuntimeException, std::exception)
363 return uno::Reference< awt::XImageProducer >();
366 // XChild
367 uno::Reference< uno::XInterface > SAL_CALL OImageControl::getParent( ) throw (uno::RuntimeException, std::exception)
369 return OShapeHelper::getParent(this);
372 void SAL_CALL OImageControl::setParent( const uno::Reference< uno::XInterface >& Parent ) throw (lang::NoSupportException, uno::RuntimeException, std::exception)
374 OShapeHelper::setParent(Parent,this);
376 uno::Reference< report::XFormatCondition > SAL_CALL OImageControl::createFormatCondition( ) throw (uno::Exception, uno::RuntimeException, std::exception)
378 return new OFormatCondition(m_aProps.aComponent.m_xContext);
381 // XContainer
382 void SAL_CALL OImageControl::addContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException, std::exception)
384 m_aProps.addContainerListener(xListener);
387 void SAL_CALL OImageControl::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException, std::exception)
389 m_aProps.removeContainerListener(xListener);
392 // XElementAccess
393 uno::Type SAL_CALL OImageControl::getElementType( ) throw (uno::RuntimeException, std::exception)
395 return cppu::UnoType<report::XFormatCondition>::get();
398 sal_Bool SAL_CALL OImageControl::hasElements( ) throw (uno::RuntimeException, std::exception)
400 return m_aProps.hasElements();
403 // XIndexContainer
404 void SAL_CALL OImageControl::insertByIndex( ::sal_Int32 Index, const uno::Any& Element ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
406 m_aProps.insertByIndex(Index,Element);
409 void SAL_CALL OImageControl::removeByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
411 m_aProps.removeByIndex(Index);
414 // XIndexReplace
415 void SAL_CALL OImageControl::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
417 m_aProps.replaceByIndex(Index,Element);
420 // XIndexAccess
421 ::sal_Int32 SAL_CALL OImageControl::getCount( ) throw (uno::RuntimeException, std::exception)
423 return m_aProps.getCount();
426 uno::Any SAL_CALL OImageControl::getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
428 return m_aProps.getByIndex( Index );
432 // XShape
433 awt::Point SAL_CALL OImageControl::getPosition( ) throw (uno::RuntimeException, std::exception)
435 return OShapeHelper::getPosition(this);
438 void SAL_CALL OImageControl::setPosition( const awt::Point& aPosition ) throw (uno::RuntimeException, std::exception)
440 OShapeHelper::setPosition(aPosition,this);
443 awt::Size SAL_CALL OImageControl::getSize( ) throw (uno::RuntimeException, std::exception)
445 return OShapeHelper::getSize(this);
448 void SAL_CALL OImageControl::setSize( const awt::Size& aSize ) throw (beans::PropertyVetoException, uno::RuntimeException, std::exception)
450 OShapeHelper::setSize(aSize,this);
454 // XShapeDescriptor
455 OUString SAL_CALL OImageControl::getShapeType( ) throw (uno::RuntimeException, std::exception)
457 ::osl::MutexGuard aGuard(m_aMutex);
458 if ( m_aProps.aComponent.m_xShape.is() )
459 return m_aProps.aComponent.m_xShape->getShapeType();
460 return OUString("com.sun.star.drawing.ControlShape");
463 ::sal_Int16 SAL_CALL OImageControl::getScaleMode() throw (uno::RuntimeException, std::exception)
465 ::osl::MutexGuard aGuard(m_aMutex);
466 return m_nScaleMode;
469 void SAL_CALL OImageControl::setScaleMode( ::sal_Int16 _scalemode ) throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
471 if ( _scalemode < awt::ImageScaleMode::NONE ||_scalemode > awt::ImageScaleMode::ANISOTROPIC )
472 throw lang::IllegalArgumentException();
473 set(PROPERTY_SCALEMODE,_scalemode,m_nScaleMode);
476 sal_Bool SAL_CALL OImageControl::getPreserveIRI() throw (uno::RuntimeException, std::exception)
478 ::osl::MutexGuard aGuard(m_aMutex);
479 return m_bPreserveIRI;
482 void SAL_CALL OImageControl::setPreserveIRI( sal_Bool _preserveiri ) throw (uno::RuntimeException, std::exception)
484 set(PROPERTY_PRESERVEIRI,_preserveiri,m_bPreserveIRI);
487 } // namespace reportdesign
490 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */