1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #include "precompiled_reportdesign.hxx"
24 #include "Group.hxx"
25 #include "Section.hxx"
26 #include <com/sun/star/beans/PropertyAttribute.hpp>
27 #include <com/sun/star/report/GroupOn.hpp>
28 #include <com/sun/star/report/KeepTogether.hpp>
29 #ifndef REPORTDESIGN_SHARED_CORESTRINGS_HRC
30 #include "corestrings.hrc"
31 #endif
32 #ifndef REPORTDESIGN_CORE_RESOURCE_HRC_
33 #include "core_resource.hrc"
34 #endif
35 #include "core_resource.hxx"
36 #include "Tools.hxx"
37 #include <tools/debug.hxx>
38 #include <comphelper/property.hxx>
39 #include "Functions.hxx"
40 
41 // =============================================================================
42 namespace reportdesign
43 {
44 // =============================================================================
45 	using namespace com::sun::star;
46 	using namespace comphelper;
DBG_NAME(rpt_OGroup)47 DBG_NAME( rpt_OGroup )
48 // -----------------------------------------------------------------------------
49 OGroup::OGroup(const uno::Reference< report::XGroups >& _xParent
50 			   ,const uno::Reference< uno::XComponentContext >& _xContext)
51 :GroupBase(m_aMutex)
52 ,GroupPropertySet(_xContext,static_cast< GroupPropertySet::Implements >(IMPLEMENTS_PROPERTY_SET),uno::Sequence< ::rtl::OUString >())
53 ,m_xContext(_xContext)
54 ,m_xParent(_xParent)
55 {
56 	DBG_CTOR( rpt_OGroup,NULL);
57     osl_incrementInterlockedCount(&m_refCount);
58 	{
59         m_xFunctions = new OFunctions(this,m_xContext);
60     }
61 	osl_decrementInterlockedCount( &m_refCount );
62 }
63 //--------------------------------------------------------------------------
64 // TODO: VirtualFunctionFinder: This is virtual function!
65 //
~OGroup()66 OGroup::~OGroup()
67 {
68     DBG_DTOR( rpt_OGroup,NULL);
69 }
70 //--------------------------------------------------------------------------
copyGroup(const uno::Reference<report::XGroup> & _xSource)71 void OGroup::copyGroup(const uno::Reference< report::XGroup >& _xSource)
72 {
73 	::comphelper::copyProperties(_xSource.get(),static_cast<GroupPropertySet*>(this));
74 
75 	if ( _xSource->getHeaderOn() )
76 	{
77 		setHeaderOn(sal_True);
78 		OSection::lcl_copySection(_xSource->getHeader(),m_xHeader);
79 	} // if ( _xSource->getHeaderOn() )
80 
81 	if ( _xSource->getFooterOn() )
82 	{
83 		setFooterOn(sal_True);
84 		OSection::lcl_copySection(_xSource->getFooter(),m_xFooter);
85 	} // if ( _xSource->getFooterOn() )
86 }
87 //--------------------------------------------------------------------------
IMPLEMENT_FORWARD_XINTERFACE2(OGroup,GroupBase,GroupPropertySet)88 IMPLEMENT_FORWARD_XINTERFACE2(OGroup,GroupBase,GroupPropertySet)
89 //--------------------------------------------------------------------------
90 ::rtl::OUString SAL_CALL OGroup::getImplementationName(  ) throw(uno::RuntimeException)
91 {
92     return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.report.Group"));
93 }
94 //------------------------------------------------------------------------------
getSupportedServiceNames_Static(void)95 uno::Sequence< ::rtl::OUString> OGroup::getSupportedServiceNames_Static(void) throw( uno::RuntimeException )
96 {
97 	uno::Sequence< ::rtl::OUString> aSupported(1);
98 	aSupported.getArray()[0] = SERVICE_GROUP;
99 	return aSupported;
100 }
101 //-------------------------------------------------------------------------
getSupportedServiceNames()102 uno::Sequence< ::rtl::OUString> SAL_CALL OGroup::getSupportedServiceNames() throw(uno::RuntimeException)
103 {
104 	return getSupportedServiceNames_Static();
105 }
106 // -----------------------------------------------------------------------------
supportsService(const::rtl::OUString & _rServiceName)107 sal_Bool SAL_CALL OGroup::supportsService( const ::rtl::OUString& _rServiceName ) throw(uno::RuntimeException)
108 {
109 	return ::comphelper::existsValue(_rServiceName,getSupportedServiceNames_Static());
110 }
111 // -----------------------------------------------------------------------------
dispose()112 void SAL_CALL OGroup::dispose() throw(uno::RuntimeException)
113 {
114 	GroupPropertySet::dispose();
115 	cppu::WeakComponentImplHelperBase::dispose();
116 }
117 // -----------------------------------------------------------------------------
118 // TODO: VirtualFunctionFinder: This is virtual function!
119 //
disposing()120 void SAL_CALL OGroup::disposing()
121 {
122     m_xHeader.clear();
123     m_xFooter.clear();
124     //::comphelper::disposeComponent(m_xHeader);
125     //::comphelper::disposeComponent(m_xFooter);
126     ::comphelper::disposeComponent(m_xFunctions);
127     m_xContext.clear();
128 }
129 // -----------------------------------------------------------------------------
130 // XGroup
getSortAscending()131 ::sal_Bool SAL_CALL OGroup::getSortAscending() throw (uno::RuntimeException)
132 {
133 	::osl::MutexGuard aGuard(m_aMutex);
134 	return m_aProps.m_eSortAscending;
135 }
136 // -----------------------------------------------------------------------------
setSortAscending(::sal_Bool _sortascending)137 void SAL_CALL OGroup::setSortAscending( ::sal_Bool _sortascending ) throw (uno::RuntimeException)
138 {
139 	set(PROPERTY_SORTASCENDING,_sortascending,m_aProps.m_eSortAscending);
140 }
141 // -----------------------------------------------------------------------------
getHeaderOn()142 ::sal_Bool SAL_CALL OGroup::getHeaderOn() throw (uno::RuntimeException)
143 {
144 	::osl::MutexGuard aGuard(m_aMutex);
145 	return m_xHeader.is();
146 }
147 // -----------------------------------------------------------------------------
setHeaderOn(::sal_Bool _headeron)148 void SAL_CALL OGroup::setHeaderOn( ::sal_Bool _headeron ) throw (uno::RuntimeException)
149 {
150 	if ( _headeron != m_xHeader.is() )
151     {
152         ::rtl::OUString sName(RPT_RESSTRING(RID_STR_GROUP_HEADER,m_xContext->getServiceManager()));
153         /*const ::rtl::OUString sPlaceHolder(RTL_CONSTASCII_USTRINGPARAM("%1"));
154         sName = sName.replaceAt(sName.indexOf(sPlaceHolder),sPlaceHolder.getLength(),m_aProps.m_sExpression);*/
155 		setSection(PROPERTY_HEADERON,_headeron,sName,m_xHeader);
156     }
157 }
158 // -----------------------------------------------------------------------------
getFooterOn()159 ::sal_Bool SAL_CALL OGroup::getFooterOn() throw (uno::RuntimeException)
160 {
161 	::osl::MutexGuard aGuard(m_aMutex);
162 	return m_xFooter.is();
163 }
164 // -----------------------------------------------------------------------------
setFooterOn(::sal_Bool _footeron)165 void SAL_CALL OGroup::setFooterOn( ::sal_Bool _footeron ) throw (uno::RuntimeException)
166 {
167 	if ( _footeron != m_xFooter.is() )
168     {
169         ::rtl::OUString sName(RPT_RESSTRING(RID_STR_GROUP_FOOTER,m_xContext->getServiceManager()));
170         /*const ::rtl::OUString sPlaceHolder(RTL_CONSTASCII_USTRINGPARAM("%1"));
171         sName = sName.replaceAt(sName.indexOf(sPlaceHolder),sPlaceHolder.getLength(),m_aProps.m_sExpression);*/
172 		setSection(PROPERTY_FOOTERON,_footeron,sName,m_xFooter);
173     }
174 }
175 // -----------------------------------------------------------------------------
getHeader()176 uno::Reference< report::XSection > SAL_CALL OGroup::getHeader() throw (container::NoSuchElementException, uno::RuntimeException)
177 {
178 	uno::Reference< report::XSection > xRet;
179 	{
180 		::osl::MutexGuard aGuard(m_aMutex);
181 		xRet = m_xHeader;
182 	}
183 
184 	if ( !xRet.is() )
185 		throw container::NoSuchElementException();
186 	return xRet;
187 }
188 // -----------------------------------------------------------------------------
getFooter()189 uno::Reference< report::XSection > SAL_CALL OGroup::getFooter() throw (container::NoSuchElementException, uno::RuntimeException)
190 {
191 	uno::Reference< report::XSection > xRet;
192 	{
193 		::osl::MutexGuard aGuard(m_aMutex);
194 		xRet = m_xFooter;
195 	}
196 
197 	if ( !xRet.is() )
198 		throw container::NoSuchElementException();
199 	return xRet;
200 }
201 // -----------------------------------------------------------------------------
getGroupOn()202 ::sal_Int16 SAL_CALL OGroup::getGroupOn() throw (uno::RuntimeException)
203 {
204 	::osl::MutexGuard aGuard(m_aMutex);
205 	return m_aProps.m_nGroupOn;
206 }
207 // -----------------------------------------------------------------------------
setGroupOn(::sal_Int16 _groupon)208 void SAL_CALL OGroup::setGroupOn( ::sal_Int16 _groupon ) throw (lang::IllegalArgumentException, uno::RuntimeException)
209 {
210 	if ( _groupon < report::GroupOn::DEFAULT || _groupon > report::GroupOn::INTERVAL )
211         throwIllegallArgumentException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com::sun::star::report::GroupOn"))
212                         ,*this
213                         ,1
214                         ,m_xContext);
215 	set(PROPERTY_GROUPON,_groupon,m_aProps.m_nGroupOn);
216 }
217 // -----------------------------------------------------------------------------
getGroupInterval()218 ::sal_Int32 SAL_CALL OGroup::getGroupInterval() throw (uno::RuntimeException)
219 {
220 	::osl::MutexGuard aGuard(m_aMutex);
221 	return m_aProps.m_nGroupInterval;
222 }
223 // -----------------------------------------------------------------------------
setGroupInterval(::sal_Int32 _groupinterval)224 void SAL_CALL OGroup::setGroupInterval( ::sal_Int32 _groupinterval ) throw (uno::RuntimeException)
225 {
226 	set(PROPERTY_GROUPINTERVAL,_groupinterval,m_aProps.m_nGroupInterval);
227 }
228 // -----------------------------------------------------------------------------
getKeepTogether()229 ::sal_Int16 SAL_CALL OGroup::getKeepTogether() throw (uno::RuntimeException)
230 {
231 	::osl::MutexGuard aGuard(m_aMutex);
232 	return m_aProps.m_nKeepTogether;
233 }
234 // -----------------------------------------------------------------------------
setKeepTogether(::sal_Int16 _keeptogether)235 void SAL_CALL OGroup::setKeepTogether( ::sal_Int16 _keeptogether ) throw (lang::IllegalArgumentException, uno::RuntimeException)
236 {
237 	if ( _keeptogether < report::KeepTogether::NO || _keeptogether > report::KeepTogether::WITH_FIRST_DETAIL )
238 		throwIllegallArgumentException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com::sun::star::report::KeepTogether"))
239                         ,*this
240                         ,1
241                         ,m_xContext);
242 	set(PROPERTY_KEEPTOGETHER,_keeptogether,m_aProps.m_nKeepTogether);
243 }
244 // -----------------------------------------------------------------------------
getGroups()245 uno::Reference< report::XGroups > SAL_CALL OGroup::getGroups() throw (uno::RuntimeException)
246 {
247 	return m_xParent;
248 }
249 // -----------------------------------------------------------------------------
getExpression()250 ::rtl::OUString SAL_CALL OGroup::getExpression() throw (uno::RuntimeException)
251 {
252 	::osl::MutexGuard aGuard(m_aMutex);
253 	return m_aProps.m_sExpression;
254 }
255 // -----------------------------------------------------------------------------
setExpression(const::rtl::OUString & _expression)256 void SAL_CALL OGroup::setExpression( const ::rtl::OUString& _expression ) throw (uno::RuntimeException)
257 {
258 	set(PROPERTY_EXPRESSION,_expression,m_aProps.m_sExpression);
259 }
260 // -----------------------------------------------------------------------------
getStartNewColumn()261 ::sal_Bool SAL_CALL OGroup::getStartNewColumn() throw (uno::RuntimeException)
262 {
263 	::osl::MutexGuard aGuard(m_aMutex);
264 	return m_aProps.m_bStartNewColumn;
265 }
266 // -----------------------------------------------------------------------------
setStartNewColumn(::sal_Bool _startnewcolumn)267 void SAL_CALL OGroup::setStartNewColumn( ::sal_Bool _startnewcolumn ) throw (uno::RuntimeException)
268 {
269 	set(PROPERTY_STARTNEWCOLUMN,_startnewcolumn,m_aProps.m_bStartNewColumn);
270 }
271 // -----------------------------------------------------------------------------
272 // -----------------------------------------------------------------------------
getResetPageNumber()273 ::sal_Bool SAL_CALL OGroup::getResetPageNumber() throw (uno::RuntimeException)
274 {
275 	::osl::MutexGuard aGuard(m_aMutex);
276 	return m_aProps.m_bResetPageNumber;
277 }
278 // -----------------------------------------------------------------------------
setResetPageNumber(::sal_Bool _resetpagenumber)279 void SAL_CALL OGroup::setResetPageNumber( ::sal_Bool _resetpagenumber ) throw (uno::RuntimeException)
280 {
281 	set(PROPERTY_RESETPAGENUMBER,_resetpagenumber,m_aProps.m_bResetPageNumber);
282 }
283 // -----------------------------------------------------------------------------
284 // XChild
getParent()285 uno::Reference< uno::XInterface > SAL_CALL OGroup::getParent(  ) throw (uno::RuntimeException)
286 {
287 	return m_xParent;
288 }
289 // -----------------------------------------------------------------------------
setParent(const uno::Reference<uno::XInterface> &)290 void SAL_CALL OGroup::setParent( const uno::Reference< uno::XInterface >& /*Parent*/ ) throw (lang::NoSupportException, uno::RuntimeException)
291 {
292 	throw lang::NoSupportException();
293 }
294 // -----------------------------------------------------------------------------
getPropertySetInfo()295 uno::Reference< beans::XPropertySetInfo > SAL_CALL OGroup::getPropertySetInfo(  ) throw(uno::RuntimeException)
296 {
297 	//	return uno::Reference< beans::XPropertySetInfo >();
298 	return GroupPropertySet::getPropertySetInfo();
299 }
300 // -----------------------------------------------------------------------------
setPropertyValue(const::rtl::OUString & aPropertyName,const uno::Any & aValue)301 void SAL_CALL OGroup::setPropertyValue( const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
302 {
303 	GroupPropertySet::setPropertyValue( aPropertyName, aValue );
304 }
305 // -----------------------------------------------------------------------------
getPropertyValue(const::rtl::OUString & PropertyName)306 uno::Any SAL_CALL OGroup::getPropertyValue( const ::rtl::OUString& PropertyName ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
307 {
308 	return GroupPropertySet::getPropertyValue( PropertyName);
309 }
310 // -----------------------------------------------------------------------------
addPropertyChangeListener(const::rtl::OUString & aPropertyName,const uno::Reference<beans::XPropertyChangeListener> & xListener)311 void SAL_CALL OGroup::addPropertyChangeListener( const ::rtl::OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& xListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
312 {
313 	GroupPropertySet::addPropertyChangeListener( aPropertyName, xListener );
314 }
315 // -----------------------------------------------------------------------------
removePropertyChangeListener(const::rtl::OUString & aPropertyName,const uno::Reference<beans::XPropertyChangeListener> & aListener)316 void SAL_CALL OGroup::removePropertyChangeListener( const ::rtl::OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& aListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
317 {
318 	GroupPropertySet::removePropertyChangeListener( aPropertyName, aListener );
319 }
320 // -----------------------------------------------------------------------------
addVetoableChangeListener(const::rtl::OUString & PropertyName,const uno::Reference<beans::XVetoableChangeListener> & aListener)321 void SAL_CALL OGroup::addVetoableChangeListener( const ::rtl::OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
322 {
323 	GroupPropertySet::addVetoableChangeListener( PropertyName, aListener );
324 }
325 // -----------------------------------------------------------------------------
removeVetoableChangeListener(const::rtl::OUString & PropertyName,const uno::Reference<beans::XVetoableChangeListener> & aListener)326 void SAL_CALL OGroup::removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
327 {
328 	GroupPropertySet::removeVetoableChangeListener( PropertyName, aListener );
329 }
330 // -----------------------------------------------------------------------------
setSection(const::rtl::OUString & _sProperty,const sal_Bool & _bOn,const::rtl::OUString & _sName,uno::Reference<report::XSection> & _member)331 void OGroup::setSection(	 const ::rtl::OUString& _sProperty
332 							,const sal_Bool& _bOn
333 							,const ::rtl::OUString& _sName
334 							,uno::Reference< report::XSection>& _member)
335 {
336 	BoundListeners l;
337 	{
338 		::osl::MutexGuard aGuard(m_aMutex);
339 		prepareSet(_sProperty, uno::makeAny(_member), uno::makeAny(_bOn), &l);
340 		lcl_createSectionIfNeeded(_bOn ,this,_member);
341 		if ( _member.is() )
342 			_member->setName(_sName);
343 	}
344 	l.notify();
345 }
346 // -----------------------------------------------------------------------------
getFunctions()347 uno::Reference< report::XFunctions > SAL_CALL OGroup::getFunctions() throw (uno::RuntimeException)
348 {
349     return m_xFunctions;
350 }
351 // =============================================================================
352 } // namespace reportdesign
353 // =============================================================================
354 
355