1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <tools/color.hxx>
26 #include <tools/debug.hxx>
27 #include <connectivity/dbtools.hxx>
28 #include <comphelper/property.hxx>
29 #include <cppuhelper/supportsservice.hxx>
31 #include "FormatCondition.hxx"
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
;
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]));
52 OFormattedField::OFormattedField(uno::Reference
< uno::XComponentContext
> const & _xContext
)
53 :FormattedFieldBase(m_aMutex
)
54 ,FormattedFieldPropertySet(_xContext
,static_cast< Implements
>(IMPLEMENTS_PROPERTY_SET
),lcl_getFormattedFieldOptionals())
55 ,m_aProps(m_aMutex
,static_cast< container::XContainer
*>( this ),_xContext
)
58 m_aProps
.aComponent
.m_sName
= RPT_RESSTRING(RID_STR_FORMATTEDFIELD
,m_aProps
.aComponent
.m_xContext
->getServiceManager());
61 OFormattedField::OFormattedField(uno::Reference
< uno::XComponentContext
> const & _xContext
62 ,const uno::Reference
< lang::XMultiServiceFactory
>& _xFactory
63 ,uno::Reference
< drawing::XShape
>& _xShape
)
64 :FormattedFieldBase(m_aMutex
)
65 ,FormattedFieldPropertySet(_xContext
,static_cast< Implements
>(IMPLEMENTS_PROPERTY_SET
),lcl_getFormattedFieldOptionals())
66 ,m_aProps(m_aMutex
,static_cast< container::XContainer
*>( this ),_xContext
)
69 m_aProps
.aComponent
.m_sName
= RPT_RESSTRING(RID_STR_FORMATTEDFIELD
,m_aProps
.aComponent
.m_xContext
->getServiceManager());
70 m_aProps
.aComponent
.m_xFactory
= _xFactory
;
71 osl_atomic_increment( &m_refCount
);
73 m_aProps
.aComponent
.setShape(_xShape
,this,m_refCount
);
75 osl_atomic_decrement( &m_refCount
);
78 OFormattedField::~OFormattedField()
82 IMPLEMENT_FORWARD_REFCOUNT( OFormattedField
, FormattedFieldBase
)
84 uno::Any SAL_CALL
OFormattedField::queryInterface( const uno::Type
& _rType
) throw (uno::RuntimeException
, std::exception
)
86 uno::Any aReturn
= FormattedFieldBase::queryInterface(_rType
);
87 if ( !aReturn
.hasValue() )
88 aReturn
= FormattedFieldPropertySet::queryInterface(_rType
);
89 if ( !aReturn
.hasValue() && OReportControlModel::isInterfaceForbidden(_rType
) )
92 return aReturn
.hasValue() ? aReturn
: (m_aProps
.aComponent
.m_xProxy
.is() ? m_aProps
.aComponent
.m_xProxy
->queryAggregation(_rType
) : aReturn
);
96 void SAL_CALL
OFormattedField::dispose() throw(uno::RuntimeException
, std::exception
)
98 FormattedFieldPropertySet::dispose();
99 cppu::WeakComponentImplHelperBase::dispose();
100 m_xFormatsSupplier
.clear();
104 OUString
OFormattedField::getImplementationName_Static( ) throw(uno::RuntimeException
, std::exception
)
106 return OUString("com.sun.star.comp.report.OFormattedField");
110 OUString SAL_CALL
OFormattedField::getImplementationName( ) throw(uno::RuntimeException
, std::exception
)
112 return getImplementationName_Static();
115 uno::Sequence
< OUString
> OFormattedField::getSupportedServiceNames_Static( ) throw(uno::RuntimeException
, std::exception
)
117 uno::Sequence
< OUString
> aServices(2);
118 aServices
[0] = SERVICE_FORMATTEDFIELD
;
119 aServices
[1] = "com.sun.star.awt.UnoControlFormattedFieldModel";
124 uno::Sequence
< OUString
> SAL_CALL
OFormattedField::getSupportedServiceNames( ) throw(uno::RuntimeException
, std::exception
)
126 return getSupportedServiceNames_Static();
129 sal_Bool SAL_CALL
OFormattedField::supportsService(const OUString
& ServiceName
) throw( uno::RuntimeException
, std::exception
)
131 return cppu::supportsService(this, ServiceName
);
135 REPORTCOMPONENT_IMPL(OFormattedField
,m_aProps
.aComponent
)
136 REPORTCOMPONENT_IMPL2(OFormattedField
,m_aProps
.aComponent
)
137 REPORTCOMPONENT_NOMASTERDETAIL(OFormattedField
)
138 REPORTCONTROLFORMAT_IMPL(OFormattedField
,m_aProps
.aFormatProperties
)
141 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
OFormattedField::getPropertySetInfo( ) throw(uno::RuntimeException
, std::exception
)
143 return FormattedFieldPropertySet::getPropertySetInfo();
146 void SAL_CALL
OFormattedField::setPropertyValue( const OUString
& aPropertyName
, const uno::Any
& aValue
) throw (beans::UnknownPropertyException
, beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
148 // special case here /// TODO check
149 if ( !aValue
.hasValue() && aPropertyName
== PROPERTY_FORMATKEY
)
152 FormattedFieldPropertySet::setPropertyValue( aPropertyName
, aValue
);
155 uno::Any SAL_CALL
OFormattedField::getPropertyValue( const OUString
& PropertyName
) throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
157 return FormattedFieldPropertySet::getPropertyValue( PropertyName
);
160 void SAL_CALL
OFormattedField::addPropertyChangeListener( const OUString
& aPropertyName
, const uno::Reference
< beans::XPropertyChangeListener
>& xListener
) throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
162 FormattedFieldPropertySet::addPropertyChangeListener( aPropertyName
, xListener
);
165 void SAL_CALL
OFormattedField::removePropertyChangeListener( const OUString
& aPropertyName
, const uno::Reference
< beans::XPropertyChangeListener
>& aListener
) throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
167 FormattedFieldPropertySet::removePropertyChangeListener( aPropertyName
, aListener
);
170 void SAL_CALL
OFormattedField::addVetoableChangeListener( const OUString
& PropertyName
, const uno::Reference
< beans::XVetoableChangeListener
>& aListener
) throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
172 FormattedFieldPropertySet::addVetoableChangeListener( PropertyName
, aListener
);
175 void SAL_CALL
OFormattedField::removeVetoableChangeListener( const OUString
& PropertyName
, const uno::Reference
< beans::XVetoableChangeListener
>& aListener
) throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
177 FormattedFieldPropertySet::removeVetoableChangeListener( PropertyName
, aListener
);
180 // XReportControlModel
181 OUString SAL_CALL
OFormattedField::getDataField() throw ( beans::UnknownPropertyException
, uno::RuntimeException
, std::exception
)
183 ::osl::MutexGuard
aGuard(m_aMutex
);
184 return m_aProps
.aDataField
;
187 void SAL_CALL
OFormattedField::setDataField( const OUString
& _datafield
) throw (lang::IllegalArgumentException
, beans::UnknownPropertyException
, uno::RuntimeException
, std::exception
)
189 set(PROPERTY_DATAFIELD
,_datafield
,m_aProps
.aDataField
);
192 sal_Bool SAL_CALL
OFormattedField::getPrintWhenGroupChange() throw (beans::UnknownPropertyException
, uno::RuntimeException
, std::exception
)
194 ::osl::MutexGuard
aGuard(m_aMutex
);
195 return m_aProps
.bPrintWhenGroupChange
;
198 void SAL_CALL
OFormattedField::setPrintWhenGroupChange( sal_Bool _printwhengroupchange
) throw (beans::UnknownPropertyException
, uno::RuntimeException
, std::exception
)
200 set(PROPERTY_PRINTWHENGROUPCHANGE
,_printwhengroupchange
,m_aProps
.bPrintWhenGroupChange
);
203 OUString SAL_CALL
OFormattedField::getConditionalPrintExpression() throw (beans::UnknownPropertyException
, uno::RuntimeException
, std::exception
)
205 ::osl::MutexGuard
aGuard(m_aMutex
);
206 return m_aProps
.aConditionalPrintExpression
;
209 void SAL_CALL
OFormattedField::setConditionalPrintExpression( const OUString
& _conditionalprintexpression
) throw (beans::UnknownPropertyException
, uno::RuntimeException
, std::exception
)
211 set(PROPERTY_CONDITIONALPRINTEXPRESSION
,_conditionalprintexpression
,m_aProps
.aConditionalPrintExpression
);
217 uno::Reference
< util::XCloneable
> SAL_CALL
OFormattedField::createClone( ) throw (uno::RuntimeException
, std::exception
)
219 uno::Reference
< report::XReportComponent
> xSource
= this;
220 uno::Reference
< report::XFormattedField
> xSet(cloneObject(xSource
,m_aProps
.aComponent
.m_xFactory
,SERVICE_FORMATTEDFIELD
),uno::UNO_QUERY_THROW
);
224 ::std::vector
< uno::Reference
< report::XFormatCondition
> >::iterator aIter
= m_aProps
.m_aFormatConditions
.begin();
225 ::std::vector
< uno::Reference
< report::XFormatCondition
> >::iterator aEnd
= m_aProps
.m_aFormatConditions
.end();
226 for (sal_Int32 i
= 0; aIter
!= aEnd
; ++aIter
,++i
)
228 uno::Reference
< report::XFormatCondition
> xCond
= xSet
->createFormatCondition();
229 ::comphelper::copyProperties(aIter
->get(),xCond
.get());
230 xSet
->insertByIndex(i
,uno::makeAny(xCond
));
238 ::sal_Int32 SAL_CALL
OFormattedField::getFormatKey() throw (uno::RuntimeException
, std::exception
)
240 ::osl::MutexGuard
aGuard(m_aMutex
);
244 void SAL_CALL
OFormattedField::setFormatKey(::sal_Int32 _formatkey
) throw (uno::RuntimeException
, std::exception
)
246 set(PROPERTY_FORMATKEY
,_formatkey
,m_nFormatKey
);
249 uno::Reference
< util::XNumberFormatsSupplier
> SAL_CALL
OFormattedField::getFormatsSupplier() throw (uno::RuntimeException
, std::exception
)
251 ::osl::MutexGuard
aGuard(m_aMutex
);
252 if ( !m_xFormatsSupplier
.is() )
254 uno::Reference
< report::XSection
> xSection
= getSection();
256 m_xFormatsSupplier
.set(xSection
->getReportDefinition(),uno::UNO_QUERY
);
257 if ( !m_xFormatsSupplier
.is() )
259 uno::Reference
< beans::XPropertySet
> xProp(::dbtools::findDataSource(getParent()),uno::UNO_QUERY
);
261 m_xFormatsSupplier
.set(xProp
->getPropertyValue("NumberFormatsSupplier"),uno::UNO_QUERY
);
264 return m_xFormatsSupplier
;
267 void SAL_CALL
OFormattedField::setFormatsSupplier( const uno::Reference
< util::XNumberFormatsSupplier
>& _formatssupplier
) throw (uno::RuntimeException
, std::exception
)
269 set(PROPERTY_FORMATSSUPPLIER
,_formatssupplier
,m_xFormatsSupplier
);
273 uno::Reference
< uno::XInterface
> SAL_CALL
OFormattedField::getParent( ) throw (uno::RuntimeException
, std::exception
)
275 return OShapeHelper::getParent(this);
278 void SAL_CALL
OFormattedField::setParent( const uno::Reference
< uno::XInterface
>& Parent
) throw (lang::NoSupportException
, uno::RuntimeException
, std::exception
)
280 OShapeHelper::setParent(Parent
,this);
283 uno::Reference
< report::XFormatCondition
> SAL_CALL
OFormattedField::createFormatCondition( ) throw (uno::Exception
, uno::RuntimeException
, std::exception
)
285 return new OFormatCondition(m_aProps
.aComponent
.m_xContext
);
289 void SAL_CALL
OFormattedField::addContainerListener( const uno::Reference
< container::XContainerListener
>& xListener
) throw (uno::RuntimeException
, std::exception
)
291 m_aProps
.addContainerListener(xListener
);
294 void SAL_CALL
OFormattedField::removeContainerListener( const uno::Reference
< container::XContainerListener
>& xListener
) throw (uno::RuntimeException
, std::exception
)
296 m_aProps
.removeContainerListener(xListener
);
300 uno::Type SAL_CALL
OFormattedField::getElementType( ) throw (uno::RuntimeException
, std::exception
)
302 return cppu::UnoType
<report::XFormatCondition
>::get();
305 sal_Bool SAL_CALL
OFormattedField::hasElements( ) throw (uno::RuntimeException
, std::exception
)
307 return m_aProps
.hasElements();
311 void SAL_CALL
OFormattedField::insertByIndex( ::sal_Int32 Index
, const uno::Any
& Element
) throw (lang::IllegalArgumentException
, lang::IndexOutOfBoundsException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
313 m_aProps
.insertByIndex(Index
,Element
);
316 void SAL_CALL
OFormattedField::removeByIndex( ::sal_Int32 Index
) throw (lang::IndexOutOfBoundsException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
318 m_aProps
.removeByIndex(Index
);
322 void SAL_CALL
OFormattedField::replaceByIndex( ::sal_Int32 Index
, const uno::Any
& Element
) throw (lang::IllegalArgumentException
, lang::IndexOutOfBoundsException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
324 m_aProps
.replaceByIndex(Index
,Element
);
328 ::sal_Int32 SAL_CALL
OFormattedField::getCount( ) throw (uno::RuntimeException
, std::exception
)
330 return m_aProps
.getCount();
333 uno::Any SAL_CALL
OFormattedField::getByIndex( ::sal_Int32 Index
) throw (lang::IndexOutOfBoundsException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
335 return m_aProps
.getByIndex( Index
);
339 awt::Point SAL_CALL
OFormattedField::getPosition( ) throw (uno::RuntimeException
, std::exception
)
341 return OShapeHelper::getPosition(this);
344 void SAL_CALL
OFormattedField::setPosition( const awt::Point
& aPosition
) throw (uno::RuntimeException
, std::exception
)
346 OShapeHelper::setPosition(aPosition
,this);
349 awt::Size SAL_CALL
OFormattedField::getSize( ) throw (uno::RuntimeException
, std::exception
)
351 return OShapeHelper::getSize(this);
354 void SAL_CALL
OFormattedField::setSize( const awt::Size
& aSize
) throw (beans::PropertyVetoException
, uno::RuntimeException
, std::exception
)
356 OShapeHelper::setSize(aSize
,this);
361 OUString SAL_CALL
OFormattedField::getShapeType( ) throw (uno::RuntimeException
, std::exception
)
363 ::osl::MutexGuard
aGuard(m_aMutex
);
364 if ( m_aProps
.aComponent
.m_xShape
.is() )
365 return m_aProps
.aComponent
.m_xShape
->getShapeType();
366 return OUString("com.sun.star.drawing.ControlShape");
370 } // namespace reportdesign
373 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */