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 "Groups.hxx" 25 #include "Group.hxx" 26 #include <tools/debug.hxx> 27 #include "core_resource.hxx" 28 #ifndef REPORTDESIGN_CORE_RESOURCE_HRC_ 29 #include "core_resource.hrc" 30 #endif 31 #include <boost/bind.hpp> 32 #include <algorithm> 33 // ============================================================================= 34 namespace reportdesign 35 { 36 // ============================================================================= 37 using namespace com::sun::star; 38 DBG_NAME( rpt_OGroups ) 39 // ----------------------------------------------------------------------------- 40 OGroups::OGroups(const uno::Reference< report::XReportDefinition >& _xParent,const uno::Reference< uno::XComponentContext >& context) 41 :GroupsBase(m_aMutex) 42 ,m_aContainerListeners(m_aMutex) 43 ,m_xContext(context) 44 ,m_xParent(_xParent) 45 { 46 DBG_CTOR( rpt_OGroups,NULL); 47 } 48 //-------------------------------------------------------------------------- 49 // TODO: VirtualFunctionFinder: This is virtual function! 50 // 51 OGroups::~OGroups() 52 { 53 DBG_DTOR( rpt_OGroups,NULL); 54 } 55 //-------------------------------------------------------------------------- 56 void OGroups::copyGroups(const uno::Reference< report::XGroups >& _xSource) 57 { 58 sal_Int32 nCount = _xSource->getCount(); 59 for (sal_Int32 i = 0; i != nCount; ++i) 60 { 61 OGroup* pGroup = new OGroup(this,m_xContext); 62 m_aGroups.push_back(pGroup); 63 uno::Reference<report::XGroup> xGroup(_xSource->getByIndex(i),uno::UNO_QUERY); 64 pGroup->copyGroup(xGroup); 65 } 66 } 67 // ----------------------------------------------------------------------------- 68 void SAL_CALL OGroups::dispose() throw(uno::RuntimeException) 69 { 70 cppu::WeakComponentImplHelperBase::dispose(); 71 } 72 // ----------------------------------------------------------------------------- 73 // TODO: VirtualFunctionFinder: This is virtual function! 74 // 75 void SAL_CALL OGroups::disposing() 76 { 77 ::std::for_each(m_aGroups.begin(),m_aGroups.end(),::boost::mem_fn(&com::sun::star::report::XGroup::dispose)); 78 m_aGroups.clear(); 79 lang::EventObject aDisposeEvent( static_cast< ::cppu::OWeakObject* >( this ) ); 80 m_aContainerListeners.disposeAndClear( aDisposeEvent ); 81 m_xContext.clear(); 82 } 83 // ----------------------------------------------------------------------------- 84 // XGroups 85 uno::Reference< report::XReportDefinition > SAL_CALL OGroups::getReportDefinition() throw (uno::RuntimeException) 86 { 87 return m_xParent; 88 } 89 // ----------------------------------------------------------------------------- 90 uno::Reference< report::XGroup > SAL_CALL OGroups::createGroup( ) throw (uno::RuntimeException) 91 { 92 return new OGroup(this,m_xContext); 93 } 94 // ----------------------------------------------------------------------------- 95 // XIndexContainer 96 void SAL_CALL OGroups::insertByIndex( ::sal_Int32 Index, const uno::Any& aElement ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException) 97 { 98 { 99 ::osl::MutexGuard aGuard(m_aMutex); 100 sal_Bool bAdd = (Index == static_cast<sal_Int32>(m_aGroups.size())); 101 if ( !bAdd ) 102 checkIndex(Index); 103 uno::Reference< report::XGroup > xGroup(aElement,uno::UNO_QUERY); 104 if ( !xGroup.is() ) 105 throw lang::IllegalArgumentException(RPT_RESSTRING(RID_STR_ARGUMENT_IS_NULL,m_xContext->getServiceManager()),*this,2); 106 107 if ( bAdd ) 108 m_aGroups.push_back(xGroup); 109 else 110 { 111 TGroups::iterator aPos = m_aGroups.begin(); 112 ::std::advance(aPos,Index); 113 m_aGroups.insert(aPos, xGroup); 114 } 115 } 116 // notify our container listeners 117 container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::makeAny(Index), aElement, uno::Any()); 118 m_aContainerListeners.notifyEach(&container::XContainerListener::elementInserted,aEvent); 119 } 120 121 // ----------------------------------------------------------------------------- 122 void SAL_CALL OGroups::removeByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException) 123 { 124 uno::Reference< report::XGroup > xGroup; 125 { 126 ::osl::MutexGuard aGuard(m_aMutex); 127 checkIndex(Index); 128 TGroups::iterator aPos = m_aGroups.begin(); 129 ::std::advance(aPos,Index); 130 xGroup = *aPos; 131 m_aGroups.erase(aPos); 132 } 133 container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::makeAny(Index), uno::makeAny(xGroup), uno::Any()); 134 m_aContainerListeners.notifyEach(&container::XContainerListener::elementRemoved,aEvent); 135 } 136 // ----------------------------------------------------------------------------- 137 // XIndexReplace 138 void SAL_CALL OGroups::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException) 139 { 140 uno::Any aOldElement; 141 { 142 ::osl::MutexGuard aGuard(m_aMutex); 143 checkIndex(Index); 144 uno::Reference< report::XGroup > xGroup(Element,uno::UNO_QUERY); 145 if ( !xGroup.is() ) 146 throw lang::IllegalArgumentException(RPT_RESSTRING(RID_STR_ARGUMENT_IS_NULL,m_xContext->getServiceManager()),*this,2); 147 TGroups::iterator aPos = m_aGroups.begin(); 148 ::std::advance(aPos,Index); 149 aOldElement <<= *aPos; 150 *aPos = xGroup; 151 } 152 153 container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::makeAny(Index), Element, aOldElement); 154 m_aContainerListeners.notifyEach(&container::XContainerListener::elementReplaced,aEvent); 155 } 156 // ----------------------------------------------------------------------------- 157 // XIndexAccess 158 ::sal_Int32 SAL_CALL OGroups::getCount( ) throw (uno::RuntimeException) 159 { 160 ::osl::MutexGuard aGuard(m_aMutex); 161 return m_aGroups.size(); 162 } 163 // ----------------------------------------------------------------------------- 164 uno::Any SAL_CALL OGroups::getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException) 165 { 166 ::osl::MutexGuard aGuard(m_aMutex); 167 checkIndex(Index); 168 TGroups::iterator aPos = m_aGroups.begin(); 169 ::std::advance(aPos,Index); 170 return uno::makeAny(*aPos); 171 } 172 // ----------------------------------------------------------------------------- 173 // XElementAccess 174 uno::Type SAL_CALL OGroups::getElementType( ) throw (uno::RuntimeException) 175 { 176 return ::getCppuType(static_cast< uno::Reference<report::XGroup>*>(NULL)); 177 } 178 // ----------------------------------------------------------------------------- 179 ::sal_Bool SAL_CALL OGroups::hasElements( ) throw (uno::RuntimeException) 180 { 181 ::osl::MutexGuard aGuard(m_aMutex); 182 return !m_aGroups.empty(); 183 } 184 // ----------------------------------------------------------------------------- 185 // XChild 186 uno::Reference< uno::XInterface > SAL_CALL OGroups::getParent( ) throw (uno::RuntimeException) 187 { 188 return m_xParent; 189 } 190 // ----------------------------------------------------------------------------- 191 void SAL_CALL OGroups::setParent( const uno::Reference< uno::XInterface >& /*Parent*/ ) throw (lang::NoSupportException, uno::RuntimeException) 192 { 193 throw lang::NoSupportException(); 194 } 195 // ----------------------------------------------------------------------------- 196 // XContainer 197 void SAL_CALL OGroups::addContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException) 198 { 199 m_aContainerListeners.addInterface(xListener); 200 } 201 // ----------------------------------------------------------------------------- 202 void SAL_CALL OGroups::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException) 203 { 204 m_aContainerListeners.removeInterface(xListener); 205 } 206 // ----------------------------------------------------------------------------- 207 void OGroups::checkIndex(sal_Int32 _nIndex) 208 { 209 if ( _nIndex < 0 || static_cast<sal_Int32>(m_aGroups.size()) <= _nIndex ) 210 throw lang::IndexOutOfBoundsException(); 211 } 212 // ============================================================================= 213 } 214 // ============================================================================= 215