lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / reportdesign / source / core / api / FormattedField.cxx
blob6ba798b977ba13c897c55195c2ec9049c5437c0b
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 <FormattedField.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/color.hxx>
26 #include <connectivity/dbtools.hxx>
27 #include <comphelper/property.hxx>
28 #include <cppuhelper/supportsservice.hxx>
29 #include <Tools.hxx>
30 #include <FormatCondition.hxx>
31 #include <com/sun/star/text/ParagraphVertAlign.hpp>
32 #include <ReportHelperImpl.hxx>
34 namespace reportdesign
37 using namespace com::sun::star;
38 using namespace comphelper;
40 uno::Reference< uno::XInterface > OFormattedField::create(uno::Reference< uno::XComponentContext > const & xContext)
42 return *(new OFormattedField(xContext));
45 static uno::Sequence< OUString > lcl_getFormattedFieldOptionals()
47 OUString pProps[] = { OUString(PROPERTY_MASTERFIELDS),OUString(PROPERTY_DETAILFIELDS) };
48 return uno::Sequence< OUString >(pProps,SAL_N_ELEMENTS(pProps));
51 OFormattedField::OFormattedField(uno::Reference< uno::XComponentContext > const & _xContext)
52 :FormattedFieldBase(m_aMutex)
53 ,FormattedFieldPropertySet(_xContext,IMPLEMENTS_PROPERTY_SET,lcl_getFormattedFieldOptionals())
54 ,m_aProps(m_aMutex,static_cast< container::XContainer*>( this ),_xContext)
55 ,m_nFormatKey(0)
57 m_aProps.aComponent.m_sName = RptResId(RID_STR_FORMATTEDFIELD);
60 OFormattedField::OFormattedField(uno::Reference< uno::XComponentContext > const & _xContext
61 ,const uno::Reference< lang::XMultiServiceFactory>& _xFactory
62 ,uno::Reference< drawing::XShape >& _xShape)
63 :FormattedFieldBase(m_aMutex)
64 ,FormattedFieldPropertySet(_xContext,IMPLEMENTS_PROPERTY_SET,lcl_getFormattedFieldOptionals())
65 ,m_aProps(m_aMutex,static_cast< container::XContainer*>( this ),_xContext)
66 ,m_nFormatKey(0)
68 m_aProps.aComponent.m_sName = RptResId(RID_STR_FORMATTEDFIELD);
69 m_aProps.aComponent.m_xFactory = _xFactory;
70 osl_atomic_increment( &m_refCount );
72 m_aProps.aComponent.setShape(_xShape,this,m_refCount);
74 osl_atomic_decrement( &m_refCount );
77 OFormattedField::~OFormattedField()
81 IMPLEMENT_FORWARD_REFCOUNT( OFormattedField, FormattedFieldBase )
83 uno::Any SAL_CALL OFormattedField::queryInterface( const uno::Type& _rType )
85 uno::Any aReturn = FormattedFieldBase::queryInterface(_rType);
86 if ( !aReturn.hasValue() )
87 aReturn = FormattedFieldPropertySet::queryInterface(_rType);
88 if ( !aReturn.hasValue() && OReportControlModel::isInterfaceForbidden(_rType) )
89 return aReturn;
91 return aReturn.hasValue() ? aReturn : (m_aProps.aComponent.m_xProxy.is() ? m_aProps.aComponent.m_xProxy->queryAggregation(_rType) : aReturn);
95 void SAL_CALL OFormattedField::dispose()
97 FormattedFieldPropertySet::dispose();
98 cppu::WeakComponentImplHelperBase::dispose();
99 m_xFormatsSupplier.clear();
102 OUString OFormattedField::getImplementationName_Static( )
104 return OUString("com.sun.star.comp.report.OFormattedField");
108 OUString SAL_CALL OFormattedField::getImplementationName( )
110 return getImplementationName_Static();
113 uno::Sequence< OUString > OFormattedField::getSupportedServiceNames_Static( )
115 uno::Sequence< OUString > aServices(2);
116 aServices[0] = SERVICE_FORMATTEDFIELD;
117 aServices[1] = "com.sun.star.awt.UnoControlFormattedFieldModel";
119 return aServices;
122 uno::Sequence< OUString > SAL_CALL OFormattedField::getSupportedServiceNames( )
124 return getSupportedServiceNames_Static();
127 sal_Bool SAL_CALL OFormattedField::supportsService(const OUString& ServiceName)
129 return cppu::supportsService(this, ServiceName);
132 // XReportComponent
133 REPORTCOMPONENT_IMPL(OFormattedField,m_aProps.aComponent)
134 REPORTCOMPONENT_IMPL2(OFormattedField,m_aProps.aComponent)
135 REPORTCOMPONENT_NOMASTERDETAIL(OFormattedField)
136 REPORTCONTROLFORMAT_IMPL(OFormattedField,m_aProps.aFormatProperties)
139 uno::Reference< beans::XPropertySetInfo > SAL_CALL OFormattedField::getPropertySetInfo( )
141 return FormattedFieldPropertySet::getPropertySetInfo();
144 void SAL_CALL OFormattedField::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
146 // special case here /// TODO check
147 if ( !aValue.hasValue() && aPropertyName == PROPERTY_FORMATKEY )
148 m_nFormatKey = 0;
149 else
150 FormattedFieldPropertySet::setPropertyValue( aPropertyName, aValue );
153 uno::Any SAL_CALL OFormattedField::getPropertyValue( const OUString& PropertyName )
155 return FormattedFieldPropertySet::getPropertyValue( PropertyName);
158 void SAL_CALL OFormattedField::addPropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& xListener )
160 FormattedFieldPropertySet::addPropertyChangeListener( aPropertyName, xListener );
163 void SAL_CALL OFormattedField::removePropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& aListener )
165 FormattedFieldPropertySet::removePropertyChangeListener( aPropertyName, aListener );
168 void SAL_CALL OFormattedField::addVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener )
170 FormattedFieldPropertySet::addVetoableChangeListener( PropertyName, aListener );
173 void SAL_CALL OFormattedField::removeVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener )
175 FormattedFieldPropertySet::removeVetoableChangeListener( PropertyName, aListener );
178 // XReportControlModel
179 OUString SAL_CALL OFormattedField::getDataField()
181 ::osl::MutexGuard aGuard(m_aMutex);
182 return m_aProps.aDataField;
185 void SAL_CALL OFormattedField::setDataField( const OUString& _datafield )
187 set(PROPERTY_DATAFIELD,_datafield,m_aProps.aDataField);
190 sal_Bool SAL_CALL OFormattedField::getPrintWhenGroupChange()
192 ::osl::MutexGuard aGuard(m_aMutex);
193 return m_aProps.bPrintWhenGroupChange;
196 void SAL_CALL OFormattedField::setPrintWhenGroupChange( sal_Bool _printwhengroupchange )
198 set(PROPERTY_PRINTWHENGROUPCHANGE,_printwhengroupchange,m_aProps.bPrintWhenGroupChange);
201 OUString SAL_CALL OFormattedField::getConditionalPrintExpression()
203 ::osl::MutexGuard aGuard(m_aMutex);
204 return m_aProps.aConditionalPrintExpression;
207 void SAL_CALL OFormattedField::setConditionalPrintExpression( const OUString& _conditionalprintexpression )
209 set(PROPERTY_CONDITIONALPRINTEXPRESSION,_conditionalprintexpression,m_aProps.aConditionalPrintExpression);
213 // XCloneable
214 uno::Reference< util::XCloneable > SAL_CALL OFormattedField::createClone( )
216 uno::Reference< report::XReportComponent> xSource = this;
217 uno::Reference< report::XFormattedField> xSet(cloneObject(xSource,m_aProps.aComponent.m_xFactory,SERVICE_FORMATTEDFIELD),uno::UNO_QUERY_THROW);
219 ::std::vector< uno::Reference< report::XFormatCondition> >::const_iterator aIter = m_aProps.m_aFormatConditions.begin();
220 ::std::vector< uno::Reference< report::XFormatCondition> >::const_iterator aEnd = m_aProps.m_aFormatConditions.end();
221 for (sal_Int32 i = 0; aIter != aEnd; ++aIter,++i)
223 uno::Reference< report::XFormatCondition > xCond = xSet->createFormatCondition();
224 ::comphelper::copyProperties(aIter->get(),xCond.get());
225 xSet->insertByIndex(i,uno::makeAny(xCond));
227 return xSet.get();
230 // XFormattedField
232 ::sal_Int32 SAL_CALL OFormattedField::getFormatKey()
234 ::osl::MutexGuard aGuard(m_aMutex);
235 return m_nFormatKey;
238 void SAL_CALL OFormattedField::setFormatKey(::sal_Int32 _formatkey)
240 set(PROPERTY_FORMATKEY,_formatkey,m_nFormatKey);
243 uno::Reference< util::XNumberFormatsSupplier > SAL_CALL OFormattedField::getFormatsSupplier()
245 ::osl::MutexGuard aGuard(m_aMutex);
246 if ( !m_xFormatsSupplier.is() )
248 uno::Reference< report::XSection> xSection = getSection();
249 if ( xSection.is() )
250 m_xFormatsSupplier.set(xSection->getReportDefinition(),uno::UNO_QUERY);
251 if ( !m_xFormatsSupplier.is() )
253 uno::Reference< beans::XPropertySet> xProp(::dbtools::findDataSource(getParent()),uno::UNO_QUERY);
254 if ( xProp.is() )
255 m_xFormatsSupplier.set(xProp->getPropertyValue("NumberFormatsSupplier"),uno::UNO_QUERY);
258 return m_xFormatsSupplier;
261 void SAL_CALL OFormattedField::setFormatsSupplier( const uno::Reference< util::XNumberFormatsSupplier >& _formatssupplier )
263 set(PROPERTY_FORMATSSUPPLIER,_formatssupplier,m_xFormatsSupplier);
266 // XChild
267 uno::Reference< uno::XInterface > SAL_CALL OFormattedField::getParent( )
269 return OShapeHelper::getParent(this);
272 void SAL_CALL OFormattedField::setParent( const uno::Reference< uno::XInterface >& Parent )
274 OShapeHelper::setParent(Parent,this);
277 uno::Reference< report::XFormatCondition > SAL_CALL OFormattedField::createFormatCondition( )
279 return new OFormatCondition(m_aProps.aComponent.m_xContext);
282 // XContainer
283 void SAL_CALL OFormattedField::addContainerListener( const uno::Reference< container::XContainerListener >& xListener )
285 m_aProps.addContainerListener(xListener);
288 void SAL_CALL OFormattedField::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener )
290 m_aProps.removeContainerListener(xListener);
293 // XElementAccess
294 uno::Type SAL_CALL OFormattedField::getElementType( )
296 return cppu::UnoType<report::XFormatCondition>::get();
299 sal_Bool SAL_CALL OFormattedField::hasElements( )
301 return m_aProps.hasElements();
304 // XIndexContainer
305 void SAL_CALL OFormattedField::insertByIndex( ::sal_Int32 Index, const uno::Any& Element )
307 m_aProps.insertByIndex(Index,Element);
310 void SAL_CALL OFormattedField::removeByIndex( ::sal_Int32 Index )
312 m_aProps.removeByIndex(Index);
315 // XIndexReplace
316 void SAL_CALL OFormattedField::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element )
318 m_aProps.replaceByIndex(Index,Element);
321 // XIndexAccess
322 ::sal_Int32 SAL_CALL OFormattedField::getCount( )
324 return m_aProps.getCount();
327 uno::Any SAL_CALL OFormattedField::getByIndex( ::sal_Int32 Index )
329 return m_aProps.getByIndex( Index );
332 // XShape
333 awt::Point SAL_CALL OFormattedField::getPosition( )
335 return OShapeHelper::getPosition(this);
338 void SAL_CALL OFormattedField::setPosition( const awt::Point& aPosition )
340 OShapeHelper::setPosition(aPosition,this);
343 awt::Size SAL_CALL OFormattedField::getSize( )
345 return OShapeHelper::getSize(this);
348 void SAL_CALL OFormattedField::setSize( const awt::Size& aSize )
350 OShapeHelper::setSize(aSize,this);
354 // XShapeDescriptor
355 OUString SAL_CALL OFormattedField::getShapeType( )
357 ::osl::MutexGuard aGuard(m_aMutex);
358 if ( m_aProps.aComponent.m_xShape.is() )
359 return m_aProps.aComponent.m_xShape->getShapeType();
360 return OUString("com.sun.star.drawing.ControlShape");
364 } // namespace reportdesign
367 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */