bump product version to 7.6.3.2-android
[LibreOffice.git] / reportdesign / source / core / api / Groups.cxx
blob375b8b0f545bbca112c73e5f2fd41d2e62693562
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 <o3tl/safeint.hxx>
24 #include <core_resource.hxx>
25 #include <strings.hrc>
26 #include <utility>
28 namespace reportdesign
31 using namespace com::sun::star;
33 OGroups::OGroups(const uno::Reference< report::XReportDefinition >& _xParent,uno::Reference< uno::XComponentContext > context)
34 :GroupsBase(m_aMutex)
35 ,m_aContainerListeners(m_aMutex)
36 ,m_xContext(std::move(context))
37 ,m_xParent(_xParent)
41 // TODO: VirtualFunctionFinder: This is virtual function!
43 OGroups::~OGroups()
47 void SAL_CALL OGroups::dispose()
49 cppu::WeakComponentImplHelperBase::dispose();
52 // TODO: VirtualFunctionFinder: This is virtual function!
54 void SAL_CALL OGroups::disposing()
56 for(auto& rGroup : m_aGroups)
57 rGroup->dispose();
58 m_aGroups.clear();
59 lang::EventObject aDisposeEvent( getXWeak() );
60 m_aContainerListeners.disposeAndClear( aDisposeEvent );
61 m_xContext.clear();
64 // XGroups
65 uno::Reference< report::XReportDefinition > SAL_CALL OGroups::getReportDefinition()
67 return m_xParent;
70 uno::Reference< report::XGroup > SAL_CALL OGroups::createGroup( )
72 return new OGroup(this,m_xContext);
75 // XIndexContainer
76 void SAL_CALL OGroups::insertByIndex( ::sal_Int32 Index, const uno::Any& aElement )
79 ::osl::MutexGuard aGuard(m_aMutex);
80 bool bAdd = (Index == static_cast<sal_Int32>(m_aGroups.size()));
81 if ( !bAdd )
82 checkIndex(Index);
83 uno::Reference< report::XGroup > xGroup(aElement,uno::UNO_QUERY);
84 if ( !xGroup.is() )
85 throw lang::IllegalArgumentException(RptResId(RID_STR_ARGUMENT_IS_NULL),*this,2);
87 if ( bAdd )
88 m_aGroups.push_back(xGroup);
89 else
91 TGroups::iterator aPos = m_aGroups.begin();
92 ::std::advance(aPos,Index);
93 m_aGroups.insert(aPos, xGroup);
96 // notify our container listeners
97 container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::Any(Index), aElement, uno::Any());
98 m_aContainerListeners.notifyEach(&container::XContainerListener::elementInserted,aEvent);
102 void SAL_CALL OGroups::removeByIndex( ::sal_Int32 Index )
104 uno::Reference< report::XGroup > xGroup;
106 ::osl::MutexGuard aGuard(m_aMutex);
107 checkIndex(Index);
108 TGroups::iterator aPos = m_aGroups.begin();
109 ::std::advance(aPos,Index);
110 xGroup = *aPos;
111 m_aGroups.erase(aPos);
113 container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::Any(Index), uno::Any(xGroup), uno::Any());
114 m_aContainerListeners.notifyEach(&container::XContainerListener::elementRemoved,aEvent);
117 // XIndexReplace
118 void SAL_CALL OGroups::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element )
120 uno::Any aOldElement;
122 ::osl::MutexGuard aGuard(m_aMutex);
123 checkIndex(Index);
124 uno::Reference< report::XGroup > xGroup(Element,uno::UNO_QUERY);
125 if ( !xGroup.is() )
126 throw lang::IllegalArgumentException(RptResId(RID_STR_ARGUMENT_IS_NULL),*this,2);
127 TGroups::iterator aPos = m_aGroups.begin();
128 ::std::advance(aPos,Index);
129 aOldElement <<= *aPos;
130 *aPos = xGroup;
133 container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::Any(Index), Element, aOldElement);
134 m_aContainerListeners.notifyEach(&container::XContainerListener::elementReplaced,aEvent);
137 // XIndexAccess
138 ::sal_Int32 SAL_CALL OGroups::getCount( )
140 ::osl::MutexGuard aGuard(m_aMutex);
141 return m_aGroups.size();
144 uno::Any SAL_CALL OGroups::getByIndex( ::sal_Int32 Index )
146 ::osl::MutexGuard aGuard(m_aMutex);
147 checkIndex(Index);
148 TGroups::const_iterator aPos = m_aGroups.begin();
149 ::std::advance(aPos,Index);
150 return uno::Any(*aPos);
153 // XElementAccess
154 uno::Type SAL_CALL OGroups::getElementType( )
156 return cppu::UnoType<report::XGroup>::get();
159 sal_Bool SAL_CALL OGroups::hasElements( )
161 ::osl::MutexGuard aGuard(m_aMutex);
162 return !m_aGroups.empty();
165 // XChild
166 uno::Reference< uno::XInterface > SAL_CALL OGroups::getParent( )
168 return m_xParent;
171 void SAL_CALL OGroups::setParent( const uno::Reference< uno::XInterface >& /*Parent*/ )
173 throw lang::NoSupportException();
176 // XContainer
177 void SAL_CALL OGroups::addContainerListener( const uno::Reference< container::XContainerListener >& xListener )
179 m_aContainerListeners.addInterface(xListener);
182 void SAL_CALL OGroups::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener )
184 m_aContainerListeners.removeInterface(xListener);
187 void OGroups::checkIndex(sal_Int32 _nIndex)
189 if ( _nIndex < 0 || m_aGroups.size() <= o3tl::make_unsigned(_nIndex) )
190 throw lang::IndexOutOfBoundsException();
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */