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