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