LibreOffice Module reportdesign (master) 1
Groups.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
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>
27
28namespace reportdesign
29{
30
31 using namespace com::sun::star;
32
33OGroups::OGroups(const uno::Reference< report::XReportDefinition >& _xParent,uno::Reference< uno::XComponentContext > context)
35,m_aContainerListeners(m_aMutex)
36,m_xContext(std::move(context))
37,m_xParent(_xParent)
38{
39}
40
41// TODO: VirtualFunctionFinder: This is virtual function!
42
43OGroups::~OGroups()
44{
45}
46
47void SAL_CALL OGroups::dispose()
48{
49 cppu::WeakComponentImplHelperBase::dispose();
50}
51
52// TODO: VirtualFunctionFinder: This is virtual function!
53
54void SAL_CALL OGroups::disposing()
55{
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();
62}
63
64// XGroups
65uno::Reference< report::XReportDefinition > SAL_CALL OGroups::getReportDefinition()
66{
67 return m_xParent;
68}
69
70uno::Reference< report::XGroup > SAL_CALL OGroups::createGroup( )
71{
72 return new OGroup(this,m_xContext);
73}
74
75// XIndexContainer
76void SAL_CALL OGroups::insertByIndex( ::sal_Int32 Index, const uno::Any& aElement )
77{
78 {
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);
86
87 if ( bAdd )
88 m_aGroups.push_back(xGroup);
89 else
90 {
91 TGroups::iterator aPos = m_aGroups.begin();
92 ::std::advance(aPos,Index);
93 m_aGroups.insert(aPos, xGroup);
94 }
95 }
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);
99}
100
101
102void SAL_CALL OGroups::removeByIndex( ::sal_Int32 Index )
103{
104 uno::Reference< report::XGroup > xGroup;
105 {
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);
112 }
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);
115}
116
117// XIndexReplace
118void SAL_CALL OGroups::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element )
119{
120 uno::Any aOldElement;
121 {
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;
131 }
132
133 container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::Any(Index), Element, aOldElement);
134 m_aContainerListeners.notifyEach(&container::XContainerListener::elementReplaced,aEvent);
135}
136
137// XIndexAccess
138::sal_Int32 SAL_CALL OGroups::getCount( )
139{
140 ::osl::MutexGuard aGuard(m_aMutex);
141 return m_aGroups.size();
142}
143
144uno::Any SAL_CALL OGroups::getByIndex( ::sal_Int32 Index )
145{
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);
151}
152
153// XElementAccess
154uno::Type SAL_CALL OGroups::getElementType( )
155{
157}
158
159sal_Bool SAL_CALL OGroups::hasElements( )
160{
161 ::osl::MutexGuard aGuard(m_aMutex);
162 return !m_aGroups.empty();
163}
164
165// XChild
166uno::Reference< uno::XInterface > SAL_CALL OGroups::getParent( )
167{
168 return m_xParent;
169}
170
171void SAL_CALL OGroups::setParent( const uno::Reference< uno::XInterface >& /*Parent*/ )
172{
173 throw lang::NoSupportException();
174}
175
176// XContainer
177void SAL_CALL OGroups::addContainerListener( const uno::Reference< container::XContainerListener >& xListener )
178{
179 m_aContainerListeners.addInterface(xListener);
180}
181
182void SAL_CALL OGroups::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener )
183{
184 m_aContainerListeners.removeInterface(xListener);
185}
186
187void OGroups::checkIndex(sal_Int32 _nIndex)
188{
189 if ( _nIndex < 0 || m_aGroups.size() <= o3tl::make_unsigned(_nIndex) )
190 throw lang::IndexOutOfBoundsException();
191}
192
193}
194
195
196/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _ADOIndex Index
Reference< XComponentContext > m_xContext
AnyEventRef aEvent
css::uno::Type const & get()
implementation of a
Definition: Group.hxx:44
OGroups(const OGroups &)=delete
OUString RptResId(TranslateId aId)
std::mutex m_aMutex
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
::cppu::WeakComponentImplHelper< css::report::XGroups > GroupsBase
Definition: Groups.hxx:32
unsigned char sal_Bool