lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / reportdesign / source / core / api / ImageControl.cxx
blob247d1042824f59fa3a17eb7af12a38a55a0c08bc
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 <strings.hxx>
23 #include <strings.hrc>
24 #include <core_resource.hxx>
25 #include <Tools.hxx>
26 #include <tools/color.hxx>
27 #include <cppuhelper/supportsservice.hxx>
28 #include <FormatCondition.hxx>
29 #include <com/sun/star/awt/ImageScaleMode.hpp>
30 #include <com/sun/star/text/ParagraphVertAlign.hpp>
31 #include <ReportHelperImpl.hxx>
33 namespace reportdesign
36 using namespace com::sun::star;
37 static uno::Sequence< OUString > lcl_getImageOptionals()
39 OUString pProps[] = {
40 OUString(PROPERTY_CHARCOLOR)
41 ,OUString(PROPERTY_CHAREMPHASIS)
42 ,OUString(PROPERTY_CHARFONTCHARSET)
43 ,OUString(PROPERTY_CHARFONTFAMILY)
44 ,OUString(PROPERTY_CHARFONTNAME)
45 ,OUString(PROPERTY_CHARFONTPITCH)
46 ,OUString(PROPERTY_CHARFONTSTYLENAME)
47 ,OUString(PROPERTY_CHARHEIGHT)
48 ,OUString(PROPERTY_CHARPOSTURE)
49 ,OUString(PROPERTY_CHARRELIEF)
50 ,OUString(PROPERTY_FONTDESCRIPTOR)
51 ,OUString(PROPERTY_FONTDESCRIPTORASIAN)
52 ,OUString(PROPERTY_FONTDESCRIPTORCOMPLEX)
53 ,OUString(PROPERTY_CONTROLTEXTEMPHASISMARK)
54 ,OUString(PROPERTY_CHARROTATION)
55 ,OUString(PROPERTY_CHARSCALEWIDTH)
56 ,OUString(PROPERTY_CHARSTRIKEOUT)
57 ,OUString(PROPERTY_CHARUNDERLINECOLOR)
58 ,OUString(PROPERTY_CHARUNDERLINE)
59 ,OUString(PROPERTY_CHARWEIGHT)
60 ,OUString(PROPERTY_CHARWORDMODE)
61 ,OUString(PROPERTY_CHARFLASH)
62 ,OUString(PROPERTY_CHARAUTOKERNING)
63 ,OUString(PROPERTY_CHARESCAPEMENTHEIGHT)
64 ,OUString(PROPERTY_CHARLOCALE)
65 ,OUString(PROPERTY_CHARESCAPEMENT)
66 ,OUString(PROPERTY_CHARCASEMAP)
67 ,OUString(PROPERTY_CHARCOMBINEISON)
68 ,OUString(PROPERTY_CHARCOMBINEPREFIX)
69 ,OUString(PROPERTY_CHARCOMBINESUFFIX)
70 ,OUString(PROPERTY_CHARHIDDEN)
71 ,OUString(PROPERTY_CHARSHADOWED)
72 ,OUString(PROPERTY_CHARCONTOURED)
73 ,OUString(PROPERTY_VISITEDCHARSTYLENAME)
74 ,OUString(PROPERTY_UNVISITEDCHARSTYLENAME)
75 ,OUString(PROPERTY_CHARKERNING)
76 ,OUString(PROPERTY_MASTERFIELDS)
77 ,OUString(PROPERTY_DETAILFIELDS)
78 ,OUString(PROPERTY_PARAADJUST)
79 , OUString(PROPERTY_CHAREMPHASISASIAN)
80 , OUString(PROPERTY_CHARFONTNAMEASIAN)
81 , OUString(PROPERTY_CHARFONTSTYLENAMEASIAN)
82 , OUString(PROPERTY_CHARFONTFAMILYASIAN)
83 , OUString(PROPERTY_CHARFONTCHARSETASIAN)
84 , OUString(PROPERTY_CHARFONTPITCHASIAN)
85 , OUString(PROPERTY_CHARHEIGHTASIAN)
86 , OUString(PROPERTY_CHARUNDERLINEASIAN)
87 , OUString(PROPERTY_CHARWEIGHTASIAN)
88 , OUString(PROPERTY_CHARPOSTUREASIAN)
89 , OUString(PROPERTY_CHARWORDMODEASIAN)
90 , OUString(PROPERTY_CHARROTATIONASIAN)
91 , OUString(PROPERTY_CHARSCALEWIDTHASIAN)
92 , OUString(PROPERTY_CHARLOCALEASIAN)
93 , OUString(PROPERTY_CHAREMPHASISCOMPLEX)
94 , OUString(PROPERTY_CHARFONTNAMECOMPLEX)
95 , OUString(PROPERTY_CHARFONTSTYLENAMECOMPLEX)
96 , OUString(PROPERTY_CHARFONTFAMILYCOMPLEX)
97 , OUString(PROPERTY_CHARFONTCHARSETCOMPLEX)
98 , OUString(PROPERTY_CHARFONTPITCHCOMPLEX)
99 , OUString(PROPERTY_CHARHEIGHTCOMPLEX)
100 , OUString(PROPERTY_CHARUNDERLINECOMPLEX)
101 , OUString(PROPERTY_CHARWEIGHTCOMPLEX)
102 , OUString(PROPERTY_CHARPOSTURECOMPLEX)
103 , OUString(PROPERTY_CHARWORDMODECOMPLEX)
104 , OUString(PROPERTY_CHARROTATIONCOMPLEX)
105 , OUString(PROPERTY_CHARSCALEWIDTHCOMPLEX)
106 , OUString(PROPERTY_CHARLOCALECOMPLEX)
109 return uno::Sequence< OUString >(pProps,SAL_N_ELEMENTS(pProps));
113 OImageControl::OImageControl(uno::Reference< uno::XComponentContext > const & _xContext)
114 :ImageControlBase(m_aMutex)
115 ,ImageControlPropertySet(_xContext,IMPLEMENTS_PROPERTY_SET,lcl_getImageOptionals())
116 ,m_aProps(m_aMutex,static_cast< container::XContainer*>( this ),_xContext)
117 ,m_nScaleMode(awt::ImageScaleMode::NONE)
118 ,m_bPreserveIRI(true)
120 m_aProps.aComponent.m_sName = RptResId(RID_STR_IMAGECONTROL);
123 OImageControl::OImageControl(uno::Reference< uno::XComponentContext > const & _xContext
124 ,const uno::Reference< lang::XMultiServiceFactory>& _xFactory
125 ,uno::Reference< drawing::XShape >& _xShape)
126 :ImageControlBase(m_aMutex)
127 ,ImageControlPropertySet(_xContext,IMPLEMENTS_PROPERTY_SET,lcl_getImageOptionals())
128 ,m_aProps(m_aMutex,static_cast< container::XContainer*>( this ),_xContext)
129 ,m_nScaleMode(awt::ImageScaleMode::NONE)
130 ,m_bPreserveIRI(true)
132 m_aProps.aComponent.m_sName = RptResId(RID_STR_IMAGECONTROL);
133 m_aProps.aComponent.m_xFactory = _xFactory;
134 osl_atomic_increment( &m_refCount );
136 m_aProps.aComponent.setShape(_xShape,this,m_refCount);
138 osl_atomic_decrement( &m_refCount );
141 OImageControl::~OImageControl()
145 //IMPLEMENT_FORWARD_XINTERFACE2(OImageControl,ImageControlBase,ImageControlPropertySet)
146 IMPLEMENT_FORWARD_REFCOUNT( OImageControl, ImageControlBase )
148 uno::Any SAL_CALL OImageControl::queryInterface( const uno::Type& _rType )
150 uno::Any aReturn = ImageControlBase::queryInterface(_rType);
151 if ( !aReturn.hasValue() )
152 aReturn = ImageControlPropertySet::queryInterface(_rType);
154 if ( !aReturn.hasValue() && OReportControlModel::isInterfaceForbidden(_rType) )
155 return aReturn;
157 return aReturn.hasValue() ? aReturn : (m_aProps.aComponent.m_xProxy.is() ? m_aProps.aComponent.m_xProxy->queryAggregation(_rType) : aReturn);
161 void SAL_CALL OImageControl::dispose()
163 ImageControlPropertySet::dispose();
164 cppu::WeakComponentImplHelperBase::dispose();
167 OUString OImageControl::getImplementationName_Static( )
169 return OUString("com.sun.star.comp.report.OImageControl");
173 OUString SAL_CALL OImageControl::getImplementationName( )
175 return getImplementationName_Static();
178 uno::Sequence< OUString > OImageControl::getSupportedServiceNames_Static( )
180 uno::Sequence< OUString > aServices { SERVICE_IMAGECONTROL };
182 return aServices;
185 uno::Reference< uno::XInterface > OImageControl::create(uno::Reference< uno::XComponentContext > const & xContext)
187 return *(new OImageControl(xContext));
191 uno::Sequence< OUString > SAL_CALL OImageControl::getSupportedServiceNames( )
193 return getSupportedServiceNames_Static();
196 sal_Bool SAL_CALL OImageControl::supportsService(const OUString& ServiceName)
198 return cppu::supportsService(this, ServiceName);
201 // XReportComponent
202 REPORTCOMPONENT_IMPL(OImageControl,m_aProps.aComponent)
203 REPORTCOMPONENT_IMPL2(OImageControl,m_aProps.aComponent)
204 REPORTCOMPONENT_NOMASTERDETAIL(OImageControl)
205 NO_REPORTCONTROLFORMAT_IMPL(OImageControl)
206 OUString SAL_CALL OImageControl::getHyperLinkURL()
208 ::osl::MutexGuard aGuard(m_aMutex);
209 return m_aProps.aFormatProperties.sHyperLinkURL;
211 void SAL_CALL OImageControl::setHyperLinkURL(const OUString & the_value)
213 set(PROPERTY_HYPERLINKURL,the_value,m_aProps.aFormatProperties.sHyperLinkURL);
215 OUString SAL_CALL OImageControl::getHyperLinkTarget()
217 ::osl::MutexGuard aGuard(m_aMutex);
218 return m_aProps.aFormatProperties.sHyperLinkTarget;
220 void SAL_CALL OImageControl::setHyperLinkTarget(const OUString & the_value)
222 set(PROPERTY_HYPERLINKTARGET,the_value,m_aProps.aFormatProperties.sHyperLinkTarget);
224 OUString SAL_CALL OImageControl::getHyperLinkName()
226 ::osl::MutexGuard aGuard(m_aMutex);
227 return m_aProps.aFormatProperties.sHyperLinkName;
229 void SAL_CALL OImageControl::setHyperLinkName(const OUString & the_value)
231 set(PROPERTY_HYPERLINKNAME,the_value,m_aProps.aFormatProperties.sHyperLinkName);
235 ::sal_Int32 SAL_CALL OImageControl::getControlBackground()
237 ::osl::MutexGuard aGuard(m_aMutex);
238 return sal_Int32(m_aProps.aFormatProperties.m_bBackgroundTransparent ? COL_TRANSPARENT : m_aProps.aFormatProperties.nBackgroundColor);
241 void SAL_CALL OImageControl::setControlBackground( ::sal_Int32 _backgroundcolor )
243 bool bTransparent = _backgroundcolor == static_cast<sal_Int32>(COL_TRANSPARENT);
244 setControlBackgroundTransparent(bTransparent);
245 if ( !bTransparent )
246 set(PROPERTY_CONTROLBACKGROUND,_backgroundcolor,m_aProps.aFormatProperties.nBackgroundColor);
249 sal_Bool SAL_CALL OImageControl::getControlBackgroundTransparent()
251 ::osl::MutexGuard aGuard(m_aMutex);
252 return m_aProps.aFormatProperties.m_bBackgroundTransparent;
255 void SAL_CALL OImageControl::setControlBackgroundTransparent( sal_Bool _controlbackgroundtransparent )
257 set(PROPERTY_CONTROLBACKGROUNDTRANSPARENT,_controlbackgroundtransparent,m_aProps.aFormatProperties.m_bBackgroundTransparent);
258 if ( _controlbackgroundtransparent )
259 set(PROPERTY_CONTROLBACKGROUND,static_cast<sal_Int32>(COL_TRANSPARENT),m_aProps.aFormatProperties.nBackgroundColor);
263 uno::Reference< beans::XPropertySetInfo > SAL_CALL OImageControl::getPropertySetInfo( )
265 return ImageControlPropertySet::getPropertySetInfo();
268 void SAL_CALL OImageControl::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
270 ImageControlPropertySet::setPropertyValue( aPropertyName, aValue );
273 uno::Any SAL_CALL OImageControl::getPropertyValue( const OUString& PropertyName )
275 return ImageControlPropertySet::getPropertyValue( PropertyName);
278 void SAL_CALL OImageControl::addPropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& xListener )
280 ImageControlPropertySet::addPropertyChangeListener( aPropertyName, xListener );
283 void SAL_CALL OImageControl::removePropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& aListener )
285 ImageControlPropertySet::removePropertyChangeListener( aPropertyName, aListener );
288 void SAL_CALL OImageControl::addVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener )
290 ImageControlPropertySet::addVetoableChangeListener( PropertyName, aListener );
293 void SAL_CALL OImageControl::removeVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener )
295 ImageControlPropertySet::removeVetoableChangeListener( PropertyName, aListener );
298 // XReportControlModel
299 OUString SAL_CALL OImageControl::getDataField()
301 ::osl::MutexGuard aGuard(m_aMutex);
302 return m_aProps.aDataField;
305 void SAL_CALL OImageControl::setDataField( const OUString& _datafield )
307 set(PROPERTY_DATAFIELD,_datafield,m_aProps.aDataField);
311 sal_Bool SAL_CALL OImageControl::getPrintWhenGroupChange()
313 ::osl::MutexGuard aGuard(m_aMutex);
314 return m_aProps.bPrintWhenGroupChange;
317 void SAL_CALL OImageControl::setPrintWhenGroupChange( sal_Bool _printwhengroupchange )
319 set(PROPERTY_PRINTWHENGROUPCHANGE,_printwhengroupchange,m_aProps.bPrintWhenGroupChange);
322 OUString SAL_CALL OImageControl::getConditionalPrintExpression()
324 ::osl::MutexGuard aGuard(m_aMutex);
325 return m_aProps.aConditionalPrintExpression;
328 void SAL_CALL OImageControl::setConditionalPrintExpression( const OUString& _conditionalprintexpression )
330 set(PROPERTY_CONDITIONALPRINTEXPRESSION,_conditionalprintexpression,m_aProps.aConditionalPrintExpression);
334 // XCloneable
335 uno::Reference< util::XCloneable > SAL_CALL OImageControl::createClone( )
337 uno::Reference< report::XReportComponent> xSource = this;
338 uno::Reference< report::XImageControl> xSet(cloneObject(xSource,m_aProps.aComponent.m_xFactory,SERVICE_IMAGECONTROL),uno::UNO_QUERY_THROW);
339 return xSet.get();
343 // XImageControl
345 OUString SAL_CALL OImageControl::getImageURL()
347 ::osl::MutexGuard aGuard(m_aMutex);
348 return m_aImageURL;
351 void SAL_CALL OImageControl::setImageURL( const OUString& _imageurl )
353 set(PROPERTY_IMAGEURL,_imageurl,m_aImageURL);
356 uno::Reference< awt::XImageProducer > SAL_CALL OImageControl::getImageProducer( )
358 return uno::Reference< awt::XImageProducer >();
361 // XChild
362 uno::Reference< uno::XInterface > SAL_CALL OImageControl::getParent( )
364 return OShapeHelper::getParent(this);
367 void SAL_CALL OImageControl::setParent( const uno::Reference< uno::XInterface >& Parent )
369 OShapeHelper::setParent(Parent,this);
371 uno::Reference< report::XFormatCondition > SAL_CALL OImageControl::createFormatCondition( )
373 return new OFormatCondition(m_aProps.aComponent.m_xContext);
376 // XContainer
377 void SAL_CALL OImageControl::addContainerListener( const uno::Reference< container::XContainerListener >& xListener )
379 m_aProps.addContainerListener(xListener);
382 void SAL_CALL OImageControl::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener )
384 m_aProps.removeContainerListener(xListener);
387 // XElementAccess
388 uno::Type SAL_CALL OImageControl::getElementType( )
390 return cppu::UnoType<report::XFormatCondition>::get();
393 sal_Bool SAL_CALL OImageControl::hasElements( )
395 return m_aProps.hasElements();
398 // XIndexContainer
399 void SAL_CALL OImageControl::insertByIndex( ::sal_Int32 Index, const uno::Any& Element )
401 m_aProps.insertByIndex(Index,Element);
404 void SAL_CALL OImageControl::removeByIndex( ::sal_Int32 Index )
406 m_aProps.removeByIndex(Index);
409 // XIndexReplace
410 void SAL_CALL OImageControl::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element )
412 m_aProps.replaceByIndex(Index,Element);
415 // XIndexAccess
416 ::sal_Int32 SAL_CALL OImageControl::getCount( )
418 return m_aProps.getCount();
421 uno::Any SAL_CALL OImageControl::getByIndex( ::sal_Int32 Index )
423 return m_aProps.getByIndex( Index );
427 // XShape
428 awt::Point SAL_CALL OImageControl::getPosition( )
430 return OShapeHelper::getPosition(this);
433 void SAL_CALL OImageControl::setPosition( const awt::Point& aPosition )
435 OShapeHelper::setPosition(aPosition,this);
438 awt::Size SAL_CALL OImageControl::getSize( )
440 return OShapeHelper::getSize(this);
443 void SAL_CALL OImageControl::setSize( const awt::Size& aSize )
445 OShapeHelper::setSize(aSize,this);
449 // XShapeDescriptor
450 OUString SAL_CALL OImageControl::getShapeType( )
452 ::osl::MutexGuard aGuard(m_aMutex);
453 if ( m_aProps.aComponent.m_xShape.is() )
454 return m_aProps.aComponent.m_xShape->getShapeType();
455 return OUString("com.sun.star.drawing.ControlShape");
458 ::sal_Int16 SAL_CALL OImageControl::getScaleMode()
460 ::osl::MutexGuard aGuard(m_aMutex);
461 return m_nScaleMode;
464 void SAL_CALL OImageControl::setScaleMode( ::sal_Int16 _scalemode )
466 if ( _scalemode < awt::ImageScaleMode::NONE ||_scalemode > awt::ImageScaleMode::ANISOTROPIC )
467 throw lang::IllegalArgumentException();
468 set(PROPERTY_SCALEMODE,_scalemode,m_nScaleMode);
471 sal_Bool SAL_CALL OImageControl::getPreserveIRI()
473 ::osl::MutexGuard aGuard(m_aMutex);
474 return m_bPreserveIRI;
477 void SAL_CALL OImageControl::setPreserveIRI( sal_Bool _preserveiri )
479 set(PROPERTY_PRESERVEIRI,_preserveiri,m_bPreserveIRI);
482 } // namespace reportdesign
485 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */