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