1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #include "precompiled_reportdesign.hxx"
24 #include "FormattedField.hxx"
25 #include <com/sun/star/beans/PropertyAttribute.hpp>
26 #include <com/sun/star/beans/XPropertyState.hpp>
27 #ifndef REPORTDESIGN_SHARED_CORESTRINGS_HRC
28 #include "corestrings.hrc"
29 #endif
30 #ifndef REPORTDESIGN_CORE_RESOURCE_HRC_
31 #include "core_resource.hrc"
32 #endif
33 #include "core_resource.hxx"
34 #include <comphelper/sequence.hxx>
35 #include <tools/debug.hxx>
36 #include <connectivity/dbtools.hxx>
37 #include <comphelper/property.hxx>
38 #include "Tools.hxx"
39 #include "FormatCondition.hxx"
40 #include <com/sun/star/text/ParagraphVertAlign.hpp>
41 #include "ReportHelperImpl.hxx"
42 // =============================================================================
43 namespace reportdesign
44 {
45 // =============================================================================
46 	using namespace com::sun::star;
47 	using namespace comphelper;
48 //------------------------------------------------------------------------------
create(uno::Reference<uno::XComponentContext> const & xContext)49 uno::Reference< uno::XInterface > OFormattedField::create(uno::Reference< uno::XComponentContext > const & xContext)
50 {
51 	return *(new OFormattedField(xContext));
52 }
53 
lcl_getFormattedFieldOptionals()54 uno::Sequence< ::rtl::OUString > lcl_getFormattedFieldOptionals()
55 {
56 	::rtl::OUString pProps[] = { PROPERTY_MASTERFIELDS,PROPERTY_DETAILFIELDS };
57 	return uno::Sequence< ::rtl::OUString >(pProps,sizeof(pProps)/sizeof(pProps[0]));
58 }
DBG_NAME(rpt_OFormattedField)59 DBG_NAME( rpt_OFormattedField )
60 // -----------------------------------------------------------------------------
61 OFormattedField::OFormattedField(uno::Reference< uno::XComponentContext > const & _xContext)
62 :FormattedFieldBase(m_aMutex)
63 ,FormattedFieldPropertySet(_xContext,static_cast< Implements >(IMPLEMENTS_PROPERTY_SET),lcl_getFormattedFieldOptionals())
64 ,m_aProps(m_aMutex,static_cast< container::XContainer*>( this ),_xContext)
65 ,m_nFormatKey(0)
66 {
67 	DBG_CTOR( rpt_OFormattedField,NULL);
68 	m_aProps.aComponent.m_sName  = RPT_RESSTRING(RID_STR_FORMATTEDFIELD,m_aProps.aComponent.m_xContext->getServiceManager());
69 }
70 // -----------------------------------------------------------------------------
OFormattedField(uno::Reference<uno::XComponentContext> const & _xContext,const uno::Reference<lang::XMultiServiceFactory> & _xFactory,uno::Reference<drawing::XShape> & _xShape)71 OFormattedField::OFormattedField(uno::Reference< uno::XComponentContext > const & _xContext
72                                  ,const uno::Reference< lang::XMultiServiceFactory>& _xFactory
73                                  ,uno::Reference< drawing::XShape >& _xShape)
74 :FormattedFieldBase(m_aMutex)
75 ,FormattedFieldPropertySet(_xContext,static_cast< Implements >(IMPLEMENTS_PROPERTY_SET),lcl_getFormattedFieldOptionals())
76 ,m_aProps(m_aMutex,static_cast< container::XContainer*>( this ),_xContext)
77 ,m_nFormatKey(0)
78 {
79 	DBG_CTOR( rpt_OFormattedField,NULL);
80 	m_aProps.aComponent.m_sName  = RPT_RESSTRING(RID_STR_FORMATTEDFIELD,m_aProps.aComponent.m_xContext->getServiceManager());
81     m_aProps.aComponent.m_xFactory = _xFactory;
82     osl_incrementInterlockedCount( &m_refCount );
83     {
84         m_aProps.aComponent.setShape(_xShape,this,m_refCount);
85     }
86     osl_decrementInterlockedCount( &m_refCount );
87 }
88 // -----------------------------------------------------------------------------
~OFormattedField()89 OFormattedField::~OFormattedField()
90 {
91     DBG_DTOR( rpt_OFormattedField,NULL);
92 }
93 // -----------------------------------------------------------------------------
94 //IMPLEMENT_FORWARD_XINTERFACE2(OFormattedField,FormattedFieldBase,FormattedFieldPropertySet)
IMPLEMENT_FORWARD_REFCOUNT(OFormattedField,FormattedFieldBase)95 IMPLEMENT_FORWARD_REFCOUNT( OFormattedField, FormattedFieldBase )
96 // --------------------------------------------------------------------------------
97 uno::Any SAL_CALL OFormattedField::queryInterface( const uno::Type& _rType ) throw (uno::RuntimeException)
98 {
99 	uno::Any aReturn = FormattedFieldBase::queryInterface(_rType);
100     if ( !aReturn.hasValue() )
101         aReturn = FormattedFieldPropertySet::queryInterface(_rType);
102     if ( !aReturn.hasValue() && OReportControlModel::isInterfaceForbidden(_rType) )
103         return aReturn;
104 
105 	return aReturn.hasValue() ? aReturn : (m_aProps.aComponent.m_xProxy.is() ? m_aProps.aComponent.m_xProxy->queryAggregation(_rType) : aReturn);
106 }
107 
108 // -----------------------------------------------------------------------------
dispose()109 void SAL_CALL OFormattedField::dispose() throw(uno::RuntimeException)
110 {
111 	FormattedFieldPropertySet::dispose();
112 	cppu::WeakComponentImplHelperBase::dispose();
113     m_xFormatsSupplier.clear();
114     m_xFunction.clear();
115 }
116 // -----------------------------------------------------------------------------
getImplementationName_Static()117 ::rtl::OUString OFormattedField::getImplementationName_Static(  ) throw(uno::RuntimeException)
118 {
119 	return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.report.OFormattedField"));
120 }
121 
122 //--------------------------------------------------------------------------
getImplementationName()123 ::rtl::OUString SAL_CALL OFormattedField::getImplementationName(  ) throw(uno::RuntimeException)
124 {
125 	return getImplementationName_Static();
126 }
127 //--------------------------------------------------------------------------
getSupportedServiceNames_Static()128 uno::Sequence< ::rtl::OUString > OFormattedField::getSupportedServiceNames_Static(  ) throw(uno::RuntimeException)
129 {
130 	uno::Sequence< ::rtl::OUString > aServices(2);
131 	aServices.getArray()[0] = SERVICE_FORMATTEDFIELD;
132     aServices.getArray()[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlFormattedFieldModel"));
133 
134 	return aServices;
135 }
136 //--------------------------------------------------------------------------
getSupportedServiceNames()137 uno::Sequence< ::rtl::OUString > SAL_CALL OFormattedField::getSupportedServiceNames(  ) throw(uno::RuntimeException)
138 {
139 	return getSupportedServiceNames_Static();
140 }
141 //------------------------------------------------------------------------------
supportsService(const::rtl::OUString & ServiceName)142 sal_Bool SAL_CALL OFormattedField::supportsService(const ::rtl::OUString& ServiceName) throw( uno::RuntimeException )
143 {
144 	return ::comphelper::existsValue(ServiceName,getSupportedServiceNames_Static());
145 }
146 // -----------------------------------------------------------------------------
147 // XReportComponent
148 REPORTCOMPONENT_IMPL(OFormattedField,m_aProps.aComponent)
149 REPORTCOMPONENT_IMPL2(OFormattedField,m_aProps.aComponent)
REPORTCOMPONENT_NOMASTERDETAIL(OFormattedField)150 REPORTCOMPONENT_NOMASTERDETAIL(OFormattedField)
151 REPORTCONTROLFORMAT_IMPL(OFormattedField,m_aProps.aFormatProperties)
152 
153 // -----------------------------------------------------------------------------
154 uno::Reference< beans::XPropertySetInfo > SAL_CALL OFormattedField::getPropertySetInfo(  ) throw(uno::RuntimeException)
155 {
156 	return FormattedFieldPropertySet::getPropertySetInfo();
157 }
158 // -----------------------------------------------------------------------------
setPropertyValue(const::rtl::OUString & aPropertyName,const uno::Any & aValue)159 void SAL_CALL OFormattedField::setPropertyValue( const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
160 {
161     // special case here /// TODO check
162     if ( !aValue.hasValue() && aPropertyName == PROPERTY_FORMATKEY )
163         m_nFormatKey = 0;
164     else
165 	    FormattedFieldPropertySet::setPropertyValue( aPropertyName, aValue );
166 }
167 // -----------------------------------------------------------------------------
getPropertyValue(const::rtl::OUString & PropertyName)168 uno::Any SAL_CALL OFormattedField::getPropertyValue( const ::rtl::OUString& PropertyName ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
169 {
170 	return FormattedFieldPropertySet::getPropertyValue( PropertyName);
171 }
172 // -----------------------------------------------------------------------------
addPropertyChangeListener(const::rtl::OUString & aPropertyName,const uno::Reference<beans::XPropertyChangeListener> & xListener)173 void SAL_CALL OFormattedField::addPropertyChangeListener( const ::rtl::OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& xListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
174 {
175 	FormattedFieldPropertySet::addPropertyChangeListener( aPropertyName, xListener );
176 }
177 // -----------------------------------------------------------------------------
removePropertyChangeListener(const::rtl::OUString & aPropertyName,const uno::Reference<beans::XPropertyChangeListener> & aListener)178 void SAL_CALL OFormattedField::removePropertyChangeListener( const ::rtl::OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& aListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
179 {
180 	FormattedFieldPropertySet::removePropertyChangeListener( aPropertyName, aListener );
181 }
182 // -----------------------------------------------------------------------------
addVetoableChangeListener(const::rtl::OUString & PropertyName,const uno::Reference<beans::XVetoableChangeListener> & aListener)183 void SAL_CALL OFormattedField::addVetoableChangeListener( const ::rtl::OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
184 {
185 	FormattedFieldPropertySet::addVetoableChangeListener( PropertyName, aListener );
186 }
187 // -----------------------------------------------------------------------------
removeVetoableChangeListener(const::rtl::OUString & PropertyName,const uno::Reference<beans::XVetoableChangeListener> & aListener)188 void SAL_CALL OFormattedField::removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
189 {
190 	FormattedFieldPropertySet::removeVetoableChangeListener( PropertyName, aListener );
191 }
192 // -----------------------------------------------------------------------------
193 // XReportControlModel
getDataField()194 ::rtl::OUString SAL_CALL OFormattedField::getDataField() throw ( beans::UnknownPropertyException, uno::RuntimeException)
195 {
196 	::osl::MutexGuard aGuard(m_aMutex);
197 	return m_aProps.aDataField;
198 }
199 // -----------------------------------------------------------------------------
setDataField(const::rtl::OUString & _datafield)200 void SAL_CALL OFormattedField::setDataField( const ::rtl::OUString& _datafield ) throw (lang::IllegalArgumentException, beans::UnknownPropertyException, uno::RuntimeException)
201 {
202 	set(PROPERTY_DATAFIELD,_datafield,m_aProps.aDataField);
203 }
204 // -----------------------------------------------------------------------------
getPrintWhenGroupChange()205 ::sal_Bool SAL_CALL OFormattedField::getPrintWhenGroupChange() throw (beans::UnknownPropertyException, uno::RuntimeException)
206 {
207 	::osl::MutexGuard aGuard(m_aMutex);
208 	return m_aProps.bPrintWhenGroupChange;
209 }
210 // -----------------------------------------------------------------------------
setPrintWhenGroupChange(::sal_Bool _printwhengroupchange)211 void SAL_CALL OFormattedField::setPrintWhenGroupChange( ::sal_Bool _printwhengroupchange ) throw (beans::UnknownPropertyException, uno::RuntimeException)
212 {
213 	set(PROPERTY_PRINTWHENGROUPCHANGE,_printwhengroupchange,m_aProps.bPrintWhenGroupChange);
214 }
215 // -----------------------------------------------------------------------------
getConditionalPrintExpression()216 ::rtl::OUString SAL_CALL OFormattedField::getConditionalPrintExpression() throw (beans::UnknownPropertyException, uno::RuntimeException)
217 {
218 	::osl::MutexGuard aGuard(m_aMutex);
219 	return m_aProps.aConditionalPrintExpression;
220 }
221 // -----------------------------------------------------------------------------
setConditionalPrintExpression(const::rtl::OUString & _conditionalprintexpression)222 void SAL_CALL OFormattedField::setConditionalPrintExpression( const ::rtl::OUString& _conditionalprintexpression ) throw (beans::UnknownPropertyException, uno::RuntimeException)
223 {
224 	set(PROPERTY_CONDITIONALPRINTEXPRESSION,_conditionalprintexpression,m_aProps.aConditionalPrintExpression);
225 }
226 
227 // -----------------------------------------------------------------------------
228 
229 // XCloneable
createClone()230 uno::Reference< util::XCloneable > SAL_CALL OFormattedField::createClone(  ) throw (uno::RuntimeException)
231 {
232     uno::Reference< report::XReportComponent> xSource = this;
233     uno::Reference< report::XFormattedField> xSet(cloneObject(xSource,m_aProps.aComponent.m_xFactory,SERVICE_FORMATTEDFIELD),uno::UNO_QUERY_THROW);
234 
235     if ( xSet.is() )
236     {
237 	    ::std::vector< uno::Reference< report::XFormatCondition> >::iterator aIter = m_aProps.m_aFormatConditions.begin();
238 	    ::std::vector< uno::Reference< report::XFormatCondition> >::iterator aEnd  = m_aProps.m_aFormatConditions.end();
239 	    for (sal_Int32 i = 0; aIter != aEnd; ++aIter,++i)
240 	    {
241 		    uno::Reference< report::XFormatCondition > xCond = xSet->createFormatCondition();
242 		    ::comphelper::copyProperties(aIter->get(),xCond.get());
243 		    xSet->insertByIndex(i,uno::makeAny(xCond));
244 	    }
245     }
246 	return xSet.get();
247 }
248 // -----------------------------------------------------------------------------
249 // XFormattedField
250 // -----------------------------------------------------------------------------
getFormatKey()251 ::sal_Int32 SAL_CALL OFormattedField::getFormatKey() throw (uno::RuntimeException)
252 {
253     ::osl::MutexGuard aGuard(m_aMutex);
254     return m_nFormatKey;
255 }
256 
setFormatKey(::sal_Int32 _formatkey)257 void SAL_CALL OFormattedField::setFormatKey(::sal_Int32 _formatkey) throw (uno::RuntimeException)
258 {
259     set(PROPERTY_FORMATKEY,_formatkey,m_nFormatKey);
260 }
261 // -----------------------------------------------------------------------------
getFormatsSupplier()262 uno::Reference< util::XNumberFormatsSupplier > SAL_CALL OFormattedField::getFormatsSupplier() throw (uno::RuntimeException)
263 {
264 	::osl::MutexGuard aGuard(m_aMutex);
265 	if ( !m_xFormatsSupplier.is() )
266 	{
267         uno::Reference< report::XSection> xSection = getSection();
268         if ( xSection.is() )
269             m_xFormatsSupplier.set(xSection->getReportDefinition(),uno::UNO_QUERY);
270         if ( !m_xFormatsSupplier.is() )
271 	    {
272 		    uno::Reference< beans::XPropertySet> xProp(::dbtools::findDataSource(getParent()),uno::UNO_QUERY);
273 		    if ( xProp.is() )
274 			    m_xFormatsSupplier.set(xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NumberFormatsSupplier"))),uno::UNO_QUERY);
275         }
276 	}
277 	return m_xFormatsSupplier;
278 }
279 // -----------------------------------------------------------------------------
setFormatsSupplier(const uno::Reference<util::XNumberFormatsSupplier> & _formatssupplier)280 void SAL_CALL OFormattedField::setFormatsSupplier( const uno::Reference< util::XNumberFormatsSupplier >& _formatssupplier ) throw (uno::RuntimeException)
281 {
282 	set(PROPERTY_FORMATSSUPPLIER,_formatssupplier,m_xFormatsSupplier);
283 }
284 // -----------------------------------------------------------------------------
285 // XChild
getParent()286 uno::Reference< uno::XInterface > SAL_CALL OFormattedField::getParent(  ) throw (uno::RuntimeException)
287 {
288 	return OShapeHelper::getParent(this);
289 }
290 // -----------------------------------------------------------------------------
setParent(const uno::Reference<uno::XInterface> & Parent)291 void SAL_CALL OFormattedField::setParent( const uno::Reference< uno::XInterface >& Parent ) throw (lang::NoSupportException, uno::RuntimeException)
292 {
293     OShapeHelper::setParent(Parent,this);
294 }
295 // -----------------------------------------------------------------------------
createFormatCondition()296 uno::Reference< report::XFormatCondition > SAL_CALL OFormattedField::createFormatCondition(  ) throw (uno::Exception, uno::RuntimeException)
297 {
298 	return new OFormatCondition(m_aProps.aComponent.m_xContext);
299 }
300 // -----------------------------------------------------------------------------
301 // XContainer
addContainerListener(const uno::Reference<container::XContainerListener> & xListener)302 void SAL_CALL OFormattedField::addContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException)
303 {
304 	m_aProps.addContainerListener(xListener);
305 }
306 // -----------------------------------------------------------------------------
removeContainerListener(const uno::Reference<container::XContainerListener> & xListener)307 void SAL_CALL OFormattedField::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException)
308 {
309 	m_aProps.removeContainerListener(xListener);
310 }
311 // -----------------------------------------------------------------------------
312 // XElementAccess
getElementType()313 uno::Type SAL_CALL OFormattedField::getElementType(  ) throw (uno::RuntimeException)
314 {
315 	return ::getCppuType(static_cast< uno::Reference<report::XFormatCondition>*>(NULL));
316 }
317 // -----------------------------------------------------------------------------
hasElements()318 ::sal_Bool SAL_CALL OFormattedField::hasElements(  ) throw (uno::RuntimeException)
319 {
320 	return m_aProps.hasElements();
321 }
322 // -----------------------------------------------------------------------------
323 // XIndexContainer
insertByIndex(::sal_Int32 Index,const uno::Any & Element)324 void SAL_CALL OFormattedField::insertByIndex( ::sal_Int32 Index, const uno::Any& Element ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
325 {
326     m_aProps.insertByIndex(Index,Element);
327 }
328 // -----------------------------------------------------------------------------
removeByIndex(::sal_Int32 Index)329 void SAL_CALL OFormattedField::removeByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
330 {
331     m_aProps.removeByIndex(Index);
332 }
333 // -----------------------------------------------------------------------------
334 // XIndexReplace
replaceByIndex(::sal_Int32 Index,const uno::Any & Element)335 void SAL_CALL OFormattedField::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
336 {
337     m_aProps.replaceByIndex(Index,Element);
338 }
339 // -----------------------------------------------------------------------------
340 // XIndexAccess
getCount()341 ::sal_Int32 SAL_CALL OFormattedField::getCount(  ) throw (uno::RuntimeException)
342 {
343 	return m_aProps.getCount();
344 }
345 // -----------------------------------------------------------------------------
getByIndex(::sal_Int32 Index)346 uno::Any SAL_CALL OFormattedField::getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
347 {
348     return m_aProps.getByIndex( Index );
349 }
350 // -----------------------------------------------------------------------------
351 // XShape
getPosition()352 awt::Point SAL_CALL OFormattedField::getPosition(  ) throw (uno::RuntimeException)
353 {
354 	return OShapeHelper::getPosition(this);
355 }
356 // -----------------------------------------------------------------------------
setPosition(const awt::Point & aPosition)357 void SAL_CALL OFormattedField::setPosition( const awt::Point& aPosition ) throw (uno::RuntimeException)
358 {
359     OShapeHelper::setPosition(aPosition,this);
360 }
361 // -----------------------------------------------------------------------------
getSize()362 awt::Size SAL_CALL OFormattedField::getSize(  ) throw (uno::RuntimeException)
363 {
364 	return OShapeHelper::getSize(this);
365 }
366 // -----------------------------------------------------------------------------
setSize(const awt::Size & aSize)367 void SAL_CALL OFormattedField::setSize( const awt::Size& aSize ) throw (beans::PropertyVetoException, uno::RuntimeException)
368 {
369     OShapeHelper::setSize(aSize,this);
370 }
371 // -----------------------------------------------------------------------------
372 
373 // XShapeDescriptor
getShapeType()374 ::rtl::OUString SAL_CALL OFormattedField::getShapeType(  ) throw (uno::RuntimeException)
375 {
376 	return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.ControlShape"));
377 }
378 // -----------------------------------------------------------------------------
379 // =============================================================================
380 } // namespace reportdesign
381 // =============================================================================
382