xref: /AOO41X/main/reportdesign/source/core/api/Groups.cxx (revision 9e0e41911c53968aad5ad356e2b2126da667034f)
1*9e0e4191SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9e0e4191SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9e0e4191SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9e0e4191SAndrew Rist  * distributed with this work for additional information
6*9e0e4191SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9e0e4191SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9e0e4191SAndrew Rist  * "License"); you may not use this file except in compliance
9*9e0e4191SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*9e0e4191SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*9e0e4191SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9e0e4191SAndrew Rist  * software distributed under the License is distributed on an
15*9e0e4191SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9e0e4191SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9e0e4191SAndrew Rist  * specific language governing permissions and limitations
18*9e0e4191SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*9e0e4191SAndrew Rist  *************************************************************/
21*9e0e4191SAndrew Rist 
22*9e0e4191SAndrew Rist 
23cdf0e10cSrcweir #include "Groups.hxx"
24cdf0e10cSrcweir #include "Group.hxx"
25cdf0e10cSrcweir #include <tools/debug.hxx>
26cdf0e10cSrcweir #include "core_resource.hxx"
27cdf0e10cSrcweir #ifndef REPORTDESIGN_CORE_RESOURCE_HRC_
28cdf0e10cSrcweir #include "core_resource.hrc"
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #include <boost/bind.hpp>
31cdf0e10cSrcweir #include <algorithm>
32cdf0e10cSrcweir // =============================================================================
33cdf0e10cSrcweir namespace reportdesign
34cdf0e10cSrcweir {
35cdf0e10cSrcweir // =============================================================================
36cdf0e10cSrcweir 	using namespace com::sun::star;
DBG_NAME(rpt_OGroups)37cdf0e10cSrcweir DBG_NAME( rpt_OGroups )
38cdf0e10cSrcweir // -----------------------------------------------------------------------------
39cdf0e10cSrcweir OGroups::OGroups(const uno::Reference< report::XReportDefinition >& _xParent,const uno::Reference< uno::XComponentContext >& context)
40cdf0e10cSrcweir :GroupsBase(m_aMutex)
41cdf0e10cSrcweir ,m_aContainerListeners(m_aMutex)
42cdf0e10cSrcweir ,m_xContext(context)
43cdf0e10cSrcweir ,m_xParent(_xParent)
44cdf0e10cSrcweir {
45cdf0e10cSrcweir 	DBG_CTOR( rpt_OGroups,NULL);
46cdf0e10cSrcweir }
47cdf0e10cSrcweir //--------------------------------------------------------------------------
48cdf0e10cSrcweir // TODO: VirtualFunctionFinder: This is virtual function!
49cdf0e10cSrcweir //
~OGroups()50cdf0e10cSrcweir OGroups::~OGroups()
51cdf0e10cSrcweir {
52cdf0e10cSrcweir     DBG_DTOR( rpt_OGroups,NULL);
53cdf0e10cSrcweir }
54cdf0e10cSrcweir //--------------------------------------------------------------------------
copyGroups(const uno::Reference<report::XGroups> & _xSource)55cdf0e10cSrcweir void OGroups::copyGroups(const uno::Reference< report::XGroups >& _xSource)
56cdf0e10cSrcweir {
57cdf0e10cSrcweir 	sal_Int32 nCount = _xSource->getCount();
58cdf0e10cSrcweir 	for (sal_Int32 i = 0; i != nCount; ++i)
59cdf0e10cSrcweir 	{
60cdf0e10cSrcweir 		OGroup* pGroup = new OGroup(this,m_xContext);
61cdf0e10cSrcweir 		m_aGroups.push_back(pGroup);
62cdf0e10cSrcweir 		uno::Reference<report::XGroup> xGroup(_xSource->getByIndex(i),uno::UNO_QUERY);
63cdf0e10cSrcweir 		pGroup->copyGroup(xGroup);
64cdf0e10cSrcweir 	}
65cdf0e10cSrcweir }
66cdf0e10cSrcweir // -----------------------------------------------------------------------------
dispose()67cdf0e10cSrcweir void SAL_CALL OGroups::dispose() throw(uno::RuntimeException)
68cdf0e10cSrcweir {
69cdf0e10cSrcweir 	cppu::WeakComponentImplHelperBase::dispose();
70cdf0e10cSrcweir }
71cdf0e10cSrcweir // -----------------------------------------------------------------------------
72cdf0e10cSrcweir // TODO: VirtualFunctionFinder: This is virtual function!
73cdf0e10cSrcweir //
disposing()74cdf0e10cSrcweir void SAL_CALL OGroups::disposing()
75cdf0e10cSrcweir {
76cdf0e10cSrcweir     ::std::for_each(m_aGroups.begin(),m_aGroups.end(),::boost::mem_fn(&com::sun::star::report::XGroup::dispose));
77cdf0e10cSrcweir     m_aGroups.clear();
78cdf0e10cSrcweir     lang::EventObject aDisposeEvent( static_cast< ::cppu::OWeakObject* >( this ) );
79cdf0e10cSrcweir     m_aContainerListeners.disposeAndClear( aDisposeEvent );
80cdf0e10cSrcweir     m_xContext.clear();
81cdf0e10cSrcweir }
82cdf0e10cSrcweir // -----------------------------------------------------------------------------
83cdf0e10cSrcweir // XGroups
getReportDefinition()84cdf0e10cSrcweir uno::Reference< report::XReportDefinition > SAL_CALL OGroups::getReportDefinition() throw (uno::RuntimeException)
85cdf0e10cSrcweir {
86cdf0e10cSrcweir 	return m_xParent;
87cdf0e10cSrcweir }
88cdf0e10cSrcweir // -----------------------------------------------------------------------------
createGroup()89cdf0e10cSrcweir uno::Reference< report::XGroup > SAL_CALL OGroups::createGroup(  ) throw (uno::RuntimeException)
90cdf0e10cSrcweir {
91cdf0e10cSrcweir 	return new OGroup(this,m_xContext);
92cdf0e10cSrcweir }
93cdf0e10cSrcweir // -----------------------------------------------------------------------------
94cdf0e10cSrcweir // XIndexContainer
insertByIndex(::sal_Int32 Index,const uno::Any & aElement)95cdf0e10cSrcweir void SAL_CALL OGroups::insertByIndex( ::sal_Int32 Index, const uno::Any& aElement ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
96cdf0e10cSrcweir {
97cdf0e10cSrcweir 	{
98cdf0e10cSrcweir 		::osl::MutexGuard aGuard(m_aMutex);
99cdf0e10cSrcweir 		sal_Bool bAdd = (Index == static_cast<sal_Int32>(m_aGroups.size()));
100cdf0e10cSrcweir 		if ( !bAdd )
101cdf0e10cSrcweir 			checkIndex(Index);
102cdf0e10cSrcweir 		uno::Reference< report::XGroup > xGroup(aElement,uno::UNO_QUERY);
103cdf0e10cSrcweir 		if ( !xGroup.is() )
104cdf0e10cSrcweir 			throw lang::IllegalArgumentException(RPT_RESSTRING(RID_STR_ARGUMENT_IS_NULL,m_xContext->getServiceManager()),*this,2);
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 		if ( bAdd )
107cdf0e10cSrcweir 			m_aGroups.push_back(xGroup);
108cdf0e10cSrcweir 		else
109cdf0e10cSrcweir 		{
110cdf0e10cSrcweir 			TGroups::iterator aPos = m_aGroups.begin();
111cdf0e10cSrcweir 			::std::advance(aPos,Index);
112cdf0e10cSrcweir 			m_aGroups.insert(aPos, xGroup);
113cdf0e10cSrcweir 		}
114cdf0e10cSrcweir 	}
115cdf0e10cSrcweir 	// notify our container listeners
116cdf0e10cSrcweir 	container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::makeAny(Index), aElement, uno::Any());
117cdf0e10cSrcweir 	m_aContainerListeners.notifyEach(&container::XContainerListener::elementInserted,aEvent);
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir // -----------------------------------------------------------------------------
removeByIndex(::sal_Int32 Index)121cdf0e10cSrcweir void SAL_CALL OGroups::removeByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
122cdf0e10cSrcweir {
123cdf0e10cSrcweir 	uno::Reference< report::XGroup > xGroup;
124cdf0e10cSrcweir 	{
125cdf0e10cSrcweir 		::osl::MutexGuard aGuard(m_aMutex);
126cdf0e10cSrcweir 		checkIndex(Index);
127cdf0e10cSrcweir 		TGroups::iterator aPos = m_aGroups.begin();
128cdf0e10cSrcweir 		::std::advance(aPos,Index);
129cdf0e10cSrcweir 		xGroup = *aPos;
130cdf0e10cSrcweir 		m_aGroups.erase(aPos);
131cdf0e10cSrcweir 	}
132cdf0e10cSrcweir 	container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::makeAny(Index), uno::makeAny(xGroup), uno::Any());
133cdf0e10cSrcweir 	m_aContainerListeners.notifyEach(&container::XContainerListener::elementRemoved,aEvent);
134cdf0e10cSrcweir }
135cdf0e10cSrcweir // -----------------------------------------------------------------------------
136cdf0e10cSrcweir // XIndexReplace
replaceByIndex(::sal_Int32 Index,const uno::Any & Element)137cdf0e10cSrcweir void SAL_CALL OGroups::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
138cdf0e10cSrcweir {
139cdf0e10cSrcweir 	uno::Any aOldElement;
140cdf0e10cSrcweir 	{
141cdf0e10cSrcweir 		::osl::MutexGuard aGuard(m_aMutex);
142cdf0e10cSrcweir 		checkIndex(Index);
143cdf0e10cSrcweir 		uno::Reference< report::XGroup > xGroup(Element,uno::UNO_QUERY);
144cdf0e10cSrcweir 		if ( !xGroup.is() )
145cdf0e10cSrcweir 			throw lang::IllegalArgumentException(RPT_RESSTRING(RID_STR_ARGUMENT_IS_NULL,m_xContext->getServiceManager()),*this,2);
146cdf0e10cSrcweir 		TGroups::iterator aPos = m_aGroups.begin();
147cdf0e10cSrcweir 		::std::advance(aPos,Index);
148cdf0e10cSrcweir 		aOldElement <<= *aPos;
149cdf0e10cSrcweir 		*aPos = xGroup;
150cdf0e10cSrcweir 	}
151cdf0e10cSrcweir 
152cdf0e10cSrcweir 	container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::makeAny(Index), Element, aOldElement);
153cdf0e10cSrcweir 	m_aContainerListeners.notifyEach(&container::XContainerListener::elementReplaced,aEvent);
154cdf0e10cSrcweir }
155cdf0e10cSrcweir // -----------------------------------------------------------------------------
156cdf0e10cSrcweir // XIndexAccess
getCount()157cdf0e10cSrcweir ::sal_Int32 SAL_CALL OGroups::getCount(  ) throw (uno::RuntimeException)
158cdf0e10cSrcweir {
159cdf0e10cSrcweir 	::osl::MutexGuard aGuard(m_aMutex);
160cdf0e10cSrcweir 	return m_aGroups.size();
161cdf0e10cSrcweir }
162cdf0e10cSrcweir // -----------------------------------------------------------------------------
getByIndex(::sal_Int32 Index)163cdf0e10cSrcweir uno::Any SAL_CALL OGroups::getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
164cdf0e10cSrcweir {
165cdf0e10cSrcweir 	::osl::MutexGuard aGuard(m_aMutex);
166cdf0e10cSrcweir 	checkIndex(Index);
167cdf0e10cSrcweir 	TGroups::iterator aPos = m_aGroups.begin();
168cdf0e10cSrcweir 	::std::advance(aPos,Index);
169cdf0e10cSrcweir 	return uno::makeAny(*aPos);
170cdf0e10cSrcweir }
171cdf0e10cSrcweir // -----------------------------------------------------------------------------
172cdf0e10cSrcweir // XElementAccess
getElementType()173cdf0e10cSrcweir uno::Type SAL_CALL OGroups::getElementType(  ) throw (uno::RuntimeException)
174cdf0e10cSrcweir {
175cdf0e10cSrcweir 	return ::getCppuType(static_cast< uno::Reference<report::XGroup>*>(NULL));
176cdf0e10cSrcweir }
177cdf0e10cSrcweir // -----------------------------------------------------------------------------
hasElements()178cdf0e10cSrcweir ::sal_Bool SAL_CALL OGroups::hasElements(  ) throw (uno::RuntimeException)
179cdf0e10cSrcweir {
180cdf0e10cSrcweir 	::osl::MutexGuard aGuard(m_aMutex);
181cdf0e10cSrcweir 	return !m_aGroups.empty();
182cdf0e10cSrcweir }
183cdf0e10cSrcweir // -----------------------------------------------------------------------------
184cdf0e10cSrcweir // XChild
getParent()185cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL OGroups::getParent(  ) throw (uno::RuntimeException)
186cdf0e10cSrcweir {
187cdf0e10cSrcweir 	return m_xParent;
188cdf0e10cSrcweir }
189cdf0e10cSrcweir // -----------------------------------------------------------------------------
setParent(const uno::Reference<uno::XInterface> &)190cdf0e10cSrcweir void SAL_CALL OGroups::setParent( const uno::Reference< uno::XInterface >& /*Parent*/ ) throw (lang::NoSupportException, uno::RuntimeException)
191cdf0e10cSrcweir {
192cdf0e10cSrcweir 	throw lang::NoSupportException();
193cdf0e10cSrcweir }
194cdf0e10cSrcweir // -----------------------------------------------------------------------------
195cdf0e10cSrcweir // XContainer
addContainerListener(const uno::Reference<container::XContainerListener> & xListener)196cdf0e10cSrcweir void SAL_CALL OGroups::addContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException)
197cdf0e10cSrcweir {
198cdf0e10cSrcweir 	m_aContainerListeners.addInterface(xListener);
199cdf0e10cSrcweir }
200cdf0e10cSrcweir // -----------------------------------------------------------------------------
removeContainerListener(const uno::Reference<container::XContainerListener> & xListener)201cdf0e10cSrcweir void SAL_CALL OGroups::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException)
202cdf0e10cSrcweir {
203cdf0e10cSrcweir 	m_aContainerListeners.removeInterface(xListener);
204cdf0e10cSrcweir }
205cdf0e10cSrcweir // -----------------------------------------------------------------------------
checkIndex(sal_Int32 _nIndex)206cdf0e10cSrcweir void OGroups::checkIndex(sal_Int32 _nIndex)
207cdf0e10cSrcweir {
208cdf0e10cSrcweir 	if ( _nIndex < 0 || static_cast<sal_Int32>(m_aGroups.size()) <= _nIndex )
209cdf0e10cSrcweir 		throw lang::IndexOutOfBoundsException();
210cdf0e10cSrcweir }
211cdf0e10cSrcweir // =============================================================================
212cdf0e10cSrcweir }
213cdf0e10cSrcweir // =============================================================================
214