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 <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>
28 namespace reportdesign
31 using namespace com::sun::star
;
33 OGroups::OGroups(const uno::Reference
< report::XReportDefinition
>& _xParent
,uno::Reference
< uno::XComponentContext
> context
)
35 ,m_aContainerListeners(m_aMutex
)
36 ,m_xContext(std::move(context
))
41 // TODO: VirtualFunctionFinder: This is virtual function!
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
)
59 lang::EventObject
aDisposeEvent( getXWeak() );
60 m_aContainerListeners
.disposeAndClear( aDisposeEvent
);
65 uno::Reference
< report::XReportDefinition
> SAL_CALL
OGroups::getReportDefinition()
70 uno::Reference
< report::XGroup
> SAL_CALL
OGroups::createGroup( )
72 return new OGroup(this,m_xContext
);
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()));
83 uno::Reference
< report::XGroup
> xGroup(aElement
,uno::UNO_QUERY
);
85 throw lang::IllegalArgumentException(RptResId(RID_STR_ARGUMENT_IS_NULL
),*this,2);
88 m_aGroups
.push_back(xGroup
);
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
);
108 TGroups::iterator aPos
= m_aGroups
.begin();
109 ::std::advance(aPos
,Index
);
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
);
118 void SAL_CALL
OGroups::replaceByIndex( ::sal_Int32 Index
, const uno::Any
& Element
)
120 uno::Any aOldElement
;
122 ::osl::MutexGuard
aGuard(m_aMutex
);
124 uno::Reference
< report::XGroup
> xGroup(Element
,uno::UNO_QUERY
);
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
;
133 container::ContainerEvent
aEvent(static_cast<container::XContainer
*>(this), uno::Any(Index
), Element
, aOldElement
);
134 m_aContainerListeners
.notifyEach(&container::XContainerListener::elementReplaced
,aEvent
);
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
);
148 TGroups::const_iterator aPos
= m_aGroups
.begin();
149 ::std::advance(aPos
,Index
);
150 return uno::Any(*aPos
);
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();
166 uno::Reference
< uno::XInterface
> SAL_CALL
OGroups::getParent( )
171 void SAL_CALL
OGroups::setParent( const uno::Reference
< uno::XInterface
>& /*Parent*/ )
173 throw lang::NoSupportException();
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: */