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