update dev300-m58
[ooovba.git] / reportdesign / source / core / api / FormattedField.cxx
blob9a3ce6919fe3f28dd708198a07af24e39004dddc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: FormattedField.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include "FormattedField.hxx"
31 #include <com/sun/star/beans/PropertyAttribute.hpp>
32 #include <com/sun/star/beans/XPropertyState.hpp>
33 #ifndef REPORTDESIGN_SHARED_CORESTRINGS_HRC
34 #include "corestrings.hrc"
35 #endif
36 #ifndef REPORTDESIGN_CORE_RESOURCE_HRC_
37 #include "core_resource.hrc"
38 #endif
39 #include "core_resource.hxx"
40 #include <comphelper/sequence.hxx>
41 #include <tools/debug.hxx>
42 #include <connectivity/dbtools.hxx>
43 #include <comphelper/property.hxx>
44 #include "Tools.hxx"
45 #include "FormatCondition.hxx"
46 #include <com/sun/star/text/ParagraphVertAlign.hpp>
47 #include "ReportHelperImpl.hxx"
48 // =============================================================================
49 namespace reportdesign
51 // =============================================================================
52 using namespace com::sun::star;
53 using namespace comphelper;
54 //------------------------------------------------------------------------------
55 uno::Reference< uno::XInterface > OFormattedField::create(uno::Reference< uno::XComponentContext > const & xContext)
57 return *(new OFormattedField(xContext));
60 uno::Sequence< ::rtl::OUString > lcl_getFormattedFieldOptionals()
62 ::rtl::OUString pProps[] = { PROPERTY_MASTERFIELDS,PROPERTY_DETAILFIELDS };
63 return uno::Sequence< ::rtl::OUString >(pProps,sizeof(pProps)/sizeof(pProps[0]));
65 DBG_NAME( rpt_OFormattedField )
66 // -----------------------------------------------------------------------------
67 OFormattedField::OFormattedField(uno::Reference< uno::XComponentContext > const & _xContext)
68 :FormattedFieldBase(m_aMutex)
69 ,FormattedFieldPropertySet(_xContext,static_cast< Implements >(IMPLEMENTS_PROPERTY_SET),lcl_getFormattedFieldOptionals())
70 ,m_aProps(m_aMutex,static_cast< container::XContainer*>( this ),_xContext)
71 ,m_nFormatKey(0)
73 DBG_CTOR( rpt_OFormattedField,NULL);
74 m_aProps.aComponent.m_sName = RPT_RESSTRING(RID_STR_FORMATTEDFIELD,m_aProps.aComponent.m_xContext->getServiceManager());
76 // -----------------------------------------------------------------------------
77 OFormattedField::OFormattedField(uno::Reference< uno::XComponentContext > const & _xContext
78 ,const uno::Reference< lang::XMultiServiceFactory>& _xFactory
79 ,uno::Reference< drawing::XShape >& _xShape)
80 :FormattedFieldBase(m_aMutex)
81 ,FormattedFieldPropertySet(_xContext,static_cast< Implements >(IMPLEMENTS_PROPERTY_SET),lcl_getFormattedFieldOptionals())
82 ,m_aProps(m_aMutex,static_cast< container::XContainer*>( this ),_xContext)
83 ,m_nFormatKey(0)
85 DBG_CTOR( rpt_OFormattedField,NULL);
86 m_aProps.aComponent.m_sName = RPT_RESSTRING(RID_STR_FORMATTEDFIELD,m_aProps.aComponent.m_xContext->getServiceManager());
87 m_aProps.aComponent.m_xFactory = _xFactory;
88 osl_incrementInterlockedCount( &m_refCount );
90 m_aProps.aComponent.setShape(_xShape,this,m_refCount);
92 osl_decrementInterlockedCount( &m_refCount );
94 // -----------------------------------------------------------------------------
95 OFormattedField::~OFormattedField()
97 DBG_DTOR( rpt_OFormattedField,NULL);
99 // -----------------------------------------------------------------------------
100 //IMPLEMENT_FORWARD_XINTERFACE2(OFormattedField,FormattedFieldBase,FormattedFieldPropertySet)
101 IMPLEMENT_FORWARD_REFCOUNT( OFormattedField, FormattedFieldBase )
102 // --------------------------------------------------------------------------------
103 uno::Any SAL_CALL OFormattedField::queryInterface( const uno::Type& _rType ) throw (uno::RuntimeException)
105 uno::Any aReturn = FormattedFieldBase::queryInterface(_rType);
106 if ( !aReturn.hasValue() )
107 aReturn = FormattedFieldPropertySet::queryInterface(_rType);
108 if ( !aReturn.hasValue() && OReportControlModel::isInterfaceForbidden(_rType) )
109 return aReturn;
111 return aReturn.hasValue() ? aReturn : (m_aProps.aComponent.m_xProxy.is() ? m_aProps.aComponent.m_xProxy->queryAggregation(_rType) : aReturn);
114 // -----------------------------------------------------------------------------
115 void SAL_CALL OFormattedField::dispose() throw(uno::RuntimeException)
117 FormattedFieldPropertySet::dispose();
118 cppu::WeakComponentImplHelperBase::dispose();
119 m_xFormatsSupplier.clear();
120 m_xFunction.clear();
122 // -----------------------------------------------------------------------------
123 ::rtl::OUString OFormattedField::getImplementationName_Static( ) throw(uno::RuntimeException)
125 return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.report.OFormattedField"));
128 //--------------------------------------------------------------------------
129 ::rtl::OUString SAL_CALL OFormattedField::getImplementationName( ) throw(uno::RuntimeException)
131 return getImplementationName_Static();
133 //--------------------------------------------------------------------------
134 uno::Sequence< ::rtl::OUString > OFormattedField::getSupportedServiceNames_Static( ) throw(uno::RuntimeException)
136 uno::Sequence< ::rtl::OUString > aServices(2);
137 aServices.getArray()[0] = SERVICE_FORMATTEDFIELD;
138 aServices.getArray()[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlFormattedFieldModel"));
140 return aServices;
142 //--------------------------------------------------------------------------
143 uno::Sequence< ::rtl::OUString > SAL_CALL OFormattedField::getSupportedServiceNames( ) throw(uno::RuntimeException)
145 return getSupportedServiceNames_Static();
147 //------------------------------------------------------------------------------
148 sal_Bool SAL_CALL OFormattedField::supportsService(const ::rtl::OUString& ServiceName) throw( uno::RuntimeException )
150 return ::comphelper::existsValue(ServiceName,getSupportedServiceNames_Static());
152 // -----------------------------------------------------------------------------
153 // XReportComponent
154 REPORTCOMPONENT_IMPL(OFormattedField,m_aProps.aComponent)
155 REPORTCOMPONENT_IMPL2(OFormattedField,m_aProps.aComponent)
156 REPORTCOMPONENT_NOMASTERDETAIL(OFormattedField)
157 REPORTCONTROLFORMAT_IMPL(OFormattedField,m_aProps.aFormatProperties)
159 // -----------------------------------------------------------------------------
160 uno::Reference< beans::XPropertySetInfo > SAL_CALL OFormattedField::getPropertySetInfo( ) throw(uno::RuntimeException)
162 return FormattedFieldPropertySet::getPropertySetInfo();
164 // -----------------------------------------------------------------------------
165 void SAL_CALL OFormattedField::setPropertyValue( const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
167 // special case here /// TODO check
168 if ( !aValue.hasValue() && aPropertyName == PROPERTY_FORMATKEY )
169 m_nFormatKey = 0;
170 else
171 FormattedFieldPropertySet::setPropertyValue( aPropertyName, aValue );
173 // -----------------------------------------------------------------------------
174 uno::Any SAL_CALL OFormattedField::getPropertyValue( const ::rtl::OUString& PropertyName ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
176 return FormattedFieldPropertySet::getPropertyValue( PropertyName);
178 // -----------------------------------------------------------------------------
179 void SAL_CALL OFormattedField::addPropertyChangeListener( const ::rtl::OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& xListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
181 FormattedFieldPropertySet::addPropertyChangeListener( aPropertyName, xListener );
183 // -----------------------------------------------------------------------------
184 void SAL_CALL OFormattedField::removePropertyChangeListener( const ::rtl::OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& aListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
186 FormattedFieldPropertySet::removePropertyChangeListener( aPropertyName, aListener );
188 // -----------------------------------------------------------------------------
189 void SAL_CALL OFormattedField::addVetoableChangeListener( const ::rtl::OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
191 FormattedFieldPropertySet::addVetoableChangeListener( PropertyName, aListener );
193 // -----------------------------------------------------------------------------
194 void SAL_CALL OFormattedField::removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
196 FormattedFieldPropertySet::removeVetoableChangeListener( PropertyName, aListener );
198 // -----------------------------------------------------------------------------
199 // XReportControlModel
200 ::rtl::OUString SAL_CALL OFormattedField::getDataField() throw ( beans::UnknownPropertyException, uno::RuntimeException)
202 ::osl::MutexGuard aGuard(m_aMutex);
203 return m_aProps.aDataField;
205 // -----------------------------------------------------------------------------
206 void SAL_CALL OFormattedField::setDataField( const ::rtl::OUString& _datafield ) throw (lang::IllegalArgumentException, beans::UnknownPropertyException, uno::RuntimeException)
208 set(PROPERTY_DATAFIELD,_datafield,m_aProps.aDataField);
210 // -----------------------------------------------------------------------------
211 ::sal_Bool SAL_CALL OFormattedField::getPrintWhenGroupChange() throw (beans::UnknownPropertyException, uno::RuntimeException)
213 ::osl::MutexGuard aGuard(m_aMutex);
214 return m_aProps.bPrintWhenGroupChange;
216 // -----------------------------------------------------------------------------
217 void SAL_CALL OFormattedField::setPrintWhenGroupChange( ::sal_Bool _printwhengroupchange ) throw (beans::UnknownPropertyException, uno::RuntimeException)
219 set(PROPERTY_PRINTWHENGROUPCHANGE,_printwhengroupchange,m_aProps.bPrintWhenGroupChange);
221 // -----------------------------------------------------------------------------
222 ::rtl::OUString SAL_CALL OFormattedField::getConditionalPrintExpression() throw (beans::UnknownPropertyException, uno::RuntimeException)
224 ::osl::MutexGuard aGuard(m_aMutex);
225 return m_aProps.aConditionalPrintExpression;
227 // -----------------------------------------------------------------------------
228 void SAL_CALL OFormattedField::setConditionalPrintExpression( const ::rtl::OUString& _conditionalprintexpression ) throw (beans::UnknownPropertyException, uno::RuntimeException)
230 set(PROPERTY_CONDITIONALPRINTEXPRESSION,_conditionalprintexpression,m_aProps.aConditionalPrintExpression);
233 // -----------------------------------------------------------------------------
235 // XCloneable
236 uno::Reference< util::XCloneable > SAL_CALL OFormattedField::createClone( ) throw (uno::RuntimeException)
238 uno::Reference< report::XReportComponent> xSource = this;
239 uno::Reference< report::XFormattedField> xSet(cloneObject(xSource,m_aProps.aComponent.m_xFactory,SERVICE_FORMATTEDFIELD),uno::UNO_QUERY_THROW);
241 if ( xSet.is() )
243 ::std::vector< uno::Reference< report::XFormatCondition> >::iterator aIter = m_aProps.m_aFormatConditions.begin();
244 ::std::vector< uno::Reference< report::XFormatCondition> >::iterator aEnd = m_aProps.m_aFormatConditions.end();
245 for (sal_Int32 i = 0; aIter != aEnd; ++aIter,++i)
247 uno::Reference< report::XFormatCondition > xCond = xSet->createFormatCondition();
248 ::comphelper::copyProperties(aIter->get(),xCond.get());
249 xSet->insertByIndex(i,uno::makeAny(xCond));
252 return xSet.get();
254 // -----------------------------------------------------------------------------
255 // XFormattedField
256 // -----------------------------------------------------------------------------
257 ::sal_Int32 SAL_CALL OFormattedField::getFormatKey() throw (uno::RuntimeException)
259 ::osl::MutexGuard aGuard(m_aMutex);
260 return m_nFormatKey;
263 void SAL_CALL OFormattedField::setFormatKey(::sal_Int32 _formatkey) throw (uno::RuntimeException)
265 set(PROPERTY_FORMATKEY,_formatkey,m_nFormatKey);
267 // -----------------------------------------------------------------------------
268 uno::Reference< util::XNumberFormatsSupplier > SAL_CALL OFormattedField::getFormatsSupplier() throw (uno::RuntimeException)
270 ::osl::MutexGuard aGuard(m_aMutex);
271 if ( !m_xFormatsSupplier.is() )
273 uno::Reference< report::XSection> xSection = getSection();
274 if ( xSection.is() )
275 m_xFormatsSupplier.set(xSection->getReportDefinition(),uno::UNO_QUERY);
276 if ( !m_xFormatsSupplier.is() )
278 uno::Reference< beans::XPropertySet> xProp(::dbtools::findDataSource(getParent()),uno::UNO_QUERY);
279 if ( xProp.is() )
280 m_xFormatsSupplier.set(xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NumberFormatsSupplier"))),uno::UNO_QUERY);
283 return m_xFormatsSupplier;
285 // -----------------------------------------------------------------------------
286 void SAL_CALL OFormattedField::setFormatsSupplier( const uno::Reference< util::XNumberFormatsSupplier >& _formatssupplier ) throw (uno::RuntimeException)
288 set(PROPERTY_FORMATSSUPPLIER,_formatssupplier,m_xFormatsSupplier);
290 // -----------------------------------------------------------------------------
291 // XChild
292 uno::Reference< uno::XInterface > SAL_CALL OFormattedField::getParent( ) throw (uno::RuntimeException)
294 return OShapeHelper::getParent(this);
296 // -----------------------------------------------------------------------------
297 void SAL_CALL OFormattedField::setParent( const uno::Reference< uno::XInterface >& Parent ) throw (lang::NoSupportException, uno::RuntimeException)
299 OShapeHelper::setParent(Parent,this);
301 // -----------------------------------------------------------------------------
302 uno::Reference< report::XFormatCondition > SAL_CALL OFormattedField::createFormatCondition( ) throw (uno::Exception, uno::RuntimeException)
304 return new OFormatCondition(m_aProps.aComponent.m_xContext);
306 // -----------------------------------------------------------------------------
307 // XContainer
308 void SAL_CALL OFormattedField::addContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException)
310 m_aProps.addContainerListener(xListener);
312 // -----------------------------------------------------------------------------
313 void SAL_CALL OFormattedField::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException)
315 m_aProps.removeContainerListener(xListener);
317 // -----------------------------------------------------------------------------
318 // XElementAccess
319 uno::Type SAL_CALL OFormattedField::getElementType( ) throw (uno::RuntimeException)
321 return ::getCppuType(static_cast< uno::Reference<report::XFormatCondition>*>(NULL));
323 // -----------------------------------------------------------------------------
324 ::sal_Bool SAL_CALL OFormattedField::hasElements( ) throw (uno::RuntimeException)
326 return m_aProps.hasElements();
328 // -----------------------------------------------------------------------------
329 // XIndexContainer
330 void SAL_CALL OFormattedField::insertByIndex( ::sal_Int32 Index, const uno::Any& Element ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
332 m_aProps.insertByIndex(Index,Element);
334 // -----------------------------------------------------------------------------
335 void SAL_CALL OFormattedField::removeByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
337 m_aProps.removeByIndex(Index);
339 // -----------------------------------------------------------------------------
340 // XIndexReplace
341 void SAL_CALL OFormattedField::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
343 m_aProps.replaceByIndex(Index,Element);
345 // -----------------------------------------------------------------------------
346 // XIndexAccess
347 ::sal_Int32 SAL_CALL OFormattedField::getCount( ) throw (uno::RuntimeException)
349 return m_aProps.getCount();
351 // -----------------------------------------------------------------------------
352 uno::Any SAL_CALL OFormattedField::getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
354 return m_aProps.getByIndex( Index );
356 // -----------------------------------------------------------------------------
357 // XShape
358 awt::Point SAL_CALL OFormattedField::getPosition( ) throw (uno::RuntimeException)
360 return OShapeHelper::getPosition(this);
362 // -----------------------------------------------------------------------------
363 void SAL_CALL OFormattedField::setPosition( const awt::Point& aPosition ) throw (uno::RuntimeException)
365 OShapeHelper::setPosition(aPosition,this);
367 // -----------------------------------------------------------------------------
368 awt::Size SAL_CALL OFormattedField::getSize( ) throw (uno::RuntimeException)
370 return OShapeHelper::getSize(this);
372 // -----------------------------------------------------------------------------
373 void SAL_CALL OFormattedField::setSize( const awt::Size& aSize ) throw (beans::PropertyVetoException, uno::RuntimeException)
375 OShapeHelper::setSize(aSize,this);
377 // -----------------------------------------------------------------------------
379 // XShapeDescriptor
380 ::rtl::OUString SAL_CALL OFormattedField::getShapeType( ) throw (uno::RuntimeException)
382 ::osl::MutexGuard aGuard(m_aMutex);
383 if ( m_aProps.aComponent.m_xShape.is() )
384 return m_aProps.aComponent.m_xShape->getShapeType();
385 return ::rtl::OUString();
387 // -----------------------------------------------------------------------------
388 // =============================================================================
389 } // namespace reportdesign
390 // =============================================================================