tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / reportdesign / source / core / api / FormattedField.cxx
blob4a168c4f3137dc88be942cddd635bfeb147bef35
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
27 #include <cppuhelper/supportsservice.hxx>
28 #include <Tools.hxx>
29 #include <FormatCondition.hxx>
30 #include <ReportHelperImpl.hxx>
32 namespace reportdesign
35 using namespace com::sun::star;
36 using namespace comphelper;
38 uno::Reference< uno::XInterface > OFormattedField::create(uno::Reference< uno::XComponentContext > const & xContext)
40 return *(new OFormattedField(xContext));
43 static uno::Sequence< OUString > lcl_getFormattedFieldOptionals()
45 OUString pProps[] = { PROPERTY_MASTERFIELDS,PROPERTY_DETAILFIELDS };
46 return uno::Sequence< OUString >(pProps,SAL_N_ELEMENTS(pProps));
49 OFormattedField::OFormattedField(uno::Reference< uno::XComponentContext > const & _xContext)
50 :FormattedFieldBase(m_aMutex)
51 ,FormattedFieldPropertySet(_xContext,IMPLEMENTS_PROPERTY_SET,lcl_getFormattedFieldOptionals())
52 ,m_aProps(m_aMutex,static_cast< container::XContainer*>( this ),_xContext)
53 ,m_nFormatKey(0)
55 m_aProps.aComponent.m_sName = RptResId(RID_STR_FORMATTEDFIELD);
58 OFormattedField::OFormattedField(uno::Reference< uno::XComponentContext > const & _xContext
59 ,const uno::Reference< lang::XMultiServiceFactory>& _xFactory
60 ,uno::Reference< drawing::XShape >& _xShape)
61 :FormattedFieldBase(m_aMutex)
62 ,FormattedFieldPropertySet(_xContext,IMPLEMENTS_PROPERTY_SET,lcl_getFormattedFieldOptionals())
63 ,m_aProps(m_aMutex,static_cast< container::XContainer*>( this ),_xContext)
64 ,m_nFormatKey(0)
66 m_aProps.aComponent.m_sName = RptResId(RID_STR_FORMATTEDFIELD);
67 m_aProps.aComponent.m_xFactory = _xFactory;
68 osl_atomic_increment( &m_refCount );
70 m_aProps.aComponent.setShape(_xShape,this,m_refCount);
72 osl_atomic_decrement( &m_refCount );
75 OFormattedField::~OFormattedField()
79 IMPLEMENT_FORWARD_REFCOUNT( OFormattedField, FormattedFieldBase )
81 uno::Any SAL_CALL OFormattedField::queryInterface( const uno::Type& _rType )
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;
89 return aReturn.hasValue() ? aReturn : (m_aProps.aComponent.m_xProxy.is() ? m_aProps.aComponent.m_xProxy->queryAggregation(_rType) : aReturn);
93 void SAL_CALL OFormattedField::dispose()
95 FormattedFieldPropertySet::dispose();
96 cppu::WeakComponentImplHelperBase::dispose();
97 m_xFormatsSupplier.clear();
100 OUString OFormattedField::getImplementationName_Static( )
102 return u"com.sun.star.comp.report.OFormattedField"_ustr;
106 OUString SAL_CALL OFormattedField::getImplementationName( )
108 return getImplementationName_Static();
111 uno::Sequence< OUString > OFormattedField::getSupportedServiceNames_Static( )
113 return { SERVICE_FORMATTEDFIELD, u"com.sun.star.awt.UnoControlFormattedFieldModel"_ustr };
116 uno::Sequence< OUString > SAL_CALL OFormattedField::getSupportedServiceNames( )
118 return getSupportedServiceNames_Static();
121 sal_Bool SAL_CALL OFormattedField::supportsService(const OUString& ServiceName)
123 return cppu::supportsService(this, ServiceName);
126 // XReportComponent
127 REPORTCOMPONENT_IMPL(OFormattedField,m_aProps.aComponent)
128 REPORTCOMPONENT_IMPL2(OFormattedField,m_aProps.aComponent)
129 REPORTCOMPONENT_NOMASTERDETAIL(OFormattedField)
130 REPORTCONTROLFORMAT_IMPL(OFormattedField,m_aProps.aFormatProperties)
133 uno::Reference< beans::XPropertySetInfo > SAL_CALL OFormattedField::getPropertySetInfo( )
135 return FormattedFieldPropertySet::getPropertySetInfo();
138 void SAL_CALL OFormattedField::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
140 // special case here /// TODO check
141 if ( !aValue.hasValue() && aPropertyName == PROPERTY_FORMATKEY )
142 m_nFormatKey = 0;
143 else
144 FormattedFieldPropertySet::setPropertyValue( aPropertyName, aValue );
147 uno::Any SAL_CALL OFormattedField::getPropertyValue( const OUString& PropertyName )
149 return FormattedFieldPropertySet::getPropertyValue( PropertyName);
152 void SAL_CALL OFormattedField::addPropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& xListener )
154 FormattedFieldPropertySet::addPropertyChangeListener( aPropertyName, xListener );
157 void SAL_CALL OFormattedField::removePropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& aListener )
159 FormattedFieldPropertySet::removePropertyChangeListener( aPropertyName, aListener );
162 void SAL_CALL OFormattedField::addVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener )
164 FormattedFieldPropertySet::addVetoableChangeListener( PropertyName, aListener );
167 void SAL_CALL OFormattedField::removeVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener )
169 FormattedFieldPropertySet::removeVetoableChangeListener( PropertyName, aListener );
172 // XReportControlModel
173 OUString SAL_CALL OFormattedField::getDataField()
175 ::osl::MutexGuard aGuard(m_aMutex);
176 return m_aProps.aDataField;
179 void SAL_CALL OFormattedField::setDataField( const OUString& _datafield )
181 set(PROPERTY_DATAFIELD,_datafield,m_aProps.aDataField);
184 sal_Bool SAL_CALL OFormattedField::getPrintWhenGroupChange()
186 ::osl::MutexGuard aGuard(m_aMutex);
187 return m_aProps.bPrintWhenGroupChange;
190 void SAL_CALL OFormattedField::setPrintWhenGroupChange( sal_Bool _printwhengroupchange )
192 set(PROPERTY_PRINTWHENGROUPCHANGE,_printwhengroupchange,m_aProps.bPrintWhenGroupChange);
195 OUString SAL_CALL OFormattedField::getConditionalPrintExpression()
197 ::osl::MutexGuard aGuard(m_aMutex);
198 return m_aProps.aConditionalPrintExpression;
201 void SAL_CALL OFormattedField::setConditionalPrintExpression( const OUString& _conditionalprintexpression )
203 set(PROPERTY_CONDITIONALPRINTEXPRESSION,_conditionalprintexpression,m_aProps.aConditionalPrintExpression);
207 // XCloneable
208 uno::Reference< util::XCloneable > SAL_CALL OFormattedField::createClone( )
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);
213 sal_Int32 i = 0;
214 for (const auto& rxFormatCondition : m_aProps.m_aFormatConditions)
216 uno::Reference< report::XFormatCondition > xCond = xSet->createFormatCondition();
217 ::comphelper::copyProperties(rxFormatCondition, xCond);
218 xSet->insertByIndex(i,uno::Any(xCond));
219 ++i;
221 return xSet;
224 // XFormattedField
226 ::sal_Int32 SAL_CALL OFormattedField::getFormatKey()
228 ::osl::MutexGuard aGuard(m_aMutex);
229 return m_nFormatKey;
232 void SAL_CALL OFormattedField::setFormatKey(::sal_Int32 _formatkey)
234 set(PROPERTY_FORMATKEY,_formatkey,m_nFormatKey);
237 uno::Reference< util::XNumberFormatsSupplier > SAL_CALL OFormattedField::getFormatsSupplier()
239 ::osl::MutexGuard aGuard(m_aMutex);
240 if ( !m_xFormatsSupplier.is() )
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() )
247 uno::Reference< beans::XPropertySet> xProp(::dbtools::findDataSource(getParent()),uno::UNO_QUERY);
248 if ( xProp.is() )
249 m_xFormatsSupplier.set(xProp->getPropertyValue(u"NumberFormatsSupplier"_ustr),uno::UNO_QUERY);
252 return m_xFormatsSupplier;
255 void SAL_CALL OFormattedField::setFormatsSupplier( const uno::Reference< util::XNumberFormatsSupplier >& _formatssupplier )
257 set(PROPERTY_FORMATSSUPPLIER,_formatssupplier,m_xFormatsSupplier);
260 // XChild
261 uno::Reference< uno::XInterface > SAL_CALL OFormattedField::getParent( )
263 return OShapeHelper::getParent(this);
266 void SAL_CALL OFormattedField::setParent( const uno::Reference< uno::XInterface >& Parent )
268 OShapeHelper::setParent(Parent,this);
271 uno::Reference< report::XFormatCondition > SAL_CALL OFormattedField::createFormatCondition( )
273 return new OFormatCondition(m_aProps.aComponent.m_xContext);
276 // XContainer
277 void SAL_CALL OFormattedField::addContainerListener( const uno::Reference< container::XContainerListener >& xListener )
279 m_aProps.addContainerListener(xListener);
282 void SAL_CALL OFormattedField::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener )
284 m_aProps.removeContainerListener(xListener);
287 // XElementAccess
288 uno::Type SAL_CALL OFormattedField::getElementType( )
290 return cppu::UnoType<report::XFormatCondition>::get();
293 sal_Bool SAL_CALL OFormattedField::hasElements( )
295 return m_aProps.hasElements();
298 // XIndexContainer
299 void SAL_CALL OFormattedField::insertByIndex( ::sal_Int32 Index, const uno::Any& Element )
301 m_aProps.insertByIndex(Index,Element);
304 void SAL_CALL OFormattedField::removeByIndex( ::sal_Int32 Index )
306 m_aProps.removeByIndex(Index);
309 // XIndexReplace
310 void SAL_CALL OFormattedField::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element )
312 m_aProps.replaceByIndex(Index,Element);
315 // XIndexAccess
316 ::sal_Int32 SAL_CALL OFormattedField::getCount( )
318 return m_aProps.getCount();
321 uno::Any SAL_CALL OFormattedField::getByIndex( ::sal_Int32 Index )
323 return m_aProps.getByIndex( Index );
326 // XShape
327 awt::Point SAL_CALL OFormattedField::getPosition( )
329 return OShapeHelper::getPosition(this);
332 void SAL_CALL OFormattedField::setPosition( const awt::Point& aPosition )
334 OShapeHelper::setPosition(aPosition,this);
337 awt::Size SAL_CALL OFormattedField::getSize( )
339 return OShapeHelper::getSize(this);
342 void SAL_CALL OFormattedField::setSize( const awt::Size& aSize )
344 OShapeHelper::setSize(aSize,this);
348 // XShapeDescriptor
349 OUString SAL_CALL OFormattedField::getShapeType( )
351 ::osl::MutexGuard aGuard(m_aMutex);
352 if ( m_aProps.aComponent.m_xShape.is() )
353 return m_aProps.aComponent.m_xShape->getShapeType();
354 return u"com.sun.star.drawing.ControlShape"_ustr;
358 } // namespace reportdesign
361 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */