1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <tools/debug.hxx>
22 #include "core_resource.hxx"
23 #include "core_resource.hrc"
24 #include <boost/mem_fn.hpp>
26 // =============================================================================
27 namespace reportdesign
29 // =============================================================================
30 using namespace com::sun::star
;
31 DBG_NAME( rpt_OGroups
)
32 // -----------------------------------------------------------------------------
33 OGroups::OGroups(const uno::Reference
< report::XReportDefinition
>& _xParent
,const uno::Reference
< uno::XComponentContext
>& context
)
35 ,m_aContainerListeners(m_aMutex
)
39 DBG_CTOR( rpt_OGroups
,NULL
);
41 //--------------------------------------------------------------------------
42 // TODO: VirtualFunctionFinder: This is virtual function!
46 DBG_DTOR( rpt_OGroups
,NULL
);
48 //--------------------------------------------------------------------------
49 void OGroups::copyGroups(const uno::Reference
< report::XGroups
>& _xSource
)
51 sal_Int32 nCount
= _xSource
->getCount();
52 for (sal_Int32 i
= 0; i
!= nCount
; ++i
)
54 OGroup
* pGroup
= new OGroup(this,m_xContext
);
55 m_aGroups
.push_back(pGroup
);
56 uno::Reference
<report::XGroup
> xGroup(_xSource
->getByIndex(i
),uno::UNO_QUERY
);
57 pGroup
->copyGroup(xGroup
);
60 // -----------------------------------------------------------------------------
61 void SAL_CALL
OGroups::dispose() throw(uno::RuntimeException
)
63 cppu::WeakComponentImplHelperBase::dispose();
65 // -----------------------------------------------------------------------------
66 // TODO: VirtualFunctionFinder: This is virtual function!
68 void SAL_CALL
OGroups::disposing()
70 ::std::for_each(m_aGroups
.begin(),m_aGroups
.end(),::boost::mem_fn(&com::sun::star::report::XGroup::dispose
));
72 lang::EventObject
aDisposeEvent( static_cast< ::cppu::OWeakObject
* >( this ) );
73 m_aContainerListeners
.disposeAndClear( aDisposeEvent
);
76 // -----------------------------------------------------------------------------
78 uno::Reference
< report::XReportDefinition
> SAL_CALL
OGroups::getReportDefinition() throw (uno::RuntimeException
)
82 // -----------------------------------------------------------------------------
83 uno::Reference
< report::XGroup
> SAL_CALL
OGroups::createGroup( ) throw (uno::RuntimeException
)
85 return new OGroup(this,m_xContext
);
87 // -----------------------------------------------------------------------------
89 void SAL_CALL
OGroups::insertByIndex( ::sal_Int32 Index
, const uno::Any
& aElement
) throw (lang::IllegalArgumentException
, lang::IndexOutOfBoundsException
, lang::WrappedTargetException
, uno::RuntimeException
)
92 ::osl::MutexGuard
aGuard(m_aMutex
);
93 sal_Bool bAdd
= (Index
== static_cast<sal_Int32
>(m_aGroups
.size()));
96 uno::Reference
< report::XGroup
> xGroup(aElement
,uno::UNO_QUERY
);
98 throw lang::IllegalArgumentException(RPT_RESSTRING(RID_STR_ARGUMENT_IS_NULL
,m_xContext
->getServiceManager()),*this,2);
101 m_aGroups
.push_back(xGroup
);
104 TGroups::iterator aPos
= m_aGroups
.begin();
105 ::std::advance(aPos
,Index
);
106 m_aGroups
.insert(aPos
, xGroup
);
109 // notify our container listeners
110 container::ContainerEvent
aEvent(static_cast<container::XContainer
*>(this), uno::makeAny(Index
), aElement
, uno::Any());
111 m_aContainerListeners
.notifyEach(&container::XContainerListener::elementInserted
,aEvent
);
114 // -----------------------------------------------------------------------------
115 void SAL_CALL
OGroups::removeByIndex( ::sal_Int32 Index
) throw (lang::IndexOutOfBoundsException
, lang::WrappedTargetException
, uno::RuntimeException
)
117 uno::Reference
< report::XGroup
> xGroup
;
119 ::osl::MutexGuard
aGuard(m_aMutex
);
121 TGroups::iterator aPos
= m_aGroups
.begin();
122 ::std::advance(aPos
,Index
);
124 m_aGroups
.erase(aPos
);
126 container::ContainerEvent
aEvent(static_cast<container::XContainer
*>(this), uno::makeAny(Index
), uno::makeAny(xGroup
), uno::Any());
127 m_aContainerListeners
.notifyEach(&container::XContainerListener::elementRemoved
,aEvent
);
129 // -----------------------------------------------------------------------------
131 void SAL_CALL
OGroups::replaceByIndex( ::sal_Int32 Index
, const uno::Any
& Element
) throw (lang::IllegalArgumentException
, lang::IndexOutOfBoundsException
, lang::WrappedTargetException
, uno::RuntimeException
)
133 uno::Any aOldElement
;
135 ::osl::MutexGuard
aGuard(m_aMutex
);
137 uno::Reference
< report::XGroup
> xGroup(Element
,uno::UNO_QUERY
);
139 throw lang::IllegalArgumentException(RPT_RESSTRING(RID_STR_ARGUMENT_IS_NULL
,m_xContext
->getServiceManager()),*this,2);
140 TGroups::iterator aPos
= m_aGroups
.begin();
141 ::std::advance(aPos
,Index
);
142 aOldElement
<<= *aPos
;
146 container::ContainerEvent
aEvent(static_cast<container::XContainer
*>(this), uno::makeAny(Index
), Element
, aOldElement
);
147 m_aContainerListeners
.notifyEach(&container::XContainerListener::elementReplaced
,aEvent
);
149 // -----------------------------------------------------------------------------
151 ::sal_Int32 SAL_CALL
OGroups::getCount( ) throw (uno::RuntimeException
)
153 ::osl::MutexGuard
aGuard(m_aMutex
);
154 return m_aGroups
.size();
156 // -----------------------------------------------------------------------------
157 uno::Any SAL_CALL
OGroups::getByIndex( ::sal_Int32 Index
) throw (lang::IndexOutOfBoundsException
, lang::WrappedTargetException
, uno::RuntimeException
)
159 ::osl::MutexGuard
aGuard(m_aMutex
);
161 TGroups::iterator aPos
= m_aGroups
.begin();
162 ::std::advance(aPos
,Index
);
163 return uno::makeAny(*aPos
);
165 // -----------------------------------------------------------------------------
167 uno::Type SAL_CALL
OGroups::getElementType( ) throw (uno::RuntimeException
)
169 return ::getCppuType(static_cast< uno::Reference
<report::XGroup
>*>(NULL
));
171 // -----------------------------------------------------------------------------
172 ::sal_Bool SAL_CALL
OGroups::hasElements( ) throw (uno::RuntimeException
)
174 ::osl::MutexGuard
aGuard(m_aMutex
);
175 return !m_aGroups
.empty();
177 // -----------------------------------------------------------------------------
179 uno::Reference
< uno::XInterface
> SAL_CALL
OGroups::getParent( ) throw (uno::RuntimeException
)
183 // -----------------------------------------------------------------------------
184 void SAL_CALL
OGroups::setParent( const uno::Reference
< uno::XInterface
>& /*Parent*/ ) throw (lang::NoSupportException
, uno::RuntimeException
)
186 throw lang::NoSupportException();
188 // -----------------------------------------------------------------------------
190 void SAL_CALL
OGroups::addContainerListener( const uno::Reference
< container::XContainerListener
>& xListener
) throw (uno::RuntimeException
)
192 m_aContainerListeners
.addInterface(xListener
);
194 // -----------------------------------------------------------------------------
195 void SAL_CALL
OGroups::removeContainerListener( const uno::Reference
< container::XContainerListener
>& xListener
) throw (uno::RuntimeException
)
197 m_aContainerListeners
.removeInterface(xListener
);
199 // -----------------------------------------------------------------------------
200 void OGroups::checkIndex(sal_Int32 _nIndex
)
202 if ( _nIndex
< 0 || static_cast<sal_Int32
>(m_aGroups
.size()) <= _nIndex
)
203 throw lang::IndexOutOfBoundsException();
205 // =============================================================================
207 // =============================================================================
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */