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 <core_resource.hxx>
24 #include <strings.hrc>
25 
26 namespace reportdesign
27 {
28 
29  using namespace com::sun::star;
30 
31 OGroups::OGroups(const uno::Reference< report::XReportDefinition >& _xParent,const uno::Reference< uno::XComponentContext >& context)
33 ,m_aContainerListeners(m_aMutex)
34 ,m_xContext(context)
35 ,m_xParent(_xParent)
36 {
37 }
38 
39 // TODO: VirtualFunctionFinder: This is virtual function!
40 
41 OGroups::~OGroups()
42 {
43 }
44 
45 void SAL_CALL OGroups::dispose()
46 {
47  cppu::WeakComponentImplHelperBase::dispose();
48 }
49 
50 // TODO: VirtualFunctionFinder: This is virtual function!
51 
52 void SAL_CALL OGroups::disposing()
53 {
54  for(auto& rGroup : m_aGroups)
55  rGroup->dispose();
56  m_aGroups.clear();
57  lang::EventObject aDisposeEvent( static_cast< ::cppu::OWeakObject* >( this ) );
58  m_aContainerListeners.disposeAndClear( aDisposeEvent );
59  m_xContext.clear();
60 }
61 
62 // XGroups
63 uno::Reference< report::XReportDefinition > SAL_CALL OGroups::getReportDefinition()
64 {
65  return m_xParent;
66 }
67 
68 uno::Reference< report::XGroup > SAL_CALL OGroups::createGroup( )
69 {
70  return new OGroup(this,m_xContext);
71 }
72 
73 // XIndexContainer
74 void SAL_CALL OGroups::insertByIndex( ::sal_Int32 Index, const uno::Any& aElement )
75 {
76  {
77  ::osl::MutexGuard aGuard(m_aMutex);
78  bool bAdd = (Index == static_cast<sal_Int32>(m_aGroups.size()));
79  if ( !bAdd )
80  checkIndex(Index);
81  uno::Reference< report::XGroup > xGroup(aElement,uno::UNO_QUERY);
82  if ( !xGroup.is() )
83  throw lang::IllegalArgumentException(RptResId(RID_STR_ARGUMENT_IS_NULL),*this,2);
84 
85  if ( bAdd )
86  m_aGroups.push_back(xGroup);
87  else
88  {
89  TGroups::iterator aPos = m_aGroups.begin();
90  ::std::advance(aPos,Index);
91  m_aGroups.insert(aPos, xGroup);
92  }
93  }
94  // notify our container listeners
95  container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::makeAny(Index), aElement, uno::Any());
96  m_aContainerListeners.notifyEach(&container::XContainerListener::elementInserted,aEvent);
97 }
98 
99 
100 void SAL_CALL OGroups::removeByIndex( ::sal_Int32 Index )
101 {
102  uno::Reference< report::XGroup > xGroup;
103  {
104  ::osl::MutexGuard aGuard(m_aMutex);
105  checkIndex(Index);
106  TGroups::iterator aPos = m_aGroups.begin();
107  ::std::advance(aPos,Index);
108  xGroup = *aPos;
109  m_aGroups.erase(aPos);
110  }
111  container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::makeAny(Index), uno::makeAny(xGroup), uno::Any());
112  m_aContainerListeners.notifyEach(&container::XContainerListener::elementRemoved,aEvent);
113 }
114 
115 // XIndexReplace
116 void SAL_CALL OGroups::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element )
117 {
118  uno::Any aOldElement;
119  {
120  ::osl::MutexGuard aGuard(m_aMutex);
121  checkIndex(Index);
122  uno::Reference< report::XGroup > xGroup(Element,uno::UNO_QUERY);
123  if ( !xGroup.is() )
124  throw lang::IllegalArgumentException(RptResId(RID_STR_ARGUMENT_IS_NULL),*this,2);
125  TGroups::iterator aPos = m_aGroups.begin();
126  ::std::advance(aPos,Index);
127  aOldElement <<= *aPos;
128  *aPos = xGroup;
129  }
130 
131  container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::makeAny(Index), Element, aOldElement);
132  m_aContainerListeners.notifyEach(&container::XContainerListener::elementReplaced,aEvent);
133 }
134 
135 // XIndexAccess
136 ::sal_Int32 SAL_CALL OGroups::getCount( )
137 {
138  ::osl::MutexGuard aGuard(m_aMutex);
139  return m_aGroups.size();
140 }
141 
142 uno::Any SAL_CALL OGroups::getByIndex( ::sal_Int32 Index )
143 {
144  ::osl::MutexGuard aGuard(m_aMutex);
145  checkIndex(Index);
146  TGroups::const_iterator aPos = m_aGroups.begin();
147  ::std::advance(aPos,Index);
148  return uno::makeAny(*aPos);
149 }
150 
151 // XElementAccess
152 uno::Type SAL_CALL OGroups::getElementType( )
153 {
155 }
156 
157 sal_Bool SAL_CALL OGroups::hasElements( )
158 {
159  ::osl::MutexGuard aGuard(m_aMutex);
160  return !m_aGroups.empty();
161 }
162 
163 // XChild
164 uno::Reference< uno::XInterface > SAL_CALL OGroups::getParent( )
165 {
166  return m_xParent;
167 }
168 
169 void SAL_CALL OGroups::setParent( const uno::Reference< uno::XInterface >& /*Parent*/ )
170 {
171  throw lang::NoSupportException();
172 }
173 
174 // XContainer
175 void SAL_CALL OGroups::addContainerListener( const uno::Reference< container::XContainerListener >& xListener )
176 {
177  m_aContainerListeners.addInterface(xListener);
178 }
179 
180 void SAL_CALL OGroups::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener )
181 {
182  m_aContainerListeners.removeInterface(xListener);
183 }
184 
185 void OGroups::checkIndex(sal_Int32 _nIndex)
186 {
187  if ( _nIndex < 0 || static_cast<sal_Int32>(m_aGroups.size()) <= _nIndex )
188  throw lang::IndexOutOfBoundsException();
189 }
190 
191 }
192 
193 
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
implementation of a
Definition: Group.hxx:41
osl::Mutex m_aMutex
::cppu::WeakComponentImplHelper< css::report::XGroups > GroupsBase
Definition: Groups.hxx:32
unsigned char sal_Bool
css::uno::Type const & get()
OUString RptResId(const char *pId)
OGroups(const OGroups &)=delete
Reference< XComponentContext > m_xContext
struct _ADOIndex Index
AnyEventRef aEvent