cid#1607171 Data race condition
[LibreOffice.git] / reportdesign / source / core / api / Group.cxx
blobfbb3f69157544b58ca99efa3a1012609711be0a4
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 <Group.hxx>
20 #include <Groups.hxx>
21 #include <Section.hxx>
22 #include <com/sun/star/lang/NoSupportException.hpp>
23 #include <com/sun/star/report/GroupOn.hpp>
24 #include <com/sun/star/report/KeepTogether.hpp>
25 #include <strings.hxx>
26 #include <strings.hrc>
27 #include <core_resource.hxx>
28 #include <Tools.hxx>
29 #include <cppuhelper/supportsservice.hxx>
30 #include <comphelper/types.hxx>
31 #include <Functions.hxx>
34 namespace reportdesign
37 using namespace com::sun::star;
39 OGroup::OGroup(const rtl::Reference< OGroups >& _xParent
40 ,const uno::Reference< uno::XComponentContext >& _xContext)
41 :GroupBase(m_aMutex)
42 ,GroupPropertySet(_xContext,IMPLEMENTS_PROPERTY_SET,uno::Sequence< OUString >())
43 ,m_xContext(_xContext)
44 ,m_xParent(_xParent)
46 osl_atomic_increment(&m_refCount);
48 m_xFunctions = new OFunctions(this,m_xContext);
50 osl_atomic_decrement( &m_refCount );
53 // TODO: VirtualFunctionFinder: This is virtual function!
55 OGroup::~OGroup()
59 IMPLEMENT_FORWARD_XINTERFACE2(OGroup,GroupBase,GroupPropertySet)
61 OUString SAL_CALL OGroup::getImplementationName( )
63 return u"com.sun.star.comp.report.Group"_ustr;
66 uno::Sequence< OUString> OGroup::getSupportedServiceNames_Static()
68 uno::Sequence<OUString> aSupported { SERVICE_GROUP };
69 return aSupported;
72 uno::Sequence< OUString> SAL_CALL OGroup::getSupportedServiceNames()
74 return getSupportedServiceNames_Static();
77 sal_Bool SAL_CALL OGroup::supportsService( const OUString& _rServiceName )
79 return cppu::supportsService(this, _rServiceName);
82 void SAL_CALL OGroup::dispose()
84 GroupPropertySet::dispose();
85 cppu::WeakComponentImplHelperBase::dispose();
88 // TODO: VirtualFunctionFinder: This is virtual function!
90 void SAL_CALL OGroup::disposing()
92 m_xHeader.clear();
93 m_xFooter.clear();
94 ::comphelper::disposeComponent(m_xFunctions);
95 m_xContext.clear();
98 // XGroup
99 sal_Bool SAL_CALL OGroup::getSortAscending()
101 ::osl::MutexGuard aGuard(m_aMutex);
102 return m_aProps.m_eSortAscending;
105 void SAL_CALL OGroup::setSortAscending( sal_Bool _sortascending )
107 set(PROPERTY_SORTASCENDING,_sortascending,m_aProps.m_eSortAscending);
110 sal_Bool SAL_CALL OGroup::getHeaderOn()
112 ::osl::MutexGuard aGuard(m_aMutex);
113 return m_xHeader.is();
116 void SAL_CALL OGroup::setHeaderOn( sal_Bool _headeron )
118 if ( bool(_headeron) != m_xHeader.is() )
120 OUString sName(RptResId(RID_STR_GROUP_HEADER));
121 setSection(PROPERTY_HEADERON,_headeron,sName,m_xHeader);
125 sal_Bool SAL_CALL OGroup::getFooterOn()
127 ::osl::MutexGuard aGuard(m_aMutex);
128 return m_xFooter.is();
131 void SAL_CALL OGroup::setFooterOn( sal_Bool _footeron )
133 if ( bool(_footeron) != m_xFooter.is() )
135 OUString sName(RptResId(RID_STR_GROUP_FOOTER));
136 setSection(PROPERTY_FOOTERON,_footeron,sName,m_xFooter);
140 uno::Reference< report::XSection > SAL_CALL OGroup::getHeader()
142 uno::Reference< report::XSection > xRet;
144 ::osl::MutexGuard aGuard(m_aMutex);
145 xRet = m_xHeader;
148 if ( !xRet.is() )
149 throw container::NoSuchElementException();
150 return xRet;
153 uno::Reference< report::XSection > SAL_CALL OGroup::getFooter()
155 uno::Reference< report::XSection > xRet;
157 ::osl::MutexGuard aGuard(m_aMutex);
158 xRet = m_xFooter;
161 if ( !xRet.is() )
162 throw container::NoSuchElementException();
163 return xRet;
166 ::sal_Int16 SAL_CALL OGroup::getGroupOn()
168 ::osl::MutexGuard aGuard(m_aMutex);
169 return m_aProps.m_nGroupOn;
172 void SAL_CALL OGroup::setGroupOn( ::sal_Int16 _groupon )
174 if ( _groupon < report::GroupOn::DEFAULT || _groupon > report::GroupOn::INTERVAL )
175 throwIllegallArgumentException(u"css::report::GroupOn"
176 ,*this
177 ,1);
178 set(PROPERTY_GROUPON,_groupon,m_aProps.m_nGroupOn);
181 ::sal_Int32 SAL_CALL OGroup::getGroupInterval()
183 ::osl::MutexGuard aGuard(m_aMutex);
184 return m_aProps.m_nGroupInterval;
187 void SAL_CALL OGroup::setGroupInterval( ::sal_Int32 _groupinterval )
189 set(PROPERTY_GROUPINTERVAL,_groupinterval,m_aProps.m_nGroupInterval);
192 ::sal_Int16 SAL_CALL OGroup::getKeepTogether()
194 ::osl::MutexGuard aGuard(m_aMutex);
195 return m_aProps.m_nKeepTogether;
198 void SAL_CALL OGroup::setKeepTogether( ::sal_Int16 _keeptogether )
200 if ( _keeptogether < report::KeepTogether::NO || _keeptogether > report::KeepTogether::WITH_FIRST_DETAIL )
201 throwIllegallArgumentException(u"css::report::KeepTogether"
202 ,*this
203 ,1);
204 set(PROPERTY_KEEPTOGETHER,_keeptogether,m_aProps.m_nKeepTogether);
207 uno::Reference< report::XGroups > SAL_CALL OGroup::getGroups()
209 return m_xParent.get();
212 rtl::Reference< OGroups > OGroup::getOGroups() const
214 return m_xParent.get();
217 OUString SAL_CALL OGroup::getExpression()
219 ::osl::MutexGuard aGuard(m_aMutex);
220 return m_aProps.m_sExpression;
223 void SAL_CALL OGroup::setExpression( const OUString& _expression )
225 set(PROPERTY_EXPRESSION,_expression,m_aProps.m_sExpression);
228 sal_Bool SAL_CALL OGroup::getStartNewColumn()
230 ::osl::MutexGuard aGuard(m_aMutex);
231 return m_aProps.m_bStartNewColumn;
234 void SAL_CALL OGroup::setStartNewColumn( sal_Bool _startnewcolumn )
236 set(PROPERTY_STARTNEWCOLUMN,_startnewcolumn,m_aProps.m_bStartNewColumn);
240 sal_Bool SAL_CALL OGroup::getResetPageNumber()
242 ::osl::MutexGuard aGuard(m_aMutex);
243 return m_aProps.m_bResetPageNumber;
246 void SAL_CALL OGroup::setResetPageNumber( sal_Bool _resetpagenumber )
248 set(PROPERTY_RESETPAGENUMBER,_resetpagenumber,m_aProps.m_bResetPageNumber);
251 // XChild
252 uno::Reference< uno::XInterface > SAL_CALL OGroup::getParent( )
254 return m_xParent;
257 void SAL_CALL OGroup::setParent( const uno::Reference< uno::XInterface >& /*Parent*/ )
259 throw lang::NoSupportException();
262 uno::Reference< beans::XPropertySetInfo > SAL_CALL OGroup::getPropertySetInfo( )
264 return GroupPropertySet::getPropertySetInfo();
267 void SAL_CALL OGroup::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
269 GroupPropertySet::setPropertyValue( aPropertyName, aValue );
272 uno::Any SAL_CALL OGroup::getPropertyValue( const OUString& PropertyName )
274 return GroupPropertySet::getPropertyValue( PropertyName);
277 void SAL_CALL OGroup::addPropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& xListener )
279 GroupPropertySet::addPropertyChangeListener( aPropertyName, xListener );
282 void SAL_CALL OGroup::removePropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& aListener )
284 GroupPropertySet::removePropertyChangeListener( aPropertyName, aListener );
287 void SAL_CALL OGroup::addVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener )
289 GroupPropertySet::addVetoableChangeListener( PropertyName, aListener );
292 void SAL_CALL OGroup::removeVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener )
294 GroupPropertySet::removeVetoableChangeListener( PropertyName, aListener );
297 void OGroup::setSection( const OUString& _sProperty
298 ,bool _bOn
299 ,const OUString& _sName
300 ,rtl::Reference< OSection>& _member)
302 BoundListeners l;
304 ::osl::MutexGuard aGuard(m_aMutex);
305 prepareSet(_sProperty, uno::Any(uno::Reference<report::XSection>(_member)), uno::Any(_bOn), &l);
307 // create section if needed
308 if ( _bOn && !_member.is() )
309 _member = OSection::createOSection(this, m_xContext);
310 else if ( !_bOn )
311 ::comphelper::disposeComponent(_member);
313 if ( _member.is() )
314 _member->setName(_sName);
316 l.notify();
319 uno::Reference< report::XFunctions > SAL_CALL OGroup::getFunctions()
321 return m_xFunctions;
324 } // namespace reportdesign
327 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */