lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / reportdesign / source / core / api / Groups.cxx
blob96270e5d3f19e1834713827835e6ee4a0a282c59
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
19 #include <Groups.hxx>
20 #include <Group.hxx>
21 #include <com/sun/star/lang/NoSupportException.hpp>
22 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
23 #include <core_resource.hxx>
24 #include <strings.hrc>
25 #include <algorithm>
27 namespace reportdesign
30 using namespace com::sun::star;
32 OGroups::OGroups(const uno::Reference< report::XReportDefinition >& _xParent,const uno::Reference< uno::XComponentContext >& context)
33 :GroupsBase(m_aMutex)
34 ,m_aContainerListeners(m_aMutex)
35 ,m_xContext(context)
36 ,m_xParent(_xParent)
40 // TODO: VirtualFunctionFinder: This is virtual function!
42 OGroups::~OGroups()
46 void SAL_CALL OGroups::dispose()
48 cppu::WeakComponentImplHelperBase::dispose();
51 // TODO: VirtualFunctionFinder: This is virtual function!
53 void SAL_CALL OGroups::disposing()
55 for(auto& rGroup : m_aGroups)
56 rGroup->dispose();
57 m_aGroups.clear();
58 lang::EventObject aDisposeEvent( static_cast< ::cppu::OWeakObject* >( this ) );
59 m_aContainerListeners.disposeAndClear( aDisposeEvent );
60 m_xContext.clear();
63 // XGroups
64 uno::Reference< report::XReportDefinition > SAL_CALL OGroups::getReportDefinition()
66 return m_xParent;
69 uno::Reference< report::XGroup > SAL_CALL OGroups::createGroup( )
71 return new OGroup(this,m_xContext);
74 // XIndexContainer
75 void SAL_CALL OGroups::insertByIndex( ::sal_Int32 Index, const uno::Any& aElement )
78 ::osl::MutexGuard aGuard(m_aMutex);
79 bool bAdd = (Index == static_cast<sal_Int32>(m_aGroups.size()));
80 if ( !bAdd )
81 checkIndex(Index);
82 uno::Reference< report::XGroup > xGroup(aElement,uno::UNO_QUERY);
83 if ( !xGroup.is() )
84 throw lang::IllegalArgumentException(RptResId(RID_STR_ARGUMENT_IS_NULL),*this,2);
86 if ( bAdd )
87 m_aGroups.push_back(xGroup);
88 else
90 TGroups::iterator aPos = m_aGroups.begin();
91 ::std::advance(aPos,Index);
92 m_aGroups.insert(aPos, xGroup);
95 // notify our container listeners
96 container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::makeAny(Index), aElement, uno::Any());
97 m_aContainerListeners.notifyEach(&container::XContainerListener::elementInserted,aEvent);
101 void SAL_CALL OGroups::removeByIndex( ::sal_Int32 Index )
103 uno::Reference< report::XGroup > xGroup;
105 ::osl::MutexGuard aGuard(m_aMutex);
106 checkIndex(Index);
107 TGroups::iterator aPos = m_aGroups.begin();
108 ::std::advance(aPos,Index);
109 xGroup = *aPos;
110 m_aGroups.erase(aPos);
112 container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::makeAny(Index), uno::makeAny(xGroup), uno::Any());
113 m_aContainerListeners.notifyEach(&container::XContainerListener::elementRemoved,aEvent);
116 // XIndexReplace
117 void SAL_CALL OGroups::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element )
119 uno::Any aOldElement;
121 ::osl::MutexGuard aGuard(m_aMutex);
122 checkIndex(Index);
123 uno::Reference< report::XGroup > xGroup(Element,uno::UNO_QUERY);
124 if ( !xGroup.is() )
125 throw lang::IllegalArgumentException(RptResId(RID_STR_ARGUMENT_IS_NULL),*this,2);
126 TGroups::iterator aPos = m_aGroups.begin();
127 ::std::advance(aPos,Index);
128 aOldElement <<= *aPos;
129 *aPos = xGroup;
132 container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::makeAny(Index), Element, aOldElement);
133 m_aContainerListeners.notifyEach(&container::XContainerListener::elementReplaced,aEvent);
136 // XIndexAccess
137 ::sal_Int32 SAL_CALL OGroups::getCount( )
139 ::osl::MutexGuard aGuard(m_aMutex);
140 return m_aGroups.size();
143 uno::Any SAL_CALL OGroups::getByIndex( ::sal_Int32 Index )
145 ::osl::MutexGuard aGuard(m_aMutex);
146 checkIndex(Index);
147 TGroups::const_iterator aPos = m_aGroups.begin();
148 ::std::advance(aPos,Index);
149 return uno::makeAny(*aPos);
152 // XElementAccess
153 uno::Type SAL_CALL OGroups::getElementType( )
155 return cppu::UnoType<report::XGroup>::get();
158 sal_Bool SAL_CALL OGroups::hasElements( )
160 ::osl::MutexGuard aGuard(m_aMutex);
161 return !m_aGroups.empty();
164 // XChild
165 uno::Reference< uno::XInterface > SAL_CALL OGroups::getParent( )
167 return m_xParent;
170 void SAL_CALL OGroups::setParent( const uno::Reference< uno::XInterface >& /*Parent*/ )
172 throw lang::NoSupportException();
175 // XContainer
176 void SAL_CALL OGroups::addContainerListener( const uno::Reference< container::XContainerListener >& xListener )
178 m_aContainerListeners.addInterface(xListener);
181 void SAL_CALL OGroups::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener )
183 m_aContainerListeners.removeInterface(xListener);
186 void OGroups::checkIndex(sal_Int32 _nIndex)
188 if ( _nIndex < 0 || static_cast<sal_Int32>(m_aGroups.size()) <= _nIndex )
189 throw lang::IndexOutOfBoundsException();
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */