bump product version to 4.1.6.2
[LibreOffice.git] / reportdesign / source / core / api / FormattedField.cxx
blob9aa5090f07f62cc2502575ce02995878ab56024a
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 "corestrings.hrc"
23 #include "core_resource.hrc"
24 #include "core_resource.hxx"
25 #include <comphelper/sequence.hxx>
26 #include <tools/color.hxx>
27 #include <tools/debug.hxx>
28 #include <connectivity/dbtools.hxx>
29 #include <comphelper/property.hxx>
30 #include "Tools.hxx"
31 #include "FormatCondition.hxx"
32 #include <com/sun/star/text/ParagraphVertAlign.hpp>
33 #include "ReportHelperImpl.hxx"
34 // =============================================================================
35 namespace reportdesign
37 // =============================================================================
38 using namespace com::sun::star;
39 using namespace comphelper;
40 //------------------------------------------------------------------------------
41 uno::Reference< uno::XInterface > OFormattedField::create(uno::Reference< uno::XComponentContext > const & xContext)
43 return *(new OFormattedField(xContext));
46 uno::Sequence< OUString > lcl_getFormattedFieldOptionals()
48 OUString pProps[] = { OUString(PROPERTY_MASTERFIELDS),OUString(PROPERTY_DETAILFIELDS) };
49 return uno::Sequence< OUString >(pProps,sizeof(pProps)/sizeof(pProps[0]));
51 DBG_NAME( rpt_OFormattedField )
52 // -----------------------------------------------------------------------------
53 OFormattedField::OFormattedField(uno::Reference< uno::XComponentContext > const & _xContext)
54 :FormattedFieldBase(m_aMutex)
55 ,FormattedFieldPropertySet(_xContext,static_cast< Implements >(IMPLEMENTS_PROPERTY_SET),lcl_getFormattedFieldOptionals())
56 ,m_aProps(m_aMutex,static_cast< container::XContainer*>( this ),_xContext)
57 ,m_nFormatKey(0)
59 DBG_CTOR( rpt_OFormattedField,NULL);
60 m_aProps.aComponent.m_sName = RPT_RESSTRING(RID_STR_FORMATTEDFIELD,m_aProps.aComponent.m_xContext->getServiceManager());
62 // -----------------------------------------------------------------------------
63 OFormattedField::OFormattedField(uno::Reference< uno::XComponentContext > const & _xContext
64 ,const uno::Reference< lang::XMultiServiceFactory>& _xFactory
65 ,uno::Reference< drawing::XShape >& _xShape)
66 :FormattedFieldBase(m_aMutex)
67 ,FormattedFieldPropertySet(_xContext,static_cast< Implements >(IMPLEMENTS_PROPERTY_SET),lcl_getFormattedFieldOptionals())
68 ,m_aProps(m_aMutex,static_cast< container::XContainer*>( this ),_xContext)
69 ,m_nFormatKey(0)
71 DBG_CTOR( rpt_OFormattedField,NULL);
72 m_aProps.aComponent.m_sName = RPT_RESSTRING(RID_STR_FORMATTEDFIELD,m_aProps.aComponent.m_xContext->getServiceManager());
73 m_aProps.aComponent.m_xFactory = _xFactory;
74 osl_atomic_increment( &m_refCount );
76 m_aProps.aComponent.setShape(_xShape,this,m_refCount);
78 osl_atomic_decrement( &m_refCount );
80 // -----------------------------------------------------------------------------
81 OFormattedField::~OFormattedField()
83 DBG_DTOR( rpt_OFormattedField,NULL);
85 // -----------------------------------------------------------------------------
86 IMPLEMENT_FORWARD_REFCOUNT( OFormattedField, FormattedFieldBase )
87 // --------------------------------------------------------------------------------
88 uno::Any SAL_CALL OFormattedField::queryInterface( const uno::Type& _rType ) throw (uno::RuntimeException)
90 uno::Any aReturn = FormattedFieldBase::queryInterface(_rType);
91 if ( !aReturn.hasValue() )
92 aReturn = FormattedFieldPropertySet::queryInterface(_rType);
93 if ( !aReturn.hasValue() && OReportControlModel::isInterfaceForbidden(_rType) )
94 return aReturn;
96 return aReturn.hasValue() ? aReturn : (m_aProps.aComponent.m_xProxy.is() ? m_aProps.aComponent.m_xProxy->queryAggregation(_rType) : aReturn);
99 // -----------------------------------------------------------------------------
100 void SAL_CALL OFormattedField::dispose() throw(uno::RuntimeException)
102 FormattedFieldPropertySet::dispose();
103 cppu::WeakComponentImplHelperBase::dispose();
104 m_xFormatsSupplier.clear();
105 m_xFunction.clear();
107 // -----------------------------------------------------------------------------
108 OUString OFormattedField::getImplementationName_Static( ) throw(uno::RuntimeException)
110 return OUString("com.sun.star.comp.report.OFormattedField");
113 //--------------------------------------------------------------------------
114 OUString SAL_CALL OFormattedField::getImplementationName( ) throw(uno::RuntimeException)
116 return getImplementationName_Static();
118 //--------------------------------------------------------------------------
119 uno::Sequence< OUString > OFormattedField::getSupportedServiceNames_Static( ) throw(uno::RuntimeException)
121 uno::Sequence< OUString > aServices(2);
122 aServices.getArray()[0] = SERVICE_FORMATTEDFIELD;
123 aServices.getArray()[1] = OUString("com.sun.star.awt.UnoControlFormattedFieldModel");
125 return aServices;
127 //--------------------------------------------------------------------------
128 uno::Sequence< OUString > SAL_CALL OFormattedField::getSupportedServiceNames( ) throw(uno::RuntimeException)
130 return getSupportedServiceNames_Static();
132 //------------------------------------------------------------------------------
133 sal_Bool SAL_CALL OFormattedField::supportsService(const OUString& ServiceName) throw( uno::RuntimeException )
135 return ::comphelper::existsValue(ServiceName,getSupportedServiceNames_Static());
137 // -----------------------------------------------------------------------------
138 // XReportComponent
139 REPORTCOMPONENT_IMPL(OFormattedField,m_aProps.aComponent)
140 REPORTCOMPONENT_IMPL2(OFormattedField,m_aProps.aComponent)
141 REPORTCOMPONENT_NOMASTERDETAIL(OFormattedField)
142 REPORTCONTROLFORMAT_IMPL(OFormattedField,m_aProps.aFormatProperties)
144 // -----------------------------------------------------------------------------
145 uno::Reference< beans::XPropertySetInfo > SAL_CALL OFormattedField::getPropertySetInfo( ) throw(uno::RuntimeException)
147 return FormattedFieldPropertySet::getPropertySetInfo();
149 // -----------------------------------------------------------------------------
150 void SAL_CALL OFormattedField::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue ) throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
152 // special case here /// TODO check
153 if ( !aValue.hasValue() && aPropertyName == PROPERTY_FORMATKEY )
154 m_nFormatKey = 0;
155 else
156 FormattedFieldPropertySet::setPropertyValue( aPropertyName, aValue );
158 // -----------------------------------------------------------------------------
159 uno::Any SAL_CALL OFormattedField::getPropertyValue( const OUString& PropertyName ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
161 return FormattedFieldPropertySet::getPropertyValue( PropertyName);
163 // -----------------------------------------------------------------------------
164 void SAL_CALL OFormattedField::addPropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& xListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
166 FormattedFieldPropertySet::addPropertyChangeListener( aPropertyName, xListener );
168 // -----------------------------------------------------------------------------
169 void SAL_CALL OFormattedField::removePropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& aListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
171 FormattedFieldPropertySet::removePropertyChangeListener( aPropertyName, aListener );
173 // -----------------------------------------------------------------------------
174 void SAL_CALL OFormattedField::addVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
176 FormattedFieldPropertySet::addVetoableChangeListener( PropertyName, aListener );
178 // -----------------------------------------------------------------------------
179 void SAL_CALL OFormattedField::removeVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
181 FormattedFieldPropertySet::removeVetoableChangeListener( PropertyName, aListener );
183 // -----------------------------------------------------------------------------
184 // XReportControlModel
185 OUString SAL_CALL OFormattedField::getDataField() throw ( beans::UnknownPropertyException, uno::RuntimeException)
187 ::osl::MutexGuard aGuard(m_aMutex);
188 return m_aProps.aDataField;
190 // -----------------------------------------------------------------------------
191 void SAL_CALL OFormattedField::setDataField( const OUString& _datafield ) throw (lang::IllegalArgumentException, beans::UnknownPropertyException, uno::RuntimeException)
193 set(PROPERTY_DATAFIELD,_datafield,m_aProps.aDataField);
195 // -----------------------------------------------------------------------------
196 ::sal_Bool SAL_CALL OFormattedField::getPrintWhenGroupChange() throw (beans::UnknownPropertyException, uno::RuntimeException)
198 ::osl::MutexGuard aGuard(m_aMutex);
199 return m_aProps.bPrintWhenGroupChange;
201 // -----------------------------------------------------------------------------
202 void SAL_CALL OFormattedField::setPrintWhenGroupChange( ::sal_Bool _printwhengroupchange ) throw (beans::UnknownPropertyException, uno::RuntimeException)
204 set(PROPERTY_PRINTWHENGROUPCHANGE,_printwhengroupchange,m_aProps.bPrintWhenGroupChange);
206 // -----------------------------------------------------------------------------
207 OUString SAL_CALL OFormattedField::getConditionalPrintExpression() throw (beans::UnknownPropertyException, uno::RuntimeException)
209 ::osl::MutexGuard aGuard(m_aMutex);
210 return m_aProps.aConditionalPrintExpression;
212 // -----------------------------------------------------------------------------
213 void SAL_CALL OFormattedField::setConditionalPrintExpression( const OUString& _conditionalprintexpression ) throw (beans::UnknownPropertyException, uno::RuntimeException)
215 set(PROPERTY_CONDITIONALPRINTEXPRESSION,_conditionalprintexpression,m_aProps.aConditionalPrintExpression);
218 // -----------------------------------------------------------------------------
220 // XCloneable
221 uno::Reference< util::XCloneable > SAL_CALL OFormattedField::createClone( ) throw (uno::RuntimeException)
223 uno::Reference< report::XReportComponent> xSource = this;
224 uno::Reference< report::XFormattedField> xSet(cloneObject(xSource,m_aProps.aComponent.m_xFactory,SERVICE_FORMATTEDFIELD),uno::UNO_QUERY_THROW);
226 if ( xSet.is() )
228 ::std::vector< uno::Reference< report::XFormatCondition> >::iterator aIter = m_aProps.m_aFormatConditions.begin();
229 ::std::vector< uno::Reference< report::XFormatCondition> >::iterator aEnd = m_aProps.m_aFormatConditions.end();
230 for (sal_Int32 i = 0; aIter != aEnd; ++aIter,++i)
232 uno::Reference< report::XFormatCondition > xCond = xSet->createFormatCondition();
233 ::comphelper::copyProperties(aIter->get(),xCond.get());
234 xSet->insertByIndex(i,uno::makeAny(xCond));
237 return xSet.get();
239 // -----------------------------------------------------------------------------
240 // XFormattedField
241 // -----------------------------------------------------------------------------
242 ::sal_Int32 SAL_CALL OFormattedField::getFormatKey() throw (uno::RuntimeException)
244 ::osl::MutexGuard aGuard(m_aMutex);
245 return m_nFormatKey;
248 void SAL_CALL OFormattedField::setFormatKey(::sal_Int32 _formatkey) throw (uno::RuntimeException)
250 set(PROPERTY_FORMATKEY,_formatkey,m_nFormatKey);
252 // -----------------------------------------------------------------------------
253 uno::Reference< util::XNumberFormatsSupplier > SAL_CALL OFormattedField::getFormatsSupplier() throw (uno::RuntimeException)
255 ::osl::MutexGuard aGuard(m_aMutex);
256 if ( !m_xFormatsSupplier.is() )
258 uno::Reference< report::XSection> xSection = getSection();
259 if ( xSection.is() )
260 m_xFormatsSupplier.set(xSection->getReportDefinition(),uno::UNO_QUERY);
261 if ( !m_xFormatsSupplier.is() )
263 uno::Reference< beans::XPropertySet> xProp(::dbtools::findDataSource(getParent()),uno::UNO_QUERY);
264 if ( xProp.is() )
265 m_xFormatsSupplier.set(xProp->getPropertyValue(OUString("NumberFormatsSupplier")),uno::UNO_QUERY);
268 return m_xFormatsSupplier;
270 // -----------------------------------------------------------------------------
271 void SAL_CALL OFormattedField::setFormatsSupplier( const uno::Reference< util::XNumberFormatsSupplier >& _formatssupplier ) throw (uno::RuntimeException)
273 set(PROPERTY_FORMATSSUPPLIER,_formatssupplier,m_xFormatsSupplier);
275 // -----------------------------------------------------------------------------
276 // XChild
277 uno::Reference< uno::XInterface > SAL_CALL OFormattedField::getParent( ) throw (uno::RuntimeException)
279 return OShapeHelper::getParent(this);
281 // -----------------------------------------------------------------------------
282 void SAL_CALL OFormattedField::setParent( const uno::Reference< uno::XInterface >& Parent ) throw (lang::NoSupportException, uno::RuntimeException)
284 OShapeHelper::setParent(Parent,this);
286 // -----------------------------------------------------------------------------
287 uno::Reference< report::XFormatCondition > SAL_CALL OFormattedField::createFormatCondition( ) throw (uno::Exception, uno::RuntimeException)
289 return new OFormatCondition(m_aProps.aComponent.m_xContext);
291 // -----------------------------------------------------------------------------
292 // XContainer
293 void SAL_CALL OFormattedField::addContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException)
295 m_aProps.addContainerListener(xListener);
297 // -----------------------------------------------------------------------------
298 void SAL_CALL OFormattedField::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException)
300 m_aProps.removeContainerListener(xListener);
302 // -----------------------------------------------------------------------------
303 // XElementAccess
304 uno::Type SAL_CALL OFormattedField::getElementType( ) throw (uno::RuntimeException)
306 return ::getCppuType(static_cast< uno::Reference<report::XFormatCondition>*>(NULL));
308 // -----------------------------------------------------------------------------
309 ::sal_Bool SAL_CALL OFormattedField::hasElements( ) throw (uno::RuntimeException)
311 return m_aProps.hasElements();
313 // -----------------------------------------------------------------------------
314 // XIndexContainer
315 void SAL_CALL OFormattedField::insertByIndex( ::sal_Int32 Index, const uno::Any& Element ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
317 m_aProps.insertByIndex(Index,Element);
319 // -----------------------------------------------------------------------------
320 void SAL_CALL OFormattedField::removeByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
322 m_aProps.removeByIndex(Index);
324 // -----------------------------------------------------------------------------
325 // XIndexReplace
326 void SAL_CALL OFormattedField::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
328 m_aProps.replaceByIndex(Index,Element);
330 // -----------------------------------------------------------------------------
331 // XIndexAccess
332 ::sal_Int32 SAL_CALL OFormattedField::getCount( ) throw (uno::RuntimeException)
334 return m_aProps.getCount();
336 // -----------------------------------------------------------------------------
337 uno::Any SAL_CALL OFormattedField::getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
339 return m_aProps.getByIndex( Index );
341 // -----------------------------------------------------------------------------
342 // XShape
343 awt::Point SAL_CALL OFormattedField::getPosition( ) throw (uno::RuntimeException)
345 return OShapeHelper::getPosition(this);
347 // -----------------------------------------------------------------------------
348 void SAL_CALL OFormattedField::setPosition( const awt::Point& aPosition ) throw (uno::RuntimeException)
350 OShapeHelper::setPosition(aPosition,this);
352 // -----------------------------------------------------------------------------
353 awt::Size SAL_CALL OFormattedField::getSize( ) throw (uno::RuntimeException)
355 return OShapeHelper::getSize(this);
357 // -----------------------------------------------------------------------------
358 void SAL_CALL OFormattedField::setSize( const awt::Size& aSize ) throw (beans::PropertyVetoException, uno::RuntimeException)
360 OShapeHelper::setSize(aSize,this);
362 // -----------------------------------------------------------------------------
364 // XShapeDescriptor
365 OUString SAL_CALL OFormattedField::getShapeType( ) throw (uno::RuntimeException)
367 ::osl::MutexGuard aGuard(m_aMutex);
368 if ( m_aProps.aComponent.m_xShape.is() )
369 return m_aProps.aComponent.m_xShape->getShapeType();
370 return OUString("com.sun.star.drawing.ControlShape");
372 // -----------------------------------------------------------------------------
373 // =============================================================================
374 } // namespace reportdesign
375 // =============================================================================
377 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */