1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Group.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "Section.hxx"
32 #include <com/sun/star/beans/PropertyAttribute.hpp>
33 #include <com/sun/star/report/GroupOn.hpp>
34 #include <com/sun/star/report/KeepTogether.hpp>
35 #ifndef REPORTDESIGN_SHARED_CORESTRINGS_HRC
36 #include "corestrings.hrc"
38 #ifndef REPORTDESIGN_CORE_RESOURCE_HRC_
39 #include "core_resource.hrc"
41 #include "core_resource.hxx"
43 #include <tools/debug.hxx>
44 #include <comphelper/property.hxx>
45 #include "Functions.hxx"
47 // =============================================================================
48 namespace reportdesign
50 // =============================================================================
51 using namespace com::sun::star
;
52 using namespace comphelper
;
53 DBG_NAME( rpt_OGroup
)
54 // -----------------------------------------------------------------------------
55 OGroup::OGroup(const uno::Reference
< report::XGroups
>& _xParent
56 ,const uno::Reference
< uno::XComponentContext
>& _xContext
)
58 ,GroupPropertySet(_xContext
,static_cast< GroupPropertySet::Implements
>(IMPLEMENTS_PROPERTY_SET
),uno::Sequence
< ::rtl::OUString
>())
59 ,m_xContext(_xContext
)
62 DBG_CTOR( rpt_OGroup
,NULL
);
63 osl_incrementInterlockedCount(&m_refCount
);
65 m_xFunctions
= new OFunctions(this,m_xContext
);
67 osl_decrementInterlockedCount( &m_refCount
);
69 //--------------------------------------------------------------------------
70 // TODO: VirtualFunctionFinder: This is virtual function!
74 DBG_DTOR( rpt_OGroup
,NULL
);
76 //--------------------------------------------------------------------------
77 void OGroup::copyGroup(const uno::Reference
< report::XGroup
>& _xSource
)
79 ::comphelper::copyProperties(_xSource
.get(),static_cast<GroupPropertySet
*>(this));
81 if ( _xSource
->getHeaderOn() )
83 setHeaderOn(sal_True
);
84 OSection::lcl_copySection(_xSource
->getHeader(),m_xHeader
);
85 } // if ( _xSource->getHeaderOn() )
87 if ( _xSource
->getFooterOn() )
89 setFooterOn(sal_True
);
90 OSection::lcl_copySection(_xSource
->getFooter(),m_xFooter
);
91 } // if ( _xSource->getFooterOn() )
93 //--------------------------------------------------------------------------
94 IMPLEMENT_FORWARD_XINTERFACE2(OGroup
,GroupBase
,GroupPropertySet
)
95 //--------------------------------------------------------------------------
96 ::rtl::OUString SAL_CALL
OGroup::getImplementationName( ) throw(uno::RuntimeException
)
98 return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.report.Group"));
100 //------------------------------------------------------------------------------
101 uno::Sequence
< ::rtl::OUString
> OGroup::getSupportedServiceNames_Static(void) throw( uno::RuntimeException
)
103 uno::Sequence
< ::rtl::OUString
> aSupported(1);
104 aSupported
.getArray()[0] = SERVICE_GROUP
;
107 //-------------------------------------------------------------------------
108 uno::Sequence
< ::rtl::OUString
> SAL_CALL
OGroup::getSupportedServiceNames() throw(uno::RuntimeException
)
110 return getSupportedServiceNames_Static();
112 // -----------------------------------------------------------------------------
113 sal_Bool SAL_CALL
OGroup::supportsService( const ::rtl::OUString
& _rServiceName
) throw(uno::RuntimeException
)
115 return ::comphelper::existsValue(_rServiceName
,getSupportedServiceNames_Static());
117 // -----------------------------------------------------------------------------
118 void SAL_CALL
OGroup::dispose() throw(uno::RuntimeException
)
120 GroupPropertySet::dispose();
121 cppu::WeakComponentImplHelperBase::dispose();
123 // -----------------------------------------------------------------------------
124 // TODO: VirtualFunctionFinder: This is virtual function!
126 void SAL_CALL
OGroup::disposing()
130 //::comphelper::disposeComponent(m_xHeader);
131 //::comphelper::disposeComponent(m_xFooter);
132 ::comphelper::disposeComponent(m_xFunctions
);
135 // -----------------------------------------------------------------------------
137 ::sal_Bool SAL_CALL
OGroup::getSortAscending() throw (uno::RuntimeException
)
139 ::osl::MutexGuard
aGuard(m_aMutex
);
140 return m_aProps
.m_eSortAscending
;
142 // -----------------------------------------------------------------------------
143 void SAL_CALL
OGroup::setSortAscending( ::sal_Bool _sortascending
) throw (uno::RuntimeException
)
145 set(PROPERTY_SORTASCENDING
,_sortascending
,m_aProps
.m_eSortAscending
);
147 // -----------------------------------------------------------------------------
148 ::sal_Bool SAL_CALL
OGroup::getHeaderOn() throw (uno::RuntimeException
)
150 ::osl::MutexGuard
aGuard(m_aMutex
);
151 return m_xHeader
.is();
153 // -----------------------------------------------------------------------------
154 void SAL_CALL
OGroup::setHeaderOn( ::sal_Bool _headeron
) throw (uno::RuntimeException
)
156 if ( _headeron
!= m_xHeader
.is() )
158 ::rtl::OUString
sName(RPT_RESSTRING(RID_STR_GROUP_HEADER
,m_xContext
->getServiceManager()));
159 /*const ::rtl::OUString sPlaceHolder(RTL_CONSTASCII_USTRINGPARAM("%1"));
160 sName = sName.replaceAt(sName.indexOf(sPlaceHolder),sPlaceHolder.getLength(),m_aProps.m_sExpression);*/
161 setSection(PROPERTY_HEADERON
,_headeron
,sName
,m_xHeader
);
164 // -----------------------------------------------------------------------------
165 ::sal_Bool SAL_CALL
OGroup::getFooterOn() throw (uno::RuntimeException
)
167 ::osl::MutexGuard
aGuard(m_aMutex
);
168 return m_xFooter
.is();
170 // -----------------------------------------------------------------------------
171 void SAL_CALL
OGroup::setFooterOn( ::sal_Bool _footeron
) throw (uno::RuntimeException
)
173 if ( _footeron
!= m_xFooter
.is() )
175 ::rtl::OUString
sName(RPT_RESSTRING(RID_STR_GROUP_FOOTER
,m_xContext
->getServiceManager()));
176 /*const ::rtl::OUString sPlaceHolder(RTL_CONSTASCII_USTRINGPARAM("%1"));
177 sName = sName.replaceAt(sName.indexOf(sPlaceHolder),sPlaceHolder.getLength(),m_aProps.m_sExpression);*/
178 setSection(PROPERTY_FOOTERON
,_footeron
,sName
,m_xFooter
);
181 // -----------------------------------------------------------------------------
182 uno::Reference
< report::XSection
> SAL_CALL
OGroup::getHeader() throw (container::NoSuchElementException
, uno::RuntimeException
)
184 uno::Reference
< report::XSection
> xRet
;
186 ::osl::MutexGuard
aGuard(m_aMutex
);
191 throw container::NoSuchElementException();
194 // -----------------------------------------------------------------------------
195 uno::Reference
< report::XSection
> SAL_CALL
OGroup::getFooter() throw (container::NoSuchElementException
, uno::RuntimeException
)
197 uno::Reference
< report::XSection
> xRet
;
199 ::osl::MutexGuard
aGuard(m_aMutex
);
204 throw container::NoSuchElementException();
207 // -----------------------------------------------------------------------------
208 ::sal_Int16 SAL_CALL
OGroup::getGroupOn() throw (uno::RuntimeException
)
210 ::osl::MutexGuard
aGuard(m_aMutex
);
211 return m_aProps
.m_nGroupOn
;
213 // -----------------------------------------------------------------------------
214 void SAL_CALL
OGroup::setGroupOn( ::sal_Int16 _groupon
) throw (lang::IllegalArgumentException
, uno::RuntimeException
)
216 if ( _groupon
< report::GroupOn::DEFAULT
|| _groupon
> report::GroupOn::INTERVAL
)
217 throwIllegallArgumentException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com::sun::star::report::GroupOn"))
221 set(PROPERTY_GROUPON
,_groupon
,m_aProps
.m_nGroupOn
);
223 // -----------------------------------------------------------------------------
224 ::sal_Int32 SAL_CALL
OGroup::getGroupInterval() throw (uno::RuntimeException
)
226 ::osl::MutexGuard
aGuard(m_aMutex
);
227 return m_aProps
.m_nGroupInterval
;
229 // -----------------------------------------------------------------------------
230 void SAL_CALL
OGroup::setGroupInterval( ::sal_Int32 _groupinterval
) throw (uno::RuntimeException
)
232 set(PROPERTY_GROUPINTERVAL
,_groupinterval
,m_aProps
.m_nGroupInterval
);
234 // -----------------------------------------------------------------------------
235 ::sal_Int16 SAL_CALL
OGroup::getKeepTogether() throw (uno::RuntimeException
)
237 ::osl::MutexGuard
aGuard(m_aMutex
);
238 return m_aProps
.m_nKeepTogether
;
240 // -----------------------------------------------------------------------------
241 void SAL_CALL
OGroup::setKeepTogether( ::sal_Int16 _keeptogether
) throw (lang::IllegalArgumentException
, uno::RuntimeException
)
243 if ( _keeptogether
< report::KeepTogether::NO
|| _keeptogether
> report::KeepTogether::WITH_FIRST_DETAIL
)
244 throwIllegallArgumentException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com::sun::star::report::KeepTogether"))
248 set(PROPERTY_KEEPTOGETHER
,_keeptogether
,m_aProps
.m_nKeepTogether
);
250 // -----------------------------------------------------------------------------
251 uno::Reference
< report::XGroups
> SAL_CALL
OGroup::getGroups() throw (uno::RuntimeException
)
255 // -----------------------------------------------------------------------------
256 ::rtl::OUString SAL_CALL
OGroup::getExpression() throw (uno::RuntimeException
)
258 ::osl::MutexGuard
aGuard(m_aMutex
);
259 return m_aProps
.m_sExpression
;
261 // -----------------------------------------------------------------------------
262 void SAL_CALL
OGroup::setExpression( const ::rtl::OUString
& _expression
) throw (uno::RuntimeException
)
264 set(PROPERTY_EXPRESSION
,_expression
,m_aProps
.m_sExpression
);
266 // -----------------------------------------------------------------------------
267 ::sal_Bool SAL_CALL
OGroup::getStartNewColumn() throw (uno::RuntimeException
)
269 ::osl::MutexGuard
aGuard(m_aMutex
);
270 return m_aProps
.m_bStartNewColumn
;
272 // -----------------------------------------------------------------------------
273 void SAL_CALL
OGroup::setStartNewColumn( ::sal_Bool _startnewcolumn
) throw (uno::RuntimeException
)
275 set(PROPERTY_STARTNEWCOLUMN
,_startnewcolumn
,m_aProps
.m_bStartNewColumn
);
277 // -----------------------------------------------------------------------------
278 // -----------------------------------------------------------------------------
279 ::sal_Bool SAL_CALL
OGroup::getResetPageNumber() throw (uno::RuntimeException
)
281 ::osl::MutexGuard
aGuard(m_aMutex
);
282 return m_aProps
.m_bResetPageNumber
;
284 // -----------------------------------------------------------------------------
285 void SAL_CALL
OGroup::setResetPageNumber( ::sal_Bool _resetpagenumber
) throw (uno::RuntimeException
)
287 set(PROPERTY_RESETPAGENUMBER
,_resetpagenumber
,m_aProps
.m_bResetPageNumber
);
289 // -----------------------------------------------------------------------------
291 uno::Reference
< uno::XInterface
> SAL_CALL
OGroup::getParent( ) throw (uno::RuntimeException
)
295 // -----------------------------------------------------------------------------
296 void SAL_CALL
OGroup::setParent( const uno::Reference
< uno::XInterface
>& /*Parent*/ ) throw (lang::NoSupportException
, uno::RuntimeException
)
298 throw lang::NoSupportException();
300 // -----------------------------------------------------------------------------
301 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
OGroup::getPropertySetInfo( ) throw(uno::RuntimeException
)
303 // return uno::Reference< beans::XPropertySetInfo >();
304 return GroupPropertySet::getPropertySetInfo();
306 // -----------------------------------------------------------------------------
307 void SAL_CALL
OGroup::setPropertyValue( const ::rtl::OUString
& aPropertyName
, const uno::Any
& aValue
) throw (beans::UnknownPropertyException
, beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
)
309 GroupPropertySet::setPropertyValue( aPropertyName
, aValue
);
311 // -----------------------------------------------------------------------------
312 uno::Any SAL_CALL
OGroup::getPropertyValue( const ::rtl::OUString
& PropertyName
) throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
314 return GroupPropertySet::getPropertyValue( PropertyName
);
316 // -----------------------------------------------------------------------------
317 void SAL_CALL
OGroup::addPropertyChangeListener( const ::rtl::OUString
& aPropertyName
, const uno::Reference
< beans::XPropertyChangeListener
>& xListener
) throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
319 GroupPropertySet::addPropertyChangeListener( aPropertyName
, xListener
);
321 // -----------------------------------------------------------------------------
322 void SAL_CALL
OGroup::removePropertyChangeListener( const ::rtl::OUString
& aPropertyName
, const uno::Reference
< beans::XPropertyChangeListener
>& aListener
) throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
324 GroupPropertySet::removePropertyChangeListener( aPropertyName
, aListener
);
326 // -----------------------------------------------------------------------------
327 void SAL_CALL
OGroup::addVetoableChangeListener( const ::rtl::OUString
& PropertyName
, const uno::Reference
< beans::XVetoableChangeListener
>& aListener
) throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
329 GroupPropertySet::addVetoableChangeListener( PropertyName
, aListener
);
331 // -----------------------------------------------------------------------------
332 void SAL_CALL
OGroup::removeVetoableChangeListener( const ::rtl::OUString
& PropertyName
, const uno::Reference
< beans::XVetoableChangeListener
>& aListener
) throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
334 GroupPropertySet::removeVetoableChangeListener( PropertyName
, aListener
);
336 // -----------------------------------------------------------------------------
337 void OGroup::setSection( const ::rtl::OUString
& _sProperty
338 ,const sal_Bool
& _bOn
339 ,const ::rtl::OUString
& _sName
340 ,uno::Reference
< report::XSection
>& _member
)
344 ::osl::MutexGuard
aGuard(m_aMutex
);
345 prepareSet(_sProperty
, uno::makeAny(_member
), uno::makeAny(_bOn
), &l
);
346 lcl_createSectionIfNeeded(_bOn
,this,_member
);
348 _member
->setName(_sName
);
352 // -----------------------------------------------------------------------------
353 uno::Reference
< report::XFunctions
> SAL_CALL
OGroup::getFunctions() throw (uno::RuntimeException
)
357 // =============================================================================
358 } // namespace reportdesign
359 // =============================================================================