1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Groups.cxx,v $
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 ************************************************************************/
32 #include <tools/debug.hxx>
33 #include "core_resource.hxx"
34 #ifndef REPORTDESIGN_CORE_RESOURCE_HRC_
35 #include "core_resource.hrc"
37 #include <boost/bind.hpp>
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
)
48 ,m_aContainerListeners(m_aMutex
)
52 DBG_CTOR( rpt_OGroups
,NULL
);
54 //--------------------------------------------------------------------------
55 // TODO: VirtualFunctionFinder: This is virtual function!
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!
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
));
85 lang::EventObject
aDisposeEvent( static_cast< ::cppu::OWeakObject
* >( this ) );
86 m_aContainerListeners
.disposeAndClear( aDisposeEvent
);
89 // -----------------------------------------------------------------------------
91 uno::Reference
< report::XReportDefinition
> SAL_CALL
OGroups::getReportDefinition() throw (uno::RuntimeException
)
95 // -----------------------------------------------------------------------------
96 uno::Reference
< report::XGroup
> SAL_CALL
OGroups::createGroup( ) throw (uno::RuntimeException
)
98 return new OGroup(this,m_xContext
);
100 // -----------------------------------------------------------------------------
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()));
109 uno::Reference
< report::XGroup
> xGroup(aElement
,uno::UNO_QUERY
);
111 throw lang::IllegalArgumentException(RPT_RESSTRING(RID_STR_ARGUMENT_IS_NULL
,m_xContext
->getServiceManager()),*this,2);
114 m_aGroups
.push_back(xGroup
);
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
);
134 TGroups::iterator aPos
= m_aGroups
.begin();
135 ::std::advance(aPos
,Index
);
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 // -----------------------------------------------------------------------------
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
);
150 uno::Reference
< report::XGroup
> xGroup(Element
,uno::UNO_QUERY
);
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
;
159 container::ContainerEvent
aEvent(static_cast<container::XContainer
*>(this), uno::makeAny(Index
), Element
, aOldElement
);
160 m_aContainerListeners
.notifyEach(&container::XContainerListener::elementReplaced
,aEvent
);
162 // -----------------------------------------------------------------------------
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
);
174 TGroups::iterator aPos
= m_aGroups
.begin();
175 ::std::advance(aPos
,Index
);
176 return uno::makeAny(*aPos
);
178 // -----------------------------------------------------------------------------
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 // -----------------------------------------------------------------------------
192 uno::Reference
< uno::XInterface
> SAL_CALL
OGroups::getParent( ) throw (uno::RuntimeException
)
196 // -----------------------------------------------------------------------------
197 void SAL_CALL
OGroups::setParent( const uno::Reference
< uno::XInterface
>& /*Parent*/ ) throw (lang::NoSupportException
, uno::RuntimeException
)
199 throw lang::NoSupportException();
201 // -----------------------------------------------------------------------------
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 // =============================================================================