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