LibreOffice Module reportdesign (master)  1
FormattedField.cxx
Go to the documentation of this file.
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/sdbc/XDataSource.hpp>
21 #include <strings.hxx>
22 #include <strings.hrc>
23 #include <core_resource.hxx>
24 #include <tools/color.hxx>
25 #include <connectivity/dbtools.hxx>
26 #include <comphelper/property.hxx>
28 #include <Tools.hxx>
29 #include <FormatCondition.hxx>
30 #include <ReportHelperImpl.hxx>
31 
32 namespace reportdesign
33 {
34 
35  using namespace com::sun::star;
36  using namespace comphelper;
37 
38 static uno::Sequence< OUString > lcl_getFormattedFieldOptionals()
39 {
40  OUString pProps[] = { OUString(PROPERTY_MASTERFIELDS),OUString(PROPERTY_DETAILFIELDS) };
41  return uno::Sequence< OUString >(pProps,SAL_N_ELEMENTS(pProps));
42 }
43 
44 OFormattedField::OFormattedField(uno::Reference< uno::XComponentContext > const & _xContext)
46 ,FormattedFieldPropertySet(_xContext,IMPLEMENTS_PROPERTY_SET,lcl_getFormattedFieldOptionals())
47 ,m_aProps(m_aMutex,static_cast< container::XContainer*>( this ),_xContext)
48 ,m_nFormatKey(0)
49 {
50  m_aProps.aComponent.m_sName = RptResId(RID_STR_FORMATTEDFIELD);
51 }
52 
53 OFormattedField::OFormattedField(uno::Reference< uno::XComponentContext > const & _xContext
54  ,const uno::Reference< lang::XMultiServiceFactory>& _xFactory
55  ,uno::Reference< drawing::XShape >& _xShape)
57 ,FormattedFieldPropertySet(_xContext,IMPLEMENTS_PROPERTY_SET,lcl_getFormattedFieldOptionals())
58 ,m_aProps(m_aMutex,static_cast< container::XContainer*>( this ),_xContext)
59 ,m_nFormatKey(0)
60 {
61  m_aProps.aComponent.m_sName = RptResId(RID_STR_FORMATTEDFIELD);
62  m_aProps.aComponent.m_xFactory = _xFactory;
63  osl_atomic_increment( &m_refCount );
64  {
65  m_aProps.aComponent.setShape(_xShape,this,m_refCount);
66  }
67  osl_atomic_decrement( &m_refCount );
68 }
69 
70 OFormattedField::~OFormattedField()
71 {
72 }
73 
75 
76 uno::Any SAL_CALL OFormattedField::queryInterface( const uno::Type& _rType )
77 {
78  uno::Any aReturn = FormattedFieldBase::queryInterface(_rType);
79  if ( !aReturn.hasValue() )
80  aReturn = FormattedFieldPropertySet::queryInterface(_rType);
81  if ( !aReturn.hasValue() && OReportControlModel::isInterfaceForbidden(_rType) )
82  return aReturn;
83 
84  return aReturn.hasValue() ? aReturn : (m_aProps.aComponent.m_xProxy.is() ? m_aProps.aComponent.m_xProxy->queryAggregation(_rType) : aReturn);
85 }
86 
87 
88 void SAL_CALL OFormattedField::dispose()
89 {
90  FormattedFieldPropertySet::dispose();
91  cppu::WeakComponentImplHelperBase::dispose();
92  m_xFormatsSupplier.clear();
93 }
94 
95 OUString SAL_CALL OFormattedField::getImplementationName( )
96 {
97  return "com.sun.star.comp.report.OFormattedField";
98 }
99 
100 uno::Sequence< OUString > SAL_CALL OFormattedField::getSupportedServiceNames( )
101 {
102  return { SERVICE_FORMATTEDFIELD, "com.sun.star.awt.UnoControlFormattedFieldModel" };
103 }
104 
105 sal_Bool SAL_CALL OFormattedField::supportsService(const OUString& ServiceName)
106 {
107  return cppu::supportsService(this, ServiceName);
108 }
109 
110 // XReportComponent
111 REPORTCOMPONENT_IMPL(OFormattedField,m_aProps.aComponent)
112 REPORTCOMPONENT_IMPL2(OFormattedField,m_aProps.aComponent)
113 REPORTCOMPONENT_NOMASTERDETAIL(OFormattedField)
114 REPORTCONTROLFORMAT_IMPL(OFormattedField,m_aProps.aFormatProperties)
115 
116 
117 uno::Reference< beans::XPropertySetInfo > SAL_CALL OFormattedField::getPropertySetInfo( )
118 {
119  return FormattedFieldPropertySet::getPropertySetInfo();
120 }
121 
122 void SAL_CALL OFormattedField::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
123 {
124  // special case here /// TODO check
125  if ( !aValue.hasValue() && aPropertyName == PROPERTY_FORMATKEY )
126  m_nFormatKey = 0;
127  else
128  FormattedFieldPropertySet::setPropertyValue( aPropertyName, aValue );
129 }
130 
131 uno::Any SAL_CALL OFormattedField::getPropertyValue( const OUString& PropertyName )
132 {
133  return FormattedFieldPropertySet::getPropertyValue( PropertyName);
134 }
135 
136 void SAL_CALL OFormattedField::addPropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& xListener )
137 {
138  FormattedFieldPropertySet::addPropertyChangeListener( aPropertyName, xListener );
139 }
140 
141 void SAL_CALL OFormattedField::removePropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& aListener )
142 {
143  FormattedFieldPropertySet::removePropertyChangeListener( aPropertyName, aListener );
144 }
145 
146 void SAL_CALL OFormattedField::addVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener )
147 {
148  FormattedFieldPropertySet::addVetoableChangeListener( PropertyName, aListener );
149 }
150 
151 void SAL_CALL OFormattedField::removeVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener )
152 {
153  FormattedFieldPropertySet::removeVetoableChangeListener( PropertyName, aListener );
154 }
155 
156 // XReportControlModel
157 OUString SAL_CALL OFormattedField::getDataField()
158 {
159  ::osl::MutexGuard aGuard(m_aMutex);
160  return m_aProps.aDataField;
161 }
162 
163 void SAL_CALL OFormattedField::setDataField( const OUString& _datafield )
164 {
165  set(PROPERTY_DATAFIELD,_datafield,m_aProps.aDataField);
166 }
167 
168 sal_Bool SAL_CALL OFormattedField::getPrintWhenGroupChange()
169 {
170  ::osl::MutexGuard aGuard(m_aMutex);
171  return m_aProps.bPrintWhenGroupChange;
172 }
173 
174 void SAL_CALL OFormattedField::setPrintWhenGroupChange( sal_Bool _printwhengroupchange )
175 {
176  set(PROPERTY_PRINTWHENGROUPCHANGE,_printwhengroupchange,m_aProps.bPrintWhenGroupChange);
177 }
178 
179 OUString SAL_CALL OFormattedField::getConditionalPrintExpression()
180 {
181  ::osl::MutexGuard aGuard(m_aMutex);
182  return m_aProps.aConditionalPrintExpression;
183 }
184 
185 void SAL_CALL OFormattedField::setConditionalPrintExpression( const OUString& _conditionalprintexpression )
186 {
187  set(PROPERTY_CONDITIONALPRINTEXPRESSION,_conditionalprintexpression,m_aProps.aConditionalPrintExpression);
188 }
189 
190 
191 // XCloneable
192 uno::Reference< util::XCloneable > SAL_CALL OFormattedField::createClone( )
193 {
194  uno::Reference< report::XReportComponent> xSource = this;
195  uno::Reference< report::XFormattedField> xSet(cloneObject(xSource,m_aProps.aComponent.m_xFactory,SERVICE_FORMATTEDFIELD),uno::UNO_QUERY_THROW);
196 
197  sal_Int32 i = 0;
198  for (const auto& rxFormatCondition : m_aProps.m_aFormatConditions)
199  {
200  uno::Reference< report::XFormatCondition > xCond = xSet->createFormatCondition();
201  ::comphelper::copyProperties(rxFormatCondition, xCond);
202  xSet->insertByIndex(i,uno::makeAny(xCond));
203  ++i;
204  }
205  return xSet;
206 }
207 
208 // XFormattedField
209 
210 ::sal_Int32 SAL_CALL OFormattedField::getFormatKey()
211 {
212  ::osl::MutexGuard aGuard(m_aMutex);
213  return m_nFormatKey;
214 }
215 
216 void SAL_CALL OFormattedField::setFormatKey(::sal_Int32 _formatkey)
217 {
218  set(PROPERTY_FORMATKEY,_formatkey,m_nFormatKey);
219 }
220 
221 uno::Reference< util::XNumberFormatsSupplier > SAL_CALL OFormattedField::getFormatsSupplier()
222 {
223  ::osl::MutexGuard aGuard(m_aMutex);
224  if ( !m_xFormatsSupplier.is() )
225  {
226  uno::Reference< report::XSection> xSection = getSection();
227  if ( xSection.is() )
228  m_xFormatsSupplier.set(xSection->getReportDefinition(),uno::UNO_QUERY);
229  if ( !m_xFormatsSupplier.is() )
230  {
231  uno::Reference< beans::XPropertySet> xProp(::dbtools::findDataSource(getParent()),uno::UNO_QUERY);
232  if ( xProp.is() )
233  m_xFormatsSupplier.set(xProp->getPropertyValue("NumberFormatsSupplier"),uno::UNO_QUERY);
234  }
235  }
236  return m_xFormatsSupplier;
237 }
238 
239 void SAL_CALL OFormattedField::setFormatsSupplier( const uno::Reference< util::XNumberFormatsSupplier >& _formatssupplier )
240 {
241  set(PROPERTY_FORMATSSUPPLIER,_formatssupplier,m_xFormatsSupplier);
242 }
243 
244 // XChild
245 uno::Reference< uno::XInterface > SAL_CALL OFormattedField::getParent( )
246 {
247  return OShapeHelper::getParent(this);
248 }
249 
250 void SAL_CALL OFormattedField::setParent( const uno::Reference< uno::XInterface >& Parent )
251 {
252  OShapeHelper::setParent(Parent,this);
253 }
254 
255 uno::Reference< report::XFormatCondition > SAL_CALL OFormattedField::createFormatCondition( )
256 {
257  return new OFormatCondition(m_aProps.aComponent.m_xContext);
258 }
259 
260 // XContainer
261 void SAL_CALL OFormattedField::addContainerListener( const uno::Reference< container::XContainerListener >& xListener )
262 {
263  m_aProps.addContainerListener(xListener);
264 }
265 
266 void SAL_CALL OFormattedField::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener )
267 {
268  m_aProps.removeContainerListener(xListener);
269 }
270 
271 // XElementAccess
272 uno::Type SAL_CALL OFormattedField::getElementType( )
273 {
275 }
276 
277 sal_Bool SAL_CALL OFormattedField::hasElements( )
278 {
279  return m_aProps.hasElements();
280 }
281 
282 // XIndexContainer
283 void SAL_CALL OFormattedField::insertByIndex( ::sal_Int32 Index, const uno::Any& Element )
284 {
285  m_aProps.insertByIndex(Index,Element);
286 }
287 
288 void SAL_CALL OFormattedField::removeByIndex( ::sal_Int32 Index )
289 {
290  m_aProps.removeByIndex(Index);
291 }
292 
293 // XIndexReplace
294 void SAL_CALL OFormattedField::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element )
295 {
296  m_aProps.replaceByIndex(Index,Element);
297 }
298 
299 // XIndexAccess
300 ::sal_Int32 SAL_CALL OFormattedField::getCount( )
301 {
302  return m_aProps.getCount();
303 }
304 
305 uno::Any SAL_CALL OFormattedField::getByIndex( ::sal_Int32 Index )
306 {
307  return m_aProps.getByIndex( Index );
308 }
309 
310 // XShape
311 awt::Point SAL_CALL OFormattedField::getPosition( )
312 {
313  return OShapeHelper::getPosition(this);
314 }
315 
316 void SAL_CALL OFormattedField::setPosition( const awt::Point& aPosition )
317 {
318  OShapeHelper::setPosition(aPosition,this);
319 }
320 
321 awt::Size SAL_CALL OFormattedField::getSize( )
322 {
323  return OShapeHelper::getSize(this);
324 }
325 
326 void SAL_CALL OFormattedField::setSize( const awt::Size& aSize )
327 {
328  OShapeHelper::setSize(aSize,this);
329 }
330 
331 
332 // XShapeDescriptor
333 OUString SAL_CALL OFormattedField::getShapeType( )
334 {
335  ::osl::MutexGuard aGuard(m_aMutex);
336  if ( m_aProps.aComponent.m_xShape.is() )
337  return m_aProps.aComponent.m_xShape->getShapeType();
338  return "com.sun.star.drawing.ControlShape";
339 }
340 
341 
342 } // namespace reportdesign
343 
344 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
346  css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
347 {
348  return cppu::acquire(new reportdesign::OFormattedField(context));
349 }
350 
351 
352 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define PROPERTY_MASTERFIELDS
Definition: strings.hxx:56
bool hasValue()
osl::Mutex m_aMutex
#define PROPERTY_DETAILFIELDS
Definition: strings.hxx:57
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * reportdesign_OFormattedField_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
#define PROPERTY_PRINTWHENGROUPCHANGE
Definition: strings.hxx:113
#define PROPERTY_DATAFIELD
Definition: strings.hxx:78
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
#define REPORTCOMPONENT_NOMASTERDETAIL(clazz)
#define REPORTCOMPONENT_IMPL(clazz, arg)
#define SAL_N_ELEMENTS(arr)
::sal_Int32 m_nFormatKey
OFormattedField(const OFormattedField &)=delete
#define SERVICE_FORMATTEDFIELD
Definition: strings.hxx:23
Reference< XDataSource > findDataSource(const Reference< XInterface > &_xParent)
int i
#define REPORTCOMPONENT_IMPL2(clazz, arg)
unsigned char sal_Bool
#define PROPERTY_FORMATSSUPPLIER
Definition: strings.hxx:97
css::uno::Type const & get()
OUString RptResId(const char *pId)
#define REPORTCONTROLFORMAT_IMPL(clazz, varName)
#define IMPLEMENT_FORWARD_REFCOUNT(classname, refcountbase)
::cppu::PropertySetMixin< css::report::XFormattedField > FormattedFieldPropertySet
static uno::Sequence< OUString > lcl_getFormattedFieldOptionals()
::cppu::WeakComponentImplHelper< css::report::XFormattedField,css::lang::XServiceInfo > FormattedFieldBase
uno::Reference< util::XCloneable > cloneObject(const uno::Reference< report::XReportComponent > &_xReportComponent, const uno::Reference< lang::XMultiServiceFactory > &_xFactory, const OUString &_sServiceName)
Definition: Tools.cxx:53
#define PROPERTY_CONDITIONALPRINTEXPRESSION
Definition: strings.hxx:110
#define PROPERTY_FORMATKEY
Definition: strings.hxx:94
struct _ADOIndex Index
void set(css::uno::UnoInterfaceReference const &value)