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