update dev300-m58
[ooovba.git] / reportdesign / source / core / api / Groups.cxx
blob8f76753ccc269821114b50d540797e4b3a674580
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Groups.cxx,v $
10 * $Revision: 1.4 $
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 ************************************************************************/
30 #include "Groups.hxx"
31 #include "Group.hxx"
32 #include <tools/debug.hxx>
33 #include "core_resource.hxx"
34 #ifndef REPORTDESIGN_CORE_RESOURCE_HRC_
35 #include "core_resource.hrc"
36 #endif
37 #include <boost/bind.hpp>
38 #include <algorithm>
39 // =============================================================================
40 namespace reportdesign
42 // =============================================================================
43 using namespace com::sun::star;
44 DBG_NAME( rpt_OGroups )
45 // -----------------------------------------------------------------------------
46 OGroups::OGroups(const uno::Reference< report::XReportDefinition >& _xParent,const uno::Reference< uno::XComponentContext >& context)
47 :GroupsBase(m_aMutex)
48 ,m_aContainerListeners(m_aMutex)
49 ,m_xContext(context)
50 ,m_xParent(_xParent)
52 DBG_CTOR( rpt_OGroups,NULL);
54 //--------------------------------------------------------------------------
55 // TODO: VirtualFunctionFinder: This is virtual function!
56 //
57 OGroups::~OGroups()
59 DBG_DTOR( rpt_OGroups,NULL);
61 //--------------------------------------------------------------------------
62 void OGroups::copyGroups(const uno::Reference< report::XGroups >& _xSource)
64 sal_Int32 nCount = _xSource->getCount();
65 for (sal_Int32 i = 0; i != nCount; ++i)
67 OGroup* pGroup = new OGroup(this,m_xContext);
68 m_aGroups.push_back(pGroup);
69 uno::Reference<report::XGroup> xGroup(_xSource->getByIndex(i),uno::UNO_QUERY);
70 pGroup->copyGroup(xGroup);
73 // -----------------------------------------------------------------------------
74 void SAL_CALL OGroups::dispose() throw(uno::RuntimeException)
76 cppu::WeakComponentImplHelperBase::dispose();
78 // -----------------------------------------------------------------------------
79 // TODO: VirtualFunctionFinder: This is virtual function!
80 //
81 void SAL_CALL OGroups::disposing()
83 ::std::for_each(m_aGroups.begin(),m_aGroups.end(),::boost::mem_fn(&com::sun::star::report::XGroup::dispose));
84 m_aGroups.clear();
85 lang::EventObject aDisposeEvent( static_cast< ::cppu::OWeakObject* >( this ) );
86 m_aContainerListeners.disposeAndClear( aDisposeEvent );
87 m_xContext.clear();
89 // -----------------------------------------------------------------------------
90 // XGroups
91 uno::Reference< report::XReportDefinition > SAL_CALL OGroups::getReportDefinition() throw (uno::RuntimeException)
93 return m_xParent;
95 // -----------------------------------------------------------------------------
96 uno::Reference< report::XGroup > SAL_CALL OGroups::createGroup( ) throw (uno::RuntimeException)
98 return new OGroup(this,m_xContext);
100 // -----------------------------------------------------------------------------
101 // XIndexContainer
102 void SAL_CALL OGroups::insertByIndex( ::sal_Int32 Index, const uno::Any& aElement ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
105 ::osl::MutexGuard aGuard(m_aMutex);
106 sal_Bool bAdd = (Index == static_cast<sal_Int32>(m_aGroups.size()));
107 if ( !bAdd )
108 checkIndex(Index);
109 uno::Reference< report::XGroup > xGroup(aElement,uno::UNO_QUERY);
110 if ( !xGroup.is() )
111 throw lang::IllegalArgumentException(RPT_RESSTRING(RID_STR_ARGUMENT_IS_NULL,m_xContext->getServiceManager()),*this,2);
113 if ( bAdd )
114 m_aGroups.push_back(xGroup);
115 else
117 TGroups::iterator aPos = m_aGroups.begin();
118 ::std::advance(aPos,Index);
119 m_aGroups.insert(aPos, xGroup);
122 // notify our container listeners
123 container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::makeAny(Index), aElement, uno::Any());
124 m_aContainerListeners.notifyEach(&container::XContainerListener::elementInserted,aEvent);
127 // -----------------------------------------------------------------------------
128 void SAL_CALL OGroups::removeByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
130 uno::Reference< report::XGroup > xGroup;
132 ::osl::MutexGuard aGuard(m_aMutex);
133 checkIndex(Index);
134 TGroups::iterator aPos = m_aGroups.begin();
135 ::std::advance(aPos,Index);
136 xGroup = *aPos;
137 m_aGroups.erase(aPos);
139 container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::makeAny(Index), uno::makeAny(xGroup), uno::Any());
140 m_aContainerListeners.notifyEach(&container::XContainerListener::elementRemoved,aEvent);
142 // -----------------------------------------------------------------------------
143 // XIndexReplace
144 void SAL_CALL OGroups::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
146 uno::Any aOldElement;
148 ::osl::MutexGuard aGuard(m_aMutex);
149 checkIndex(Index);
150 uno::Reference< report::XGroup > xGroup(Element,uno::UNO_QUERY);
151 if ( !xGroup.is() )
152 throw lang::IllegalArgumentException(RPT_RESSTRING(RID_STR_ARGUMENT_IS_NULL,m_xContext->getServiceManager()),*this,2);
153 TGroups::iterator aPos = m_aGroups.begin();
154 ::std::advance(aPos,Index);
155 aOldElement <<= *aPos;
156 *aPos = xGroup;
159 container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::makeAny(Index), Element, aOldElement);
160 m_aContainerListeners.notifyEach(&container::XContainerListener::elementReplaced,aEvent);
162 // -----------------------------------------------------------------------------
163 // XIndexAccess
164 ::sal_Int32 SAL_CALL OGroups::getCount( ) throw (uno::RuntimeException)
166 ::osl::MutexGuard aGuard(m_aMutex);
167 return m_aGroups.size();
169 // -----------------------------------------------------------------------------
170 uno::Any SAL_CALL OGroups::getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
172 ::osl::MutexGuard aGuard(m_aMutex);
173 checkIndex(Index);
174 TGroups::iterator aPos = m_aGroups.begin();
175 ::std::advance(aPos,Index);
176 return uno::makeAny(*aPos);
178 // -----------------------------------------------------------------------------
179 // XElementAccess
180 uno::Type SAL_CALL OGroups::getElementType( ) throw (uno::RuntimeException)
182 return ::getCppuType(static_cast< uno::Reference<report::XGroup>*>(NULL));
184 // -----------------------------------------------------------------------------
185 ::sal_Bool SAL_CALL OGroups::hasElements( ) throw (uno::RuntimeException)
187 ::osl::MutexGuard aGuard(m_aMutex);
188 return !m_aGroups.empty();
190 // -----------------------------------------------------------------------------
191 // XChild
192 uno::Reference< uno::XInterface > SAL_CALL OGroups::getParent( ) throw (uno::RuntimeException)
194 return m_xParent;
196 // -----------------------------------------------------------------------------
197 void SAL_CALL OGroups::setParent( const uno::Reference< uno::XInterface >& /*Parent*/ ) throw (lang::NoSupportException, uno::RuntimeException)
199 throw lang::NoSupportException();
201 // -----------------------------------------------------------------------------
202 // XContainer
203 void SAL_CALL OGroups::addContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException)
205 m_aContainerListeners.addInterface(xListener);
207 // -----------------------------------------------------------------------------
208 void SAL_CALL OGroups::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException)
210 m_aContainerListeners.removeInterface(xListener);
212 // -----------------------------------------------------------------------------
213 void OGroups::checkIndex(sal_Int32 _nIndex)
215 if ( _nIndex < 0 || static_cast<sal_Int32>(m_aGroups.size()) <= _nIndex )
216 throw lang::IndexOutOfBoundsException();
218 // =============================================================================
220 // =============================================================================