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