1*9e0e4191SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*9e0e4191SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*9e0e4191SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*9e0e4191SAndrew Rist * distributed with this work for additional information
6*9e0e4191SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*9e0e4191SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*9e0e4191SAndrew Rist * "License"); you may not use this file except in compliance
9*9e0e4191SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*9e0e4191SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*9e0e4191SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*9e0e4191SAndrew Rist * software distributed under the License is distributed on an
15*9e0e4191SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9e0e4191SAndrew Rist * KIND, either express or implied. See the License for the
17*9e0e4191SAndrew Rist * specific language governing permissions and limitations
18*9e0e4191SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*9e0e4191SAndrew Rist *************************************************************/
21*9e0e4191SAndrew Rist
22*9e0e4191SAndrew Rist
23cdf0e10cSrcweir #include "Functions.hxx"
24cdf0e10cSrcweir #include "Function.hxx"
25cdf0e10cSrcweir #include <tools/debug.hxx>
26cdf0e10cSrcweir #include "core_resource.hxx"
27cdf0e10cSrcweir #ifndef REPORTDESIGN_CORE_RESOURCE_HRC_
28cdf0e10cSrcweir #include "core_resource.hrc"
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #include <comphelper/property.hxx>
31cdf0e10cSrcweir #include <boost/bind.hpp>
32cdf0e10cSrcweir #include <algorithm>
33cdf0e10cSrcweir // =============================================================================
34cdf0e10cSrcweir namespace reportdesign
35cdf0e10cSrcweir {
36cdf0e10cSrcweir // =============================================================================
37cdf0e10cSrcweir using namespace com::sun::star;
DBG_NAME(rpt_OFunctions)38cdf0e10cSrcweir DBG_NAME( rpt_OFunctions )
39cdf0e10cSrcweir // -----------------------------------------------------------------------------
40cdf0e10cSrcweir OFunctions::OFunctions(const uno::Reference< report::XFunctionsSupplier >& _xParent,const uno::Reference< uno::XComponentContext >& context)
41cdf0e10cSrcweir :FunctionsBase(m_aMutex)
42cdf0e10cSrcweir ,m_aContainerListeners(m_aMutex)
43cdf0e10cSrcweir ,m_xContext(context)
44cdf0e10cSrcweir ,m_xParent(_xParent)
45cdf0e10cSrcweir {
46cdf0e10cSrcweir DBG_CTOR( rpt_OFunctions,NULL);
47cdf0e10cSrcweir }
48cdf0e10cSrcweir //--------------------------------------------------------------------------
49cdf0e10cSrcweir // TODO: VirtualFunctionFinder: This is virtual function!
50cdf0e10cSrcweir //
~OFunctions()51cdf0e10cSrcweir OFunctions::~OFunctions()
52cdf0e10cSrcweir {
53cdf0e10cSrcweir DBG_DTOR( rpt_OFunctions,NULL);
54cdf0e10cSrcweir }
55cdf0e10cSrcweir //--------------------------------------------------------------------------
dispose()56cdf0e10cSrcweir void SAL_CALL OFunctions::dispose() throw(uno::RuntimeException)
57cdf0e10cSrcweir {
58cdf0e10cSrcweir cppu::WeakComponentImplHelperBase::dispose();
59cdf0e10cSrcweir }
60cdf0e10cSrcweir // -----------------------------------------------------------------------------
61cdf0e10cSrcweir // TODO: VirtualFunctionFinder: This is virtual function!
62cdf0e10cSrcweir //
disposing()63cdf0e10cSrcweir void SAL_CALL OFunctions::disposing()
64cdf0e10cSrcweir {
65cdf0e10cSrcweir ::std::for_each(m_aFunctions.begin(),m_aFunctions.end(),::boost::mem_fn(&com::sun::star::report::XFunction::dispose));
66cdf0e10cSrcweir m_aFunctions.clear();
67cdf0e10cSrcweir lang::EventObject aDisposeEvent( static_cast< ::cppu::OWeakObject* >( this ) );
68cdf0e10cSrcweir m_aContainerListeners.disposeAndClear( aDisposeEvent );
69cdf0e10cSrcweir m_xContext.clear();
70cdf0e10cSrcweir }
71cdf0e10cSrcweir // -----------------------------------------------------------------------------
72cdf0e10cSrcweir // XFunctionsSupplier
73cdf0e10cSrcweir // -----------------------------------------------------------------------------
createFunction()74cdf0e10cSrcweir uno::Reference< report::XFunction > SAL_CALL OFunctions::createFunction( ) throw (uno::RuntimeException)
75cdf0e10cSrcweir {
76cdf0e10cSrcweir return new OFunction(m_xContext);
77cdf0e10cSrcweir }
78cdf0e10cSrcweir // -----------------------------------------------------------------------------
79cdf0e10cSrcweir // XIndexContainer
insertByIndex(::sal_Int32 Index,const uno::Any & aElement)80cdf0e10cSrcweir void SAL_CALL OFunctions::insertByIndex( ::sal_Int32 Index, const uno::Any& aElement ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
81cdf0e10cSrcweir {
82cdf0e10cSrcweir {
83cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex);
84cdf0e10cSrcweir sal_Bool bAdd = (Index == static_cast<sal_Int32>(m_aFunctions.size()));
85cdf0e10cSrcweir if ( !bAdd )
86cdf0e10cSrcweir checkIndex(Index);
87cdf0e10cSrcweir uno::Reference< report::XFunction > xFunction(aElement,uno::UNO_QUERY);
88cdf0e10cSrcweir if ( !xFunction.is() )
89cdf0e10cSrcweir throw lang::IllegalArgumentException(RPT_RESSTRING(RID_STR_ARGUMENT_IS_NULL,m_xContext->getServiceManager()),*this,2);
90cdf0e10cSrcweir
91cdf0e10cSrcweir if ( bAdd )
92cdf0e10cSrcweir m_aFunctions.push_back(xFunction);
93cdf0e10cSrcweir else
94cdf0e10cSrcweir {
95cdf0e10cSrcweir TFunctions::iterator aPos = m_aFunctions.begin();
96cdf0e10cSrcweir ::std::advance(aPos,Index);
97cdf0e10cSrcweir m_aFunctions.insert(aPos, xFunction);
98cdf0e10cSrcweir }
99cdf0e10cSrcweir xFunction->setParent(*this);
100cdf0e10cSrcweir }
101cdf0e10cSrcweir // notify our container listeners
102cdf0e10cSrcweir container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::makeAny(Index), aElement, uno::Any());
103cdf0e10cSrcweir m_aContainerListeners.notifyEach(&container::XContainerListener::elementInserted,aEvent);
104cdf0e10cSrcweir }
105cdf0e10cSrcweir
106cdf0e10cSrcweir // -----------------------------------------------------------------------------
removeByIndex(::sal_Int32 Index)107cdf0e10cSrcweir void SAL_CALL OFunctions::removeByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
108cdf0e10cSrcweir {
109cdf0e10cSrcweir uno::Reference< report::XFunction > xFunction;
110cdf0e10cSrcweir {
111cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex);
112cdf0e10cSrcweir checkIndex(Index);
113cdf0e10cSrcweir TFunctions::iterator aPos = m_aFunctions.begin();
114cdf0e10cSrcweir ::std::advance(aPos,Index);
115cdf0e10cSrcweir xFunction = *aPos;
116cdf0e10cSrcweir m_aFunctions.erase(aPos);
117cdf0e10cSrcweir xFunction->setParent(NULL);
118cdf0e10cSrcweir }
119cdf0e10cSrcweir container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::makeAny(Index), uno::makeAny(xFunction), uno::Any());
120cdf0e10cSrcweir m_aContainerListeners.notifyEach(&container::XContainerListener::elementRemoved,aEvent);
121cdf0e10cSrcweir }
122cdf0e10cSrcweir // -----------------------------------------------------------------------------
123cdf0e10cSrcweir // XIndexReplace
replaceByIndex(::sal_Int32 Index,const uno::Any & Element)124cdf0e10cSrcweir void SAL_CALL OFunctions::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
125cdf0e10cSrcweir {
126cdf0e10cSrcweir uno::Any aOldElement;
127cdf0e10cSrcweir {
128cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex);
129cdf0e10cSrcweir checkIndex(Index);
130cdf0e10cSrcweir uno::Reference< report::XFunction > xFunction(Element,uno::UNO_QUERY);
131cdf0e10cSrcweir if ( !xFunction.is() )
132cdf0e10cSrcweir throw lang::IllegalArgumentException(RPT_RESSTRING(RID_STR_ARGUMENT_IS_NULL,m_xContext->getServiceManager()),*this,2);
133cdf0e10cSrcweir TFunctions::iterator aPos = m_aFunctions.begin();
134cdf0e10cSrcweir ::std::advance(aPos,Index);
135cdf0e10cSrcweir aOldElement <<= *aPos;
136cdf0e10cSrcweir *aPos = xFunction;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir
139cdf0e10cSrcweir container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::makeAny(Index), Element, aOldElement);
140cdf0e10cSrcweir m_aContainerListeners.notifyEach(&container::XContainerListener::elementReplaced,aEvent);
141cdf0e10cSrcweir }
142cdf0e10cSrcweir // -----------------------------------------------------------------------------
143cdf0e10cSrcweir // XIndexAccess
getCount()144cdf0e10cSrcweir ::sal_Int32 SAL_CALL OFunctions::getCount( ) throw (uno::RuntimeException)
145cdf0e10cSrcweir {
146cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex);
147cdf0e10cSrcweir return m_aFunctions.size();
148cdf0e10cSrcweir }
149cdf0e10cSrcweir // -----------------------------------------------------------------------------
getByIndex(::sal_Int32 Index)150cdf0e10cSrcweir uno::Any SAL_CALL OFunctions::getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
151cdf0e10cSrcweir {
152cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex);
153cdf0e10cSrcweir checkIndex(Index);
154cdf0e10cSrcweir TFunctions::iterator aPos = m_aFunctions.begin();
155cdf0e10cSrcweir ::std::advance(aPos,Index);
156cdf0e10cSrcweir return uno::makeAny(*aPos);
157cdf0e10cSrcweir }
158cdf0e10cSrcweir // -----------------------------------------------------------------------------
159cdf0e10cSrcweir // XElementAccess
getElementType()160cdf0e10cSrcweir uno::Type SAL_CALL OFunctions::getElementType( ) throw (uno::RuntimeException)
161cdf0e10cSrcweir {
162cdf0e10cSrcweir return ::getCppuType(static_cast< uno::Reference<report::XFunction>*>(NULL));
163cdf0e10cSrcweir }
164cdf0e10cSrcweir // -----------------------------------------------------------------------------
hasElements()165cdf0e10cSrcweir ::sal_Bool SAL_CALL OFunctions::hasElements( ) throw (uno::RuntimeException)
166cdf0e10cSrcweir {
167cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex);
168cdf0e10cSrcweir return !m_aFunctions.empty();
169cdf0e10cSrcweir }
170cdf0e10cSrcweir // -----------------------------------------------------------------------------
171cdf0e10cSrcweir // XChild
getParent()172cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL OFunctions::getParent( ) throw (uno::RuntimeException)
173cdf0e10cSrcweir {
174cdf0e10cSrcweir return m_xParent;
175cdf0e10cSrcweir }
176cdf0e10cSrcweir // -----------------------------------------------------------------------------
setParent(const uno::Reference<uno::XInterface> &)177cdf0e10cSrcweir void SAL_CALL OFunctions::setParent( const uno::Reference< uno::XInterface >& /*Parent*/ ) throw (lang::NoSupportException, uno::RuntimeException)
178cdf0e10cSrcweir {
179cdf0e10cSrcweir throw lang::NoSupportException();
180cdf0e10cSrcweir }
181cdf0e10cSrcweir // -----------------------------------------------------------------------------
182cdf0e10cSrcweir // XContainer
addContainerListener(const uno::Reference<container::XContainerListener> & xListener)183cdf0e10cSrcweir void SAL_CALL OFunctions::addContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException)
184cdf0e10cSrcweir {
185cdf0e10cSrcweir m_aContainerListeners.addInterface(xListener);
186cdf0e10cSrcweir }
187cdf0e10cSrcweir // -----------------------------------------------------------------------------
removeContainerListener(const uno::Reference<container::XContainerListener> & xListener)188cdf0e10cSrcweir void SAL_CALL OFunctions::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException)
189cdf0e10cSrcweir {
190cdf0e10cSrcweir m_aContainerListeners.removeInterface(xListener);
191cdf0e10cSrcweir }
192cdf0e10cSrcweir // -----------------------------------------------------------------------------
checkIndex(sal_Int32 _nIndex)193cdf0e10cSrcweir void OFunctions::checkIndex(sal_Int32 _nIndex)
194cdf0e10cSrcweir {
195cdf0e10cSrcweir if ( _nIndex < 0 || static_cast<sal_Int32>(m_aFunctions.size()) <= _nIndex )
196cdf0e10cSrcweir throw lang::IndexOutOfBoundsException();
197cdf0e10cSrcweir }
198cdf0e10cSrcweir // =============================================================================
199cdf0e10cSrcweir }
200cdf0e10cSrcweir // =============================================================================
201