Update ooo320-m1
[ooovba.git] / reportdesign / source / core / api / Functions.cxx
blob846e3f9fd9b5b9034dc654c38b7f03740f8d0049
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Functions.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include "Functions.hxx"
31 #include "Function.hxx"
32 #include <tools/debug.hxx>
33 #include "core_resource.hxx"
34 #ifndef REPORTDESIGN_CORE_RESOURCE_HRC_
35 #include "core_resource.hrc"
36 #endif
37 #include <comphelper/property.hxx>
38 #include <boost/bind.hpp>
39 #include <algorithm>
40 // =============================================================================
41 namespace reportdesign
43 // =============================================================================
44 using namespace com::sun::star;
45 DBG_NAME( rpt_OFunctions )
46 // -----------------------------------------------------------------------------
47 OFunctions::OFunctions(const uno::Reference< report::XFunctionsSupplier >& _xParent,const uno::Reference< uno::XComponentContext >& context)
48 :FunctionsBase(m_aMutex)
49 ,m_aContainerListeners(m_aMutex)
50 ,m_xContext(context)
51 ,m_xParent(_xParent)
53 DBG_CTOR( rpt_OFunctions,NULL);
55 //--------------------------------------------------------------------------
56 // TODO: VirtualFunctionFinder: This is virtual function!
57 //
58 OFunctions::~OFunctions()
60 DBG_DTOR( rpt_OFunctions,NULL);
62 //--------------------------------------------------------------------------
63 void SAL_CALL OFunctions::dispose() throw(uno::RuntimeException)
65 cppu::WeakComponentImplHelperBase::dispose();
67 // -----------------------------------------------------------------------------
68 // TODO: VirtualFunctionFinder: This is virtual function!
69 //
70 void SAL_CALL OFunctions::disposing()
72 ::std::for_each(m_aFunctions.begin(),m_aFunctions.end(),::boost::mem_fn(&com::sun::star::report::XFunction::dispose));
73 m_aFunctions.clear();
74 lang::EventObject aDisposeEvent( static_cast< ::cppu::OWeakObject* >( this ) );
75 m_aContainerListeners.disposeAndClear( aDisposeEvent );
76 m_xContext.clear();
78 // -----------------------------------------------------------------------------
79 // XFunctionsSupplier
80 // -----------------------------------------------------------------------------
81 uno::Reference< report::XFunction > SAL_CALL OFunctions::createFunction( ) throw (uno::RuntimeException)
83 return new OFunction(m_xContext);
85 // -----------------------------------------------------------------------------
86 // XIndexContainer
87 void SAL_CALL OFunctions::insertByIndex( ::sal_Int32 Index, const uno::Any& aElement ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
90 ::osl::MutexGuard aGuard(m_aMutex);
91 sal_Bool bAdd = (Index == static_cast<sal_Int32>(m_aFunctions.size()));
92 if ( !bAdd )
93 checkIndex(Index);
94 uno::Reference< report::XFunction > xFunction(aElement,uno::UNO_QUERY);
95 if ( !xFunction.is() )
96 throw lang::IllegalArgumentException(RPT_RESSTRING(RID_STR_ARGUMENT_IS_NULL,m_xContext->getServiceManager()),*this,2);
98 if ( bAdd )
99 m_aFunctions.push_back(xFunction);
100 else
102 TFunctions::iterator aPos = m_aFunctions.begin();
103 ::std::advance(aPos,Index);
104 m_aFunctions.insert(aPos, xFunction);
106 xFunction->setParent(*this);
108 // notify our container listeners
109 container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::makeAny(Index), aElement, uno::Any());
110 m_aContainerListeners.notifyEach(&container::XContainerListener::elementInserted,aEvent);
113 // -----------------------------------------------------------------------------
114 void SAL_CALL OFunctions::removeByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
116 uno::Reference< report::XFunction > xFunction;
118 ::osl::MutexGuard aGuard(m_aMutex);
119 checkIndex(Index);
120 TFunctions::iterator aPos = m_aFunctions.begin();
121 ::std::advance(aPos,Index);
122 xFunction = *aPos;
123 m_aFunctions.erase(aPos);
124 xFunction->setParent(NULL);
126 container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::makeAny(Index), uno::makeAny(xFunction), uno::Any());
127 m_aContainerListeners.notifyEach(&container::XContainerListener::elementRemoved,aEvent);
129 // -----------------------------------------------------------------------------
130 // XIndexReplace
131 void SAL_CALL OFunctions::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
133 uno::Any aOldElement;
135 ::osl::MutexGuard aGuard(m_aMutex);
136 checkIndex(Index);
137 uno::Reference< report::XFunction > xFunction(Element,uno::UNO_QUERY);
138 if ( !xFunction.is() )
139 throw lang::IllegalArgumentException(RPT_RESSTRING(RID_STR_ARGUMENT_IS_NULL,m_xContext->getServiceManager()),*this,2);
140 TFunctions::iterator aPos = m_aFunctions.begin();
141 ::std::advance(aPos,Index);
142 aOldElement <<= *aPos;
143 *aPos = xFunction;
146 container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::makeAny(Index), Element, aOldElement);
147 m_aContainerListeners.notifyEach(&container::XContainerListener::elementReplaced,aEvent);
149 // -----------------------------------------------------------------------------
150 // XIndexAccess
151 ::sal_Int32 SAL_CALL OFunctions::getCount( ) throw (uno::RuntimeException)
153 ::osl::MutexGuard aGuard(m_aMutex);
154 return m_aFunctions.size();
156 // -----------------------------------------------------------------------------
157 uno::Any SAL_CALL OFunctions::getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
159 ::osl::MutexGuard aGuard(m_aMutex);
160 checkIndex(Index);
161 TFunctions::iterator aPos = m_aFunctions.begin();
162 ::std::advance(aPos,Index);
163 return uno::makeAny(*aPos);
165 // -----------------------------------------------------------------------------
166 // XElementAccess
167 uno::Type SAL_CALL OFunctions::getElementType( ) throw (uno::RuntimeException)
169 return ::getCppuType(static_cast< uno::Reference<report::XFunction>*>(NULL));
171 // -----------------------------------------------------------------------------
172 ::sal_Bool SAL_CALL OFunctions::hasElements( ) throw (uno::RuntimeException)
174 ::osl::MutexGuard aGuard(m_aMutex);
175 return !m_aFunctions.empty();
177 // -----------------------------------------------------------------------------
178 // XChild
179 uno::Reference< uno::XInterface > SAL_CALL OFunctions::getParent( ) throw (uno::RuntimeException)
181 return m_xParent;
183 // -----------------------------------------------------------------------------
184 void SAL_CALL OFunctions::setParent( const uno::Reference< uno::XInterface >& /*Parent*/ ) throw (lang::NoSupportException, uno::RuntimeException)
186 throw lang::NoSupportException();
188 // -----------------------------------------------------------------------------
189 // XContainer
190 void SAL_CALL OFunctions::addContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException)
192 m_aContainerListeners.addInterface(xListener);
194 // -----------------------------------------------------------------------------
195 void SAL_CALL OFunctions::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException)
197 m_aContainerListeners.removeInterface(xListener);
199 // -----------------------------------------------------------------------------
200 void OFunctions::checkIndex(sal_Int32 _nIndex)
202 if ( _nIndex < 0 || static_cast<sal_Int32>(m_aFunctions.size()) <= _nIndex )
203 throw lang::IndexOutOfBoundsException();
205 // =============================================================================
207 // =============================================================================